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