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 GOB_GOBLIN_H 24 #define GOB_GOBLIN_H 25 26 #include "gob/util.h" 27 #include "gob/mult.h" 28 #include "gob/variables.h" 29 #include "gob/sound/sounddesc.h" 30 31 namespace Gob { 32 33 #define TYPE_USUAL 0 34 #define TYPE_AMORPHOUS 1 35 #define TYPE_MOBILE 3 36 37 class Goblin { 38 39 public: 40 41 #include "common/pack-start.h" // START STRUCT PACKING 42 43 struct Gob_State { 44 int16 animation; 45 int16 layer; 46 int16 unk0; 47 int16 unk1; 48 int16 sndItem; // high/low byte - sound sample index 49 int16 freq; // high/low byte * 100 - frequency 50 int16 repCount; // high/low byte - repeat count 51 int16 sndFrame; 52 } PACKED_STRUCT; 53 54 typedef Gob_State *Gob_PState; 55 56 typedef Gob_PState Gob_StateLine[6]; 57 58 struct Gob_Object { 59 int16 animation; 60 int16 state; 61 int16 stateColumn; 62 int16 curFrame; 63 int16 xPos; 64 int16 yPos; 65 int16 dirtyLeft; 66 int16 dirtyTop; 67 int16 dirtyRight; 68 int16 dirtyBottom; 69 int16 left; 70 int16 top; 71 int16 right; 72 int16 bottom; 73 int16 nextState; 74 int16 multState; 75 int16 actionStartState; 76 int16 curLookDir; 77 int16 pickable; 78 int16 relaxTime; 79 Gob_StateLine *stateMach; 80 Gob_StateLine *realStateMach; 81 char doAnim; 82 int8 order; 83 char noTick; 84 char toRedraw; 85 char type; 86 char maxTick; 87 char tick; 88 char multObjIndex; 89 char unk14; 90 char visible; 91 } PACKED_STRUCT; 92 93 struct Gob_Pos { 94 char x; 95 char y; 96 } PACKED_STRUCT; 97 98 #include "common/pack-end.h" // END STRUCT PACKING 99 100 Gob_Object *_goblins[4]; 101 int16 _currentGoblin; 102 SoundDesc _soundData[16]; 103 int16 _gobStateLayer; 104 char _goesAtTarget; 105 char _readyToAct; 106 int16 _gobAction; // 0 - move, 3 - do action, 4 - pick 107 // goblins: 0 - picker, 1 - fighter, 2 - mage 108 Gob_Pos _gobPositions[3]; 109 int16 _gobDestX; 110 int16 _gobDestY; 111 int16 _pressedMapX; 112 int16 _pressedMapY; 113 char _pathExistence; 114 115 // Pointers to interpreter variables 116 VariableReference _some0ValPtr; 117 118 VariableReference _gobRetVarPtr; 119 VariableReference _curGobVarPtr; 120 VariableReference _curGobXPosVarPtr; 121 VariableReference _curGobYPosVarPtr; 122 VariableReference _itemInPocketVarPtr; 123 124 VariableReference _curGobStateVarPtr; 125 VariableReference _curGobFrameVarPtr; 126 VariableReference _curGobMultStateVarPtr; 127 VariableReference _curGobNextStateVarPtr; 128 VariableReference _curGobScrXVarPtr; 129 VariableReference _curGobScrYVarPtr; 130 VariableReference _curGobLeftVarPtr; 131 VariableReference _curGobTopVarPtr; 132 VariableReference _curGobRightVarPtr; 133 VariableReference _curGobBottomVarPtr; 134 VariableReference _curGobDoAnimVarPtr; 135 VariableReference _curGobOrderVarPtr; 136 VariableReference _curGobNoTickVarPtr; 137 VariableReference _curGobTypeVarPtr; 138 VariableReference _curGobMaxTickVarPtr; 139 VariableReference _curGobTickVarPtr; 140 VariableReference _curGobActStartStateVarPtr; 141 VariableReference _curGobLookDirVarPtr; 142 VariableReference _curGobPickableVarPtr; 143 VariableReference _curGobRelaxVarPtr; 144 VariableReference _curGobMaxFrameVarPtr; 145 146 VariableReference _destItemStateVarPtr; 147 VariableReference _destItemFrameVarPtr; 148 VariableReference _destItemMultStateVarPtr; 149 VariableReference _destItemNextStateVarPtr; 150 VariableReference _destItemScrXVarPtr; 151 VariableReference _destItemScrYVarPtr; 152 VariableReference _destItemLeftVarPtr; 153 VariableReference _destItemTopVarPtr; 154 VariableReference _destItemRightVarPtr; 155 VariableReference _destItemBottomVarPtr; 156 VariableReference _destItemDoAnimVarPtr; 157 VariableReference _destItemOrderVarPtr; 158 VariableReference _destItemNoTickVarPtr; 159 VariableReference _destItemTypeVarPtr; 160 VariableReference _destItemMaxTickVarPtr; 161 VariableReference _destItemTickVarPtr; 162 VariableReference _destItemActStartStVarPtr; 163 VariableReference _destItemLookDirVarPtr; 164 VariableReference _destItemPickableVarPtr; 165 VariableReference _destItemRelaxVarPtr; 166 VariableReference _destItemMaxFrameVarPtr; 167 168 int16 _destItemType; 169 int16 _destItemState; 170 int16 _itemToObject[20]; 171 Gob_Object *_objects[20]; 172 int16 _objCount; 173 int16 _gobsCount; 174 int16 _itemIndInPocket; 175 int16 _itemIdInPocket; 176 char _itemByteFlag; 177 int16 _destItemId; 178 int16 _destActionItem; 179 Gob_Object *_actDestItemDesc; 180 int16 _forceNextState[10]; 181 char _boreCounter; 182 int16 _positionedGob; 183 char _noPick; 184 185 // Gob2: 186 int16 _soundSlotsCount; 187 int16 _soundSlots[60]; 188 bool _gob1Busy; 189 bool _gob2Busy; 190 int16 _gob1RelaxTimeVar; 191 int16 _gob2RelaxTimeVar; 192 bool _gob1NoTurn; 193 bool _gob2NoTurn; 194 195 // Functions 196 char rotateState(int16 from, int16 to); 197 void playSound(SoundDesc &snd, int16 repCount, int16 freq); 198 void drawObjects(); 199 void animateObjects(); 200 int16 getObjMaxFrame(Gob_Object * obj); 201 bool objIntersected(Gob_Object * obj1, Gob_Object * obj2); 202 void setMultStates(Gob_Object * gobDesc); 203 int16 nextLayer(Gob_Object * gobDesc); 204 void showBoredom(int16 gobIndex); 205 void switchGoblin(int16 index); 206 void zeroObjects(); 207 void freeAllObjects(); 208 void loadObjects(const char *source); 209 void initVarPointers(); 210 void saveGobDataToVars(int16 xPos, int16 yPos, int16 someVal); 211 void loadGobDataFromVars(); 212 void pickItem(int16 indexToPocket, int16 idToPocket); 213 void placeItem(int16 indexInPocket, int16 idInPocket); 214 void swapItems(int16 indexToPick, int16 idToPick); 215 void treatItemPick(int16 itemId); 216 int16 treatItem(int16 action); 217 int16 doMove(Gob_Object *gobDesc, int16 cont, int16 action); 218 219 void setState(int16 index, int16 state); 220 void updateLayer1(Mult::Mult_AnimData *animData); 221 void updateLayer2(Mult::Mult_AnimData *animData); 222 void move(int16 destX, int16 destY, int16 objIndex); 223 void animate(Mult::Mult_Object *obj); 224 225 virtual void handleGoblins() = 0; 226 virtual void placeObject(Gob_Object * objDesc, char animated, 227 int16 index, int16 x, int16 y, int16 state) = 0; 228 virtual void freeObjects() = 0; 229 virtual void initiateMove(Mult::Mult_Object *obj) = 0; 230 virtual void moveAdvance(Mult::Mult_Object *obj, Gob_Object *gobDesc, 231 int16 nextAct, int16 framesCount) = 0; 232 233 Goblin(GobEngine *vm); 234 virtual ~Goblin(); 235 236 protected: 237 Util::List *_objList; 238 int16 _rotStates[4][4]; 239 240 GobEngine *_vm; 241 242 int16 peekGoblin(Gob_Object *curGob); 243 void initList(); 244 void sortByOrder(Util::List *list); 245 void adjustDest(int16 posX, int16 posY); 246 void adjustTarget(); 247 void targetDummyItem(Gob_Object *gobDesc); 248 void targetItem(); 249 void moveFindItem(int16 posX, int16 posY); 250 void moveCheckSelect(int16 framesCount, Gob_Object * gobDesc, 251 int16 *pGobIndex, int16 *nextAct); 252 void moveInitStep(int16 framesCount, int16 action, int16 cont, 253 Gob_Object *gobDesc, int16 *pGobIndex, int16 *pNextAct); 254 void moveTreatRopeStairs(Gob_Object *gobDesc); 255 void playSounds(Mult::Mult_Object *obj); 256 257 virtual bool isMovement(int8 state) = 0; 258 virtual void advMovement(Mult::Mult_Object *obj, int8 state) = 0; 259 virtual void movePathFind(Mult::Mult_Object *obj, 260 Gob_Object *gobDesc, int16 nextAct) = 0; 261 }; 262 263 class Goblin_v1 : public Goblin { 264 public: handleGoblins()265 virtual void handleGoblins() {} 266 virtual void placeObject(Gob_Object * objDesc, char animated, 267 int16 index, int16 x, int16 y, int16 state); 268 virtual void freeObjects(); 269 virtual void initiateMove(Mult::Mult_Object *obj); 270 virtual void moveAdvance(Mult::Mult_Object *obj, Gob_Object *gobDesc, 271 int16 nextAct, int16 framesCount); 272 273 Goblin_v1(GobEngine *vm); ~Goblin_v1()274 virtual ~Goblin_v1() {} 275 276 protected: isMovement(int8 state)277 virtual bool isMovement(int8 state) { return false; } advMovement(Mult::Mult_Object * obj,int8 state)278 virtual void advMovement(Mult::Mult_Object *obj, int8 state) {} 279 virtual void movePathFind(Mult::Mult_Object *obj, 280 Gob_Object *gobDesc, int16 nextAct); 281 }; 282 283 class Goblin_v2 : public Goblin_v1 { 284 public: 285 virtual void handleGoblins(); 286 virtual void placeObject(Gob_Object * objDesc, char animated, 287 int16 index, int16 x, int16 y, int16 state); 288 virtual void freeObjects(); 289 virtual void initiateMove(Mult::Mult_Object *obj); 290 virtual void moveAdvance(Mult::Mult_Object *obj, Gob_Object *gobDesc, 291 int16 nextAct, int16 framesCount); 292 293 Goblin_v2(GobEngine *vm); ~Goblin_v2()294 virtual ~Goblin_v2() {} 295 296 protected: 297 virtual bool isMovement(int8 state); 298 virtual void advMovement(Mult::Mult_Object *obj, int8 state); 299 virtual void movePathFind(Mult::Mult_Object *obj, 300 Gob_Object *gobDesc, int16 nextAct); 301 }; 302 303 class Goblin_v3 : public Goblin_v2 { 304 public: 305 virtual void placeObject(Gob_Object * objDesc, char animated, 306 int16 index, int16 x, int16 y, int16 state); 307 308 Goblin_v3(GobEngine *vm); ~Goblin_v3()309 virtual ~Goblin_v3() {} 310 311 protected: 312 virtual bool isMovement(int8 state); 313 virtual void advMovement(Mult::Mult_Object *obj, int8 state); 314 }; 315 316 class Goblin_v4 : public Goblin_v3 { 317 public: 318 virtual void movePathFind(Mult::Mult_Object *obj, 319 Gob_Object *gobDesc, int16 nextAct); 320 virtual void moveAdvance(Mult::Mult_Object *obj, Gob_Object *gobDesc, 321 int16 nextAct, int16 framesCount); 322 323 Goblin_v4(GobEngine *vm); ~Goblin_v4()324 virtual ~Goblin_v4() {} 325 326 private: 327 int16 turnState(int16 state, uint16 dir); 328 }; 329 330 } // End of namespace Gob 331 332 #endif // GOB_GOBLIN_H 333