ScummVM API documentation
toon.h
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 modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (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, see <http://www.gnu.org/licenses/>.
19  *
20  *
21  * This file is dual-licensed.
22  * In addition to the GPLv3 license mentioned above, MojoTouch has
23  * exclusively licensed this code on March 23th, 2024, to be used in
24  * closed-source products.
25  * Therefore, any contributions (commits) to it will also be dual-licensed.
26  *
27  */
28 
29 #ifndef TOON_TOON_H
30 #define TOON_TOON_H
31 
32 #include "engines/engine.h"
33 #include "graphics/surface.h"
34 #include "common/random.h"
35 #include "common/error.h"
36 #include "toon/resource.h"
37 #include "toon/script.h"
38 #include "toon/script_func.h"
39 #include "toon/state.h"
40 #include "toon/picture.h"
41 #include "toon/anim.h"
42 #include "toon/movie.h"
43 #include "toon/font.h"
44 #include "toon/text.h"
45 #include "toon/audio.h"
46 #include "toon/console.h"
47 
48 namespace Common {
49 class MemoryWriteStreamDynamic;
50 }
51 
52 struct ADGameDescription;
53 
54 #define TOON_DAT_VER_MAJ 0 // 1 byte
55 #define TOON_DAT_VER_MIN 4 // 1 byte
56 #define TOON_SAVEGAME_VERSION 6
57 #define DATAALIGNMENT 4
58 #define MAX_SAVE_SLOT 99
59 
60 #define TOON_SCREEN_WIDTH 640
61 #define TOON_SCREEN_HEIGHT 400
62 #define TOON_BACKBUFFER_WIDTH 1280
63 #define TOON_BACKBUFFER_HEIGHT 400
64 
73 namespace Toon {
74 
75 enum ToonGameType {
76  GType_TOON = 1
77 };
78 
79 enum ToonDebugChannels {
80  kDebugAnim = 1 << 0,
81  kDebugCharacter = 1 << 1,
82  kDebugAudio = 1 << 2,
83  kDebugHotspot = 1 << 3,
84  kDebugFont = 1 << 4,
85  kDebugPath = 1 << 5,
86  kDebugMovie = 1 << 6,
87  kDebugPicture = 1 << 7,
88  kDebugResource = 1 << 8,
89  kDebugState = 1 << 9,
90  kDebugTools = 1 << 10,
91  kDebugText = 1 << 11
92 };
93 
94 class Picture;
95 class Movie;
96 class Hotspots;
97 class Character;
98 class CharacterDrew;
99 class CharacterFlux;
100 class FontRenderer;
101 class TextResource;
102 class AudioManager;
103 class PathFinding;
104 
105 class ToonEngine : public Engine {
106 public:
107  ToonEngine(OSystem *syst, const ADGameDescription *gameDescription);
108  ~ToonEngine() override;
109 
110  const ADGameDescription *_gameDescription;
111  Common::Language _language;
112  byte _numVariant;
113  byte _gameVariant;
114  char **_locationDirNotVisited;
115  char **_locationDirVisited;
116  char **_specialInfoLine;
117 
118  Common::Error run() override;
119  bool showMainMenu(bool &loadedGame);
120  bool showOptions();
121  bool showQuitConfirmationDialogue();
122  void init();
123  bool loadToonDat();
124  char **loadTextsVariants(Common::File &in);
125  void unloadTextsVariants(char **texts);
126  void unloadToonDat();
127  void setPaletteEntries(uint8 *palette, int32 offset, int32 num);
128  void fixPaletteEntries(uint8 *palette, int num);
129  void flushPalette(bool deferFlushToNextRender = true);
130  void parseInput();
131  void initChapter();
132  void initFonts();
133  void setFont(bool alternative);
134  void loadScene(int32 SceneId, bool forGameLoad = false);
135  void exitScene();
136  void loadCursor();
137  void setCursor(int32 type, bool inventory = false, int32 offsetX = 0, int offsetY = 0);
138  void loadAdditionalPalette(const Common::Path &fileName, int32 mode);
139  void setupGeneralPalette();
140  void render();
141  void update(int32 timeIncrement);
142  void doFrame();
143  void updateAnimationSceneScripts(int32 timeElapsed);
144  void updateCharacters(int32 timeElapsed);
145  void setSceneAnimationScriptUpdate(bool enable);
146  bool isUpdatingSceneAnimation();
147  int32 getCurrentUpdatingSceneAnimation();
148  int32 randRange(int32 minStart, int32 maxStart);
149  void selectHotspot();
150  void clickEvent();
151  int32 runEventScript(int32 x, int32 y, int32 mode, int32 id, int32 scriptId);
152  void flipScreens();
153  void drawInfoLine();
154  void drawConversationLine();
155  const char *getLocationString(int32 locationId, bool alreadyVisited);
156  int32 getScaleAtPoint(int32 x, int32 y);
157  int32 getZAtPoint(int32 x, int32 y);
158  int32 getLayerAtPoint(int32 x, int32 y);
159  int32 characterTalk(int32 dialogid, bool blocking = true);
160  int32 simpleCharacterTalk(int32 dialogid);
161  void sayLines(int numLines, int dialogId);
162  void haveAConversation(int32 convId);
163  void processConversationClick(Conversation *conv, int32 status);
164  int32 runConversationCommand(int16 **command);
165  void prepareConversations();
166  void drawConversationIcons();
167  void simpleUpdate(bool waitCharacterToTalk = false);
168  int32 waitTicks(int32 numTicks, bool breakOnMouseClick);
169  void copyToVirtualScreen(bool updateScreen = true);
170  void getMouseEvent();
171  int32 showInventory();
172  void drawSack();
173  void addItemToInventory(int32 item);
174  void deleteItemFromInventory(int32 item);
175  void replaceItemFromInventory(int32 item, int32 destItem);
176  void rearrangeInventory();
177  void createMouseItem(int32 item);
178  void deleteMouseItem();
179  void showCutaway(const Common::Path &cutawayPicture);
180  void hideCutaway();
181  void drawPalette();
182  void newGame();
183  void playSoundWrong();
184  void playSFX(int32 id, int32 volume);
185  void storeRifFlags(int32 location);
186  void restoreRifFlags(int32 location);
187  void getTextPosition(int32 characterId, int32 *retX, int32 *retY);
188  int32 getConversationFlag(int32 locationId, int32 param);
189  int32 getSpecialInventoryItem(int32 item);
190  Character *getCharacterById(int32 charId);
191  Common::String getSavegameName(int nr);
192  bool loadGame(int32 slot);
193  bool saveGame(int32 slot, const Common::String &saveGameDesc);
194  void fadeIn(int32 numFrames);
195  void fadeOut(int32 numFrames);
196  void initCharacter(int32 characterId, int32 animScriptId, int32 animToPlayId, int32 sceneAnimationId);
197  int32 handleInventoryOnFlux(int32 itemId);
198  int32 handleInventoryOnInventory(int32 itemDest, int32 itemSrc);
199  int32 handleInventoryOnDrew(int32 itemId);
200  int32 pauseSceneAnimationScript(int32 animScriptId, int32 tickToWait);
201  void updateTimer(int32 timeIncrement);
202  Common::Path createRoomFilename(const Common::String &name);
203  void createShadowLUT();
204  void playTalkAnimOnCharacter(int32 animID, int32 characterId, bool talker);
205  void updateScrolling(bool force, int32 timeIncrement);
206  void enableTimer(int32 timerId);
207  void setTimer(int32 timerId, int32 timerWait);
208  void disableTimer(int32 timerId);
209  void updateTimers();
210  void makeLineNonWalkable(int32 x, int32 y, int32 x2, int32 y2);
211  void makeLineWalkable(int32 x, int32 y, int32 x2, int32 y2);
212  void renderInventory();
213  void viewInventoryItem(const Common::Path &str, int32 lineId, int32 itemDest);
214  void storePalette();
215  void restorePalette();
216  const char *getSpecialConversationMusic(int32 locationId);
217  void playRoomMusic();
218  void waitForScriptStep();
219  void doMagnifierEffect();
220  void drawCustomText(int16 x, int16 y, const char *line, Graphics::Surface *frame, byte color);
221  bool showConversationText() const;
222  bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override;
223  bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override;
224  void pauseEngineIntern(bool pause) override;
225  void syncSoundSettings() override;
226 
227  Resources *resources() {
228  return _resources;
229  }
230 
231  State *state() {
232  return _gameState;
233  }
234 
235  Graphics::Surface &getMainSurface() {
236  return *_mainSurface;
237  }
238 
239  Picture *getMask() {
240  return _currentMask;
241  }
242 
243  Picture *getPicture() {
244  return _currentPicture;
245  }
246 
247  AnimationManager *getAnimationManager() {
248  return _animationManager;
249  }
250 
251  Movie *getMoviePlayer() {
252  return _moviePlayer;
253  }
254 
255  SceneAnimation *getSceneAnimation(int32 id) {
256  return &_sceneAnimations[id];
257  }
258 
259  SceneAnimationScript *getSceneAnimationScript(int32 id) {
260  return &_sceneAnimationScripts[id];
261  }
262 
263  EMCInterpreter *getScript() {
264  return _script;
265  }
266 
267  Hotspots *getHotspots() {
268  return _hotspots;
269  }
270 
271  Character *getCharacter(int32 charId) {
272  return _characters[charId];
273  }
274 
275  uint8 *getShadowLUT() {
276  return _shadowLUT;
277  }
278 
279  int32 getCurrentLineToSay() {
280  return _currentTextLineId;
281  }
282 
283  int32 getCurrentCharacterTalking() {
284  return _currentTextLineCharacterId;
285  }
286 
287  CharacterDrew *getDrew() {
288  return (CharacterDrew *)_drew;
289  }
290 
291  CharacterFlux *getFlux() {
292  return (CharacterFlux *)_flux;
293  }
294 
295  int32 getTickLength() {
296  return _tickLength;
297  }
298 
299  int32 getOldMilli() {
300  return _oldTimer2;
301  }
302 
303  AudioManager *getAudioManager() {
304  return _audioManager;
305  }
306 
307  int32 getScriptRegionNested() {
308  return _currentScriptRegion;
309  }
310 
311  int32 getMouseX() {
312  return _mouseX;
313  }
314 
315  int32 getMouseY() {
316  return _mouseY;
317  }
318 
319  PathFinding *getPathFinding() {
320  return _pathFinding;
321  }
322 
323  bool isEnglishDemo() {
324  return _isEnglishDemo;
325  }
326 
327  Common::WriteStream *getSaveBufferStream();
328 
329  bool shouldQuitGame() const {
330  return _shouldQuit;
331  }
332 
333  Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave = false) override {
334  return (saveGame(slot, desc) ? Common::kNoError : Common::kWritingFailed);
335  }
336 
337  Common::Error loadGameState(int slot) override {
338  return (loadGame(slot) ? Common::kNoError : Common::kReadingFailed);
339  }
340 
341  bool hasFeature(EngineFeature f) const override {
342  return
343  (f == kSupportsSubtitleOptions) ||
344  (f == kSupportsReturnToLauncher) ||
345  (f == kSupportsLoadingDuringRuntime) ||
346  (f == kSupportsSavingDuringRuntime);
347  }
348 
349  void dirtyAllScreen();
350  void addDirtyRect(int32 left, int32 top, int32 right, int32 bottom);
351  void clearDirtyRects();
352 
353 protected:
354  int32 _tickLength;
355  Resources *_resources;
356  TextResource *_genericTexts;
357  TextResource *_roomTexts;
358  State *_gameState;
359  uint8 *_finalPalette;
360  uint8 *_backupPalette;
361  uint8 *_additionalPalette1;
362  uint8 *_additionalPalette2;
363  bool _additionalPalette2Present;
364  uint8 *_cutawayPalette;
365  uint8 *_universalPalette;
366  uint8 *_fluxPalette;
367  uint8 *_roomScaleData;
368  uint8 *_shadowLUT;
369 
370  Picture *_currentPicture;
371  Picture *_currentMask;
372  Picture *_currentCutaway;
373  Picture *_inventoryPicture;
374  PathFinding *_pathFinding;
375 
376  EMCInterpreter *_script;
377  EMCData _scriptData;
378  EMCState _scriptState[4];
379  int32 _currentScriptRegion; // script region ( nested script run )
380 
381  ScriptFunc *_script_func;
382 
383  SceneAnimation _sceneAnimations[64];
384  SceneAnimationScript _sceneAnimationScripts[64];
385  int32 _lastProcessedSceneScript;
386  bool _animationSceneScriptRunFlag;
387  bool _updatingSceneScriptRunFlag;
388 
389  Graphics::Surface *_mainSurface;
390  Common::Array<Common::Rect> _dirtyRects;
391  Common::Array<Common::Rect> _oldDirtyRects;
392 
393  bool _dirtyAll;
394 
395 
396  AnimationInstance *_cursorAnimationInstance;
397  Animation *_cursorAnimation;
398  Animation *_dialogIcons;
399  Animation *_inventoryIcons;
400  Animation *_inventoryIconSlots;
401  int32 _cursorOffsetX;
402  int32 _cursorOffsetY;
403 
404  char *_currentTextLine;
405  int32 _currentTextLineId;
406  int32 _currentTextLineX;
407  int32 _currentTextLineY;
408  int32 _currentTextLineCharacterId;
409 
410  int32 _oldScrollValue;
411 
412  AnimationManager *_animationManager;
413 
414  Character *_characters[32];
415  Character *_drew;
416  Character *_flux;
417 
418  Hotspots *_hotspots;
419  int32 _currentHotspotItem;
420 
421  bool _shouldQuit;
422  int32 _scriptStep;
423 
424  int32 _mouseX;
425  int32 _mouseY;
426  int32 _mouseButton;
427  int32 _lastMouseButton;
428 
429  int32 _oldTimer;
430  int32 _oldTimer2;
431  int32 _lastRenderTime;
432 
433  Movie *_moviePlayer;
434 
436 
437  FontRenderer *_fontRenderer;
438  Animation *_fontToon;
439  Animation *_fontEZ;
440  Animation *_currentFont;
441  Common::String *_currentDemoFont;
442 
443  AudioManager *_audioManager;
444 
445  Common::MemoryWriteStreamDynamic *_saveBufferStream;
446 
447  int16 *_conversationData;
448 
449  bool _firstFrame;
450  bool _isDemo;
451  bool _isEnglishDemo;
452  bool _showConversationText;
453  int _textSpeed;
454  bool _useAlternativeFont;
455  bool _needPaletteFlush;
456  bool _noMusicDriver; // If "Music Device" is set to "No Music" from Audio tab
457 };
458 
459 } // End of namespace Toon
460 
461 #endif
Definition: anim.h:193
Definition: flux.h:38
Definition: str.h:59
Definition: surface.h:66
Failed to read a file (permission denied?).
Definition: error.h:62
EngineFeature
Definition: engine.h:250
Definition: stream.h:77
Definition: error.h:84
Definition: conversation.h:37
Definition: script.h:44
Definition: advancedDetector.h:120
Definition: random.h:44
Definition: state.h:52
No error occurred.
Definition: error.h:48
Definition: memstream.h:194
Definition: path.h:52
Definition: anim.h:181
Definition: script_func.h:41
Common::Error loadGameState(int slot) override
Definition: toon.h:337
bool hasFeature(EngineFeature f) const override
Definition: toon.h:341
Definition: toon.h:105
Definition: movie.h:54
Definition: resource.h:80
Definition: ustr.h:57
Definition: file.h:47
Definition: anim.h:164
Definition: algorithm.h:29
Definition: text.h:36
Definition: drew.h:38
Definition: audio.h:131
Definition: font.h:38
Definition: anim.h:39
Definition: hotspot.h:54
Definition: script.h:55
Definition: anim.h:95
Definition: system.h:167
Definition: character.h:58
Failure to write data - disk full?
Definition: error.h:63
Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave=false) override
Definition: toon.h:333
Definition: engine.h:143
Definition: path.h:64
Definition: picture.h:43
Definition: script.h:100
Definition: anim.h:54
Language
Definition: language.h:45