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 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. 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, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 */ 22 23 #ifndef WORLD_ACTORS_ANIMATIONTRACKER_H 24 #define WORLD_ACTORS_ANIMATIONTRACKER_H 25 26 #include "ultima/ultima8/world/actors/animation.h" 27 #include "ultima/ultima8/world/actors/pathfinder.h" 28 29 namespace Ultima { 30 namespace Ultima8 { 31 32 class Actor; 33 class AnimAction; 34 struct AnimFrame; 35 36 class AnimationTracker { 37 public: 38 AnimationTracker(); 39 ~AnimationTracker(); 40 41 //! initialize the AnimationTracker for the given actor, action, dir 42 //! if state is non-zero, start from that state instead of the Actor's 43 //! current state 44 bool init(const Actor *actor, Animation::Sequence action, Direction dir, 45 const PathfindingState *state = 0); 46 47 //! evaluate the maximum distance the actor will travel if the current 48 //! animation runs to completion by incremental calls to step 49 void evaluateMaxAnimTravel(int32 &max_endx, int32 &max_endy, Direction dir); 50 51 //! do a single step of the animation 52 //! returns true if everything ok, false if not 53 //! caller must decide if animation should continue after a 'false' 54 bool step(); 55 56 //! do a single step of the animation, starting at (x,y,z) 57 //! returns true if everything ok, false if not 58 //! caller must decide if animation should continue after a 'false' 59 bool stepFrom(int32 x, int32 y, int32 z); 60 61 //! update the PathfindingState with latest coordinates and flags 62 void updateState(PathfindingState &state); 63 64 //! update the Actor with latest flags and animframe 65 void updateActorFlags(); 66 67 //! get the current position getPosition(int32 & x,int32 & y,int32 & z)68 void getPosition(int32 &x, int32 &y, int32 &z) const { 69 x = _x; 70 y = _y; 71 z = _z; 72 } 73 74 void getInterpolatedPosition(int32 &x, int32 &y, int32 &z, int fc) 75 const; 76 77 //! get the difference between current position and previous position 78 void getSpeed(int32 &dx, int32 &dy, int32 &dz) const; 79 80 //! get the current (shape)frame getFrame()81 uint32 getFrame() const { 82 return _shapeFrame; 83 } 84 85 //! get the current AnimAction getAnimAction()86 const AnimAction *getAnimAction() const { 87 return _animAction; 88 } 89 90 //! get the current AnimFrame 91 const AnimFrame *getAnimFrame() const; 92 93 void setTargetedMode(int32 x, int32 y, int32 z); 94 isDone()95 bool isDone() const { 96 return _done; 97 } isBlocked()98 bool isBlocked() const { 99 return _blocked; 100 } isUnsupported()101 bool isUnsupported() const { 102 return _unsupported; 103 } hitSomething()104 ObjId hitSomething() const { 105 return _hitObject; 106 } 107 108 bool load(Common::ReadStream *rs, uint32 version); 109 void save(Common::WriteStream *ods); 110 111 private: 112 enum Mode { 113 NormalMode = 0, 114 TargetMode 115 }; 116 117 unsigned int getNextFrame(unsigned int frame) const; 118 void checkWeaponHit(); 119 120 unsigned int _startFrame, _endFrame; 121 bool _firstFrame; 122 unsigned int _currentFrame; 123 124 ObjId _actor; 125 Direction _dir; 126 127 const AnimAction *_animAction; 128 129 // actor state 130 int32 _prevX, _prevY, _prevZ; 131 int32 _x, _y, _z; 132 int32 _startX, _startY, _startZ; 133 int32 _targetDx, _targetDy, _targetDz; 134 int32 _targetOffGroundLeft; 135 bool _firstStep, _flipped; 136 uint32 _shapeFrame; 137 138 // status flags 139 bool _done; 140 bool _blocked; 141 bool _unsupported; 142 ObjId _hitObject; 143 144 Mode _mode; 145 }; 146 147 } // End of namespace Ultima8 148 } // End of namespace Ultima 149 150 #endif 151