diff options
Diffstat (limited to 'src/inventorymanager.h')
-rw-r--r-- | src/inventorymanager.h | 77 |
1 files changed, 46 insertions, 31 deletions
diff --git a/src/inventorymanager.h b/src/inventorymanager.h index fa9e94b63..69bf30169 100644 --- a/src/inventorymanager.h +++ b/src/inventorymanager.h @@ -26,21 +26,29 @@ class ServerActiveObject; struct InventoryLocation { - enum Type - { + enum Type{ UNDEFINED, CURRENT_PLAYER, PLAYER, NODEMETA, - DETACHED, + DETACHED, } type; std::string name; // PLAYER, DETACHED - v3s16 p; // NODEMETA + v3s16 p; // NODEMETA - InventoryLocation() { setUndefined(); } - void setUndefined() { type = UNDEFINED; } - void setCurrentPlayer() { type = CURRENT_PLAYER; } + InventoryLocation() + { + setUndefined(); + } + void setUndefined() + { + type = UNDEFINED; + } + void setCurrentPlayer() + { + type = CURRENT_PLAYER; + } void setPlayer(const std::string &name_) { type = PLAYER; @@ -59,9 +67,9 @@ struct InventoryLocation bool operator==(const InventoryLocation &other) const { - if (type != other.type) + if(type != other.type) return false; - switch (type) { + switch(type){ case UNDEFINED: return false; case CURRENT_PLAYER: @@ -82,7 +90,7 @@ struct InventoryLocation void applyCurrentPlayer(const std::string &name_) { - if (type == CURRENT_PLAYER) + if(type == CURRENT_PLAYER) setPlayer(name_); } @@ -101,15 +109,14 @@ public: virtual ~InventoryManager() = default; // Get an inventory (server and client) - virtual Inventory *getInventory(const InventoryLocation &loc) { return NULL; } - // Set modified (will be saved and sent over network; only on server) + virtual Inventory* getInventory(const InventoryLocation &loc){return NULL;} + // Set modified (will be saved and sent over network; only on server) virtual void setInventoryModified(const InventoryLocation &loc) {} - // Send inventory action to server (only on client) - virtual void inventoryAction(InventoryAction *a) {} + // Send inventory action to server (only on client) + virtual void inventoryAction(InventoryAction *a){} }; -enum class IAction : u16 -{ +enum class IAction : u16 { Move, Drop, Craft @@ -124,8 +131,7 @@ struct InventoryAction virtual void apply(InventoryManager *mgr, ServerActiveObject *player, IGameDef *gamedef) = 0; virtual void clientApply(InventoryManager *mgr, IGameDef *gamedef) = 0; - virtual ~InventoryAction() = default; - ; + virtual ~InventoryAction() = default;; }; struct MoveAction @@ -153,7 +159,10 @@ struct IMoveAction : public InventoryAction, public MoveAction IMoveAction(std::istream &is, bool somewhere); - IAction getType() const { return IAction::Move; } + IAction getType() const + { + return IAction::Move; + } void serialize(std::ostream &os) const { @@ -185,15 +194,18 @@ struct IDropAction : public InventoryAction, public MoveAction IDropAction(std::istream &is); - IAction getType() const { return IAction::Drop; } + IAction getType() const + { + return IAction::Drop; + } void serialize(std::ostream &os) const { - os << "Drop "; - os << count << " "; - os << from_inv.dump() << " "; - os << from_list << " "; - os << from_i; + os<<"Drop "; + os<<count<<" "; + os<<from_inv.dump()<<" "; + os<<from_list<<" "; + os<<from_i; } void apply(InventoryManager *mgr, ServerActiveObject *player, IGameDef *gamedef); @@ -211,13 +223,16 @@ struct ICraftAction : public InventoryAction ICraftAction(std::istream &is); - IAction getType() const { return IAction::Craft; } + IAction getType() const + { + return IAction::Craft; + } void serialize(std::ostream &os) const { - os << "Craft "; - os << count << " "; - os << craft_inv.dump() << " "; + os<<"Craft "; + os<<count<<" "; + os<<craft_inv.dump()<<" "; } void apply(InventoryManager *mgr, ServerActiveObject *player, IGameDef *gamedef); @@ -227,5 +242,5 @@ struct ICraftAction : public InventoryAction // Crafting helper bool getCraftingResult(Inventory *inv, ItemStack &result, - std::vector<ItemStack> &output_replacements, bool decrementInput, - IGameDef *gamedef); + std::vector<ItemStack> &output_replacements, + bool decrementInput, IGameDef *gamedef); |