Browse Source

- Added function npc_unload_duplicates(), it unloads all npcs that are a duplicate of the passed one. For use with @unloadnpc to prevent crashes when you unload the npc that has duplicates.

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@8939 54d463be-8e91-2dee-dedb-b68131a5f0ec
skotlex 18 years ago
parent
commit
0db4ee6126
4 changed files with 27 additions and 0 deletions
  1. 4 0
      Changelog-Trunk.txt
  2. 1 0
      src/map/atcommand.c
  3. 21 0
      src/map/npc.c
  4. 1 0
      src/map/npc.h

+ 4 - 0
Changelog-Trunk.txt

@@ -3,6 +3,10 @@ Date	Added
 AS OF SVN REV. 5091, WE ARE NOW USING TRUNK.  ALL UNTESTED BUGFIXES/FEATURES GO INTO TRUNK.
 IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
 
+2006/10/05
+	* Added function npc_unload_duplicates(), it unloads all npcs that are a
+	  duplicate of the passed one. For use with @unloadnpc to prevent crashes
+	  when you unload the npc that has duplicates. [Skotlex]
 2006/10/04
 	* Bowling bash now always hits twice regardless of situation. [Skotlex]
 	* Added an underflow check to prevent sending to the client negative mdef2

+ 1 - 0
src/map/atcommand.c

@@ -6234,6 +6234,7 @@ int atcommand_unloadnpc(const int fd, struct map_session_data* sd,
 	}
 
 	if ((nd = npc_name2id(NPCname)) != NULL) {
+		npc_unload_duplicates(nd);
 		npc_unload(nd);
 		clif_displaymessage(fd, msg_txt(112)); // Npc Disabled.
 	} else {

+ 21 - 0
src/map/npc.c

@@ -1417,6 +1417,27 @@ static int npc_unload_ev(DBKey key,void *data,va_list ap) {
 	return 0;
 }
 
+static int npc_unload_dup_sub(DBKey key,void * data,va_list app)
+{
+	struct npc_data *nd = (struct npc_data *)data;
+	va_list ap;
+	int src_id;
+
+	if(nd->bl.type!=BL_NPC || nd->bl.subtype != SCRIPT)
+		return 0;
+
+	ap = va_arg(app, va_list);
+	src_id=va_arg(ap,int);
+	if (nd->u.scr.src_id == src_id)
+		npc_unload(nd);
+	return 0;
+}
+//Removes all npcs that are duplicates of the passed one. [Skotlex]
+void npc_unload_duplicates (struct npc_data *nd)
+{
+	map_foreachiddb(npc_unload_dup_sub,nd->bl.id);
+}
+
 int npc_unload (struct npc_data *nd)
 {
 	nullpo_ret(nd);

+ 1 - 0
src/map/npc.h

@@ -77,6 +77,7 @@ void npc_timerevent_quit(struct map_session_data *sd);
 int npc_gettimerevent_tick(struct npc_data *nd);
 int npc_settimerevent_tick(struct npc_data *nd,int newtimer);
 int npc_remove_map(struct npc_data *nd);
+void npc_unload_duplicates (struct npc_data *nd);
 int npc_unload(struct npc_data *nd);
 int npc_reload(void);
 int npc_script_event(TBL_PC* sd, int type);