aboutsummaryrefslogtreecommitdiff
path: root/engines/mohawk/myst_state.h
blob: a3bb38b808ab9977b9c113306bb24074180b28d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

#ifndef MYST_SAVELOAD_H
#define MYST_SAVELOAD_H

#include "common/savefile.h"
#include "common/file.h"
#include "common/str.h"

#include "engines/savestate.h"

namespace Common {
class Serializer;
}

namespace Mohawk {

class MohawkEngine_Myst;

struct MystSaveMetadata {
	uint8 saveDay;
	uint8 saveMonth;
	uint16 saveYear;

	uint8 saveHour;
	uint8 saveMinute;

	uint32 totalPlayTime;

	bool autoSave;

	Common::String saveDescription;

	MystSaveMetadata();
	bool sync(Common::Serializer &s);
};

// Page being held
enum HeldPage {
	kNoPage              = 0,
	kBlueLibraryPage     = 1,
	kBlueSeleniticPage   = 2,
	kBlueMechanicalPage  = 3,
	kBlueStoneshipPage   = 4,
	kBlueChannelwoodPage = 5,
	kBlueFirePlacePage   = 6,
	kRedLibraryPage      = 7,
	kRedSeleniticPage    = 8,
	kRedMechanicalPage   = 9,
	kRedStoneshipPage    = 10,
	kRedChannelwoodPage  = 11,
	kRedFirePlacePage    = 12,
	kWhitePage           = 13
};

// Age the player is in
enum ActiveAge {
	kSelenitic     = 0,
	kStoneship     = 1,
	kMystLibrary   = 2,
	kMechanical    = 3,
	kChannelwood   = 4,
	kIntro         = 5,
	kDni           = 6,
	kMystStart     = 7,
	kCredits       = 8,
	kSirrusEnding  = 9,
	kAchenarEnding = 10
};

// Various states that Atrus can be in when in Dni
enum DniEnding {
	kDniNotVisited    = 0, // Player hasn't been to Dni/K'veer yet
	kAtrusWantsPage   = 1, // Player is in Dni with the white page
	kAtrusLeaves      = 2, // Atrus leaves Dni after receiving the white page
	kForgotPage       = 3, // Player has entered Dni without bringing the white page
	kBooksDestroyed   = 4  // Atrus returns to Dni after previously leaving 
						   // and destroying the books of his sons
};

class MystGameState {
public:
	static const int kAutoSaveSlot;

	MystGameState(MohawkEngine_Myst*, Common::SaveFileManager*);
	~MystGameState();

	static SaveStateDescriptor querySaveMetaInfos(int slot);
	static Common::String querySaveDescription(int slot);

	void reset();
	bool load(int slot);
	bool save(int slot, const Common::String &desc, const Graphics::Surface *thumbnail, bool autosave);
	bool isAutoSaveAllowed();
	static void deleteSave(int slot);

	void addZipDest(MystStack stack, uint16 view);
	bool isReachableZipDest(MystStack stack, uint16 view);

	/* 8 Game Global Variables :
	   0 = Unknown - Fixed at 2
	   1 = Current Age / Stack
	   2 = Page Being Held
	   3 = Unknown - Fixed at 1
	   4 = Slide Transitions
	   5 = Ending
	   6 = Red Pages in Book
	   7 = Blue Pages in Book
	*/
	struct Globals {
		uint16 u0;
		ActiveAge currentAge;
		HeldPage heldPage;
		uint16 u1;
		uint16 transitions;
		uint16 zipMode;
		uint16 redPagesInBook;
		uint16 bluePagesInBook;
		DniEnding ending;
	} _globals;

