ScummVM API documentation
trecision.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 TRECISION_TRECISION_H
23 #define TRECISION_TRECISION_H
24 
25 #include "common/str-array.h"
26 #include "common/keyboard.h"
27 #include "common/str.h"
28 #include "common/serializer.h"
29 #include "common/stream.h"
30 #include "engines/advancedDetector.h"
31 #include "engines/engine.h"
32 #include "graphics/surface.h"
33 
34 #include "trecision/defines.h"
35 #include "trecision/fastfile.h"
36 #include "trecision/struct.h"
37 #include "trecision/scheduler.h"
38 
39 namespace Trecision {
40 class AnimManager;
41 class DialogManager;
42 class GraphicsManager;
43 class LogicManager;
44 class SoundManager;
45 class Actor;
46 class Renderer3D;
47 class PathFinding3D;
48 class TextManager;
49 class Scheduler;
50 class AnimTypeManager;
51 
52 // Saved game versions
53 // Version history:
54 // - 102: Original PC full version
55 // - 103: Original PC demo version
56 // - 110: First ScummVM version
57 #define SAVE_VERSION_ORIGINAL_MIN 102
58 #define SAVE_VERSION_ORIGINAL_MAX 109
59 #define SAVE_VERSION_SCUMMVM_MIN 110
60 #define SAVE_VERSION_SCUMMVM 110
61 
62 #define MAXROOMS 100 // Game rooms
63 #define MAXOBJ 1400 // Game objects
64 #define MAXINVENTORY 150 // Inventory Items
65 #define MAXSAVEFILE 12
66 
67 enum TrecisionGameId {
68  GID_ArkOfTime = 0,
69  GID_NightLong = 1
70 };
71 
72 enum TrecisionMessageIds {
73  kMessageSavePosition = 9,
74  kMessageEmptySpot = 10,
75  kMessageLoadPosition = 11,
76  kMessageConfirmExit = 13,
77  kMessageDemoOver = 17,
78  kMessageError = 19,
79  kMessageUse = 23,
80  kMessageWith = 24,
81  kMessageGoto = 25,
82  kMessageGoto2 = 26
83 };
84 
85 typedef Common::List<Common::Rect>::iterator DirtyRectsIterator;
86 
88  uint16 dialog;
89  uint16 choice;
90  uint16 action;
91  uint16 newRoom;
92 };
93 
95  uint16 *buf;
96  uint8 *mask;
97 };
98 
99 class TrecisionEngine : public Engine {
100  void initMain();
101  void loadAll();
102  void loadSaveSlots(Common::StringArray &saveNames);
103  void eventLoop();
104 
105  // Inventory
106  void refreshInventory(uint8 startIcon, uint8 startLine);
107  void moveInventoryLeft();
108  void moveInventoryRight();
109  void syncInventory(Common::Serializer &ser);
110  void rollInventory(uint8 status);
111  void doScrollInventory(Common::Point pos);
112  void endUseWith();
113 
114  // Script
115  void endScript();
116  void evalScript();
117  void processScriptFrame();
118  void doAction();
119  void doMouse();
120  void processMouseMovement();
121  void doCharacter();
122  void doIdle();
123  void doRoomIn(uint16 curObj);
124  void doRoomOut(uint16 curObj);
125  void doMouseExamine(uint16 curObj);
126  void doMouseOperate(uint16 curObj);
127  void doMouseTake(uint16 curObj);
128  void doUseWith();
129  void doScreenUseWithScreen();
130  void doInvExamine();
131  void doInvOperate();
132  void doScript();
133  void processCurrentMessage();
134 
135  // Utils
136  char *getNextSentence();
137  uint16 getKey();
138  void processTime();
139  void processMouse();
140  static bool isBetween(int a, int x, int b);
141 
142  // Others
143  bool canPlayerInteract();
144 
145  // Objects
146  void readObj(Common::SeekableReadStream *stream);
147  void readObject(Common::SeekableReadStream *stream, uint16 objIndex, uint16 objectId);
148 
149  TrecisionGameId _gameId;
150 
151  char *_textArea;
152  uint16 _curScriptFrame[10];
153  char *_textPtr;
154 
155  uint16 _curAscii;
156  bool _keybInput;
157  bool _gamePaused;
158  uint8 _curStack;
159 
160  Common::List<SSortTable> _sortTableReplay;
161 
162 public:
163  TrecisionEngine(OSystem *syst, const ADGameDescription *desc);
164  ~TrecisionEngine() override;
165 
166  // ScummVM
167  Common::Error run() override;
168  TrecisionGameId getGameId() const { return _gameId; }
169  bool isDemo() const { return _gameDescription->flags & ADGF_DEMO; }
170  bool isAmiga() const { return _gameDescription->platform == Common::kPlatformAmiga; }
171  bool hasFeature(EngineFeature f) const override;
172  bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override { return canPlayerInteract() && _curRoom != kRoomIntro; }
173  bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override { return canPlayerInteract() && _curRoom != kRoomIntro; }
174  Common::Error loadGameStream(Common::SeekableReadStream *stream) override;
175  Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave = false) override;
176  bool syncGameStream(Common::Serializer &ser);
177 
178  // Data files
179  Common::SeekableReadStreamEndian *readEndian(Common::SeekableReadStream *stream, DisposeAfterUse::Flag disposeParentStream = DisposeAfterUse::YES);
180  void read3D(const Common::Path &c);
181 
182  // Inventory
183  void setInventoryStart(uint8 startIcon, uint8 startLine);
184  void showInventoryName(uint16 obj, bool showhide);
185  void showIconName();
186  uint8 whatIcon(Common::Point pos);
187  int8 iconPos(uint8 icon);
188  void removeIcon(uint8 icon);
189  void addIcon(uint8 icon);
190  void replaceIcon(uint8 oldIcon, uint8 newIcon);
191  void openInventory();
192  void closeInventory();
193  void closeInventoryImmediately();
194  void useItem();
195  void examineItem();
196  void clearUseWith();
197 
198  // Script
199  void playScript(uint16 id);
200  bool quitPrompt();
201  void demoOver();
202  void startCharacterAction(uint16 action, uint16 newRoom, uint8 newPos, uint16 sent);
203  void doMouseTalk(uint16 curObj);
204  void changeRoom(uint16 room, uint16 action = 0, byte position = 0);
205 
206  // Utils
207  uint16 textLength(const Common::String &text, uint16 begin = 0, uint16 end = 0);
208  Common::KeyCode waitKey();
209  void waitDelay(uint32 val);
210  void freeKey();
211  uint32 readTime();
212  bool checkMask(Common::Point pos);
213  float sinCosAngle(float sinus, float cosinus);
214  float dist2D(float x1, float y1, float x2, float y2);
215  float dist3D(float x1, float y1, float z1, float x2, float y2, float z2);
216  static bool isGameArea(Common::Point pos);
217  static bool isInventoryArea(Common::Point pos);
218  static bool isIconArea(Common::Point pos);
219  int getRoomObjectIndex(uint16 objectId);
220  int floatComp(float f1, float f2) const;
221 
222  // Others
223  void checkSystem();
224  bool dataSave();
225  bool dataLoad();
226  void reEvent();
227 
228  // Objects
229  void setObjectVisible(uint16 objectId, bool visible);
230  void refreshObject(uint16 objectId);
231  bool isObjectVisible(uint16 objectId);
232  void setObjectAnim(uint16 objectId, uint16 animId);
233  void redrawRoom();
234  void readLoc();
235  Common::SeekableReadStreamEndian *getLocStream();
236  void tendIn();
237  void readExtraObj2C();
238  void readPositionerSnapshots();
239 
240  // Data files
241  byte *readData(const Common::Path &fileName);
242 
243  const ADGameDescription *_gameDescription;
244 
245  Graphics::Surface _thumbnail;
246  bool _controlPanelSave = false;
247 
248  uint16 _curRoom;
249  uint16 _oldRoom;
250  SRoom _room[MAXROOMS];
251 
252  Common::List<SSortTable> _sortTable;
253 
254  uint16 _curObj;
255  SObject _obj[MAXOBJ];
256 
257  SDText _drawText;
258 
259  // Inventory
260  uint16 _curInventory;
261  SInvObject _inventoryObj[MAXINVENTORY];
262  Common::Array<byte> _inventory;
263  Common::Array<byte> _cyberInventory;
264  uint8 _iconBase;
265  uint8 _inventoryStatus;
266  uint8 _lightIcon;
267  uint8 _inventoryRefreshStartIcon;
268  uint8 _inventoryRefreshStartLine;
269  int16 _inventoryCounter;
270  bool _flagInventoryLocked;
271  uint8 _inventorySpeedIndex;
272  uint32 _inventoryScrollTime;
273  uint16 _lastInv;
274  uint16 _lastObj;
275 
276  bool _fastWalk;
277 
278  // Use With
279  uint16 _useWith[2];
280  bool _useWithInv[2];
281 
282  // Messages
283  const char *_objName[MAXOBJNAME];
284  const char *_sentence[MAXSENTENCE];
285  const char *_sysText[MAXSYSTEXT];
286 
287  // Message system
288  Message *_curMessage;
289  // Snake management
290  Message _snake52;
291 
292  uint32 _nextRefresh;
293 
294  Common::Point _mousePos;
295  bool _mouseMoved, _mouseLeftBtn, _mouseRightBtn;
296  Common::KeyCode _curKey;
297 
298  bool _flagScriptActive;
299  SScriptFrame _scriptFrame[MAXSCRIPTFRAME];
300  uint16 _scriptFirstFrame[MAXSCRIPT];
301 
302  AnimManager *_animMgr;
303  GraphicsManager *_graphicsMgr;
304  DialogManager *_dialogMgr;
305  LogicManager *_logicMgr;
306  SoundManager *_soundMgr;
307  Renderer3D *_renderer;
308  PathFinding3D *_pathFind;
309  TextManager *_textMgr;
310  Scheduler *_scheduler;
311  AnimTypeManager *_animTypeMgr;
312 
313  Actor *_actor;
314 
315  // Data files
316  FastFile _dataFile; // nldata.cd0
317 
318  bool _flagDialogActive;
319  bool _flagDialogMenuActive;
320  bool _flagSkipTalk;
321  bool _flagPaintCharacter;
322  bool _flagShowCharacter;
323  bool _flagSomeoneSpeaks;
324  bool _flagCharacterSpeak;
325  bool _flagUseWithStarted;
326  bool _flagNoPaintScreen;
327  bool _flagWaitRegen;
328 
329  ObjectGraphics _objectGraphics[MAXOBJINROOM];
330 
331  uint32 _curTime;
332  uint32 _characterSpeakTime;
333 
334  int _cx, _cy;
335 
336  uint8 _textStatus;
337 
338  uint32 _pauseStartTime;
339 };
340 
341 uint8 static const defActionLen[hLAST + 1] = {
342  /* STAND */ 1,
343  /* PARTE */ 1,
344  /* WALK */ 10,
345  /* END */ 1,
346  /* STOP0 */ 3,
347  /* STOP1 */ 4,
348  /* STOP2 */ 3,
349  /* STOP3 */ 2,
350  /* STOP4 */ 3,
351  /* STOP5 */ 4,
352  /* STOP6 */ 3,
353  /* STOP7 */ 3,
354  /* STOP8 */ 2,
355  /* STOP9 */ 3,
356  /* WALKI */ 12,
357  /* BOH */ 9,
358  /* UGG */ 41,
359  /* UTT */ 35,
360  /* WALKO */ 12,
361  /* LAST */ 15
362 };
363 
364 } // End of namespace Trecision
365 
366 #endif
Definition: struct.h:34
Definition: text.h:43
Definition: str.h:59
Definition: surface.h:66
EngineFeature
Definition: engine.h:250
Definition: stream.h:77
Definition: error.h:84
Definition: scheduler.h:34
Definition: fastfile.h:38
Definition: advancedDetector.h:120
Definition: trecision.h:99
Definition: dialog.h:69
Definition: list.h:44
Definition: animtype.h:38
Definition: path.h:52
Definition: struct.h:103
Definition: stream.h:745
Definition: actor.h:35
Definition: serializer.h:79
Definition: sound.h:58
Definition: renderer3d.h:41
Definition: actor.h:29
Definition: logic.h:31
bool canLoadGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: trecision.h:172
Definition: animmanager.h:49
Definition: struct.h:53
Definition: ustr.h:57
Definition: scheduler.h:55
Definition: rect.h:45
Definition: pathfinding3d.h:89
Definition: graphics.h:36
Definition: trecision.h:94
Definition: struct.h:169
Definition: stream.h:944
Definition: trecision.h:87
Definition: list_intern.h:51
Definition: struct.h:189
bool canSaveGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: trecision.h:173
Definition: system.h:167
Definition: graphics.h:42
Add "-demo" to gameid.
Definition: advancedDetector.h:113
Definition: engine.h:143