From f42c57d9a885450014cadd56a0eaf7c79eefebf4 Mon Sep 17 00:00:00 2001 From: Kahrl Date: Sun, 27 Nov 2011 05:01:38 +0200 Subject: Add IDropAction and related stuff --- src/inventory.cpp | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 105 insertions(+), 4 deletions(-) (limited to 'src/inventory.cpp') diff --git a/src/inventory.cpp b/src/inventory.cpp index c7dd2a87b..f3b81090b 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -27,6 +27,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "content_mapnode.h" #include "content_inventory.h" #include "content_sao.h" +#include "environment.h" +#include "mapblock.h" #include "player.h" #include "log.h" #include "nodedef.h" @@ -173,7 +175,7 @@ std::string InventoryItem::getItemString() { return os.str(); } -ServerActiveObject* InventoryItem::createSAO(ServerEnvironment *env, u16 id, v3f pos) +ServerActiveObject* InventoryItem::createSAO(ServerEnvironment *env, v3f pos) { /* Create an ItemSAO @@ -307,14 +309,14 @@ video::ITexture * CraftItem::getImage() const } #endif -ServerActiveObject* CraftItem::createSAO(ServerEnvironment *env, u16 id, v3f pos) +ServerActiveObject* CraftItem::createSAO(ServerEnvironment *env, v3f pos) { // Special cases ServerActiveObject *obj = item_craft_create_object(m_subname, env, pos); if(obj) return obj; // Default - return InventoryItem::createSAO(env, id, pos); + return InventoryItem::createSAO(env, pos); } u16 CraftItem::getDropCount() const @@ -884,6 +886,10 @@ InventoryAction * InventoryAction::deSerialize(std::istream &is) { a = new IMoveAction(is); } + else if(type == "Drop") + { + a = new IDropAction(is); + } return a; } @@ -918,7 +924,8 @@ IMoveAction::IMoveAction(std::istream &is) to_i = stoi(ts); } -void IMoveAction::apply(InventoryContext *c, InventoryManager *mgr) +void IMoveAction::apply(InventoryContext *c, InventoryManager *mgr, + ServerEnvironment *env) { Inventory *inv_from = mgr->getInventory(c, from_inv); Inventory *inv_to = mgr->getInventory(c, to_inv); @@ -1022,6 +1029,100 @@ void IMoveAction::apply(InventoryContext *c, InventoryManager *mgr) <getInventory(c, from_inv); + + if(!inv_from){ + infostream<<"IDropAction::apply(): FAIL: source inventory not found: " + <<"context=["<getList(from_list); + + /* + If a list doesn't exist or the source item doesn't exist + */ + if(!list_from){ + infostream<<"IDropAction::apply(): FAIL: source list not found: " + <<"context=["<getItem(from_i) == NULL) + { + infostream<<"IDropAction::apply(): FAIL: source item not found: " + <<"context=["<getItem(from_i)->getDropCount(); + InventoryItem *item1 = list_from->takeItem(from_i, count); + + // Create an active object + ServerActiveObject *obj = item1->createSAO(env, pos); + if(obj == NULL) + { + infostream<<"IDropAction::apply(): item resulted in NULL object, " + <<"not placing onto map" + <addActiveObject(obj); + + infostream<<"Dropped object"<inventoryModified(c, from_inv); + + infostream<<"IDropAction::apply(): dropped " + <<"["<