-
Notifications
You must be signed in to change notification settings - Fork 224
/
item.h
319 lines (267 loc) · 10.4 KB
/
item.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
//////////////////////////////////////////////////////////////////////
// This file is part of Remere's Map Editor
//////////////////////////////////////////////////////////////////////
// Remere's Map Editor is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Remere's Map Editor is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//////////////////////////////////////////////////////////////////////
#ifndef RME_ITEM_H_
#define RME_ITEM_H_
#include "items.h"
#include "iomap_otbm.h"
//#include "iomap_otmm.h"
#include "item_attributes.h"
enum ITEMPROPERTY {
BLOCKSOLID,
HASHEIGHT,
BLOCKPROJECTILE,
BLOCKPATHFIND,
PROTECTIONZONE,
HOOK_SOUTH,
HOOK_EAST,
MOVEABLE,
BLOCKINGANDNOTMOVEABLE
};
enum SplashType
{
LIQUID_NONE = 0,
LIQUID_WATER = 1,
LIQUID_BLOOD = 2,
LIQUID_BEER = 3,
LIQUID_SLIME = 4,
LIQUID_LEMONADE = 5,
LIQUID_MILK = 6,
LIQUID_MANAFLUID = 7,
LIQUID_INK = 8,
LIQUID_WATER2 = 9,
LIQUID_LIFEFLUID = 10,
LIQUID_OIL = 11,
LIQUID_SLIME2 = 12,
LIQUID_URINE = 13,
LIQUID_COCONUT_MILK = 14,
LIQUID_WINE = 15,
LIQUID_MUD = 19,
LIQUID_FRUIT_JUICE = 21,
LIQUID_LAVA = 26,
LIQUID_RUM = 27,
LIQUID_SWAMP = 28,
LIQUID_TEA = 35,
LIQUID_MEAD = 43,
LIQUID_FIRST = LIQUID_WATER,
LIQUID_LAST = LIQUID_MEAD
};
IMPLEMENT_INCREMENT_OP(SplashType)
class Creature;
class Border;
class Tile;
class Container;
class Depot;
class Teleport;
class Door;
struct SpriteLight;
class Item : public ItemAttributes
{
public:
//Factory member to create item of right type based on type
static Item* Create(uint16_t id, uint16_t subtype = 0xFFFF);
static Item* Create(pugi::xml_node);
static Item* Create_OTBM(const IOMap& maphandle, BinaryNode* stream);
//static Item* Create_OTMM(const IOMap& maphandle, BinaryNode* stream);
protected:
// Constructor for items
Item(unsigned short _type, unsigned short _count);
public:
virtual ~Item();
// Deep copy thingy
virtual Item* deepCopy() const;
// Get memory footprint size
uint32_t memsize() const;
virtual Container* getContainer() { return nullptr; }
virtual Depot* getDepot() { return nullptr; }
virtual Teleport* getTeleport() { return nullptr; }
virtual Door* getDoor() { return nullptr; }
// OTBM map interface
// Serialize and unserialize (for save/load)
// Used internally
virtual bool readItemAttribute_OTBM(const IOMap& maphandle, OTBM_ItemAttribute attr, BinaryNode* stream);
virtual bool unserializeAttributes_OTBM(const IOMap& maphandle, BinaryNode* stream);
virtual bool unserializeItemNode_OTBM(const IOMap& maphandle, BinaryNode* node);
// Will return a node containing this item
virtual bool serializeItemNode_OTBM(const IOMap& maphandle, NodeFileWriteHandle& f) const;
// Will write this item to the stream supplied in the argument
virtual void serializeItemCompact_OTBM(const IOMap& maphandle, NodeFileWriteHandle& f) const;
virtual void serializeItemAttributes_OTBM(const IOMap& maphandle, NodeFileWriteHandle& f) const;
// OTMM map interface
/*
// Serialize and unserialize (for save/load)
// Used internally
virtual bool readItemAttribute_OTMM(const IOMap& maphandle, OTMM_ItemAttribute attr, BinaryNode* stream);
virtual bool unserializeAttributes_OTMM(const IOMap& maphandle, BinaryNode* stream);
virtual bool unserializeItemNode_OTMM(const IOMap& maphandle, BinaryNode* node);
// Will return a node containing this item
virtual bool serializeItemNode_OTMM(const IOMap& maphandle, NodeFileWriteHandle& f) const;
// Will write this item to the stream supplied in the argument
virtual void serializeItemCompact_OTMM(const IOMap& maphandle, NodeFileWriteHandle& f) const;
virtual void serializeItemAttributes_OTMM(const IOMap& maphandle, NodeFileWriteHandle& f) const;
*/
// Static conversions
static std::string LiquidID2Name(uint16_t id);
static uint16_t LiquidName2ID(std::string id);
const ItemType& getItemType() const noexcept { return g_items.getItemType(id); }
// IDs
uint16_t getID() const { return id; }
uint16_t getClientID() const { return g_items.getItemType(id).clientID; }
// NOTE: This is very volatile, do NOT use this unless you know exactly what you're doing
// which you probably don't so avoid it like the plague!
void setID(uint16_t new_id);
bool isValidID() const { return g_items.isValidID(id); }
// Usual attributes
virtual double getWeight() const;
int getAttack() const { return getItemType().attack; }
int getArmor() const { return getItemType().armor; }
int getDefense() const { return getItemType().defense; }
//int getSlotPosition() const { return g_items.getItemType(id).slot_position; }
// Item g_settings
bool canHoldText() const;
bool canHoldDescription() const;
bool isReadable() const { return getItemType().canReadText; }
bool canWriteText() const { return getItemType().canWriteText; }
uint32_t getMaxWriteLength() const { return getItemType().maxTextLen; }
Brush* getBrush() const { return getItemType().brush; }
GroundBrush* getGroundBrush() const;
WallBrush* getWallBrush() const;
DoorBrush* getDoorBrush() const;
TableBrush* getTableBrush() const;
CarpetBrush* getCarpetBrush() const;
Brush* getDoodadBrush() const { return getItemType().doodad_brush; } // This is not necessarily a doodad brush
RAWBrush* getRAWBrush() const { return getItemType().raw_brush; }
uint16_t getGroundEquivalent() const { return getItemType().ground_equivalent; }
uint16_t hasBorderEquivalent() const { return getItemType().has_equivalent; }
uint32_t getBorderGroup() const { return getItemType().border_group; }
// Drawing related
uint8_t getMiniMapColor() const;
wxPoint getDrawOffset() const;
uint16_t getGroundSpeed() const;
bool hasLight() const;
SpriteLight getLight() const;
// Item types
bool hasProperty(enum ITEMPROPERTY prop) const;
bool isBlocking() const { return getItemType().unpassable; }
bool isStackable() const { return getItemType().stackable; }
bool isClientCharged() const { return getItemType().isClientCharged(); }
bool isExtraCharged() const { return getItemType().isExtraCharged(); }
bool isCharged() const { return isClientCharged() || isExtraCharged(); }
bool isFluidContainer() const { return (getItemType().isFluidContainer()); }
bool isAlwaysOnBottom() const { return getItemType().alwaysOnBottom; }
int getTopOrder() const { return getItemType().alwaysOnTopOrder; }
bool isGroundTile() const { return getItemType().isGroundTile(); }
bool isSplash() const { return getItemType().isSplash(); }
bool isMagicField() const { return getItemType().isMagicField(); }
bool isNotMoveable() const { return !getItemType().moveable; }
bool isMoveable() const { return getItemType().moveable; }
bool isPickupable() const { return getItemType().pickupable; }
//bool isWeapon() const { return (getItemType().weaponType != WEAPON_NONE && g_items[id].weaponType != WEAPON_AMMO); }
//bool isUseable() const { return getItemType().useable; }
bool isHangable() const { return getItemType().isHangable; }
bool isRoteable() const { return getItemType().rotable && getItemType().rotateTo; }
bool hasCharges() const { return getItemType().charges != 0; }
bool isBorder() const { return getItemType().isBorder; }
bool isOptionalBorder() const { return getItemType().isOptionalBorder; }
bool isWall() const { return getItemType().isWall; }
bool isDoor() const { return getItemType().isDoor(); }
bool isOpen() const { return getItemType().isOpen; }
bool isBrushDoor() const { return getItemType().isBrushDoor; }
bool isTable() const { return getItemType().isTable; }
bool isCarpet() const { return getItemType().isCarpet; }
bool isMetaItem() const { return getItemType().isMetaItem(); }
// Wall alignment (vertical, horizontal, pole, corner)
BorderType getWallAlignment() const;
// Border aligment (south, west etc.)
BorderType getBorderAlignment() const;
// Get the name!
const std::string getName() const { return getItemType().name; }
const std::string getFullName() const { return getItemType().name + getItemType().editorsuffix; }
// Selection
bool isSelected() const { return selected; }
void select() {selected = true; }
void deselect() {selected = false; }
void toggleSelection() {selected =! selected; }
// Item properties!
virtual bool isComplex() const { return attributes && attributes->size(); } // If this item requires full save (not compact)
// Weight
bool hasWeight() { return isPickupable(); }
virtual double getWeight();
// Subtype (count, fluid, charges)
int getCount() const;
uint16_t getSubtype() const;
void setSubtype(uint16_t subtype);
bool hasSubtype() const;
void setUniqueID(uint16_t n);
uint16_t getUniqueID() const;
void setActionID(uint16_t n);
uint16_t getActionID() const;
void setText(const std::string& str);
std::string getText() const;
void setDescription(const std::string& str);
std::string getDescription() const;
void animate();
int getFrame() const { return frame; }
void doRotate() {
if(isRoteable()) {
setID(getItemType().rotateTo);
}
}
protected:
uint16_t id; // the same id as in ItemType
// Subtype is either fluid type, count, subtype or charges
uint16_t subtype;
bool selected;
int frame;
private:
Item& operator=(const Item& i);// Can't copy
Item(const Item &i); // Can't copy-construct
Item& operator==(const Item& i);// Can't compare
};
typedef std::vector<Item*> ItemVector;
typedef std::list<Item*> ItemList;
Item* transformItem(Item* old_item, uint16_t new_id, Tile* parent = nullptr);
inline int Item::getCount() const {
if(isStackable() || isExtraCharged() || isClientCharged()) {
return subtype;
}
return 1;
}
inline uint16_t Item::getUniqueID() const {
const int32_t* a = getIntegerAttribute("uid");
if(a)
return *a;
return 0;
}
inline uint16_t Item::getActionID() const {
const int32_t* a = getIntegerAttribute("aid");
if(a)
return *a;
return 0;
}
inline std::string Item::getText() const {
const std::string* a = getStringAttribute("text");
if(a)
return *a;
return "";
}
inline std::string Item::getDescription() const {
const std::string* a = getStringAttribute("desc");
if(a)
return *a;
return "";
}
#endif