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 
47 namespace Tot {
48 
49 struct TotGameDescription;
50 
51 enum 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 
65 class TotEngine : public Engine {
66 
67 private:
68  Common::RandomSource _randomSource;
69 
70  void handleEvent(Common::Event e);
75  Common::Error syncGame(Common::Serializer &s);
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 
92  RoomFileRegister *readScreenDataFile(Common::SeekableReadStream *screenDataFile);
93  void lookAtObject(byte objectNumber);
94  void useInventoryObjectWithInventoryObject(uint obj1, uint obj2);
95  void pickupScreenObject();
96  void useScreenObject();
97  void openScreenObject();
98  void closeScreenObject();
99  void action();
100  void handleAction(byte invPos);
101  void loadInventory();
102  void obtainName(Common::String &playerName);
103  void calculateRoute(byte zone1, byte zone2, bool extraCorrection = false, bool zonavedada = false);
104  void wcScene();
105  void advanceAnimations(bool barredZone, bool animateMouse);
106  void updateSecondaryAnimationDepth();
107  void updateMainCharacterDepth();
108  void actionLineText(const Common::String &actionLine);
109  void initializeObjectFile();
110  void saveObjectsData(ScreenObject *object, Common::SeekableWriteStream *out);
111  void scrollLeft(uint horizontalPos);
112  void scrollRight(uint horizontalPos);
113  TextEntry readTextRegister(uint numRegister);
114 
115  void readConversationFile();
116 
117  void adjustKey();
118  void adjustKey2();
119  void animateBat();
120  void updateVideo();
121  void nicheAnimation(byte nicheDir, int32 bitmap);
122  void replaceBackpack(byte obj1, uint obj2);
123  void dropObjectInScreen(ScreenObject *replacementObject);
124  void calculateTrajectory(uint finalX, uint finalY);
125  void animatedSequence(uint numSequence);
126  void initScreenPointers();
127 
128  void loadAnimation(const Common::String &animation);
129  void loadCharAnimation();
130  void animateGive(uint dir, uint height);
131  void animatePickup1(uint dir, uint height);
132  void animatePickup2(uint dir, uint height);
133  void animateOpen2(uint dir, uint height);
134 
135  void loadTV();
136  void loadScreen();
137  void loadScreenLayerWithDepth(uint coordx, uint coordy, uint bitmapSize, int32 bitmapIndex, uint depth);
138  void loadScreenLayer(uint coordx, uint coordy, uint picSize, int32 pic, uint prof);
139  void readBitmap(int32 bitmapOffset, byte *bitmap, uint bitmapSize, uint errorCode);
140  void updateAltScreen(byte altScreenNumber);
141 
142  void freeInventory();
143  void updateInventory(byte index);
144  void updateObject(uint filePos);
145  void readObject(Common::SeekableReadStream *stream, uint objPos, ScreenObject *thisRegObj);
146  void saveObject(ScreenObject *object, Common::SeekableWriteStream *stream);
147  void saveItemRegister();
148 
149  void saveTemporaryGame();
150  void drawLookAtItem(RoomObjectListEntry obj);
151  void putIcon(uint posX, uint posY, uint iconNumber);
152  void drawInventory(byte direction, byte limit);
153  void generateDiploma(Common::String &photoName);
154  void credits();
155  void checkMouseGrid();
156  void introduction();
157  void firstIntroduction();
158  void readAlphaGraph(Common::String &data, int length, int x, int y, byte barColor);
159  void readAlphaGraphSmall(Common::String &data, int length, int x, int y, byte barColor, byte textColor, Common::Event startEvent);
160  void displayObjectDescription(const Common::String &text);
161  void copyProtection();
162  void initialLogo();
163  void mainMenu(bool fade);
164  void exitToDOS();
165  void soundControls();
166  void sacrificeScene();
167  void ending();
168  void loadBat();
169  void loadDevil();
170  void assembleCompleteBackground(byte *image, uint coordx, uint coordy);
171  void assembleScreen(bool scroll = false);
172  void disableSecondAnimation();
173  void clearGame();
174 
175  // vars
176  void initVars();
177  void resetGameState();
178  void clearVars();
179 
180  void processEvents(bool &escapePressed);
181  void oldProcessEvents(bool &escapePressed);
182 protected:
183  // Engine APIs
184  Common::Error run() override;
185  void syncSoundSettings() override;
186 
187 public:
188  Graphics::Screen *_screen = nullptr;
189  GraphicsManager *_graphics = nullptr;
190  SoundManager *_sound = nullptr;
191  MouseManager *_mouse = nullptr;
192  ChronoManager *_chrono = nullptr;
193  Tot::TotEventManager *_events = nullptr;
194  const ADGameDescription *_gameDescription;
195 
196  bool _showMouseGrid = false;
197  bool _showScreenGrid = false;
198  bool _showGameGrid = false;
199  bool _drawObjectAreas = false;
200 
201  Common::Language _lang = Common::ES_ESP;
202 
203  Common::MemorySeekableReadWriteStream *_conversationData = nullptr;
204  Common::MemorySeekableReadWriteStream *_rooms = nullptr;
205  Common::MemorySeekableReadWriteStream *_sceneObjectsData = nullptr;
206 
207  bool _roomChange = false;
208  bool _isTVOn = false;
209  bool _isVasePlaced = false;
210  bool _isScytheTaken = false;
211  bool _isTridentTaken = false;
212  bool _isPottersWheelDelivered = false;
213  bool _isMudDelivered = false;
214  bool _isGreenDevilDelivered = false;
215  bool _isRedDevilCaptured = false;
216  bool _isPottersManualDelivered = false;
217  bool _isCupboardOpen = false;
218  bool _isChestOpen = false;
219  bool _isTrapSet = false;
220  bool _isPeterCoughing = false;
221 
222  bool _isSealRemoved = false;
223  bool _inGame = false;
224  bool _firstTimeDone = false; // Flag for first time run of the game.
225  bool _isIntroSeen = false;
226  bool _shouldQuitGame = false;
227  bool _startNewGame = false; // Flag to initialize game
228  bool _continueGame = false; // Flag to resume game
229  bool _isSavingDisabled = false;
230  bool _isDrawingEnabled = false; // true if sprites should be drawn
231  bool _isSecondaryAnimationEnabled = false; // Whether room has secondary animation
232 
233  InventoryEntry _inventory[kInventoryIconCount]; // These are the icons currnetly in the inventory
237  byte *_inventoryIconBitmaps[kInventoryIconCount] = { nullptr };
246  uint _mainCharFrameSize = 0;
247  SecondaryAnim _secondaryAnimation;
248  uint _secondaryAnimFrameSize = 0;
252  byte _actionCode = 0;
256  byte _oldActionCode = 0;
264  byte _doorIndex = 0;
268  byte _gamePart = 1;
280  byte _cpCounter = 0, _cpCounter2 = 0;
284  byte _destinationX = 0, _destinationY = 0;
293 
297  uint _secondaryAnimWidth = 0, _secondaryAnimHeight = 0;
305  uint _oldposx = 0, _oldposy = 0;
306 
310  int _element1 = 0, _element2 = 0;
314  uint16 _characterPosX = 0, _characterPosY = 0;
318  int _xframe2 = 0, _yframe2 = 0;
319 
328 
333 
334  Common::String _decryptionKey;
335 
339  uint _niche[2][4];
340 
341  RoomFileRegister *_currentRoomData = nullptr;
342 
343  ScreenObject *_curObject = nullptr; // Currently selected object in the screen
347  Route _mainRoute;
348 
353 
369  byte _currentZone = 0, _targetZone = 0, _oldTargetZone = 0;
370 
374  byte _maxXGrid = 0, _maxYGrid = 0;
375 
392 
393  bool _list1Complete = false,
394  _list2Complete = false,
395  _obtainedList1 = false, // whether we've been given list 1
396  _obtainedList2 = false; // whether we've been given list 2
397 
399  bool _firstTimeTopicA[kCharacterCount] = { false },
400  _firstTimeTopicB[kCharacterCount] = { false },
401  _firstTimeTopicC[kCharacterCount] = { false },
402  _bookTopic[kCharacterCount] = { false },
403  _mintTopic[kCharacterCount] = { false };
404 
405  bool _caves[5] = { false };
406 
410  uint16 _firstList[5] = { 0 }, _secondList[5] = { 0 };
411 
412  int32 _screenSize = 65520;
413 
417  byte _iframe = 0, _iframe2 = 0;
418 
422  ObjectInfo _depthMap[kNumScreenOverlays];
426  byte *_screenLayers[kNumScreenOverlays] = { nullptr };
435 
439  byte *_sceneBackground = nullptr;
440 
444  byte *_characterDirtyRect = nullptr;
448  byte *_backgroundCopy = nullptr;
449 
450  uint _currentRoomNumber = 0;
451 
452  bool _isLoadingFromLauncher = false;
453 
454  bool _saveAllowed = false;
455 
459  uint _oldGridX = 0, _oldGridY = 0;
460 
461  uint _curDepth = 0;
466  uint16 _dirtyMainSpriteX = 0, _dirtyMainSpriteY = 0;
471  uint _dirtyMainSpriteX2 = 0, _dirtyMainSpriteY2 = 0;
472  byte *_spriteBackground = nullptr;
473 public:
474  TotEngine(OSystem *syst, const ADGameDescription *gameDesc);
475  ~TotEngine() override;
476 
477  uint32 getFeatures() const;
478 
482  Common::String getGameId() const;
483 
487  uint32 getRandomNumber(uint maxNum) {
488  return _randomSource.getRandomNumber(maxNum);
489  }
490 
491  bool hasFeature(EngineFeature f) const override {
492  return (f == kSupportsLoadingDuringRuntime) ||
495  };
496 
497  void drawFontSurface(Graphics::BgiFont &litt);
498 
499  // Save/Load
500  Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave = false) override;
502  bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override;
503  bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override;
504 
505  void loadScreenData(uint screenNumber);
506  void clearScreenLayers();
507  void clearAnimation();
508  void buttonBorder(uint x1, uint y1, uint x2, uint y2, byte color1, byte color2, byte color3, byte color4, byte color5);
509  void drawMenu(byte menuNumber);
510  void drawLeftArrow(uint x, uint y);
511  void drawRightArrow(uint x, uint y);
512  void readTextFile();
513  void loadAnimationForDirection(Common::SeekableReadStream *stream, int direction);
514  void sayLine(uint textRef, byte textColor, byte shadowColor, uint &responseNumber, bool isWithinConversation);
515  void goToObject(byte zone1, byte zone2);
516  void readObject(uint objPos);
517  TextEntry readTextRegister();
518  void drawInventory();
519  void drawInventoryMask();
520  void setRoomTrajectories(int height, int width, TRAJECTORIES_OP op, bool fixGrids = true);
521  void saveRoomData(RoomFileRegister *room, Common::SeekableWriteStream *stream);
522  //vars
523  void initializeScreenFile();
524 };
525 
526 extern TotEngine *g_engine;
527 #define SHOULD_QUIT ::Tot::g_engine->shouldQuit()
528 
529 } // End of namespace Tot
530 
531 #endif // TOT_H
byte _oldActionCode
Definition: tot.h:256
Definition: sound.h:34
Definition: bgifont.h:36
Common::File _verbFile
Definition: tot.h:323
byte * _screenLayers[kNumScreenOverlays]
Definition: tot.h:426
Definition: str.h:59
Definition: graphics.h:32
byte _trajectorySteps
Definition: tot.h:260
EngineFeature
Definition: engine.h:258
byte * _sceneBackground
Definition: tot.h:439
byte _destinationX
Definition: tot.h:284
int _xframe2
Definition: tot.h:318
Definition: stream.h:77
bool hasFeature(EngineFeature f) const override
Definition: tot.h:491
Definition: error.h:81
byte _cpCounter
Definition: tot.h:280
Common::Error run() override
Definition: advancedDetector.h:164
ObjectInfo _depthMap[kNumScreenOverlays]
Definition: tot.h:422
Definition: random.h:44
Definition: memstream.h:397
Definition: types.h:104
uint _currentTrajectoryIndex
Definition: tot.h:361
Definition: types.h:95
Definition: tot.h:65
bool canLoadGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: types.h:218
Definition: types.h:125
uint getRandomNumber(uint max)
byte _secondaryAnimDirCount
Definition: tot.h:276
byte _maxXGrid
Definition: tot.h:374
Definition: types.h:109
Definition: stream.h:745
uint16 _dirtyMainSpriteX
Definition: tot.h:466
Definition: mouse.h:32
Definition: screen.h:48
uint16 _characterPosX
Definition: tot.h:314
void syncSoundSettings() override
Engine * g_engine
Definition: serializer.h:79
bool _firstTimeTopicA[kCharacterCount]
Definition: tot.h:399
Definition: engine.h:272
uint _secondaryAnimWidth
Definition: tot.h:297
uint _niche[2][4]
Definition: tot.h:339
Definition: types.h:179
bool canSaveGameStateCurrently(Common::U32String *msg=nullptr) override
byte * _characterDirtyRect
Definition: tot.h:444
Definition: types.h:168
byte _mouseGridForSecondaryAnim[10][10]
Definition: tot.h:383
byte _secondaryAnimationFrameCount
Definition: tot.h:272
CharacterAnim _mainCharAnimation
Definition: tot.h:245
byte _inventoryPosition
Definition: tot.h:241
uint _trajectoryLength
Definition: tot.h:357
uint _currentSecondaryTrajectoryIndex
Definition: tot.h:365
uint _oldposx
Definition: tot.h:305
byte * _curCharacterAnimationFrame
Definition: tot.h:430
Common::String _oldInventoryObjectName
Definition: tot.h:327
Definition: ustr.h:57
Definition: file.h:47
Route _mainRoute
Definition: tot.h:347
Definition: events.h:210
byte _iframe
Definition: tot.h:417
Definition: rect.h:144
uint16 _firstList[5]
Definition: tot.h:410
Common::String getGameId() const
byte _gamePart
Definition: tot.h:268
byte _movementGridForSecondaryAnim[10][10]
Definition: tot.h:379
byte _doorIndex
Definition: tot.h:264
byte _actionCode
Definition: tot.h:252
uint _backpackObjectCode
Definition: tot.h:301
Definition: anims.h:26
Definition: events.h:44
Definition: chrono.h:33
Definition: stream.h:351
byte * _curSecondaryAnimationFrame
Definition: tot.h:434
Common::Point _trajectory[300]
Definition: tot.h:352
Definition: system.h:163
uint _dirtyMainSpriteX2
Definition: tot.h:471
Common::String _characterName
Definition: tot.h:332
byte _charFacingDirection
Definition: tot.h:292
Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave=false) override
uint32 getRandomNumber(uint maxNum)
Definition: tot.h:487
byte * _inventoryIconBitmaps[kInventoryIconCount]
Definition: tot.h:237
Definition: engine.h:290
byte _maskMouseSecondaryAnim[10][10]
Definition: tot.h:391
Common::Error loadGameStream(Common::SeekableReadStream *stream) override
Definition: engine.h:144
byte * _backgroundCopy
Definition: tot.h:448
Definition: types.h:118
byte _currentZone
Definition: tot.h:369
byte _maskGridSecondaryAnim[10][10]
Definition: tot.h:387
int _element1
Definition: tot.h:310
Definition: types.h:99
uint _oldGridX
Definition: tot.h:459
Language
Definition: language.h:45