GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/resources/iteminfo.h Lines: 25 56 44.6 %
Date: 2017-11-29 Branches: 5 16 31.3 %

Line Branch Exec Source
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-2017  The ManaPlus Developers
6
 *
7
 *  This file is part of The ManaPlus Client.
8
 *
9
 *  This program is free software; you can redistribute it and/or modify
10
 *  it under the terms of the GNU General Public License as published by
11
 *  the Free Software Foundation; either version 2 of the License, or
12
 *  any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
#ifndef RESOURCES_ITEMINFO_H
24
#define RESOURCES_ITEMINFO_H
25
26
#include "enums/being/gender.h"
27
28
#include "enums/resources/item/itemdbtype.h"
29
30
#include "enums/simpletypes/beingtypeid.h"
31
32
#include "resources/cursors.h"
33
#include "resources/itemcolordata.h"
34
#include "resources/missileinfo.h"
35
#include "resources/soundinfo.h"
36
37
#include "resources/sprite/spritedisplay.h"
38
39
#include "utils/cast.h"
40
#include "utils/intmap.h"
41
42
struct ItemMenuItem;
43
44
// sprite, <itemfrom, itemto>
45
typedef std::map<int, IntMap> SpriteToItemMap;
46
typedef SpriteToItemMap::const_iterator SpriteToItemMapCIter;
47
48
/**
49
 * Defines a class for storing item infos. This includes information used when
50
 * the item is equipped.
51
 */
