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