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 ILLUSIONS_ILLUSIONS_H
24 #define ILLUSIONS_ILLUSIONS_H
25 
26 #include "illusions/graphics.h"
27 #include "audio/mixer.h"
28 #include "audio/decoders/aiff.h"
29 #include "common/array.h"
30 #include "common/events.h"
31 #include "common/file.h"
32 #include "common/memstream.h"
33 #include "common/random.h"
34 #include "common/str.h"
35 #include "common/substream.h"
36 #include "common/system.h"
37 #include "common/winexe.h"
38 #include "common/winexe_pe.h"
39 #include "engines/engine.h"
40 #include "graphics/surface.h"
41 
42 namespace Illusions {
43 
44 char *debugW2I(byte *wstr);
45 
46 #define ILLUSIONS_SAVEGAME_VERSION 0
47 
48 class ResourceSystem;
49 class BaseResourceReader;
50 
51 struct SurfInfo;
52 
53 class ActorInstanceList;
54 struct ActorType;
55 class BackgroundInstanceList;
56 class BackgroundResource;
57 class Camera;
58 class Control;
59 class Controls;
60 class Cursor;
61 class Dictionary;
62 struct Fader;
63 class FramesList;
64 struct IllusionsGameDescription;
65 class Input;
66 class Screen;
67 class ScreenText;
68 class ScriptOpcodes;
69 class ScriptResource;
70 class ScriptStack;
71 struct Sequence;
72 class SoundMan;
73 class SpecialCode;
74 class TalkInstanceList;
75 class ThreadList;
76 class UpdateFunctions;
77 class GameState;
78 class ScreenPaletteBase;
79 
80 enum {
81 	kGameIdBBDOU   = 1,
82 	kGameIdDuckman = 2
83 };
84 
85 class IllusionsEngine : public Engine {
86 public:
87 	IllusionsEngine(OSystem *syst, const IllusionsGameDescription *gd);
88 	~IllusionsEngine();
getTargetName()89 	const Common::String getTargetName() { return _targetName; }
90 private:
91 	const IllusionsGameDescription *_gameDescription;
92 	Graphics::PixelFormat _pixelFormat;
93 public:
94 
95 	Common::RandomSource *_random;
96 	Dictionary *_dict;
97 	ResourceSystem *_resSys;
98 	BaseResourceReader *_resReader;
99 	UpdateFunctions *_updateFunctions;
100 	GameState *_gameState;
101 
102 	void updateEvents();
103 
104 	Screen *_screen;
105 	ScreenPaletteBase *_screenPalette;
106 	ScreenText *_screenText;
107 	Input *_input;
108 	ActorInstanceList *_actorInstances;
109 	BackgroundInstanceList *_backgroundInstances;
110 	Camera *_camera;
111 	Controls *_controls;
112 	TalkInstanceList *_talkItems;
113 	ScriptOpcodes *_scriptOpcodes;
114 	SpecialCode *_specialCode;
115 	ThreadList *_threads;
116 	SoundMan *_soundMan;
117 
118 	uint32 _nextTempThreadId;
119 	bool _doScriptThreadInit;
120 	ScriptStack *_stack;
121 	ScriptResource *_scriptResource;
122 	bool _rerunThreads;
123 
124 	Fader *_fader;
125 
126 	int _pauseCtr;
127 
128 	int _resGetCtr;
129 	uint32 _resGetTime;
130 	bool _unpauseControlActorFlag;
131 	uint32 _lastUpdateTime;
132 
133 	int _resumeFromSavegameRequested;
134 	int _savegameSlotNum;
135 	Common::String _savegameDescription;
136 	uint32 _savegameSceneId;
137 	uint32 _savegameThreadId;
138 
139 	uint32 _fontId;
140 	int _field8;
141 	uint32 _fieldA;
142 	uint32 _subtitleDuration;
143 
144 	WidthHeight _defaultTextDimensions;
145 	Common::Point _defaultTextPosition;
146 
147 	int16 _menuChoiceOfs;
148 
149 	int getGameId() const;
150 
151 	void runUpdateFunctions();
152 	int updateActors(uint flags);
153 	int updateSequences(uint flags);
154 	int updateGraphics(uint flags);
155 	int updateSoundMan(uint flags);
156 	int updateSprites(uint flags);
157 
158 	uint32 getElapsedUpdateTime();
159 	Common::Point *getObjectActorPositionPtr(uint32 objectId);
160 	int getRandom(int max);
161 	int convertPanXCoord(int16 x);
162 	bool calcPointDirection(Common::Point &srcPt, Common::Point &dstPt, uint &facing);
163 	bool isSoundActive();
164 
updateFader()165 	virtual void updateFader() {};
clearFader()166 	virtual void clearFader() {};
pauseFader()167 	virtual void pauseFader() {};
unpauseFader()168 	virtual void unpauseFader() {};
isVideoPlaying()169 	virtual bool isVideoPlaying() { return false; }
170 
171 	void setCurrFontId(uint32 fontId);
172 	bool checkActiveTalkThreads();
173 	void setTextDuration(int kind, uint32 duration);
174 	uint32 clipTextDuration(uint32 duration);
175 	void getDefaultTextDimensions(WidthHeight &dimensions);
176 	void setDefaultTextDimensions(WidthHeight &dimensions);
177 	void getDefaultTextPosition(Common::Point &position);
178 	void setDefaultTextPosition(Common::Point &position);
179 
180 	uint16 getSubtitleDuration();
181 	void setSubtitleDuration(uint16 duration);
182 
183 	FramesList *findActorSequenceFrames(Sequence *sequence);
184 
185 	virtual void setDefaultTextCoords() = 0;
186 	virtual void loadSpecialCode(uint32 resId) = 0;
187 	virtual void unloadSpecialCode(uint32 resId) = 0;
188 	virtual void notifyThreadId(uint32 &threadId) = 0;
189 	virtual bool testMainActorFastWalk(Control *control) = 0;
190 	virtual bool testMainActorCollision(Control *control) = 0;
191 	virtual Control *getObjectControl(uint32 objectId) = 0;
192 	virtual Common::Point getNamedPointPosition(uint32 namedPointId) = 0;
193 	virtual uint32 getPriorityFromBase(int16 priority) = 0;
194 	virtual uint32 getPrevScene() = 0;
195 	virtual uint32 getCurrentScene() = 0;
196 	virtual bool isCursorObject(uint32 actorTypeId, uint32 objectId) = 0;
197 	virtual void setCursorControlRoutine(Control *control) = 0;
198 	virtual void placeCursorControl(Control *control, uint32 sequenceId) = 0;
199 	virtual void setCursorControl(Control *control) = 0;
200 	virtual void showCursor() = 0;
201 	virtual void hideCursor() = 0;
202 	virtual void startScriptThreadSimple(uint32 threadId, uint32 callingThreadId) = 0;
203 	virtual uint32 startTempScriptThread(byte *scriptCodeIp, uint32 callingThreadId,
204 		uint32 value8, uint32 valueC, uint32 value10) = 0;
205 
206 	// Savegame API
207 
208 	enum kReadSaveHeaderError {
209 		kRSHENoError = 0,
210 		kRSHEInvalidType = 1,
211 		kRSHEInvalidVersion = 2,
212 		kRSHEIoError = 3
213 	};
214 
215 	struct SaveHeader {
216 		Common::String description;
217 		uint32 version;
218 		byte gameID;
219 		uint32 flags;
220 		uint32 saveDate;
221 		uint32 saveTime;
222 		uint32 playTime;
223 		Graphics::Surface *thumbnail;
224 	};
225 
226 	bool _isSaveAllowed;
227 
canLoadGameStateCurrently()228 	bool canLoadGameStateCurrently() { return _isSaveAllowed; }
canSaveGameStateCurrently()229 	bool canSaveGameStateCurrently() { return _isSaveAllowed; }
230 	Common::Error loadGameState(int slot);
231 	Common::Error saveGameState(int slot, const Common::String &description);
232 	Common::Error removeGameState(int slot);
233 	bool savegame(const char *filename, const char *description);
234 	bool loadgame(const char *filename);
235 	const char *getSavegameFilename(int num);
236 	bool existsSavegame(int num);
237 	static Common::String getSavegameFilename(const Common::String &target, int num);
238 	static kReadSaveHeaderError readSaveHeader(Common::SeekableReadStream *in, SaveHeader &header, bool skipThumbnail = true);
239 
240 };
241 
242 } // End of namespace Illusions
243 
244 #endif // ILLUSIONS_ILLUSIONS_H
245