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"
58 Direction
operator>>(Direction a
, Direction b
);
66 kTurnAnimators
= 0x14,
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
);
80 void parse(const byte
*data
);
84 uint16 _animators
[16];
87 class Actor
: public Animation
{
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) {
106 for (int i
= 0; i
< 8; i
++)
117 Common::Point _position
;
118 std::vector
<byte
> _nexts
;
119 mutable byte _nextCount
;
124 Speech() : _actor(0) {}
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
);
133 Common::String _text
;
134 Common::Queue
<CodePointer
> _cb
;
138 Innocent::Sprite
*_image
;
141 friend class MainDat
;
142 friend class Program
;
152 kOffsetMainSprite
= 8,
153 kOffsetTicksLeft
= 0xa,
155 kOffsetInterval
= 0x10,
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);
171 void setAnimation(const CodePointer
&anim
);
172 void setAnimation(uint16
);
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
);
190 void setPuppeteer(const Puppeteer
&p
) { _puppeteer
= p
; }
192 Actor(const CodePointer
&code
);
194 // just in case, we'll explicitly add those if needed
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;
211 bool turnTo(Direction
);
214 Common::Queue
<Frame
> _framequeue
;
218 Direction _direction
, _nextDirection
;
219 uint16 _nextAnimator
; // to change to whenever possible
220 bool _attentionNeeded
, _confused
;
221 Puppeteer _puppeteer
;
223 Common::Queue
<CodePointer
> _callBacks
;
226 struct RoomCallback
{
228 CodePointer callback
;
229 RoomCallback(uint16 t
, const CodePointer
&p
) : timeout(t
), callback(p
) {}
231 Common::List
<RoomCallback
> _roomCallbacks
;
235 template <int opcode
>
236 Animation::Status
opcodeHandler();
241 virtual Animation::Status
op(byte code
);
243 typedef Animation::Status (Actor::*OpcodeHandler
)();
244 OpcodeHandler _handlers
[38];