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 #ifndef DRAGONS_ACTOR_H 23 #define DRAGONS_ACTOR_H 24 25 #include "common/system.h" 26 27 namespace Dragons { 28 class Actor; 29 class ActorResourceLoader; 30 class ActorResource; 31 struct ActorFrame; 32 33 #define DRAGONS_ENGINE_NUM_ACTORS 64 34 35 enum ActorFlags { 36 ACTOR_FLAG_1 = 1, 37 ACTOR_FLAG_2 = 2, 38 ACTOR_FLAG_4 = 4, 39 ACTOR_FLAG_8 = 8, 40 ACTOR_FLAG_10 = 0x10, //actor is walking a path 41 ACTOR_FLAG_20 = 0x20, 42 ACTOR_FLAG_40 = 0x40, 43 ACTOR_FLAG_80 = 0x80, 44 ACTOR_FLAG_100 = 0x100, 45 ACTOR_FLAG_200 = 0x200, // Use screen coordinates not map coordinates. 46 ACTOR_FLAG_400 = 0x400, // Actor is hidden 47 ACTOR_FLAG_800 = 0x800, 48 ACTOR_FLAG_1000 = 0x1000, 49 ACTOR_FLAG_2000 = 0x2000, 50 ACTOR_FLAG_4000 = 0x4000, 51 ACTOR_FLAG_8000 = 0x8000 //Seems turn off semi trans mode when selected. 52 }; 53 54 enum ActorFrameFlags { 55 ACTOR_FRAME_FLAG_2 = 0x2, 56 ACTOR_FRAME_FLAG_10 = 0x10, 57 ACTOR_FRAME_FLAG_20 = 0x20 58 }; 59 60 class ActorManager { 61 public: 62 typedef Common::Array<Actor> Actors; 63 typedef Actors::iterator ActorsIterator; 64 65 private: 66 ActorResourceLoader *_actorResourceLoader; 67 Actors _actors; 68 uint16 _displayOrder[DRAGONS_ENGINE_NUM_ACTORS]; 69 public: 70 ActorManager(ActorResourceLoader *actorResourceLoader); 71 72 public: 73 Actor *loadActor(uint32 resourceId, uint32 sequenceId, int16 x, int16 y); 74 Actor *loadActor(uint32 resourceId, uint32 sequenceId, int16 x, int16 y, uint16 priorityLayer); 75 Actor *loadActor(uint32 resourceId, uint16 actorId); 76 Actor *getActor(uint16 actorId); 77 Actor *getActorByDisplayOrder(uint16 position); 78 void clearActorFlags(uint16 startingActorId); 79 ActorResource *getActorResource(uint32 resourceId); 80 void updateActorDisplayOrder(); 81 private: 82 Actor *findFreeActor(int16 resourceID); 83 void resetDisplayOrder(); 84 }; 85 86 class Actor { 87 public: 88 uint16 _actorID; 89 ActorResource* _actorResource; 90 uint16 _actorFileDictionaryIndex; 91 int16 _resourceID; 92 byte *_seqCodeIp; 93 ActorFrame *_frame; 94 Graphics::Surface *_surface; 95 uint16 _sequenceTimerMaxValue; 96 int16 _scale; // scale factor 0x100 is 100% 97 uint16 _sequenceTimer; 98 uint16 _sequenceID; 99 int16 _direction; 100 int16 _priorityLayer; 101 uint16 _flags; 102 int16 _x_pos; 103 int16 _y_pos; 104 int16 _walkDestX; 105 int16 _walkDestY; 106 int32 _xShl16; 107 int32 _yShl16; 108 int32 _walkSlopeX; 109 int32 _walkSlopeY; 110 uint16 _walkPointsTbl[32]; 111 int16 _walkPointsIndex; 112 int16 _finalWalkDestX; 113 int16 _finalWalkDestY; 114 uint16 _field_7a; 115 int32 _walkSpeed; 116 uint16 _frame_flags; 117 public: 118 119 Actor(uint16 id); 120 void init(ActorResource *resource, int16 x, int16 y, uint32 sequenceID); 121 void updateSequence(uint16 newSequenceID); 122 void resetSequenceIP(); 123 byte *getSeqIpAtOffset(uint32 offset); 124 void loadFrame(uint16 frameOffset); 125 void freeFrame(); 126 void reset_maybe(); 127 bool startWalk(int16 destX, int16 destY, uint16 flags); 128 void walkPath(); 129 void waitUntilFlag4IsSet(); 130 void waitUntilFlag8IsSet(); 131 void waitUntilFlag8And4AreSet(); 132 void waitUntilFlag8SetThenSet1000(); 133 void waitUntilFlag8SetThenSet1000AndWaitFor4(); 134 void waitForWalkToFinish(); 135 136 bool waitUntilFlag4IsSetAllowSkip(); 137 bool actorSetSequenceAndWaitAllowSkip(uint16 newSequenceID); 138 139 void clearFlag(uint32 flag); 140 void setFlag(uint32 flag); 141 bool isFlagSet(uint32 flag); isFlagClear(uint32 flag)142 bool isFlagClear(uint32 flag) { return !isFlagSet(flag); } 143 144 byte *getPalette(); 145 int16 getFrameYOffset(); 146 private: 147 void stopWalk(); 148 uint16 canWalkLine(int16 actor_x, int16 actor_y, int16 target_x, int16 target_y, uint16 walkFlags); 149 int16 pathfindingFindClosestPoint(int16 actor_x, int16 actor_y, int16 target_x, int16 target_y, int16 unkType, 150 bool *pointsInUseTbl); 151 int startMoveToPoint(int destX, int destY); 152 }; 153 154 } // End of namespace Dragons 155 156 #endif //DRAGONS_ACTOR_H 157