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
32namespace Myst3 {
33
34class Database;
35
36// View type
37enum 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
48class GameState {
49public:
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(MovieNoFrameSkip)
162 DECLARE_VAR(MovieUnk147)
163 DECLARE_VAR(MovieUnk148)
164 DECLARE_VAR(MovieScriptDriven)
165 DECLARE_VAR(MovieNextFrameSetVar)
166 DECLARE_VAR(MovieNextFrameGetVar)
167 DECLARE_VAR(MovieStartFrameVar)
168 DECLARE_VAR(MovieEndFrameVar)
169 DECLARE_VAR(MovieForce2d)
170 DECLARE_VAR(MovieVolumeVar)
171 DECLARE_VAR(MovieSoundHeading)
172 DECLARE_VAR(MoviePanningStrenght)
173 DECLARE_VAR(MovieSynchronized)
174 DECLARE_VAR(MovieOverrideCondition)
175 DECLARE_VAR(MovieUVar)
176 DECLARE_VAR(MovieVVar)
177 DECLARE_VAR(MovieOverridePosition)
178 DECLARE_VAR(MovieOverridePosU)
179 DECLARE_VAR(MovieOverridePosV)
180 DECLARE_VAR(MovieAdditiveBlending)
181 DECLARE_VAR(MovieTransparency)
182 DECLARE_VAR(MovieTransparencyVar)
183 DECLARE_VAR(MoviePlayingVar)
184 DECLARE_VAR(MovieStartSoundId)
185 DECLARE_VAR(MovieStartSoundVolume)
186 DECLARE_VAR(MovieStartSoundHeading)
187 DECLARE_VAR(MovieStartSoundAttenuation)
188
189 DECLARE_VAR(MovieUseBackground)
190 DECLARE_VAR(CameraSkipAnimation)
191 DECLARE_VAR(MovieAmbiantScriptStartFrame)
192 DECLARE_VAR(MovieAmbiantScript)
193 DECLARE_VAR(MovieScriptStartFrame)
194 DECLARE_VAR(MovieScript)
195
196 DECLARE_VAR(CameraMoveSpeed)
197
198 DECLARE_VAR(TransitionSound)
199 DECLARE_VAR(TransitionSoundVolume)
200
201 DECLARE_VAR(LocationNextNode)
202 DECLARE_VAR(LocationNextRoom)
203 DECLARE_VAR(LocationNextAge)
204
205 DECLARE_VAR(BallPosition)
206 DECLARE_VAR(BallFrame)
207 DECLARE_VAR(BallLeverLeft)
208 DECLARE_VAR(BallLeverRight)
209
210 DECLARE_VAR(BallDoorOpen)
211
212 DECLARE_VAR(ProjectorX)
213 DECLARE_VAR(ProjectorY)
214 DECLARE_VAR(ProjectorZoom)
215 DECLARE_VAR(ProjectorBlur)
216 DECLARE_VAR(ProjectorAngleXOffset)
217 DECLARE_VAR(ProjectorAngleYOffset)
218 DECLARE_VAR(ProjectorAngleZoomOffset)
219 DECLARE_VAR(ProjectorAngleBlurOffset)
220
221 DECLARE_VAR(JournalAtrusState)
222 DECLARE_VAR(JournalSaavedroState)
223 DECLARE_VAR(JournalSaavedroClosed)
224 DECLARE_VAR(JournalSaavedroOpen)
225 DECLARE_VAR(JournalSaavedroLastPage)
226 DECLARE_VAR(JournalSaavedroChapter)
227 DECLARE_VAR(JournalSaavedroPageInChapter)
228
229 DECLARE_VAR(TeslaAllAligned)
230 DECLARE_VAR(TeslaTopAligned)
231 DECLARE_VAR(TeslaMiddleAligned)
232 DECLARE_VAR(TeslaBottomAligned)
233 DECLARE_VAR(TeslaMovieStart)
234
235 DECLARE_VAR(AmateriaSecondsCounter)
236 DECLARE_VAR(AmateriaTicksCounter)
237
238 DECLARE_VAR(ResonanceRingsSolved)
239
240 DECLARE_VAR(PinballRemainingPegs)
241
242 DECLARE_VAR(OuterShieldUp)
243 DECLARE_VAR(InnerShieldUp)
244 DECLARE_VAR(SaavedroStatus)
245
246 DECLARE_VAR(BookStateTomahna)
247 DECLARE_VAR(BookStateReleeshahn)
248
249 DECLARE_VAR(SymbolCode2Solved)
250 DECLARE_VAR(SymbolCode1AllSolved)
251 DECLARE_VAR(SymbolCode1CurrentSolved)
252 DECLARE_VAR(SymbolCode1TopSolved)
253 DECLARE_VAR(SymbolCode1LeftSolved)
254 DECLARE_VAR(SymbolCode1RightSolved)
255
256 DECLARE_VAR(SoundVoltaicUnk540)
257 DECLARE_VAR(SoundEdannaUnk587)
258 DECLARE_VAR(SoundAmateriaUnk627)
259 DECLARE_VAR(SoundAmateriaUnk930)
260 DECLARE_VAR(SoundEdannaUnk1031)
261 DECLARE_VAR(SoundVoltaicUnk1146)
262
263 DECLARE_VAR(ZipModeEnabled)
264 DECLARE_VAR(SubtitlesEnabled)
265 DECLARE_VAR(WaterEffects)
266 DECLARE_VAR(TransitionSpeed)
267 DECLARE_VAR(MouseSpeed)
268 DECLARE_VAR(DialogResult)
269
270 DECLARE_VAR(MenuEscapePressed)
271 DECLARE_VAR(MenuNextAction)
272 DECLARE_VAR(MenuLoadBack)
273 DECLARE_VAR(MenuSaveBack)
274 DECLARE_VAR(MenuSaveAction)
275 DECLARE_VAR(MenuOptionsBack)
276
277 DECLARE_VAR(MenuSaveLoadPageLeft)
278 DECLARE_VAR(MenuSaveLoadPageRight)
279 DECLARE_VAR(MenuSaveLoadSelectedItem)
280 DECLARE_VAR(MenuSaveLoadCurrentPage)
281
282 DECLARE_VAR(OverallVolume)
283 DECLARE_VAR(MusicVolume)
284 DECLARE_VAR(MusicFrequency)
285 DECLARE_VAR(LanguageAudio)
286 DECLARE_VAR(LanguageText)
287 DECLARE_VAR(HotspotIgnoreClick)
288 DECLARE_VAR(HotspotHovered)
289 DECLARE_VAR(SpotSubtitle)
290
291 DECLARE_VAR(DragLeverLimited)
292 DECLARE_VAR(DragLeverLimitMin)
293 DECLARE_VAR(DragLeverLimitMax)
294
295 DECLARE_VAR(ShieldEffectActive)
296
297 // Xbox specific variables
298 DECLARE_VAR(GamePadActionPressed)
299 DECLARE_VAR(GamePadDownPressed)
300 DECLARE_VAR(GamePadUpPressed)
301 DECLARE_VAR(GamePadLeftPressed)
302 DECLARE_VAR(GamePadRightPressed)
303 DECLARE_VAR(GamePadCancelPressed)
304
305 DECLARE_VAR(DragWithDirectionKeys)
306 DECLARE_VAR(MenuSavesAvailable)
307 DECLARE_VAR(MenuSelectedSave)
308 DECLARE_VAR(MenuAttractCountDown)
309 DECLARE_VAR(MovieOptional)
310 DECLARE_VAR(VibrationEnabled)
311 DECLARE_VAR(StateCanSave)
312
313 void updateFrameCounters();
314 uint getTickCount() const;
315
317 void pauseEngine(bool pause);
318
319 ViewType getViewType() { return static_cast<ViewType>(_data.currentNodeType); }
320 void setViewType(ViewType t) { _data.currentNodeType = t; }
321
322 float getLookAtFOV() { return _data.lookatFOV; }
323 void setLookAtFOV(float fov) { _data.lookatFOV = fov; }
324 float getLookAtPitch() { return _data.lookatPitch; }
325 float getLookAtHeading() { return _data.lookatHeading; }
326 void lookAt(float pitch, float heading) { _data.lookatPitch = pitch; _data.lookatHeading = heading; }
327
328 void limitCubeCamera(float minPitch, float maxPitch, float minHeading, float maxHeading);
329 void freeCubeCamera() { _data.limitCubeCamera = false; }
330 bool isCameraLimited() { return _data.limitCubeCamera != 0; }
331 float getMinPitch() { return _data.minPitch; }
332 float getMaxPitch() { return _data.maxPitch; }
333 float getMinHeading() { return _data.minHeading; }
334 float getMaxHeading() { return _data.maxHeading; }
335
336 void markNodeAsVisited(uint16 node, uint16 room, uint32 age);
337 bool isZipDestinationAvailable(uint16 node, uint16 room, uint32 age);
338
339 Common::String formatSaveTime();
340
341 Common::Array<uint16> getInventory();
342 void updateInventory(const Common::Array<uint16> &items);
343
344 struct StateData {
345 uint32 version;
346 uint32 gameRunning;
347 uint32 tickCount;
348 uint32 nextSecondsUpdate;
349 uint32 secondsPlayed;
350 uint32 dword_4C2C44;
351 uint32 dword_4C2C48;
352 uint32 dword_4C2C4C;
353 uint32 dword_4C2C50;
354 uint32 dword_4C2C54;
355 uint32 dword_4C2C58;
356 uint32 dword_4C2C5C;
357 uint32 dword_4C2C60;
358 uint32 currentNodeType;
359 float lookatPitch;
360 float lookatHeading;
361 float lookatFOV;
362 float pitchOffset;
363 float headingOffset;
364 uint32 limitCubeCamera;
365 float minPitch;
366 float maxPitch;
367 float minHeading;
368 float maxHeading;
369 uint32 dword_4C2C90;
370 int32 vars[2048];
371 uint32 inventoryCount;
372 uint32 inventoryList[7];
373 uint32 zipDestinations[64];
374
375 uint8 saveDay;
376 uint8 saveMonth;
377 uint16 saveYear;
378
379 uint8 saveHour;
380 uint8 saveMinute;
381
382 Common::String saveDescription;
383
384 bool isAutosave;
385
386 StateData();
387 Common::Error syncWithSaveGame(Common::Serializer &s);
388 };
389
390 static const Graphics::PixelFormat getThumbnailSavePixelFormat();
391 static Graphics::Surface *readThumbnail(Common::ReadStream *inStream);
392 static void writeThumbnail(Common::WriteStream *outStream, const Graphics::Surface *thumbnail);
393 static Graphics::Surface *resizeThumbnail(Graphics::Surface *big, uint width, uint height);
394
395 static const uint kThumbnailWidth = 240;
396 static const uint kThumbnailHeight = 135;
397
398private:
399 const Common::Platform _platform;
400 Database *_db;
401
402 static const uint32 kSaveVersion = 150;
403
404 StateData _data;
405
406 static const uint32 kTickDuration = 1000 / 30;
407 uint32 _lastTickStartTime;
408
409 struct VarDescription {
410 VarDescription() : var(0), name(0), unknown(0) {}
411 VarDescription(uint16 v, const char *n, bool u) : var(v), name(n), unknown(u) {}
412
413 uint16 var;
414 const char *name;
415 bool unknown;
416 };
417
419
420 VarMap _varDescriptions;
421
422 void checkRange(uint16 var);
423 const VarDescription findDescription(uint16 var);
424 void shiftVariables(uint16 base, int32 value);
425
426 int32 engineGet(const Common::String &varName);
427 void engineSet(const Common::String &varName, int32 value);
428
429 static void syncFloat(Common::Serializer &s, float &val,
430 Common::Serializer::Version minVersion = 0,
431 Common::Serializer::Version maxVersion = Common::Serializer::kLastVersion);
432
433 void updateTickCounters();
434};
435
439struct Saves {
441 static Common::String buildName(const char *name, Common::Platform platform);
442
445};
446
447} // End of namespace Myst3
448
449#endif // VARIABLES_H_
Definition: error.h:81
Definition: savefile.h:54
Definition: stream.h:385
Definition: savefile.h:142
Definition: stream.h:745
Definition: serializer.h:80
Definition: str.h:59
Definition: stream.h:77
Definition: database.h:162
Definition: state.h:48
void pauseEngine(bool pause)
Platform
Definition: platform.h:93
Definition: pixelformat.h:138
Definition: surface.h:67
Definition: state.h:344
Definition: state.h:439
static Common::StringArray list(Common::SaveFileManager *saveFileManager, Common::Platform platform)
static Common::String buildName(const char *name, Common::Platform platform)