ScummVM API documentation
creature.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 ULTIMA4_GAME_CREATURE_H
23 #define ULTIMA4_GAME_CREATURE_H
24 
25 #include "ultima/ultima4/game/object.h"
26 #include "ultima/ultima4/map/movement.h"
27 #include "ultima/ultima4/filesys/savegame.h"
28 #include "ultima/ultima4/core/types.h"
29 
30 namespace Ultima {
31 namespace Ultima4 {
32 
33 class CombatController;
34 class ConfigElement;
35 class Tile;
36 
37 typedef unsigned short CreatureId;
39 typedef Std::vector<class Creature *> CreatureVector;
40 
41 #define MAX_CREATURES 128
42 
43 /* Creatures on world map */
44 
45 #define MAX_CREATURES_ON_MAP 4
46 #define MAX_CREATURE_DISTANCE 16
47 
48 /* Creature ids */
49 
50 typedef enum {
51  HORSE1_ID = 0,
52  HORSE2_ID = 1,
53 
54  MAGE_ID = 2,
55  BARD_ID = 3,
56  FIGHTER_ID = 4,
57  DRUID_ID = 5,
58  TINKER_ID = 6,
59  PALADIN_ID = 7,
60  RANGER_ID = 8,
61  SHEPHERD_ID = 9,
62 
63  GUARD_ID = 10,
64  VILLAGER_ID = 11,
65  SINGINGBARD_ID = 12,
66  JESTER_ID = 13,
67  BEGGAR_ID = 14,
68  CHILD_ID = 15,
69  BULL_ID = 16,
70  LORDBRITISH_ID = 17,
71 
72  PIRATE_ID = 18,
73  NIXIE_ID = 19,
74  GIANT_SQUID_ID = 20,
75  SEA_SERPENT_ID = 21,
76  SEAHORSE_ID = 22,
77  WHIRLPOOL_ID = 23,
78  STORM_ID = 24,
79  RAT_ID = 25,
80  BAT_ID = 26,
81  GIANT_SPIDER_ID = 27,
82  GHOST_ID = 28,
83  SLIME_ID = 29,
84  TROLL_ID = 30,
85  GREMLIN_ID = 31,
86  MIMIC_ID = 32,
87  REAPER_ID = 33,
88  INSECT_SWARM_ID = 34,
89  GAZER_ID = 35,
90  PHANTOM_ID = 36,
91  ORC_ID = 37,
92  SKELETON_ID = 38,
93  ROGUE_ID = 39,
94  PYTHON_ID = 40,
95  ETTIN_ID = 41,
96  HEADLESS_ID = 42,
97  CYCLOPS_ID = 43,
98  WISP_ID = 44,
99  EVILMAGE_ID = 45,
100  LICH_ID = 46,
101  LAVA_LIZARD_ID = 47,
102  ZORN_ID = 48,
103  DAEMON_ID = 49,
104  HYDRA_ID = 50,
105  DRAGON_ID = 51,
106  BALRON_ID = 52
107 } CreatureType;
108 
109 typedef enum {
110  MATTR_STEALFOOD = 0x1,
111  MATTR_STEALGOLD = 0x2,
112  MATTR_CASTS_SLEEP = 0x4,
113  MATTR_UNDEAD = 0x8,
114  MATTR_GOOD = 0x10,
115  MATTR_WATER = 0x20,
116  MATTR_NONATTACKABLE = 0x40,
117  MATTR_NEGATE = 0x80,
118  MATTR_CAMOUFLAGE = 0x100,
119  MATTR_NOATTACK = 0x200,
120  MATTR_AMBUSHES = 0x400,
121  MATTR_RANDOMRANGED = 0x800,
122  MATTR_INCORPOREAL = 0x1000,
123  MATTR_NOCHEST = 0x2000,
124  MATTR_DIVIDES = 0x4000,
125  MATTR_SPAWNSONDEATH = 0x8000,
126  MATTR_FORCE_OF_NATURE = 0x10000
127 } CreatureAttrib;
128 
129 typedef enum {
130  MATTR_STATIONARY = 0x1,
131  MATTR_WANDERS = 0x2,
132  MATTR_SWIMS = 0x4,
133  MATTR_SAILS = 0x8,
134  MATTR_FLIES = 0x10,
135  MATTR_TELEPORT = 0x20,
136  MATTR_CANMOVECREATURES = 0x40,
137  MATTR_CANMOVEAVATAR = 0x80
138 } CreatureMovementAttrib;
139 
140 typedef enum {
141  MSTAT_DEAD,
142  MSTAT_FLEEING,
143  MSTAT_CRITICAL,
144  MSTAT_HEAVILYWOUNDED,
145  MSTAT_LIGHTLYWOUNDED,
146  MSTAT_BARELYWOUNDED
147 } CreatureStatus;
148 
159 class Creature : public Object {
161 
162 public:
166  Creature(MapTile tile = MapTile(0));
167 
168  void load(const ConfigElement &conf);
169 
170  // Accessor methods
171  virtual Common::String getName() const {
172  return _name;
173  }
174  virtual const Common::String &getHitTile() const {
175  return _rangedHitTile;
176  }
177  virtual const Common::String &getMissTile() const {
178  return _rangedMissTile;
179  }
180  CreatureId getId() const {
181  return _id;
182  }
183  CreatureId getLeader() const {
184  return _leader;
185  }
186  virtual int getHp() const {
187  return _hp;
188  }
189  virtual int getXp() const {
190  return _xp;
191  }
192  virtual const Common::String &getWorldrangedtile() const {
193  return _worldRangedTile;
194  }
195  SlowedType getSlowedType() const {
196  return _slowedType;
197  }
198  int getEncounterSize() const {
199  return _encounterSize;
200  }
201  byte getResists() const {
202  return _resists;
203  }
204 
205  // Setters
206  void setName(Common::String s) {
207  _name = s;
208  }
209  void setHitTile(const Common::String &t) {
210  _rangedHitTile = t;
211  }
212  void setMissTile(const Common::String &t) {
213  _rangedMissTile = t;
214  }
215  virtual void setHp(int points) {
216  _hp = points;
217  }
218 
219  // Query methods
220  bool isGood() const {
221  return _mAttr & MATTR_GOOD;
222  }
223  bool isEvil() const {
224  return !isGood();
225  }
226  bool isUndead() const {
227  return _mAttr & MATTR_UNDEAD;
228  }
229  bool leavesChest() const {
230  return !isAquatic() && !(_mAttr & MATTR_NOCHEST);
231  }
232  bool isAquatic() const {
233  return _mAttr & MATTR_WATER;
234  }
235  bool wanders() const {
236  return _movementAttr & MATTR_WANDERS;
237  }
238  bool isStationary() const {
239  return _movementAttr & MATTR_STATIONARY;
240  }
241  bool flies() const {
242  return _movementAttr & MATTR_FLIES;
243  }
244  bool teleports() const {
245  return _movementAttr & MATTR_TELEPORT;
246  }
247  bool swims() const {
248  return _movementAttr & MATTR_SWIMS;
249  }
250  bool sails() const {
251  return _movementAttr & MATTR_SAILS;
252  }
253  bool walks() const {
254  return !(flies() || swims() || sails());
255  }
256  bool divides() const {
257  return _mAttr & MATTR_DIVIDES;
258  }
259  bool spawnsOnDeath() const {
260  return _mAttr & MATTR_SPAWNSONDEATH;
261  }
262  bool canMoveOntoCreatures() const {
263  return _movementAttr & MATTR_CANMOVECREATURES;
264  }
265  bool canMoveOntoPlayer() const {
266  return _movementAttr & MATTR_CANMOVEAVATAR;
267  }
268  bool isAttackable() const;
269  bool willAttack() const {
270  return !(_mAttr & MATTR_NOATTACK);
271  }
272  bool stealsGold() const {
273  return _mAttr & MATTR_STEALGOLD;
274  }
275  bool stealsFood() const {
276  return _mAttr & MATTR_STEALFOOD;
277  }
278  bool negates() const {
279  return _mAttr & MATTR_NEGATE;
280  }
281  bool camouflages() const {
282  return _mAttr & MATTR_CAMOUFLAGE;
283  }
284  bool ambushes() const {
285  return _mAttr & MATTR_AMBUSHES;
286  }
287  bool isIncorporeal() const {
288  return _mAttr & MATTR_INCORPOREAL;
289  }
290  bool hasRandomRanged() const {
291  return _mAttr & MATTR_RANDOMRANGED;
292  }
293  bool leavesTile() const {
294  return _leavesTile;
295  }
296  bool castsSleep() const {
297  return _mAttr & MATTR_CASTS_SLEEP;
298  }
299  bool isForceOfNature() const {
300  return _mAttr & MATTR_FORCE_OF_NATURE;
301  }
302  int getDamage() const;
303  const Common::String &getCamouflageTile() const {
304  return _camouflageTile;
305  }
306  void setRandomRanged();
307  int setInitialHp(int hp = -1);
308 
314  bool specialAction();
315 
321  bool specialEffect();
322 
323  /* combat methods */
324  void act(CombatController *controller);
325 
329  virtual void addStatus(StatusType status);
330  void applyTileEffect(TileEffect effect);
331  virtual int getAttackBonus() const;
332  virtual int getDefense() const;
333  bool divide();
334  bool spawnOnDeath();
335  virtual CreatureStatus getState() const;
336  StatusType getStatus() const;
337  bool isAsleep() const;
338 
343  bool hideOrShow();
344 
345  Creature *nearestOpponent(int *dist, bool ranged);
346  virtual void putToSleep();
347  virtual void removeStatus(StatusType status);
348  virtual void setStatus(StatusType status);
349  virtual void wakeUp();
350 
360  virtual bool applyDamage(int damage, bool byplayer = true);
361  virtual bool dealDamage(Creature *m, int damage);
362 
363  // Properties
364 protected:
365  Common::String _name;
366  Common::String _rangedHitTile;
367  Common::String _rangedMissTile;
368  CreatureId _id;
369  Common::String _camouflageTile;
370  CreatureId _leader;
371  int _baseHp;
372  int _hp;
373  StatusList _status;
374  int _xp;
375  byte _ranged;
376  Common::String _worldRangedTile;
377  bool _leavesTile;
378  CreatureAttrib _mAttr;
379  CreatureMovementAttrib _movementAttr;
380  SlowedType _slowedType;
381  int _encounterSize;
382  byte _resists;
383  CreatureId _spawn;
384 };
385 
389 class CreatureMgr {
390 public:
391  static CreatureMgr *getInstance();
392 
393  void loadAll();
394 
399  Creature *getByTile(MapTile tile);
400 
406  Creature *getById(CreatureId id);
407 
413  Creature *getByName(Common::String name);
414 
418  Creature *randomForTile(const Tile *tile);
419 
423  Creature *randomForDungeon(int dnglevel);
424 
428  Creature *randomAmbushing();
429 
430 private:
431  CreatureMgr() {}
432 
433  // disallow assignments, copy contruction
434  CreatureMgr(const CreatureMgr &);
435  const CreatureMgr &operator=(const CreatureMgr &);
436 
437  static CreatureMgr *_instance;
438 
439  CreatureMap _creatures;
440 };
441 
442 bool isCreature(Object *punknown);
443 
444 #define creatureMgr (CreatureMgr::getInstance())
445 
446 } // End of namespace Ultima4
447 } // End of namespace Ultima
448 
449 #endif
Definition: vector.h:39
virtual void addStatus(StatusType status)
Definition: str.h:59
Definition: config.h:127
Definition: creature.h:389
Definition: detection.h:27
Definition: combat_controller.h:59
Definition: map_tile.h:34
Definition: creature.h:159
Definition: object.h:42
Creature(MapTile tile=MapTile(0))
Definition: tile.h:65
virtual bool applyDamage(int damage, bool byplayer=true)