From 3de176cc587c4e0601c3c3f5a049e30db6bd2c17 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Wed, 22 Dec 2010 16:30:23 +0200 Subject: crafting system! --- src/inventory.h | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'src/inventory.h') 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 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<