Adapting to the new API.
[scummvm-innocent.git] / engines / innocent / actor.h
blob0e59bd2dea0610bbf6c9ddada8b38e823d0a390d
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;
44 enum Direction {
45 kDirNone = 0,
46 kDirUp,
47 kDirUpRight,
48 kDirRight,
49 kDirDownRight,
50 kDirDown,
51 kDirDownLeft,
52 kDirLeft,
53 kDirUpLeft,
54 kDirCenter = 99
57 Direction operator>>(Direction a, Direction b);
59 class Puppeteer {
60 public:
61 enum Offsets {
62 kActorId = 0,
63 kMainCode = 2,
64 kMoveAnimators = 4,
65 kTurnAnimators = 0x14,
66 kSize = 0x24
68 Puppeteer() : _offset(0), _actorId(0) {}
69 Puppeteer(const byte *data) { parse(data); }
71 uint16 mainCodeOffset() const { return _offset; }
72 uint16 offset() const { return _offset; }
73 uint16 actorId() const { return _actorId; }
74 bool valid() const { return _offset; }
75 CodePointer moveAnimator(Direction d);
76 CodePointer turnAnimator(Direction d);
78 private:
79 void parse(const byte *data);
81 uint16 _actorId;
82 uint16 _offset;
83 uint16 _animators[16];
86 class Actor : public Animation {
88 public:
89 class Frame {
90 public:
91 Frame() : _position(999, 999), _nexts(8), _nextCount(0xff) {}
92 Frame(Common::Point pos, std::vector<byte> n, uint16 i) : _position(pos), _nexts(n), _index(i), _nextCount(0xff) {}
94 Common::Point position() const { return _position; }
95 const std::vector<byte> &nexts() const { return _nexts; }
96 uint16 index() const { return _index; }
98 Direction operator-(const Frame &other) const;
99 bool operator==(const Frame &other) const {
100 return _index == other._index;
102 byte nextCount() const {
103 if (_nextCount == 0xff) {
104 byte ct = 0;
105 for (int i = 0; i < 8; i++)
106 if (_nexts[i])
107 ct++;
108 _nextCount = ct;
111 return _nextCount;
114 private:
115 uint16 _index;
116 Common::Point _position;
117 std::vector<byte> _nexts;
118 mutable byte _nextCount;
121 class Speech {
122 public:
123 Speech() {}
124 ~Speech();
125 Speech(Common::String text);
126 bool active() const { return !_text.empty(); }
127 void callWhenDone(const CodePointer &cp) { _cb.push(cp); }
128 void paint(Graphics *g, Common::Point p);
129 void tick();
131 private:
132 Common::String _text;
133 Common::Queue<CodePointer> _cb;
134 uint16 _ticksLeft;
137 friend class MainDat;
138 friend class Program;
139 enum {
140 Size = 0x71
143 enum ActorOffsets {
144 kOffsetSegment = 0,
145 kOffsetOffset = 2,
146 kOffsetLeft = 4,
147 kOffsetTop = 6,
148 kOffsetMainSprite = 8,
149 kOffsetTicksLeft = 0xa,
150 kOffsetCode = 0xc,
151 kOffsetInterval = 0x10,
152 kOffsetRoom = 0x59
155 void setFrame(uint16 f);
156 uint16 frameId() const { return _frame; }
157 void moveTo(uint16 f);
158 static Common::List<Frame> findPath(Frame from, uint16 to);
160 uint16 room() const { return _room; }
161 void setRoom(uint16, uint16 frame = 0, uint16 nextFrame = 0);
163 bool isFine() const;
165 void setAnimation(const CodePointer &anim);
166 void setAnimation(uint16);
168 void hide();
169 void callMe(const CodePointer &cp);
170 void tellMe(const CodePointer &cp, uint16 timeout);
172 bool isSpeaking() const;
173 void callMeWhenSilent(const CodePointer &cp);
174 void say(const Common::String &text);
176 bool isMoving() const;
177 void callMeWhenStill(const CodePointer &cp);
179 Animation::Status tick();
180 void paint(Graphics *g);
182 void toggleDebug();
184 void setPuppeteer(const Puppeteer &p) { _puppeteer = p; }
185 private:
186 Actor(const CodePointer &code);
188 // just in case, we'll explicitly add those if needed
189 Actor();
190 Actor(const Actor &);
191 Actor &operator=(const Actor &);
193 void readHeader(const byte *code);
195 void animate();
196 bool turnTo(Direction);
197 bool nextFrame();
199 Common::Queue<Frame> _framequeue;
200 uint16 _frame;
201 uint16 _nextFrame;
202 uint16 _room;
203 Direction _direction, _nextDirection;
204 uint16 _nextAnimator; // to change to whenever possible
205 bool _attentionNeeded, _confused;
206 Puppeteer _puppeteer;
208 Common::Queue<CodePointer> _callBacks;
209 void callBacks();
211 struct RoomCallback {
212 uint16 timeout;
213 CodePointer callback;
214 RoomCallback(uint16 t, const CodePointer &p) : timeout(t), callback(p) {}
216 Common::List<RoomCallback> _roomCallbacks;
218 bool _debug;
220 template <int opcode>
221 Animation::Status opcodeHandler();
223 template <int N>
224 void init_opcodes();
226 virtual Animation::Status op(byte code);
228 typedef Animation::Status (Actor::*OpcodeHandler)();
229 OpcodeHandler _handlers[38];
231 Speech _speech;
236 #endif