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