File: data.cpp

package info (click to toggle)
scummvm 2.9.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 450,580 kB
  • sloc: cpp: 4,299,825; asm: 28,322; python: 12,901; sh: 11,302; java: 9,289; xml: 7,895; perl: 2,639; ansic: 2,465; yacc: 1,670; javascript: 1,020; makefile: 933; lex: 578; awk: 275; objc: 82; sed: 11; php: 1
file content (406 lines) | stat: -rw-r--r-- 12,287 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include "common/textconsole.h"

#include "engines/asylum/detection.h"

#include "engines/asylum/resources/data.h"

namespace Asylum {

SharedData::SharedData() : crowsData(this) {
	// Public data
	cdNumber                           = 0;
	movieIndex                         = 0;
	sceneCounter                       = 0;
	actorEnableForStatus7              = false;
	globalDirection                    = kDirectionN;

	memset(&_ambientFlags, 0, sizeof(_ambientFlags));
	memset(&_ambientTicks, 0, sizeof(_ambientTicks));
	_globalPoint.x                     = -1;
	_globalPoint.y                     = -1;
	_flagSkipScriptProcessing          = false;
	_flagIsEncounterRunning            = false;
	_playerIndex                       = 0;
	_sceneOffset                       = 0;
	_sceneOffsetAdd                    = 0;
	memset(&_cursorResources, kResourceNone, sizeof(_cursorResources));
	memset(&_sceneFonts, kResourceNone, sizeof(_sceneFonts));
	memset(&_chapter2Data1, 0, sizeof(_chapter2Data1));
	_smallCurUp                        = 0;
	_smallCurDown                      = 0;
	_encounterFrameBg                  = kResourceNone;
	_flagSkipDrawScene                 = false;
	_matteVar1                         = 0;
	_flagActorUpdateEnabledCheck       = false;
	_matteInitialized                  = false;
	_mattePlaySound                    = false;
	_currentScreenUpdatesCount         = 0;
	memset(&_chapter2Data2, 0, sizeof(_chapter2Data2));
	memset(&_chapter2Counters, 0, sizeof(_chapter2Counters));
	memset(&_chapter2Data3, 0, sizeof(_chapter2Data3));
	_chapter2FrameIndexOffset          = 0;
	_chapter2ActorIndex                = 0;
	_eventUpdate                       = 0;
	memset(&_chapter2Data4, 0, sizeof(_chapter2Data4));
	_actorUpdateStatusEnabledCounter   = 0;
	memset(&_chapter2Data5, 0, sizeof(_chapter2Data5));
	_flagEncounterDisablePlayerOnExit  = false;
	_flag1                             = false;
	_nextScreenUpdate                  = 0;
	// _moviesViewed
	_flagActorUpdateStatus15Check      = false;

	// Non-saved data
	_flag2                             = false;
	_flag3                             = false;
	_flagScene1                        = false;
	_flagRedraw                        = false;

	_matteBarHeight                    = 0;
	_matteVar2                         = 0;
}

//////////////////////////////////////////////////////////////////////////
// Saved scene data
//////////////////////////////////////////////////////////////////////////
void SharedData::saveCursorResources(ResourceId *resources, uint32 size) {
	memcpy((ResourceId *)&_cursorResources, resources, size);
}

void SharedData::loadCursorResources(ResourceId *resources, uint32 size) const {
	memcpy(resources, (const ResourceId *)&_cursorResources, size);
}

void SharedData::saveSceneFonts(ResourceId font1, ResourceId font2, ResourceId font3) {
	_sceneFonts[0] = font1;
	_sceneFonts[1] = font2;
	_sceneFonts[2] = font3;
}

void SharedData::loadSceneFonts(ResourceId *font1, ResourceId *font2, ResourceId *font3) const {
	*font1 = _sceneFonts[0];
	*font2 = _sceneFonts[1];
	*font3 = _sceneFonts[2];
}

void SharedData::saveSmallCursor(int32 smallCurUp, int32 smallCurDown) {
	_smallCurUp = smallCurUp;
	_smallCurDown = smallCurDown;
}

void SharedData::loadSmallCursor(int32 *smallCurUp, int32 *smallCurDown) const {
	*smallCurUp = _smallCurUp;
	*smallCurDown = _smallCurDown;
}

//////////////////////////////////////////////////////////////////////////
// Chapter 2 data
//////////////////////////////////////////////////////////////////////////
void SharedData::resetChapter2Data() {
	for (int i = 0; i < 9; i++) {
		crowsData[i + 11] = 160;
		crowsData[i + 39] = 0;
		crowsData[i + 73] = 0;
	}
}

void SharedData::reset() {
	for (int i = 0; i < 9; i++)
		crowsData[i + 11] = 160;

	_chapter2FrameIndexOffset = 1;
}

//static const uint32 chapter2DataSizes[5] = {5, 9, 23, 18, 9};
int32 &CrowsData::operator[](uint32 index) {
	if (index >= ARRAYSIZE(_data))
		error("[CrowsData::operator[]] Invalid index (was: %d, valid: [0;%d])", index, ARRAYSIZE(_data) - 1);

	// TODO use _chapter2Data*[] instead of a dedicated array
	return _data[index];
}

void SharedData::setChapter2Counter(uint32 index, int32 val) {
	if (index == 0 || index > 8)
		error("[SharedData::setChapter2Counter] Invalid index (was: %d, valid: [1;8])", index);

	_chapter2Counters[index - 1] = val;
}

int32 SharedData::getChapter2Counter(uint32 index) const {
	if (index == 0 || index > 8)
		error("[SharedData::setChapter2Counter] Invalid index (was: %d, valid: [1;8])", index);

	return _chapter2Counters[index - 1];
}

//////////////////////////////////////////////////////////////////////////
// Ambient sounds
//////////////////////////////////////////////////////////////////////////
uint32 SharedData::getAmbientTick(uint32 index) const {
	if (index >= ARRAYSIZE(_ambientTicks))
		error("[SharedData::getAmbientTick] index is outside valid values (was: %d, valid: [0:%d]", index, ARRAYSIZE(_ambientTicks));

	return _ambientTicks[index];
}

void SharedData::setAmbientTick(uint32 index, uint32 val) {
	if (index >= ARRAYSIZE(_ambientTicks))
		error("[SharedData::setAmbientTick] index is outside valid values (was: %d, valid: [0:%d]", index, ARRAYSIZE(_ambientTicks));

	_ambientTicks[index] = val;
}

uint32 SharedData::getAmbientFlag(uint32 index) const {
	if (index >= ARRAYSIZE(_ambientFlags))
		error("[SharedData::getAmbientFlag] index is outside valid values (was: %d, valid: [0:%d]", index, ARRAYSIZE(_ambientFlags));

	return _ambientFlags[index];
}

void SharedData::setAmbientFlag(uint32 index, uint32 val) {
	if (index >= ARRAYSIZE(_ambientFlags))
		error("[SharedData::setAmbientFlag] index is outside valid values (was: %d, valid: [0:%d]", index, ARRAYSIZE(_ambientFlags));

	_ambientFlags[index] = val;
}

void SharedData::resetAmbientFlags() {
	memset(&_ambientFlags, 0, sizeof(_ambientFlags));
}

//////////////////////////////////////////////////////////////////////////
// Flags
//////////////////////////////////////////////////////////////////////////
bool SharedData::getFlag(GlobalFlag flag) const {
	switch (flag) {
	default:
		error("[SharedData::getFlag] Invalid flag type (%d)!", flag);

	case kFlag1:
		return _flag1;

	case kFlag2:
		return _flag2;

	case kFlag3:
		return _flag3;

	case kFlagRedraw:
		return _flagRedraw;

	case kFlagSkipDrawScene:
		return _flagSkipDrawScene;

	case kFlagSceneRectChanged:
		error("[SharedData::getFlag] Invalid flag type (kFlagSceneRectChanged)!");

	case kFlagScene1:
		return _flagScene1;

	case kFlagSkipScriptProcessing:
		return _flagSkipScriptProcessing;

	case kFlagIsEncounterRunning:
		return _flagIsEncounterRunning;

	case kFlagEncounterDisablePlayerOnExit:
		return _flagEncounterDisablePlayerOnExit;

	case kFlagActorUpdateEnabledCheck:
		return _flagActorUpdateEnabledCheck;

	case kFlagActorUpdateStatus15Check:
		return _flagActorUpdateStatus15Check;
	}
}

void SharedData::setFlag(GlobalFlag flag, bool state) {
	switch (flag) {
	default:
		error("[SharedData::setFlag] Invalid flag type (%d)!", flag);

	case kFlag1:
		_flag1 = state;
		break;

	case kFlag2:
		_flag2 = state;
		break;

	case kFlag3:
		_flag3 = state;
		break;

	case kFlagRedraw:
		_flagRedraw = state;
		break;

	case kFlagSkipDrawScene:
		_flagSkipDrawScene = state;
		break;

	case kFlagSceneRectChanged:
		warning("[SharedData::setFlag] Invalid flag type (kFlagSceneRectChanged)!");
		break;

	case kFlagScene1:
		_flagScene1 = state;
		break;

	case kFlagSkipScriptProcessing:
		_flagSkipScriptProcessing = state;
		break;

	case kFlagIsEncounterRunning:
		_flagIsEncounterRunning = state;
		break;

	case kFlagEncounterDisablePlayerOnExit:
		_flagEncounterDisablePlayerOnExit = state;
		break;

	case kFlagActorUpdateEnabledCheck:
		_flagActorUpdateEnabledCheck = state;
		break;

	case kFlagActorUpdateStatus15Check:
		_flagActorUpdateStatus15Check = state;
		break;
	}
}

//////////////////////////////////////////////////////////////////////////
// Serializer
//////////////////////////////////////////////////////////////////////////
void SharedData::saveLoadAmbientSoundData(Common::Serializer &s) {
	// Ambient sound flags/ticks
	for (uint32 i = 0; i < ARRAYSIZE(_ambientFlags); i++)
		s.syncAsUint32LE(_ambientFlags[i]);

	for (uint32 i = 0; i < ARRAYSIZE(_ambientTicks); i++)
		s.syncAsUint32LE(_ambientTicks[i]);
}

void SharedData::saveLoadWithSerializer(Common::Serializer &s) {
	debugC(kDebugLevelSavegame, "[SharedData::saveLoadWithSerializer] Saving Chapter 2 actor data is not implemented");

	// Global coordinates (original uses int32 for coordinates)
	s.syncAsSint32LE(_globalPoint.x);
	s.syncAsSint32LE(_globalPoint.y);

	// Processing of scripts/encounter
	s.syncAsUint32LE(_flagSkipScriptProcessing);
	s.syncAsUint32LE(_flagIsEncounterRunning);

	// Player index
	s.syncAsSint32LE(_playerIndex);

	// Scene coordinates
	s.syncAsSint32LE(_sceneCoords.x);
	s.syncAsSint32LE(_sceneCoords.y);
	s.syncAsSint32LE(_sceneOffset);
	s.syncAsSint32LE(_sceneOffsetAdd);

	// Original skips 4 bytes
	s.skip(4);

	// Cursor resources
	for (uint32 i = 0; i < ARRAYSIZE(_cursorResources); i++)
		s.syncAsUint32LE(_cursorResources[i]);

	// Fonts
	for (uint32 i = 0; i < ARRAYSIZE(_sceneFonts); i++)
		s.syncAsUint32LE(_sceneFonts[i]);

	// Chapter 2 actor data (Part 1)
	for (uint32 i = 0; i < ARRAYSIZE(_chapter2Data1); i++)
		s.syncAsUint32LE(_chapter2Data1[i]);

	// Scene information
	s.syncAsSint32LE(_smallCurUp);
	s.syncAsSint32LE(_smallCurDown);
	s.syncAsSint32LE(_encounterFrameBg);
	s.syncAsUint32LE(_flagSkipDrawScene);
	s.syncAsSint32LE(_matteVar1);
	s.syncAsUint32LE(_flagActorUpdateEnabledCheck);
	s.syncAsUint32LE(_matteInitialized);
	s.syncAsUint32LE(_mattePlaySound);
	s.syncAsSint32LE(_currentScreenUpdatesCount);

	// Chapter 2 actor data (Part 2)
	for (uint32 i = 0; i < ARRAYSIZE(_chapter2Data2); i++)
		s.syncAsUint32LE(_chapter2Data2[i]);

	// Chapter 2 counters (1-4)
	s.syncAsSint32LE(_chapter2Counters[0]);
	s.syncAsSint32LE(_chapter2Counters[1]);
	s.syncAsSint32LE(_chapter2Counters[2]);
	s.syncAsSint32LE(_chapter2Counters[3]);

	// Chapter 2 actor data (Part 3)
	for (uint32 i = 0; i < ARRAYSIZE(_chapter2Data3); i++)
		s.syncAsUint32LE(_chapter2Data3[i]);

	// Chapter 2 counter (5) and other data
	s.syncAsSint32LE(_chapter2Counters[4]);
	s.syncAsSint32LE(_chapter2FrameIndexOffset);
	s.syncAsSint32LE(_chapter2ActorIndex);

	s.syncAsSint32LE(_eventUpdate);

	// Chapter 2 counters (6-8)
	s.syncAsSint32LE(_chapter2Counters[5]);
	s.syncAsSint32LE(_chapter2Counters[6]);
	s.syncAsSint32LE(_chapter2Counters[7]);

	// Chapter 2 actor data (Part 4)
	for (uint32 i = 0; i < ARRAYSIZE(_chapter2Data4); i++)
		s.syncAsUint32LE(_chapter2Data4[i]);

	// Actor UpdateStatusEnabled Counter
	s.syncAsSint32LE(_actorUpdateStatusEnabledCounter);

	// Chapter2 actor data (part 5)
	for (uint32 i = 0; i < ARRAYSIZE(_chapter2Data5); i++)
		s.syncAsUint32LE(_chapter2Data5[i]);

	// Encounter disable player on exit
	s.syncAsUint32LE(_flagEncounterDisablePlayerOnExit);

	// Scene flag 1
	s.syncAsUint32LE(_flagScene1);

	// Next screen update
	s.syncAsUint32LE(_nextScreenUpdate);

	// Viewed movies
	// (we load it directly from an external file, the original overwrites the data with the one from the external file)
	s.skip(196);

	// Actor update status 15 check
	s.syncAsUint32LE(_flagActorUpdateStatus15Check);
}

} // End of namespace Asylum