ScummVM API documentation
gnap.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 GNAP_GNAP_H
23 #define GNAP_GNAP_H
24 
25 #include "common/array.h"
26 #include "common/events.h"
27 #include "common/file.h"
28 #include "common/memstream.h"
29 #include "common/random.h"
30 #include "common/savefile.h"
31 #include "common/serializer.h"
32 #include "common/str.h"
33 #include "common/substream.h"
34 #include "common/system.h"
35 #include "engines/engine.h"
36 #include "graphics/pixelformat.h"
37 #include "graphics/fontman.h"
38 #include "graphics/font.h"
39 #include "graphics/fonts/ttf.h"
40 
41 #include "gnap/debugger.h"
42 #include "gnap/resource.h"
43 #include "gnap/scenes/scenecore.h"
44 #include "gnap/character.h"
45 #include "gnap/music.h"
46 
47 struct ADGameDescription;
48 
49 namespace Common {
50 class PEResources;
51 }
52 
53 namespace Gnap {
54 
55 class DatManager;
56 class SequenceResource;
57 class SpriteResource;
58 class GameSys;
59 class SoundMan;
60 class MusicPlayer;
61 
62 #define GNAP_SAVEGAME_VERSION 2
63 
65  bool _left;
66  bool _right;
67  MouseButtonState() : _left(false), _right(false) {
68  }
69 };
70 
71 struct Hotspot {
72  Common::Rect _rect;
73  uint16 _flags;
74 
75  bool isPointInside(Common::Point pos) const {
76  return _rect.contains(pos);
77  }
78 
79  bool isFlag(uint16 flag) const {
80  return (_flags & flag) != 0;
81  }
82 
83  void clearRect() {
84  _rect = Common::Rect(0, 0, 0, 0);
85  }
86 };
87 
88 const int kMaxTimers = 10;
89 
90 enum GnapDebugChannels {
91  kDebugBasic = 1 << 0,
92  kDebugMusic = 1 << 1
93 };
94 
95 enum {
96  SF_NONE = 0x0000,
97  SF_LOOK_CURSOR = 0x0001,
98  SF_GRAB_CURSOR = 0x0002,
99  SF_TALK_CURSOR = 0x0004,
100  SF_PLAT_CURSOR = 0x0008,
101  SF_DISABLED = 0x0010,
102  SF_WALKABLE = 0x0020,
103  SF_EXIT_L_CURSOR = 0x0040,
104  SF_EXIT_R_CURSOR = 0x0080,
105  SF_EXIT_U_CURSOR = 0x0100,
106  SF_EXIT_D_CURSOR = 0x0200,
107  SF_EXIT_NW_CURSOR = 0x0400,
108  SF_EXIT_NE_CURSOR = 0x0800,
109  SF_EXIT_SW_CURSOR = 0x1000,
110  SF_EXIT_SE_CURSOR = 0x2000
111 };
112 
113 enum {
114  LOOK_CURSOR = 0,
115  GRAB_CURSOR = 1,
116  TALK_CURSOR = 2,
117  PLAT_CURSOR = 3,
118  NOLOOK_CURSOR = 4,
119  NOGRAB_CURSOR = 5,
120  NOTALK_CURSOR = 6,
121  NOPLAT_CURSOR = 7,
122  EXIT_L_CURSOR = 8,
123  EXIT_R_CURSOR = 9,
124  EXIT_U_CURSOR = 10,
125  EXIT_D_CURSOR = 11,
126  EXIT_NE_CURSOR = 12,
127  EXIT_NW_CURSOR = 13,
128  EXIT_SE_CURSOR = 14,
129  EXIT_SW_CURSOR = 15,
130  WAIT_CURSOR = 16
131 };
132 
133 enum {
134  kGSPullOutDevice = 0,
135  kGSPullOutDeviceNonWorking = 1,
136  kGSIdle = 2,
137  kGSBrainPulsating = 3,
138  kGSImpossible = 4,
139  kGSScratchingHead = 5,
140  kGSDeflect = 6,
141  kGSUseDevice = 7,
142  kGSMoan1 = 8,
143  kGSMoan2 = 9
144 };
145 
146 enum {
147  kItemMagazine = 0,
148  kItemMud = 1,
149  kItemGrass = 2,
150  kItemDisguise = 3,
151  kItemNeedle = 4,
152  kItemTwig = 5,
153  kItemGas = 6,
154  kItemKeys = 7,
155  kItemDice = 8,
156  kItemTongs = 9,
157  kItemQuarter = 10,
158  kItemQuarterWithHole = 11,
159  kItemDiceQuarterHole = 12,
160  kItemWrench = 13,
161  kItemCowboyHat = 14,
162  kItemGroceryStoreHat = 15,
163  kItemBanana = 16,
164  kItemTickets = 17,
165  kItemPicture = 18,
166  kItemEmptyBucket = 19,
167  kItemBucketWithBeer = 20,
168  kItemBucketWithPill = 21,
169  kItemPill = 22,
170  kItemHorn = 23,
171  kItemJoint = 24,
172  kItemChickenBucket = 25,
173  kItemGum = 26,
174  kItemSpring = 27,
175  kItemLightbulb = 28,
176  kItemCereals = 29
177 };
178 
179 enum {
180  kGFPlatypus = 0,
181  kGFMudTaken = 1,
182  kGFNeedleTaken = 2,
183  kGFTwigTaken = 3,
184  kGFUnk04 = 4,
185  kGFKeysTaken = 5,
186  kGFGrassTaken = 6,
187  kGFBarnPadlockOpen = 7,
188  kGFTruckFilledWithGas = 8,
189  kGFTruckKeysUsed = 9,
190  kGFPlatypusDisguised = 10,
191  kGFSceneFlag1 = 11,
192  kGFGnapControlsToyUFO = 12,
193  kGFUnk13 = 13, // Tongue Fight Won?
194  kGFUnk14 = 14,
195  kGFSpringTaken = 15,
196  kGFUnk16 = 16,
197  kGFJointTaken = 17,
198  kGFUnk18 = 18,
199  kGFGroceryStoreHatTaken = 19,
200  kGFPictureTaken = 20,
201  kGFUnk21 = 21,
202  kGFUnk22 = 22,
203  kGFUnk23 = 23,
204  kGFUnk24 = 24,
205  kGFUnk25 = 25,
206  kGFPlatypusTalkingToAssistant = 26,
207  kGFUnk27 = 27,
208  kGFUnk28 = 28,
209  kGFGasTaken = 29,
210  kGFUnk30 = 30,
211  kGFUnk31 = 31
212 };
213 
215  uint8 _version;
216  Common::String _saveName;
217  Graphics::Surface *_thumbnail;
218  int _year, _month, _day;
219  int _hour, _minute;
220 };
221 
222 class GnapEngine : public Engine {
223 protected:
224  Common::Error run() override;
225  bool hasFeature(EngineFeature f) const override;
226 public:
227  GnapEngine(OSystem *syst, const ADGameDescription *gd);
228  ~GnapEngine() override;
229 private:
230  const ADGameDescription *_gameDescription;
231  Graphics::PixelFormat _pixelFormat;
232  int _loadGameSlot;
233 
234 public:
235  Common::RandomSource *_random;
236  Common::PEResources *_exe;
237 
238  DatManager *_dat;
239  SpriteCache *_spriteCache;
240  SoundCache *_soundCache;
241  SequenceCache *_sequenceCache;
242  GameSys *_gameSys;
243  SoundMan *_soundMan;
244  Debugger *_debugger;
245  Scene *_scene;
246  PlayerGnap *_gnap;
247  PlayerPlat *_plat;
248  MusicPlayer *_music;
249  Graphics::Font *_font;
250 
251  Common::MemoryWriteStreamDynamic *_tempThumbnail;
252 
253  int _lastUpdateClock;
254  bool _gameDone;
255 
256  bool _keyPressState[512];
257  bool _keyDownState[512];
258 
259  bool _isPaused;
260  Graphics::Surface *_pauseSprite;
261  int _timers[kMaxTimers], _savedTimers[kMaxTimers];
262 
263  MouseButtonState _mouseButtonState;
264  MouseButtonState _mouseClickState;
265 
266  bool _sceneSavegameLoaded, _wasSavegameLoaded;
267 
268  Graphics::Surface *_backgroundSurface;
269  int _prevSceneNum, _currentSceneNum, _newSceneNum;
270  bool _sceneDone, _sceneWaiting;
271 
272  uint32 _inventory, _gameFlags;
273 
274  Hotspot _hotspots[20];
275  Common::Point _hotspotsWalkPos[20];
276  int _hotspotsCount;
277  int _sceneClickedHotspot;
278 
279  bool _isWaiting;
280  bool _isLeavingScene;
281 
282  bool _isStockDatLoaded;
283 
284  int _newCursorValue, _cursorValue;
285 
286  int _verbCursor, _cursorIndex;
287  Common::Point _mousePos;
288  int _leftClickMouseX, _leftClickMouseY;
289 
290  Graphics::Surface *_grabCursorSprite;
291  int _currGrabCursorX, _currGrabCursorY;
292  int _grabCursorSpriteIndex, _newGrabCursorSpriteIndex;
293 
294  Graphics::Surface *_fullScreenSprite;
295  int _fullScreenSpriteId;
296 
297  int _deviceX1, _deviceY1;
298 
299  int _soundTimerIndexA;
300  int _soundTimerIndexB;
301  int _soundTimerIndexC;
302  int _idleTimerIndex;
303 
304  void updateEvents();
305  void gameUpdateTick();
306  void saveTimers();
307  void restoreTimers();
308 
309  void pauseGame();
310  void resumeGame();
311  void updatePause();
312 
313  int getRandom(int max);
314 
315  int readSavegameDescription(int savegameNum, Common::String &description);
316  int loadSavegame(int savegameNum);
317  Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave = false) override;
318  Common::Error loadGameState(int slot) override;
319  void synchronize(Common::Serializer &s);
320  void writeSavegameHeader(Common::OutSaveFile *out, GnapSavegameHeader &header);
321  WARN_UNUSED_RESULT static bool readSavegameHeader(Common::InSaveFile *in, GnapSavegameHeader &header, bool skipThumbnail = true);
322 
323  void delayTicks(int val, int idx, bool updateCursor);
324  void delayTicksA(int val, int idx);
325  void delayTicksCursor(int val);
326 
327  void setHotspot(int index, int16 x1, int16 y1, int16 x2, int16 y2, uint16 flags = SF_NONE,
328  int16 walkX = -1, int16 walkY = -1);
329  int getHotspotIndexAtPos(Common::Point pos);
330  void updateCursorByHotspot();
331  int getClickedHotspotId();
332 
333  int getInventoryItemSpriteNum(int index);
334 
335  void updateMouseCursor();
336  void setVerbCursor(int verbCursor);
337  void setCursor(int cursorIndex);
338  void showCursor();
339  void hideCursor();
340 
341  void setGrabCursorSprite(int index);
342  void createGrabCursorSprite(int spriteId);
343  void freeGrabCursorSprite();
344  void updateGrabCursorSprite(int x, int y);
345 
346  void invClear();
347  void invAdd(int itemId);
348  void invRemove(int itemId);
349  bool invHas(int itemId);
350 
351  void clearFlags();
352  void setFlag(int num);
353  void clearFlag(int num);
354  bool isFlag(int num);
355 
356  Graphics::Surface *addFullScreenSprite(int resourceId, int id);
357  void removeFullScreenSprite();
358  void showFullScreenSprite(int resourceId);
359 
360  void queueInsertDeviceIcon();
361  void insertDeviceIconActive();
362  void removeDeviceIconActive();
363  void setDeviceHotspot(int hotspotIndex, int x1, int y1, int x2, int y2);
364 
365  int getSequenceTotalDuration(int resourceId);
366 
367  bool isSoundPlaying(int resourceId);
368  void playSound(int resourceId, bool looping);
369  void stopSound(int resourceId);
370  void setSoundVolume(int resourceId, int volume);
371 
372  void updateTimers();
373 
374  void initGameFlags(int num);
375  void loadStockDat();
376 
377  void mainLoop();
378  void initScene();
379  void endSceneInit();
380  void afterScene();
381 
382  int initSceneLogic();
383  void runSceneLogic();
384 
385  void checkGameKeys();
386 
387  void startSoundTimerA(int timerIndex);
388  int playSoundA();
389  void startSoundTimerB(int timerIndex);
390  int playSoundB();
391  void startSoundTimerC(int timerIndex);
392  int playSoundC();
393  void startIdleTimer(int timerIndex);
394  void updateIdleTimer();
395 
396  void screenEffect(int dir, byte r, byte g, byte b);
397 
398  bool isKeyStatus1(int key);
399  bool isKeyStatus2(int key);
400  void clearKeyStatus1(int key);
401  void clearAllKeyStatus1();
402 
403  void deleteSurface(Graphics::Surface **surface);
404 
405  // Menu
406  int _menuStatus;
407  int _menuSpritesIndex;
408  bool _menuDone;
409  Graphics::Surface *_menuBackgroundSurface;
410  Graphics::Surface *_menuQuitQuerySprite;
411  Graphics::Surface *_largeSprite;
412  Graphics::Surface *_menuSaveLoadSprite;
413  Graphics::Surface *_menuSprite2;
414  Graphics::Surface *_menuSprite1;
415  char _savegameFilenames[7][30];
416  Graphics::Surface *_savegameSprites[7];
417  Graphics::Surface *_spriteHandle;
418  Graphics::Surface *_cursorSprite;
419  int _menuInventoryIndices[30];
420  Graphics::Surface *_menuInventorySprites[30];
421  int _savegameIndex;
422  void createMenuSprite();
423  void freeMenuSprite();
424  void initMenuHotspots1();
425  void initMenuHotspots2();
426  void initMenuQuitQueryHotspots();
427  void initSaveLoadHotspots();
428  void drawInventoryFrames();
429  void insertInventorySprites();
430  void removeInventorySprites();
431  void runMenu();
432  void updateMenuStatusInventory();
433  void updateMenuStatusMainMenu();
434  void updateMenuStatusSaveGame();
435  void updateMenuStatusLoadGame();
436  void updateMenuStatusQueryQuit();
437 
438  // Grid common
439  int _gridMinX, _gridMinY;
440  int _gridMaxX, _gridMaxY;
441  bool isPointBlocked(int gridX, int gridY);
442  bool isPointBlocked(Common::Point gridPos);
443  void initSceneGrid(int gridMinX, int gridMinY, int gridMaxX, int gridMaxY);
444  bool testWalk(int animationIndex, int someStatus, int gridX1, int gridY1, int gridX2, int gridY2);
445 
446  // Gnap
447  void doCallback(int callback);
448 
449  // Scenes
450  int _toyUfoNextSequenceId, _toyUfoSequenceId;
451  int _toyUfoId;
452  int _toyUfoActionStatus;
453  int _toyUfoX;
454  int _toyUfoY;
455 
456  void initGlobalSceneVars();
457  void playSequences(int fullScreenSpriteId, int sequenceId1, int sequenceId2, int sequenceId3);
458 
459  // Shared by scenes 17 & 18
460  int _s18GarbageCanPos;
461 
462  // Scene 4x
463  void toyUfoSetStatus(int flagNum);
464  int toyUfoGetSequenceId();
465  bool toyUfoCheckTimer();
466  void toyUfoFlyTo(int destX, int destY, int minX, int maxX, int minY, int maxY, int animationIndex);
467 
468  void playMidi(const char *name);
469  void stopMidi();
470 };
471 
472 } // End of namespace Gnap
473 
474 #endif // GNAP_GNAP_H
Definition: str.h:59
Definition: font.h:83
Definition: winexe_pe.h:48
Definition: surface.h:67
EngineFeature
Definition: engine.h:253
Definition: character.h:79
Definition: savefile.h:54
Definition: error.h:84
Definition: pixelformat.h:138
Definition: advancedDetector.h:163
bool contains(int16 x, int16 y) const
Definition: rect.h:210
Definition: random.h:44
Definition: rect.h:144
Definition: memstream.h:194
Definition: gnap.h:214
Definition: stream.h:745
Definition: gnap.h:64
Definition: serializer.h:79
Definition: datarchive.h:60
Definition: algorithm.h:29
Definition: rect.h:45
bool skipThumbnail(Common::SeekableReadStream &in)
Definition: character.h:25
Definition: gnap.h:222
Definition: sound.h:37
Definition: resource.h:109
Definition: system.h:161
Definition: character.h:123
Definition: scenecore.h:31
Definition: gnap.h:71
Definition: engine.h:144
Definition: gamesys.h:99
Definition: music.h:33
Definition: debugger.h:32