ScummVM API documentation
shared.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
13#ifndef SCUMM_INSANE_REBEL2_SHARED_H
14#define SCUMM_INSANE_REBEL2_SHARED_H
15
16#include "common/keyboard.h"
17
18namespace Common {
19class RandomSource;
20}
21
22namespace Scumm {
23
24enum Rebel2MenuCommand {
25 kRebel2MenuCommandNone,
26 kRebel2MenuCommandUp,
27 kRebel2MenuCommandDown,
28 kRebel2MenuCommandAccept,
29 kRebel2MenuCommandCancel
30};
31
32enum {
33 kRebel2MenuResultCancel = -2,
34 kRebel2MenuResultNone = -1
35};
36
38public:
39 enum Result {
40 kQuit,
41 kComplete,
42 kDeath,
43 kGameOver,
44 kError
45 };
46
47 virtual ~Rebel2Level1Handler() {}
48 virtual bool shouldQuit() const = 0;
49 virtual Result playAttempt(int &lives) = 0;
50 virtual bool playComplete() = 0;
51 virtual bool playDeath() = 0;
52 virtual bool playRetry(int lives) = 0;
53 virtual bool playGameOver(int lives) = 0;
54};
55
56Rebel2Level1Handler::Result runRebel2Level1(Rebel2Level1Handler &handler, int lives);
57
58// Level 2 - and the chapters built on the same cover shooter - runs three phases of waves
59// against a budget. The flow below is the level's design rather than any one release's, so
60// the handler only has to play what the runner asks for and report the state it keeps.
62public:
63 enum Result {
64 kQuit,
65 kComplete,
66 kGameOver,
67 kError
68 };
69
70 // What a finished wave credited toward picking the next one, and whether the phase
71 // should stop regardless.
72 struct WaveCredit {
73 WaveCredit() : bits(0), stop(false) {}
74
75 uint16 bits;
76 bool stop;
77 };
78
79 virtual ~Rebel2Level2Handler() {}
80 virtual bool shouldQuit() const = 0;
81
82 virtual bool playOpening() = 0;
83 virtual void beginAttempt() = 0;
84 virtual void beginPhase(int phase, bool clearEnemies) = 0;
85 virtual int16 waveBudget(int phase) = 0;
86 virtual bool playBackgroundWave(int phase) = 0;
87 virtual bool playWave(int phase, uint16 selection) = 0;
88 virtual WaveCredit creditWave(int16 mask, int16 *budget, int16 threshold) = 0;
89 virtual bool playPhaseEnd(int phase) = 0;
90
91 virtual uint16 phaseState() const = 0;
92 virtual bool playerDead() const = 0;
93 virtual void accumulateKills() = 0;
94 virtual void accumulateMisses() = 0;
95
96 // Returns true when the player still has a life and the attempt should restart.
97 virtual bool handleDeath(int phase, Result &result) = 0;
98 virtual void playComplete(int bonusCount) = 0;
99};
100
101Rebel2Level2Handler::Result runRebel2Level2(Rebel2Level2Handler &handler,
102 Common::RandomSource &random);
103
104inline Rebel2MenuCommand getRebel2MenuCommand(const Common::KeyState &key) {
105 switch (key.keycode) {
106 case Common::KEYCODE_UP:
107 return kRebel2MenuCommandUp;
108 case Common::KEYCODE_DOWN:
109 return kRebel2MenuCommandDown;
110 case Common::KEYCODE_RETURN:
111 case Common::KEYCODE_KP_ENTER:
112 return kRebel2MenuCommandAccept;
113 case Common::KEYCODE_ESCAPE:
114 return kRebel2MenuCommandCancel;
115 default:
116 return kRebel2MenuCommandNone;
117 }
118}
119
120inline int applyRebel2MenuCommand(Rebel2MenuCommand command, int itemCount,
121 int &selection) {
122 if (itemCount <= 0)
123 return kRebel2MenuResultNone;
124
125 switch (command) {
126 case kRebel2MenuCommandUp:
127 if (--selection < 0)
128 selection = itemCount - 1;
129 break;
130 case kRebel2MenuCommandDown:
131 if (++selection >= itemCount)
132 selection = 0;
133 break;
134 case kRebel2MenuCommandAccept:
135 return selection >= 0 && selection < itemCount ? selection : kRebel2MenuResultNone;
136 case kRebel2MenuCommandCancel:
137 return kRebel2MenuResultCancel;
138 default:
139 break;
140 }
141 return kRebel2MenuResultNone;
142}
143
144inline bool updateRebel2Fire(bool pressed, bool wasPressed,
145 bool rapidFire, bool autoFire, int16 &rapidFireCounter) {
146 const bool pressedEdge = pressed && !wasPressed;
147 if (pressedEdge)
148 rapidFireCounter = 0;
149
150 bool rapidFireShot = false;
151 if (rapidFire) {
152 rapidFireShot = pressed && rapidFireCounter % 5 == 0;
153 rapidFireCounter = (rapidFireCounter + 1) % 5;
154 }
155 return pressedEdge || rapidFireShot || autoFire;
156}
157
158} // End of namespace Scumm
159
160#endif
Definition: random.h:44
Definition: shared.h:37
Definition: shared.h:61
Definition: algorithm.h:29
Definition: actor.h:30
Definition: keyboard.h:294