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
55
56namespace MacVenture {
57
58class SaveFileManager;
59
60class Console;
61class World;
62class ScriptEngine;
63
64class SoundManager;
65
66typedef uint32 ObjID;
67
68enum {
69 kScreenWidth = 512,
70 kScreenHeight = 342
71};
72
73enum {
74 kGlobalSettingsID = 0x80,
75 kDiplomaGeometryID = 0x81,
76 kTextHuffmanTableID = 0x83,
77 kDialogBoxTextID = 0x84,
78 kDialogBoxDiplomaID = 0x87
79};
80
81enum {
82 kSaveGameStrID = 0x82,
83 kDiplomaFilenameID = 0x83,
84 kClickToContinueTextID = 0x84,
85 kStartGameFilenameID = 0x85
86};
87
88enum 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
99const uint kMaxConsoleTextLength = 200000;
100
102public:
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
110public:
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
131enum GameState {
132 kGameStateInit,
133 kGameStatePlaying,
134 kGameStateWinning,
135 kGameStateLosing,
136 kGameStateQuitting
137};
138
139enum 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
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
164enum TextQueueID {
165 kTextNumber = 1,
166 kTextNewLine = 2,
167 kTextPlain = 3
168};
169
171 TextQueueID id;
172 ObjID source;
173 ObjID destination;
174 ObjID asset;
175};
176
177enum SoundQueueID {
178 kSoundPlay = 1,
179 kSoundPlayAndWait = 2,
180 kSoundWait = 3
181};
182
184 SoundQueueID id;
185 ObjID reference;
186};
187
188struct Item {
189 ObjID id;
190 Common::Rect bounds;
191};
192
193class Layout {
194public:
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
213private:
214 int _width = 8;
215 Common::Array<Item> _items;
216};
217
218class MacVentureEngine : public Engine {
219
220public:
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 isObjDraggable(ObjID objID);
314 bool isObjSelected(ObjID objID);
315 bool isObjExit(ObjID objID);
316 bool isHiddenExit(ObjID objID);
317 Common::Point getObjExitPosition(ObjID objID);
318 ObjID getParent(ObjID objID);
319
320 // Utils
321 ControlAction referenceToAction(ControlType id);
322
323 // Encapsulation HACK
324 Common::Rect getObjBounds(ObjID objID);
325 uint getOverlapPercent(ObjID one, ObjID other);
326
327 WindowReference getObjWindow(ObjID objID);
328 WindowReference findParentWindow(ObjID objID);
329
330 Common::Point getDeltaPoint();
331 ObjID getDestObject();
332 ControlAction getSelectedControl();
333
334private:
335 void processEvents();
336
337 bool runScriptEngine();
338 void endGame();
339 void updateControls();
340 void resetVars();
341
342 void unselectObject(ObjID objID);
343 void highlightExit(ObjID objID);
344 void selectPrimaryObject(ObjID objID);
345 void updateExits();
346
347 // Object queue methods
348 void openObject(ObjID objID);
349 void closeObject(ObjID objID);
350 void checkObject(QueuedObject objID);
351 void reflectSwap(ObjID fromID, ObjID toID);
352 void toggleExits();
353 void zoomObject(ObjID objID);
354
355 bool isObjEnqueued(ObjID obj);
356
357 bool isGameRunning();
358
359 // Data loading
360 bool loadGlobalSettings();
361 bool loadTextHuffman();
362
363 const char *getGameFileName() const;
364
365 Common::String capitalize(const Common::String &str) const;
366
367private: // Attributes
368
369 const ADGameDescription *_gameDescription;
371
372 Common::MacResManager *_resourceManager;
373
374 Gui *_gui;
375 World *_world;
376 ScriptEngine *_scriptEngine;
377
378 // String tables
379 StringTable *_filenames;
380 StringTable *_decodingDirectArticles;
381 StringTable *_decodingNamingArticles;
382 StringTable *_decodingIndirectArticles;
383
384 SoundManager *_soundManager;
385
386 Common::FSNode _gamePath;
387 Common::Archive *_dataBundle;
388
389 // Engine state
390 GameState _gameState;
391 GlobalSettings *_globalSettings;
392 HuffmanLists *_textHuffman;
393 bool _oldTextEncoding;
394 bool _paused, _halted, _cmdReady, _prepared;
395 bool _haltedAtEnd, _haltedInSelection;
396 bool _gameChanged;
397 bool _clickToContinue;
398 bool _enginePaused;
399 uint32 _nextFrameTime;
400 uint _consoleRowsSincePause;
401
404 Common::Array<QueuedSound> _soundQueue;
405 Common::Array<QueuedText> _textQueue;
406
407 // Selections
408 ObjID _destObject;
409 ControlAction _selectedControl;
410 Common::Array<ObjID> _currentSelection;
411 Common::Array<ObjID> _selectedObjs;
412 Common::Point _deltaPoint;
413 Common::String _userInput;
414
415 Common::String _currentConsoleText;
416};
417
418
419class Console : public GUI::Debugger {
420public:
422 ~Console(void) override {}
423};
424} // End of namespace MacVenture
425
426#endif
Definition: archive.h:141
T remove_at(size_type idx)
Definition: array.h:261
size_type size() const
Definition: array.h:316
void push_back(const T &element)
Definition: array.h:181
Definition: error.h:81
Definition: fs.h:69
Definition: macresman.h:126
Definition: path.h:52
Definition: random.h:44
Definition: stream.h:745
Definition: str.h:59
Definition: ustr.h:57
Definition: engine.h:155
EngineFeature
Definition: engine.h:293
Definition: debugger.h:41
Definition: macventure.h:419
Definition: macventure.h:101
Definition: hufflists.h:36
Definition: macventure.h:193
Definition: macventure.h:218
Common::Error run() override
bool canLoadGameStateCurrently(Common::U32String *msg=nullptr) override
bool hasFeature(EngineFeature f) const override
bool canSaveGameStateCurrently(Common::U32String *msg=nullptr) override
Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave=false) override
void initializePath(const Common::FSNode &gamePath) override
Common::Error loadGameState(int slot) override
Definition: script.h:145
Definition: system.h:166
Definition: advancedDetector.h:164
Definition: rect.h:144
T width() const
Definition: rect.h:217
Definition: rect.h:536
Definition: macventure.h:188
Definition: macventure.h:150
Definition: macventure.h:183
Definition: macventure.h:170