ScummVM API documentation
state.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 VARIABLES_H_
23 #define VARIABLES_H_
24 
25 #include "common/hashmap.h"
26 #include "common/hash-str.h"
27 #include "common/savefile.h"
28 #include "common/serializer.h"
29 
30 #include "engines/myst3/myst3.h"
31 
32 namespace Myst3 {
33 
34 class Database;
35 
36 // View type
37 enum ViewType {
38  kCube = 1,
39  kFrame = 2,
40  kMenu = 3
41 };
42 
43 #define DECLARE_VAR(name) \
44  void set##name(int32 value) { engineSet(#name, value); } \
45  int32 get##name() { return engineGet(#name); } \
46  bool hasVar##name() { return _varDescriptions.contains(#name); }
47 
48 class GameState {
49 public:
50  GameState(const Common::Platform platform, Database *database);
51  virtual ~GameState();
52 
53  void newGame();
54  Common::Error load(Common::InSaveFile *saveFile);
55  Common::Error save(Common::OutSaveFile *saveFile, const Common::String &description, const Graphics::Surface *thumbnail, bool isAutosave);
56 
57  int32 getVar(uint16 var);
58  void setVar(uint16 var, int32 value);
59  bool evaluate(int16 condition);
60  int32 valueOrVarValue(int16 value);
61 
62  const Common::String describeVar(uint16 var);
63  const Common::String describeCondition(int16 condition);
64 
65  DECLARE_VAR(CursorTransparency)
66 
67  DECLARE_VAR(ProjectorAngleX)
68  DECLARE_VAR(ProjectorAngleY)
69  DECLARE_VAR(ProjectorAngleZoom)
70  DECLARE_VAR(ProjectorAngleBlur)
71  DECLARE_VAR(DraggedWeight)
72 
73  DECLARE_VAR(DragEnded)
74  DECLARE_VAR(DragLeverSpeed)
75  DECLARE_VAR(DragPositionFound)
76  DECLARE_VAR(DragLeverPositionChanged)
77 
78  DECLARE_VAR(LocationAge)
79  DECLARE_VAR(LocationRoom)
80  DECLARE_VAR(LocationNode)
81  DECLARE_VAR(BookSavedAge)
82  DECLARE_VAR(BookSavedRoom)
83  DECLARE_VAR(BookSavedNode)
84  DECLARE_VAR(MenuSavedAge)
85  DECLARE_VAR(MenuSavedRoom)
86  DECLARE_VAR(MenuSavedNode)
87 
88  DECLARE_VAR(SecondsCountdown)
89  DECLARE_VAR(TickCountdown)
90 
91  DECLARE_VAR(SweepEnabled)
92  DECLARE_VAR(SweepValue)
93  DECLARE_VAR(SweepStep)
94  DECLARE_VAR(SweepMin)
95  DECLARE_VAR(SweepMax)
96 
97  DECLARE_VAR(InputMousePressed)
98  DECLARE_VAR(InputEscapePressed)
99  DECLARE_VAR(InputTildePressed)
100  DECLARE_VAR(InputSpacePressed)
101 
102  DECLARE_VAR(HotspotActiveRect)
103 
104  DECLARE_VAR(WaterEffectRunning)
105  DECLARE_VAR(WaterEffectActive)
106  DECLARE_VAR(WaterEffectSpeed)
107  DECLARE_VAR(WaterEffectAttenuation)
108  DECLARE_VAR(WaterEffectFrequency)
109  DECLARE_VAR(WaterEffectAmpl)
110  DECLARE_VAR(WaterEffectMaxStep)
111  DECLARE_VAR(WaterEffectAmplOffset)
112 
113  DECLARE_VAR(LavaEffectActive)
114  DECLARE_VAR(LavaEffectSpeed)
115  DECLARE_VAR(LavaEffectAmpl)
116  DECLARE_VAR(LavaEffectStepSize)
117 
118  DECLARE_VAR(MagnetEffectActive)
119  DECLARE_VAR(MagnetEffectSpeed)
120  DECLARE_VAR(MagnetEffectUnk1)
121  DECLARE_VAR(MagnetEffectUnk2)
122  DECLARE_VAR(MagnetEffectSound)
123  DECLARE_VAR(MagnetEffectNode)
124  DECLARE_VAR(MagnetEffectUnk3)
125 
126  DECLARE_VAR(ShakeEffectAmpl)
127  DECLARE_VAR(ShakeEffectTickPeriod)
128  DECLARE_VAR(RotationEffectSpeed)
129  DECLARE_VAR(SunspotIntensity)
130  DECLARE_VAR(SunspotColor)
131  DECLARE_VAR(SunspotRadius)
132 
133  DECLARE_VAR(AmbiantFadeOutDelay)
134  DECLARE_VAR(AmbiantPreviousFadeOutDelay)
135  DECLARE_VAR(AmbientOverrideFadeOutDelay)
136  DECLARE_VAR(SoundScriptsSuspended)
137 
138  DECLARE_VAR(SoundNextMultipleSounds)
139  DECLARE_VAR(SoundNextIsChoosen)
140  DECLARE_VAR(SoundNextId)
141  DECLARE_VAR(SoundNextIsLast)
142  DECLARE_VAR(SoundScriptsTimer)
143  DECLARE_VAR(SoundScriptsPaused)
144  DECLARE_VAR(SoundScriptFadeOutDelay)
145 
146  DECLARE_VAR(CursorLocked)
147  DECLARE_VAR(CursorHidden)
148 
149  DECLARE_VAR(CameraPitch)
150  DECLARE_VAR(CameraHeading)
151  DECLARE_VAR(CameraMinPitch)
152  DECLARE_VAR(CameraMaxPitch)
153 
154  DECLARE_VAR(MovieStartFrame)
155  DECLARE_VAR(MovieEndFrame)
156  DECLARE_VAR(MovieVolume1)
157  DECLARE_VAR(MovieVolume2)
158  DECLARE_VAR(MovieOverrideSubtitles)
159  DECLARE_VAR(MovieConditionBit)
160  DECLARE_VAR(MoviePreloadToMemory)
161  DECLARE_VAR(MovieScriptDriven)
162  DECLARE_VAR(MovieNextFrameSetVar)
163  DECLARE_VAR(MovieNextFrameGetVar)
164  DECLARE_VAR(MovieStartFrameVar)
165  DECLARE_VAR(MovieEndFrameVar)
166  DECLARE_VAR(MovieForce2d)
167  DECLARE_VAR(MovieVolumeVar)
168  DECLARE_VAR(MovieSoundHeading)
169  DECLARE_VAR(MoviePanningStrenght)
170  DECLARE_VAR(MovieSynchronized)
171  DECLARE_VAR(MovieOverrideCondition)
172  DECLARE_VAR(MovieUVar)
173  DECLARE_VAR(MovieVVar)
174  DECLARE_VAR(MovieOverridePosition)
175  DECLARE_VAR(MovieOverridePosU)
176  DECLARE_VAR(MovieOverridePosV)
177  DECLARE_VAR(MovieAdditiveBlending)
178  DECLARE_VAR(MovieTransparency)
179  DECLARE_VAR(MovieTransparencyVar)
180  DECLARE_VAR(MoviePlayingVar)
181  DECLARE_VAR(MovieStartSoundId)
182  DECLARE_VAR(MovieStartSoundVolume)
183  DECLARE_VAR(MovieStartSoundHeading)
184  DECLARE_VAR(MovieStartSoundAttenuation)
185 
186  DECLARE_VAR(MovieUseBackground)
187  DECLARE_VAR(CameraSkipAnimation)
188  DECLARE_VAR(MovieAmbiantScriptStartFrame)
189  DECLARE_VAR(MovieAmbiantScript)
190  DECLARE_VAR(MovieScriptStartFrame)
191  DECLARE_VAR(MovieScript)
192 
193  DECLARE_VAR(CameraMoveSpeed)
194 
195  DECLARE_VAR(TransitionSound)
196  DECLARE_VAR(TransitionSoundVolume)
197 
198  DECLARE_VAR(LocationNextNode)
199  DECLARE_VAR(LocationNextRoom)
200  DECLARE_VAR(LocationNextAge)
201 
202  DECLARE_VAR(BallPosition)
203  DECLARE_VAR(BallFrame)
204  DECLARE_VAR(BallLeverLeft)
205  DECLARE_VAR(BallLeverRight)
206 
207  DECLARE_VAR(BallDoorOpen)
208 
209  DECLARE_VAR(ProjectorX)
210  DECLARE_VAR(ProjectorY)
211  DECLARE_VAR(ProjectorZoom)
212  DECLARE_VAR(ProjectorBlur)
213  DECLARE_VAR(ProjectorAngleXOffset)
214  DECLARE_VAR(ProjectorAngleYOffset)
215  DECLARE_VAR(ProjectorAngleZoomOffset)
216  DECLARE_VAR(ProjectorAngleBlurOffset)
217 
218  DECLARE_VAR(JournalAtrusState)
219  DECLARE_VAR(JournalSaavedroState)
220  DECLARE_VAR(JournalSaavedroClosed)
221  DECLARE_VAR(JournalSaavedroOpen)
222  DECLARE_VAR(JournalSaavedroLastPage)
223  DECLARE_VAR(JournalSaavedroChapter)
224  DECLARE_VAR(JournalSaavedroPageInChapter)
225 
226  DECLARE_VAR(TeslaAllAligned)
227  DECLARE_VAR(TeslaTopAligned)
228  DECLARE_VAR(TeslaMiddleAligned)
229  DECLARE_VAR(TeslaBottomAligned)
230  DECLARE_VAR(TeslaMovieStart)
231 
232  DECLARE_VAR(AmateriaSecondsCounter)
233  DECLARE_VAR(AmateriaTicksCounter)
234 
235  DECLARE_VAR(ResonanceRingsSolved)
236 
237  DECLARE_VAR(PinballRemainingPegs)
238 
239  DECLARE_VAR(OuterShieldUp)
240  DECLARE_VAR(InnerShieldUp)
241  DECLARE_VAR(SaavedroStatus)
242 
243  DECLARE_VAR(BookStateTomahna)
244  DECLARE_VAR(BookStateReleeshahn)
245 
246  DECLARE_VAR(SymbolCode2Solved)
247  DECLARE_VAR(SymbolCode1AllSolved)
248  DECLARE_VAR(SymbolCode1CurrentSolved)
249  DECLARE_VAR(SymbolCode1TopSolved)
250  DECLARE_VAR(SymbolCode1LeftSolved)
251  DECLARE_VAR(SymbolCode1RightSolved)
252 
253  DECLARE_VAR(SoundVoltaicUnk540)
254  DECLARE_VAR(SoundEdannaUnk587)
255  DECLARE_VAR(SoundAmateriaUnk627)
256  DECLARE_VAR(SoundAmateriaUnk930)
257  DECLARE_VAR(SoundEdannaUnk1031)
258  DECLARE_VAR(SoundVoltaicUnk1146)
259 
260  DECLARE_VAR(ZipModeEnabled)
261  DECLARE_VAR(SubtitlesEnabled)
262  DECLARE_VAR(WaterEffects)
263  DECLARE_VAR(TransitionSpeed)
264  DECLARE_VAR(MouseSpeed)
265  DECLARE_VAR(DialogResult)
266 
267  DECLARE_VAR(MenuEscapePressed)
268  DECLARE_VAR(MenuNextAction)
269  DECLARE_VAR(MenuLoadBack)
270  DECLARE_VAR(MenuSaveBack)
271  DECLARE_VAR(MenuSaveAction)
272  DECLARE_VAR(MenuOptionsBack)
273 
274  DECLARE_VAR(MenuSaveLoadPageLeft)
275  DECLARE_VAR(MenuSaveLoadPageRight)
276  DECLARE_VAR(MenuSaveLoadSelectedItem)
277  DECLARE_VAR(MenuSaveLoadCurrentPage)
278 
279  DECLARE_VAR(OverallVolume)
280  DECLARE_VAR(MusicVolume)
281  DECLARE_VAR(MusicFrequency)
282  DECLARE_VAR(LanguageAudio)
283  DECLARE_VAR(LanguageText)
284  DECLARE_VAR(HotspotIgnoreClick)
285  DECLARE_VAR(HotspotHovered)
286  DECLARE_VAR(SpotSubtitle)
287 
288  DECLARE_VAR(DragLeverLimited)
289  DECLARE_VAR(DragLeverLimitMin)
290  DECLARE_VAR(DragLeverLimitMax)
291 
292  DECLARE_VAR(ShieldEffectActive)
293 
294  // Xbox specific variables
295  DECLARE_VAR(GamePadActionPressed)
296  DECLARE_VAR(GamePadDownPressed)
297  DECLARE_VAR(GamePadUpPressed)
298  DECLARE_VAR(GamePadLeftPressed)
299  DECLARE_VAR(GamePadRightPressed)
300  DECLARE_VAR(GamePadCancelPressed)
301 
302  DECLARE_VAR(DragWithDirectionKeys)
303  DECLARE_VAR(MenuSavesAvailable)
304  DECLARE_VAR(MenuSelectedSave)
305  DECLARE_VAR(MenuAttractCountDown)
306  DECLARE_VAR(MovieOptional)
307  DECLARE_VAR(VibrationEnabled)
308  DECLARE_VAR(StateCanSave)
309 
310  void updateFrameCounters();
311  uint getTickCount() const;
312 
314  void pauseEngine(bool pause);
315 
316  ViewType getViewType() { return static_cast<ViewType>(_data.currentNodeType); }
317  void setViewType(ViewType t) { _data.currentNodeType = t; }
318 
319  float getLookAtFOV() { return _data.lookatFOV; }
320  void setLookAtFOV(float fov) { _data.lookatFOV = fov; }
321  float getLookAtPitch() { return _data.lookatPitch; }
322  float getLookAtHeading() { return _data.lookatHeading; }
323  void lookAt(float pitch, float heading) { _data.lookatPitch = pitch; _data.lookatHeading = heading; }
324 
325  void limitCubeCamera(float minPitch, float maxPitch, float minHeading, float maxHeading);
326  void freeCubeCamera() { _data.limitCubeCamera = false; }
327  bool isCameraLimited() { return _data.limitCubeCamera != 0; }
328  float getMinPitch() { return _data.minPitch; }
329  float getMaxPitch() { return _data.maxPitch; }
330  float getMinHeading() { return _data.minHeading; }
331  float getMaxHeading() { return _data.maxHeading; }
332 
333  void markNodeAsVisited(uint16 node, uint16 room, uint32 age);
334  bool isZipDestinationAvailable(uint16 node, uint16 room, uint32 age);
335 
336  Common::String formatSaveTime();
337 
338  Common::Array<uint16> getInventory();
339  void updateInventory(const Common::Array<uint16> &items);
340 
341  struct StateData {
342  uint32 version;
343  uint32 gameRunning;
344  uint32 tickCount;
345  uint32 nextSecondsUpdate;
346  uint32 secondsPlayed;
347  uint32 dword_4C2C44;
348  uint32 dword_4C2C48;
349  uint32 dword_4C2C4C;
350  uint32 dword_4C2C50;
351  uint32 dword_4C2C54;
352  uint32 dword_4C2C58;
353  uint32 dword_4C2C5C;
354  uint32 dword_4C2C60;
355  uint32 currentNodeType;
356  float lookatPitch;
357  float lookatHeading;
358  float lookatFOV;
359  float pitchOffset;
360  float headingOffset;
361  uint32 limitCubeCamera;
362  float minPitch;
363  float maxPitch;
364  float minHeading;
365  float maxHeading;
366  uint32 dword_4C2C90;
367  int32 vars[2048];
368  uint32 inventoryCount;
369  uint32 inventoryList[7];
370  uint32 zipDestinations[64];
371 
372  uint8 saveDay;
373  uint8 saveMonth;
374  uint16 saveYear;
375 
376  uint8 saveHour;
377  uint8 saveMinute;
378 
379  Common::String saveDescription;
380 
381  bool isAutosave;
382 
383  StateData();
384  Common::Error syncWithSaveGame(Common::Serializer &s);
385  };
386 
387  static const Graphics::PixelFormat getThumbnailSavePixelFormat();
388  static Graphics::Surface *readThumbnail(Common::ReadStream *inStream);
389  static void writeThumbnail(Common::WriteStream *outStream, const Graphics::Surface *thumbnail);
390  static Graphics::Surface *resizeThumbnail(Graphics::Surface *big, uint width, uint height);
391 
392  static const uint kThumbnailWidth = 240;
393  static const uint kThumbnailHeight = 135;
394 
395 private:
396  const Common::Platform _platform;
397  Database *_db;
398 
399  static const uint32 kSaveVersion = 150;
400 
401  StateData _data;
402 
403  static const uint32 kTickDuration = 1000 / 30;
404  uint32 _lastTickStartTime;
405 
406  struct VarDescription {
407  VarDescription() : var(0), name(0), unknown(0) {}
408  VarDescription(uint16 v, const char *n, bool u) : var(v), name(n), unknown(u) {}
409 
410  uint16 var;
411  const char *name;
412  bool unknown;
413  };
414 
416 
417  VarMap _varDescriptions;
418 
419  void checkRange(uint16 var);
420  const VarDescription findDescription(uint16 var);
421  void shiftVariables(uint16 base, int32 value);
422 
423  int32 engineGet(const Common::String &varName);
424  void engineSet(const Common::String &varName, int32 value);
425 
426  static void syncFloat(Common::Serializer &s, float &val,
427  Common::Serializer::Version minVersion = 0,
428  Common::Serializer::Version maxVersion = Common::Serializer::kLastVersion);
429 
430  void updateTickCounters();
431 };
432 
436 struct Saves {
438  static Common::String buildName(const char *name, Common::Platform platform);
439 
441  static Common::StringArray list(Common::SaveFileManager *saveFileManager, Common::Platform platform);
442 };
443 
444 } // End of namespace Myst3
445 
446 #endif // VARIABLES_H_
Definition: state.h:341
Definition: state.h:436
Definition: str.h:59
Definition: surface.h:67
Definition: stream.h:77
Definition: savefile.h:54
Definition: error.h:84
Definition: pixelformat.h:138
Definition: ambient.h:27
Definition: state.h:48
Definition: stream.h:745
Definition: serializer.h:79
void pauseEngine(bool pause)
Definition: database.h:162
Definition: stream.h:385
Definition: savefile.h:142
Platform
Definition: platform.h:46