summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIra Rice <irarice@gmail.com>2008-11-06 17:44:35 +0000
committerIra Rice <irarice@gmail.com>2008-11-06 17:44:35 +0000
commit0db6dce98d9c07b569dd29207979818f114f7a32 (patch)
tree3ae317c611a6e1d530b7d5e2b693ffc554aaa920 /src
parentcb81caa6ddbe1861d7b276d48f337dd8841d68c1 (diff)
downloadmana-0db6dce98d9c07b569dd29207979818f114f7a32.tar.gz
mana-0db6dce98d9c07b569dd29207979818f114f7a32.tar.bz2
mana-0db6dce98d9c07b569dd29207979818f114f7a32.tar.xz
mana-0db6dce98d9c07b569dd29207979818f114f7a32.zip
Ported a patch by Peavey on TMW to keep all item pointers inside of
inventory. For us, this should get rid of the arrow crashing bug, if it still exists (been a few weeks since I've heard of it happening now).
Diffstat (limited to 'src')
-rw-r--r--src/equipment.cpp29
-rw-r--r--src/equipment.h21
-rw-r--r--src/gui/equipmentwindow.cpp21
-rw-r--r--src/gui/equipmentwindow.h2
-rw-r--r--src/localplayer.cpp2
-rw-r--r--src/net/equipmenthandler.cpp8
6 files changed, 38 insertions, 45 deletions
diff --git a/src/equipment.cpp b/src/equipment.cpp
index b2d5e609..984df74d 100644
--- a/src/equipment.cpp
+++ b/src/equipment.cpp
@@ -21,36 +21,25 @@
* $Id: equipment.cpp 4347 2008-06-12 09:06:01Z b_lindeijer $
*/
-#include "equipment.h"
-
#include <algorithm>
+#include "equipment.h"
#include "item.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;
- }
+ mEquipment[index] = inventoryIndex;
+ Item* item = player_node->getInventory()->getItem(inventoryIndex);
+ if (item)
+ item->setEquipped(true);
}
-void Equipment::removeEquipment(int index)
-{
- if (index >= 0 && index < EQUIPMENT_SIZE)
- mEquipment[index] = 0;
-}
-
-void Equipment::setEquipment(int index, Item *item)
-{
- mEquipment[index] = item;
- item->setEquipped(true);
-}
diff --git a/src/equipment.h b/src/equipment.h
index 7977894a..8b2ce127 100644
--- a/src/equipment.h
+++ b/src/equipment.h
@@ -24,8 +24,6 @@
#ifndef _TMW_EQUIPMENT_H_
#define _TMW_EQUIPMENT_H_
-#include <guichan/actionlistener.hpp>
-
class Item;
#define EQUIPMENT_SIZE 10
@@ -41,41 +39,36 @@ class Equipment
/**
* Get equipment at the given slot.
*/
- Item* getEquipment(int index) const
+ int getEquipment(int index) const
{ return mEquipment[index]; }
/**
* Set equipment at the given slot.
*/
void
- setEquipment(int index, Item *item);
+ setEquipment(int index, int inventoryIndex);
/**
* Remove equipment from the given slot.
*/
void
- removeEquipment(int index);
-
- /**
- * Remove the given item from equipment.
- */
- void removeEquipment(Item *item);
+ removeEquipment(int index) { mEquipment[index] = 0; }
/**
* Get the item used in the arrow slot.
*/
- Item*
+ int
getArrows() { return mArrows; }
/**
* Set the item used in the arrow slot.
*/
void
- setArrows(Item *arrows) {mArrows = arrows;}
+ setArrows(int arrows) {mArrows = arrows;}
private:
- Item *mEquipment[EQUIPMENT_SIZE];
- Item *mArrows;
+ int mEquipment[EQUIPMENT_SIZE];
+ int mArrows;
};
#endif
diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp
index 564486aa..727ac732 100644
--- a/src/gui/equipmentwindow.cpp
+++ b/src/gui/equipmentwindow.cpp
@@ -25,7 +25,9 @@
#include "../equipment.h"
#include "../graphics.h"
+#include "../inventory.h"
#include "../item.h"
+#include "../localplayer.h"
#include "../log.h"
#include "../resources/iteminfo.h"
@@ -40,6 +42,7 @@ EquipmentWindow::EquipmentWindow(Equipment *equipment):
setCloseButton(true);
setDefaultSize(5, 230, 200, 120);
loadWindowState();
+ inventory = player_node->getInventory();
}
EquipmentWindow::~EquipmentWindow()
@@ -61,22 +64,28 @@ void EquipmentWindow::draw(gcn::Graphics *graphics)
graphics->drawRectangle(gcn::Rectangle(10 + 36 * (i % 4),
36 * (i / 4) + 25, 32, 32));
- if (!(item = mEquipment->getEquipment(i)))
+ if (!(item = inventory->getItem(mEquipment->getEquipment(i))))
continue;
image = item->getImage();
- static_cast<Graphics*>(graphics)->drawImage(
- image, 36 * (i % 4) + 10, 36 * (i / 4) + 25);
+ if (image)
+ {
+ static_cast<Graphics*>(graphics)->drawImage(
+ image, 36 * (i % 4) + 10, 36 * (i / 4) + 25);
+ }
}
graphics->drawRectangle(gcn::Rectangle(160, 25, 32, 32));
- if (!(item = mEquipment->getArrows()))
+ if (!(item = inventory->getItem(mEquipment->getArrows())))
return;
image = item->getImage();
- static_cast<Graphics*>(graphics)->drawImage(image, 160, 25);
+ if (image)
+ {
+ static_cast<Graphics*>(graphics)->drawImage(image, 160, 25);
+ }
graphics->drawText(toString(item->getQuantity()), 170, 62,
- gcn::Graphics::CENTER);
+ gcn::Graphics::CENTER);
}
diff --git a/src/gui/equipmentwindow.h b/src/gui/equipmentwindow.h
index bb8eb32f..6a7a4944 100644
--- a/src/gui/equipmentwindow.h
+++ b/src/gui/equipmentwindow.h
@@ -27,6 +27,7 @@
#include "window.h"
#include "../guichanfwd.h"
+#include "../inventory.h"
class Equipment;
@@ -55,6 +56,7 @@ class EquipmentWindow : public Window
private:
Equipment *mEquipment;
+ Inventory *inventory;
};
extern EquipmentWindow *equipmentWindow;
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index 129626f0..9475fcbb 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -200,7 +200,7 @@ void LocalPlayer::unequipItem(Item *item)
outMsg.writeInt16(item->getInvIndex());
// Tidy equipment directly to avoid weapon still shown bug, for instance
- mEquipment->removeEquipment(item);
+ mEquipment->removeEquipment(item->getInvIndex());
}
void LocalPlayer::useItem(Item *item)
diff --git a/src/net/equipmenthandler.cpp b/src/net/equipmenthandler.cpp
index b5c9fe2b..5464fa55 100644
--- a/src/net/equipmenthandler.cpp
+++ b/src/net/equipmenthandler.cpp
@@ -87,7 +87,7 @@ void EquipmentHandler::handleMessage(MessageIn *msg)
position++;
}
item = inventory->getItem(index);
- player_node->mEquipment->setEquipment(position, item);
+ player_node->mEquipment->setEquipment(position, index);
}
}
break;
@@ -120,7 +120,7 @@ void EquipmentHandler::handleMessage(MessageIn *msg)
position++;
}
logger->log("Position %i", position);
- item = player_node->mEquipment->getEquipment(position);
+ item = player_node->getInventory()->getItem(player_node->mEquipment->getEquipment(position));
// Unequip any existing equipped item in this position
if (item) {
@@ -128,7 +128,7 @@ void EquipmentHandler::handleMessage(MessageIn *msg)
}
item = inventory->getItem(index);
- player_node->mEquipment->setEquipment(position, item);
+ player_node->mEquipment->setEquipment(position, index);
break;
case SMSG_PLAYER_UNEQUIP:
@@ -181,7 +181,7 @@ void EquipmentHandler::handleMessage(MessageIn *msg)
item = inventory->getItem(index);
if (item) {
item->setEquipped(true);
- player_node->mEquipment->setArrows(item);
+ player_node->mEquipment->setArrows(index);
logger->log("Arrows equipped: %i", index);
}
break;