aboutsummaryrefslogtreecommitdiff
path: root/src/inventorymanager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/inventorymanager.cpp')
-rw-r--r--src/inventorymanager.cpp313
1 files changed, 152 insertions, 161 deletions
diff --git a/src/inventorymanager.cpp b/src/inventorymanager.cpp
index b6f464901..6b5a79fd9 100644
--- a/src/inventorymanager.cpp
+++ b/src/inventorymanager.cpp
@@ -29,7 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "util/strfnd.h"
#include "util/basic_macros.h"
-#define PLAYER_TO_SA(p) p->getEnv()->getScriptIface()
+#define PLAYER_TO_SA(p) p->getEnv()->getScriptIface()
/*
InventoryLocation
@@ -46,19 +46,19 @@ void InventoryLocation::serialize(std::ostream &os) const
{
switch (type) {
case InventoryLocation::UNDEFINED:
- os<<"undefined";
+ os << "undefined";
break;
case InventoryLocation::CURRENT_PLAYER:
- os<<"current_player";
+ os << "current_player";
break;
case InventoryLocation::PLAYER:
- os<<"player:"<<name;
+ os << "player:" << name;
break;
case InventoryLocation::NODEMETA:
- os<<"nodemeta:"<<p.X<<","<<p.Y<<","<<p.Z;
+ os << "nodemeta:" << p.X << "," << p.Y << "," << p.Z;
break;
case InventoryLocation::DETACHED:
- os<<"detached:"<<name;
+ os << "detached:" << name;
break;
default:
FATAL_ERROR("Unhandled inventory location type");
@@ -88,7 +88,8 @@ void InventoryLocation::deSerialize(std::istream &is)
type = InventoryLocation::DETACHED;
std::getline(is, name, '\n');
} else {
- infostream<<"Unknown InventoryLocation type=\""<<tname<<"\""<<std::endl;
+ infostream << "Unknown InventoryLocation type=\"" << tname << "\""
+ << std::endl;
throw SerializationError("Unknown InventoryLocation type");
}
}
@@ -127,8 +128,7 @@ InventoryAction *InventoryAction::deSerialize(std::istream &is)
IMoveAction
*/
-IMoveAction::IMoveAction(std::istream &is, bool somewhere) :
- move_somewhere(somewhere)
+IMoveAction::IMoveAction(std::istream &is, bool somewhere) : move_somewhere(somewhere)
{
std::string ts;
@@ -154,21 +154,23 @@ IMoveAction::IMoveAction(std::istream &is, bool somewhere) :
}
}
-void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGameDef *gamedef)
+void IMoveAction::apply(
+ InventoryManager *mgr, ServerActiveObject *player, IGameDef *gamedef)
{
Inventory *inv_from = mgr->getInventory(from_inv);
Inventory *inv_to = mgr->getInventory(to_inv);
if (!inv_from) {
infostream << "IMoveAction::apply(): FAIL: source inventory not found: "
- << "from_inv=\""<<from_inv.dump() << "\""
- << ", to_inv=\"" << to_inv.dump() << "\"" << std::endl;
+ << "from_inv=\"" << from_inv.dump() << "\""
+ << ", to_inv=\"" << to_inv.dump() << "\"" << std::endl;
return;
}
if (!inv_to) {
- infostream << "IMoveAction::apply(): FAIL: destination inventory not found: "
- << "from_inv=\"" << from_inv.dump() << "\""
- << ", to_inv=\"" << to_inv.dump() << "\"" << std::endl;
+ infostream << "IMoveAction::apply(): FAIL: destination inventory not "
+ "found: "
+ << "from_inv=\"" << from_inv.dump() << "\""
+ << ", to_inv=\"" << to_inv.dump() << "\"" << std::endl;
return;
}
@@ -180,14 +182,14 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
*/
if (!list_from) {
infostream << "IMoveAction::apply(): FAIL: source list not found: "
- << "from_inv=\"" << from_inv.dump() << "\""
- << ", from_list=\"" << from_list << "\"" << std::endl;
+ << "from_inv=\"" << from_inv.dump() << "\""
+ << ", from_list=\"" << from_list << "\"" << std::endl;
return;
}
if (!list_to) {
infostream << "IMoveAction::apply(): FAIL: destination list not found: "
- << "to_inv=\""<<to_inv.dump() << "\""
- << ", to_list=\"" << to_list << "\"" << std::endl;
+ << "to_inv=\"" << to_inv.dump() << "\""
+ << ", to_list=\"" << to_list << "\"" << std::endl;
return;
}
@@ -198,14 +200,11 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
move_somewhere = false;
infostream << "IMoveAction::apply(): moving item somewhere"
- << " msom=" << move_somewhere
- << " count=" << count
- << " from inv=\"" << from_inv.dump() << "\""
- << " list=\"" << from_list << "\""
- << " i=" << from_i
- << " to inv=\"" << to_inv.dump() << "\""
- << " list=\"" << to_list << "\""
- << std::endl;
+ << " msom=" << move_somewhere << " count=" << count
+ << " from inv=\"" << from_inv.dump() << "\""
+ << " list=\"" << from_list << "\""
+ << " i=" << from_i << " to inv=\"" << to_inv.dump() << "\""
+ << " list=\"" << to_list << "\"" << std::endl;
// Try to add the item to destination list
s16 dest_size = list_to->getSize();
@@ -235,17 +234,17 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
}
if ((u16)to_i > list_to->getSize()) {
- infostream << "IMoveAction::apply(): FAIL: destination index out of bounds: "
- << "to_i=" << to_i
- << ", size=" << list_to->getSize() << std::endl;
+ infostream << "IMoveAction::apply(): FAIL: destination index out of "
+ "bounds: "
+ << "to_i=" << to_i << ", size=" << list_to->getSize()
+ << std::endl;
return;
}
/*
Do not handle rollback if both inventories are that of the same player
*/
- bool ignore_rollback = (
- from_inv.type == InventoryLocation::PLAYER &&
- from_inv == to_inv);
+ bool ignore_rollback = (from_inv.type == InventoryLocation::PLAYER &&
+ from_inv == to_inv);
/*
Collect information of endpoints
@@ -261,25 +260,28 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
/* Query detached inventories */
// Move occurs in the same detached inventory
- if (from_inv.type == InventoryLocation::DETACHED &&
- from_inv == to_inv) {
+ if (from_inv.type == InventoryLocation::DETACHED && from_inv == to_inv) {
src_can_take_count = PLAYER_TO_SA(player)->detached_inventory_AllowMove(
- *this, try_take_count, player);
+ *this, try_take_count, player);
dst_can_put_count = src_can_take_count;
} else {
// Destination is detached
if (to_inv.type == InventoryLocation::DETACHED) {
ItemStack src_item = list_from->getItem(from_i);
src_item.count = try_take_count;
- dst_can_put_count = PLAYER_TO_SA(player)->detached_inventory_AllowPut(
- *this, src_item, player);
+ dst_can_put_count =
+ PLAYER_TO_SA(player)->detached_inventory_AllowPut(
+ *this, src_item, player);
}
// Source is detached
if (from_inv.type == InventoryLocation::DETACHED) {
ItemStack src_item = list_from->getItem(from_i);
src_item.count = try_take_count;
- src_can_take_count = PLAYER_TO_SA(player)->detached_inventory_AllowTake(
- *this, src_item, player);
+ src_can_take_count =
+ PLAYER_TO_SA(player)
+ ->detached_inventory_AllowTake(
+ *this, src_item,
+ player);
}
}
@@ -287,50 +289,54 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
// Both endpoints are nodemeta
// Move occurs in the same nodemeta inventory
- if (from_inv.type == InventoryLocation::NODEMETA &&
- from_inv == to_inv) {
+ if (from_inv.type == InventoryLocation::NODEMETA && from_inv == to_inv) {
src_can_take_count = PLAYER_TO_SA(player)->nodemeta_inventory_AllowMove(
- *this, try_take_count, player);
+ *this, try_take_count, player);
dst_can_put_count = src_can_take_count;
} else {
// Destination is nodemeta
if (to_inv.type == InventoryLocation::NODEMETA) {
ItemStack src_item = list_from->getItem(from_i);
src_item.count = try_take_count;
- dst_can_put_count = PLAYER_TO_SA(player)->nodemeta_inventory_AllowPut(
- *this, src_item, player);
+ dst_can_put_count =
+ PLAYER_TO_SA(player)->nodemeta_inventory_AllowPut(
+ *this, src_item, player);
}
// Source is nodemeta
if (from_inv.type == InventoryLocation::NODEMETA) {
ItemStack src_item = list_from->getItem(from_i);
src_item.count = try_take_count;
- src_can_take_count = PLAYER_TO_SA(player)->nodemeta_inventory_AllowTake(
- *this, src_item, player);
+ src_can_take_count =
+ PLAYER_TO_SA(player)
+ ->nodemeta_inventory_AllowTake(
+ *this, src_item,
+ player);
}
}
// Query player inventories
// Move occurs in the same player inventory
- if (from_inv.type == InventoryLocation::PLAYER &&
- from_inv == to_inv) {
+ if (from_inv.type == InventoryLocation::PLAYER && from_inv == to_inv) {
src_can_take_count = PLAYER_TO_SA(player)->player_inventory_AllowMove(
- *this, try_take_count, player);
+ *this, try_take_count, player);
dst_can_put_count = src_can_take_count;
} else {
// Destination is a player
if (to_inv.type == InventoryLocation::PLAYER) {
ItemStack src_item = list_from->getItem(from_i);
src_item.count = try_take_count;
- dst_can_put_count = PLAYER_TO_SA(player)->player_inventory_AllowPut(
- *this, src_item, player);
+ dst_can_put_count =
+ PLAYER_TO_SA(player)->player_inventory_AllowPut(
+ *this, src_item, player);
}
// Source is a player
if (from_inv.type == InventoryLocation::PLAYER) {
ItemStack src_item = list_from->getItem(from_i);
src_item.count = try_take_count;
- src_can_take_count = PLAYER_TO_SA(player)->player_inventory_AllowTake(
- *this, src_item, player);
+ src_can_take_count =
+ PLAYER_TO_SA(player)->player_inventory_AllowTake(
+ *this, src_item, player);
}
}
@@ -355,15 +361,13 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
if (to_inv.type == InventoryLocation::PLAYER)
list_to->setModified();
- infostream<<"IMoveAction::apply(): move was completely disallowed:"
- <<" count="<<old_count
- <<" from inv=\""<<from_inv.dump()<<"\""
- <<" list=\""<<from_list<<"\""
- <<" i="<<from_i
- <<" to inv=\""<<to_inv.dump()<<"\""
- <<" list=\""<<to_list<<"\""
- <<" i="<<to_i
- <<std::endl;
+ infostream << "IMoveAction::apply(): move was completely disallowed:"
+ << " count=" << old_count << " from inv=\"" << from_inv.dump()
+ << "\""
+ << " list=\"" << from_list << "\""
+ << " i=" << from_i << " to inv=\"" << to_inv.dump() << "\""
+ << " list=\"" << to_list << "\""
+ << " i=" << to_i << std::endl;
return;
}
@@ -379,19 +383,19 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
same as source), nothing happens
*/
bool did_swap = false;
- move_count = list_from->moveItem(from_i,
- list_to, to_i, count, !caused_by_move_somewhere, &did_swap);
+ move_count = list_from->moveItem(from_i, list_to, to_i, count,
+ !caused_by_move_somewhere, &did_swap);
// If source is infinite, reset it's stack
if (src_can_take_count == -1) {
- // For the caused_by_move_somewhere == true case we didn't force-put the item,
- // which guarantees there is no leftover, and code below would duplicate the
- // (not replaced) to_stack_was item.
+ // For the caused_by_move_somewhere == true case we didn't force-put the
+ // item, which guarantees there is no leftover, and code below would
+ // duplicate the (not replaced) to_stack_was item.
if (!caused_by_move_somewhere) {
- // If destination stack is of different type and there are leftover
- // items, attempt to put the leftover items to a different place in the
- // destination inventory.
- // The client-side GUI will try to guess if this happens.
+ // If destination stack is of different type and there are
+ // leftover items, attempt to put the leftover items to a
+ // different place in the destination inventory. The client-side
+ // GUI will try to guess if this happens.
if (from_stack_was.name != to_stack_was.name) {
for (u32 i = 0; i < list_to->getSize(); i++) {
if (list_to->getItem(i).empty()) {
@@ -416,16 +420,12 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
}
infostream << "IMoveAction::apply(): moved"
- << " msom=" << move_somewhere
- << " caused=" << caused_by_move_somewhere
- << " count=" << count
- << " from inv=\"" << from_inv.dump() << "\""
- << " list=\"" << from_list << "\""
- << " i=" << from_i
- << " to inv=\"" << to_inv.dump() << "\""
- << " list=\"" << to_list << "\""
- << " i=" << to_i
- << std::endl;
+ << " msom=" << move_somewhere << " caused=" << caused_by_move_somewhere
+ << " count=" << count << " from inv=\"" << from_inv.dump() << "\""
+ << " list=\"" << from_list << "\""
+ << " i=" << from_i << " to inv=\"" << to_inv.dump() << "\""
+ << " list=\"" << to_list << "\""
+ << " i=" << to_i << std::endl;
// If we are inside the move somewhere loop, we don't need to report
// anything if nothing happened (perhaps we don't need to report
@@ -448,8 +448,8 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
from_inv.serialize(os);
loc = os.str();
}
- action.setModifyInventoryStack(loc, from_list, from_i, false,
- src_item);
+ action.setModifyInventoryStack(
+ loc, from_list, from_i, false, src_item);
rollback->reportAction(action);
}
// If destination is not infinite, record item put
@@ -461,8 +461,8 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
to_inv.serialize(os);
loc = os.str();
}
- action.setModifyInventoryStack(loc, to_list, to_i, true,
- src_item);
+ action.setModifyInventoryStack(
+ loc, to_list, to_i, true, src_item);
rollback->reportAction(action);
}
}
@@ -474,60 +474,54 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
/* Detached inventories */
// Both endpoints are same detached
- if (from_inv.type == InventoryLocation::DETACHED &&
- from_inv == to_inv) {
- PLAYER_TO_SA(player)->detached_inventory_OnMove(
- *this, count, player);
+ if (from_inv.type == InventoryLocation::DETACHED && from_inv == to_inv) {
+ PLAYER_TO_SA(player)->detached_inventory_OnMove(*this, count, player);
} else {
// Destination is detached
if (to_inv.type == InventoryLocation::DETACHED) {
PLAYER_TO_SA(player)->detached_inventory_OnPut(
- *this, src_item, player);
+ *this, src_item, player);
}
// Source is detached
if (from_inv.type == InventoryLocation::DETACHED) {
PLAYER_TO_SA(player)->detached_inventory_OnTake(
- *this, src_item, player);
+ *this, src_item, player);
}
}
/* Node metadata inventories */
// Both endpoints are same nodemeta
- if (from_inv.type == InventoryLocation::NODEMETA &&
- from_inv == to_inv) {
- PLAYER_TO_SA(player)->nodemeta_inventory_OnMove(
- *this, count, player);
+ if (from_inv.type == InventoryLocation::NODEMETA && from_inv == to_inv) {
+ PLAYER_TO_SA(player)->nodemeta_inventory_OnMove(*this, count, player);
} else {
// Destination is nodemeta
if (to_inv.type == InventoryLocation::NODEMETA) {
PLAYER_TO_SA(player)->nodemeta_inventory_OnPut(
- *this, src_item, player);
+ *this, src_item, player);
}
// Source is nodemeta
if (from_inv.type == InventoryLocation::NODEMETA) {
PLAYER_TO_SA(player)->nodemeta_inventory_OnTake(
- *this, src_item, player);
+ *this, src_item, player);
}
}
// Player inventories
// Both endpoints are same player inventory
- if (from_inv.type == InventoryLocation::PLAYER &&
- from_inv == to_inv) {
- PLAYER_TO_SA(player)->player_inventory_OnMove(
- *this, count, player);
+ if (from_inv.type == InventoryLocation::PLAYER && from_inv == to_inv) {
+ PLAYER_TO_SA(player)->player_inventory_OnMove(*this, count, player);
} else {
// Destination is player inventory
if (to_inv.type == InventoryLocation::PLAYER) {
PLAYER_TO_SA(player)->player_inventory_OnPut(
- *this, src_item, player);
+ *this, src_item, player);
}
// Source is player inventory
if (from_inv.type == InventoryLocation::PLAYER) {
PLAYER_TO_SA(player)->player_inventory_OnTake(
- *this, src_item, player);
+ *this, src_item, player);
}
}
@@ -587,13 +581,14 @@ IDropAction::IDropAction(std::istream &is)
from_i = stoi(ts);
}
-void IDropAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGameDef *gamedef)
+void IDropAction::apply(
+ InventoryManager *mgr, ServerActiveObject *player, IGameDef *gamedef)
{
Inventory *inv_from = mgr->getInventory(from_inv);
if (!inv_from) {
- infostream<<"IDropAction::apply(): FAIL: source inventory not found: "
- <<"from_inv=\""<<from_inv.dump()<<"\""<<std::endl;
+ infostream << "IDropAction::apply(): FAIL: source inventory not found: "
+ << "from_inv=\"" << from_inv.dump() << "\"" << std::endl;
return;
}
@@ -603,15 +598,15 @@ void IDropAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
If a list doesn't exist or the source item doesn't exist
*/
if (!list_from) {
- infostream<<"IDropAction::apply(): FAIL: source list not found: "
- <<"from_inv=\""<<from_inv.dump()<<"\""<<std::endl;
+ infostream << "IDropAction::apply(): FAIL: source list not found: "
+ << "from_inv=\"" << from_inv.dump() << "\"" << std::endl;
return;
}
if (list_from->getItem(from_i).empty()) {
- infostream<<"IDropAction::apply(): FAIL: source item not found: "
- <<"from_inv=\""<<from_inv.dump()<<"\""
- <<", from_list=\""<<from_list<<"\""
- <<" from_i="<<from_i<<std::endl;
+ infostream << "IDropAction::apply(): FAIL: source item not found: "
+ << "from_inv=\"" << from_inv.dump() << "\""
+ << ", from_list=\"" << from_list << "\""
+ << " from_i=" << from_i << std::endl;
return;
}
@@ -636,15 +631,15 @@ void IDropAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
switch (from_inv.type) {
case InventoryLocation::DETACHED:
src_can_take_count = PLAYER_TO_SA(player)->detached_inventory_AllowTake(
- *this, src_item, player);
+ *this, src_item, player);
break;
case InventoryLocation::NODEMETA:
src_can_take_count = PLAYER_TO_SA(player)->nodemeta_inventory_AllowTake(
- *this, src_item, player);
+ *this, src_item, player);
break;
case InventoryLocation::PLAYER:
src_can_take_count = PLAYER_TO_SA(player)->player_inventory_AllowTake(
- *this, src_item, player);
+ *this, src_item, player);
break;
default:
break;
@@ -659,12 +654,11 @@ void IDropAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
// Drop the item
ItemStack item1 = list_from->getItem(from_i);
item1.count = take_count;
- if(PLAYER_TO_SA(player)->item_OnDrop(item1, player,
- player->getBasePosition())) {
+ if (PLAYER_TO_SA(player)->item_OnDrop(item1, player, player->getBasePosition())) {
int actually_dropped_count = take_count - item1.count;
if (actually_dropped_count == 0) {
- infostream<<"Actually dropped no items"<<std::endl;
+ infostream << "Actually dropped no items" << std::endl;
// Revert client prediction. See 'clientApply'
if (from_inv.type == InventoryLocation::PLAYER)
@@ -675,22 +669,22 @@ void IDropAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
// If source isn't infinite
if (src_can_take_count != -1) {
// Take item from source list
- ItemStack item2 = list_from->takeItem(from_i, actually_dropped_count);
+ ItemStack item2 = list_from->takeItem(
+ from_i, actually_dropped_count);
if (item2.count != actually_dropped_count)
- errorstream<<"Could not take dropped count of items"<<std::endl;
+ errorstream << "Could not take dropped count of items"
+ << std::endl;
}
src_item.count = actually_dropped_count;
mgr->setInventoryModified(from_inv);
}
- infostream<<"IDropAction::apply(): dropped "
- <<" from inv=\""<<from_inv.dump()<<"\""
- <<" list=\""<<from_list<<"\""
- <<" i="<<from_i
- <<std::endl;
-
+ infostream << "IDropAction::apply(): dropped "
+ << " from inv=\"" << from_inv.dump() << "\""
+ << " list=\"" << from_list << "\""
+ << " i=" << from_i << std::endl;
/*
Report drop to endpoints
@@ -698,16 +692,13 @@ void IDropAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
switch (from_inv.type) {
case InventoryLocation::DETACHED:
- PLAYER_TO_SA(player)->detached_inventory_OnTake(
- *this, src_item, player);
+ PLAYER_TO_SA(player)->detached_inventory_OnTake(*this, src_item, player);
break;
case InventoryLocation::NODEMETA:
- PLAYER_TO_SA(player)->nodemeta_inventory_OnTake(
- *this, src_item, player);
+ PLAYER_TO_SA(player)->nodemeta_inventory_OnTake(*this, src_item, player);
break;
case InventoryLocation::PLAYER:
- PLAYER_TO_SA(player)->player_inventory_OnTake(
- *this, src_item, player);
+ PLAYER_TO_SA(player)->player_inventory_OnTake(*this, src_item, player);
break;
default:
break;
@@ -728,8 +719,8 @@ void IDropAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
from_inv.serialize(os);
loc = os.str();
}
- action.setModifyInventoryStack(loc, from_list, from_i,
- false, src_item);
+ action.setModifyInventoryStack(
+ loc, from_list, from_i, false, src_item);
rollback->reportAction(action);
}
}
@@ -777,14 +768,14 @@ ICraftAction::ICraftAction(std::istream &is)
craft_inv.deSerialize(ts);
}
-void ICraftAction::apply(InventoryManager *mgr,
- ServerActiveObject *player, IGameDef *gamedef)
+void ICraftAction::apply(
+ InventoryManager *mgr, ServerActiveObject *player, IGameDef *gamedef)
{
Inventory *inv_craft = mgr->getInventory(craft_inv);
if (!inv_craft) {
infostream << "ICraftAction::apply(): FAIL: inventory not found: "
- << "craft_inv=\"" << craft_inv.dump() << "\"" << std::endl;
+ << "craft_inv=\"" << craft_inv.dump() << "\"" << std::endl;
return;
}
@@ -797,17 +788,17 @@ void ICraftAction::apply(InventoryManager *mgr,
*/
if (!list_craft) {
infostream << "ICraftAction::apply(): FAIL: craft list not found: "
- << "craft_inv=\"" << craft_inv.dump() << "\"" << std::endl;
+ << "craft_inv=\"" << craft_inv.dump() << "\"" << std::endl;
return;
}
if (!list_craftresult) {
infostream << "ICraftAction::apply(): FAIL: craftresult list not found: "
- << "craft_inv=\"" << craft_inv.dump() << "\"" << std::endl;
+ << "craft_inv=\"" << craft_inv.dump() << "\"" << std::endl;
return;
}
if (list_craftresult->getSize() < 1) {
infostream << "ICraftAction::apply(): FAIL: craftresult list too short: "
- << "craft_inv=\"" << craft_inv.dump() << "\"" << std::endl;
+ << "craft_inv=\"" << craft_inv.dump() << "\"" << std::endl;
return;
}
@@ -825,7 +816,8 @@ void ICraftAction::apply(InventoryManager *mgr,
std::vector<ItemStack> temp;
// Decrement input and add crafting output
getCraftingResult(inv_craft, crafted, temp, true, gamedef);
- PLAYER_TO_SA(player)->item_OnCraft(crafted, player, &saved_craft_list, craft_inv);
+ PLAYER_TO_SA(player)->item_OnCraft(
+ crafted, player, &saved_craft_list, craft_inv);
list_craftresult->addItem(0, crafted);
mgr->setInventoryModified(craft_inv);
@@ -834,7 +826,8 @@ void ICraftAction::apply(InventoryManager *mgr,
for (auto &itemstack : temp) {
for (auto &output_replacement : output_replacements) {
if (itemstack.name == output_replacement.name) {
- itemstack = output_replacement.addItem(itemstack, itemdef);
+ itemstack = output_replacement.addItem(
+ itemstack, itemdef);
if (itemstack.empty())
continue;
}
@@ -842,10 +835,8 @@ void ICraftAction::apply(InventoryManager *mgr,
output_replacements.push_back(itemstack);
}
- actionstream << player->getDescription()
- << " crafts "
- << crafted.getItemString()
- << std::endl;
+ actionstream << player->getDescription() << " crafts "
+ << crafted.getItemString() << std::endl;
// Decrement counter
if (count_remaining == 1)
@@ -856,7 +847,8 @@ void ICraftAction::apply(InventoryManager *mgr,
// Get next crafting result
getCraftingResult(inv_craft, crafted, temp, false, gamedef);
- PLAYER_TO_SA(player)->item_CraftPredict(crafted, player, list_craft, craft_inv);
+ PLAYER_TO_SA(player)->item_CraftPredict(
+ crafted, player, list_craft, craft_inv);
found = !crafted.empty();
}
@@ -870,20 +862,21 @@ void ICraftAction::apply(InventoryManager *mgr,
u16 count = output_replacement.count;
do {
PLAYER_TO_SA(player)->item_OnDrop(output_replacement, player,
- player->getBasePosition());
+ player->getBasePosition());
if (count >= output_replacement.count) {
- errorstream << "Couldn't drop replacement stack " <<
- output_replacement.getItemString() << " because drop loop didn't "
- "decrease count." << std::endl;
+ errorstream << "Couldn't drop replacement stack "
+ << output_replacement.getItemString()
+ << " because drop loop didn't "
+ "decrease count."
+ << std::endl;
break;
}
} while (!output_replacement.empty());
}
- infostream<<"ICraftAction::apply(): crafted "
- <<" craft_inv=\""<<craft_inv.dump()<<"\""
- <<std::endl;
+ infostream << "ICraftAction::apply(): crafted "
+ << " craft_inv=\"" << craft_inv.dump() << "\"" << std::endl;
}
void ICraftAction::clientApply(InventoryManager *mgr, IGameDef *gamedef)
@@ -892,11 +885,10 @@ void ICraftAction::clientApply(InventoryManager *mgr, IGameDef *gamedef)
// to make lag less apparent.
}
-
// 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)
{
result.clear();
@@ -909,7 +901,7 @@ bool getCraftingResult(Inventory *inv, ItemStack &result,
CraftInput ci;
ci.method = CRAFT_METHOD_NORMAL;
ci.width = clist->getWidth() ? clist->getWidth() : 3;
- for (u16 i=0; i < clist->getSize(); i++)
+ for (u16 i = 0; i < clist->getSize(); i++)
ci.items.push_back(clist->getItem(i));
// Find out what is crafted and add it to result item slot
@@ -921,11 +913,10 @@ bool getCraftingResult(Inventory *inv, ItemStack &result,
if (found && decrementInput) {
// CraftInput has been changed, apply changes in clist
- for (u16 i=0; i < clist->getSize(); i++) {
+ for (u16 i = 0; i < clist->getSize(); i++) {
clist->changeItem(i, ci.items[i]);
}
}
return found;
}
-