ScummVM API documentation
tot.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
22#ifndef TOT_H
23#define TOT_H
24
25#include "common/error.h"
26#include "common/events.h"
27#include "common/fs.h"
28#include "common/hash-str.h"
29#include "common/memstream.h"
30#include "common/random.h"
31#include "common/scummsys.h"
32#include "common/serializer.h"
33#include "common/system.h"
34#include "common/util.h"
35#include "engines/engine.h"
36#include "engines/savestate.h"
37#include "graphics/screen.h"
38
39#include "tot/chrono.h"
40#include "tot/detection.h"
41#include "tot/events.h"
42#include "tot/graphics.h"
43#include "tot/mouse.h"
44#include "tot/sound.h"
45#include "tot/types.h"
46
47namespace Tot {
48
49struct TotGameDescription;
50
51enum TotAction {
52 kActionEscape,
53 kActionVolume,
54 kActionSaveLoad,
55 kActionTalk,
56 kActionPickup,
57 kActionLookAt,
58 kActionUse,
59 kActionOpen,
60 kActionClose,
61 kActionYes,
62 kActionNo
63};
64
65class TotEngine : public Engine {
66
67private:
68 Common::RandomSource _randomSource;
69
70 void handleEvent(Common::Event e);
76
77 int engineStart();
78 int startGame();
79 void newGame();
80 void resumeGame();
81
82 void changeRoom();
83 void loadScrollData(uint roomCode, bool rightScroll, uint horizontalPos, int scrollCorrection);
84 void drawText(uint number);
85 void displayLoading();
86 void runaroundRed();
87 void sprites(bool drawCharacter);
88 SavedGame *saveGameToRegister();
89 void originalSaveLoadScreen();
90 void loadGame(SavedGame *game);
91 bool autosaveExists();
92
93 RoomFileRegister *readScreenDataFile(Common::SeekableReadStream *screenDataFile);
94 void lookAtObject(byte objectNumber);
95 void useInventoryObjectWithInventoryObject(int16 obj1, int16 obj2);
96 void pickupScreenObject();
97 void useScreenObject();
98 void openScreenObject();
99 void closeScreenObject();
100 void action();
101 void handleAction(byte invPos);
102 void loadInventory();
103 void obtainName(Common::String &playerName);
104 void calculateRoute(byte zone1, byte zone2, bool extraCorrection = false, bool zonavedada = false);
105 void wcScene();
106 void advanceAnimations(bool barredZone, bool animateMouse);
107 void updateSecondaryAnimationDepth();
108 void updateMainCharacterDepth();
109 void actionLineText(const Common::String &actionLine);
110 void initializeObjectFile();
111 void saveObjectsData(ScreenObject *object, Common::SeekableWriteStream *out);
112 void scrollLeft(uint horizontalPos);
113 void scrollRight(uint horizontalPos);
114 TextEntry readTextRegister(uint numRegister);
115
116 void readConversationFile();
117
118 void adjustKey();
119 void adjustKey2();
120 void animateBat();
121 void updateVideo();
122 void nicheAnimation(byte nicheDir, int32 bitmap);
123 void replaceBackpack(byte obj1, uint obj2);
124 void dropObjectInScreen(ScreenObject *replacementObject);
125 void calculateTrajectory(uint finalX, uint finalY);
126 void animatedSequence(uint numSequence);
127 void initScreenPointers();
128
129 void loadAnimation(const Common::String &animation);
130 void loadCharAnimation();
131 void animateGive(uint dir, uint height);
132 void animatePickup1(uint dir, uint height);
133 void animatePickup2(uint dir, uint height);
134 void animateOpen2(uint dir, uint height);
135
136 void loadTV();
137 void loadScreen();
138 void loadScreenLayerWithDepth(uint coordx, uint coordy, uint bitmapSize, int32 bitmapIndex, uint depth);
139 void loadScreenLayer(uint coordx, uint coordy, uint picSize, int32 pic, uint prof);
140 void readBitmap(int32 bitmapOffset, byte *bitmap, uint bitmapSize, uint errorCode);
141 void updateAltScreen(byte altScreenNumber);
142
143 void freeInventory();
144 void updateInventory(byte index);
145 void updateObject(uint filePos);
146 void readObject(Common::SeekableReadStream *stream, uint objPos, ScreenObject *thisRegObj);
147 void saveObject(ScreenObject *object, Common::SeekableWriteStream *stream);
148 void saveItemRegister();
149
150 void saveTemporaryGame();
151 void drawLookAtItem(RoomObjectListEntry obj);
152 void putIcon(uint posX, uint posY, uint iconNumber);
153 void drawInventory(byte direction, byte limit);
154 void generateDiploma(Common::String &photoName);
155 void credits();
156 void checkMouseGrid();
157 void introduction();
158 void firstIntroduction();
159 void readAlphaGraph(Common::String &data, int length, int x, int y, byte barColor);
160 void readAlphaGraphSmall(Common::String &data, int length, int x, int y, byte barColor, byte textColor, Common::Event startEvent);
161 void displayObjectDescription(const Common::String &text);
162 void copyProtection();
163 void initialLogo();
164 void mainMenu(bool fade);
165 void exitToDOS();
166 void soundControls();
167 void sacrificeScene();
168 void ending();
169 void loadBat();
170 void loadDevil();
171 void assembleCompleteBackground(byte *image, uint coordx, uint coordy);
172 void assembleScreen(bool scroll = false);
173 void disableSecondAnimation();
174 void clearGame();
175
176 // vars
177 void initVars();
178 void resetGameState();
179 void clearVars();
180
181 void processEvents(bool &escapePressed);
182 void oldProcessEvents(bool &escapePressed);
183protected:
184 // Engine APIs
185 Common::Error run() override;
186 void syncSoundSettings() override;
187
188public:
189 Graphics::Screen *_screen = nullptr;
190 GraphicsManager *_graphics = nullptr;
191 SoundManager *_sound = nullptr;
192 MouseManager *_mouse = nullptr;
193 ChronoManager *_chrono = nullptr;
194 Tot::TotEventManager *_events = nullptr;
195 const ADGameDescription *_gameDescription;
196
197 bool _showMouseGrid = false;
198 bool _showScreenGrid = false;
199 bool _showGameGrid = false;
200 bool _drawObjectAreas = false;
201
202 Common::Language _lang = Common::ES_ESP;
203
204 Common::MemorySeekableReadWriteStream *_conversationData = nullptr;
206 Common::MemorySeekableReadWriteStream *_sceneObjectsData = nullptr;
207
208 bool _roomChange = false;
209 bool _isTVOn = false;
210 bool _isVasePlaced = false;
211 bool _isScytheTaken = false;
212 bool _isTridentTaken = false;
213 bool _isPottersWheelDelivered = false;
214 bool _isMudDelivered = false;
215 bool _isGreenDevilDelivered = false;
216 bool _isRedDevilCaptured = false;
217 bool _isPottersManualDelivered = false;
218 bool _isCupboardOpen = false;
219 bool _isChestOpen = false;
220 bool _isTrapSet = false;
221 bool _isPeterCoughing = false;
222
223 bool _isSealRemoved = false;
224 bool _inGame = false;
225 bool _firstTimeDone = false; // Flag for first time run of the game.
226 bool _isIntroSeen = false;
227 bool _shouldQuitGame = false;
228 bool _startNewGame = false; // Flag to initialize game
229 bool _continueGame = false; // Flag to resume game
230 bool _isSavingDisabled = false;
231 bool _isDrawingEnabled = false; // true if sprites should be drawn
232 bool _isSecondaryAnimationEnabled = false; // Whether room has secondary animation
233
234 InventoryEntry _inventory[kInventoryIconCount]; // These are the icons currnetly in the inventory
238 byte *_inventoryIconBitmaps[kInventoryIconCount] = { nullptr };
247 uint _mainCharFrameSize = 0;
248 SecondaryAnim _secondaryAnimation;
249 uint _secondaryAnimFrameSize = 0;
253 byte _actionCode = 0;
265 byte _doorIndex = 0;
269 byte _gamePart = 1;
281 byte _cpCounter = 0, _cpCounter2 = 0;
285 byte _destinationX = 0, _destinationY = 0;
294
298 uint _secondaryAnimWidth = 0, _secondaryAnimHeight = 0;
306 uint _oldposx = 0, _oldposy = 0;
307
311 int _element1 = 0, _element2 = 0;
315 uint16 _characterPosX = 0, _characterPosY = 0;
319 int _xframe2 = 0, _yframe2 = 0;
320
329
334
335 Common::String _decryptionKey;
336
340 uint _niche[2][4];
341
342 RoomFileRegister *_currentRoomData = nullptr;
343
344 ScreenObject *_curObject = nullptr; // Currently selected object in the screen
349
354
370 byte _currentZone = 0, _targetZone = 0, _oldTargetZone = 0;
371
375 byte _maxXGrid = 0, _maxYGrid = 0;
376
393
394 bool _list1Complete = false,
395 _list2Complete = false,
396 _obtainedList1 = false, // whether we've been given list 1
397 _obtainedList2 = false; // whether we've been given list 2
398
400 bool _firstTimeTopicA[kCharacterCount] = { false },
401 _firstTimeTopicB[kCharacterCount] = { false },
402 _firstTimeTopicC[kCharacterCount] = { false },
403 _bookTopic[kCharacterCount] = { false },
404 _mintTopic[kCharacterCount] = { false };
405
406 bool _caves[5] = { false };
407
411 uint16 _firstList[5] = { 0 }, _secondList[5] = { 0 };
412
413 int32 _screenSize = 65520;
414
418 byte _iframe = 0, _iframe2 = 0;
419
423 ObjectInfo _depthMap[kNumScreenOverlays];
427 byte *_screenLayers[kNumScreenOverlays] = { nullptr };
436
440 byte *_sceneBackground = nullptr;
441
445 byte *_characterDirtyRect = nullptr;
449 byte *_backgroundCopy = nullptr;
450
451 uint _currentRoomNumber = 0;
452
453 bool _isLoadingFromLauncher = false;
454
455 bool _saveAllowed = false;
456
460 uint _oldGridX = 0, _oldGridY = 0;
461
462 uint _curDepth = 0;
467 uint16 _dirtyMainSpriteX = 0, _dirtyMainSpriteY = 0;
472 uint _dirtyMainSpriteX2 = 0, _dirtyMainSpriteY2 = 0;
473 byte *_spriteBackground = nullptr;
474public:
475 TotEngine(OSystem *syst, const ADGameDescription *gameDesc);
476 ~TotEngine() override;
477
478 uint32 getFeatures() const;
479
484
488 uint32 getRandomNumber(uint maxNum) {
489 return _randomSource.getRandomNumber(maxNum);
490 }
491
492 bool hasFeature(EngineFeature f) const override {
493 return (f == kSupportsLoadingDuringRuntime) ||
496 };
497
498 void drawFontSurface(Graphics::BgiFont &litt);
499
500 // Save/Load
501 Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave = false) override;
503 bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override;
504 bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override;
505
506 void loadScreenData(uint screenNumber);
507 void clearScreenLayers();
508 void clearAnimation();
509 void buttonBorder(uint x1, uint y1, uint x2, uint y2, byte color1, byte color2, byte color3, byte color4, byte color5);
510 void drawMenu(byte menuNumber);
511 void drawLeftArrow(uint x, uint y);
512 void drawRightArrow(uint x, uint y);
513 void readTextFile();
514 void loadAnimationForDirection(Common::SeekableReadStream *stream, int direction);
515 void sayLine(uint textRef, byte textColor, byte shadowColor, uint &responseNumber, bool isWithinConversation);
516 void goToObject(byte zone1, byte zone2);
517 void readObject(uint objPos);
518 TextEntry readTextRegister();
519 void drawInventory();
520 void drawInventoryMask();
521 void setRoomTrajectories(int height, int width, TRAJECTORIES_OP op, bool fixGrids = true);
522 void saveRoomData(RoomFileRegister *room, Common::SeekableWriteStream *stream);
523 //vars
524 void initializeScreenFile();
525};
526
527extern TotEngine *g_engine;
528#define SHOULD_QUIT ::Tot::g_engine->shouldQuit()
529
530} // End of namespace Tot
531
532#endif // TOT_H
Definition: error.h:81
Definition: file.h:47
Definition: memstream.h:397
Definition: random.h:44
uint getRandomNumber(uint max)
Definition: stream.h:745
Definition: stream.h:351
Definition: serializer.h:80
Definition: str.h:59
Definition: ustr.h:57
Definition: stream.h:77
Definition: engine.h:149
EngineFeature
Definition: engine.h:282
@ kSupportsReturnToLauncher
Definition: engine.h:296
@ kSupportsSavingDuringRuntime
Definition: engine.h:314
@ kSupportsLoadingDuringRuntime
Definition: engine.h:305
Definition: bgifont.h:36
Definition: screen.h:47
Definition: system.h:166
Definition: chrono.h:33
Definition: graphics.h:32
Definition: mouse.h:32
Definition: sound.h:34
Definition: tot.h:65
uint _currentTrajectoryIndex
Definition: tot.h:362
byte * _inventoryIconBitmaps[kInventoryIconCount]
Definition: tot.h:238
int _element1
Definition: tot.h:311
byte _destinationX
Definition: tot.h:285
Common::File _verbFile
Definition: tot.h:324
byte _mouseGridForSecondaryAnim[10][10]
Definition: tot.h:384
byte _oldActionCode
Definition: tot.h:257
int _xframe2
Definition: tot.h:319
bool _firstTimeTopicA[kCharacterCount]
Definition: tot.h:400
byte _iframe
Definition: tot.h:418
void syncSoundSettings() override
Common::Point _trajectory[300]
Definition: tot.h:353
uint _dirtyMainSpriteX2
Definition: tot.h:472
uint _oldposx
Definition: tot.h:306
byte _maskGridSecondaryAnim[10][10]
Definition: tot.h:388
byte _cpCounter
Definition: tot.h:281
byte _movementGridForSecondaryAnim[10][10]
Definition: tot.h:380
Common::String getGameId() const
uint _oldGridX
Definition: tot.h:460
bool hasFeature(EngineFeature f) const override
Definition: tot.h:492
byte _maxXGrid
Definition: tot.h:375
Common::String _oldInventoryObjectName
Definition: tot.h:328
byte _maskMouseSecondaryAnim[10][10]
Definition: tot.h:392
uint16 _characterPosX
Definition: tot.h:315
byte * _sceneBackground
Definition: tot.h:440
uint _backpackObjectCode
Definition: tot.h:302
byte _gamePart
Definition: tot.h:269
byte * _characterDirtyRect
Definition: tot.h:445
uint16 _firstList[5]
Definition: tot.h:411
byte _currentZone
Definition: tot.h:370
Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave=false) override
uint _currentSecondaryTrajectoryIndex
Definition: tot.h:366
uint _niche[2][4]
Definition: tot.h:340
byte * _curSecondaryAnimationFrame
Definition: tot.h:435
uint _trajectoryLength
Definition: tot.h:358
byte _secondaryAnimationFrameCount
Definition: tot.h:273
byte * _screenLayers[kNumScreenOverlays]
Definition: tot.h:427
byte _doorIndex
Definition: tot.h:265
ObjectInfo _depthMap[kNumScreenOverlays]
Definition: tot.h:423
bool canSaveGameStateCurrently(Common::U32String *msg=nullptr) override
Common::Error run() override
byte * _backgroundCopy
Definition: tot.h:449
byte * _curCharacterAnimationFrame
Definition: tot.h:431
Route _mainRoute
Definition: tot.h:348
uint _secondaryAnimWidth
Definition: tot.h:298
uint32 getRandomNumber(uint maxNum)
Definition: tot.h:488
byte _inventoryPosition
Definition: tot.h:242
Common::String _characterName
Definition: tot.h:333
byte _actionCode
Definition: tot.h:253
CharacterAnim _mainCharAnimation
Definition: tot.h:246
Common::Error loadGameStream(Common::SeekableReadStream *stream) override
uint16 _dirtyMainSpriteX
Definition: tot.h:467
byte _trajectorySteps
Definition: tot.h:261
byte _secondaryAnimDirCount
Definition: tot.h:277
byte _charFacingDirection
Definition: tot.h:293
bool canLoadGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: events.h:44
Language
Definition: language.h:45
Engine * g_engine
Definition: advancedDetector.h:164
Definition: events.h:218
Definition: rect.h:144
Definition: types.h:99
Definition: types.h:109
Definition: types.h:95
Definition: types.h:179
Definition: types.h:168
Definition: types.h:218
Definition: types.h:125
Definition: types.h:104
Definition: types.h:118