	/* 50 Myst Specific Variables :
	   0  = Marker Switch Near Cabin
	   1  = Marker Switch Near Clock Tower
	   2  = Marker Switch on Dock
	   3  = Marker Switch Near Ship Pool
	   4  = Marker Switch Near Gears
	   5  = Marker Switch Near Generator Room
	   6  = Marker Switch Near Stellar Observatory
	   7  = Marker Switch Near Rocket Ship
	   8  = Fireplace, Opened Green Book Before
	   9  = Ship State
	   10 = Cabin Gas Valve Position
	   11 = Clock Tower Hour Hand Position
	   12 = Clock Tower Minute Hand Position
	   13 = Clock Tower Puzzle Solved / Gears Open
	   14 = Clock Tower Gear Bridge
	   15 = Generator Breaker State
	   16 = Generator Button State
	   17 = Generator Voltage State
	   18 = Library Bookcase Door
	   19 = Dock Imager Numeric Selection
	   20 = Dock Imager Active
	   21 = Unknown #1 - Fixed at 0
	   22 = Unknown #2 - Fixed at 0
	   23 = Unknown #3 - Fixed at 0
	   24 = Unknown #4 - Fixed at 0
	   25 = Tower Rotation Angle
	   26 = Boxes For Ship Float Puzzle
	   27 = Tree Boiler Pilot Light Lit
	   28 = Stellar Observatory Viewer, Control Setting Day
	   29 = Stellar Observatory Lights
	   30 = Stellar Observatory Viewer, Control Setting Month
	   31 = Stellar Observatory Viewer, Control Setting Time
	   32 = Stellar Observatory Viewer, Control Setting Year
	   33 = Stellar Observatory Viewer, Target Day
	   34 = Stellar Observatory Viewer, Target Month
	   35 = Stellar Observatory Viewer, Target Time
	   36 = Stellar Observatory Viewer, Target Year
 	   37 = Cabin Safe Combination
	   38 = Channelwood Tree Position
	   39 = Checksum? #1
	   40 = Checksum? #2
	   41 = Rocketship Music Puzzle Slider #1 Position
	   42 = Rocketship Music Puzzle Slider #2 Position
	   43 = Rocketship Music Puzzle Slider #3 Position
	   44 = Rocketship Music Puzzle Slider #4 Position
	   45 = Rocketship Music Puzzle Slider #5 Position
	   46 = Unknown #5
	   47 = Unknown #6
	   48 = Unknown #7
	   49 = Unknown #8
	*/
	struct Myst {
		uint32 cabinMarkerSwitch;
		uint32 clockTowerMarkerSwitch;
		uint32 dockMarkerSwitch;
		uint32 poolMarkerSwitch;
		uint32 gearsMarkerSwitch;
		uint32 generatorMarkerSwitch;
		uint32 observatoryMarkerSwitch;
		uint32 rocketshipMarkerSwitch;
		uint16 greenBookOpenedBefore;
		uint16 shipFloating;
		uint16 cabinValvePosition;
		uint16 clockTowerHourPosition;
		uint16 clockTowerMinutePosition;
		uint16 gearsOpen;
		uint16 clockTowerBridgeOpen;
		uint16 generatorBreakers;
		uint16 generatorButtons;
		uint16 generatorVoltage;
		uint16 libraryBookcaseDoor;
		uint16 imagerSelection;
		uint16 imagerActive;
		uint16 imagerWaterErased;
		uint16 imagerMountainErased;
		uint16 imagerAtrusErased;
		uint16 imagerMarkerErased;
		uint16 towerRotationAngle;
		uint16 courtyardImageBoxes;
		uint16 cabinPilotLightLit;
		uint16 observatoryDaySetting;
		uint16 observatoryLights;
		uint16 observatoryMonthSetting;
		uint16 observatoryTimeSetting;
		uint16 observatoryYearSetting;
		uint16 observatoryDayTarget;
		uint16 observatoryMonthTarget;
		uint16 observatoryTimeTarget;
		uint16 observatoryYearTarget;
		uint16 cabinSafeCombination;
		uint16 treePosition;
		uint32 treeLastMoveTime;
		uint16 rocketSliderPosition[5];
		uint16 observatoryDaySlider;
		uint16 observatoryMonthSlider;
		uint16 observatoryYearSlider;
		uint16 observatoryTimeSlider;
	} _myst;

	/* 7 Channelwood Specific Variables :
	    0 = Water Pump Bridge State
	    1 = Lower Walkway to Upper Walkway Elevator State
	    2 = Lower Walkway to Upper Walkway Spiral Stair Lower Door State
	    3 = Extendable Pipe State
	    4 = Water Valve States
	    5 = Achenar's Holoprojector Selection
	    6 = Lower Walkway to Upper Walkway Spiral Stair Upper Door State
	*/
	struct Channelwood {
		uint32 waterPumpBridgeState;
		uint32 elevatorState;
		uint32 stairsLowerDoorState;
		uint32 pipeState;
		uint16 waterValveStates;
		uint16 holoprojectorSelection;
		uint16 stairsUpperDoorState;
	} _channelwood;

