From 87f43f7621dda3071ba189df6975cd0a0595165a Mon Sep 17 00:00:00 2001 From: Dennis Friis Date: Thu, 6 Nov 2008 16:46:18 +0000 Subject: 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. --- src/equipment.cpp | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'src/equipment.cpp') 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); } -- cgit v1.2.3-70-g09d2