Browse Source

- Little code cleanup
- Cleaned merc_hom_evolution to avoid free'ing/realloc'ing
- Fixed "args of aFree is freed pointer" on Homunc deletion


git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@8341 54d463be-8e91-2dee-dedb-b68131a5f0ec

toms 19 năm trước cách đây
mục cha
commit
70f4570b81
7 tập tin đã thay đổi với 27 bổ sung23 xóa
  1. 3 0
      Changelog-Trunk.txt
  2. 0 3
      src/map/map.c
  3. 19 11
      src/map/mercenary.c
  4. 0 3
      src/map/pet.c
  5. 0 3
      src/map/skill.c
  6. 3 3
      src/map/unit.c
  7. 2 0
      src/map/unit.h

+ 3 - 0
Changelog-Trunk.txt

@@ -4,6 +4,9 @@ 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.
 
 2006/08/18
+	* Little code cleanup [Toms]
+	* Cleaned merc_hom_evolution to avoid free'ing/realloc'ing [Toms]
+	* Fixed "args of aFree is freed pointer" on Homunc deletion [Toms]
 	* Changed unit_free so that it receives which cleartype should be used when
 	  the character is still on a map. Used this on status_damage so that mobs
 	  that do not respawn when killed will properly display the death animation.

+ 0 - 3
src/map/map.c

@@ -196,9 +196,6 @@ char wisp_server_name[NAME_LENGTH] = "Server"; // can be modified in char-server
 int console = 0;
 int enable_spy = 0; //To enable/disable @spy commands, which consume too much cpu time when sending packets. [Skotlex]
 
-static const int dirx[8]={0,-1,-1,-1,0,1,1,1};
-static const int diry[8]={1,1,0,-1,-1,-1,0,1};
-
 /*==========================================
  * 全map鯖?計での接??設定
  * (char鯖から送られてくる)

+ 19 - 11
src/map/mercenary.c

@@ -34,9 +34,6 @@
 #include "mercenary.h"
 #include "charsave.h"
 
-static int dirx[8]={0,-1,-1,-1,0,1,1,1};	//[orn]
-static int diry[8]={1,1,0,-1,-1,-1,0,1};	//[orn]
-
 //Better equiprobability than rand()% [orn]
 #define rand(a, b) a+(int) ((float)(b-a+1)*rand()/(RAND_MAX+1.0))
 
@@ -180,7 +177,7 @@ int merc_hom_delete(struct homun_data *hd, int emote)
 	// Send homunculus_dead to client
 	sd->homunculus.hp = 0;
 	clif_hominfo(sd, hd, 0);
-	return unit_free(&hd->bl,1);
+	return unit_remove_map(&hd->bl,0);
 }
 
 int merc_hom_calc_skilltree(struct map_session_data *sd)
@@ -323,10 +320,22 @@ int merc_hom_levelup(struct homun_data *hd)
 	return 1 ;
 }
 
+int merc_hom_change_class(struct homun_data *hd, short class_)
+{
+	int i;
+	i = search_homunculusDB_index(class_,HOMUNCULUS_CLASS);
+	if(i < 0) {
+		return 0;
+	}
+	hd->homunculusDB = &homunculus_db[i];
+	hd->master->homunculus.class_ = class_;
+	status_set_viewdata(&hd->bl, class_);
+	return 1;
+}
+
 int merc_hom_evolution(struct homun_data *hd)
 {
 	struct map_session_data *sd;
-	short x,y;
 	nullpo_retr(0, hd);
 
 	if(!hd->homunculusDB->evo_class)
@@ -337,13 +346,12 @@ int merc_hom_evolution(struct homun_data *hd)
 	sd = hd->master;
 	if (!sd) return 0;
 
-	//TODO: Clean this up to avoid free'ing/realloc'ing. 
-	sd->homunculus.class_ = hd->homunculusDB->evo_class;
-	x = hd->bl.x;
-	y = hd->bl.y;
 	merc_hom_vaporize(sd, 0);
-	unit_free(&hd->bl,0);
-	merc_call_homunculus(sd, x, y);
+
+	if (!merc_hom_change_class(hd, hd->homunculusDB->evo_class))
+		ShowError("merc_hom_evolution: Can't evoluate homunc from %d to %d", hd->master->homunculus.class_, hd->homunculusDB->evo_class);
+
+	merc_call_homunculus(sd, hd->bl.x, hd->bl.y);
 	clif_emotion(&sd->bl, 21) ;	//no1
 	clif_misceffect2(&hd->bl,568);
 	return 1 ;

+ 0 - 3
src/map/pet.c

@@ -34,9 +34,6 @@ struct pet_db pet_db[MAX_PET_DB];
 static struct eri *item_drop_ers; //For loot drops delay structures.
 static struct eri *item_drop_list_ers;
 
-static int dirx[8]={0,-1,-1,-1,0,1,1,1};
-static int diry[8]={1,1,0,-1,-1,-1,0,1};
-
 int pet_hungry_val(struct pet_data *pd)
 {
 	nullpo_retr(0, pd);

+ 0 - 3
src/map/skill.c

@@ -627,9 +627,6 @@ const struct skill_name_db skill_names[] = {
  { 0, "UNKNOWN_SKILL", "Unknown_Skill" }
 };
 
-static const int dirx[8]={0,-1,-1,-1,0,1,1,1};
-static const int diry[8]={1,1,0,-1,-1,-1,0,1};
-
 static struct eri *skill_unit_ers = NULL; //For handling skill_unit's [Skotlex]
 static struct eri *skill_timer_ers = NULL; //For handling skill_timerskills [Skotlex]
 

+ 3 - 3
src/map/unit.c

@@ -15,7 +15,7 @@
 #include "pc.h"
 #include "mob.h"
 #include "pet.h"
-#include "mercenary.h"	///[orn]
+#include "mercenary.h"
 #include "skill.h"
 #include "clif.h"
 #include "npc.h"
@@ -30,8 +30,8 @@
 #include "chrif.h"
 #include "script.h"
 
-static int dirx[8]={0,-1,-1,-1,0,1,1,1};
-static int diry[8]={1,1,0,-1,-1,-1,0,1};
+const int dirx[8]={0,-1,-1,-1,0,1,1,1};
+const int diry[8]={1,1,0,-1,-1,-1,0,1};
 
 struct unit_data* unit_bl2ud(struct block_list *bl) {
 	if( bl == NULL) return NULL;

+ 2 - 0
src/map/unit.h

@@ -67,4 +67,6 @@ int unit_changeviewsize(struct block_list *bl,short size);
 int do_init_unit(void);
 int do_final_unit(void);
 
+extern const int dirx[8];
+extern const int diry[8];
 #endif /* _UNIT_H_ */