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