X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Finventorymanager.cpp;h=1c511e9cbe69f7659e70e8a7a1d5e172285af73b;hb=b8ba6318d6ed9edd59455674d39ff1d5018393df;hp=b42a80673574b15398d14b4670fe606f3c3a90d6;hpb=1efdc36b22532807d21a0beac94524e3eacfe7bc;p=minetest.git diff --git a/src/inventorymanager.cpp b/src/inventorymanager.cpp index b42a80673..1c511e9cb 100644 --- a/src/inventorymanager.cpp +++ b/src/inventorymanager.cpp @@ -1,18 +1,18 @@ /* -Minetest-c55 -Copyright (C) 2010-2011 celeron55, Perttu Ahola +Minetest +Copyright (C) 2010-2013 celeron55, Perttu Ahola This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. +GNU Lesser General Public License for more details. -You should have received a copy of the GNU General Public License along +You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ @@ -20,12 +20,16 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "inventorymanager.h" #include "log.h" #include "environment.h" -#include "scriptapi.h" +#include "scripting_game.h" #include "serverobject.h" #include "main.h" // for g_settings #include "settings.h" -#include "utility.h" #include "craftdef.h" +#include "rollback_interface.h" + +#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")" + +#define PLAYER_TO_SA(p) p->getEnv()->getScriptIface() /* InventoryLocation @@ -40,30 +44,25 @@ std::string InventoryLocation::dump() const void InventoryLocation::serialize(std::ostream &os) const { - switch(type){ - case InventoryLocation::UNDEFINED: - { + switch(type){ + case InventoryLocation::UNDEFINED: os<<"undefined"; - } - break; - case InventoryLocation::CURRENT_PLAYER: - { + break; + case InventoryLocation::CURRENT_PLAYER: os<<"current_player"; - } - break; - case InventoryLocation::PLAYER: - { + break; + case InventoryLocation::PLAYER: os<<"player:"<getItem(from_i).empty()) - { - infostream<<"IMoveAction::apply(): FAIL: source item not found: " - <<"from_inv=\""< src_can_take_count) + count = src_can_take_count; + if(dst_can_put_count != -1 && count > dst_can_put_count) + count = dst_can_put_count; + /* Limit according to source item count */ + if(count > list_from->getItem(from_i).count) + count = list_from->getItem(from_i).count; + + /* If no items will be moved, don't go further */ + if(count == 0) + { + infostream<<"IMoveAction::apply(): move was completely disallowed:" + <<" count="<takeItem(from_i, actually_dropped_count); - list_from->addItem(from_i, item2); + if(item2.count != actually_dropped_count) + errorstream<<"Could not take dropped count of items"<setInventoryModified(from_inv); + } } infostream<<"IDropAction::apply(): dropped " @@ -336,8 +605,81 @@ void IDropAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame <<" list=\""<getList("craft"); - if(!clist || clist->getSize() != 9) + if(!clist) return false; // Mangle crafting grid to an another format CraftInput ci; ci.method = CRAFT_METHOD_NORMAL; - ci.width = 3; - for(u16 i=0; i<9; i++) + ci.width = clist->getWidth() ? clist->getWidth() : 3; + for(u16 i=0; igetSize(); i++) ci.items.push_back(clist->getItem(i)); // Find out what is crafted and add it to result item slot @@ -445,7 +799,7 @@ bool getCraftingResult(Inventory *inv, ItemStack& result, if(found && decrementInput) { // CraftInput has been changed, apply changes in clist - for(u16 i=0; i<9; i++) + for(u16 i=0; igetSize(); i++) { clist->changeItem(i, ci.items[i]); }