ScummVM API documentation
bbvs.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 #ifndef BBVS_BBVS_H
23 #define BBVS_BBVS_H
24 
25 #include "audio/mixer.h"
26 
27 #include "common/array.h"
28 #include "common/events.h"
29 #include "common/file.h"
30 #include "common/memstream.h"
31 #include "common/random.h"
32 #include "common/str.h"
33 #include "common/substream.h"
34 #include "common/system.h"
35 
36 #include "engines/engine.h"
37 
38 #include "bbvs/detection.h"
39 
40 struct ADGameDescription;
41 
42 namespace Bbvs {
43 
44 class ActionCommands;
45 struct Action;
46 class GameModule;
47 struct Condition;
48 struct Conditions;
49 struct ActionResult;
50 struct ActionResults;
51 struct ActionCommand;
52 struct CameraInit;
53 struct SceneObjectDef;
54 struct SceneObjectInit;
55 struct SceneExit;
56 struct Animation;
57 struct SceneSound;
58 class DrawList;
59 class SpriteModule;
60 class Screen;
61 class SoundMan;
62 
63 #define BBVS_SAVEGAME_VERSION 0
64 
65 enum {
66  kVerbLook = 0,
67  kVerbUse = 1,
68  kVerbTalk = 2,
69  kVerbWalk = 3,
70  kVerbInvItem = 4,
71  kVerbShowInv = 5
72 };
73 
74 enum {
75  kITNone = 0,
76  kITEmpty = 1,
77  KITSceneObject = 2,
78  kITBgObject = 3,
79  kITDialog = 4,
80  kITScroll = 5,
81  kITSceneExit = 6,
82  kITInvItem = 7
83 };
84 
85 enum {
86  kGSScene = 0,
87  kGSInventory = 1,
88  kGSVerbs = 2,
89  kGSWait = 3,
90  kGSDialog = 4,
91  kGSWaitDialog = 5
92 };
93 
94 enum {
95  kActionCmdStop = 0,
96  kActionCmdWalkObject = 3,
97  kActionCmdMoveObject = 4,
98  kActionCmdAnimObject = 5,
99  kActionCmdSetCameraPos = 7,
100  kActionCmdPlaySpeech = 8,
101  kActionCmdPlaySound = 10,
102  kActionCmdStartBackgroundSound = 11,
103  kActionCmdStopBackgroundSound = 12
104 };
105 
106 enum {
107  kCondUnused = 1,
108  kCondSceneObjectVerb = 2,
109  kCondBgObjectVerb = 3,
110  kCondSceneObjectInventory = 4,
111  kCondBgObjectInventory = 5,
112  kCondHasInventoryItem = 6,
113  kCondHasNotInventoryItem = 7,
114  kCondIsGameVar = 8,
115  kCondIsNotGameVar = 9,
116  kCondIsPrevSceneNum = 10,
117  kCondIsCurrTalkObject = 11,
118  kCondIsDialogItem = 12,
119  kCondIsCameraNum = 13,
120  kCondIsNotPrevSceneNum = 14,
121  kCondDialogItem0 = 15,
122  kCondIsButtheadAtBgObject = 16,
123  kCondIsNotSceneVisited = 17,
124  kCondIsSceneVisited = 18,
125  kCondIsCameraNumTransition = 19
126 };
127 
128 enum {
129  kActResAddInventoryItem = 1,
130  kActResRemoveInventoryItem = 2,
131  kActResSetGameVar = 3,
132  kActResUnsetGameVar = 4,
133  kActResStartDialog = 5,
134  kActResChangeScene = 6
135 };
136 
137 enum {
138  kLeftButtonClicked = 1,
139  kRightButtonClicked = 2,
140  kLeftButtonDown = 4,
141  kRightButtonDown = 8,
142  kAnyButtonClicked = kLeftButtonClicked | kRightButtonClicked,
143  kAnyButtonDown = kLeftButtonDown | kRightButtonDown
144 };
145 
146 struct BBPoint {
147  int16 x, y;
148 };
149 
150 struct BBRect {
151  int16 x, y, width, height;
152 };
153 
154 struct BBPolygon {
155  const BBPoint *points;
156  int pointsCount;
157 };
158 
159 struct Rect {
160  int16 left, top, right, bottom;
161 };
162 
163 struct SceneObject {
164  uint32 x, y;
165  SceneObjectDef *sceneObjectDef;
166  Animation *anim;
167  int animIndex;
168  int frameIndex;
169  int frameTicks;
170  int walkCount;
171  int xIncr, yIncr;
172  int turnValue, turnCount, turnTicks;
173  Common::Point walkDestPt;
174 
175  SceneObject() {
176  clear();
177  }
178 
179  void clear() {
180  x = 0;
181  y = 0;
182  sceneObjectDef = nullptr;
183  anim = nullptr;
184  animIndex = 0;
185  frameIndex = 0;
186  frameTicks = 0;
187  walkCount = 0;
188  xIncr = 0;
189  yIncr = 0;
190  turnValue = 0;
191  turnCount = 0;
192  turnTicks = 0;
193  walkDestPt.x = 0;
194  walkDestPt.y = 0;
195  }
196 };
197 
199  int sceneObjectIndex;
200  int animationIndex;
201  Common::Point walkDest;
202 };
203 
204 struct WalkInfo {
205  int16 x, y;
206  int delta;
207  int direction;
208  Common::Point midPt;
209  int walkAreaIndex;
210 };
211 
212 struct WalkArea {
213  int16 x, y, width, height;
214  bool checked;
215  int linksCount;
216  WalkArea *links[16];
217  WalkInfo *linksD1[32];
218  WalkInfo *linksD2[32];
219  bool contains(const Common::Point &pt) const;
220 };
221 
222 const int kSnapshotSize = 23072;
223 const int kSceneObjectsCount = 64;
224 const int kSceneSoundsCount = 8;
225 const int kInventoryItemStatusCount = 50;
226 const int kDialogItemStatusCount = 50;
227 const int kGameVarsCount = 2000;
228 const int kSceneVisitedCount = 64;
229 
230 const int kMainMenu = 44;
231 const int kCredits = 45;
232 
233 const int kMaxDistance = 0xFFFFFF;
234 static const int8 kWalkTurnTbl[] = {
235  7, 9, 4, 8, 6, 10, 5, 11
236 };
237 
238 class BbvsEngine : public Engine {
239 protected:
240  Common::Error run() override;
241  bool hasFeature(EngineFeature f) const override;
242 public:
243  BbvsEngine(OSystem *syst, const ADGameDescription *gd);
244  ~BbvsEngine() override;
245  void newGame();
246  void continueGameFromQuickSave();
247  void setNewSceneNum(int newSceneNum);
248  const Common::String getTargetName() { return _targetName; }
249  const ADGameDescription *_gameDescription;
250 
251  bool isDemo() const;
252  bool isLoogieDemo() const;
253  bool isLoogieAltDemo() const;
254 
260  int getAutosaveSlot() const override { return -1; }
261 private:
262  Graphics::PixelFormat _pixelFormat;
263 
264 #ifdef USE_TRANSLATION
265  Common::String _oldGUILanguage;
266 #endif
267 
268 public:
269  Common::RandomSource *_random;
270 
271  GameModule *_gameModule;
272  SpriteModule *_spriteModule;
273  SoundMan *_sound;
274 
275  Screen *_screen;
276 
277  int _bootSaveSlot;
278 
279  int _mouseX, _mouseY;
280  uint _mouseButtons;
281  Common::KeyCode _keyCode;
282 
283  int _mouseCursorSpriteIndex;
284 
285  int _gameState;
286  int _gameTicks;
287 
288  Common::Point _mousePos;
289  Common::Point _verbPos;
290  Common::Point _walkMousePos;
291 
292  int _activeItemType;
293  int _activeItemIndex;
294  int _currTalkObjectIndex;
295 
296  Common::Point _cameraPos, _newCameraPos;
297 
298  int _newSceneNum, _prevSceneNum, _currSceneNum;
299  int _playVideoNumber;
300 
301  int _dialogSlotCount;
302  byte _dialogItemStatus[kDialogItemStatusCount];
303 
304  byte _gameVars[kGameVarsCount];
305  byte _sceneVisited[kSceneVisitedCount];
306 
307  int _currVerbNum;
308 
309  int _currInventoryItem;
310  byte _inventoryItemStatus[kInventoryItemStatusCount];
311  int _inventoryButtonIndex;
312 
313  Action *_currAction;
314  uint32 _currActionCommandTimeStamp;
315  int _currActionCommandIndex;
316 
317  Common::Array<Action*> _walkAreaActions;
318 
319  SceneObject _sceneObjects[kSceneObjectsCount];
320  Common::Array<SceneObjectAction> _sceneObjectActions;
321 
322  SceneObject *_buttheadObject, *_beavisObject;
323  int _currCameraNum;
324 
325  byte _backgroundSoundsActive[kSceneSoundsCount];
326  Audio::SoundHandle _speechSoundHandle;
327 
328  int _walkAreasCount;
329  WalkArea _walkAreas[80];
330  int _walkInfosCount;
331  WalkInfo _walkInfos[256];
332  int _walkableRectsCount;
333  Common::Rect _walkableRects[256];
334  Common::Rect _tempWalkableRects1[256];
335  Common::Rect _tempWalkableRects2[256];
336  WalkInfo *_walkInfoPtrs[256];
337 
338  WalkArea *_sourceWalkArea, *_destWalkArea;
339  Common::Point _sourceWalkAreaPt, _destWalkAreaPt, _finalWalkPt;
340  int _currWalkDistance;
341  bool _walkReachedDestArea;
342 
343  bool _hasSnapshot;
344  byte *_snapshot;
345  Common::SeekableMemoryWriteStream *_snapshotStream;
346 
347  char _easterEggInput[7];
348 
349  void updateEvents();
350  int getRandom(int max);
351 
352  void drawDebugInfo();
353  void drawScreen();
354 
355  void updateGame();
356 
357  bool evalCondition(Conditions &conditions);
358  bool evalCameraCondition(Conditions &conditions, int value);
359  int evalDialogCondition(Conditions &conditions);
360  void evalActionResults(ActionResults &results);
361 
362  void updateBackgroundSounds();
363 
364  void loadScene(int sceneNum);
365  void initScene(bool sounds);
366  bool changeScene();
367  bool update(int mouseX, int mouseY, uint mouseButtons, Common::KeyCode keyCode);
368 
369  void buildDrawList(DrawList &drawList);
370 
371  void updateVerbs();
372  void updateDialog(bool clicked);
373  void updateInventory(bool clicked);
374  void updateScene(bool clicked);
375 
376  bool performActionCommand(ActionCommand *actionCommand);
377  bool processCurrAction();
378  void skipCurrAction();
379 
380  void updateCommon();
381 
382  void updateWalkableRects();
383  void startWalkObject(SceneObject *sceneObject);
384  void updateWalkObject(SceneObject *sceneObject);
385  void walkObject(SceneObject *sceneObject, const Common::Point &destPt, int walkSpeed);
386  void turnObject(SceneObject *sceneObject);
387 
388  int rectSubtract(const Common::Rect &rect1, const Common::Rect &rect2, Common::Rect *outRects);
389 
390  WalkInfo *addWalkInfo(int16 x, int16 y, int delta, int direction, int16 midPtX, int16 midPtY, int walkAreaIndex);
391  void initWalkAreas(SceneObject *sceneObject);
392  WalkArea *getWalkAreaAtPos(const Common::Point &pt);
393  bool canButtheadWalkToDest(const Common::Point &destPt);
394  void canWalkToDest(WalkArea *walkArea, int infoCount);
395  bool walkTestLineWalkable(const Common::Point &sourcePt, const Common::Point &destPt, WalkInfo *walkInfo);
396  void walkFindPath(WalkArea *sourceWalkArea, int infoCount);
397  int calcDistance(const Common::Point &pt1, const Common::Point &pt2);
398  void walkFoundPath(int count);
399 
400  void updateSceneObjectsTurnValue();
401  void updateDialogConditions();
402 
403  void playSpeech(int soundNum);
404  void stopSpeech();
405 
406  void playSound(uint soundNum, bool loop = false);
407  void stopSound(uint soundNum);
408  void stopSounds();
409 
410  bool runMinigame(int minigameNum);
411  void playVideo(int videoNum);
412 
413  void runMainMenu();
414  void checkEasterEgg(char key);
415 
416  // Savegame API
417 
418  enum kReadSaveHeaderError {
419  kRSHENoError = 0,
420  kRSHEInvalidType = 1,
421  kRSHEInvalidVersion = 2,
422  kRSHEIoError = 3
423  };
424 
425  struct SaveHeader {
426  Common::String description;
427  uint32 version;
428  byte gameID;
429  uint32 flags;
430  uint32 saveDate;
431  uint32 saveTime;
432  uint32 playTime;
433  Graphics::Surface *thumbnail;
434  };
435 
436  bool _isSaveAllowed;
437 
438  bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override { return _isSaveAllowed; }
439  bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override { return _isSaveAllowed; }
440  Common::Error loadGameState(int slot) override;
441  Common::Error saveGameState(int slot, const Common::String &description, bool isAutosave = false) override;
442  void savegame(const char *filename, const char *description);
443  void loadgame(const char *filename);
444  bool existsSavegame(int num);
445  static Common::String getSavegameFilename(const Common::String &target, int num);
446  WARN_UNUSED_RESULT static kReadSaveHeaderError readSaveHeader(Common::SeekableReadStream *in, SaveHeader &header, bool skipThumbnail = true);
447 
448  void allocSnapshot();
449  void freeSnapshot();
450  void saveSnapshot();
451 
452  void writeContinueSavegame();
453 
454 };
455 
456 } // End of namespace Bbvs
457 
458 #endif // BBVS_BBVS_H
Definition: str.h:59
Definition: bbvs.h:425
Definition: surface.h:66
EngineFeature
Definition: engine.h:250
Definition: graphics.h:38
Definition: error.h:84
Definition: bbvs.h:146
Definition: graphics.h:43
Definition: pixelformat.h:138
Definition: advancedDetector.h:120
bool canSaveGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: bbvs.h:439
Definition: random.h:44
Definition: default_display_client.h:78
bool canLoadGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: bbvs.h:438
Definition: bbvs.h:150
Definition: rect.h:144
Definition: spritemodule.h:47
Definition: bbvs.h:163
Definition: stream.h:745
Definition: gamemodule.h:55
Definition: bbvs.h:159
Definition: bbvs.h:154
Definition: bbvs.h:204
Definition: mixer.h:49
Definition: bbvs.h:42
Definition: ustr.h:57
Definition: gamemodule.h:70
int getAutosaveSlot() const override
Definition: bbvs.h:260
Definition: rect.h:45
bool skipThumbnail(Common::SeekableReadStream &in)
Definition: bbvs.h:198
int16 x
Definition: rect.h:46
int16 y
Definition: rect.h:47
Definition: gamemodule.h:105
Definition: bbvs.h:238
Definition: bbvs.h:212
Definition: sound.h:49
Definition: gamemodule.h:87
Definition: system.h:167
Definition: engine.h:143
Definition: gamemodule.h:45
Definition: gamemodule.h:132
Definition: memstream.h:155
Definition: gamemodule.h:59