aboutsummaryrefslogtreecommitdiff
path: root/engines/toon/toon.h
blob: f3370aed5e409e505ba519728484c4ab22dc2910 (plain)
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
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
/* 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 2
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* $URL$
* $Id$
*
*/

#ifndef TOON_TOON_H
#define TOON_TOON_H

#include "engines/advancedDetector.h"
#include "engines/engine.h"
#include "graphics/surface.h"
#include "common/random.h"
#include "common/error.h"
#include "toon/resource.h"
#include "toon/script.h"
#include "toon/script_func.h"
#include "toon/state.h"
#include "toon/picture.h"
#include "toon/anim.h"
#include "toon/movie.h"
#include "toon/font.h"
#include "toon/text.h"
#include "toon/audio.h"
#include "toon/console.h"

namespace Common {
class MemoryWriteStreamDynamic;
}

#define TOON_DAT_VER_MAJ 0  // 1 byte
#define TOON_DAT_VER_MIN 3  // 1 byte
#define TOON_SAVEGAME_VERSION 4
#define DATAALIGNMENT 4

/**
 * This is the namespace of the Toon engine.
 *
 * Status of this engine: ???
 *
 * Games using this engine:
 * - Toonstruck
 */
namespace Toon {

enum ToonGameType {
	GType_TOON = 1
};

enum ToonDebugChannels {
	kDebugAnim      = 1 <<  0,
	kDebugCharacter = 1 <<  1,
	kDebugAudio     = 1 <<  2,
	kDebugHotspot   = 1 <<  3,
	kDebugFont      = 1 <<  4,
	kDebugPath      = 1 <<  5,
	kDebugMovie     = 1 <<  6,
	kDebugPicture   = 1 <<  7,
	kDebugResource  = 1 <<  8,
	kDebugState     = 1 <<  9,
	kDebugTools     = 1 << 10,
	kDebugText      = 1 << 11
};

class Picture;
class Movie;
class Hotspots;
class Character;
class CharacterDrew;
class CharacterFlux;
class FontRenderer;
class TextResource;
class AudioManager;
class PathFinding;

class ToonEngine : public Engine {
public:
	ToonEngine(OSystem *syst, const ADGameDescription *gameDescription);
	~ToonEngine();

	const ADGameDescription *_gameDescription;
	Common::Language _language;
	byte   _numVariant;
	byte   _gameVariant;
	char **_locationDirNotVisited;
	char **_locationDirVisited;
	char **_specialInfoLine;

