summaryrefslogtreecommitdiff
path: root/src/game-server/inventory.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game-server/inventory.cpp')
-rw-r--r--src/game-server/inventory.cpp45
1 files changed, 17 insertions, 28 deletions
diff --git a/src/game-server/inventory.cpp b/src/game-server/inventory.cpp
index 4b15f4cf..9468001e 100644
--- a/src/game-server/inventory.cpp
+++ b/src/game-server/inventory.cpp
@@ -66,10 +66,9 @@ void Inventory::initialize()
/*
* Set the equipment slots
*/
- for (auto it = mPoss->equipment.begin(),
- it_end = mPoss->equipment.end(); it != it_end; ++it)
+ for (int it : mPoss->equipment)
{
- auto itemIt = mPoss->inventory.find(*it);
+ auto itemIt = mPoss->inventory.find(it);
const ItemEquipRequirement &equipReq = itemManager->getItem(
itemIt->second.itemId)->getItemEquipRequirement();
itemIt->second.equipmentSlot = equipReq.equipSlotId;
@@ -207,11 +206,10 @@ unsigned Inventory::insert(unsigned itemId, unsigned amount)
unsigned Inventory::count(unsigned itemId) const
{
unsigned nb = 0;
- for (auto it = mPoss->inventory.begin(),
- it_end = mPoss->inventory.end(); it != it_end; ++it)
+ for (auto &it : mPoss->inventory)
{
- if (it->second.itemId == itemId)
- nb += it->second.amount;
+ if (it.second.itemId == itemId)
+ nb += it.second.amount;
}
return nb;
@@ -219,10 +217,9 @@ unsigned Inventory::count(unsigned itemId) const
int Inventory::getFirstSlot(unsigned itemId)
{
- for (auto it = mPoss->inventory.begin(),
- it_end = mPoss->inventory.end(); it != it_end; ++it)
- if (it->second.itemId == itemId)
- return (int)it->first;
+ for (auto &it : mPoss->inventory)
+ if (it.second.itemId == itemId)
+ return (int)it.first;
return -1;
}
@@ -304,12 +301,10 @@ unsigned Inventory::removeFromSlot(unsigned slot, unsigned amount)
MessageOut invMsg(GPMSG_INVENTORY);
// Check if an item of the same id exists elsewhere in the inventory
bool exists = false;
- for (InventoryData::const_iterator it2 = mPoss->inventory.begin(),
- it2_end = mPoss->inventory.end();
- it2 != it2_end; ++it2)
+ for (const auto &it2 : mPoss->inventory)
{
- if (it2->second.itemId == it->second.itemId
- && it->first != it2->first)
+ if (it2.second.itemId == it->second.itemId
+ && it->first != it2.first)
{
exists = true;
break;
@@ -382,10 +377,9 @@ bool Inventory::checkEquipmentCapacity(unsigned equipmentSlot,
return false;
// Test whether the slot capacity requested is reached.
- for (auto it = mPoss->equipment.begin(),
- it_end = mPoss->equipment.end(); it != it_end; ++it)
+ for (int it : mPoss->equipment)
{
- auto itemIt = mPoss->inventory.find(*it);
+ auto itemIt = mPoss->inventory.find(it);
if (itemIt->second.equipmentSlot == equipmentSlot)
{
const int itemId = itemIt->second.itemId;
@@ -460,10 +454,8 @@ bool Inventory::equip(int inventorySlot)
&& hasInventoryEnoughSpace(equipReq.equipSlotId))
{
// Then, we unequip each iteminstance of the equip slot
- for (auto it = mPoss->equipment.begin(),
- it_end = mPoss->equipment.end(); it != it_end; ++it)
+ for (unsigned int slot : mPoss->equipment)
{
- const unsigned slot = *it;
auto itemIt = mPoss->inventory.find(slot);
assert(itemIt != mPoss->inventory.end());
if (itemIt->second.equipmentSlot == equipReq.equipSlotId) {
@@ -481,18 +473,15 @@ bool Inventory::equip(int inventorySlot)
}
// Potential Pre-unequipment process
- for (auto itemsToUnequip =
- slotsToUnequipFirst.begin(),
- itemsToUnequip_end = slotsToUnequipFirst.end();
- itemsToUnequip != itemsToUnequip_end; ++itemsToUnequip)
+ for (unsigned int itemsToUnequip : slotsToUnequipFirst)
{
- if (!unequip(*itemsToUnequip))
+ if (!unequip(itemsToUnequip))
{
// Something went wrong even when we tested the unequipment process.
LOG_WARN("Unable to unequip even when unequip was tested. "
"Character : "
<< mCharacter->getComponent<BeingComponent>()->getName()
- << ", unequip slot: " << *itemsToUnequip);
+ << ", unequip slot: " << itemsToUnequip);
return false;
}
}