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