ManaPlus
iteminfo.h
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2004-2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2019 The ManaPlus Developers
6  * Copyright (C) 2019-2021 Andrei Karas
7  *
8  * This file is part of The ManaPlus Client.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #ifndef RESOURCES_ITEMINFO_H
25 #define RESOURCES_ITEMINFO_H
26 
27 #include "enums/being/gender.h"
28 
30 
32 
33 #include "resources/cursors.h"
35 #include "resources/missileinfo.h"
36 #include "resources/soundinfo.h"
37 
39 
40 #include "utils/cast.h"
41 #include "utils/intmap.h"
42 
43 struct ItemMenuItem;
44 
45 // sprite, <itemfrom, itemto>
46 typedef std::map<int, IntMap> SpriteToItemMap;
47 typedef SpriteToItemMap::const_iterator SpriteToItemMapCIter;
48 
54 {
55  public:
59  ItemInfo();
60 
62 
63  ~ItemInfo();
64 
65  void setId(const int id) noexcept2
66  { mId = id; }
67 
69  { return mId; }
70 
71  void setName(const std::string &name) noexcept2
72  { mName = name; }
73 
74  const std::string &getName() const noexcept2 A_WARN_UNUSED
75  { return mName; }
76 
77  const std::string getName(const ItemColor color)
78  const A_WARN_UNUSED;
79 
80  void setNameEn(const std::string &name) noexcept2
81  { mNameEn = name; }
82 
83  const std::string &getNameEn() const noexcept2 A_WARN_UNUSED
84  { return mNameEn; }
85 
86  const std::string getNameEn(const ItemColor color)
87  const A_WARN_UNUSED;
88 
89  const std::string getLink() const A_WARN_UNUSED;
90 
91  void setDisplay(const SpriteDisplay &display) noexcept2
92  { mDisplay = display; }
93 
95  { return mDisplay; }
96 
97  void setDescription(const std::string &description) noexcept2
98  { mDescription = description; }
99 
100  const std::string &getDescription() const noexcept2 A_WARN_UNUSED
101  { return mDescription; }
102 
103  const std::string getDescription(const ItemColor color)
104  const A_WARN_UNUSED;
105 
106  void setEffect(const std::string &effect) noexcept2
107  { mEffect = effect; }
108 
109  const std::string &getEffect() const noexcept2 A_WARN_UNUSED
110  { return mEffect; }
111 
112  void setType(const ItemDbTypeT type) noexcept2
113  { mType = type; }
114 
115  void setUseButton(const std::string &str) noexcept2
116  { mUseButton = str; }
117 
118  const std::string &getUseButton() const noexcept2 A_WARN_UNUSED
119  { return mUseButton; }
120 
121  void setUseButton2(const std::string &str) noexcept2
122  { mUseButton2 = str; }
123 
124  const std::string &getUseButton2() const noexcept2 A_WARN_UNUSED
125  { return mUseButton2; }
126 
128  { return mType; }
129 
130  void setWeight(const int weight) noexcept2
131  { mWeight = weight; }
132 
134  { return mWeight; }
135 
137  { return mView; }
138 
139  void setView(const int view) noexcept2
140  { mView = view; }
141 
142  void setSprite(const std::string &animationFile,
143  const GenderT gender, const int race);
144 
145  const std::string &getSprite(const GenderT gender,
146  const BeingTypeId race)
147  const A_WARN_UNUSED;
148 
149  void setAttackAction(const std::string &attackAction);
150 
151  void setSkyAttackAction(const std::string &attackAction);
152 
153  void setWaterAttackAction(const std::string &attackAction);
154 
155  void setRideAttackAction(const std::string &attackAction);
156 
157  // Handlers for seting and getting the string
158  // used for particles when attacking
159  void setMissileParticleFile(const std::string &s) noexcept2
160  { mMissile.particle = s; }
161 
163  { return mMissile; }
164 
166  { return mMissile; }
167 
168  void setHitEffectId(const int s) noexcept2
169  { mHitEffectId = s; }
170 
172  { return mHitEffectId; }
173 
175  { mCriticalHitEffectId = s; }
176 
178  { return mCriticalHitEffectId; }
179 
180  void setMissEffectId(const int s) noexcept2
181  { mMissEffectId = s; }
182 
184  { return mMissEffectId; }
185 
186  const std::string &getAttackAction() const noexcept2 A_WARN_UNUSED
187  { return mAttackAction; }
188 
189  const std::string &getSkyAttackAction() const noexcept2 A_WARN_UNUSED
190  { return mSkyAttackAction; }
191 
192  const std::string &getWaterAttackAction() const noexcept2 A_WARN_UNUSED
193  { return mWaterAttackAction; }
194 
195  const std::string &getRideAttackAction() const noexcept2 A_WARN_UNUSED
196  { return mRideAttackAction; }
197 
199  { return mAttackRange; }
200 
201  void setAttackRange(const int r) noexcept2
202  { mAttackRange = r; }
203 
204  void addSound(const ItemSoundEvent::Type event,
205  const std::string &filename,
206  const int delay);
207 
208  const SoundInfo &getSound(const ItemSoundEvent::Type event)
209  const A_WARN_UNUSED;
210 
211  int getDrawBefore(const int direction) const A_WARN_UNUSED;
212 
213  void setDrawBefore(const int direction, const int n);
214 
215  int getDrawAfter(const int direction) const A_WARN_UNUSED;
216 
217  void setDrawAfter(const int direction, const int n);
218 
219  int getDrawPriority(const int direction) const A_WARN_UNUSED;
220 
221  void setDrawPriority(const int direction, const int n);
222 
224  { return mTags; }
225 
226  void addTag(const int tag)
227  { mTags[tag] = 1; }
228 
230  { mIsRemoveSprites = true; }
231 
233  { return mIsRemoveSprites; }
234 
235  void setMaxFloorOffsetX(const int i) noexcept2
236  { maxFloorOffsetX = i; }
237 
238  void setMaxFloorOffsetY(const int i) noexcept2
239  { maxFloorOffsetY = i; }
240 
242  { return maxFloorOffsetX; }
243 
245  { return maxFloorOffsetY; }
246 
247  bool isRemoveItemId(int id) const A_WARN_UNUSED;
248 
249  void setCardColor(const ItemColor color) noexcept2
250  { mCardColor = color; }
251 
253  { return mCardColor; }
254 
256 
257  IntMap *addReplaceSprite(const int sprite,
258  const int direction);
259 
261  const A_WARN_UNUSED;
262 
263  std::string getDyeColorsString(const ItemColor color)
264  const A_WARN_UNUSED;
265 
266  std::string getDyeIconColorsString(const ItemColor color)
267  const A_WARN_UNUSED;
268 
269  void setColorsList(const std::string &name);
270 
271  void setIconColorsList(const std::string &name);
272 
274  { return !mColorsListName.empty(); }
275 
277  { return !mIconColorsListName.empty(); }
278 
280  { return mColorsListName; }
281 
283  { return mIconColorsListName; }
284 
285  const std::string replaceColors(std::string str,
286  const ItemColor color)
287  const A_WARN_UNUSED;
288 
289  void setPickupCursor(const std::string &cursor)
290  { return setPickupCursor(Cursors::stringToCursor(cursor)); }
291 
292  void setPickupCursor(const CursorT &cursor) noexcept2
293  { mPickupCursor = cursor; }
294 
296  { return mPickupCursor; }
297 
298  void setProtected(const bool b) noexcept2
299  { mProtected = b; }
300 
302  { return mProtected; }
303 
305  { return mColorsList != nullptr ? CAST_S32(mColorsList->size()) : 0; }
306 
308  {
309  return mIconColorsList != nullptr ?
310  CAST_S32(mIconColorsList->size()) : 0;
311  }
312 
313  std::string getColorName(const ItemColor idx) const;
314  std::string getColor(const ItemColor idx) const;
315 
316  std::string getIconColorName(const ItemColor idx) const;
317  std::string getIconColor(const ItemColor idx) const;
318 
319  STD_VECTOR<ItemMenuItem> &getInventoryMenu()
320  { return mInventoryMenu; }
321  STD_VECTOR<ItemMenuItem> &getStorageMenu()
322  { return mStorageMenu; }
323  STD_VECTOR<ItemMenuItem> &getCartMenu()
324  { return mCartMenu; }
325 
326  const STD_VECTOR<ItemMenuItem> &getInventoryMenuConst() const A_CONST
327  { return mInventoryMenu; }
328  const STD_VECTOR<ItemMenuItem> &getStorageMenuConst() const A_CONST
329  { return mStorageMenu; }
330  const STD_VECTOR<ItemMenuItem> &getCartMenuConst() const A_CONST
331  { return mCartMenu; }
332 
333  int mDrawBefore[10];
334  int mDrawAfter[10];
335  int mDrawPriority[10];
336 
337  private:
338  static void setSpriteOrder(int *const ptr,
339  const int direction,
340  const int n,
341  const int def) A_NONNULL(1);
342 
345  std::string mName;
346  std::string mNameEn;
347  std::string mDescription;
348  std::string mEffect;
349  std::string mUseButton;
350  std::string mUseButton2;
352  int mWeight;
353  int mView;
354  int mId;
356  // sprite, <itemfrom, itemto> [direction]
358 
359  STD_VECTOR<SpriteToItemMap*> mSpriteToItemReplaceList;
360 
361  // Equipment related members.
366  std::string mAttackAction;
367  std::string mSkyAttackAction;
368  std::string mWaterAttackAction;
369  std::string mRideAttackAction;
372  // Particle to be shown when weapon attacks
373  std::string mMissileParticle;
374 
376  std::map <int, std::string> mAnimationFiles;
377 
379  std::map <ItemSoundEvent::Type, SoundInfoVect> mSounds;
380  std::map <int, int> mTags;
381  const std::map <ItemColor, ItemColorData> *mColorsList;
382  const std::map <ItemColor, ItemColorData> *mIconColorsList;
383  STD_VECTOR<ItemMenuItem> mInventoryMenu;
384  STD_VECTOR<ItemMenuItem> mStorageMenu;
385  STD_VECTOR<ItemMenuItem> mCartMenu;
386  std::string mColorsListName;
387  std::string mIconColorsListName;
396 };
397 
398 #endif // RESOURCES_ITEMINFO_H
int BeingTypeId
Definition: beingtypeid.h:30
#define CAST_S32
Definition: cast.h:30
static const uint8_t directions[]
std::string mName
Definition: iteminfo.h:345
bool isHaveColors() const
Definition: iteminfo.h:273
int mWeight
Definition: iteminfo.h:352
const std::string & getSprite(const GenderT gender, const BeingTypeId race) const
Definition: iteminfo.cpp:100
const std::string & getDescription() const
Definition: iteminfo.h:100
bool isHaveIconColors() const
Definition: iteminfo.h:276
std::string getColor(const ItemColor idx) const
Definition: iteminfo.cpp:430
MissileInfo mMissile
Definition: iteminfo.h:344
ItemColor mCardColor
Definition: iteminfo.h:388
void setProtected(const bool b)
Definition: iteminfo.h:298
int getId() const
Definition: iteminfo.h:68
int getColorsSize() const
Definition: iteminfo.h:304
int mDrawPriority[10]
Definition: iteminfo.h:335
void setMissEffectId(const int s)
Definition: iteminfo.h:180
std::string getColorsListName() const
Definition: iteminfo.h:279
const std::string & getWaterAttackAction() const
Definition: iteminfo.h:192
const std::string & getName() const
Definition: iteminfo.h:74
void setRemoveSprites()
Definition: iteminfo.h:229
int mAttackRange
Definition: iteminfo.h:370
void setHitEffectId(const int s)
Definition: iteminfo.h:168
const std::string & getUseButton() const
Definition: iteminfo.h:118
void setDescription(const std::string &description)
Definition: iteminfo.h:97
int mDrawBefore[10]
Definition: iteminfo.h:333
int mHitEffectId
Definition: iteminfo.h:389
MissileInfo & getMissile()
Definition: iteminfo.h:162
void setPickupCursor(const std::string &cursor)
Definition: iteminfo.h:289
ItemColor getCardColor() const
Definition: iteminfo.h:252
std::string getIconColorName(const ItemColor idx) const
Definition: iteminfo.cpp:447
void setRideAttackAction(const std::string &attackAction)
Definition: iteminfo.cpp:145
int getDrawAfter(const int direction) const
Definition: iteminfo.cpp:392
int maxFloorOffsetY
Definition: iteminfo.h:393
void setSkyAttackAction(const std::string &attackAction)
Definition: iteminfo.cpp:129
int getWeight() const
Definition: iteminfo.h:133
int getCriticalHitEffectId() const
Definition: iteminfo.h:177
std::string getDyeColorsString(const ItemColor color) const
Definition: iteminfo.cpp:227
bool isRemoveSprites() const
Definition: iteminfo.h:232
std::string mMissileParticle
Definition: iteminfo.h:373
int getDrawBefore(const int direction) const
Definition: iteminfo.cpp:385
const std::string & getNameEn() const
Definition: iteminfo.h:83
const std::string & getUseButton2() const
Definition: iteminfo.h:124
std::string getColorName(const ItemColor idx) const
Definition: iteminfo.cpp:413
ItemDbTypeT getType() const
Definition: iteminfo.h:127
std::string mRideAttackAction
Definition: iteminfo.h:369
const std::vector< ItemMenuItem > & getStorageMenuConst() const A_CONST
Definition: iteminfo.h:328
void setNameEn(const std::string &name)
Definition: iteminfo.h:80
IntMap * addReplaceSprite(const int sprite, const int direction)
Definition: iteminfo.cpp:174
std::string getIconColor(const ItemColor idx) const
Definition: iteminfo.cpp:464
int mId
Definition: iteminfo.h:354
int getMaxFloorOffsetY() const
Definition: iteminfo.h:244
~ItemInfo()
Definition: iteminfo.cpp:92
std::string mIconColorsListName
Definition: iteminfo.h:387
void setCriticalHitEffectId(const int s)
Definition: iteminfo.h:174
SpriteDisplay mDisplay
Definition: iteminfo.h:343
const std::vector< ItemMenuItem > & getCartMenuConst() const A_CONST
Definition: iteminfo.h:330
void setEffect(const std::string &effect)
Definition: iteminfo.h:106
int mView
Definition: iteminfo.h:353
std::string mUseButton
Definition: iteminfo.h:349
SpriteToItemMap * mSpriteToItemReplaceMap[10]
Definition: iteminfo.h:357
const SpriteDisplay & getDisplay() const
Definition: iteminfo.h:94
const std::vector< ItemMenuItem > & getInventoryMenuConst() const A_CONST
Definition: iteminfo.h:326
void setAttackRange(const int r)
Definition: iteminfo.h:201
std::string mDescription
Definition: iteminfo.h:347
CursorT mPickupCursor
Definition: iteminfo.h:394
int getMissEffectId() const
Definition: iteminfo.h:183
const MissileInfo & getMissileConst() const
Definition: iteminfo.h:165
const SoundInfo & getSound(const ItemSoundEvent::Type event) const
Definition: iteminfo.cpp:161
void setIconColorsList(const std::string &name)
Definition: iteminfo.cpp:213
std::vector< ItemMenuItem > mStorageMenu
Definition: iteminfo.h:384
int getAttackRange() const
Definition: iteminfo.h:198
const std::string & getEffect() const
Definition: iteminfo.h:109
int getDrawPriority(const int direction) const
Definition: iteminfo.cpp:399
void setUseButton2(const std::string &str)
Definition: iteminfo.h:121
void setColorsList(const std::string &name)
Definition: iteminfo.cpp:199
void setPickupCursor(const CursorT &cursor)
Definition: iteminfo.h:292
int mMissEffectId
Definition: iteminfo.h:391
const std::map< ItemColor, ItemColorData > * mColorsList
Definition: iteminfo.h:381
void setSprite(const std::string &animationFile, const GenderT gender, const int race)
Definition: iteminfo.cpp:406
int mCriticalHitEffectId
Definition: iteminfo.h:390
int mDrawAfter[10]
Definition: iteminfo.h:334
std::vector< ItemMenuItem > & getCartMenu()
Definition: iteminfo.h:323
std::vector< ItemMenuItem > & getStorageMenu()
Definition: iteminfo.h:321
void setMaxFloorOffsetX(const int i)
Definition: iteminfo.h:235
void setMaxFloorOffsetY(const int i)
Definition: iteminfo.h:238
std::string getIconColorsListName() const
Definition: iteminfo.h:282
std::vector< ItemMenuItem > mInventoryMenu
Definition: iteminfo.h:383
void setDrawAfter(const int direction, const int n)
Definition: iteminfo.cpp:375
std::map< int, std::string > mAnimationFiles
Definition: iteminfo.h:376
std::vector< ItemMenuItem > & getInventoryMenu()
Definition: iteminfo.h:319
std::map< ItemSoundEvent::Type, SoundInfoVect > mSounds
Definition: iteminfo.h:379
const std::map< ItemColor, ItemColorData > * mIconColorsList
Definition: iteminfo.h:382
ItemDbTypeT mType
Definition: iteminfo.h:351
void setAttackAction(const std::string &attackAction)
Definition: iteminfo.cpp:121
const std::string getLink() const
Definition: iteminfo.cpp:481
int getReplaceToSpriteId(int id) const
std::string mWaterAttackAction
Definition: iteminfo.h:368
const std::string & getRideAttackAction() const
Definition: iteminfo.h:195
void addSound(const ItemSoundEvent::Type event, const std::string &filename, const int delay)
Definition: iteminfo.cpp:153
const SpriteToItemMap * getSpriteToItemReplaceMap(const int directions) const
Definition: iteminfo.cpp:293
void setDrawPriority(const int direction, const int n)
Definition: iteminfo.cpp:380
std::string mNameEn
Definition: iteminfo.h:346
bool isProtected() const
Definition: iteminfo.h:301
void setCardColor(const ItemColor color)
Definition: iteminfo.h:249
int getHitEffectId() const
Definition: iteminfo.h:171
void addTag(const int tag)
Definition: iteminfo.h:226
int getIconColorsSize() const
Definition: iteminfo.h:307
void setMissileParticleFile(const std::string &s)
Definition: iteminfo.h:159
void setDisplay(const SpriteDisplay &display)
Definition: iteminfo.h:91
std::string mColorsListName
Definition: iteminfo.h:386
void setId(const int id)
Definition: iteminfo.h:65
const std::string & getAttackAction() const
Definition: iteminfo.h:186
static void setSpriteOrder(int *const ptr, const int direction, const int n, const int def)
Definition: iteminfo.cpp:317
void setWaterAttackAction(const std::string &attackAction)
Definition: iteminfo.cpp:137
std::vector< ItemMenuItem > mCartMenu
Definition: iteminfo.h:385
CursorT getPickupCursor() const
Definition: iteminfo.h:295
void setWeight(const int weight)
Definition: iteminfo.h:130
bool mProtected
Definition: iteminfo.h:395
ItemInfo()
Definition: iteminfo.cpp:43
int maxFloorOffsetX
Definition: iteminfo.h:392
bool isRemoveItemId(int id) const
const std::string replaceColors(std::string str, const ItemColor color) const
Definition: iteminfo.cpp:268
std::string getDyeIconColorsString(const ItemColor color) const
Definition: iteminfo.cpp:240
void setType(const ItemDbTypeT type)
Definition: iteminfo.h:112
std::string mSkyAttackAction
Definition: iteminfo.h:367
void setDrawBefore(const int direction, const int n)
Definition: iteminfo.cpp:370
std::vector< SpriteToItemMap * > mSpriteToItemReplaceList
Definition: iteminfo.h:359
bool mIsRemoveSprites
Definition: iteminfo.h:355
std::string mEffect
Definition: iteminfo.h:348
const std::string & getSkyAttackAction() const
Definition: iteminfo.h:189
std::string mAttackAction
Definition: iteminfo.h:366
int getView() const
Definition: iteminfo.h:136
std::string mUseButton2
Definition: iteminfo.h:350
void setView(const int view)
Definition: iteminfo.h:139
int getMaxFloorOffsetX() const
Definition: iteminfo.h:241
const IntMap & getTags() const
Definition: iteminfo.h:223
void setUseButton(const std::string &str)
Definition: iteminfo.h:115
void setName(const std::string &name)
Definition: iteminfo.h:71
std::map< int, int > mTags
Definition: iteminfo.h:380
Cursor ::T CursorT
Definition: cursor.h:44
Gender ::T GenderT
Definition: gender.h:35
std::map< int, int > IntMap
Definition: intmap.h:27
uint16_t ItemColor
Definition: itemcolor.h:30
ItemDbType ::T ItemDbTypeT
Definition: itemdbtype.h:49
SpriteToItemMap::const_iterator SpriteToItemMapCIter
Definition: iteminfo.h:47
std::map< int, IntMap > SpriteToItemMap
Definition: iteminfo.h:43
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define A_NONNULL(...)
Definition: localconsts.h:168
#define noexcept2
Definition: localconsts.h:50
#define final
Definition: localconsts.h:46
#define A_DELETE_COPY(func)
Definition: localconsts.h:53
CursorT stringToCursor(const std::string &name)
Definition: cursors.cpp:60
std::string particle
Definition: missileinfo.h:41