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 
98  void setLastSceneNum(int16 num) { _lastOpcode1SceneChageNum = num; }
99 
100 protected:
101 
102  // these ones seem to be common between games
103  int16 _lastOpcode1SceneChageNum;
104  int16 _sceneOp12SceneNum;
105  int16 _currentSelectedItem;
106  int16 _gameMinsToAddOnLClick;
107  int16 _gameMinsToAddOnStartDrag;
108  int16 _gameMinsToAddOnRClick;
109  int16 _gameMinsToAddOnDragFinished;
110  int16 _gameMinsToAddOnObjInteraction;
111  int16 _gameIsInteractiveGlobal; // used to decide if the game can start a "meanwhile" sequence
112  int16 _sceneOpcode15FromScene;
113  int16 _sceneOpcode15ToScene;
114 
115  Common::Array<Global *> _globals;
116 };
117 
118 // TODO: Work out what this table is even for..
120 public:
121  DragonDataTable();
122  uint16 getValueFromTable();
123 
124  int16 _row;
125  int16 _col;
126  int16 _divBy4;
127  int16 _output;
128 
129 private:
130  int getOffsetForVal(uint16 val) const;
131 };
132 
133 
134 class DragonGlobals : public Globals {
135 public:
136  DragonGlobals(Clock &clock);
137 
138 private:
139  // Dragon-specific globals
140  int16 _sceneOpcode100Var;
141  int16 _arcadeModeState;
142  int16 _opcode106EndMinutes;
143  DragonDataTable _table;
144 
145  Common::Error syncState(Common::Serializer &s) override;
146 };
147 
148 class HocGlobals : public Globals {
149 public:
150  HocGlobals(Clock &clock);
151 
152  int16 getSheckels() const { return _sheckels; }
153 
154  int16 getShellBet() const { return _shellBet; }
155  void setShellBet(int16 bet) { _shellBet = bet; }
156 
157  int16 getShellPea() const { return _shellPea; }
158  void setShellPea(int16 pea) { _shellPea = pea; }
159 
160  int16 getNativeGameState() const { return _nativeGameState; }
161  void setNativeGameState(int16 state) { _nativeGameState = state; }
162 
163 private:
164  // HoC-specific globals
165  int16 _unk39;
166  int16 _unk40;
167  int16 _unk41;
168  int16 _shellPea;
169  int16 _shellBet;
170  int16 _sheckels;
171  int16 _unk45;
172  int16 _unk46;
173  int16 _unk47;
174  int16 _unk48;
175  int16 _nativeGameState; // state for the shell game, tank game, etc.
176  int16 _unk50;
177  int16 _currentCharacter;
178  int16 _currentCharacter2;
179  int16 _unkDlgDlgNum;
180  int16 _unkDlgFileNum;
181  int16 _unk55;
182  int16 _unk82;
183 
184  Common::Error syncState(Common::Serializer &s) override;
185 };
186 
187 class WillyGlobals : public Globals {
188 public:
189  WillyGlobals(Clock &clock);
190 
191 private:
192  // Willy-specific globals
193  int16 _unk2;
194  int16 _unk3;
195  int16 _unk4;
196  int16 _unk5;
197  int16 _unk74;
198  int16 _unk75;
199  int16 _unk77;
200  int16 _unk78;
201  int16 _unk79;
202  int16 _unk80;
203  int16 _unk81;
204  int16 _unk82;
205 
206  Common::Error syncState(Common::Serializer &s) override;
207 };
208 
209 } // end namespace Dgds
210 
211 #endif // DGDS_GLOBALS_H
Definition: globals.h:119
Definition: error.h:84
Definition: array.h:52
Definition: globals.h:81
Definition: globals.h:187
Definition: ads.h:28
Definition: serializer.h:79
Definition: globals.h:70
Definition: globals.h:60
Definition: clock.h:39
Definition: globals.h:134
Definition: globals.h:44
Definition: globals.h:148