1 /* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23 #include "hopkins/globals.h"
24
25 #include "hopkins/files.h"
26 #include "hopkins/font.h"
27 #include "hopkins/graphics.h"
28 #include "hopkins/hopkins.h"
29
30 #include "common/textconsole.h"
31 #include "common/file.h"
32
33 namespace Hopkins {
34
35 // Default data for the Hopkins array
36
37 const int HOPKINS_PERSO_0[] = {
38 0, -2, 0, -3, 0, -6, 0, -1, 0, -3, 0, -3, 0, -5, 0, -3, 0, -6, 0, -3, 0, -3, 0, -3,
39 9, -4, 8, -4, 6, -2, 9, -2, 9, -3, 9, -3, 9, -4, 9, -2, 9, -2, 8, -2, 9, -3, 9, -2,
40 13, 0, 13, 0, 13, 0, 13, 0, 14, 0, 13, 0, 13, 0, 12, 0, 12, 0, 14, 0, 13, 0, 14, 0,
41 10, 3, 9, 3, 10, 4, 8, 2, 7, 1, 10, 2, 9, 2, 7, 4, 7, 3, 8, 0, 9, 1, 9, 1, 0, 4, 0,
42 4, 0, 6, 0, 3, 0, 4, 0, 3, 0, 4, 0, 4, 0, 6, 0, 3, 0, 3, 0, 3
43 };
44
45 const int HOPKINS_PERSO_1[] = {
46 0, -2, 0, -2, 0, -5, 0, -1, 0, -2, 0, -2, 0, -4, 0, -2, 0, -5, 0, -2, 0, -2, 0, -2,
47 11, 0, 10, 0, 11, 0, 11, 0, 11, 0, 11, 0, 12, 0, 11, 0, 9, 0, 10, 0, 11, 0, 11, 0,
48 11, 0, 10, 0, 11, 0, 11, 0, 11, 0, 11, 0, 12, 0, 11, 0, 9, 0, 10, 0, 11, 0, 11, 0,
49 11, 0, 10, 0, 11, 0, 11, 0, 11, 0, 11, 0, 12, 0, 11, 0, 9, 0, 10, 0, 11, 0, 11, 0,
50 0, 3, 0, 3, 0, 5, 0, 3, 0, 3, 0, 3, 0, 3, 0, 3, 0, 5, 0, 3, 0, 3, 0, 3
51 };
52
53 const int HOPKINS_PERSO_2[] = {
54 0, -2, 0, 0, 0, -3, 0, -2, 0, -2, 0, -1, 0, -2, 0, -1, 0, -3, 0, -2, 0, -2, 0, -2,
55 8, 0, 9, 0, 5, 0, 9, 0, 7, 0, 7, 0, 7, 0, 7, 0, 6, 0, 7, 0, 6, 0, 9, 0, 8, 0, 9, 0,
56 5, 0, 9, 0, 7, 0, 7, 0, 7, 0, 7, 0, 6, 0, 7, 0, 6, 0, 9, 0, 8, 0, 9, 0, 5, 0, 9, 0,
57 7, 0, 7, 0, 7, 0, 7, 0, 6, 0, 7, 0, 6, 0, 9, 0, 0, 2, 0, 0, 0, 2, 0, 1, 0, 2, 0, 2,
58 0, 2, 0, 2, 0, 2, 0, 1, 0, 2, 0, 2
59 };
60
Globals(HopkinsEngine * vm)61 Globals::Globals(HopkinsEngine *vm) {
62 _vm = vm;
63
64 // Initialize array properties
65 for (int i = 0; i < 500; ++i)
66 _spriteSize[i] = 0;
67 for (int i = 0; i < 70; ++i)
68 Common::fill((byte *)&_hopkinsItem[i], (byte *)&_hopkinsItem[i] + sizeof(HopkinsItem), 0);
69
70 for (int i = 0; i < 36; ++i)
71 _inventory[i] = 0;
72
73 // Initialize fields
74 _language = LANG_EN;
75
76 _linuxEndDemoFl = false;
77 _speed = 1;
78 _eventMode = EVENTMODE_DEFAULT;
79 _exitId = 0;
80 _characterSpriteBuf = 0;
81 _screenId = 0;
82 _prevScreenId = 0;
83 _characterMaxPosY = 0;
84 _menuScrollSpeed = 0;
85 _menuSpeed = 0;
86 _menuSoundOff = 0;
87 _menuVoiceOff = 0;
88 _menuMusicOff = 0;
89 _menuTextOff = 0;
90 _menuDisplayType = 0;
91 _checkDistanceFl = false;
92 _characterType = CHARACTER_HOPKINS;
93 _actionMoveTo = false;
94 _actionDirection = DIR_NONE;
95
96 _creditsStartX = -1;
97 _creditsEndX = -1;
98 _creditsStartY = -1;
99 _creditsEndY = -1;
100 _creditsPosY = 0;
101 _creditsLineNumb = 0;
102 memset(_creditsItem, 0, 12000);
103 _creditsStep = 0;
104
105 _oceanDirection = DIR_NONE;
106
107 // Initialize pointers
108 _levelSpriteBuf = NULL;
109 _saveData = NULL;
110 _answerBuffer = NULL;
111 _characterSpriteBuf = NULL;
112 _optionDialogSpr = NULL;
113
114 // Reset flags
115 _censorshipFl = false;
116 _disableInventFl = false;
117 _freezeCharacterFl = false;
118 _optionDialogFl = false;
119 _introSpeechOffFl = false;
120 _cityMapEnabledFl = false;
121
122 _baseMapColor = 50;
123 _curRoomNum = 0;
124 }
125
~Globals()126 Globals::~Globals() {
127 freeMemory(_levelSpriteBuf);
128 freeMemory((byte *)_saveData);
129 freeMemory(_answerBuffer);
130 freeMemory(_characterSpriteBuf);
131 free(NULL);
132 }
133
setConfig()134 void Globals::setConfig() {
135 // CHECKME: Should be in Globals() but it doesn't work
136 // The Polish version is a translation of the English version. The filenames are the same.
137 // The Russian version looks like a translation of the English version, based on the filenames.
138 switch (_vm->getLanguage()) {
139 case Common::EN_ANY:
140 case Common::PL_POL:
141 case Common::RU_RUS:
142 _language = LANG_EN;
143 break;
144 case Common::FR_FRA:
145 _language = LANG_FR;
146 break;
147 case Common::ES_ESP:
148 _language = LANG_SP;
149 break;
150 default:
151 error("Hopkins - SetConfig(): Unknown language in internal language mapping");
152 break;
153 }
154 // End of CHECKME
155
156 switch (_language) {
157 case LANG_EN:
158 _zoneFilename = "ZONEAN.TXT";
159 _textFilename = "TEXTEAN.TXT";
160 break;
161 case LANG_FR:
162 _zoneFilename = "ZONE01.TXT";
163 _textFilename = "TEXTE01.TXT";
164 break;
165 case LANG_SP:
166 _zoneFilename = "ZONEES.TXT";
167 _textFilename = "TEXTEES.TXT";
168 break;
169 default:
170 break;
171 }
172 }
173
clearAll()174 void Globals::clearAll() {
175 _vm->_fontMan->clearAll();
176 _vm->_dialog->clearAll();
177 _answerBuffer = NULL;
178 _levelSpriteBuf = NULL;
179 _saveData = NULL;
180 _vm->_objectsMan->_curObjectIndex = 0;
181
182 _vm->_linesMan->clearAll();
183 _vm->_objectsMan->clearAll();
184
185 _saveData = (Savegame *)malloc(sizeof(Savegame));
186 _saveData->reset();
187
188 _vm->_events->clearAll();
189 }
190
loadCharacterData()191 void Globals::loadCharacterData() {
192 const int *srcList[] = { HOPKINS_PERSO_0, HOPKINS_PERSO_1, HOPKINS_PERSO_2 };
193 const int *srcP = srcList[_characterType];
194
195 for (int idx = 0; idx < 240 / 4; ++idx) {
196 _hopkinsItem[idx]._speedX = *srcP++;
197 _hopkinsItem[idx]._speedY = *srcP++;
198 }
199
200 _vm->_objectsMan->resetOldFrameIndex();
201 _vm->_objectsMan->resetOldDirection();
202 }
203
allocMemory(int count)204 byte *Globals::allocMemory(int count) {
205 byte *result = (byte *)malloc(count);
206 if (!result)
207 result = NULL;
208 return result;
209 }
210
freeMemory(byte * p)211 byte *Globals::freeMemory(byte *p) {
212 if (p)
213 free(p);
214 return NULL;
215 }
216
217 } // End of namespace Hopkins
218