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  byte color;
73  byte slot;
74  union {
75  uint16 animation;
76  uint16 callback;
77  };
78  uint16 timer;
79  byte orientation;
80  Common::Point dst;
81  byte scene; //fixme: put some of these to the union?
82  byte ons;
83  byte lan;
84  union {
85  byte music;
86  byte firstFrame;
87  };
88  union {
89  byte sound;
90  byte lastFrame;
91  };
92  byte object;
93 
94  SceneEvent(Type type_) :
95  type(type_), message(), color(textColorMark), slot(0), animation(0), timer(0), orientation(0), dst(),
96  scene(0), ons(0), lan(0), music(0), sound(0), object(0) {}
97 
98  void clear() {
99  type = kNone;
100  message.clear();
101  color = textColorMark;
102  slot = 0;
103  orientation = 0;
104  animation = 0;
105  timer = 0;
106  dst.x = dst.y = 0;
107  scene = 0;
108  ons = 0;
109  lan = 0;
110  music = 0;
111  sound = 0;
112  object = 0;
113  }
114 
115  inline bool empty() const {
116  return type == kNone;
117  }
118 
119  void dump() const {
120  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",
121  (int)type, message.c_str(), color, slot, animation, timer, dst.x, dst.y, orientation, scene, ons, lan, object, music, sound
122  );
123  }
124 };
125 
126 class Scene {
127 public:
128  Scene(TeenAgentEngine *engine);
129  ~Scene();
130 
131  bool intro;
132 
133  void init(int id, const Common::Point &pos);
134  bool render(bool tickGame, bool tickMark, uint32 messageDelta);
135  int getId() const { return _id; }
136 
137  void warp(const Common::Point &point, byte orientation = 0);
138 
139  void moveTo(const Common::Point &point, byte orientation = 0, bool validate = false);
140  Common::Point getPosition() const { return position; }
141 
142  void displayMessage(const Common::String &str, byte color = textColorMark, const Common::Point &pos = Common::Point());
143  void setOrientation(uint8 o) { orientation = o; }
144  void push(const SceneEvent &event);
145  byte peekFlagEvent(uint16 addr) const;
146  SceneEvent::Type last_event_type() const { return !events.empty() ? events.back().type : SceneEvent::kNone; }
147 
148  bool processEvent(const Common::Event &event);
149 
150  void clear();
151 
152  byte *getOns(int id);
153  byte *getLans(int id);
154 
155  bool eventRunning() const { return !currentEvent.empty(); }
156 
157  Walkbox *getWalkbox(byte id) { return &walkboxes[_id - 1][id]; }
158  Object *getObject(int id, int sceneId = 0);
159  Object *findObject(const Common::Point &point);
160 
161  void loadObjectData();
162  Animation *getAnimation(byte slot);
163  inline Animation *getActorAnimation() { return &actorAnimation; }
164  inline const Common::String &getMessage() const { return message; }
165  void setPalette(unsigned mul);
166  int lookupZoom(uint y) const;
167 
168 private:
169  void loadOns();
170  void loadLans();
171 
172  void playAnimation(byte idx, uint id, bool loop, bool paused, bool ignore);
173  void playActorAnimation(uint id, bool loop, bool ignore);
174 
175  byte palette[3 * 256];
176  void paletteEffect(byte step);
177  byte findFade() const;
178 
179  Common::Point messagePosition(const Common::String &str, Common::Point pos);
180  uint messageDuration(const Common::String &str);
181 
182  bool processEventQueue();
183  inline bool nextEvent() {
184  currentEvent.clear();
185  return processEventQueue();
186  }
187  void clearMessage();
188 
189  TeenAgentEngine *_vm;
190 
191  int _id;
192  Graphics::Surface background;
193  SurfaceList on;
194  bool onEnabled;
195  Surface *ons;
196  uint32 _onsCount;
197  Animation actorAnimation, animation[4], customAnimation[4];
198  Common::Rect actorAnimationPosition, animationPosition[4];
199 
200  Actor teenagent, teenagentIdle;
201  Common::Point position;
202 
204  Path path;
205  uint8 orientation;
206  bool actorTalking;
207 
208  bool findPath(Path &p, const Common::Point &src, const Common::Point &dst) const;
209 
213 
214  Common::String message;
215  Common::Point messagePos;
216  byte _messageColor;
217  uint messageTimer;
218  byte messageFirstFrame;
219  byte messageLastFrame;
220  Animation *messageAnimation;
221 
223  EventList events;
224  SceneEvent currentEvent;
225  bool hideActor;
226 
227  uint16 callback, callbackTimer;
228 
229  int _fadeTimer;
230  byte _fadeOld;
231 
232  uint _idleTimer;
233 
234  struct Sound {
235  byte id, delay;
236  Sound(byte i, byte d): id(i), delay(d) {}
237  };
238  typedef Common::List<Sound> Sounds;
239  Sounds sounds;
240 
241  struct DebugFeatures {
242  enum {
243  kShowBack,
244  kShowLan,
245  kShowOns,
246  kShowOn,
247  kHidePath,
248  kMax
249  };
250  bool feature[kMax];
251 
252  DebugFeatures() {
253  for (uint i = 0; i < kMax; ++i) {
254  feature[i] = true;
255  }
256  }
257  } debugFeatures;
258 };
259 
260 } // End of namespace TeenAgent
261 
262 #endif
Definition: str.h:59
Definition: surface.h:66
Definition: array.h:52
Definition: objects.h:202
Definition: teenagent.h:83
Definition: surface_list.h:31
Definition: rect.h:144
Definition: objects.h:158
Definition: actor.h:33
Definition: animation.h:30
Definition: scene.h:126
Definition: events.h:198
Definition: algorithm.h:29
Definition: rect.h:45
Definition: actor.h:29
int16 x
Definition: rect.h:46
Definition: surface.h:34
int16 y
Definition: rect.h:47
Definition: scene.h:43
void void void void void debugC(int level, uint32 debugChannels, MSVC_PRINTF const char *s,...) GCC_PRINTF(3