Speech bubbles can point down right.
[scummvm-innocent.git] / engines / innocent / actor.h
blobcdfecdf7842f5562aad06f5e74aa3e213e9e5f0b
1 /* ScummVM - Graphic Adventure Engine
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.
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.
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.
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.
21 * $URL$
22 * $Id$
26 #ifndef INNOCENT_ACTOR_H
27 #define INNOCENT_ACTOR_H
29 #include <vector>
31 #include "common/endian.h"
32 #include "common/queue.h"
33 #include "common/rect.h"
35 #include "innocent/animation.h"
36 #include "innocent/value.h"
38 namespace Innocent {
41 class MainDat;
42 class Program;
43 class Sprite;
45 enum Direction {
46 kDirNone = 0,
47 kDirUp,
48 kDirUpRight,
49 kDirRight,
50 kDirDownRight,
51 kDirDown,
52 kDirDownLeft,
53 kDirLeft,
54 kDirUpLeft,
55 kDirCenter = 99
58 Direction operator>>(Direction a, Direction b);
60 class Puppeteer {
61 public:
62 enum Offsets {
63 kActorId = 0,
64 kMainCode = 2,
65 kMoveAnimators = 4,
66 kTurnAnimators = 0x14,
67 kSize = 0x24
69 Puppeteer() : _offset(0), _actorId(0) {}
70 Puppeteer(const byte *data) { parse(data); }
72 uint16 mainCodeOffset() const { return _offset; }
73 uint16 offset() const { return _offset; }
74 uint16 actorId() const { return _actorId; }
75 bool valid() const { return _offset; }
76 CodePointer moveAnimator(Direction d);
77 CodePointer turnAnimator(Direction d);
79 private:
80 void parse(const byte *data);
82 uint16 _actorId;
83 uint16 _offset;
84 uint16 _animators[16];
87 class Actor : public Animation {
89 public:
90 class Frame {
91 public:
92 Frame() : _position(999, 999), _nexts(8), _nextCount(0xff) {}
93 Frame(Common::Point pos, std::vector<byte> n, uint16 i) : _position(pos), _nexts(n), _index(i), _nextCount(0xff) {}
95 Common::Point position() const { return _position; }
96 const std::vector<byte> &nexts() const { return _nexts; }
97 uint16 index() const { return _index; }
99 Direction operator-(const Frame &other) const;
100 bool operator==(const Frame &other) const {
101 return _index == other._index;
103 byte nextCount() const {
104 if (_nextCount == 0xff) {
105 byte ct = 0;
106 for (int i = 0; i < 8; i++)
107 if (_nexts[i])
108 ct++;
109 _nextCount = ct;
112 return _nextCount;
115 private:
116 uint16 _index;
117 Common::Point _position;
118 std::vector<byte> _nexts;
119 mutable byte _nextCount;
122 class Speech {
123 public:
124 Speech() : _actor(0) {}
125 ~Speech();
126 Speech(Actor *parent, const Common::String &text);
127 bool active() const { return !_text.empty(); }
128 void callWhenDone(const CodePointer &cp) { _cb.push(cp); }
129 void paint(Graphics *g);
130 void tick();
132 private:
133 Common::String _text;
134 Common::Queue<CodePointer> _cb;
135 uint16 _ticksLeft;
136 Actor *_actor;
137 Common::Rect _rect;
138 Innocent::Sprite *_image;
141 friend class MainDat;
142 friend class Program;
143 enum {
144 Size = 0x71
147 enum ActorOffsets {
148 kOffsetSegment = 0,
149 kOffsetOffset = 2,
150 kOffsetLeft = 4,
151 kOffsetTop = 6,
152 kOffsetMainSprite = 8,
153 kOffsetTicksLeft = 0xa,
154 kOffsetCode = 0xc,
155 kOffsetInterval = 0x10,
156 kOffsetRoom = 0x59
159 virtual bool isActor() const { return true; }
161 void setFrame(uint16 f);
162 uint16 frameId() const { return _frame; }
163 void moveTo(uint16 f);
164 static Common::List<Frame> findPath(Frame from, uint16 to);
166 uint16 room() const { return _room; }
167 void setRoom(uint16, uint16 frame = 0, uint16 nextFrame = 0);
169 bool isFine() const;
171 void setAnimation(const CodePointer &anim);
172 void setAnimation(uint16);
174 void hide();
175 void callMe(const CodePointer &cp);
176 void tellMe(const CodePointer &cp, uint16 timeout);
178 bool isSpeaking() const;
179 void callMeWhenSilent(const CodePointer &cp);
180 void say(const Common::String &text);
182 bool isMoving() const;
183 void callMeWhenStill(const CodePointer &cp);
185 Animation::Status tick();
186 void paint(Graphics *g);
188 void toggleDebug();
190 void setPuppeteer(const Puppeteer &p) { _puppeteer = p; }
191 private:
192 Actor(const CodePointer &code);
194 // just in case, we'll explicitly add those if needed
195 Actor();
196 Actor(const Actor &);
197 Actor &operator=(const Actor &);
199 void readHeader(const byte *code);
202 * Get position to put the speech bubble in.
203 * It should be saved and stay still for the entire
204 * duration of a sentence (as it may move because
205 * of the actor animating).
206 * @returns position of the tip of the bubble
208 Common::Point getSpeechPosition() const;
210 void animate();
211 bool turnTo(Direction);
212 bool nextFrame();
214 Common::Queue<Frame> _framequeue;
215 uint16 _frame;
216 uint16 _nextFrame;
217 uint16 _room;
218 Direction _direction, _nextDirection;
219 uint16 _nextAnimator; // to change to whenever possible
220 bool _attentionNeeded, _confused;
221 Puppeteer _puppeteer;
223 Common::Queue<CodePointer> _callBacks;
224 void callBacks();
226 struct RoomCallback {
227 uint16 timeout;
228 CodePointer callback;
229 RoomCallback(uint16 t, const CodePointer &p) : timeout(t), callback(p) {}
231 Common::List<RoomCallback> _roomCallbacks;
233 bool _debug;
235 template <int opcode>
236 Animation::Status opcodeHandler();
238 template <int N>
239 void init_opcodes();
241 virtual Animation::Status op(byte code);
243 typedef Animation::Status (Actor::*OpcodeHandler)();
244 OpcodeHandler _handlers[38];
246 Speech _speech;
251 #endif