Browse Source

- Made recursive master check the default (otherwise it messes skill -> pet -> player kind of herarchies) and cleaned up some the battle_get_master code to prevent infinite loops in the weird case someone specifies that their master is itself.

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@8055 54d463be-8e91-2dee-dedb-b68131a5f0ec
skotlex 19 years ago
parent
commit
d239082490
2 changed files with 11 additions and 22 deletions
  1. 4 0
      Changelog-Trunk.txt
  2. 7 22
      src/map/battle.c

+ 4 - 0
Changelog-Trunk.txt

@@ -4,6 +4,10 @@ AS OF SVN REV. 5091, WE ARE NOW USING TRUNK.  ALL UNTESTED BUGFIXES/FEATURES GO
 IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
 IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
 
 
 2006/08/02
 2006/08/02
+	* Made recursive master check the default (otherwise it messes skill -> pet
+	  -> player kind of herarchies) and cleaned up some the battle_get_master
+	  code to prevent infinite loops in the weird case someone specifies that
+	  their master is itself. [Skotlex]
 	* Recoded the GuildAura code to use val3 & val4, allowing much greater stat
 	* Recoded the GuildAura code to use val3 & val4, allowing much greater stat
 	  bonuses (in case someone wants to get Guild Skill level 20 or something
 	  bonuses (in case someone wants to get Guild Skill level 20 or something
 	  crazy like that) [Skotlex]
 	  crazy like that) [Skotlex]

+ 7 - 22
src/map/battle.c

@@ -25,9 +25,6 @@
 #include "guild.h"
 #include "guild.h"
 #include "party.h"
 #include "party.h"
 
 
-// Recursive master check to prevent custom AIs from messing with each other.
-// #define RECURSIVE_MASTER_CHECK
-
 #define	is_boss(bl)	status_get_mexp(bl)	// Can refine later [Aru]
 #define	is_boss(bl)	status_get_mexp(bl)	// Can refine later [Aru]
 
 
 int attr_fix_table[4][ELE_MAX][ELE_MAX];
 int attr_fix_table[4][ELE_MAX][ELE_MAX];
@@ -3073,40 +3070,28 @@ int battle_check_undead(int race,int element)
 //Returns the upmost level master starting with the given object
 //Returns the upmost level master starting with the given object
 static struct block_list* battle_get_master(struct block_list *src)
 static struct block_list* battle_get_master(struct block_list *src)
 {
 {
+	struct block_list *mst; //Used for infinite loop check (master of yourself?)
 	do {
 	do {
+		mst = src;
 		switch (src->type) {
 		switch (src->type) {
 			case BL_PET:
 			case BL_PET:
 				if (((TBL_PET*)src)->msd)
 				if (((TBL_PET*)src)->msd)
-					src = (struct block_list*)((TBL_PET*)src)->msd;
-				else
-					return src;
+					mst = (struct block_list*)((TBL_PET*)src)->msd;
 				break;
 				break;
 			case BL_MOB:
 			case BL_MOB:
 				if (((TBL_MOB*)src)->master_id)
 				if (((TBL_MOB*)src)->master_id)
-					src = map_id2bl(((TBL_MOB*)src)->master_id);
-				else
-					return src;
+					mst = map_id2bl(((TBL_MOB*)src)->master_id);
 				break;
 				break;
 			case BL_HOMUNCULUS:
 			case BL_HOMUNCULUS:
 				if (((TBL_HOMUNCULUS*)src)->master)
 				if (((TBL_HOMUNCULUS*)src)->master)
-					src = (struct block_list*)((TBL_HOMUNCULUS*)src)->master;
-				else
-					return src;
+					mst = (struct block_list*)((TBL_HOMUNCULUS*)src)->master;
 				break;
 				break;
 			case BL_SKILL:
 			case BL_SKILL:
 				if (((TBL_SKILL*)src)->group && ((TBL_SKILL*)src)->group->src_id)
 				if (((TBL_SKILL*)src)->group && ((TBL_SKILL*)src)->group->src_id)
-					src = map_id2bl(((TBL_SKILL*)src)->group->src_id);
-				else
-					return src;
+					mst = map_id2bl(((TBL_SKILL*)src)->group->src_id);
 				break;
 				break;
-			default:
-				return src;
 		}
 		}
-#ifdef RECURSIVE_MASTER_CHECK
-	} while (src);
-#else
-	} while (0); //Single pass check.
-#endif
+	} while (mst && src != mst);
 	return src;
 	return src;
 }
 }