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_SCENE_H
24 #define TEENAGENT_SCENE_H
25 
26 #include "teenagent/surface.h"
27 #include "teenagent/actor.h"
28 #include "teenagent/objects.h"
29 #include "teenagent/surface.h"
30 #include "teenagent/surface_list.h"
31 #include "teenagent/teenagent.h"
32 
33 #include "common/array.h"
34 #include "common/list.h"
35 
36 namespace Common {
37 struct Event;
38 }
39 
40 namespace TeenAgent {
41 
42 class TeenAgentEngine;
43 
44 struct SceneEvent {
45 	enum Type {
46 	    kNone,                  //0
47 	    kMessage,
48 	    kWalk,
49 	    kPlayAnimation,
50 	    kPlayActorAnimation,    //4
51 	    kPauseAnimation,
52 	    kClearAnimations,
53 	    kLoadScene,
54 	    kSetOn,                 //8
55 	    kSetLan,
56 	    kPlayMusic,
57 	    kPlaySound,
58 	    kEnableObject,          //12
59 	    kHideActor,
60 	    kWaitForAnimation,
61 	    kWaitLanAnimationFrame,
62 	    kCreditsMessage,        //16
63 	    kCredits,
64 	    kTimer,
65 	    kEffect,
66 	    kFade,
67 	    kWait,
68 	    kSetFlag,
69 	    kQuit
70 	} type;
71 
72 	Common::String message;
73 	byte color;
74 	byte slot;
75 	union {
76 		uint16 animation;
77 		uint16 callback;
78 	};
79 	uint16 timer;
80 	byte orientation;
81 	Common::Point dst;
82 	byte scene; //fixme: put some of these to the union?
83 	byte ons;
84 	byte lan;
85 	union {
86 		byte music;
87 		byte firstFrame;
88 	};
89 	union {
90 		byte sound;
91 		byte lastFrame;
92 	};
93 	byte object;
94 
SceneEventSceneEvent95 	SceneEvent(Type type_) :
96 		type(type_), message(), color(textColorMark), slot(0), animation(0), timer(0), orientation(0), dst(),
97 		scene(0), ons(0), lan(0), music(0), sound(0), object(0) {}
98 
clearSceneEvent99 	void clear() {
100 		type = kNone;
101 		message.clear();
102 		color = textColorMark;
103 		slot = 0;
104 		orientation = 0;
105 		animation = 0;
106 		timer = 0;
107 		dst.x = dst.y = 0;
108 		scene = 0;
109 		ons = 0;
110 		lan = 0;
111 		music = 0;
112 		sound = 0;
113 		object = 0;
114 	}
115 
emptySceneEvent116 	inline bool empty() const {
117 		return type == kNone;
118 	}
119 
dumpSceneEvent120 	void dump() const {
121 		debugC(0, kDebugScene, "event[%d]: \"%s\"[%02x], slot: %d, animation: %u, timer: %u, dst: (%d, %d) [%u], scene: %u, ons: %u, lan: %u, object: %u, music: %u, sound: %u",
122 		      (int)type, message.c_str(), color, slot, animation, timer, dst.x, dst.y, orientation, scene, ons, lan, object, music, sound
123 		     );
124 	}
125 };
126 
127 class Scene {
128 public:
129 	Scene(TeenAgentEngine *engine);
130 	~Scene();
131 
132 	bool intro;
133 
134 	void init(int id, const Common::Point &pos);
135 	bool render(bool tickGame, bool tickMark, uint32 messageDelta);
getId()136 	int getId() const { return _id; }
137 
138 	void warp(const Common::Point &point, byte orientation = 0);
139 
140 	void moveTo(const Common::Point &point, byte orientation = 0, bool validate = false);
getPosition()141 	Common::Point getPosition() const { return position; }
142 
143 	void displayMessage(const Common::String &str, byte color = textColorMark, const Common::Point &pos = Common::Point());
setOrientation(uint8 o)144 	void setOrientation(uint8 o) { orientation = o; }
145 	void push(const SceneEvent &event);
146 	byte peekFlagEvent(uint16 addr) const;
last_event_type()147 	SceneEvent::Type last_event_type() const { return !events.empty() ? events.back().type : SceneEvent::kNone; }
148 
149 	bool processEvent(const Common::Event &event);
150 
151 	void clear();
152 
153 	byte *getOns(int id);
154 	byte *getLans(int id);
155 
eventRunning()156 	bool eventRunning() const { return !currentEvent.empty(); }
157 
getWalkbox(byte id)158 	Walkbox *getWalkbox(byte id) { return &walkboxes[_id - 1][id]; }
159 	Object *getObject(int id, int sceneId = 0);
160 	Object *findObject(const Common::Point &point);
161 
162 	void loadObjectData();
163 	Animation *getAnimation(byte slot);
getActorAnimation()164 	inline Animation *getActorAnimation() { return &actorAnimation; }
getMessage()165 	inline const Common::String &getMessage() const { return message; }
166 	void setPalette(unsigned mul);
167 	int lookupZoom(uint y) const;
168 
169 private:
170 	void loadOns();
171 	void loadLans();
172 
173 	void playAnimation(byte idx, uint id, bool loop, bool paused, bool ignore);
174 	void playActorAnimation(uint id, bool loop, bool ignore);
175 
176 	byte palette[3 * 256];
177 	void paletteEffect(byte step);
178 	byte findFade() const;
179 
180 	Common::Point messagePosition(const Common::String &str, Common::Point pos);
181 	uint messageDuration(const Common::String &str);
182 
183 	bool processEventQueue();
nextEvent()184 	inline bool nextEvent() {
185 		currentEvent.clear();
186 		return processEventQueue();
187 	}
188 	void clearMessage();
189 
190 	TeenAgentEngine *_vm;
191 
192 	int _id;
193 	Graphics::Surface background;
194 	SurfaceList on;
195 	bool onEnabled;
196 	Surface *ons;
197 	uint32 _onsCount;
198 	Animation actorAnimation, animation[4], customAnimation[4];
199 	Common::Rect actorAnimationPosition, animationPosition[4];
200 
201 	Actor teenagent, teenagentIdle;
202 	Common::Point position;
203 
204 	typedef Common::List<Common::Point> Path;
205 	Path path;
206 	uint8 orientation;
207 	bool actorTalking;
208 
209 	bool findPath(Path &p, const Common::Point &src, const Common::Point &dst) const;
210 
211 	Common::Array<Common::Array<Object> > objects;
212 	Common::Array<Common::Array<Walkbox> > walkboxes;
213 	Common::Array<Common::Array<FadeType> > fades;
214 
215 	Common::String message;
216 	Common::Point messagePos;
217 	byte _messageColor;
218 	uint messageTimer;
219 	byte messageFirstFrame;
220 	byte messageLastFrame;
221 	Animation *messageAnimation;
222 
223 	typedef Common::List<SceneEvent> EventList;
224 	EventList events;
225 	SceneEvent currentEvent;
226 	bool hideActor;
227 
228 	uint16 callback, callbackTimer;
229 
230 	int _fadeTimer;
231 	byte _fadeOld;
232 
233 	uint _idleTimer;
234 
235 	struct Sound {
236 		byte id, delay;
SoundSound237 		Sound(byte i, byte d): id(i), delay(d) {}
238 	};
239 	typedef Common::List<Sound> Sounds;
240 	Sounds sounds;
241 
242 	struct DebugFeatures {
243 		enum {
244 		    kShowBack,
245 		    kShowLan,
246 		    kShowOns,
247 		    kShowOn,
248 		    kHidePath,
249 		    kMax
250 		};
251 		bool feature[kMax];
252 
DebugFeaturesDebugFeatures253 		DebugFeatures() {
254 			for (uint i = 0; i < kMax; ++i) {
255 				feature[i] = true;
256 			}
257 		}
258 	} debugFeatures;
259 };
260 
261 } // End of namespace TeenAgent
262 
263 #endif
264