	Common::Error run();
	GUI::Debugger *getDebugger() { return _console; }
	bool showMainmenu(bool &loadedGame);
	void init();
	bool loadToonDat();
	char **loadTextsVariants(Common::File &in);
	void unloadTextsVariants(char **texts);
	void unloadToonDat();
	void setPaletteEntries(uint8 *palette, int32 offset, int32 num);
	void fixPaletteEntries(uint8 *palette, int num);
	void flushPalette(bool deferFlushToNextRender = true);
	void parseInput();
	void initChapter();
	void initFonts();
	void loadScene(int32 SceneId, bool forGameLoad = false);
	void exitScene();
	void loadCursor();
	void setCursor(int32 type, bool inventory = false, int32 offsetX = 0, int offsetY = 0);
	void loadAdditionalPalette(Common::String fileName, int32 mode);
	void setupGeneralPalette();
	void render();
	void update(int32 timeIncrement);
	void doFrame();
	void updateAnimationSceneScripts(int32 timeElapsed);
	void updateCharacters(int32 timeElapsed);
	void setSceneAnimationScriptUpdate(bool enable);
	bool isUpdatingSceneAnimation();
	int32 getCurrentUpdatingSceneAnimation();
	int32 randRange(int32 minStart, int32 maxStart);
	void selectHotspot();
	void clickEvent();
	int32 runEventScript(int32 x, int32 y, int32 mode, int32 id, int32 scriptId);
	void flipScreens();
	void drawInfoLine();
	void drawConversationLine();
	const char *getLocationString(int32 locationId, bool alreadyVisited);
	int32 getScaleAtPoint(int32 x, int32 y);
	int32 getZAtPoint(int32 x, int32 y);
	int32 getLayerAtPoint(int32 x, int32 y);
	int32 characterTalk(int32 dialogid, bool blocking = true);
	int32 simpleCharacterTalk(int32 dialogid);
	void sayLines(int numLines, int dialogId);
	void haveAConversation(int32 convId);
	void processConversationClick(Conversation *conv, int32 status);
	int32 runConversationCommand(int16 **command);
	void prepareConversations();
	void drawConversationIcons();
	void simpleUpdate(bool waitCharacterToTalk = false);
	int32 waitTicks(int32 numTicks, bool breakOnMouseClick);
	void copyToVirtualScreen(bool updateScreen = true);
	void getMouseEvent();
	int32 showInventory();
	void drawSack();
	void addItemToInventory(int32 item);
	void deleteItemFromInventory(int32 item);
	void replaceItemFromInventory(int32 item, int32 destItem);
	void rearrangeInventory();
	void createMouseItem(int32 item);
	void deleteMouseItem();
	void showCutaway(Common::String cutawayPicture);
	void hideCutaway();
	void drawPalette();
	void newGame();
	void playSoundWrong();
	void playSFX(int32 id, int32 volume);
	void storeRifFlags(int32 location);
	void restoreRifFlags(int32 location);
	void getTextPosition(int32 characterId, int32 *retX, int32 *retY);
	int32 getConversationFlag(int32 locationId, int32 param);
	int32 getSpecialInventoryItem(int32 item);
	Character *getCharacterById(int32 charId);
	Common::String getSavegameName(int nr);
	bool loadGame(int32 slot);
	bool saveGame(int32 slot, Common::String saveGameDesc);
	void fadeIn(int32 numFrames);
	void fadeOut(int32 numFrames);
	void initCharacter(int32 characterId, int32 animScriptId, int32 animToPlayId, int32 sceneAnimationId);
	int32 handleInventoryOnFlux(int32 itemId);
	int32 handleInventoryOnInventory(int32 itemDest, int32 itemSrc);
	int32 handleInventoryOnDrew(int32 itemId);
	int32 pauseSceneAnimationScript(int32 animScriptId, int32 tickToWait);
	void updateTimer(int32 timeIncrement);
	Common::String createRoomFilename(Common::String name);
	void createShadowLUT();
	void playTalkAnimOnCharacter(int32 animID, int32 characterId, bool talker);
	void updateScrolling(bool force, int32 timeIncrement);
	void enableTimer(int32 timerId);
	void setTimer(int32 timerId, int32 timerWait);
	void disableTimer(int32 timerId);
	void updateTimers();
	void makeLineNonWalkable(int32 x, int32 y, int32 x2, int32 y2);
	void makeLineWalkable(int32 x, int32 y, int32 x2, int32 y2);
	void renderInventory();
	void viewInventoryItem(Common::String str, int32 lineId, int32 itemDest);
	void storePalette();
	void restorePalette();
	const char *getSpecialConversationMusic(int32 locationId); 
	void playRoomMusic();
	void waitForScriptStep();
	void doMagnifierEffect();



	bool canSaveGameStateCurrently();
	bool canLoadGameStateCurrently();
	void pauseEngineIntern(bool pause);

	Resources *resources() {
		return _resources;
	}

	State *state() {
		return _gameState;
	}

	Graphics::Surface &getMainSurface() {
		return *_mainSurface;
	}

	Picture *getMask() {
		return _currentMask;
	}

	Picture *getPicture() {
		return _currentPicture;
	}

	AnimationManager *getAnimationManager() {
		return _animationManager;
	}

	Movie *getMoviePlayer() {
		return _moviePlayer;
	}

	SceneAnimation *getSceneAnimation(int32 id) {
		return &_sceneAnimations[id];
	}

	SceneAnimationScript *getSceneAnimationScript(int32 id) {
		return &_sceneAnimationScripts[id];
	}

	EMCInterpreter *getScript() {
		return _script;
	}

	Hotspots *getHotspots() {
		return _hotspots;
	}

	Character *getCharacter(int32 charId) {
		return _characters[charId];
	}

	uint8 *getShadowLUT() {
		return _shadowLUT;
	}

