From 5f5cd93f2da3377ce3b9ae45d4a15a944a723517 Mon Sep 17 00:00:00 2001
From: shennetsind <shennetsind@54d463be-8e91-2dee-dedb-b68131a5f0ec>
Date: Sat, 26 May 2012 21:49:36 +0000
Subject: Fixed bugreport:5658 Instance NPCs will now be cleared properly.
 Super-Special Thanks to Pig321

git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@16153 54d463be-8e91-2dee-dedb-b68131a5f0ec
---
 src/map/instance.c | 30 +++++++++++++++++++++++++++++-
 src/map/npc.c      |  2 +-
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/src/map/instance.c b/src/map/instance.c
index fcbc03e5e..44b735518 100644
--- a/src/map/instance.c
+++ b/src/map/instance.c
@@ -253,6 +253,34 @@ int instance_del_load(struct map_session_data* sd, va_list args)
 	return 1;
 }
 
+/* for npcs behave differently when being unloaded within a instance */
+int instance_cleanup_sub(struct block_list *bl, va_list ap) {
+	nullpo_ret(bl);
+	
+	switch(bl->type) {
+		case BL_PC:
+			map_quit((struct map_session_data *) bl);
+			break;
+		case BL_NPC:
+			npc_unload((struct npc_data *)bl,true);
+			break;
+		case BL_MOB:
+			unit_free(bl,CLR_OUTSIGHT);
+			break;
+		case BL_PET:
+			//There is no need for this, the pet is removed together with the player. [Skotlex]
+			break;
+		case BL_ITEM:
+			map_clearflooritem(bl->id);
+			break;
+		case BL_SKILL:
+			skill_delunit((struct skill_unit *) bl);
+			break;
+	}
+	
+	return 1;
+}
+
 /*--------------------------------------
  * Removes a simple instance map
  *--------------------------------------*/
@@ -266,7 +294,7 @@ void instance_del_map(int m)
 	}
 
 	map_foreachpc(instance_del_load, m);
-	map_foreachinmap(cleanup_sub, m, BL_ALL);
+	map_foreachinmap(instance_cleanup_sub, m, BL_ALL);
 
 	if( map[m].mob_delete_timer != INVALID_TIMER )
 		delete_timer(map[m].mob_delete_timer, map_removemobs_timer);
diff --git a/src/map/npc.c b/src/map/npc.c
index 4f08d28f5..9cfce37ac 100644
--- a/src/map/npc.c
+++ b/src/map/npc.c
@@ -1739,7 +1739,7 @@ int npc_unload(struct npc_data* nd, bool single) {
 	npc_remove_map(nd);
 	map_deliddb(&nd->bl);
 	if( single )
-	strdb_remove(npcname_db, nd->exname);
+		strdb_remove(npcname_db, nd->exname);
 
 	if (nd->chat_id) // remove npc chatroom object and kick users
 		chat_deletenpcchat(nd);
-- 
cgit v1.2.3-70-g09d2