3 Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #ifndef INVENTORYMANAGER_HEADER
21 #define INVENTORYMANAGER_HEADER
23 #include "inventory.h"
25 // Should probably somehow replace InventoryContext over time
26 struct InventoryLocation
34 std::string name; // PLAYER
37 void setPlayer(const std::string &name_)
42 void setNodeMeta(v3s16 p_)
51 struct InventoryContext
53 Player *current_player;
60 struct InventoryAction;
62 class InventoryManager
66 virtual ~InventoryManager(){}
68 // Get an inventory or set it modified (so it will be updated over
70 virtual Inventory* getInventory(const InventoryLocation &loc){return NULL;}
71 virtual void setInventoryModified(const InventoryLocation &loc){}
73 // Used on the client to send an action to the server
74 virtual void inventoryAction(InventoryAction *a){}
76 // (Deprecated; these wrap to the latter ones)
77 // Get a pointer to an inventory specified by id. id can be:
80 Inventory* getInventory(InventoryContext *c, std::string id);
81 // Used on the server by InventoryAction::apply and other stuff
82 void inventoryModified(InventoryContext *c, std::string id);
85 #define IACTION_MOVE 0
86 #define IACTION_DROP 1
88 struct InventoryAction
90 static InventoryAction * deSerialize(std::istream &is);
92 virtual u16 getType() const = 0;
93 virtual void serialize(std::ostream &os) const = 0;
94 virtual void apply(InventoryContext *c, InventoryManager *mgr,
95 ServerEnvironment *env) = 0;
98 struct IMoveAction : public InventoryAction
100 // count=0 means "everything"
102 std::string from_inv;
103 std::string from_list;
116 IMoveAction(std::istream &is);
123 void serialize(std::ostream &os) const
135 void apply(InventoryContext *c, InventoryManager *mgr,
136 ServerEnvironment *env);
139 struct IDropAction : public InventoryAction
141 // count=0 means "everything"
143 std::string from_inv;
144 std::string from_list;
153 IDropAction(std::istream &is);
160 void serialize(std::ostream &os) const
169 void apply(InventoryContext *c, InventoryManager *mgr,
170 ServerEnvironment *env);
174 Craft checking system
188 enum ItemSpecType type;
189 // Only other one of these is used
197 ItemSpec(enum ItemSpecType a_type, std::string a_name):
203 ItemSpec(enum ItemSpecType a_type, u16 a_num):
210 bool checkItem(const InventoryItem *item) const;
214 items: a pointer to an array of 9 pointers to items
215 specs: a pointer to an array of 9 ItemSpecs
217 bool checkItemCombination(const InventoryItem * const*items, const ItemSpec *specs);
220 items: a pointer to an array of 9 pointers to items
221 specs: a pointer to an array of 9 pointers to items
223 bool checkItemCombination(const InventoryItem * const * items,
224 const InventoryItem * const * specs);