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 CINE_CINE_H
24 #define CINE_CINE_H
25 
26 
27 #include "common/scummsys.h"
28 #include "common/file.h"
29 #include "common/util.h"
30 #include "common/str.h"
31 #include "common/hashmap.h"
32 #include "common/hash-str.h"
33 #include "common/random.h"
34 
35 #include "engines/engine.h"
36 
37 #include "cine/texte.h"
38 #include "cine/rel.h"
39 #include "cine/script.h"
40 #include "cine/part.h"
41 #include "cine/prc.h"
42 #include "cine/msg.h"
43 #include "cine/bg.h"
44 #include "cine/pal.h"
45 #include "cine/gfx.h"
46 #include "cine/anim.h"
47 #include "cine/bg_list.h"
48 #include "cine/various.h"
49 #include "cine/console.h"
50 #include "cine/sound.h"
51 #include "cine/detection.h"
52 
53 //#define DUMP_SCRIPTS
54 
55 /**
56  * This is the namespace of the Cine engine.
57  *
58  * Status of this engine:
59  *
60  * This enigne has 2 generations Cinematique evo.1 and Cinematique evo.2
61  * first generation is fairly complete, and second one is under development
62  *
63  * Cinematique evo.1 status:
64  * The engine supports Future Wars and is basically complete with support of
65  * all known game variants. Based on Yaz0r's engine.
66  *
67  * Cinematique evo.2 status:
68  * This generation supports Operation Stealth, originally developed by Yaz0r for
69  * French variant of the game which heared to be completable.
70  * Later the work was renewed as part of GSoC'08, by Kari Salminen, but it has not
71  * yet been finished. The game is not completable.
72  *
73  *
74  * Games using this engine:
75  *
76  * Cinematique evo.1
77  * - Future Wars
78  *
79  * Cinematique evo.2
80  * - Operation Stealth
81  *
82  */
83 namespace Cine {
84 
85 struct SeqListElement;
86 
87 struct VolumeResource {
88 	char name[10];
89 	uint32 pNamesList;
90 	int16 diskNum;
91 	int32 sizeOfNamesList;
92 };
93 
94 typedef Common::HashMap<Common::String, Common::Array<VolumeResource> > StringToVolumeResourceArrayHashMap;
95 
96 class CineConsole;
97 
98 class CineEngine : public Engine {
99 
100 protected:
101 	// Engine APIs
102 	Common::Error run() override;
103 	bool hasFeature(EngineFeature f) const override;
104 
105 	void shutdown();
106 
107 	bool initGame();
108 
109 public:
110 	CineEngine(OSystem *syst, const CINEGameDescription *gameDesc);
111 	~CineEngine() override;
112 
113 	void syncSoundSettings() override;
114 
115 	bool mayHave256Colors() const;
116 	int getGameType() const;
117 	uint32 getFeatures() const;
118 	Common::Language getLanguage() const;
119 	Common::Platform getPlatform() const;
120 
121 	bool loadSaveDirectory();
122 	void makeSystemMenu();
123 	int scummVMSaveLoadDialog(bool isSave);
124 	int modifyGameSpeed(int speedChange);
125 	void setDefaultGameSpeed();
126 	uint32 getTimerDelay() const;
127 	Common::Error loadGameState(int slot) override;
128 	Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave = false) override;
129 	virtual Common::String getSaveStateName(int slot) const override;
130 	bool canLoadGameStateCurrently() override;
131 	bool canSaveGameStateCurrently() override;
132 
133 	const CINEGameDescription *_gameDescription;
134 	Common::File _partFileHandle;
135 
136 	Common::RandomSource _rnd;
137 
138 	StringToVolumeResourceArrayHashMap _volumeEntriesMap;
139 
140 	TextHandler _textHandler;
141 
142 	bool _restartRequested;
143 
144 private:
145 	void initialize();
146 	void showSplashScreen();
147 	void resetEngine();
148 	bool checkSaveHeaderData(const ChunkHeader& hdr);
149 	bool loadPlainSaveFW(Common::SeekableReadStream &in, CineSaveGameFormat saveGameFormat, uint32 version);
150 	bool loadVersionedSaveFW(Common::SeekableReadStream &in);
151 	bool loadVersionedSaveOS(Common::SeekableReadStream &in);
152 	bool makeLoad(const Common::String &saveName);
153 	void writeSaveHeader(Common::OutSaveFile &out, uint32 headerId);
154 	void makeSaveFW(Common::OutSaveFile &out);
155 	void makeSaveOS(Common::OutSaveFile &out);
156 	void makeSave(const Common::String &saveFileName, uint32 playtime,
157 		Common::String desc, bool isAutosave);
158 	void mainLoop(int bootScriptIdx);
159 	void readVolCnf();
160 	Common::String getTargetSaveStateName(Common::String target, int slot) const;
161 
162 	bool _preLoad;
163 	int _timerDelayMultiplier;
164 
165 public:
166 	// TODO: These are pseudo-global vars
167 	// They better belong to appropriate classes
168 	Common::Array<AnimData> _animDataTable;
169 	Common::List<BGIncrust> _bgIncrustList;
170 	Common::StringArray _messageTable;
171 	Common::Array<ObjectStruct> _objectTable;
172 	Common::List<overlay> _overlayList;
173 	Common::Array<PalEntry> _palArray;
174 	Common::Array<PartBuffer> _partBuffer;
175 	ScriptList _globalScripts;
176 	ScriptList _objectScripts;
177 	RawObjectScriptArray _relTable; ///< Object script bytecode table
178 
179 	/**
180 	 * Global variables.
181 	 * 255 of these are saved, but there's one more that's used for bypassing the copy protection.
182 	 * In CineEngine::mainLoop(int bootScriptIdx) there's this code: globalVars[VAR_BYPASS_PROTECTION] = 0;
183 	 * And as VAR_BYPASS_PROTECTION is 255 that's why we're allocating one more than we otherwise would.
184 	 */
185 	ScriptVars _globalVars;
186 	RawScriptArray _scriptTable; ///< Table of script bytecode
187 
188 	Common::Array<int16> _zoneData;
189 	Common::Array<uint16> _zoneQuery; ///< Only exists in Operation Stealth
190 
191 	Common::List<SeqListElement> _seqList;
192 
193 	Common::String _commandBuffer;
194 	Common::Array<Common::KeyState> _keyInputList;
195 };
196 
197 extern CineEngine *g_cine;
198 extern Sound *g_sound;
199 
200 #define BOOT_PRC_NAME "AUTO00.PRC"
201 #define BOOT_SCRIPT_INDEX 1
202 #define COPY_PROT_FAIL_PRC_NAME "L201.ANI"
203 
204 enum {
205 	// Both FW and OS
206 	VAR_MOUSE_X_POS = 249,
207 	VAR_MOUSE_Y_POS = 250,
208 	// FW only
209 	VAR_MOUSE_X_MODE = 253,
210 	VAR_MOUSE_Y_MODE = 251,
211 	// OS only
212 	VAR_MOUSE_X_POS_2ND = 251, // Many times used in conjunction with VAR_MOUSE_X_POS
213 	VAR_MOUSE_Y_POS_2ND = 252, // Many times used in conjunction with VAR_MOUSE_Y_POS
214 	VAR_BYPASS_PROTECTION = 255,
215 	VAR_LOW_MEMORY = 0
216 };
217 
218 enum {
219 	MOUSE_CURSOR_NORMAL = 0,
220 	MOUSE_CURSOR_DISK,
221 	MOUSE_CURSOR_CROSS
222 };
223 
224 enum {
225 	kCineDebugScript    = 1 << 0,
226 	kCineDebugPart      = 1 << 1,
227 	kCineDebugSound     = 1 << 2,
228 	kCineDebugCollision = 1 << 3
229 };
230 
231 enum {
232 	kCmpEQ = (1 << 0),
233 	kCmpGT = (1 << 1),
234 	kCmpLT = (1 << 2)
235 };
236 
237 
238 } // End of namespace Cine
239 
240 #endif
241