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  kDialogBoxTextID = 0x84,
78  kDialogBoxDiplomaID = 0x87
79 };
80 
81 enum {
82  kSaveGameStrID = 0x82,
83  kDiplomaFilenameID = 0x83,
84  kClickToContinueTextID = 0x84,
85  kStartGameFilenameID = 0x85
86 };
87 
88 enum FilePathID {
89  kMCVID = 1,
90  kTitlePathID = 2,
91  kSubdirPathID = 3,
92  kObjectPathID = 4,
93  kFilterPathID = 5,
94  kTextPathID = 6,
95  kGraphicPathID = 7,
96  kSoundPathID = 8
97 };
98 
99 const uint kMaxConsoleTextLength = 200000;
100 
102 public:
103  GlobalSettings();
104  ~GlobalSettings();
105 
106  void loadSettings(Common::SeekableReadStream *dataStream);
107 
108 // HACK MAybe this should be private, but the class is only here to handle
109 // memory allocation/deallocation
110 public:
111  uint16 _numObjects; // number of game objects defined
112  uint16 _numGlobals; // number of globals defined
113  uint16 _numCommands; // number of commands defined
114  uint16 _numAttributes; // number of attributes
115  uint16 _numGroups; // number of object groups
116  uint16 _invTop; // inventory window bounds
117  uint16 _invLeft;
118  uint16 _invHeight;
119  uint16 _invWidth;
120  uint16 _invOffsetY; // positioning offset for
121  uint16 _invOffsetX; // new inventory windows
122  uint16 _defaultFont; // default font
123  uint16 _defaultSize; // default font size
124  Common::Array<uint8> _attrIndices; // attribute indices into attribute table
125  Common::Array<uint16> _attrMasks; // attribute masks
126  Common::Array<uint8> _attrShifts; // attribute bit shifts
127  Common::Array<uint8> _cmdArgCnts; // command argument counts
128  Common::Array<uint8> _commands; // command buttons
129 };
130 
131 enum GameState {
132  kGameStateInit,
133  kGameStatePlaying,
134  kGameStateWinning,
135  kGameStateLosing,
136  kGameStateQuitting
137 };
138 
139 enum ObjectQueueID {
140  kFocusWindow = 2,
141  kOpenWindow = 3,
142  kCloseWindow = 4,
143  kUpdateObject = 7,
144  kUpdateWindow = 8,
145  kSetToPlayerParent = 12,
146  kHightlightExits = 13,
147  kAnimateBack = 14
148 };
149 
150 struct QueuedObject {
151  ObjectQueueID id;
152  ObjID object;
153  ObjID parent;
154  uint x;
155  uint y;
156  uint exitx;
157  uint exity;
158  bool hidden;
159  bool offscreen;
160  bool invisible;
161  ObjID target; // For swapping
162 };
163 
164 enum TextQueueID {
165  kTextNumber = 1,
166  kTextNewLine = 2,
167  kTextPlain = 3
168 };
169 
170 struct QueuedText {
171  TextQueueID id;
172  ObjID source;
173  ObjID destination;
174  ObjID asset;
175 };
176 
177 enum SoundQueueID {
178  kSoundPlay = 1,
179  kSoundPlayAndWait = 2,
180  kSoundWait = 3
181 };
182 
183 struct QueuedSound {
184  SoundQueueID id;
185  ObjID reference;
186 };
187 
188 struct Item {
189  ObjID id;
190  Common::Rect bounds;
191 };
192 
193 class Layout {
194 public:
195  void append(Item item) {
196  _items.push_back(item);
197  _width += 8 + item.bounds.width();
198  }
199 
200  Item remove(uint index) {
201  Item out = _items.remove_at(index);
202  _width -= 8 + out.bounds.width();
203  return out;
204  }
205 
206  Item at(uint index) {
207  return _items[index];
208  }
209 
210  inline uint size() const { return _items.size(); }
211  inline int width() const { return _width; }
212 
213 private:
214  int _width = 8;
215  Common::Array<Item> _items;
216 };
217 
218 class MacVentureEngine : public Engine {
219 
220 public:
221  MacVentureEngine(OSystem *syst, const ADGameDescription *gameDesc);
222  ~MacVentureEngine() override;
223 
224  void initializePath(const Common::FSNode &gamePath) override;
225 
226  bool hasFeature(EngineFeature f) const override;
227 
228  Common::Error run() override;
229 
230  bool scummVMSaveLoadDialog(bool isSave);
231  bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override;
232  bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override;
233  Common::Error loadGameState(int slot) override;
234  Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave = false) override;
235  void newGame();
236  void setInitialFlags(GameState gameState = kGameStateInit);
237  void setNewGameState();
238 
239  void reset();
240  void resetInternals();
241  void resetGui();
242  void refreshScreen();
243 
244  // datafiles.cpp
245  void loadDataBundle();
246  Common::SeekableReadStream *getBorderFile(MVWindowType windowType, bool isActive);
247 
248  void requestQuit();
249  void requestUnpause();
250  void selectControl(ControlAction action);
251  void refreshReady();
252  void preparedToRun();
253  void gameChanged();
254  void winGame();
255  void loseGame();
256  void clickToContinue();
257 
258  void updateState(bool pause);
259  void revert();
260 
261  void enqueueObject(ObjectQueueID type, ObjID objID, ObjID target = 0);
262  void enqueueText(TextQueueID type, ObjID target, ObjID source, ObjID text);
263  void enqueueSound(SoundQueueID type, ObjID target);
264 
265  void runObjQueue();
266  void printTexts();
267  void playSounds(bool pause);
268 
269  Item removeOutlier(Layout &layout, bool flag, Common::Rect rect);
270  void cleanUp(WindowReference reference);
271  void messUp(WindowReference reference);
272  void moveItems(Common::Array<Item> &items, WindowReference reference);
273 
274  void unselectAll();
275  void selectObject(ObjID objID);
276  void handleObjectSelect(ObjID objID, WindowReference win, bool shiftPressed, bool isDoubleClick);
277  void handleObjectDrop(ObjID objID, Common::Point delta, ObjID newParent);
278  void setDeltaPoint(Common::Point newPos);
279  void focusObjectWindow(ObjID objID);
280  void updateWindow(WindowReference winID);
281 
282  bool showTextEntry(ObjID text, ObjID srcObj, ObjID destObj);
283  void setTextInput(const Common::String &content);
284  Common::String getUserInput();
285 
286  // Data retrieval
287  Common::Path getDiplomaFileName();
288  Common::Path getStartGameFileName();
289  bool isPaused();
290  bool needsClickToContinue();
291  Common::String getCommandsPausedString() const;
292  const GlobalSettings &getGlobalSettings() const;
293  Common::Path getFilePath(FilePathID id) const;
294  bool isOldText() const;
295  const HuffmanLists *getDecodingHuffman() const;
296  uint32 randBetween(uint32 min, uint32 max);
297  uint32 getInvolvedObjects();
298  int findObjectInArray(ObjID objID, const Common::Array<ObjID> &list);
299  uint getPrefixNdx(ObjID obj);
300  Common::String getPrefixString(uint flag, ObjID obj);
301  Common::String getNoun(ObjID ndx);
302  ScriptEngine *getScriptEngine() const { return _scriptEngine; }
303  Common::Array<ObjID> &getSelectedObjects() { return _selectedObjs; }
304  GameState getGameState() const { return _gameState; }
305 
306  Common::String getConsoleText() const;
307  void setConsoleText(const Common::String &text);
308 
309  // Attributes consult
310  Common::Point getObjPosition(ObjID objID);
311  bool isObjVisible(ObjID objID);
312  bool isObjClickable(ObjID objID);
313  bool isObjSelected(ObjID objID);
314  bool isObjExit(ObjID objID);
315  bool isHiddenExit(ObjID objID);
316  Common::Point getObjExitPosition(ObjID objID);
317  ObjID getParent(ObjID objID);
318 
319  // Utils
320  ControlAction referenceToAction(ControlType id);
321 
322  // Encapsulation HACK
323  Common::Rect getObjBounds(ObjID objID);
324  uint getOverlapPercent(ObjID one, ObjID other);
325 
326  WindowReference getObjWindow(ObjID objID);
327  WindowReference findParentWindow(ObjID objID);
328 
329  Common::Point getDeltaPoint();
330  ObjID getDestObject();
331  ControlAction getSelectedControl();
332 
333 private:
334  void processEvents();
335 
336  bool runScriptEngine();
337  void endGame();
338  void updateControls();
339  void resetVars();
340 
341  void unselectObject(ObjID objID);
342  void highlightExit(ObjID objID);
343  void selectPrimaryObject(ObjID objID);
344  void updateExits();
345 
346  // Object queue methods
347  void openObject(ObjID objID);
348  void closeObject(ObjID objID);
349  void checkObject(QueuedObject objID);
350  void reflectSwap(ObjID fromID, ObjID toID);
351  void toggleExits();
352  void zoomObject(ObjID objID);
353 
354  bool isObjEnqueued(ObjID obj);
355 
356  bool isGameRunning();
357 
358  // Data loading
359  bool loadGlobalSettings();
360  bool loadTextHuffman();
361 
362  const char *getGameFileName() const;
363 
364  Common::String capitalize(const Common::String &str) const;
365 
366 private: // Attributes
367 
368  const ADGameDescription *_gameDescription;
369  Common::RandomSource *_rnd;
370 
371  Common::MacResManager *_resourceManager;
372 
373  Gui *_gui;
374  World *_world;
375  ScriptEngine *_scriptEngine;
376 
377  // String tables
378  StringTable *_filenames;
379  StringTable *_decodingDirectArticles;
380  StringTable *_decodingNamingArticles;
381  StringTable *_decodingIndirectArticles;
382 
383  SoundManager *_soundManager;
384 
385  Common::FSNode _gamePath;
386  Common::Archive *_dataBundle;
387 
388  // Engine state
389  GameState _gameState;
390  GlobalSettings *_globalSettings;
391  HuffmanLists *_textHuffman;
392  bool _oldTextEncoding;
393  bool _paused, _halted, _cmdReady, _prepared;
394  bool _haltedAtEnd, _haltedInSelection;
395  bool _gameChanged;
396  bool _clickToContinue;
397  bool _enginePaused;
398 
399  Common::Array<QueuedObject> _objQueue;
401  Common::Array<QueuedSound> _soundQueue;
402  Common::Array<QueuedText> _textQueue;
403 
404  // Selections
405  ObjID _destObject;
406  ControlAction _selectedControl;
407  Common::Array<ObjID> _currentSelection;
408  Common::Array<ObjID> _selectedObjs;
409  Common::Point _deltaPoint;
410  Common::String _userInput;
411 
412  Common::String _currentConsoleText;
413 };
414 
415 
416 class Console : public GUI::Debugger {
417 public:
418  Console(MacVentureEngine *vm) {}
419  ~Console(void) override {}
420 };
421 } // End of namespace MacVenture
422 
423 #endif
Definition: macresman.h:126
Definition: str.h:59
Definition: macventure.h:416
EngineFeature
Definition: engine.h:260
Definition: macventure.h:183
Definition: gui.h:92
Definition: error.h:81
Definition: advancedDetector.h:164
Definition: debugger.h:41
Definition: random.h:44
Definition: macventure.h:101
Definition: rect.h:524
Definition: path.h:52
Definition: macventure.h:150
Definition: stream.h:745
T width() const
Definition: rect.h:217
Definition: world.h:97
Definition: macventure.h:193
Definition: archive.h:141
Definition: ustr.h:57
Definition: sound.h:82
Definition: fs.h:69
Definition: hufflists.h:36
Definition: macventure.h:218
Definition: rect.h:144
Definition: macventure.h:188
Definition: container.h:38
Definition: stringtable.h:48
Definition: script.h:145
Definition: system.h:163
Definition: engine.h:146
Definition: macventure.h:170