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
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 TWINE_SCENE_GAMESTATE_H
24 #define TWINE_SCENE_GAMESTATE_H
25 
26 #include "common/savefile.h"
27 #include "common/scummsys.h"
28 #include "twine/menu/menu.h"
29 
30 namespace TwinE {
31 
32 /** Magicball strength*/
33 enum MagicballStrengthType {
34 	kNoBallStrength = 2,
35 	kYellowBallStrength = 3,
36 	kGreenBallStrength = 4,
37 	kRedBallStrength = 6,
38 	kFireBallStrength = 8
39 };
40 
41 class TwinEEngine;
42 
43 class GameState {
44 private:
45 	TwinEEngine *_engine;
46 
47 	void initGameStateVars();
48 	void initHeroVars();
49 
50 	MenuSettings _gameChoicesSettings;
51 
52 	/**
53 	 * LBA engine game flags to save quest states
54 	 *
55 	 * 0-27: inventory related
56 	 * 28-158: story related
57 	 * 159..199: unused
58 	 * 200-219: video related
59 	 * 220..255: unused
60 	 *
61 	 * 35: If 0, a zommed sequence of opening the ventilation shaft will be played when Twinsen escapes
62 	 * his house after arresting Zoe. Set to 1 after the sequence (also if Twinsen is killed during the arrest).
63 	 * 47: Value of 1 indicates that Twinsen has opened the door to the Citadel Island Tavern's basement.
64 	 * The door will be always open from now on.
65 	 * 70: Set to 1 if inventory items are taken from Twinsen when he goes to jail (inventory is empty),
66 	 * set to 0 after he gets back his stuff.
67 	 * 92: Set to 1 if the green grobo in the Citadel Island Tavern has told Twinsen about taking Zoe to the
68 	 * port and leaving for another island.
69 	 * 107: Set to 1 after Twinsen kills yellow groboclone in the Citadel Island Tavern (after the Tavern has
70 	 * been closed down). Makes the Tavern open again and groboclone not appear any more.
71 	 */
72 	// TODO: why not NUM_GAME_FLAGS?
73 	uint8 _gameStateFlags[256];
74 
75 public:
76 	GameState(TwinEEngine *engine);
77 
78 	/**
79 	 * LBA engine chapter
80 	 *  0: Inprisoned
81 	 *  1: Escape from the citadel
82 	 *  2: Zoe got captured
83 	 *  3: - looking for a young girl
84 	 *  4: - looking for a "friend"
85 	 *  5: The legend of Sendell
86 	 *  6: The book of Bu
87 	 *  7: Pirate LeBorne
88 	 *  8: - "good day"
89 	 *  9: - "good day"
90 	 * 10: - ?? nothing
91 	 * 11: - ?? nothing
92 	 * 12: - ?? nothing
93 	 * 13: - looking for plans
94 	 * 14: - still looking for plans
95 	 * 15: The final showdown - "good day"
96 	 */
97 	int16 _gameChapter = 0;
98 
99 	/** Magic ball type index */
100 	int16 _magicBallIdx = 0;
101 	/** Magic ball num bounce */
102 	int16 _magicBallNumBounce = 0;
103 	/** Magic ball auxiliar bounce number */
104 	int16 _magicBallAuxBounce = 0; // magicBallParam
105 	/** Magic level index */
106 	int16 _magicLevelIdx = 0;
107 
108 	/** Store the number of inventory keys */
109 	int16 _inventoryNumKeys = 0;
110 	/** Store the number of inventory kashes */
111 	int16 _inventoryNumKashes = 0;
112 	/** Store the number of inventory clover leafs boxes */
113 	int16 _inventoryNumLeafsBox = 0;
114 	/** Store the number of inventory clover leafs */
115 	int16 _inventoryNumLeafs = 0;
116 	/** Store the number of inventory magic points */
117 	int16 _inventoryMagicPoints = 0;
118 	/** Store the number of gas */
119 	int16 _inventoryNumGas = 0;
120 
121 	/** Its using FunFrock Sabre */
122 	bool _usingSabre = false;
123 
124 	/**
125 	 * Inventory used flags
126 	 * 0 means never used, 1 means already used and automatic re-use
127 	 */
128 	uint8 _inventoryFlags[NUM_INVENTORY_ITEMS];
129 
130 	uint8 _holomapFlags[NUM_LOCATIONS]; // GV14
131 
132 	char _sceneName[30] {};
133 
134 	TextId _gameChoices[10];  // inGameMenuData
135 	int32 _numChoices = 0;   // numOfOptionsInChoice
136 	TextId _choiceAnswer = TextId::kNone; // inGameMenuAnswer
137 
inventoryDisabled()138 	inline bool inventoryDisabled() const {
139 		return hasGameFlag(GAMEFLAG_INVENTORY_DISABLED) != 0;
140 	}
141 
hasOpenedFunfrocksSafe()142 	inline bool hasOpenedFunfrocksSafe() const {
143 		return hasGameFlag(30) != 0;
144 	}
145 
146 	// Arrived on the hamalayi with the rebels
hasArrivedHamalayi()147 	inline bool hasArrivedHamalayi() const {
148 		return hasGameFlag(90) != 0;
149 	}
150 
hasItem(InventoryItems item)151 	inline bool hasItem(InventoryItems item) const {
152 		return hasGameFlag(item) != 0;
153 	}
154 
giveItem(InventoryItems item)155 	inline void giveItem(InventoryItems item) {
156 		setGameFlag(item, 1);
157 	}
158 
removeItem(InventoryItems item)159 	inline void removeItem(InventoryItems item) {
160 		setGameFlag(item, 0);
161 	}
162 
163 	void clearGameFlags();
164 
165 	uint8 hasGameFlag(uint8 index) const;
166 
167 	void setGameFlag(uint8 index, uint8 value);
168 
169 	int16 setKeys(int16 value);
170 	int16 setGas(int16 value);
171 	int16 setLeafs(int16 value);
172 	int16 setKashes(int16 value);
173 	int16 setMagicPoints(int16 val);
174 	int16 setMaxMagicPoints();
175 	int16 setLeafBoxes(int16 val);
176 
177 	void addGas(int16 value);
178 	void addKeys(int16 val);
179 	void addKashes(int16 val);
180 	void addMagicPoints(int16 val);
181 	void addLeafs(int16 val);
182 	void addLeafBoxes(int16 val);
183 
184 	/** Initialize all engine variables */
185 	void initEngineVars();
186 
187 	/** Initialize engine 3D projections */
188 	void initEngineProjections();
189 
190 	void processFoundItem(InventoryItems item);
191 
192 	void giveUp();
193 	bool loadGame(Common::SeekableReadStream *file);
194 	bool saveGame(Common::WriteStream *file);
195 
196 	void processGameChoices(TextId choiceIdx);
197 
198 	void processGameoverAnimation();
199 };
200 
201 } // namespace TwinE
202 
203 #endif
204