ScummVM API documentation
game_bountyhunter.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 ALG_GAME_BOUNTYHUNTER_H
23 #define ALG_GAME_BOUNTYHUNTER_H
24 
25 #include "common/hashmap.h"
26 #include "common/rect.h"
27 
28 #include "gui/debugger.h"
29 
30 #include "alg/game.h"
31 #include "alg/scene.h"
32 
33 namespace Alg {
34 
35 typedef Common::Functor1Mem<Scene *, void, GameBountyHunter> BHScriptFunctionScene;
36 typedef Common::Functor1Mem<Rect *, void, GameBountyHunter> BHScriptFunctionRect;
38 typedef Common::HashMap<Common::String, BHScriptFunctionScene *> BHScriptFunctionSceneMap;
39 typedef Common::HashMap<Common::String, BHScriptFunctionRect *> BHScriptFunctionRectMap;
40 typedef Common::HashMap<Common::String, BHScriptFunctionPoint *> BHScriptFunctionPointMap;
41 
42 class GameBountyHunter : public Game {
43 
44  enum SceneFuncType {
45  PREOP = 1,
46  SHOWMSG = 2,
47  INSOP = 3,
48  WEPDWN = 4,
49  SCNSCR = 5,
50  NXTFRM = 6,
51  NXTSCN = 7
52  };
53 
54 public:
56  ~GameBountyHunter() override;
57  Common::Error run() override;
58  void debug_warpTo(int val);
59 
60 private:
61  void init() override;
62  void registerScriptFunctions();
63  void verifyScriptFunctions();
64  void unregisterScriptFunctions();
65  BHScriptFunctionRect getScriptFunctionRectHit(Common::String name);
66  BHScriptFunctionScene getScriptFunctionScene(SceneFuncType type, Common::String name);
67  void callScriptFunctionRectHit(Common::String name, Rect *rect);
68  void callScriptFunctionScene(SceneFuncType type, Common::String name, Scene *scene);
69 
70  BHScriptFunctionRectMap _rectHitFuncs;
71  BHScriptFunctionSceneMap _scenePreOps;
72  BHScriptFunctionSceneMap _sceneShowMsg;
73  BHScriptFunctionSceneMap _sceneInsOps;
74  BHScriptFunctionSceneMap _sceneWepDwn;
75  BHScriptFunctionSceneMap _sceneScnScr;
76  BHScriptFunctionSceneMap _sceneNxtFrm;
77  BHScriptFunctionSceneMap _sceneNxtScn;
78 
79  // images
80  Graphics::Surface *_shotIcon = nullptr;
81  Graphics::Surface *_emptyIcon = nullptr;
82  Graphics::Surface *_shellIcon = nullptr;
83  Graphics::Surface *_liveIcon = nullptr;
84  Graphics::Surface *_deadIcon = nullptr;
85  Graphics::Surface *_playersIcon1 = nullptr;
86  Graphics::Surface *_playersIcon2 = nullptr;
87  Graphics::Surface *_textScoreIcon = nullptr;
88  Graphics::Surface *_textMenuIcon = nullptr;
89  Graphics::Surface *_textBlackBarIcon = nullptr;
90  Common::Array<Graphics::Surface *> *_gun = nullptr;
91  Common::Array<Graphics::Surface *> *_numbers = nullptr;
92  Common::Array<Graphics::Surface *> *_bagsIcons = nullptr;
93  Common::Array<Graphics::Surface *> *_bulletHoleIcon = nullptr;
94  Common::Array<Graphics::Surface *> *_shotgunHoleIcon = nullptr;
95 
96  // sounds
97  Audio::SeekableAudioStream *_saveSound = nullptr;
98  Audio::SeekableAudioStream *_loadSound = nullptr;
99  Audio::SeekableAudioStream *_skullSound = nullptr;
100  Audio::SeekableAudioStream *_shotSound = nullptr;
101  Audio::SeekableAudioStream *_shotgunSound = nullptr;
102  Audio::SeekableAudioStream *_emptySound = nullptr;
103 
104  // constants
105  uint16 _randomHarry1[7] = {0x01B9, 0x01B7, 0x01B5, 0x01B3, 0x01AF, 0x01AD, 0};
106  uint16 _randomHarry2[6] = {0x0194, 0x0190, 0x018E, 0x018C, 0};
107  uint16 _randomDan1[5] = {0x0173, 0x0171, 0x016F, 0x016D, 0};
108  uint16 _randomDan1TwoPlayer[6] = {0x0173, 0x0171, 0x016F, 0x016D, 0x016B, 0};
109  uint16 _randomDan2[7] = {0x0165, 0x0163, 0x0161, 0x015F, 0x015D, 0x015B, 0};
110  uint16 _randomLoco1[4] = {0xF7, 0xF5, 0xF3, 0};
111  uint16 _randomLoco2[3] = {0xED, 0xEB, 0};
112  uint16 _randomKid1[4] = {0xBA, 0xB7, 0xB5, 0};
113  uint16 _randomKid2[4] = {0xB1, 0xAE, 0xAC, 0};
114 
115  uint16 *_randomScenes[8] = {_randomHarry1, _randomHarry2, _randomDan1, _randomDan2, _randomLoco1, _randomLoco2, _randomKid1, _randomKid2};
116  const uint8 _randomScenesPicks[8] = {6, 6, 4, 7, 3, 2, 5, 5};
117 
118  const uint8 _subLevelOrder[96] = {0, 1, 2, 4, 0, 0, 0, 1, 3, 4, 0, 0, 0, 2, 3, 4, 0, 0, 0, 1, 2, 3, 4, 0,
119  0, 1, 2, 4, 0, 0, 0, 1, 3, 4, 0, 0, 0, 2, 3, 4, 0, 0, 0, 1, 2, 3, 4, 0,
120  0, 1, 3, 4, 0, 0, 0, 2, 3, 4, 0, 0, 1, 2, 3, 4, 0, 0, 0, 1, 2, 3, 4, 0,
121  0, 1, 2, 3, 4, 0, 0, 1, 2, 3, 4, 0, 0, 1, 2, 3, 4, 0, 0, 1, 2, 3, 4, 0};
122  const uint16 _subLevelSceneIds[20] = {0x01BE, 0x017A, 0x01A2, 0x0198, 0x0183, 0x0178, 0x0167, 0x0159, 0x014B, 0x0147,
123  0xF1, 0xE1, 0xFF, 0xD8, 0xD0, 0x9B, 0xA8, 0x86, 0xBF, 0x74};
124 
125  const uint16 _clueLevels[4] = {0x017A, 0x013B, 0xC2, 0x68};
126  const uint8 _mainLevelMasks[5] = {2, 4, 8, 0x10, 0x80};
127  const uint8 _gunfightCountDown[15] = {5, 4, 3, 3, 3, 4, 3, 3, 2, 1, 3, 2, 2, 2, 1};
128 
129  // const uint16 _firstSceneInScenario[4] = {0x04, 0x36, 0x36, 0x66};
130  const uint16 _moneyScenes[4] = {0x017D, 0x013C, 0xC3, 0x69};
131  const uint16 _gunfightScenarios[19] = {0x0116, 0x0118, 0x011B, 0x011D, 0x011F, 0x0121, 0x0123, 0x0125, 0x0127,
132  0x0129, 0x012B, 0x012D, 0x012F, 0x0131, 0x0133, 0x0135, 0x0137, 0x0139, 0};
133  const uint16 _innocentScenarios[5] = {0x0110, 0x010F, 0x010C, 0x010B, 0};
134  const uint16 _deathScenarios[9] = {0x0100, 0x0101, 0x0102, 0x0103, 0x0104, 0x0105, 0x0106, 0x0107, 0};
135  const uint16 _onePlayerOfTwoDead[2] = {0x0109, 0x010A};
136  const uint16 _allPlayersDead = 0x108;
137  const uint16 _selectOpponentScreen = 0x017B;
138  // gamestate
139  uint8 _continuesUsed = 0;
140  uint8 _currentLevel = 0;
141  uint16 _currentSubLevelSceneId = 0;
142  uint8 _difficulty = 0;
143  uint32 _firstDrawFrame = 0;
144  int8 _gunfightCount = 0;
145  uint8 _kill3Count = 0;
146  uint32 _lastShotTime = 0;
147  uint8 _levelDoneMask = 0;
148  uint16 _mainWounds = 0;
149  uint8 _numLevelsDone = 0;
150  uint8 _numSubLevelsDone = 0;
151  uint8 _numPlayers = 1;
152  uint8 _player = 0;
153  int8 _playerLives[2] = {3, 3};
154  int8 _oldLives[2] = {0, 0};
155  uint8 _playerGun[2] = {1, 1};
156  uint8 _playerShots[2] = {6, 6};
157  uint8 _oldShots[2] = {0, 0};
158  uint32 _playerScore[2] = {0, 0};
159  uint32 _oldScore[2] = {1, 1};
160  uint32 _pointsSinceLastBonus[2] = {0, 0};
161  uint16 _restartScene = 0;
162  uint8 _whichGun = 0;
163  uint8 _oldWhichGun = 0xFF;
164  bool _wounded = false;
165 
166  uint16 *_randomSceneList = nullptr;
167  uint8 _randomMax = 0;
168  uint16 _randomMask = 0;
169  int16 _randomPicked = 0;
170  uint8 _randomSceneCount = 0;
171  bool _gunfightInitialized = false;
172  uint16 _gunfightMask = 0;
173  int16 _gunfightPicked = 0;
174  uint8 _gunfightSceneCount = 0;
175  bool _innocentInitialized = false;
176  uint16 _innocentMask = 0;
177  int16 _innocentPicked = 0;
178  uint8 _innocentSceneCount = 0;
179  bool _deathInitialized = false;
180  uint16 _deathMask = 0;
181  int16 _deathPicked = 0;
182  uint8 _deathSceneCount = 0;
183 
184  uint8 _iconOrder[4] = {0, 0, 0, 0};
185  uint32 _iconOffset = 0;
186  uint32 _iconCounter = 0;
187  bool _bagAnimToggle = false;
188  Rect _bagRect;
189  bool _bagActive = false;
190  uint8 _playerWhoHitBag = 0;
191 
192  bool _bulletsGiven = false;
193  bool _moneyGiven = false;
194  bool _shotgunGiven = false;
195  bool _bagDropped = false;
196 
197  // base functions
198  void updateScreen() override;
199  uint16 startMyGame();
200  void initGameStatus();
201  void doMenu();
202  void updateCursor();
203  void updateMouse();
204  void moveMouse();
205  void displayLivesLeft(uint8 player);
206  void displayScores(uint8 player);
207  void displayShotsLeft(uint8 player);
208  bool weaponDown();
209  bool saveState(Common::OutSaveFile *saveFile) override;
210  bool loadState(Common::InSaveFile *inSaveFile) override;
211  Zone *checkZones(Scene *scene, Rect *&hitRect, Common::Point *point);
212  Rect *checkZone(Zone *zone, Common::Point *point);
213 
214  // misc game functions
215  void setNextScene(uint16 sceneId);
216  void displayShotFiredImage(Common::Point *point);
217  void enableVideoFadeIn();
218  void iconBags();
219  void iconBullets();
220  void iconMoney();
221  void iconShotgun();
222  void iconReset();
223  void iconSetup();
224  void iconHitGeneric(uint8 type);
225  void displayCurrentBag();
226  void moveCurrentBag();
227  uint16 beginLevel(uint8 levelNumber);
228  uint16 randomUnusedInt(uint8 max, uint16 *mask, uint16 exclude);
229  uint16 pickRandomScene(uint16 *sceneList, uint8 max);
230  uint16 pickGunfightScene();
231  uint16 pickInnocentScene();
232  uint16 pickDeathScene();
233  uint16 timeForGunfight();
234  void waitingForShootout(uint32 drawFrame);
235 
236  // Script functions: RectHit
237  void rectNewScene(Rect *rect);
238  void rectShotMenu(Rect *rect);
239  void rectSave(Rect *rect);
240  void rectLoad(Rect *rect);
241  void rectContinue(Rect *rect);
242  void rectStart(Rect *rect);
243  void rectExit(Rect *rect);
244  void rectTogglePlayers(Rect *rect);
245  void rectHitIconJug(Rect *rect);
246  void rectHitIconLantern(Rect *rect);
247  void rectHitIconSkull(Rect *rect);
248  void rectHitIconWheel(Rect *rect);
249  void rectHitSelectHarry(Rect *rect);
250  void rectHitSelectDan(Rect *rect);
251  void rectHitSelectLoco(Rect *rect);
252  void rectHitSelectKid(Rect *rect);
253  void rectHitKillMan(Rect *rect);
254  void rectHitGiveShotgun(Rect *rect);
255  void rectHitKill3(Rect *rect);
256  void rectHitCheckShotgun(Rect *rect);
257  void rectHitCheater(Rect *rect);
258 
259  // Script functions: Scene PreOps
260  void scenePsoShootout(Scene *scene);
261  void scenePsoWoundedMain(Scene *scene);
262  void scenePsoGunfightSetup(Scene *scene);
263  void scenePsoLoseALife(Scene *scene);
264  void scenePsoSetupNdRandom1(Scene *scene);
265  void scenePsoSetCurrentScene(Scene *scene);
266 
267  // Script functions: Scene InsOps
268  void sceneIsoShootout(Scene *scene);
269  void sceneIsoGivemoney(Scene *scene);
270 
271  // Script functions: Scene NxtScn
272  void sceneNxtscnLoseALife(Scene *scene);
273  void sceneNxtscnContinueGame(Scene *scene);
274  void sceneNxtscnDidNotContinue(Scene *scene);
275  void sceneNxtscnKillInnocentMan(Scene *scene);
276  void sceneNxtscnKillInnocentWoman(Scene *scene);
277  void sceneNxtscnAfterDie(Scene *scene);
278  void sceneNxtscnGotoLevelSelect(Scene *scene);
279  void sceneNxtscnContinueRandom(Scene *scene);
280  void sceneNxtscnInitRandomHarry1(Scene *scene);
281  void sceneNxtscnInitRandomHarry2(Scene *scene);
282  void sceneNxtscnInitRandomDan1(Scene *scene);
283  void sceneNxtscnInitRandomDan2(Scene *scene);
284  void sceneNxtscnInitRandomLoco1(Scene *scene);
285  void sceneNxtscnInitRandomLoco2(Scene *scene);
286  void sceneNxtscnInitRandomKid1(Scene *scene);
287  void sceneNxtscnInitRandomKid2(Scene *scene);
288  void sceneNxtscnNextSubLevel(Scene *scene);
289  void sceneNxtscnGotoBadGuy(Scene *scene);
290  void sceneNxtscnAutoSelectLevel(Scene *scene);
291  void sceneNxtscnSelectScenario(Scene *scene);
292  void sceneNxtscnFinishScenario(Scene *scene);
293  void sceneNxtscnGameWon(Scene *scene);
294  void sceneNxtscnKilledMain(Scene *scene);
295  void sceneNxtscnWoundedMain(Scene *scene);
296  void sceneNxtscnEndLevel(Scene *scene);
297  void sceneNxtscnEndGame(Scene *scene);
298  void sceneNxtscnDoBreakoutMains(Scene *scene);
299  void sceneNxtscnDiedRefed(Scene *scene);
300  void sceneNxtscnGiveShotgun(Scene *scene);
301  void sceneNxtscnCheck2Players(Scene *scene);
302 
303  // Script functions: Scene WepDwn
304  void sceneDefaultWepdwn(Scene *scene);
305 
306  // Script functions: ScnScr
307  void sceneDefaultScore(Scene *scene);
308 
309  // debug methods
310  void debug_drawZoneRects() override;
311 };
312 
314 public:
316  bool cmdWarpTo(int argc, const char **argv);
317  bool cmdDumpLib(int argc, const char **argv);
318 
319 private:
320  GameBountyHunter *_game;
321 };
322 
323 } // End of namespace Alg
324 
325 #endif
Definition: scene.h:72
Definition: scene.h:101
Definition: str.h:59
Definition: surface.h:67
Definition: savefile.h:54
Definition: error.h:81
Definition: debugger.h:41
Definition: game_bountyhunter.h:313
Definition: stream.h:745
Definition: audiostream.h:212
Definition: alg.h:30
Definition: func.h:452
Definition: rect.h:144
Definition: scene.h:85
Definition: game.h:36
Definition: alg.h:46
Definition: game_bountyhunter.h:42
Definition: detection.h:39