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/graphics.h"
42 #include "tot/mouse.h"
43 #include "tot/sound.h"
44 #include "tot/types.h"
45 
46 namespace Tot {
47 
48 struct TotGameDescription;
49 
50 class TotEngine : public Engine {
51 
52 private:
53  const ADGameDescription *_gameDescription;
54  Common::RandomSource _randomSource;
55 
56  void handleEvent(Common::Event e);
61  Common::Error syncGame(Common::Serializer &s);
62 
63  int engineStart();
64  int startGame();
65  void newGame();
66  void resumeGame();
67 
68  void changeRoom();
69  void loadScrollData(uint roomCode, bool rightScroll, uint horizontalPos, int scrollCorrection);
70  void drawText(uint number);
71  void displayLoading();
72  void runaroundRed();
73  void sprites(bool drawCharacter);
74  void saveGameToRegister();
75  void originalSaveLoadScreen();
76  void loadGame(SavedGame game);
77 
78  RoomFileRegister *readScreenDataFile(Common::SeekableReadStream *screenDataFile);
79  void lookAtObject(byte objectNumber);
80  void useInventoryObjectWithInventoryObject(uint obj1, uint obj2);
81  void pickupScreenObject();
82  void useScreenObject();
83  void openScreenObject();
84  void closeScreenObject();
85  void action();
86  void handleAction(byte invPos);
87  void loadInventory();
88  void obtainName(Common::String &playerName);
89  void calculateRoute(byte zone1, byte zone2, bool extraCorrection = false, bool zonavedada = false);
90  void wcScene();
91  void advanceAnimations(bool barredZone, bool animateMouse);
92  void updateSecondaryAnimationDepth();
93  void updateMainCharacterDepth();
94  void actionLineText(const Common::String &actionLine);
95  void initializeObjectFile();
96  void saveObjectsData(ScreenObject object, Common::SeekableWriteStream *objectDataStream);
97  void scrollLeft(uint horizontalPos);
98  void scrollRight(uint horizontalPos);
99  TextEntry readTextRegister(uint numRegister);
100 
101  void readConversationFile();
102 
103  void adjustKey();
104  void adjustKey2();
105  void animateBat();
106  void updateVideo();
107  void nicheAnimation(byte nicheDir, int32 bitmap);
108  void replaceBackpack(byte obj1, uint obj2);
109  void dropObjectInScreen(ScreenObject replacementObject);
110  void calculateTrajectory(uint finalX, uint finalY);
111  void animatedSequence(uint numSequence);
112  void initScreenPointers();
113 
114  void loadAnimation(const Common::String &animation);
115  void loadCharAnimation();
116  void animateGive(uint dir, uint height);
117  void animatePickup1(uint dir, uint height);
118  void animatePickup2(uint dir, uint height);
119  void animateOpen2(uint dir, uint height);
120 
121  void loadTV();
122  void loadScreen();
123  void loadScreenLayerWithDepth(uint coordx, uint coordy, uint bitmapSize, int32 bitmapIndex, uint depth);
124  void loadScreenLayer(uint coordx, uint coordy, uint picSize, int32 pic, uint prof);
125  void readBitmap(int32 bitmapOffset, byte *bitmap, uint bitmapSize, uint errorCode);
126  void updateAltScreen(byte altScreenNumber);
127 
128  void freeInventory();
129  void updateInventory(byte index);
130  void updateObject(uint filePos);
131  void readObject(Common::SeekableReadStream *stream, uint objPos, ScreenObject &thisRegObj);
132  void saveObject(ScreenObject object, Common::SeekableWriteStream *stream);
133  void saveItemRegister();
134 
135  void saveTemporaryGame();
136  void drawLookAtItem(RoomObjectListEntry obj);
137  void putIcon(uint posX, uint posY, uint iconNumber);
138  void drawInventory(byte direction, byte limit);
139  void generateDiploma(Common::String &photoName);
140  void credits();
141  void checkMouseGrid();
142  void introduction();
143  void firstIntroduction();
144  void readAlphaGraph(Common::String &data, int length, int x, int y, byte barColor);
145  void readAlphaGraphSmall(Common::String &data, int length, int x, int y, byte barColor, byte textColor, char startChar = '\0');
146  void displayObjectDescription(const Common::String &text);
147  void copyProtection();
148  void initialLogo();
149  void mainMenu(bool fade);
150  void exitToDOS();
151  void soundControls();
152  void sacrificeScene();
153  void ending();
154  void loadBat();
155  void loadDevil();
156  void assembleCompleteBackground(byte *image, uint coordx, uint coordy);
157  void assembleScreen(bool scroll = false);
158  void disableSecondAnimation();
159  void clearGame();
160 
161  // vars
162  void clearCurrentInventoryObject();
163  void initVars();
164  void resetGameState();
165  void clearVars();
166 
167 protected:
168  // Engine APIs
169  Common::Error run() override;
170 
171 public:
172  Graphics::Screen *_screen = nullptr;
173  Tot::GraphicsManager *_graphics = nullptr;
174  SoundManager *_sound = nullptr;
175  MouseManager *_mouse = nullptr;
176  ChronoManager *_chrono = nullptr;
177 
178  bool _showMouseGrid = false;
179  bool _showScreenGrid = false;
180  bool _showGameGrid = false;
181  bool _drawObjectAreas = false;
182 
183  Common::Language _lang = Common::ES_ESP;
184 
185  Common::MemorySeekableReadWriteStream *_conversationData = nullptr;
186  Common::MemorySeekableReadWriteStream *_rooms = nullptr;
187  Common::MemorySeekableReadWriteStream *_sceneObjectsData = nullptr;
188 
189  bool _roomChange = false;
190  bool _isTVOn = false;
191  bool _isVasePlaced = false;
192  bool _isScytheTaken = false;
193  bool _isTridentTaken = false;
194  bool _isPottersWheelDelivered = false;
195  bool _isMudDelivered = false;
196  bool _isGreenDevilDelivered = false;
197  bool _isRedDevilCaptured = false;
198  bool _isPottersManualDelivered = false;
199  bool _isCupboardOpen = false;
200  bool _isChestOpen = false;
201  bool _isTrapSet = false;
202  bool _isPeterCoughing = false;
203 
204  bool _isSealRemoved = false;
205  bool _inGame = false;
206  bool _firstTimeDone = false; // Flag for first time run of the game.
207  bool _isIntroSeen = false;
208  bool _shouldQuitGame = false;
209  bool _startNewGame = false; // Flag to initialize game
210  bool _continueGame = false; // Flag to resume game
211  bool _isSavingDisabled = false;
212  bool _isDrawingEnabled = false; // true if sprites should be drawn
213  bool _isSecondaryAnimationEnabled = false; // Whether room has secondary animation
214 
215  InventoryEntry _inventory[kInventoryIconCount]; // These are the icons currnetly in the inventory
219  byte *_inventoryIconBitmaps[kInventoryIconCount];
228  uint _mainCharFrameSize;
229  SecondaryAnim _secondaryAnimation;
230  uint _secondaryAnimFrameSize;
234  byte _actionCode = 0;
238  byte _oldActionCode = 0;
246  byte _doorIndex = 0;
250  byte _gamePart = 1;
262  byte _cpCounter = 0, _cpCounter2 = 0;
266  byte _destinationX = 0, _destinationY = 0;
275 
279  uint _secondaryAnimWidth = 0, _secondaryAnimHeight = 0;
287  uint _oldposx = 0, _oldposy = 0;
288 
292  int _element1 = 0, _element2 = 0;
296  uint16 _characterPosX = 0, _characterPosY = 0;
300  int _xframe2 = 0, _yframe2 = 0;
301 
310 
315 
316  Common::String _decryptionKey;
317 
321  uint _niche[2][4];
322 
323  RoomFileRegister *_currentRoomData = nullptr;
324 
325  ScreenObject _curObject;
329  Route _mainRoute;
330 
335 
351  byte _currentZone = 0, _targetZone = 0, _oldTargetZone = 0;
352 
356  byte _maxXGrid = 0, _maxYGrid = 0;
357 
374 
375  bool _list1Complete = false,
376  _list2Complete = false,
377  _obtainedList1 = false, // whether we've been given list 1
378  _obtainedList2 = false; // whether we've been given list 2
379 
381  bool _firstTimeTopicA[kCharacterCount] = { false },
382  _firstTimeTopicB[kCharacterCount] = { false },
383  _firstTimeTopicC[kCharacterCount] = { false },
384  _bookTopic[kCharacterCount] = { false },
385  _mintTopic[kCharacterCount] = { false };
386 
387  bool _caves[5] = { false };
388 
392  uint16 _firstList[5] = { 0 }, _secondList[5] = { 0 };
393 
394  int32 _screenSize = 65520;
395 
399  byte _iframe = 0, _iframe2 = 0;
400 
404  ObjectInfo _depthMap[kNumScreenOverlays];
408  byte *_screenLayers[kNumScreenOverlays];
417 
422 
431 
432  uint _currentRoomNumber = 0;
433 
434  bool _isLoadingFromLauncher = false;
435 
436  bool _saveAllowed = false;
437 
441  uint _oldGridX = 0, _oldGridY = 0;
442 
443  SavedGame _savedGame;
444 
445  uint _curDepth = 0;
450  uint16 _dirtyMainSpriteX = 0, _dirtyMainSpriteY = 0;
455  uint _dirtyMainSpriteX2 = 0, _dirtyMainSpriteY2 = 0;
456  byte *_spriteBackground;
457 public:
458  TotEngine(OSystem *syst, const ADGameDescription *gameDesc);
459  ~TotEngine() override;
460 
461  uint32 getFeatures() const;
462 
466  Common::String getGameId() const;
467 
471  uint32 getRandomNumber(uint maxNum) {
472  return _randomSource.getRandomNumber(maxNum);
473  }
474 
475  bool hasFeature(EngineFeature f) const override {
476  return (f == kSupportsLoadingDuringRuntime) ||
479  };
480 
481  void drawFontSurface(Graphics::BgiFont &litt);
482 
483  // Save/Load
484  Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave = false) override;
486  bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override;
487  bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override;
488 
489  void loadScreenData(uint screenNumber);
490  void clearScreenLayers();
491  void clearAnimation();
492  void buttonBorder(uint x1, uint y1, uint x2, uint y2, byte color1, byte color2, byte color3, byte color4, byte color5);
493  void drawMenu(byte menuNumber);
494  void readTextFile();
495  void loadAnimationForDirection(Common::SeekableReadStream *stream, int direction);
496  void sayLine(uint textRef, byte textColor, byte shadowColor, uint &responseNumber, bool isWithinConversation);
497  void goToObject(byte zone1, byte zone2);
498  void readObject(uint objPos);
499  TextEntry readTextRegister();
500  void drawInventory();
501  void drawInventoryMask();
502  void setRoomTrajectories(int height, int width, TRAJECTORIES_OP op, bool fixGrids = true);
503  void saveRoomData(RoomFileRegister *room, Common::SeekableWriteStream *stream);
504  //vars
505  void initializeScreenFile();
506 };
507 
508 extern TotEngine *g_engine;
509 #define SHOULD_QUIT ::Tot::g_engine->shouldQuit()
510 
511 } // End of namespace Tot
512 
513 #endif // TOT_H
byte _oldActionCode
Definition: tot.h:238
Definition: sound.h:34
Definition: bgifont.h:36
Common::File _verbFile
Definition: tot.h:305
byte * _screenLayers[kNumScreenOverlays]
Definition: tot.h:408
Definition: str.h:59
Definition: graphics.h:32
byte _trajectorySteps
Definition: tot.h:242
EngineFeature
Definition: engine.h:260
byte * _sceneBackground
Definition: tot.h:421
byte _destinationX
Definition: tot.h:266
int _xframe2
Definition: tot.h:300
Definition: stream.h:77
bool hasFeature(EngineFeature f) const override
Definition: tot.h:475
Definition: error.h:81
byte _cpCounter
Definition: tot.h:262
Common::Error run() override
Definition: advancedDetector.h:164
ObjectInfo _depthMap[kNumScreenOverlays]
Definition: tot.h:404
Definition: random.h:44
Definition: memstream.h:394
Definition: types.h:104
uint _currentTrajectoryIndex
Definition: tot.h:343
Definition: types.h:95
Definition: tot.h:50
bool canLoadGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: types.h:218
Definition: types.h:125
uint getRandomNumber(uint max)
byte _secondaryAnimDirCount
Definition: tot.h:258
byte _maxXGrid
Definition: tot.h:356
Definition: types.h:109
Definition: stream.h:745
uint16 _dirtyMainSpriteX
Definition: tot.h:450
Definition: mouse.h:32
Definition: screen.h:48
uint16 _characterPosX
Definition: tot.h:296
Engine * g_engine
Definition: serializer.h:79
bool _firstTimeTopicA[kCharacterCount]
Definition: tot.h:381
Definition: engine.h:274
uint _secondaryAnimWidth
Definition: tot.h:279
uint _niche[2][4]
Definition: tot.h:321
Definition: types.h:179
bool canSaveGameStateCurrently(Common::U32String *msg=nullptr) override
byte * _characterDirtyRect
Definition: tot.h:426
Definition: types.h:168
byte _mouseGridForSecondaryAnim[10][10]
Definition: tot.h:365
byte _secondaryAnimationFrameCount
Definition: tot.h:254
CharacterAnim _mainCharAnimation
Definition: tot.h:227
byte _inventoryPosition
Definition: tot.h:223
uint _trajectoryLength
Definition: tot.h:339
uint _currentSecondaryTrajectoryIndex
Definition: tot.h:347
uint _oldposx
Definition: tot.h:287
byte * _curCharacterAnimationFrame
Definition: tot.h:412
Common::String _oldInventoryObjectName
Definition: tot.h:309
Definition: ustr.h:57
Definition: file.h:47
Route _mainRoute
Definition: tot.h:329
Definition: events.h:210
byte _iframe
Definition: tot.h:399
Definition: rect.h:144
uint16 _firstList[5]
Definition: tot.h:392
Common::String getGameId() const
byte _gamePart
Definition: tot.h:250
byte _movementGridForSecondaryAnim[10][10]
Definition: tot.h:361
byte _doorIndex
Definition: tot.h:246
byte _actionCode
Definition: tot.h:234
uint _backpackObjectCode
Definition: tot.h:283
Definition: anims.h:26
Definition: chrono.h:33
Definition: stream.h:351
byte * _curSecondaryAnimationFrame
Definition: tot.h:416
Common::Point _trajectory[300]
Definition: tot.h:334
Definition: system.h:163
uint _dirtyMainSpriteX2
Definition: tot.h:455
Common::String _characterName
Definition: tot.h:314
byte _charFacingDirection
Definition: tot.h:274
Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave=false) override
uint32 getRandomNumber(uint maxNum)
Definition: tot.h:471
byte * _inventoryIconBitmaps[kInventoryIconCount]
Definition: tot.h:219
Definition: engine.h:292
byte _maskMouseSecondaryAnim[10][10]
Definition: tot.h:373
Common::Error loadGameStream(Common::SeekableReadStream *stream) override
Definition: engine.h:146
byte * _backgroundCopy
Definition: tot.h:430
Definition: types.h:118
byte _currentZone
Definition: tot.h:351
byte _maskGridSecondaryAnim[10][10]
Definition: tot.h:369
int _element1
Definition: tot.h:292
Definition: types.h:99
uint _oldGridX
Definition: tot.h:441
Language
Definition: language.h:45