GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/resources/item/item.h Lines: 3 30 10.0 %
Date: 2017-11-29 Branches: 0 24 0.0 %

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_ITEM_ITEM_H
24
#define RESOURCES_ITEM_ITEM_H
25
26
#include "const/resources/item/cards.h"
27
28
#include "enums/resources/item/itemtype.h"
29
30
#include "enums/simpletypes/damaged.h"
31
#include "enums/simpletypes/equipm.h"
32
#include "enums/simpletypes/equipped.h"
33
#include "enums/simpletypes/favorite.h"
34
#include "enums/simpletypes/identified.h"
35
#include "enums/simpletypes/itemcolor.h"
36
37
#include "resources/db/itemdb.h"
38
39
#include "localconsts.h"
40
41
class Image;
42
43
struct ItemOptionsList;
44
45
/**
46
 * Represents one or more instances of a certain item type.
47
 */
48
class Item notfinal
49
{
50
    public:
51
        /**
52
         * Constructor.
53
         */
54
        Item(const int id,
55
             const ItemTypeT type,
56
             const int quantity,
57
             const uint8_t refine,
58
             const ItemColor color,
59
             const Identified identified,
60
             const Damaged damaged,
61
             const Favorite favorite,
62
             const Equipm equipment,
63
             const Equipped equipped);
64
65
        A_DELETE_COPY(Item)
66
67
        /**
68
         * Destructor.
69
         */
70
        virtual ~Item();
71
72
        /**
73
         * Sets the item id, color the item type.
74
         */
75
        void setId(const int id, const ItemColor color);
76
77
        /**
78
         * Returns the item id.
79
         */
80
        int getId() const noexcept2 A_WARN_UNUSED
81
        { return mId; }
82
83
        /**
84
         * Returns the item image.
85
         */
86
        Image *getImage() const noexcept2 A_WARN_UNUSED
87
2
        { return mImage; }
88
89
        /**
90
         * Sets the number of items.
91
         */
92
        void setQuantity(const int quantity) noexcept2
93
        { mQuantity = quantity; }
94
95
        /**
96
         * Increases the number of items by the given amount.
97
         */
98
        void increaseQuantity(const int amount) noexcept2
99
        { mQuantity += amount; }
100
101
        /**
102
         * Returns the number of items.
103
         */
104
        int getQuantity() const noexcept2 A_WARN_UNUSED
105
2
        { return mQuantity; }
106
107
        /**
108
         * Sets whether this item is considered equipment.
109
         */
110
        void setEquipment(const Equipm equipment) noexcept2
111
        { mEquipment = equipment; }
112
113
        /**
114
         * Returns whether this item is considered equipment.
115
         */
116
        Equipm isEquipment() const noexcept2 A_WARN_UNUSED
117
        { return mEquipment; }
118
119
        /**
120
         * Sets whether this item is equipped.
121
         */
122
        void setEquipped(const Equipped equipped) noexcept2
123
        { mEquipped = equipped; }
124
125
        /**
126
         * Returns whether this item is equipped.
127
         */
128
        Equipped isEquipped() const noexcept2 A_WARN_UNUSED
129
        { return mEquipped; }
130
131
        /**
132
         * Sets this item refine level.
133
         */
134
        void setRefine(const uint8_t refine) noexcept2
135
        { mRefine = refine; }
136
137
        /**
138
         * Returns this item refine level.
139
         */
140
        uint8_t getRefine() const noexcept2 A_WARN_UNUSED
141
        { return mRefine; }
142
143
        /**
144
         * Sets whether this item is in equipment.
145
         */
146
        void setInEquipment(const bool inEquipment) noexcept2
147
        { mInEquipment = inEquipment; }
148
149
        /**
150
         * Returns whether this item is in equipment.
151
         */
152
        bool isInEquipment() const noexcept2 A_WARN_UNUSED
153
        { return mInEquipment; }
154
155
        /**
156
         * Sets the inventory index of this item.
157
         */
158
        void setInvIndex(const int index) noexcept2
159
        { mInvIndex = index; }
160
161
        /**
162
         * Returns the inventory index of this item.
163
         */
164
        int getInvIndex() const noexcept2 A_WARN_UNUSED
165
        { return mInvIndex; }
166
167
        /**
168
         * Returns information about this item type.
169
         */
170
        const ItemInfo &getInfo() const A_WARN_UNUSED
171




8
        { return ItemDB::get(mId); }
172
173
        std::string getName() const A_WARN_UNUSED;
174
175
        static Image *getImage(const int id,
176
                               const ItemColor color) A_WARN_UNUSED;
177
178
        bool isHaveTag(const int tagId) const A_WARN_UNUSED;
179
180
        ItemColor getColor() const noexcept2 A_WARN_UNUSED
181
        { return mColor; }
182
183
        void setColor(const ItemColor color) noexcept2
184
        { mColor = color; }
185
186
        const std::string &getDescription() const noexcept2 A_WARN_UNUSED
187
        { return mDescription; }
188
189
        void setIdentified(const Identified b) noexcept2
190
        { mIdentified = b; }
191
192
        Identified getIdentified() const noexcept2 A_WARN_UNUSED
193
        { return mIdentified; }
194
195
        void setDamaged(const Damaged b) noexcept2
196
        { mDamaged = b; }
197
198
        Damaged getDamaged() const noexcept2 A_WARN_UNUSED
199
        { return mDamaged; }
200
201
        void setFavorite(const Favorite b) noexcept2
202
        { mFavorite = b; }
203
204
        Favorite getFavorite() const noexcept2 A_WARN_UNUSED
205
        { return mFavorite; }
206
207
        void setCard(const int index, const int id);
208
209
        int getCard(const int index) const;
210
211
        void setCards(const int *const cards, const int size);
212
213
        const int *getCards() const noexcept2 A_WARN_UNUSED
214
        { return mCards; }
215
216
        void setOptions(const ItemOptionsList *const options);
217
218
        const ItemOptionsList *getOptions() const noexcept2 A_WARN_UNUSED
219
        { return mOptions; }
220
221
        void setType(const ItemTypeT type) noexcept2
222
        { mType = type; }
223
224
        ItemTypeT getType() const noexcept2 A_WARN_UNUSED
225
        { return mType; }
226
227
        void setTag(const int tag) noexcept2
228
        { mTag = tag; }
229
230
        int getTag() const noexcept2 A_WARN_UNUSED
231
        { return mTag; }
232
233
        void addCard(const int card);
234
235
        void updateColor();
236
237
        static constexpr bool isItem(const int id) noexcept2 A_WARN_UNUSED
238
        {
239
            return id != 0 &&
240
                id != CARD0_FORGE &&
241
                id != CARD0_CREATE &&
242
                id != CARD0_PET;
243
        }
244
245
        int mId;              /**< Item id. */
246
        ItemColor mColor;
247
        int mQuantity;        /**< Number of items. */
248
        int mTag;
249
250
    protected:
251
        Image *mImage;        /**< Item image. */
252
        std::string mDescription;
253
        std::map <int, int> mTags;
254
        int mCards[maxCards];
255
        const ItemOptionsList *mOptions;
256
        uint8_t mRefine;      /**< Item refine level. */
257
        int mInvIndex;        /**< Inventory index. */
258
        ItemTypeT mType;      /**< Item type. */
259
        Equipm mEquipment;    /**< Item is equipment. */
260
        Equipped mEquipped;   /**< Item is equipped. */
261
        bool mInEquipment;    /**< Item is in equipment */
262
        Identified mIdentified;
263
        Damaged mDamaged;
264
        Favorite mFavorite;
265
};
266
267
#endif  // RESOURCES_ITEM_ITEM_H