ScummVM API documentation
lab.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  /*
23  * This code is based on Labyrinth of Time code with assistance of
24  *
25  * Copyright (c) 1993 Terra Nova Development
26  * Copyright (c) 2004 The Wyrmkeep Entertainment Co.
27  *
28  */
29 
30 #ifndef LAB_LAB_H
31 #define LAB_LAB_H
32 
33 #include "common/system.h"
34 #include "common/random.h"
35 #include "common/rect.h"
36 #include "common/savefile.h"
37 #include "engines/engine.h"
38 #include "engines/savestate.h"
39 
40 #include "lab/console.h"
41 #include "lab/image.h"
42 #include "lab/labsets.h"
43 #include "lab/detection.h"
44 
45 struct ADGameDescription;
46 
47 namespace Lab {
48 
49 struct MapData;
50 struct Action;
51 struct CloseData;
52 struct Button;
53 struct IntuiMessage;
54 struct InventoryData;
55 struct RoomData;
56 struct Rule;
57 struct TextFont;
58 struct ViewData;
59 
60 class Anim;
61 class DisplayMan;
62 class EventManager;
63 class Interface;
64 class Image;
65 class Music;
66 class Resource;
67 class SpecialLocks;
68 class Utils;
69 
71  byte _version;
72  SaveStateDescriptor _descr;
73  uint16 _roomNumber;
74  uint16 _direction;
75 };
76 
78 
79 struct CrumbData {
80  uint16 _crumbRoomNum;
81  uint16 _crumbDirection;
82 };
83 
84 #define MAX_CRUMBS 128
85 
90 
91 enum Direction {
92  kDirectionNorth,
93  kDirectionSouth,
94  kDirectionEast,
95  kDirectionWest
96 };
97 
98 enum MainButton {
99  kButtonNone = -1,
100  kButtonPickup,
101  kButtonUse,
102  kButtonOpen,
103  kButtonClose,
104  kButtonLook,
105  kButtonInventory,
106  kButtonLeft,
107  kButtonForward,
108  kButtonRight,
109  kButtonMap
110 };
111 
112 enum MessageClass {
113  kMessageLeftClick,
114  kMessageRightClick,
115  kMessageButtonUp,
116  kMessageRawKey
117 };
118 
119 class LabEngine : public Engine {
120  friend class Console;
121 
122 private:
123  bool _isCrumbWaiting;
124  bool _lastTooLong;
125  bool _lastPage;
126  bool _mainDisplay;
127  bool _noUpdateDiff;
128  bool _quitLab;
129 
130  byte *_blankJournal;
131 
132  int _lastWaitTOFTicks;
133 
134  uint16 _direction;
135  uint16 _highPalette[20];
136  uint16 _journalPage;
137  uint16 _maxRooms;
138  uint16 _monitorPage;
139  uint16 _monitorButtonHeight;
140 
141  uint32 _extraGameFeatures;
142 
143  Common::String _journalText;
144  Common::String _journalTextTitle;
145  Common::String _nextFileName;
146  Common::String _newFileName;
147  Common::String _monitorTextFilename;
148 
149  const CloseData *_closeDataPtr;
150  ButtonList _journalButtonList;
151  ButtonList _mapButtonList;
152  Image *_imgMap, *_imgRoom, *_imgUpArrowRoom, *_imgDownArrowRoom, *_imgBridge;
153  Image *_imgHRoom, *_imgVRoom, *_imgMaze, *_imgHugeMaze, *_imgPath;
154  Image *_imgMapX[4];
155  InventoryData *_inventory;
156  MapData *_maps;
157  Image *_monitorButton;
158  Image *_journalBackImage;
159  TextFont *_journalFont;
160  bool _introPlaying;
161 
162 public:
163  bool _alternate;
164  bool _droppingCrumbs;
165  bool _followingCrumbs;
166  bool _followCrumbsFast;
167  bool _isCrumbTurning;
168  bool _isHiRes;
169 
170  int _roomNum;
171 
172  uint16 _highestCondition;
173  uint16 _manyRooms;
174  uint16 _numCrumbs;
175  uint16 _numInv;
176 
177  uint32 _crumbTimestamp;
178 
179  Common::String _curFileName;
180 
181  Anim *_anim;
182  CrumbData _breadCrumbs[MAX_CRUMBS];
183  DisplayMan *_graphics;
184  EventManager *_event;
185  Interface *_interface;
186  ButtonList _invButtonList;
187  ButtonList _moveButtonList;
188  Image *_invImages[10];
189  Image *_moveImages[20];
190  LargeSet *_conditions, *_roomsFound;
191  Music *_music;
192  Resource *_resource;
193  RoomData *_rooms;
194  TextFont *_msgFont;
195  SpecialLocks *_specialLocks;
196  Utils *_utils;
197 
198 public:
199  LabEngine(OSystem *syst, const ADGameDescription *gameDesc);
200  ~LabEngine() override;
201 
202  Common::Error run() override;
203  void go();
204 
205  const ADGameDescription *_gameDescription;
206  Common::Platform getPlatform() const;
207  uint32 getFeatures() const;
208 
209  bool hasFeature(EngineFeature f) const override;
210 
211  void changeVolume(int delta);
212  uint16 getDirection() { return _direction; }
213 
217  Common::String getPictName(bool useClose);
218  uint16 getQuarters();
219  void setQuarters(uint16 quarters);
220  void updateEvents();
221  void waitTOF();
222 
223  Common::Error loadGameState(int slot) override;
224  Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave = false) override;
225  bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override;
226  bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override;
227 
228  bool isMainDisplay() const { return _mainDisplay; }
229 
230 private:
234  bool checkConditions(const Common::Array<int16> &cond);
235 
239  void decIncInv(uint16 *CurInv, bool dec);
240 
244  void doActions(const ActionList &actionList);
245 
249  bool doActionRule(Common::Point pos, int16 action, int16 roomNum);
250 
254  bool doActionRuleSub(int16 action, int16 roomNum, const CloseData *closePtr, bool allowDefaults);
255 
259  void handleMonitorCloseup();
260 
264  bool doGoForward();
265 
269  void doJournal();
270 
274  bool doMainView();
275 
279  void doMap();
280 
284  void doMonitor(const Common::String background, const Common::String textfile, bool isinteractive, Common::Rect textRect);
285 
289  void doNotes();
290 
294  bool doOperateRuleSub(int16 itemNum, int16 roomNum, const CloseData *closePtr, bool allowDefaults);
295 
299  bool doOperateRule(Common::Point pos, int16 ItemNum);
300 
304  bool doTurn(uint16 from, uint16 to);
305 
309  bool doUse(uint16 curInv);
310 
315  void doWestPaper();
316 
320  void drawDirection(const CloseData *closePtr);
321 
325  void drawJournal(uint16 wipenum, bool needFade);
326 
330  void drawJournalText();
331 
335  void drawMap(uint16 curRoom, uint16 curMsg, uint16 floorNum, bool fadeIn);
336 
340  void drawMonText(const char *text, TextFont *monitorFont, Common::Rect textRect, bool isinteractive);
341 
345  void drawRoomMap(uint16 curRoom, bool drawMarkFl);
346 
350  void drawRoomMessage(uint16 curInv, const CloseData *closePtr);
351  void drawStaticMessage(byte index);
352 
356  void eatMessages();
357 
364  const CloseData *findClosePtrMatch(const CloseData *closePtr, const CloseDataList &list);
365 
369  bool floorVisited(uint16 floorNum);
370 
374  MainButton followCrumbs();
375  void freeMapData();
376  void freeScreens();
377  bool processEvent(MessageClass tmpClass, uint16 code, uint16 qualifier, Common::Point tmpPos,
378  uint16 &curInv, IntuiMessage *curMsg, bool &forceDraw, uint16 buttonId, uint16 &actionMode);
379 
383  Common::String getInvName(uint16 curInv);
384 
389  uint16 getLowerFloor(uint16 floorNum);
390 
394  const CloseData *getObject(Common::Point pos, const CloseData *closePtr);
395 
400  uint16 getUpperFloor(uint16 floorNum);
401 
405  ViewData *getViewData(uint16 roomNum, uint16 direction);
406 
410  void interfaceOff();
411 
415  void interfaceOn();
416 
420  void loadJournalData();
421 
425  void loadMapData();
426 
430  void mainGameLoop();
431  void showLab2Teaser();
432 
436  void perFlipButton(uint16 buttonId);
437 
441  uint16 processArrow(uint16 curDirection, uint16 arrow);
442 
446  void processJournal();
447 
451  void processMap(uint16 curRoom);
452 
456  void processMonitor(const Common::String &ntext, TextFont *monitorFont, bool isInteractive, Common::Rect textRect);
457 
461  Common::Rect roomCoords(uint16 curRoom);
462  bool saveRestoreGame();
463 
467  void setCurrentClose(Common::Point pos, const CloseData **closePtrList, bool useAbsoluteCoords, bool next=false);
468 
472  bool takeItem(Common::Point pos);
473 
477  void turnPage(bool fromLeft);
478  bool processKey(IntuiMessage *curMsg, uint32 msgClass, uint16 &qualifier, Common::Point &curPos, uint16 &curInv, bool &forceDraw, uint16 code);
479  void processMainButton(uint16 &curInv, uint16 &lastInv, uint16 &oldDirection, bool &forceDraw, uint16 buttonId, uint16 &actionMode);
480  void processAltButton(uint16 &curInv, uint16 &lastInv, uint16 buttonId, uint16 &actionMode);
481  void performAction(uint16 actionMode, Common::Point curPos, uint16 &curInv);
482 
486  bool saveGame(int slot, const Common::String desc);
487 
491  bool loadGame(int slot);
492  void writeSaveGameHeader(Common::OutSaveFile *out, const Common::String &saveName);
493 
494  void handleTrialWarning();
495 };
496 
497 WARN_UNUSED_RESULT bool readSaveGameHeader(Common::InSaveFile *in, SaveGameHeader &header, bool skipThumbnail = true);
498 
499 } // End of namespace Lab
500 
501 #endif // LAB_LAB_H
Definition: str.h:59
Definition: lab.h:79
EngineFeature
Definition: engine.h:250
Definition: lab.h:70
Definition: interface.h:49
Definition: savefile.h:54
Definition: error.h:84
Definition: speciallocks.h:39
Definition: dispman.h:57
Definition: advancedDetector.h:120
Definition: rect.h:144
Definition: processroom.h:145
Definition: labsets.h:41
Definition: stream.h:745
Definition: utils.h:35
Definition: savestate.h:56
Definition: processroom.h:175
Definition: anim.h:45
Definition: eventman.h:40
Definition: processroom.h:181
Definition: processroom.h:136
Definition: anim.h:33
Definition: ustr.h:57
Definition: rect.h:45
bool skipThumbnail(Common::SeekableReadStream &in)
Definition: eventman.h:47
Definition: music.h:49
Definition: console.h:31
Definition: lab.h:119
Definition: processroom.h:167
Definition: resource.h:94
Definition: dispman.h:38
Definition: system.h:167
Definition: input.h:69
Definition: movie_decoder.h:32
Definition: engine.h:143
Platform
Definition: platform.h:46