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