ScummVM API documentation
globals.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 DGDS_GLOBALS_H
23 #define DGDS_GLOBALS_H
24 
25 #include "common/types.h"
26 #include "common/array.h"
27 
28 #include "dgds/dgds.h"
29 
30 namespace Dgds {
31 
32 class Clock;
33 
44 class Global {
45 public:
46  Global(uint16 num) : _num(num) {}
47  virtual ~Global() {}
48  virtual int16 get() = 0;
49  virtual int16 set(int16 val) = 0;
50  virtual uint16 getNum() const { return _num; }
51  virtual void setRaw(int16 val) = 0;
52 private:
53  uint16 _num;
54 };
55 
56 /*
57  This is a bit of a misnomer - the global is readonly during play,
58  but it can be set by load/save or restart operations
59 */
60 template<typename T> class ReadOnlyGlobal : public Global {
61 public:
62  ReadOnlyGlobal(uint16 num, T *val) : Global(num), _val(val) {}
63  int16 get() override { return *_val; }
64  int16 set(int16 val) override { return *_val; }
65  void setRaw(int16 val) override { *_val = val; }
66 private:
67  T *_val;
68 };
69 
70 template<typename T> class ReadWriteGlobal : public Global {
71 public:
72  ReadWriteGlobal(uint16 num, T *val) : Global(num), _val(val) {}
73  int16 get() override { return *_val; }
74  int16 set(int16 val) override { *_val = val; return *_val; }
75  void setRaw(int16 val) override { *_val = val; }
76 private:
77  T *_val;
78 };
79 
80 
81 class Globals {
82 public:
83  Globals(Clock &clock);
84  virtual ~Globals();
85 
86  int16 getGlobal(uint16 num);
87  int16 setGlobal(uint16 num, int16 val);
88 
89  virtual Common::Error syncState(Common::Serializer &s); // note: children should call parent first
90  Common::Array<Global *> &getAllGlobals() { return _globals; }
91 
92  int16 getGameMinsToAddOnLClick() const { return _gameMinsToAddOnLClick; }
93  int16 getGameMinsToAddOnStartDrag() const { return _gameMinsToAddOnStartDrag; }
94  int16 getGameMinsToAddOnRClick() const { return _gameMinsToAddOnRClick; }
95  int16 getGameMinsToAddOnDragFinished() const { return _gameMinsToAddOnDragFinished; }
96  int16 getGameMinsToAddOnObjInteraction() const { return _gameMinsToAddOnObjInteraction; }
97  int16 getGameIsInteractiveGlobal() { return _gameIsInteractiveGlobal; }
98 
99  void setLastSceneNum(int16 num) { _lastOpcode1SceneChangeNum = num; }
100  int16 getLastSceneNum() const { return _lastOpcode1SceneChangeNum; }
101 
102 protected:
103 
104  // these ones seem to be common between games
105  int16 _lastOpcode1SceneChangeNum;
106  int16 _sceneOp12SceneNum;
107  int16 _currentSelectedItem;
108  int16 _gameMinsToAddOnLClick;
109  int16 _gameMinsToAddOnStartDrag;
110  int16 _gameMinsToAddOnRClick;
111  int16 _gameMinsToAddOnDragFinished;
112  int16 _gameMinsToAddOnObjInteraction;
113  int16 _gameIsInteractiveGlobal; // used to decide if the game can start a "meanwhile" sequence
114  int16 _sceneOpcode15FromScene;
115  int16 _sceneOpcode15ToScene;
116 
117  Common::Array<Global *> _globals;
118 };
119 
120 // TODO: Work out what this table is even for..
122 public:
123  DragonDataTable();
124  uint16 getValueFromTable();
125 
126  int16 _row;
127  int16 _col;
128  int16 _divBy4;
129  int16 _output;
130 
131 private:
132  int getOffsetForVal(uint16 val) const;
133 };
134 
135 
136 class DragonGlobals : public Globals {
137 public:
138  DragonGlobals(Clock &clock);
139 
140  int16 getArcadeState() const { return _arcadeState; }
141  void setArcadeState(int16 state) { _arcadeState = state; }
142 
143 private:
144  // Dragon-specific globals
145  int16 _sceneOpcode100Var;
146  int16 _arcadeState;
147  int16 _opcode106EndMinutes;
148  DragonDataTable _table;
149 
150  Common::Error syncState(Common::Serializer &s) override;
151 };
152 
153 class HocGlobals : public Globals {
154 public:
155  HocGlobals(Clock &clock);
156 
157  int16 getSheckels() const { return _sheckels; }
158 
159  int16 getShellBet() const { return _shellBet; }
160  void setShellBet(int16 bet) { _shellBet = bet; }
161 
162  int16 getShellPea() const { return _shellPea; }
163  void setShellPea(int16 pea) { _shellPea = pea; }
164 
165  int16 getNativeGameState() const { return _nativeGameState; }
166  void setNativeGameState(int16 state) { _nativeGameState = state; }
167 
168  int16 getTrainState() const { return _trainState; }
169  void setTrainState(int16 state) { _trainState = state; }
170 
171  int16 getIntroState() const { return _introState; }
172  void setIntroState(int16 state) { _introState = state; }
173 
174 private:
175  // HoC-specific globals
176  int16 _introState;
177  int16 _startScene;
178  int16 _trainState;
179  int16 _shellPea;
180  int16 _shellBet;
181  int16 _sheckels;
182  int16 _unk45;
183  int16 _unk46;
184  int16 _unk47;
185  int16 _tankState;
186  int16 _nativeGameState; // state for the shell game, tank game, etc.
187  int16 _tankFinished;
188  int16 _currentCharacter;
189  int16 _currentCharacter2;
190  int16 _unkDlgDlgNum;
191  int16 _unkDlgFileNum;
192  int16 _unk55;
193  int16 _difficultyLevel;
194 
195  Common::Error syncState(Common::Serializer &s) override;
196 };
197 
198 class WillyGlobals : public Globals {
199 public:
200  WillyGlobals(Clock &clock);
201 
202  void setPalFade(int16 val) { _palFade = val; }
203  int16 getPalFade() const { return _palFade; }
204 
205  void setDroppedItemNum(int16 val) { _droppedItemNum = val; }
206  bool isHideMouseCursor() const { return _hideMouseCursor != 0; }
207  bool isDrawTimeSkipButtons() const { return _invDrawTimeSkipButtons != 0; }
208 
209 private:
210  // Willy-specific globals
211  int16 _trouble;
212  int16 _money;
213  int16 _invDrawTimeSkipButtons;
214  int16 _hideMouseCursor;
215  int16 _unk74;
216  int16 _unk75;
217  int16 _palFade;
218  int16 _droppedItemNum;
219  int16 _characterStance;
220  int16 _characterPos;
221  int16 _unk81;
222  int16 _unk82;
223 
224  Common::Error syncState(Common::Serializer &s) override;
225 };
226 
227 } // end namespace Dgds
228 
229 #endif // DGDS_GLOBALS_H
Definition: globals.h:121
Definition: error.h:84
Definition: array.h:52
Definition: globals.h:81
Definition: globals.h:198
Definition: ads.h:28
Definition: serializer.h:79
Definition: globals.h:70
Definition: globals.h:60
Definition: clock.h:39
Definition: globals.h:136
Definition: globals.h:44
Definition: globals.h:153