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