	/* 8 Mech Specific Variables :
	    0 = Achenar's Room Secret Panel State
	    1 = Sirrus' Room Secret Panel State
	    2 = Fortress Staircase State
	    3 = Fortress Elevator Rotation
	    4 = Code Lock Shape #1 (Left)
	    5 = Code Lock Shape #2
	    6 = Code Lock Shape #3
	    7 = Code Lock Shape #4 (Right)
	*/
	struct Mechanical {
		uint32 achenarCrateOpened;
		uint16 achenarPanelState;
		uint16 sirrusPanelState;
		uint16 staircaseState;
		uint16 elevatorRotation;
		uint16 codeShape[4];
	} _mechanical;

	/* 18 Selenitic Specific Variables :
	    0 = Sound Pickup At Water Pool
	    1 = Sound Pickup At Volcanic Crack
	    2 = Sound Pickup At Clock
	    3 = Sound Pickup At Crystal Rocks
	    4 = Sound Pickup At Windy Tunnel
	    5 = Sound Receiver Doors
	    6 = Windy Tunnel Lights
	    7 = Sound Receiver Current Input
	    8 = Sound Receiver Input #0 (Water Pool) Angle Value
	    9 = Sound Receiver Input #1 (Volcanic Crack) Angle Value
	   10 = Sound Receiver Input #2 (Clock) Angle Value
	   11 = Sound Receiver Input #3 (Crystal Rocks) Angle Value
	   12 = Sound Receiver Input #4 (Windy Tunnel) Angle Value
	   13 = Sound Lock Slider #1 (Left) Position
	   14 = Sound Lock Slider #2 Position
	   15 = Sound Lock Slider #3 Position
	   16 = Sound Lock Slider #4 Position
	   17 = Sound Lock Slider #5 (Right) Position
	*/
	struct Selenitic {
		uint32 emitterEnabledWater;
		uint32 emitterEnabledVolcano;
		uint32 emitterEnabledClock;
		uint32 emitterEnabledCrystal;
		uint32 emitterEnabledWind;
		uint32 soundReceiverOpened;
		uint32 tunnelLightsSwitchedOn;
		uint16 soundReceiverCurrentSource;
		uint16 soundReceiverPositions[5];
		uint16 soundLockSliderPositions[5];
	} _selenitic;

	/* 14 Stoneship Specific Variables :
	    0 = Light State
	    1 = Secret side door opened
	    2 = Water Pump State
	    3 = Lighthouse Trapdoor State
	    4 = Lighthouse Chest Water State
	    5 = Lighthouse Chest Valve State
	    6 = Lighthouse Chest Open State
	    7 = Lighthouse Trapdoor Key State
	    8 = Lighthouse Battery Duration
	    9 = Lighthouse Battery Power Good
	   10 = Lighthouse Battery Depletion Time
	*/
	struct Stoneship {
		uint32 lightState;
		uint16 sideDoorOpened;
		uint16 pumpState;
		uint16 trapdoorState;
		uint16 chestWaterState;
		uint16 chestValveState;
		uint16 chestOpenState;
		uint16 trapdoorKeyState;
		uint32 generatorDuration;
		uint16 generatorPowerAvailable;
		uint32 generatorDepletionTime;
	} _stoneship;

	MystSaveMetadata _metadata;

private:
	void syncGameState(Common::Serializer &s, bool isME);
	static Common::String buildSaveFilename(int slot);
	static Common::String buildMetadataFilename(int slot);
	bool loadState(int slot);
	void loadMetadata(int slot);
	bool saveState(int slot);
	void updateMetadateForSaving(const Common::String &desc, bool autoSave);
	bool saveMetadata(int slot, const Graphics::Surface *thumbnail);

	// The values in these regions are lists of VIEW resources
	// which correspond to visited zip destinations

	typedef uint16 ZipDests[41];

	ZipDests _mystReachableZipDests;

	ZipDests _channelwoodReachableZipDests;

	ZipDests _mechReachableZipDests;

	ZipDests _seleniticReachableZipDests;

	ZipDests _stoneshipReachableZipDests;

	MohawkEngine_Myst *_vm;
	Common::SaveFileManager *_saveFileMan;
};

} // End of namespace Mohawk

#endif