summaryrefslogtreecommitdiff
path: root/src/inventorymanager.cpp
diff options
context:
space:
mode:
authorLoic Blot <loic.blot@unix-experience.fr>2017-08-18 08:07:59 +0200
committerLoic Blot <loic.blot@unix-experience.fr>2017-08-18 08:07:59 +0200
commit1d086aee7cc193bed2f8ca09cc2e020f509378f1 (patch)
tree106347a80cefc8b4f9d884e669a573da653d4178 /src/inventorymanager.cpp
parent55ab4264dc3f42a4588de0cf52e8f0f88e4fd90e (diff)
downloadminetest-1d086aee7cc193bed2f8ca09cc2e020f509378f1.tar.gz
minetest-1d086aee7cc193bed2f8ca09cc2e020f509378f1.tar.bz2
minetest-1d086aee7cc193bed2f8ca09cc2e020f509378f1.zip
Modernize various files (part 2)
* range-based for loops * emplace_back instead of push_back * code style * C++ headers instead of C headers * Default operators * empty stl function
Diffstat (limited to 'src/inventorymanager.cpp')
-rw-r--r--src/inventorymanager.cpp34
1 files changed, 16 insertions, 18 deletions
diff --git a/src/inventorymanager.cpp b/src/inventorymanager.cpp
index 0d44e9cda..d4315f7a4 100644
--- a/src/inventorymanager.cpp
+++ b/src/inventorymanager.cpp
@@ -774,17 +774,15 @@ void ICraftAction::apply(InventoryManager *mgr,
// Add the new replacements to the list
IItemDefManager *itemdef = gamedef->getItemDefManager();
- for (std::vector<ItemStack>::iterator it = temp.begin();
- it != temp.end(); ++it) {
- for (std::vector<ItemStack>::iterator jt = output_replacements.begin();
- jt != output_replacements.end(); ++jt) {
- if (it->name == jt->name) {
- *it = jt->addItem(*it, itemdef);
- if (it->empty())
+ for (auto &itemstack : temp) {
+ for (auto &output_replacement : output_replacements) {
+ if (itemstack.name == output_replacement.name) {
+ itemstack = output_replacement.addItem(itemstack, itemdef);
+ if (itemstack.empty())
continue;
}
}
- output_replacements.push_back(*it);
+ output_replacements.push_back(itemstack);
}
actionstream << player->getDescription()
@@ -795,7 +793,8 @@ void ICraftAction::apply(InventoryManager *mgr,
// Decrement counter
if (count_remaining == 1)
break;
- else if (count_remaining > 1)
+
+ if (count_remaining > 1)
count_remaining--;
// Get next crafting result
@@ -806,24 +805,23 @@ void ICraftAction::apply(InventoryManager *mgr,
// Put the replacements in the inventory or drop them on the floor, if
// the invenotry is full
- for (std::vector<ItemStack>::iterator it = output_replacements.begin();
- it != output_replacements.end(); ++it) {
+ for (auto &output_replacement : output_replacements) {
if (list_main)
- *it = list_main->addItem(*it);
- if (it->empty())
+ output_replacement = list_main->addItem(output_replacement);
+ if (output_replacement.empty())
continue;
- u16 count = it->count;
+ u16 count = output_replacement.count;
do {
- PLAYER_TO_SA(player)->item_OnDrop(*it, player,
+ PLAYER_TO_SA(player)->item_OnDrop(output_replacement, player,
player->getBasePosition());
- if (count >= it->count) {
+ if (count >= output_replacement.count) {
errorstream << "Couldn't drop replacement stack " <<
- it->getItemString() << " because drop loop didn't "
+ output_replacement.getItemString() << " because drop loop didn't "
"decrease count." << std::endl;
break;
}
- } while (!it->empty());
+ } while (!output_replacement.empty());
}
infostream<<"ICraftAction::apply(): crafted "