scummvm/engines/gnap/gnap.h

503 lines
12 KiB
C
Raw Normal View History

2014-01-07 20:37:29 +00:00
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef GNAP_H
#define GNAP_H
#include "common/array.h"
#include "common/events.h"
#include "common/file.h"
#include "common/memstream.h"
#include "common/random.h"
#include "common/savefile.h"
#include "common/serializer.h"
2014-01-07 20:37:29 +00:00
#include "common/str.h"
#include "common/substream.h"
#include "common/system.h"
#include "common/winexe.h"
#include "common/winexe_pe.h"
#include "engines/engine.h"
#include "graphics/pixelformat.h"
#include "graphics/wincursor.h"
2016-04-12 05:26:30 +00:00
#include "gnap/debugger.h"
2014-01-07 20:37:29 +00:00
#include "gnap/resource.h"
2016-04-19 05:57:07 +00:00
#include "gnap/scenes/scenecore.h"
2016-05-04 05:13:48 +00:00
#include "gnap/character.h"
2014-01-07 20:37:29 +00:00
struct ADGameDescription;
namespace Gnap {
class DatManager;
class SequenceResource;
class SpriteResource;
class GameSys;
class SoundMan;
#define GNAP_SAVEGAME_VERSION 1
2014-01-07 20:37:29 +00:00
struct MouseButtonState {
bool _left;
bool _right;
MouseButtonState() : _left(false), _right(false) {
2014-01-07 20:37:29 +00:00
}
};
struct Hotspot {
int16 _x1, _y1, _x2, _y2;
uint16 _flags;
int _id;
2014-01-07 20:37:29 +00:00
bool isPointInside(int16 x, int16 y) const {
return x >= _x1 && x <= _x2 && y >= _y1 && y <= _y2;
2014-01-07 20:37:29 +00:00
}
bool isFlag(uint16 flag) const {
return (_flags & flag) != 0;
2014-01-07 20:37:29 +00:00
}
};
const int kMaxTimers = 10;
2016-04-12 06:00:11 +00:00
enum GnapDebugChannels {
kDebugBasic = 1 << 0
};
2014-01-07 20:37:29 +00:00
enum {
SF_NONE = 0x0000,
2014-01-07 20:37:29 +00:00
SF_LOOK_CURSOR = 0x0001,
SF_GRAB_CURSOR = 0x0002,
SF_TALK_CURSOR = 0x0004,
SF_PLAT_CURSOR = 0x0008,
SF_DISABLED = 0x0010,
SF_WALKABLE = 0x0020,
SF_EXIT_L_CURSOR = 0x0040,
SF_EXIT_R_CURSOR = 0x0080,
SF_EXIT_U_CURSOR = 0x0100,
SF_EXIT_D_CURSOR = 0x0200,
SF_EXIT_NW_CURSOR = 0x0400,
SF_EXIT_NE_CURSOR = 0x0800,
SF_EXIT_SW_CURSOR = 0x1000,
SF_EXIT_SE_CURSOR = 0x2000
};
enum {
LOOK_CURSOR = 0,
GRAB_CURSOR = 1,
TALK_CURSOR = 2,
PLAT_CURSOR = 3,
NOLOOK_CURSOR = 4,
NOGRAB_CURSOR = 5,
NOTALK_CURSOR = 6,
NOPLAT_CURSOR = 7,
EXIT_L_CURSOR = 8,
EXIT_R_CURSOR = 9,
EXIT_U_CURSOR = 10,
EXIT_D_CURSOR = 11,
EXIT_NE_CURSOR = 12,
EXIT_NW_CURSOR = 13,
EXIT_SE_CURSOR = 14,
EXIT_SW_CURSOR = 15,
WAIT_CURSOR = 16
};
enum {
gskPullOutDevice = 0,
gskPullOutDeviceNonWorking = 1,
gskIdle = 2,
gskBrainPulsating = 3,
gskImpossible = 4,
gskScratchingHead = 5,
gskDeflect = 6,
gskUseDevice = 7,
gskMoan1 = 8,
gskMoan2 = 9
};
enum {
kItemMagazine = 0,
kItemMud = 1,
kItemGrass = 2,
kItemDisguise = 3,
kItemNeedle = 4,
kItemTwig = 5,
kItemGas = 6,
kItemKeys = 7,
kItemDice = 8,
kItemTongs = 9,
kItemQuarter = 10,
kItemQuarterWithHole = 11,
kItemDiceQuarterHole = 12,
kItemWrench = 13,
kItemCowboyHat = 14,
kItemGroceryStoreHat = 15,
kItemBanana = 16,
kItemTickets = 17,
kItemPicture = 18,
kItemEmptyBucket = 19,
kItemBucketWithBeer = 20,
kItemBucketWithPill = 21,
kItemPill = 22,
kItemHorn = 23,
kItemJoint = 24,
kItemChickenBucket = 25,
kItemGum = 26,
kItemSpring = 27,
kItemLightbulb = 28,
kItemCereals = 29
};
enum {
kGFPlatypus = 0,
kGFMudTaken = 1,
kGFNeedleTaken = 2,
kGFTwigTaken = 3,
kGFUnk04 = 4,
kGFKeysTaken = 5,
kGFGrassTaken = 6,
kGFBarnPadlockOpen = 7,
kGFTruckFilledWithGas = 8,
kGFTruckKeysUsed = 9,
2016-05-03 05:47:15 +00:00
kGFPlatypusDisguised = 10,
kGFSceneFlag1 = 11,
kGFGnapControlsToyUFO = 12,
kGFUnk13 = 13, // Tongue Fight Won?
kGFUnk14 = 14,
kGFSpringTaken = 15,
kGFUnk16 = 16,
kGFJointTaken = 17,
kGFUnk18 = 18,
kGFGroceryStoreHatTaken = 19,
kGFPictureTaken = 20,
kGFUnk21 = 21,
kGFUnk22 = 22,
kGFUnk23 = 23,
kGFUnk24 = 24,
kGFUnk25 = 25,
kGFPlatypusTalkingToAssistant = 26,
kGFUnk27 = 27,
kGFUnk28 = 28,
kGFGasTaken = 29,
kGFUnk30 = 30,
kGFUnk31 = 31
2014-01-07 20:37:29 +00:00
};
/*
Game flags
0 1 With Platypus
1 2 Mud taken
2 4 Needle taken
3 8 Twig taken
4 0x10
5 0x20 Keys taken
6 0x40 Grass taken
7 0x80 Barn padlock open
8 0x100 Truck filled with gas
9 0x200 Truck keys used
10 0x400 Platypus disguised
11 0x800 Scene flag 1
12 0x1000 Gnap controls toy ufo
13 0x2000
14 0x4000
15 0x8000 Spring taken
16 0x10000
17 0x20000 Joint taken
18 0x40000
19 0x80000 Grocery store hat taken
20 0x100000 Picture taken
21 0x200000
22 0x400000
23 0x800000
24 0x1000000
25 0x2000000
26 0x4000000 Platypus talking with toy shop assistant
27 0x8000000
28 0x10000000
29 0x20000000 Gas taken
30 0x40000000
31 0x80000000
*/
// 0x7AB Gnap walks to the right 1
// 0x7AC Gnap walks to the right 2
// 0x7AF Gnap walks to the left 1
// 0x7B0 Gnap walks to the left 2
struct GnapSavegameHeader {
uint8 _version;
Common::String _saveName;
Graphics::Surface *_thumbnail;
int _year, _month, _day;
int _hour, _minute;
};
2014-01-07 20:37:29 +00:00
class GnapEngine : public Engine {
protected:
Common::Error run();
virtual bool hasFeature(EngineFeature f) const;
public:
GnapEngine(OSystem *syst, const ADGameDescription *gd);
~GnapEngine();
private:
const ADGameDescription *_gameDescription;
Graphics::PixelFormat _pixelFormat;
2016-04-15 05:27:13 +00:00
int _loadGameSlot;
public:
2014-01-07 20:37:29 +00:00
Common::RandomSource *_random;
2014-01-07 20:37:29 +00:00
Common::PEResources *_exe;
2014-01-07 20:37:29 +00:00
DatManager *_dat;
SpriteCache *_spriteCache;
SoundCache *_soundCache;
SequenceCache *_sequenceCache;
GameSys *_gameSys;
SoundMan *_soundMan;
2016-04-12 05:26:30 +00:00
Debugger *_debugger;
2016-04-19 05:57:07 +00:00
Scene *_scene;
2016-05-04 05:13:48 +00:00
PlayerGnap *_gnap;
PlayerPlat *_plat;
2016-04-19 05:57:07 +00:00
2014-01-07 20:37:29 +00:00
int _lastUpdateClock;
2014-01-07 20:37:29 +00:00
int _debugLevel;
bool _gameDone;
2014-01-07 20:37:29 +00:00
byte _keyPressState[512];
byte _keyDownState[512];
2014-01-07 20:37:29 +00:00
bool _isPaused;
Graphics::Surface *_pauseSprite;
int _timers[kMaxTimers], _savedTimers[kMaxTimers];
2014-01-07 20:37:29 +00:00
MouseButtonState _mouseButtonState;
MouseButtonState _mouseClickState;
2014-01-07 20:37:29 +00:00
uint32 _keyStatus1[2];
2014-01-07 20:37:29 +00:00
bool _sceneSavegameLoaded, _wasSavegameLoaded;
2014-01-07 20:37:29 +00:00
Graphics::Surface *_backgroundSurface;
int _prevSceneNum, _currentSceneNum, _newSceneNum;
2014-01-07 20:37:29 +00:00
bool _sceneDone, _sceneWaiting;
uint32 _inventory, _gameFlags;
2014-01-07 20:37:29 +00:00
Hotspot _hotspots[20];
Common::Point _hotspotsWalkPos[20];
int _hotspotsCount;
int _sceneClickedHotspot;
2014-01-07 20:37:29 +00:00
bool _isWaiting;
bool _isLeavingScene;
2014-01-07 20:37:29 +00:00
bool _isStockDatLoaded;
int _newCursorValue, _cursorValue;
int _verbCursor, _cursorIndex;
int _mouseX, _mouseY;
int _leftClickMouseX, _leftClickMouseY;
2014-01-07 20:37:29 +00:00
Graphics::Surface *_grabCursorSprite;
int _currGrabCursorX, _currGrabCursorY;
int _grabCursorSpriteIndex, _newGrabCursorSpriteIndex;
2014-01-07 20:37:29 +00:00
Graphics::Surface *_fullScreenSprite;
int _fullScreenSpriteId;
2014-01-07 20:37:29 +00:00
int _deviceX1, _deviceY1, _deviceX2, _deviceY2;
2014-01-07 20:37:29 +00:00
int _soundTimerIndexA;
int _soundTimerIndexB;
int _soundTimerIndexC;
int _idleTimerIndex;
2014-01-07 20:37:29 +00:00
void updateEvents();
void gameUpdateTick();
void saveTimers();
void restoreTimers();
2014-01-07 20:37:29 +00:00
void pauseGame();
void resumeGame();
void updatePause();
2014-01-07 20:37:29 +00:00
int getRandom(int max);
2014-01-07 20:37:29 +00:00
int readSavegameDescription(int savegameNum, Common::String &description);
int loadSavegame(int savegameNum);
Common::Error saveGameState(int slot, const Common::String &desc);
Common::Error loadGameState(int slot);
Common::String generateSaveName(int slot);
void synchronize(Common::Serializer &s);
void writeSavegameHeader(Common::OutSaveFile *out, GnapSavegameHeader &header);
static bool readSavegameHeader(Common::InSaveFile *in, GnapSavegameHeader &header);
2014-01-07 20:37:29 +00:00
void delayTicks(int a1);
void delayTicksCursor(int a1);
2014-01-07 20:37:29 +00:00
void setHotspot(int index, int16 x1, int16 y1, int16 x2, int16 y2, uint16 flags = 0,
int16 walkX = -1, int16 walkY = -1);
int getHotspotIndexAtPos(int16 x, int16 y);
void updateCursorByHotspot();
int getClickedHotspotId();
2014-01-07 20:37:29 +00:00
int getInventoryItemSpriteNum(int index);
2014-01-07 20:37:29 +00:00
void updateMouseCursor();
void setVerbCursor(int verbCursor);
void setCursor(int cursorIndex);
void showCursor();
void hideCursor();
2014-01-07 20:37:29 +00:00
void setGrabCursorSprite(int index);
void createGrabCursorSprite(int spriteId);
void freeGrabCursorSprite();
void updateGrabCursorSprite(int x, int y);
2014-01-07 20:37:29 +00:00
void invClear();
void invAdd(int itemId);
void invRemove(int itemId);
bool invHas(int itemId);
2014-01-07 20:37:29 +00:00
void clearFlags();
void setFlag(int num);
void clearFlag(int num);
bool isFlag(int num);
2014-01-07 20:37:29 +00:00
Graphics::Surface *addFullScreenSprite(int resourceId, int id);
void removeFullScreenSprite();
void showFullScreenSprite(int resourceId);
2014-01-07 20:37:29 +00:00
void queueInsertDeviceIcon();
void insertDeviceIconActive();
void removeDeviceIconActive();
void setDeviceHotspot(int hotspotIndex, int x1, int y1, int x2, int y2);
2014-01-07 20:37:29 +00:00
int getSequenceTotalDuration(int resourceId);
2014-01-07 20:37:29 +00:00
bool isSoundPlaying(int resourceId);
void playSound(int resourceId, bool looping);
void stopSound(int resourceId);
void setSoundVolume(int resourceId, int volume);
void updateTimers();
2014-01-07 20:37:29 +00:00
void initGameFlags(int num);
void loadStockDat();
void mainLoop();
void initScene();
void endSceneInit();
void afterScene();
2014-01-07 20:37:29 +00:00
int initSceneLogic();
void runSceneLogic();
2014-01-07 20:37:29 +00:00
void checkGameKeys();
2014-01-07 20:37:29 +00:00
void startSoundTimerA(int timerIndex);
int playSoundA();
void startSoundTimerB(int timerIndex);
int playSoundB();
void startSoundTimerC(int timerIndex);
int playSoundC();
void startIdleTimer(int timerIndex);
void updateIdleTimer();
2014-01-07 20:37:29 +00:00
void screenEffect(int dir, byte r, byte g, byte b);
2014-01-07 20:37:29 +00:00
bool isKeyStatus1(int key);
bool isKeyStatus2(int key);
void clearKeyStatus1(int key);
void clearAllKeyStatus1();
2014-01-07 20:37:29 +00:00
void deleteSurface(Graphics::Surface **surface);
2014-01-07 20:37:29 +00:00
// Menu
int _menuStatus;
int _menuSpritesIndex;
bool _menuDone;
Graphics::Surface *_menuBackgroundSurface;
Graphics::Surface *_menuQuitQuerySprite;
Graphics::Surface *_largeSprite;
Graphics::Surface *_menuSaveLoadSprite;
Graphics::Surface *_menuSprite2;
Graphics::Surface *_menuSprite1;
2014-01-07 20:37:29 +00:00
char _savegameFilenames[7][30];
Graphics::Surface *_savegameSprites[7];
Graphics::Surface *_spriteHandle;
Graphics::Surface *_cursorSprite;
int _menuInventoryIndices[30];
Graphics::Surface *_menuInventorySprites[30];
int _savegameIndex;
void createMenuSprite();
void freeMenuSprite();
void initMenuHotspots1();
void initMenuHotspots2();
void initMenuQuitQueryHotspots();
void initSaveLoadHotspots();
void drawInventoryFrames();
void insertInventorySprites();
void removeInventorySprites();
2014-01-07 20:37:29 +00:00
void runMenu();
void updateMenuStatusInventory();
void updateMenuStatusMainMenu();
void updateMenuStatusSaveGame();
void updateMenuStatusLoadGame();
void updateMenuStatusQueryQuit();
2014-01-07 20:37:29 +00:00
// Grid common
int _gridMinX, _gridMinY;
int _gridMaxX, _gridMaxY;
bool isPointBlocked(int gridX, int gridY);
2016-05-07 10:29:18 +00:00
bool isPointBlocked(Common::Point gridPos);
2014-01-07 20:37:29 +00:00
void initSceneGrid(int gridMinX, int gridMinY, int gridMaxX, int gridMaxY);
bool testWalk(int animationIndex, int someStatus, int gridX1, int gridY1, int gridX2, int gridY2);
// Gnap
void doCallback(int callback);
2014-01-07 20:37:29 +00:00
// Scenes
int _toyUfoNextSequenceId, _toyUfoSequenceId;
int _toyUfoId;
int _toyUfoActionStatus;
int _toyUfoX;
int _toyUfoY;
2014-01-07 20:37:29 +00:00
void initGlobalSceneVars();
void playSequences(int fullScreenSpriteId, int sequenceId1, int sequenceId2, int sequenceId3);
2016-04-23 17:34:42 +00:00
// Shared by scenes 17 & 18
int _s18GarbageCanPos;
2014-01-07 20:37:29 +00:00
// Scene 4x
2016-03-18 06:34:28 +00:00
void toyUfoSetStatus(int flagNum);
2014-01-07 20:37:29 +00:00
int toyUfoGetSequenceId();
bool toyUfoCheckTimer();
2016-03-13 23:06:56 +00:00
void toyUfoFlyTo(int destX, int destY, int minX, int maxX, int minY, int maxY, int animationIndex);
2014-01-07 20:37:29 +00:00
};
} // End of namespace Gnap
#endif // GNAP_H