summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2009-02-25 07:54:38 -0700
committerJared Adams <jaxad0127@gmail.com>2009-02-25 07:54:38 -0700
commit7a65eb17a322cb22e7940504797844114fb77d79 (patch)
treec961a8bb4d43f557bf7b4d3b1977fd27a0f8303f
parenta996d4bff3cc5a35ee5cdb6cb5bdef920cf44120 (diff)
downloadmana-client-7a65eb17a322cb22e7940504797844114fb77d79.tar.gz
mana-client-7a65eb17a322cb22e7940504797844114fb77d79.tar.bz2
mana-client-7a65eb17a322cb22e7940504797844114fb77d79.tar.xz
mana-client-7a65eb17a322cb22e7940504797844114fb77d79.zip
Fix some problems with deleting NPCs early
-rw-r--r--src/beingmanager.cpp11
-rw-r--r--src/net/npchandler.cpp2
-rw-r--r--src/npc.cpp12
3 files changed, 14 insertions, 11 deletions
diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp
index 3c8edf86..3b73d29f 100644
--- a/src/beingmanager.cpp
+++ b/src/beingmanager.cpp
@@ -96,7 +96,10 @@ Being* BeingManager::createBeing(Uint32 id, Uint16 job)
void BeingManager::destroyBeing(Being *being)
{
mBeings.remove(being);
- delete being;
+ if (being == current_npc)
+ current_npc->handleDeath();
+ else
+ delete being;
}
Being* BeingManager::findBeing(Uint32 id)
@@ -193,6 +196,12 @@ void BeingManager::clear()
mBeings.remove(player_node);
}
+ if (current_npc)
+ {
+ mBeings.remove(current_npc);
+ current_npc->handleDeath();
+ }
+
delete_all(mBeings);
mBeings.clear();
diff --git a/src/net/npchandler.cpp b/src/net/npchandler.cpp
index 5ae2ac2e..ae521bd5 100644
--- a/src/net/npchandler.cpp
+++ b/src/net/npchandler.cpp
@@ -94,7 +94,7 @@ void NPCHandler::handleMessage(MessageIn *msg)
// If we're talking to that NPC, show the next button
if (temporaryNPC == current_npc)
npcTextDialog->showNextButton();
- else
+ else if (temporaryNPC)
// Otherwise, move on as an empty dialog doesn't help
temporaryNPC->nextDialog();
break;
diff --git a/src/npc.cpp b/src/npc.cpp
index 701e280b..658334bc 100644
--- a/src/npc.cpp
+++ b/src/npc.cpp
@@ -75,12 +75,6 @@ NPC::NPC(Uint32 id, Uint16 job, Map *map, Network *network):
NPC::~NPC()
{
- if (current_npc == this) // Don't delete if current NPC
- {
- handleDeath();
- return;
- }
-
delete mName;
}
@@ -112,7 +106,7 @@ Being::Type NPC::getType() const
void NPC::talk()
{
- if (!mNetwork) return;
+ if (!this || !mNetwork) return;
MessageOut outMsg(mNetwork);
outMsg.writeInt16(CMSG_NPC_TALK);
outMsg.writeInt32(mId);
@@ -121,7 +115,7 @@ void NPC::talk()
void NPC::nextDialog()
{
- if (!mNetwork) return;
+ if (!this || !mNetwork) return;
MessageOut outMsg(mNetwork);
outMsg.writeInt16(CMSG_NPC_NEXT_REQUEST);
outMsg.writeInt32(mId);
@@ -187,7 +181,7 @@ void NPC::handleDeath()
if (npcTextDialog->isVisible())
npcTextDialog->showCloseButton();
- else {
+ else if (current_npc) {
NPC *temp = current_npc;
current_npc = NULL;
delete temp;