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 "mm/xeen/sprites.h"
30 
31 namespace MM {
32 namespace Xeen {
33 
34 #define INV_ITEMS_TOTAL 9
35 
36 class XeenEngine;
37 class Character;
38 
39 enum ItemCategory {
40  CATEGORY_WEAPON = 0, CATEGORY_ARMOR = 1, CATEGORY_ACCESSORY = 2, CATEGORY_MISC = 3,
41  NUM_ITEM_CATEGORIES = 4
42 };
43 
44 enum AttributeCategory {
45  ATTR_MIGHT = 0, ATTR_INTELLECT = 1, ATTR_PERSONALITY = 2, ATTR_SPEED = 3,
46  ATTR_ACCURACY = 4, ATTR_LUCK = 5, ATTR_HIT_POINTS = 6, ATTR_SPELL_POINTS = 7,
47  ATTR_ARMOR_CLASS = 8, ATTR_THIEVERY = 9
48 };
49 
50 enum ElementalCategory {
51  ELEM_FIRE = 0, ELEM_ELECTRICITY = 1, ELEM_COLD = 2, ELEM_ACID_POISON = 3,
52  ELEM_ENERGY = 4, ELEM_MAGIC = 5
53 };
54 
55 enum EnchantmentType {
56  ENCHANTMENT_TYPE_ELEMENT = 1, ENCHANTMENT_TYPE_ATTR_BONUS = 2,
57  ENCHANTMENT_TYPE_MATERIAL = 3, ENCHANTMENT_TYPE_USABLE = 4
58 };
59 
60 enum WeaponId {
61  XEEN_SLAYER_SWORD = 34
62 };
63 
64 enum Effectiveness {
65  EFFECTIVE_NONE = 0, EFFECTIVE_DRAGON = 1, EFFECTIVE_UNDEAD = 2, EFFECTIVE_GOLEM = 3,
66  EFFECTIVE_INSECT = 4, EFFEctIVE_MONSTERS = 5, EFFECTIVE_ANIMAL = 6
67 };
68 
69 enum MakeItemReason {
70  MAKE_ITEM_ENCHANT_WEAPON = 1, MAKE_ITEM_ENCHANT_ARMOR = 2,
71  MAKE_ITEM_ENCHANT_ACCESSORY = 3, MAKE_ITEM_SPECIAL_EVENT = 12
72 };
73 
74 struct ItemState {
75  byte _counter : 6; // Stores charges for Misc items, and the effective against for weapons
76  bool _cursed : 1;
77  bool _broken : 1;
78 
82  ItemState() : _counter(0), _cursed(false), _broken(false) {
83  }
84 
88  void clear() {
89  _counter = 0;
90  _cursed = _broken = false;
91  }
92 
96  bool empty() const {
97  return !_counter && !_cursed && !_broken;
98  }
99 
104 
108  void operator=(byte val);
109 };
110 
111 class XeenItem {
112 public:
113  int _material;
114  uint _id;
115  ItemState _state;
116  int _frame;
117 public:
121  static const char *getItemName(ItemCategory category, uint id);
122 public:
126  XeenItem();
127 
131  void clear();
132 
136  bool empty() const {
137  return _id == 0;
138  }
139 
143  bool isBad() const {
144  return _state._cursed || _state._broken;
145  }
146 
150  bool isEquipped() const {
151  return _frame != 0;
152  }
153 
158 
162  ElementalCategory getElementalCategory() const;
163 
167  static ElementalCategory getElementalCategory(int material);
168 
172  AttributeCategory getAttributeCategory() const;
173 };
174 
175 class InventoryItems : public Common::Array<XeenItem> {
176 protected:
177  Character *_character;
178  ItemCategory _category;
179  const char **_names;
180 
181  XeenEngine *getVm();
182  void equipError(int itemIndex1, ItemCategory category1, int itemIndex2,
183  ItemCategory category2);
184 
188  virtual Common::String getAttributes(XeenItem &item, const Common::String &classes) = 0;
189 
193  void capitalizeItem(Common::String &name);
194 
198  const char *getMaeName(int material);
199 
200 public:
201  InventoryItems(Character *character, ItemCategory category);
202  virtual ~InventoryItems() {
203  }
204 
208  void clear();
209 
214 
220  bool passRestrictions(int itemId, bool suppressError = false) const;
221 
225  Common::String getName(int itemIndex);
226 
227  virtual Common::String getFullDescription(int itemIndex, int displayNum = 15) = 0;
228 
232  Common::String getIdentifiedDetails(int itemIndex);
233 
237  bool discardItem(int itemIndex);
238 
242  virtual void equipItem(int itemIndex) {
243  }
244 
248  void removeItem(int itemIndex);
249 
253  void sort();
254 
258  virtual void enchantItem(int itemIndex, int amount);
259 
263  bool isFull() const;
264 };
265 
266 class WeaponItems : public InventoryItems {
267 protected:
271  Common::String getAttributes(XeenItem &item, const Common::String &classes) override;
272 public:
273  WeaponItems(Character *character) : InventoryItems(character, CATEGORY_WEAPON) {
274  }
275  ~WeaponItems() override {
276  }
277 
281  void equipItem(int itemIndex) override;
282 
287  Common::String getFullDescription(int itemIndex, int displayNum) override;
288 
292  void enchantItem(int itemIndex, int amount) override;
293 
297  bool hasElderWeapon() const;
298 };
299 
300 class ArmorItems : public InventoryItems {
301 protected:
305  Common::String getAttributes(XeenItem &item, const Common::String &classes) override;
306 public:
307  ArmorItems(Character *character) : InventoryItems(character, CATEGORY_ARMOR) {
308  }
309  ~ArmorItems() override {
310  }
311 
315  void equipItem(int itemIndex) override;
316 
321  Common::String getFullDescription(int itemIndex, int displayNum) override;
322 
326  void enchantItem(int itemIndex, int amount) override;
327 };
328 
330 protected:
334  Common::String getAttributes(XeenItem &item, const Common::String &classes) override;
335 public:
336  AccessoryItems(Character *character) : InventoryItems(character, CATEGORY_ACCESSORY) {
337  }
338 
342  void equipItem(int itemIndex) override;
343 
348  Common::String getFullDescription(int itemIndex, int displayNum) override;
349 };
350 
351 class MiscItems : public InventoryItems {
352 protected:
356  Common::String getAttributes(XeenItem &item, const Common::String &classes) override;
357 public:
358  MiscItems(Character *character) : InventoryItems(character, CATEGORY_MISC) {
359  }
360  ~MiscItems() override {
361  }
362 
367  Common::String getFullDescription(int itemIndex, int displayNum) override;
368 };
369 
371 private:
372  Character *_owner;
373 public:
374  InventoryItemsGroup(Character *owner) : _owner(owner) {
375  }
376 
380  InventoryItems &operator[](ItemCategory category);
381 
385  const InventoryItems &operator[](ItemCategory category) const;
386 
390  void breakAllItems();
391 
395  void curseUncurse(bool curse);
396 
400  bool hasCursedItems() const;
401 };
402 
403 } // End of namespace Xeen
404 } // End of namespace MM
405 
406 #endif
void synchronize(Common::Serializer &s)
Definition: str.h:59
Definition: array.h:52
bool isBad() const
Definition: item.h:143
void clear()
Definition: item.h:88
Definition: item.h:329
Definition: item.h:351
Definition: item.h:175
Definition: serializer.h:79
Definition: xeen.h:93
Definition: item.h:74
void operator=(byte val)
bool empty() const
Definition: item.h:96
virtual void equipItem(int itemIndex)
Definition: item.h:242
Definition: character.h:106
Definition: detection.h:27
bool isEquipped() const
Definition: item.h:150
Definition: item.h:266
Definition: item.h:300
ItemState()
Definition: item.h:82
Definition: item.h:370
void sort(T first, T last, StrictWeakOrdering comp)
Definition: algorithm.h:349
bool empty() const
Definition: item.h:136
Definition: item.h:111