0x9c
[scummvm-innocent.git] / engines / innocent / actor.h
blob31a99e8796934d58783973e14da74db073d65936
1 #ifndef INNOCENT_ACTOR_H
2 #define INNOCENT_ACTOR_H
4 #include <vector>
6 #include "common/endian.h"
7 #include "common/queue.h"
9 #include "innocent/animation.h"
10 #include "innocent/value.h"
12 namespace Innocent {
15 class MainDat;
16 class Program;
18 class Puppeteer {
19 public:
20 enum Offsets {
21 kActorId = 0,
22 kMainCode = 2,
23 kSize = 0x24
25 Puppeteer() : _offset(0), _actorId(0) {}
26 Puppeteer(const byte *data) { parse(data); }
28 uint16 mainCodeOffset() const { return _offset; }
29 uint16 actorId() const { return _actorId; }
31 private:
32 void parse(const byte *data) {
33 _actorId = READ_LE_UINT16(data + kActorId);
34 _offset = READ_LE_UINT16(data + kMainCode);
37 uint16 _actorId;
38 uint16 _offset;
41 class Actor : public Animation {
43 public:
44 class Frame {
45 public:
46 Frame() : _left(999), _top(999), _nexts(8) {}
47 Frame(int16 l, int16 t, std::vector<byte> nexts) : _left(l), _top(t), _nexts(nexts) {}
49 int16 left() const { return _left; }
50 int16 top() const { return _top; }
52 private:
53 int16 _left;
54 int16 _top;
55 std::vector<byte> _nexts;
58 friend class MainDat;
59 friend class Program;
60 enum {
61 Size = 0x71
64 enum ActorOffsets {
65 kOffsetOffset = 2,
66 kOffsetLeft = 4,
67 kOffsetTop = 6,
68 kOffsetMainSprite = 8,
69 kOffsetTicksLeft = 0xa,
70 kOffsetCode = 0xc,
71 kOffsetInterval = 0x10,
72 kOffsetRoom = 0x59
75 void setFrame(uint16 f);
77 uint16 room() const { return _room; }
78 void setRoom(uint16, uint16 frame = 0, uint16 nextFrame = 0);
80 bool isFine() const;
82 void setAnimation(const CodePointer &anim);
84 void hide();
85 void callMe(const CodePointer &cp);
86 void tellMe(const CodePointer &cp, uint16 timeout);
88 Animation::Status tick();
90 void toggleDebug();
92 void setPuppeteer(const Puppeteer &p) { _puppeteer = p; }
93 private:
94 Actor(const CodePointer &code);
96 // just in case, we'll explicitly add those if needed
97 Actor();
98 Actor(const Actor &);
99 Actor &operator=(const Actor &);
101 void readHeader(const byte *code);
103 uint16 _frame;
104 uint16 _nextFrame;
105 uint16 _room;
106 byte _dir63;
107 uint16 _nextAnimator; // to change to whenever possible
108 bool _attentionNeeded;
109 Puppeteer _puppeteer;
111 Common::Queue<CodePointer> _callBacks;
112 void callBacks();
114 struct RoomCallback {
115 uint16 timeout;
116 CodePointer callback;
117 RoomCallback(uint16 t, const CodePointer &p) : timeout(t), callback(p) {}
119 Common::List<RoomCallback> _roomCallbacks;
121 bool _debug;
123 template <int opcode>
124 Animation::Status opcodeHandler();
126 template <int N>
127 void init_opcodes();
129 virtual Animation::Status op(byte code);
131 typedef Animation::Status (Actor::*OpcodeHandler)();
132 OpcodeHandler _handlers[38];
137 #endif