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.
26 #ifndef INNOCENT_ACTOR_H
27 #define INNOCENT_ACTOR_H
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"
57 Direction
operator>>(Direction a
, Direction b
);
65 kTurnAnimators
= 0x14,
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
);
79 void parse(const byte
*data
);
83 uint16 _animators
[16];
86 class Actor
: public Animation
{
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) {
105 for (int i
= 0; i
< 8; i
++)
116 Common::Point _position
;
117 std::vector
<byte
> _nexts
;
118 mutable byte _nextCount
;
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
);
132 Common::String _text
;
133 Common::Queue
<CodePointer
> _cb
;
137 friend class MainDat
;
138 friend class Program
;
148 kOffsetMainSprite
= 8,
149 kOffsetTicksLeft
= 0xa,
151 kOffsetInterval
= 0x10,
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);
165 void setAnimation(const CodePointer
&anim
);
166 void setAnimation(uint16
);
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
);
184 void setPuppeteer(const Puppeteer
&p
) { _puppeteer
= p
; }
186 Actor(const CodePointer
&code
);
188 // just in case, we'll explicitly add those if needed
190 Actor(const Actor
&);
191 Actor
&operator=(const Actor
&);
193 void readHeader(const byte
*code
);
196 bool turnTo(Direction
);
199 Common::Queue
<Frame
> _framequeue
;
203 Direction _direction
, _nextDirection
;
204 uint16 _nextAnimator
; // to change to whenever possible
205 bool _attentionNeeded
, _confused
;
206 Puppeteer _puppeteer
;
208 Common::Queue
<CodePointer
> _callBacks
;
211 struct RoomCallback
{
213 CodePointer callback
;
214 RoomCallback(uint16 t
, const CodePointer
&p
) : timeout(t
), callback(p
) {}
216 Common::List
<RoomCallback
> _roomCallbacks
;
220 template <int opcode
>
221 Animation::Status
opcodeHandler();
226 virtual Animation::Status
op(byte code
);
228 typedef Animation::Status (Actor::*OpcodeHandler
)();
229 OpcodeHandler _handlers
[38];