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