-
Notifications
You must be signed in to change notification settings - Fork 21
/
container.h
153 lines (120 loc) · 5.38 KB
/
container.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
//////////////////////////////////////////////////////////////////////
// OpenTibia - an opensource roleplaying game
//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
// This program 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 2
// of the License, or (at your option) any later version.
//
// This program 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, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//////////////////////////////////////////////////////////////////////
#ifndef __OTSERV_CONTAINER_H__
#define __OTSERV_CONTAINER_H__
#include <queue>
#include "definitions.h"
#include "cylinder.h"
#include "item.h"
class Container;
class DepotChest;
class DepotLocker;
class ContainerIterator
{
public:
ContainerIterator();
ContainerIterator(const ContainerIterator& rhs);
~ContainerIterator();
ContainerIterator& operator=(const ContainerIterator& rhs);
bool operator==(const ContainerIterator& rhs);
bool operator!=(const ContainerIterator& rhs);
ContainerIterator& operator++();
ContainerIterator operator++(int);
Item* operator*();
Item* operator->();
protected:
ContainerIterator(Container* super);
Container* super;
std::queue<Container*> over;
ItemDeque::iterator cur;
friend class Container;
};
class Container : public Item, public Cylinder
{
public:
Container(uint16_t _type);
virtual ~Container();
virtual Item* clone() const;
virtual Container* getContainer() {return this;}
virtual const Container* getContainer() const {return this;}
virtual DepotChest* getDepotChest() {return NULL;}
virtual const DepotChest* getDepotChest() const {return NULL;}
virtual DepotLocker* getDepotLocker() {return NULL;}
virtual const DepotLocker* getDepotLocker() const {return NULL;}
Attr_ReadValue readAttr(AttrTypes_t attr, PropStream& propStream);
bool unserializeItemNode(FileLoader& f, NODE node, PropStream& propStream);
std::string getContentDescription() const;
uint32_t size() const {return (uint32_t)itemlist.size();}
bool empty() const {return itemlist.empty();}
uint32_t capacity() const {return maxSize;}
ContainerIterator begin();
ContainerIterator end();
ContainerIterator begin() const;
ContainerIterator end() const;
ItemDeque::const_iterator getItems() const {return itemlist.begin();}
ItemDeque::const_iterator getEnd() const {return itemlist.end();}
ItemDeque::const_reverse_iterator getReversedItems() const {return itemlist.rbegin();}
ItemDeque::const_reverse_iterator getReversedEnd() const {return itemlist.rend();}
void addItem(Item* item);
Item* getItem(uint32_t index) const;
bool isHoldingItem(const Item* item) const;
uint32_t getItemHoldingCount() const;
virtual double getWeight() const;
//cylinder implementations
virtual ReturnValue __queryAdd(int32_t index, const Thing* thing, uint32_t count,
uint32_t flags, Creature* actor = NULL) const;
virtual ReturnValue __queryMaxCount(int32_t index, const Thing* thing, uint32_t count, uint32_t& maxQueryCount,
uint32_t flags) const;
virtual ReturnValue __queryRemove(const Thing* thing, uint32_t count, uint32_t flags) const;
virtual Cylinder* __queryDestination(int32_t& index, const Thing* thing, Item** destItem,
uint32_t& flags);
virtual void __addThing(Thing* thing);
virtual void __addThing(int32_t index, Thing* thing);
virtual void __updateThing(Thing* thing, uint16_t itemId, uint32_t count);
virtual void __replaceThing(uint32_t index, Thing* thing);
virtual void __removeThing(Thing* thing, uint32_t count);
virtual int32_t __getIndexOfThing(const Thing* thing) const;
virtual int32_t __getFirstIndex() const;
virtual int32_t __getLastIndex() const;
virtual uint32_t __getItemTypeCount(uint16_t itemId, int32_t subType = -1) const;
virtual std::map<uint32_t, uint32_t>& __getAllItemTypeCount(std::map<uint32_t, uint32_t>& countMap) const;
virtual Thing* __getThing(uint32_t index) const;
virtual void postAddNotification(Thing* thing, const Cylinder* oldParent, int32_t index, cylinderlink_t link = LINK_OWNER);
virtual void postRemoveNotification(Thing* thing, const Cylinder* newParent, int32_t index, bool isCompleteRemoval, cylinderlink_t link = LINK_OWNER);
virtual void __internalAddThing(Thing* thing);
virtual void __internalAddThing(uint32_t index, Thing* thing);
virtual void __startDecaying();
private:
void onAddContainerItem(Item* item);
void onUpdateContainerItem(uint32_t index, Item* oldItem, const ItemType& oldType,
Item* newItem, const ItemType& newType);
void onRemoveContainerItem(uint32_t index, Item* item);
Container* getParentContainer();
void updateItemWeight(double diff);
protected:
std::ostringstream& getContentDescription(std::ostringstream& os) const;
uint32_t maxSize;
double totalWeight;
ItemDeque itemlist;
uint32_t serializationCount;
friend class ContainerIterator;
friend class IOMapSerialize;
};
#endif