ScummVM API documentation
item.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 XEEN_ITEM_H
23 #define XEEN_ITEM_H
24 
25 #include "common/scummsys.h"
26 #include "common/array.h"
27 #include "common/rect.h"
28 #include "common/serializer.h"
29 #include "xeen/sprites.h"
30 
31 namespace Xeen {
32 
33 #define INV_ITEMS_TOTAL 9
34 
35 class XeenEngine;
36 class Character;
37 
38 enum ItemCategory {
39  CATEGORY_WEAPON = 0, CATEGORY_ARMOR = 1, CATEGORY_ACCESSORY = 2, CATEGORY_MISC = 3,
40  NUM_ITEM_CATEGORIES = 4
41 };
42 
43 enum AttributeCategory {
44  ATTR_MIGHT = 0, ATTR_INTELLECT = 1, ATTR_PERSONALITY = 2, ATTR_SPEED = 3,
45  ATTR_ACCURACY = 4, ATTR_LUCK = 5, ATTR_HIT_POINTS = 6, ATTR_SPELL_POINTS = 7,
46  ATTR_ARMOR_CLASS = 8, ATTR_THIEVERY = 9
47 };
48 
49 enum ElementalCategory {
50  ELEM_FIRE = 0, ELEM_ELECTRICITY = 1, ELEM_COLD = 2, ELEM_ACID_POISON = 3,
51  ELEM_ENERGY = 4, ELEM_MAGIC = 5
52 };
53 
54 enum WeaponId {
55  XEEN_SLAYER_SWORD = 34
56 };
57 
58 enum Effectiveness {
59  EFFECTIVE_NONE = 0, EFFECTIVE_DRAGON = 1, EFFECTIVE_UNDEAD = 2, EFFECTIVE_GOLEM = 3,
60  EFFECTIVE_INSECT = 4, EFFEctIVE_MONSTERS = 5, EFFECTIVE_ANIMAL = 6
61 };
62 
63 struct ItemState {
64  byte _counter : 6; // Stores charges for Misc items, and the effective against for weapons
65  bool _cursed : 1;
66  bool _broken : 1;
67 
71  ItemState() : _counter(0), _cursed(false), _broken(false) {}
72 
76  void clear() {
77  _counter = 0;
78  _cursed = _broken = false;
79  }
80 
84  bool empty() const { return !_counter && !_cursed && !_broken; }
85 
90 
94  void operator=(byte val);
95 };
96 
97 class XeenItem {
98 public:
99  int _material;
100  uint _id;
101  ItemState _state;
102  int _frame;
103 public:
107  static const char *getItemName(ItemCategory category, uint id);
108 public:
112  XeenItem();
113 
117  void clear();
118 
122  bool empty() const { return _id == 0; }
123 
127  bool isBad() const { return _state._cursed || _state._broken; }
128 
132  bool isEquipped() const { return _frame != 0; }
133 
138 
142  ElementalCategory getElementalCategory() const;
143 
147  static ElementalCategory getElementalCategory(int material);
148 
152  AttributeCategory getAttributeCategory() const;
153 };
154 
155 class InventoryItems : public Common::Array<XeenItem> {
156 protected:
157  Character *_character;
158  ItemCategory _category;
159  const char **_names;
160 
161  XeenEngine *getVm();
162  void equipError(int itemIndex1, ItemCategory category1, int itemIndex2,
163  ItemCategory category2);
164 
168  virtual Common::String getAttributes(XeenItem &item, const Common::String &classes) = 0;
169 
173  void capitalizeItem(Common::String &name);
174 
178  const char *getMaeName(int material);
179 
180 public:
181  InventoryItems(Character *character, ItemCategory category);
182  virtual ~InventoryItems() {}
183 
187  void clear();
188 
193 
199  bool passRestrictions(int itemId, bool suppressError = false) const;
200 
204  Common::String getName(int itemIndex);
205 
206  virtual Common::String getFullDescription(int itemIndex, int displayNum = 15) = 0;
207 
211  Common::String getIdentifiedDetails(int itemIndex);
212 
216  bool discardItem(int itemIndex);
217 
221  virtual void equipItem(int itemIndex) {}
222 
226  void removeItem(int itemIndex);
227 
231  void sort();
232 
236  virtual void enchantItem(int itemIndex, int amount);
237 
241  bool isFull() const;
242 };
243 
245 protected:
249  Common::String getAttributes(XeenItem &item, const Common::String &classes) override;
250 public:
251  WeaponItems(Character *character) : InventoryItems(character, CATEGORY_WEAPON) {}
252  ~WeaponItems() override {}
253 
257  void equipItem(int itemIndex) override;
258 
263  Common::String getFullDescription(int itemIndex, int displayNum) override;
264 
268  void enchantItem(int itemIndex, int amount) override;
269 
273  bool hasElderWeapon() const;
274 };
275 
276 class ArmorItems : public InventoryItems {
277 protected:
281  Common::String getAttributes(XeenItem &item, const Common::String &classes) override;
282 public:
283  ArmorItems(Character *character) : InventoryItems(character, CATEGORY_ARMOR) {}
284  ~ArmorItems() override {}
285 
289  void equipItem(int itemIndex) override;
290 
295  Common::String getFullDescription(int itemIndex, int displayNum) override;
296 
300  void enchantItem(int itemIndex, int amount) override;
301 };
302 
304 protected:
308  Common::String getAttributes(XeenItem &item, const Common::String &classes) override;
309 public:
310  AccessoryItems(Character *character) : InventoryItems(character, CATEGORY_ACCESSORY) {}
311 
315  void equipItem(int itemIndex) override;
316 
321  Common::String getFullDescription(int itemIndex, int displayNum) override;
322 };
323 
324 class MiscItems : public InventoryItems {
325 protected:
329  Common::String getAttributes(XeenItem &item, const Common::String &classes) override;
330 public:
331  MiscItems(Character *character) : InventoryItems(character, CATEGORY_MISC) {}
332  ~MiscItems() override {}
333 
338  Common::String getFullDescription(int itemIndex, int displayNum) override;
339 };
340 
342 private:
343  Character *_owner;
344 public:
345  InventoryItemsGroup(Character *owner) : _owner(owner) {}
346 
350  InventoryItems &operator[](ItemCategory category);
351 
355  const InventoryItems &operator[](ItemCategory category) const;
356 
360  void breakAllItems();
361 
365  void curseUncurse(bool curse);
366 
370  bool hasCursedItems() const;
371 };
372 
373 } // End of namespace Xeen
374 
375 #endif /* XEEN_CHARACTER_H */
Definition: item.h:97
Definition: str.h:59
bool isBad() const
Definition: item.h:127
ItemState()
Definition: item.h:71
void operator=(byte val)
Definition: array.h:52
virtual void equipItem(int itemIndex)
Definition: item.h:221
void synchronize(Common::Serializer &s)
Definition: item.h:324
Definition: serializer.h:79
void clear()
Definition: item.h:76
Definition: item.h:155
bool isEquipped() const
Definition: item.h:132
Definition: item.h:244
Definition: item.h:341
bool empty() const
Definition: item.h:122
Definition: xeen.h:100
Definition: item.h:63
Definition: character.h:101
bool empty() const
Definition: item.h:84
Definition: item.h:303
void sort(T first, T last, StrictWeakOrdering comp)
Definition: algorithm.h:286
Definition: character.h:33
Definition: item.h:276