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 	}
170 }
171 
clearAll()172 void Globals::clearAll() {
173 	_vm->_fontMan->clearAll();
174 	_vm->_dialog->clearAll();
175 	_answerBuffer = NULL;
176 	_levelSpriteBuf = NULL;
177 	_saveData = NULL;
178 	_vm->_objectsMan->_curObjectIndex = 0;
179 
180 	_vm->_linesMan->clearAll();
181 	_vm->_objectsMan->clearAll();
182 
183 	_saveData = (Savegame *)malloc(sizeof(Savegame));
184 	_saveData->reset();
185 
186 	_vm->_events->clearAll();
187 }
188 
loadCharacterData()189 void Globals::loadCharacterData() {
190 	const int *srcList[] = { HOPKINS_PERSO_0, HOPKINS_PERSO_1, HOPKINS_PERSO_2 };
191 	const int *srcP = srcList[_characterType];
192 
193 	for (int idx = 0; idx < 240 / 4; ++idx) {
194 		_hopkinsItem[idx]._speedX = *srcP++;
195 		_hopkinsItem[idx]._speedY = *srcP++;
196 	}
197 
198 	_vm->_objectsMan->resetOldFrameIndex();
199 	_vm->_objectsMan->resetOldDirection();
200 }
201 
allocMemory(int count)202 byte *Globals::allocMemory(int count) {
203 	byte *result = (byte *)malloc(count);
204 	if (!result)
205 		result = NULL;
206 	return result;
207 }
208 
freeMemory(byte * p)209 byte *Globals::freeMemory(byte *p) {
210 	if (p)
211 		free(p);
212 	return NULL;
213 }
214 
215 } // End of namespace Hopkins
216