	int32 getCurrentLineToSay() {
		return _currentTextLineId;
	}

	int32 getCurrentCharacterTalking() {
		return _currentTextLineCharacterId;
	}

	CharacterDrew *getDrew() {
		return (CharacterDrew *)_drew;
	}

	CharacterFlux *getFlux() {
		return (CharacterFlux *)_flux;
	}

	int32 getTickLength() {
		return _tickLength;
	}

	int32 getOldMilli() {
		return _oldTimer2;
	}

	OSystem *getSystem() {
		return _system;
	}

	AudioManager *getAudioManager() {
		return _audioManager;
	}

	int32 getScriptRegionNested() {
		return _currentScriptRegion;
	}

	int32 getMouseX() {
		return _mouseX;
	}

	int32 getMouseY() {
		return _mouseY;
	}

	PathFinding *getPathFinding() {
		return _pathFinding;
	}

	Common::WriteStream *getSaveBufferStream();

	bool shouldQuitGame() const {
		return _shouldQuit;
	}

	Common::Error saveGameState(int slot, const char *desc) {
		
		return (saveGame(slot, desc) ? Common::kWritingFailed : Common::kNoError);
	}

	Common::Error loadGameState(int slot) {
		return (loadGame(slot) ? Common::kReadingFailed : Common::kNoError);
	}

	bool hasFeature(EngineFeature f) const {
		return
			(f == kSupportsRTL) ||
			(f == kSupportsLoadingDuringRuntime) ||
			(f == kSupportsSavingDuringRuntime);
	}

protected:
	OSystem *_system;
	int32 _tickLength;
	Resources *_resources;
	TextResource *_genericTexts;
	TextResource *_roomTexts;
	State *_gameState;
	uint8 *_finalPalette;
	uint8 *_backupPalette;
	uint8 *_additionalPalette1;
	uint8 *_additionalPalette2;
	uint8 *_cutawayPalette;
	uint8 *_universalPalette;
	uint8 *_fluxPalette;
	uint8 *_roomScaleData;
	uint8 *_shadowLUT;

	Picture *_currentPicture;
	Picture *_currentMask;
	Picture *_currentCutaway;
	Picture *_inventoryPicture;
	PathFinding *_pathFinding;

	EMCInterpreter *_script;
	EMCData _scriptData;
	EMCState _scriptState[4];
	int32 _currentScriptRegion; // script region ( nested script run )

	ScriptFunc *_script_func;

	SceneAnimation _sceneAnimations[64];
	SceneAnimationScript _sceneAnimationScripts[64];
	int32 _lastProcessedSceneScript;
	bool _animationSceneScriptRunFlag;
	bool _updatingSceneScriptRunFlag;

	Graphics::Surface *_mainSurface;

	AnimationInstance *_cursorAnimationInstance;
	Animation *_cursorAnimation;
	Animation *_dialogIcons;
	Animation *_inventoryIcons;
	Animation *_inventoryIconSlots;
	int32 _cursorOffsetX;
	int32 _cursorOffsetY;

	char *_currentTextLine;
	int32 _currentTextLineId;
	int32 _currentTextLineX;
	int32 _currentTextLineY;
	int32 _currentTextLineCharacterId;

	int32 _oldScrollValue;

	AnimationManager *_animationManager;

	Character *_characters[32];
	Character *_drew;
	Character *_flux;

	Hotspots *_hotspots;
	int32 _currentHotspotItem;

	bool _shouldQuit;
	int32 _scriptStep;

	int32 _mouseX;
	int32 _mouseY;
	int32 _mouseButton;
	int32 _lastMouseButton;

	int32 _oldTimer;
	int32 _oldTimer2;
	int32 _lastRenderTime;

	Movie *_moviePlayer;

	Common::RandomSource _rnd;

	FontRenderer *_fontRenderer;
	Animation *_fontToon;
	Animation *_fontEZ;

	AudioManager *_audioManager;

	Common::MemoryWriteStreamDynamic *_saveBufferStream;

	int16 *_conversationData;

	bool _firstFrame;
	bool _isDemo;
	bool _showConversationText;
	bool _needPaletteFlush;
private:
	ToonConsole *_console;
};

} // End of namespace Toon

#endif