ScummVM API documentation
anim_action.h
1 /* ScummVM - Graphic Adventure Engine
2  *
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.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
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.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef WORLD_ACTORS_ANIMACTION_H
23 #define WORLD_ACTORS_ANIMACTION_H
24 
25 #include "ultima/shared/std/containers.h"
26 #include "ultima/ultima8/misc/direction.h"
27 
28 namespace Ultima {
29 namespace Ultima8 {
30 
31 class Actor;
32 
33 struct AnimFrame {
34  int _frame;
35  int _deltaZ;
36  int _deltaDir;
37  int _sfx;
38  uint32 _flags;
39 
42  AFF_ONGROUND = 0x00000002,
43  AFF_FLIPPED = 0x00000020,
44  AFF_SPECIAL = 0x00000800, // U8 only
45  AFF_HURTY = 0x00001000, // Crusader only - TODO: find a better name for this.
46  AFF_USECODE = 0x00004000,
47  AFF_CRUFLIP = 0x00008000 // Crusader only
48  //AFF_UNKNOWN = 0xF0E0B01C,
49  //AFF_FIRE = 0x0F1F00C0
50  };
51 
52  inline bool is_onground() const {
53  return (_flags & AFF_ONGROUND) != 0;
54  }
55 
56  inline bool is_flipped() const {
57  return (_flags & AFF_FLIPPED) != 0;
58  }
59 
60  inline bool is_callusecode() const {
61  return (_flags & AFF_USECODE) != 0;
62  }
63 
64  inline bool is_cruflipped() const {
65  return (_flags & AFF_CRUFLIP) != 0;
66  }
67 
68  inline int attack_range() const {
69  return ((_flags >> 2) & 0x07);
70  }
71 
72  // Note: The next 3 functions each have a 4-bit
73  // value to unpack from the flags. x/y are signed, z is unsigned.
74  inline int cru_attackx() const {
75  uint32 rawx = (_flags & 0x00000780) << 5;
76  int16 signedx = static_cast<int16>(rawx) >> 12;
77  return signedx * 16;
78  }
79 
80  inline int cru_attacky() const {
81  uint32 rawy = (_flags & 0x00F00000) >> 16;
82  return static_cast<int8>(rawy);
83  }
84 
85  inline int cru_attackz() const {
86  return (_flags & 0x0F000000) >> 21;
87  }
88 
89  inline bool is_cruattack() const {
90  return (cru_attackx() || cru_attacky() || cru_attackz());
91  }
92 };
93 
94 class AnimAction {
95  friend class AnimDat;
96 
97 public:
103  void getAnimRange(const Actor *actor, Direction dir,
104  unsigned int &startframe, unsigned int &endframe) const;
105 
113  void getAnimRange(unsigned int lastanim, Direction lastdir,
114  bool firststep, Direction dir,
115  unsigned int &startframe, unsigned int &endframe) const;
116 
117  unsigned int getDirCount() const {
118  return _dirCount;
119  }
120 
121  unsigned int getSize() const {
122  return _size;
123  }
124 
125  int getFrameRepeat() const {
126  return _frameRepeat;
127  }
128 
129  uint32 getShapeNum() const {
130  return _shapeNum;
131  }
132 
133  uint32 getAction() const {
134  return _action;
135  }
136 
137  bool hasFlags(uint32 mask) const {
138  return (_flags & mask) != 0;
139  }
140 
141  uint32 getFlags() const {
142  return _flags;
143  }
144 
145  const AnimFrame &getFrame(Direction dir, unsigned int frameno) const;
146 
155  AAF_NONE = 0x0000,
156  AAF_TWOSTEP = 0x0001,
157  AAF_ATTACK = 0x0002, // U8 only? also present in crusader, but ignored.
158  AAF_LOOPING = 0x0004,
159  AAF_UNSTOPPABLE = 0x0008,
160  AAF_LOOPING2_U8 = 0x0010,
161  AAF_ENDLOOP_U8 = 0x0020, // TODO: This starts a new anim at the end if pathfinding
162  AAF_ENDLOOP_CRU = 0x0040, // TODO: This starts a new anim at the end if pathfinding
163  AAF_HANGING = 0x0080,
164  AAF_16DIRS = 0x4000, // Cru only
165  AAF_DESTROYACTOR = 0x8000, // destroy actor after animation finishes
166  AAF_ROTATED = 0x10000, // Cru only
167  AAF_COMMONFLAGS = (AAF_TWOSTEP | AAF_LOOPING | AAF_UNSTOPPABLE | AAF_HANGING | AAF_DESTROYACTOR)
168  };
169 
170 
171 private:
172  static AnimActionFlags loadAnimActionFlags(uint32 rawflags);
173 
174  uint32 _shapeNum;
175  uint32 _action;
176 
177  Std::vector<AnimFrame> _frames[16]; // 8 or 16 directions
178  unsigned int _size;
179  int _frameRepeat;
180  AnimActionFlags _flags;
181 
182  unsigned int _dirCount;
183 };
184 
185 } // End of namespace Ultima8
186 } // End of namespace Ultima
187 
188 #endif
Definition: anim_action.h:94
AnimFrameFlags
Definition: anim_action.h:41
Definition: detection.h:27
Definition: anim_dat.h:35
Definition: actor.h:37
Definition: anim_action.h:33
AnimActionFlags
Definition: anim_action.h:154
Definition: containers.h:38