summaryrefslogtreecommitdiff
path: root/src/equipment.cpp
diff options
context:
space:
mode:
authorDennis Friis <peavey@placid.dk>2008-11-06 16:46:18 +0000
committerDennis Friis <peavey@placid.dk>2008-11-06 16:46:18 +0000
commit87f43f7621dda3071ba189df6975cd0a0595165a (patch)
treefa5cf0603bbcc4ecb4506dd357124975a8534503 /src/equipment.cpp
parent9475a009e95a3f379a0e97bc66d1aab93ca24b34 (diff)
downloadmana-client-87f43f7621dda3071ba189df6975cd0a0595165a.tar.gz
mana-client-87f43f7621dda3071ba189df6975cd0a0595165a.tar.bz2
mana-client-87f43f7621dda3071ba189df6975cd0a0595165a.tar.xz
mana-client-87f43f7621dda3071ba189df6975cd0a0595165a.zip
Have equipment tied into player inventory instead of keeping its own list of pointers to items. This ensures the ressource is up-to-date and avoids crashes on stale item pointers.
Diffstat (limited to 'src/equipment.cpp')
-rw-r--r--src/equipment.cpp20
1 files changed, 8 insertions, 12 deletions
diff --git a/src/equipment.cpp b/src/equipment.cpp
index b54988a7..a8910d14 100644
--- a/src/equipment.cpp
+++ b/src/equipment.cpp
@@ -25,24 +25,20 @@
#include "equipment.h"
#include "item.h"
+#include "inventory.h"
+#include "localplayer.h"
Equipment::Equipment():
mArrows(0)
{
- std::fill_n(mEquipment, EQUIPMENT_SIZE, (Item*) 0);
+ std::fill_n(mEquipment, EQUIPMENT_SIZE, 0);
}
void
-Equipment::removeEquipment(Item *item)
+Equipment::setEquipment(int index, int inventoryIndex)
{
- Item **i = std::find(mEquipment, mEquipment + EQUIPMENT_SIZE, item);
- if (i != mEquipment + EQUIPMENT_SIZE) {
- *i = 0;
- }
-}
-
-void Equipment::setEquipment(int index, Item *item)
-{
- mEquipment[index] = item;
- item->setEquipped(true);
+ mEquipment[index] = inventoryIndex;
+ Item* item = player_node->getInventory()->getItem(inventoryIndex);
+ if (item)
+ item->setEquipped(true);
}