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
30namespace Ultima {
31namespace Shared {
32
33enum Sex { SEX_MALE = 0, SEX_FEMALE = 1, SEX_OTHER = 2, SEX_YES_PLEASE = 2 };
34
38class Itemized {
39public:
40 uint _quantity;
41public:
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() {
81 return empty();
82 }
83};
84
88class Weapon : public Itemized {
89public:
90 Common::String _shortName, _longName;
91 uint _distance;
92public:
96 Weapon() : Itemized(), _distance(0) {}
97};
98
102class Armour : public Itemized {
103public:
104 Common::String _name;
105};
106
110class Spell : public Itemized, public NamedItem {
111};
112
113template<class T>
114class ItemArray : public Common::Array<T> {
115public:
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
142public:
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;
164public:
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: array.h:52
size_type size() const
Definition: array.h:316
Definition: serializer.h:80
Definition: str.h:59
Definition: character.h:102
Definition: character.h:141
bool isSpellEquipped() const
Definition: character.h:190
Weapon * equippedWeapon() const
Definition: character.h:195
void removeArmour()
Definition: character.h:215
Spell * equippedSpell() const
Definition: character.h:205
bool isArmourEquipped() const
Definition: character.h:185
void removeWeapon()
Definition: character.h:210
void removeSpell()
Definition: character.h:220
uint getLevel() const
Definition: character.h:225
Armour * equippedArmour() const
Definition: character.h:200
Character()
Definition: character.h:168
void synchronize(Common::Serializer &s)
bool isWeaponEquipped() const
Definition: character.h:180
Definition: character.h:114
size_t itemsCount() const
Definition: character.h:120
bool hasNothing() const
Definition: character.h:133
Definition: character.h:38
void synchronize(Common::Serializer &s)
Definition: character.h:55
bool decrQuantity()
Definition: character.h:79
void incrQuantity()
Definition: character.h:69
bool empty() const
Definition: character.h:74
Itemized()
Definition: character.h:45
virtual void changeQuantity(int delta)
Definition: character.h:62
virtual ~Itemized()
Definition: character.h:50
Definition: named_item.h:33
Definition: character.h:110
Definition: character.h:88
Weapon()
Definition: character.h:96
T CLIP(T v, T amin, T amax)
Definition: util.h:69