52
class ItemInfo final
53
{
54
    public:
55
        /**
56
         * Constructor.
57
         */
58
        ItemInfo();
59
60
        A_DELETE_COPY(ItemInfo)
61
62
        ~ItemInfo();
63
64
        void setId(const int id) noexcept2
65
248
        { mId = id; }
66
67
        int getId() const noexcept2 A_WARN_UNUSED
68
38
        { return mId; }
69
70
        void setName(const std::string &name) noexcept2
71
508
        { mName = name; }
72
73
        const std::string &getName() const noexcept2 A_WARN_UNUSED
74
        { return mName; }
75
76
        const std::string getName(const ItemColor color)
77
                                  const A_WARN_UNUSED;
78
79
        void setNameEn(const std::string &name) noexcept2
80
456
        { mNameEn = name; }
81
82
        const std::string &getNameEn() const noexcept2 A_WARN_UNUSED
83
        { return mNameEn; }
84
85
        const std::string getNameEn(const ItemColor color)
86
                                    const A_WARN_UNUSED;
87
88
        const std::string getLink() const A_WARN_UNUSED;
89
90
        void setDisplay(const SpriteDisplay &display) noexcept2
91
234
        { mDisplay = display; }
92
93
        const SpriteDisplay &getDisplay() const noexcept2 A_WARN_UNUSED
94
        { return mDisplay; }
95
96
        void setDescription(const std::string &description) noexcept2
97
456
        { mDescription = description; }
98
99
        const std::string &getDescription() const noexcept2 A_WARN_UNUSED
100
        { return mDescription; }
101
102
        const std::string getDescription(const ItemColor color)
103
                                         const A_WARN_UNUSED;
104
105
        void setEffect(const std::string &effect) noexcept2
106
456
        { mEffect = effect; }
107
108
        const std::string &getEffect() const noexcept2 A_WARN_UNUSED
109
        { return mEffect; }
110
111
        void setType(const ItemDbTypeT type) noexcept2
112
456
        { mType = type; }
113
114
        void setUseButton(const std::string &str) noexcept2
115
456
        { mUseButton = str; }
116
117
        const std::string &getUseButton() const noexcept2 A_WARN_UNUSED
118
        { return mUseButton; }
119
120
        void setUseButton2(const std::string &str) noexcept2
121
456
        { mUseButton2 = str; }
122
123
        const std::string &getUseButton2() const noexcept2 A_WARN_UNUSED
124
        { return mUseButton2; }
125
126
        ItemDbTypeT getType() const noexcept2 A_WARN_UNUSED
127
904
        { return mType; }
128
129
        void setWeight(const int weight) noexcept2
130
228
        { mWeight = weight; }
131
132
        int getWeight() const noexcept2 A_WARN_UNUSED
133
        { return mWeight; }
134
135
        int getView() const noexcept2 A_WARN_UNUSED
136
        { return mView; }
137
138
        void setView(const int view) noexcept2
139
228
        { mView = view; }
140
141
        void setSprite(const std::string &animationFile,
142
                       const GenderT gender, const int race);
143
144
        const std::string &getSprite(const GenderT gender,
145
                                     const BeingTypeId race)
146
                                     const A_WARN_UNUSED;
147
148
        void setAttackAction(const std::string &attackAction);
149
150
        void setSkyAttackAction(const std::string &attackAction);
151
152
        void setWaterAttackAction(const std::string &attackAction);
153
154
        void setRideAttackAction(const std::string &attackAction);
155
156
        // Handlers for seting and getting the string
157
        // used for particles when attacking
158
        void setMissileParticleFile(const std::string &s) noexcept2
159
        { mMissile.particle = s; }
160
161
        MissileInfo &getMissile() noexcept2 A_WARN_UNUSED
162
        { return mMissile; }
163
164
        const MissileInfo &getMissileConst() const noexcept2 A_WARN_UNUSED
165
        { return mMissile; }
166
167
        void setHitEffectId(const int s) noexcept2
168
228
        { mHitEffectId = s; }
169
170
        int getHitEffectId() const noexcept2 A_WARN_UNUSED
171
        { return mHitEffectId; }
172
173
        void setCriticalHitEffectId(const int s) noexcept2
174
228
        { mCriticalHitEffectId = s; }
175
176
        int getCriticalHitEffectId() const noexcept2 A_WARN_UNUSED
177
        { return mCriticalHitEffectId; }
178
179
        void setMissEffectId(const int s) noexcept2
180
228
        { mMissEffectId = s; }
181
182
        int getMissEffectId() const noexcept2 A_WARN_UNUSED
183
        { return mMissEffectId; }
184
185
        const std::string &getAttackAction() const noexcept2 A_WARN_UNUSED
186
        { return mAttackAction; }
187
188
        const std::string &getSkyAttackAction() const noexcept2 A_WARN_UNUSED
189
        { return mSkyAttackAction; }
190
191
        const std::string &getWaterAttackAction() const noexcept2 A_WARN_UNUSED
192
        { return mWaterAttackAction; }
193
194
        const std::string &getRideAttackAction() const noexcept2 A_WARN_UNUSED
195
        { return mRideAttackAction; }
196
197
        int getAttackRange() const noexcept2 A_WARN_UNUSED
198
        { return mAttackRange; }
199
200
        void setAttackRange(const int r) noexcept2
201
228
        { mAttackRange = r; }
202
203
        void addSound(const ItemSoundEvent::Type event,
204
                      const std::string &filename,
205
                      const int delay);
206
207
        const SoundInfo &getSound(const ItemSoundEvent::Type event)
208
                                  const A_WARN_UNUSED;
209
210
        int getDrawBefore(const int direction) const A_WARN_UNUSED;
211
212
        void setDrawBefore(const int direction, const int n);
213
214
        int getDrawAfter(const int direction) const A_WARN_UNUSED;
215
216
        void setDrawAfter(const int direction, const int n);
217
218
        int getDrawPriority(const int direction) const A_WARN_UNUSED;
219
220
        void setDrawPriority(const int direction, const int n);
221
222
        const IntMap &getTags() const noexcept2 A_WARN_UNUSED
223
        { return mTags; }
224
225
        void addTag(const int tag)
226



462
        { mTags[tag] = 1; }
227
228
        void setRemoveSprites() noexcept2
229
        { mIsRemoveSprites = true; }
230
231
        bool isRemoveSprites() const noexcept2 A_WARN_UNUSED
232
        { return mIsRemoveSprites; }
233
234
        void setMaxFloorOffsetX(const int i) noexcept2
235
228
        { maxFloorOffsetX = i; }
236
237
        void setMaxFloorOffsetY(const int i) noexcept2
238
228
        { maxFloorOffsetY = i; }
239
240
        int getMaxFloorOffsetX() const noexcept2 A_WARN_UNUSED
241
        { return maxFloorOffsetX; }
242
243
        int getMaxFloorOffsetY() const noexcept2 A_WARN_UNUSED
244
        { return maxFloorOffsetY; }
245
246
        bool isRemoveItemId(int id) const A_WARN_UNUSED;
247
248
        void setCardColor(const ItemColor color) noexcept2
249
12
        { mCardColor = color; }
250
251
        ItemColor getCardColor() const noexcept2
252
        { return mCardColor; }
253
254
        int getReplaceToSpriteId(int id) const A_WARN_UNUSED;
255
256
        IntMap *addReplaceSprite(const int sprite,
257
                                 const int direction);
258
259
        const SpriteToItemMap *getSpriteToItemReplaceMap(const int directions)
260
                                                         const A_WARN_UNUSED;
261
262
        std::string getDyeColorsString(const ItemColor color)
263
                                       const A_WARN_UNUSED;
264
265
        std::string getDyeIconColorsString(const ItemColor color)
266
                                           const A_WARN_UNUSED;
267
268
        void setColorsList(const std::string &name);
269
270
        void setIconColorsList(const std::string &name);
271
272
        bool isHaveColors() const noexcept2 A_WARN_UNUSED
273
        { return !mColorsListName.empty(); }
274
275
        bool isHaveIconColors() const noexcept2 A_WARN_UNUSED
276
        { return !mIconColorsListName.empty(); }
277
278
        std::string getColorsListName() const noexcept2 A_WARN_UNUSED
279
        { return mColorsListName; }
280
281
        std::string getIconColorsListName() const noexcept2 A_WARN_UNUSED
282
        { return mIconColorsListName; }
283
284
        const std::string replaceColors(std::string str,
285
                                        const ItemColor color)
286
                                        const A_WARN_UNUSED;
287
288
        void setPickupCursor(const std::string &cursor)
289
228
        { return setPickupCursor(Cursors::stringToCursor(cursor)); }
290
291
        void setPickupCursor(const CursorT &cursor) noexcept2
292
228
        { mPickupCursor = cursor; }
293
294
        CursorT getPickupCursor() const noexcept2 A_WARN_UNUSED
295
        { return mPickupCursor; }
296
297
        void setProtected(const bool b) noexcept2
298
228
        { mProtected = b; }
299
300
        bool isProtected() const noexcept2 A_WARN_UNUSED
301
        { return mProtected; }
302
303
        int getColorsSize() const noexcept2 A_WARN_UNUSED
304
        { return mColorsList != nullptr ? CAST_S32(mColorsList->size()) : 0; }
305
306
        int getIconColorsSize() const noexcept2 A_WARN_UNUSED
307
        {
308
            return mIconColorsList != nullptr ?
309
                CAST_S32(mIconColorsList->size()) : 0;
310
        }
311
312
        std::string getColorName(const ItemColor idx) const;
313
        std::string getColor(const ItemColor idx) const;
314
315
        std::string getIconColorName(const ItemColor idx) const;
316
        std::string getIconColor(const ItemColor idx) const;
317
318
        STD_VECTOR<ItemMenuItem> &getInventoryMenu()
319
228
        { return mInventoryMenu; }
320
        STD_VECTOR<ItemMenuItem> &getStorageMenu()
321
        { return mStorageMenu; }
322
        STD_VECTOR<ItemMenuItem> &getCartMenu()
323
        { return mCartMenu; }
324
325
        const STD_VECTOR<ItemMenuItem> &getInventoryMenuConst() const A_CONST
326
        { return mInventoryMenu; }
327
        const STD_VECTOR<ItemMenuItem> &getStorageMenuConst() const A_CONST
328
        { return mStorageMenu; }
329
        const STD_VECTOR<ItemMenuItem> &getCartMenuConst() const A_CONST
330
        { return mCartMenu; }
331
332
        int mDrawBefore[10];
333
        int mDrawAfter[10];
334
        int mDrawPriority[10];
335
336
    private:
337
        static void setSpriteOrder(int *const ptr,
338
                                   const int direction,
339
                                   const int n,
340
                                   const int def = -1) A_NONNULL(1);
341
342
        SpriteDisplay mDisplay;     /**< Display info (like icon) */
343
        MissileInfo mMissile;
344
        std::string mName;
345
        std::string mNameEn;
346
        std::string mDescription;   /**< Short description. */
347
        std::string mEffect;        /**< Description of effects. */
348
        std::string mUseButton;
349
        std::string mUseButton2;
350
        ItemDbTypeT mType;          /**< Item type. */
351
        int mWeight;                /**< Weight in grams. */
352
        int mView;                  /**< Item ID of how this item looks. */
353
        int mId;                    /**< Item ID */
354
        bool mIsRemoveSprites;
355
        // sprite, <itemfrom, itemto> [direction]
356
        SpriteToItemMap *mSpriteToItemReplaceMap[10];
357
358
        STD_VECTOR<SpriteToItemMap*> mSpriteToItemReplaceList;
359
360
        // Equipment related members.
361
        /** Attack type, in case of weapon.
362
         * See SpriteAction in spritedef.h for more info.
363
         * Attack action sub-types (bow, sword, ...) are defined in items.xml.
364
         */
365
        std::string mAttackAction;
366
        std::string mSkyAttackAction;
367
        std::string mWaterAttackAction;
368
        std::string mRideAttackAction;
369
        int mAttackRange;     /**< Attack range, will be zero if non weapon. */
370
371
        // Particle to be shown when weapon attacks
372
        std::string mMissileParticle;
373
374
        /** Maps gender to sprite filenames. */
375
        std::map <int, std::string> mAnimationFiles;
376
377
        /** Stores the names of sounds to be played at certain event. */
378
        std::map <ItemSoundEvent::Type, SoundInfoVect> mSounds;
379
        std::map <int, int> mTags;
380
        const std::map <ItemColor, ItemColorData> *mColorsList;
381
        const std::map <ItemColor, ItemColorData> *mIconColorsList;
382
        STD_VECTOR<ItemMenuItem> mInventoryMenu;
383
        STD_VECTOR<ItemMenuItem> mStorageMenu;
384
        STD_VECTOR<ItemMenuItem> mCartMenu;
385
        std::string mColorsListName;
386
        std::string mIconColorsListName;
387
        ItemColor mCardColor;
388
        int mHitEffectId;
389
        int mCriticalHitEffectId;
390
        int mMissEffectId;
391
        int maxFloorOffsetX;
392
        int maxFloorOffsetY;
393
        CursorT mPickupCursor;
394
        bool mProtected;
395
};
396
397
#endif  // RESOURCES_ITEMINFO_H