summaryrefslogtreecommitdiff
path: root/src/inventory.h
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2010-12-22 16:30:23 +0200
committerPerttu Ahola <celeron55@gmail.com>2010-12-22 16:30:23 +0200
commit3de176cc587c4e0601c3c3f5a049e30db6bd2c17 (patch)
tree0a85d68c29e1354acda46e0c4e46e80a6f891039 /src/inventory.h
parent2e41a5e304d9c35ece851b8a65482bca8784b582 (diff)
downloadminetest-3de176cc587c4e0601c3c3f5a049e30db6bd2c17.tar.gz
minetest-3de176cc587c4e0601c3c3f5a049e30db6bd2c17.tar.bz2
minetest-3de176cc587c4e0601c3c3f5a049e30db6bd2c17.zip
crafting system!
Diffstat (limited to 'src/inventory.h')
-rw-r--r--src/inventory.h69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/inventory.h b/src/inventory.h
index d37761cfe..ad3b297e8 100644
--- a/src/inventory.h
+++ b/src/inventory.h
@@ -213,12 +213,20 @@ public:
// Count used slots
u32 getUsedSlots();
+ // Get pointer to item
InventoryItem * getItem(u32 i);
// Returns old item (or NULL). Parameter can be NULL.
InventoryItem * changeItem(u32 i, InventoryItem *newitem);
+ // Delete item
void deleteItem(u32 i);
// Adds an item to a suitable place. Returns false if failed.
bool addItem(InventoryItem *newitem);
+ // If possible, adds item to given slot. Returns true on success.
+ // Fails when slot is populated by a different kind of item.
+ bool addItem(u32 i, InventoryItem *newitem);
+
+ // Decrements amount of every material item
+ void decrementMaterials(u16 count);
void print(std::ostream &o);
@@ -261,5 +269,66 @@ private:
core::array<InventoryList*> m_lists;
};
+#define IACTION_MOVE 0
+
+struct InventoryAction
+{
+ static InventoryAction * deSerialize(std::istream &is);
+
+ virtual u16 getType() const = 0;
+ virtual void serialize(std::ostream &os) = 0;
+ virtual void apply(Inventory *inventory) = 0;
+};
+
+struct IMoveAction : public InventoryAction
+{
+ u16 count;
+ std::string from_name;
+ s16 from_i;
+ std::string to_name;
+ s16 to_i;
+
+ IMoveAction()
+ {
+ count = 0;
+ from_i = -1;
+ to_i = -1;
+ }
+ IMoveAction(std::istream &is)
+ {
+ std::string ts;
+
+ std::getline(is, ts, ' ');
+ count = stoi(ts);
+
+ std::getline(is, from_name, ' ');
+
+ std::getline(is, ts, ' ');
+ from_i = stoi(ts);
+
+ std::getline(is, to_name, ' ');
+
+ std::getline(is, ts, ' ');
+ to_i = stoi(ts);
+ }
+
+ u16 getType() const
+ {
+ return IACTION_MOVE;
+ }
+
+ void serialize(std::ostream &os)
+ {
+ os<<"Move ";
+ os<<count<<" ";
+ os<<from_name<<" ";
+ os<<from_i<<" ";
+ os<<to_name<<" ";
+ os<<to_i;
+ }
+
+ void apply(Inventory *inventory);
+};
+
#endif