ScummVM API documentation
player.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_PLAYER_H
23 #define ULTIMA4_GAME_PLAYER_H
24 
25 #include "ultima/ultima4/game/creature.h"
26 #include "ultima/ultima4/map/direction.h"
27 #include "ultima/ultima4/core/observable.h"
28 #include "ultima/ultima4/filesys/savegame.h"
29 #include "ultima/ultima4/game/script.h"
30 #include "ultima/ultima4/map/tile.h"
31 #include "ultima/ultima4/core/types.h"
32 
33 namespace Ultima {
34 namespace Ultima4 {
35 
36 class Armor;
37 class Party;
38 class Weapon;
39 
40 typedef Std::vector<class PartyMember *> PartyMemberVector;
41 
42 #define ALL_PLAYERS -1
43 
44 enum KarmaAction {
45  KA_FOUND_ITEM,
46  KA_STOLE_CHEST,
47  KA_GAVE_TO_BEGGAR,
48  KA_GAVE_ALL_TO_BEGGAR,
49  KA_BRAGGED,
50  KA_HUMBLE,
51  KA_HAWKWIND,
52  KA_MEDITATION,
53  KA_BAD_MANTRA,
54  KA_ATTACKED_GOOD,
55  KA_FLED_EVIL,
56  KA_FLED_GOOD,
57  KA_HEALTHY_FLED_EVIL,
58  KA_KILLED_EVIL,
59  KA_SPARED_GOOD,
60  KA_DONATED_BLOOD,
61  KA_DIDNT_DONATE_BLOOD,
62  KA_CHEAT_REAGENTS,
63  KA_DIDNT_CHEAT_REAGENTS,
64  KA_USED_SKULL,
65  KA_DESTROYED_SKULL
66 };
67 
68 enum HealType {
69  HT_NONE,
70  HT_CURE,
71  HT_FULLHEAL,
72  HT_RESURRECT,
73  HT_HEAL,
74  HT_CAMPHEAL,
75  HT_INNHEAL
76 };
77 
78 enum InventoryItem {
79  INV_NONE,
80  INV_WEAPON,
81  INV_ARMOR,
82  INV_FOOD,
83  INV_REAGENT,
84  INV_GUILDITEM,
85  INV_HORSE
86 };
87 
88 enum CannotJoinError {
89  JOIN_SUCCEEDED,
90  JOIN_NOT_EXPERIENCED,
91  JOIN_NOT_VIRTUOUS
92 };
93 
94 enum EquipError {
95  EQUIP_SUCCEEDED,
96  EQUIP_NONE_LEFT,
97  EQUIP_CLASS_RESTRICTED
98 };
99 
103 class PartyMember : public Creature, public Script::Provider {
104 public:
106  virtual ~PartyMember();
107 
111  void notifyOfChange();
112 
117 
118  // Accessor methods
119  int getHp() const override;
120  int getMaxHp() const {
121  return _player->_hpMax;
122  }
123  int getExp() const {
124  return _player->_xp;
125  }
126  int getStr() const {
127  return _player->_str;
128  }
129  int getDex() const {
130  return _player->_dex;
131  }
132  int getInt() const {
133  return _player->_intel;
134  }
135  int getMp() const {
136  return _player->_mp;
137  }
138 
143  int getMaxMp() const;
144 
145  const Weapon *getWeapon() const;
146  const Armor *getArmor() const;
147  Common::String getName() const override;
148  SexType getSex() const;
149  ClassType getClass() const;
150  CreatureStatus getState() const override;
151 
155  int getRealLevel() const;
156 
161  int getMaxLevel() const;
162 
166  void addStatus(StatusType status) override;
167 
171  void adjustMp(int pts);
172 
176  void advanceLevel();
177 
181  void applyEffect(TileEffect effect);
182 
186  void awardXp(int xp);
187 
191  bool heal(HealType type);
192 
196  void removeStatus(StatusType status) override;
197 
198  void setHp(int hp) override;
199  void setMp(int mp);
200  EquipError setArmor(const Armor *a);
201  EquipError setWeapon(const Weapon *w);
202 
211  bool applyDamage(int damage, bool byplayer = false) override;
212  int getAttackBonus() const override;
213  int getDefense() const override;
214  bool dealDamage(Creature *m, int damage) override;
215 
219  int getDamage();
220 
225  const Common::String &getHitTile() const override;
226 
231  const Common::String &getMissTile() const override;
232  bool isDead();
233  bool isDisabled();
234 
240  int loseWeapon();
241 
245  void putToSleep() override;
246 
250  void wakeUp() override;
251 
252 protected:
253  static MapTile tileForClass(int klass);
254 
255  SaveGamePlayerRecord *_player;
256  class Party *_party;
257 };
258 
262 class PartyEvent {
263 public:
264  enum Type {
265  GENERIC,
266  LOST_EIGHTH,
267  ADVANCED_LEVEL,
268  STARVING,
269  TRANSPORT_CHANGED,
270  PLAYER_KILLED,
271  ACTIVE_PLAYER_CHANGED,
272  MEMBER_JOINED,
273  PARTY_REVIVED,
274  INVENTORY_ADDED
275  };
276 
277  PartyEvent(Type type, PartyMember *partyMember) : _type(type), _player(partyMember) { }
278 
279  Type _type;
280  PartyMember *_player;
281 };
282 
283 typedef Std::vector<PartyMember *> PartyMemberVector;
284 
285 class Party : public Observable<Party *, PartyEvent &>, public Script::Provider {
286  friend class PartyMember;
287 public:
288  Party(SaveGame *saveGame);
289  virtual ~Party();
290 
294  void notifyOfChange(PartyMember *partyMember = 0, PartyEvent::Type = PartyEvent::GENERIC);
295 
296  // Used to translate script values into something useful
298 
299  void adjustFood(int food);
300  void adjustGold(int gold);
301 
307  void adjustKarma(KarmaAction action);
308 
312  void applyEffect(TileEffect effect);
313 
317  bool attemptElevation(Virtue virtue);
318 
322  void burnTorch(int turns = 1);
323 
327  bool canEnterShrine(Virtue virtue);
328 
332  bool canPersonJoin(Common::String name, Virtue *v);
333 
337  void damageShip(uint pts);
338 
343  bool donate(int quantity);
344 
348  void endTurn();
349 
353  int getChest();
354 
358  int getTorchDuration() const;
359 
363  void healShip(uint pts);
364 
368  bool isFlying() const;
369 
373  bool isImmobilized();
374 
378  bool isDead();
379 
384  bool isPersonJoined(Common::String name);
385 
390  CannotJoinError join(Common::String name);
391 
395  bool lightTorch(int duration = 100, bool loseTorch = true);
396 
400  void quenchTorch();
401 
405  void reviveParty();
406  MapTile getTransport() const;
407  void setTransport(MapTile transport);
408  void setShipHull(int str);
409 
410  Direction getDirection() const;
411  void setDirection(Direction dir);
412 
413  void adjustReagent(int reagent, int amt);
414  int getReagent(int reagent) const;
415  short *getReagentPtr(int reagent) const;
416 
417  void setActivePlayer(int p);
418  int getActivePlayer() const;
419 
420  void swapPlayers(int p1, int p2);
421 
425  int size() const;
426 
430  PartyMember *member(int index) const;
431 
432 private:
433  void syncMembers();
434  PartyMemberVector _members;
435  SaveGame *_saveGame;
436  MapTile _transport;
437  int _torchDuration;
438  int _activePlayer;
439 #ifdef IOS_ULTIMA4
440  friend void U4IOS::syncPartyMembersWithSaveGame();
441 #endif
442 };
443 
444 bool isPartyMember(Object *punknown);
445 
446 } // End of namespace Ultima4
447 } // End of namespace Ultima
448 
449 #endif
const Common::String & getHitTile() const override
Definition: vector.h:39
bool applyDamage(int damage, bool byplayer=false) override
Definition: savegame.h:270
Definition: str.h:59
Definition: savegame.h:193
Common::String translate(Std::vector< Common::String > &parts) override
void applyEffect(TileEffect effect)
Definition: player.h:103
void addStatus(StatusType status) override
const Common::String & getMissTile() const override
Definition: script.h:55
bool heal(HealType type)
Definition: player.h:262
void removeStatus(StatusType status) override
Definition: detection.h:27
Definition: player.h:285
Definition: map_tile.h:34
Definition: creature.h:159
Definition: object.h:42
Definition: observable.h:45
Definition: armor.h:35
Definition: weapon.h:34