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