ScummVM API documentation
character.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 ULTIMA_SHARED_CORE_CHARACTER_H
23 #define ULTIMA_SHARED_CORE_CHARACTER_H
24 
25 #include "common/array.h"
26 #include "common/str.h"
27 #include "common/serializer.h"
28 #include "ultima/shared/core/named_item.h"
29 
30 namespace Ultima {
31 namespace Shared {
32 
33 enum Sex { SEX_MALE = 0, SEX_FEMALE = 1, SEX_OTHER = 2, SEX_YES_PLEASE = 2 };
34 
38 class Itemized {
39 public:
40  uint _quantity;
41 public:
45  Itemized() : _quantity(0) {}
46 
50  virtual ~Itemized() {}
51 
56  s.syncAsUint16LE(_quantity);
57  }
58 
62  virtual void changeQuantity(int delta) {
63  _quantity = (uint)CLIP((int)_quantity + delta, 0, 9999);
64  }
65 
70 
74  bool empty() const { return _quantity == 0; }
75 
79  bool decrQuantity() {
80  changeQuantity(-1);
81  return empty();
82  }
83 };
84 
88 class Weapon : public Itemized {
89 public:
90  Common::String _shortName, _longName;
91  uint _distance;
92 public:
96  Weapon() : Itemized(), _distance(0) {}
97 };
98 
102 class Armour : public Itemized {
103 public:
104  Common::String _name;
105 };
106 
110 class Spell : public Itemized, public NamedItem {
111 };
112 
113 template<class T>
114 class ItemArray : public Common::Array<T> {
115 public:
120  size_t itemsCount() const {
121  uint total = 0;
122  for (uint idx = 1; idx < this->size(); ++idx) {
123  if (!(*this)[idx]->empty())
124  ++total;
125  }
126 
127  return total;
128  }
129 
133  bool hasNothing() const {
134  return itemsCount() == 0;
135  }
136 };
137 
141 class Character {
142 public:
143  Common::String _name;
144  uint _race;
145  Sex _sex;
146  uint _class;
147 
148  uint _strength;
149  uint _agility;
150  uint _stamina;
151  uint _charisma;
152  uint _wisdom;
153  uint _intelligence;
154  uint _hitPoints;
155  uint _experience;
156  uint _food;
157  uint _coins;
158  int _equippedWeapon;
159  int _equippedArmour;
160  int _equippedSpell;
161  ItemArray<Weapon *> _weapons;
162  ItemArray<Armour *> _armour;
163  ItemArray<Spell *> _spells;
164 public:
168  Character() : _strength(0), _agility(0), _stamina(0), _charisma(0), _wisdom(0), _intelligence(0),
169  _hitPoints(0), _experience(0), _food(0), _coins(0), _equippedWeapon(0), _equippedArmour(0), _equippedSpell(0),
170  _race(0), _sex(SEX_MALE), _class(0) {}
171 
176 
180  bool isWeaponEquipped() const { return _equippedWeapon != 0; }
181 
185  bool isArmourEquipped() const { return _equippedArmour != 0; }
186 
190  bool isSpellEquipped() const { return _equippedSpell != 0; }
191 
195  Weapon *equippedWeapon() const { return _weapons[_equippedWeapon]; }
196 
200  Armour *equippedArmour() const { return _armour[_equippedArmour]; }
201 
205  Spell *equippedSpell() const { return _spells[_equippedSpell]; }
206 
210  void removeWeapon() { _equippedWeapon = 0; }
211 
215  void removeArmour() { _equippedArmour = 0; }
216 
220  void removeSpell() { _equippedSpell = 0; }
221 
225  uint getLevel() const { return (_experience / 1000) + 1; }
226 };
227 
228 } // End of namespace Shared
229 } // End of namespace Ultima
230 
231 #endif
Definition: character.h:38
virtual void changeQuantity(int delta)
Definition: character.h:62
Definition: str.h:59
Itemized()
Definition: character.h:45
void removeSpell()
Definition: character.h:220
Definition: array.h:52
void removeWeapon()
Definition: character.h:210
Spell * equippedSpell() const
Definition: character.h:205
Weapon()
Definition: character.h:96
Definition: character.h:114
uint getLevel() const
Definition: character.h:225
virtual ~Itemized()
Definition: character.h:50
bool isSpellEquipped() const
Definition: character.h:190
void synchronize(Common::Serializer &s)
Definition: character.h:55
size_t itemsCount() const
Definition: character.h:120
T CLIP(T v, T amin, T amax)
Definition: util.h:65
Definition: serializer.h:79
Weapon * equippedWeapon() const
Definition: character.h:195
bool decrQuantity()
Definition: character.h:79
Definition: detection.h:27
void removeArmour()
Definition: character.h:215
Character()
Definition: character.h:168
Definition: character.h:110
Armour * equippedArmour() const
Definition: character.h:200
bool empty() const
Definition: character.h:74
Definition: character.h:141
bool isWeaponEquipped() const
Definition: character.h:180
bool isArmourEquipped() const
Definition: character.h:185
Definition: character.h:88
Definition: named_item.h:33
Definition: character.h:102
void incrQuantity()
Definition: character.h:69
bool hasNothing() const
Definition: character.h:133