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 TEENAGENT_TEENAGENT_H
24 #define TEENAGENT_TEENAGENT_H
25 
26 #include "engines/engine.h"
27 
28 #include "audio/mixer.h"
29 
30 #include "common/random.h"
31 #include "common/array.h"
32 
33 #include "gui/debugger.h"
34 
35 #include "teenagent/console.h"
36 #include "teenagent/dialog.h"
37 
38 struct ADGameDescription;
39 
40 namespace Audio {
41 class AudioStream;
42 }
43 
44 namespace Common {
45 struct Point;
46 }
47 
48 /**
49  * This is the namespace of the TeenAgent engine.
50  *
51  * Status of this engine: Complete
52  *
53  * Games using this engine:
54  * - Teen Agent
55  */
56 namespace TeenAgent {
57 
58 struct Object;
59 struct UseHotspot;
60 class Scene;
61 class MusicPlayer;
62 class Resources;
63 class Inventory;
64 class Pack;
65 
66 // Engine Debug Flags
67 enum {
68 	kDebugActor     = (1 << 0),
69 	kDebugAnimation = (1 << 1),
70 	kDebugCallbacks = (1 << 2),
71 	kDebugDialog    = (1 << 3),
72 	kDebugFont      = (1 << 4),
73 	kDebugInventory = (1 << 5),
74 	kDebugMusic     = (1 << 6),
75 	kDebugObject    = (1 << 7),
76 	kDebugPack      = (1 << 8),
77 	kDebugScene     = (1 << 9),
78 	kDebugSurface   = (1 << 10)
79 };
80 
81 const uint16 kScreenWidth = 320;
82 const uint16 kScreenHeight = 200;
83 
84 class TeenAgentEngine : public Engine {
85 public:
86 	TeenAgentEngine(OSystem *system, const ADGameDescription *gd);
87 	~TeenAgentEngine();
88 
89 	virtual Common::Error run();
90 	virtual Common::Error loadGameState(int slot);
91 	virtual Common::Error saveGameState(int slot, const Common::String &desc);
canLoadGameStateCurrently()92 	virtual bool canLoadGameStateCurrently() { return true; }
canSaveGameStateCurrently()93 	virtual bool canSaveGameStateCurrently() { return !_sceneBusy; }
94 	virtual bool hasFeature(EngineFeature f) const;
95 
getDebugger()96 	GUI::Debugger *getDebugger() { return console; }
97 
98 	void init();
99 
100 	enum Action { kActionNone, kActionExamine, kActionUse };
101 
102 	void examine(const Common::Point &point, Object *object);
103 	void use(Object *object);
cancel()104 	inline void cancel() { _action = kActionNone; }
105 
106 	bool processCallback(uint16 addr);
getScene()107 	inline Scene *getScene() { return scene; }
108 
109 	bool showLogo();
110 	bool showCDLogo();
111 	bool showMetropolis();
112 	int skipEvents() const;
113 
114 	Common::String parseMessage(uint16 addr);
115 
116 	//event driven:
117 	void displayMessage(uint16 addr, byte color = textColorMark, uint16 x = 0, uint16 y = 0);
118 	void displayMessage(const Common::String &str, byte color = textColorMark, uint16 x = 0, uint16 y = 0);
119 	void displayAsyncMessage(uint16 addr, uint16 x, uint16 y, uint16 firstFrame, uint16 lastFrame, byte color = textColorMark);
120 	void displayAsyncMessageInSlot(uint16 addr, byte slot, uint16 firstFrame, uint16 lastFrame, byte color = textColorMark);
121 	void displayCredits(uint16 addr, uint16 timer = 0);
122 	void displayCutsceneMessage(uint16 addr, uint16 x, uint16 y);
123 	void moveTo(const Common::Point &dst, byte o, bool warp = false);
124 	void moveTo(uint16 x, uint16 y, byte o, bool warp = false);
125 	void moveTo(Object *obj);
126 	void moveRel(int16 x, int16 y, byte o, bool warp = false);
127 	void playActorAnimation(uint16 id, bool async = false, bool ignore = false);
128 	void playAnimation(uint16 id, byte slot, bool async = false, bool ignore = false, bool loop = false);
129 	void loadScene(byte id, const Common::Point &pos, byte o = 0);
130 	void loadScene(byte id, uint16 x, uint16 y, byte o = 0);
131 	void enableOn(bool enable = true);
132 	void setOns(byte id, byte value, byte sceneId = 0);
133 	void setLan(byte id, byte value, byte sceneId = 0);
134 	void setFlag(uint16 addr, byte value);
135 	byte getFlag(uint16 addr);
136 	void reloadLan();
137 	void rejectMessage();
138 
139 	void playMusic(byte id); //schedules play
140 	void playSound(byte id, byte skipFrames);
141 	void playSoundNow(Pack *pack, byte id);
142 	void enableObject(byte id, byte sceneId = 0);
143 	void disableObject(byte id, byte sceneId = 0);
144 	void hideActor();
145 	void showActor();
146 	void waitAnimation();
147 	void waitLanAnimationFrame(byte slot, uint16 frame);
148 	void setTimerCallback(uint16 addr, uint16 frames);
149 	void shakeScreen();
150 	void displayCredits();
151 	void fadeIn();
152 	void fadeOut();
153 	void wait(uint16 frames);
154 
155 	Common::RandomSource _rnd;
156 
157 	Resources *res;
158 	Scene *scene;
159 	Inventory *inventory;
160 	MusicPlayer *music;
161 	Dialog *dialog;
162 	Console *console;
163 
164 	void setMusic(byte id);
165 
166 private:
167 	void processObject();
168 	bool trySelectedObject();
169 
170 	bool _sceneBusy;
171 	Action _action;
172 	Object *_dstObject;
173 
174 	Audio::AudioStream *_musicStream;
175 	Audio::SoundHandle _musicHandle, _soundHandle;
176 	const ADGameDescription *_gameDescription;
177 
178 	uint _markDelay, _gameDelay;
179 
180 	Common::Array<Common::Array<UseHotspot> > _useHotspots;
181 
182 	void fnIntro();
183 	void fnPoleClimbFail();
184 	void fnGotAnchor();
185 	void fnGetOutOfLake();
186 	void fnGuardDrinking();
187 	void fnEgoDefaultPosition();
188 	void fnEnterCave();
189 	void fnEgoScaredBySpider();
190 	void fnMoveToLadderAndLeaveCellar();
191 	void fnLeaveCellar();
192 	void fnPutRockInHole();
193 	void fnEgoBottomRightTurn();
194 	bool fnCheckingDrawers();
195 	void fnDrawerOpenMessage();
196 	bool fnRobotSafeAlreadyUnlockedCheck();
197 	void fnRobotSafeUnlockCheck();
198 	bool fnMansionIntrusionAttempt();
199 	void fnSecondMansionIntrusion();
200 	void fnThirdMansionIntrusion();
201 	void fnFourthMansionIntrusion();
202 	void fnFifthMansionIntrusion();
203 	void fnSixthMansionIntrusion();
204 	void fnTooDark();
205 	bool fnIsCookGone();
206 	void fnEgoSuspiciousPosition();
207 	void fnGivingFlowerToOldLady();
208 	void fnGiveAnotherFlowerToOldLady();
209 	void fnGivingFlowerToAnne();
210 	void fnGiveAnotherFlowerToAnne();
211 };
212 
213 } // End of namespace TeenAgent
214 
215 #endif
216