ScummVM API documentation
macventure.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  * Based on
24  * WebVenture (c) 2010, Sean Kasun
25  * https://github.com/mrkite/webventure, http://seancode.com/webventure/
26  *
27  * Used with explicit permission from the author
28  */
29 
30 #ifndef MACVENTURE_MACVENTURE_H
31 #define MACVENTURE_MACVENTURE_H
32 
33 #include "engines/engine.h"
34 #include "common/scummsys.h"
35 #include "common/system.h"
36 #include "common/debug.h"
37 #include "common/random.h"
38 #include "common/macresman.h"
39 #include "common/compression/huffman.h"
40 #include "common/savefile.h"
41 
42 #include "gui/debugger.h"
43 
44 #include "macventure/debug.h"
45 #include "macventure/gui.h"
46 #include "macventure/world.h"
47 #include "macventure/hufflists.h"
48 #include "macventure/stringtable.h"
49 #include "macventure/script.h"
50 #include "macventure/controls.h"
51 #include "macventure/windows.h"
52 #include "macventure/sound.h"
53 
54 struct ADGameDescription;
55 
56 namespace MacVenture {
57 
58 class SaveFileManager;
59 
60 class Console;
61 class World;
62 class ScriptEngine;
63 
64 class SoundManager;
65 
66 typedef uint32 ObjID;
67 
68 enum {
69  kScreenWidth = 512,
70  kScreenHeight = 342
71 };
72 
73 enum {
74  kGlobalSettingsID = 0x80,
75  kDiplomaGeometryID = 0x81,
76  kTextHuffmanTableID = 0x83
77 };
78 
79 enum {
80  kSaveGameStrID = 0x82,
81  kDiplomaFilenameID = 0x83,
82  kClickToContinueTextID = 0x84,
83  kStartGameFilenameID = 0x85
84 };
85 
86 enum FilePathID {
87  kMCVID = 1,
88  kTitlePathID = 2,
89  kSubdirPathID = 3,
90  kObjectPathID = 4,
91  kFilterPathID = 5,
92  kTextPathID = 6,
93  kGraphicPathID = 7,
94  kSoundPathID = 8
95 };
96 
97 
99 public:
100  GlobalSettings();
101  ~GlobalSettings();
102 
103  void loadSettings(Common::SeekableReadStream *dataStream);
104 
105 // HACK MAybe this should be private, but the class is only here to handle
106 // memory allocation/deallocation
107 public:
108  uint16 _numObjects; // number of game objects defined
109  uint16 _numGlobals; // number of globals defined
110  uint16 _numCommands; // number of commands defined
111  uint16 _numAttributes; // number of attributes
112  uint16 _numGroups; // number of object groups
113  uint16 _invTop; // inventory window bounds
114  uint16 _invLeft;
115  uint16 _invHeight;
116  uint16 _invWidth;
117  uint16 _invOffsetY; // positioning offset for
118  uint16 _invOffsetX; // new inventory windows
119  uint16 _defaultFont; // default font
120  uint16 _defaultSize; // default font size
121  Common::Array<uint8> _attrIndices; // attribute indices into attribute table
122  Common::Array<uint16> _attrMasks; // attribute masks
123  Common::Array<uint8> _attrShifts; // attribute bit shifts
124  Common::Array<uint8> _cmdArgCnts; // command argument counts
125  Common::Array<uint8> _commands; // command buttons
126 };
127 
128 enum GameState {
129  kGameStateInit,
130  kGameStatePlaying,
131  kGameStateWinnig,
132  kGameStateLosing,
133  kGameStateQuitting
134 };
135 
136 enum ObjectQueueID {
137  kFocusWindow = 2,
138  kOpenWindow = 3,
139  kCloseWindow = 4,
140  kUpdateObject = 7,
141  kUpdateWindow = 8,
142  kSetToPlayerParent = 12,
143  kHightlightExits = 13,
144  kAnimateBack = 14
145 };
146 
147 struct QueuedObject {
148  ObjectQueueID id;
149  ObjID object;
150  ObjID parent;
151  uint x;
152  uint y;
153  uint exitx;
154  uint exity;
155  bool hidden;
156  bool offscreen;
157  bool invisible;
158  ObjID target; // For swapping
159 };
160 
161 enum TextQueueID {
162  kTextNumber = 1,
163  kTextNewLine = 2,
164  kTextPlain = 3
165 };
166 
167 struct QueuedText {
168  TextQueueID id;
169  ObjID source;
170  ObjID destination;
171  ObjID asset;
172 };
173 
174 enum SoundQueueID {
175  kSoundPlay = 1,
176  kSoundPlayAndWait = 2,
177  kSoundWait = 3
178 };
179 
180 struct QueuedSound {
181  SoundQueueID id;
182  ObjID reference;
183 };
184 
185 class MacVentureEngine : public Engine {
186 
187 public:
188  MacVentureEngine(OSystem *syst, const ADGameDescription *gameDesc);
189  ~MacVentureEngine() override;
190 
191  bool hasFeature(EngineFeature f) const override;
192 
193  Common::Error run() override;
194 
195  bool scummVMSaveLoadDialog(bool isSave);
196  bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override;
197  bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override;
198  Common::Error loadGameState(int slot) override;
199  Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave = false) override;
200  void newGame();
201  void setInitialFlags();
202  void setNewGameState();
203 
204  void reset();
205  void resetInternals();
206  void resetGui();
207  void refreshScreen();
208 
209  // datafiles.cpp
210  void loadDataBundle();
211  Common::SeekableReadStream *getBorderFile(MVWindowType windowType, bool isActive);
212 
213  void requestQuit();
214  void requestUnpause();
215  void selectControl(ControlAction action);
216  void refreshReady();
217  void preparedToRun();
218  void gameChanged();
219  void winGame();
220  void loseGame();
221  void clickToContinue();
222 
223  void updateState(bool pause);
224  void revert();
225 
226  void enqueueObject(ObjectQueueID type, ObjID objID, ObjID target = 0);
227  void enqueueText(TextQueueID type, ObjID target, ObjID source, ObjID text);
228  void enqueueSound(SoundQueueID type, ObjID target);
229 
230  void runObjQueue();
231  void printTexts();
232  void playSounds(bool pause);
233 
234  void handleObjectSelect(ObjID objID, WindowReference win, bool shiftPressed, bool isDoubleClick);
235  void handleObjectDrop(ObjID objID, Common::Point delta, ObjID newParent);
236  void setDeltaPoint(Common::Point newPos);
237  void focusObjWin(ObjID objID);
238  void updateWindow(WindowReference winID);
239 
240  bool showTextEntry(ObjID text, ObjID srcObj, ObjID destObj);
241  void setTextInput(const Common::String &content);
242  Common::String getUserInput();
243 
244  // Data retrieval
245  Common::Path getStartGameFileName();
246  bool isPaused();
247  bool needsClickToContinue();
248  Common::String getCommandsPausedString() const;
249  const GlobalSettings &getGlobalSettings() const;
250  Common::Path getFilePath(FilePathID id) const;
251  bool isOldText() const;
252  const HuffmanLists *getDecodingHuffman() const;
253  uint32 randBetween(uint32 min, uint32 max);
254  uint32 getInvolvedObjects();
255  int findObjectInArray(ObjID objID, const Common::Array<ObjID> &list);
256  uint getPrefixNdx(ObjID obj);
257  Common::String getPrefixString(uint flag, ObjID obj);
258  Common::String getNoun(ObjID ndx);
259 
260  // Attributes consult
261  Common::Point getObjPosition(ObjID objID);
262  bool isObjVisible(ObjID objID);
263  bool isObjClickable(ObjID objID);
264  bool isObjSelected(ObjID objID);
265  bool isObjExit(ObjID objID);
266  bool isHiddenExit(ObjID objID);
267  Common::Point getObjExitPosition(ObjID objID);
268  ObjID getParent(ObjID objID);
269 
270  // Utils
271  ControlAction referenceToAction(ControlType id);
272 
273  // Encapsulation HACK
274  Common::Rect getObjBounds(ObjID objID);
275  uint getOverlapPercent(ObjID one, ObjID other);
276 
277  WindowReference getObjWindow(ObjID objID);
278  WindowReference findParentWindow(ObjID objID);
279 
280  Common::Point getDeltaPoint();
281  ObjID getDestObject();
282  ControlAction getSelectedControl();
283 
284 private:
285  void processEvents();
286 
287  bool runScriptEngine();
288  void endGame();
289  void updateControls();
290  void resetVars();
291 
292  void unselectAll();
293  void selectObject(ObjID objID);
294  void unselectObject(ObjID objID);
295  void highlightExit(ObjID objID);
296  void selectPrimaryObject(ObjID objID);
297  void updateExits();
298 
299  // Object queue methods
300  void focusObjectWindow(ObjID objID);
301  void openObject(ObjID objID);
302  void closeObject(ObjID objID);
303  void checkObject(QueuedObject objID);
304  void reflectSwap(ObjID fromID, ObjID toID);
305  void toggleExits();
306  void zoomObject(ObjID objID);
307 
308  bool isObjEnqueued(ObjID obj);
309 
310  bool isGameRunning();
311 
312  // Data loading
313  bool loadGlobalSettings();
314  bool loadTextHuffman();
315 
316  const char *getGameFileName() const;
317 
318 private: // Attributes
319 
320  const ADGameDescription *_gameDescription;
321  Common::RandomSource *_rnd;
322 
323  Common::MacResManager *_resourceManager;
324 
325  Gui *_gui;
326  World *_world;
327  ScriptEngine *_scriptEngine;
328 
329  // String tables
330  StringTable *_filenames;
331  StringTable *_decodingDirectArticles;
332  StringTable *_decodingNamingArticles;
333  StringTable *_decodingIndirectArticles;
334 
335  SoundManager *_soundManager;
336 
337  Common::Archive *_dataBundle;
338 
339  // Engine state
340  GameState _gameState;
341  GlobalSettings *_globalSettings;
342  HuffmanLists *_textHuffman;
343  bool _oldTextEncoding;
344  bool _paused, _halted, _cmdReady, _prepared;
345  bool _haltedAtEnd, _haltedInSelection;
346  bool _gameChanged;
347  bool _clickToContinue;
348 
349  Common::Array<QueuedObject> _objQueue;
351  Common::Array<QueuedSound> _soundQueue;
352  Common::Array<QueuedText> _textQueue;
353 
354  // Selections
355  ObjID _destObject;
356  ControlAction _selectedControl;
357  Common::Array<ObjID> _currentSelection;
358  Common::Point _deltaPoint;
359  Common::String _userInput;
360 
361 };
362 
363 
364 class Console : public GUI::Debugger {
365 public:
366  Console(MacVentureEngine *vm) {}
367  ~Console(void) override {}
368 };
369 } // End of namespace MacVenture
370 
371 #endif
Definition: macresman.h:125
Definition: str.h:59
Definition: macventure.h:364
EngineFeature
Definition: engine.h:253
Definition: macventure.h:180
Definition: gui.h:92
Definition: error.h:84
Definition: advancedDetector.h:163
Definition: debugger.h:41
Definition: random.h:44
Definition: macventure.h:98
Definition: rect.h:144
Definition: path.h:52
Definition: macventure.h:147
Definition: stream.h:745
Definition: world.h:97
Definition: archive.h:141
Definition: ustr.h:57
Definition: sound.h:82
Definition: hufflists.h:36
Definition: macventure.h:185
Definition: rect.h:45
Definition: container.h:38
Definition: stringtable.h:48
Definition: script.h:145
Definition: system.h:161
Definition: engine.h:144
Definition: macventure.h:167