Jelajahi Sumber

status_get_name to reference (#8893)

Lemongrass3110 4 bulan lalu
induk
melakukan
2d971a65db
6 mengubah file dengan 48 tambahan dan 27 penghapusan
  1. 5 5
      src/map/clif.cpp
  2. 5 5
      src/map/script.cpp
  3. 4 4
      src/map/skill.cpp
  4. 32 11
      src/map/status.cpp
  5. 1 1
      src/map/status.hpp
  6. 1 1
      src/map/unit.cpp

+ 5 - 5
src/map/clif.cpp

@@ -1220,7 +1220,7 @@ static void clif_set_unit_idle( struct block_list* bl, bool walking, send_target
 #endif
 /* Might be earlier, this is when the named item bug began */
 #if PACKETVER >= 20131223
-	safestrncpy(p.name, status_get_name( bl ), NAME_LENGTH);
+	safestrncpy(p.name, status_get_name( *bl ), NAME_LENGTH);
 #endif
 
 	clif_send( &p, sizeof( p ), tbl, target );
@@ -1361,7 +1361,7 @@ static void clif_spawn_unit( struct block_list *bl, enum send_target target ){
 #endif
 /* Might be earlier, this is when the named item bug began */
 #if PACKETVER >= 20131223
-	safestrncpy( p.name, status_get_name( bl ), NAME_LENGTH );
+	safestrncpy( p.name, status_get_name( *bl ), NAME_LENGTH );
 #endif
 
 	if( disguised( bl ) ){
@@ -1463,7 +1463,7 @@ static void clif_set_unit_walking( struct block_list& bl, map_session_data* tsd,
 #endif
 /* Might be earlier, this is when the named item bug began */
 #if PACKETVER >= 20131223
-	safestrncpy(p.name, status_get_name( &bl ), NAME_LENGTH);
+	safestrncpy(p.name, status_get_name( bl ), NAME_LENGTH);
 #endif
 
 	clif_send( &p, sizeof(p), tsd ? &tsd->bl : &bl, target );
@@ -14649,7 +14649,7 @@ void clif_parse_GMKick(int32 fd, map_session_data *sd)
 		case BL_PC:
 		{
 			char command[NAME_LENGTH+6];
-			safesnprintf(command,sizeof(command),"%ckick %s", atcommand_symbol, status_get_name(target));
+			safesnprintf(command,sizeof(command),"%ckick %s", atcommand_symbol, status_get_name(*target));
 			is_atcommand(fd, sd, command, 1);
 		}
 		break;
@@ -14664,7 +14664,7 @@ void clif_parse_GMKick(int32 fd, map_session_data *sd)
 				clif_GM_kickack(sd, 0);
 				return;
 			}
-			safesnprintf(command,sizeof(command),"/kick %s (%d)", status_get_name(target), status_get_class(target));
+			safesnprintf(command,sizeof(command),"/kick %s (%d)", status_get_name(*target), status_get_class(target));
 			log_atcommand(sd, command);
 			status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
 		}

+ 5 - 5
src/map/script.cpp

@@ -510,9 +510,9 @@ static void script_reportsrc(struct script_state *st)
 			} break;
 		default:
 			if( bl->m >= 0 )
-				ShowDebug("Source (Non-NPC type %d): name %s at %s (%d,%d)\n", bl->type, status_get_name(bl), map_mapid2mapname(bl->m), bl->x, bl->y);
+				ShowDebug("Source (Non-NPC type %d): name %s at %s (%d,%d)\n", bl->type, status_get_name(*bl), map_mapid2mapname(bl->m), bl->x, bl->y);
 			else
-				ShowDebug("Source (Non-NPC type %d): name %s (invisible/not on a map)\n", bl->type, status_get_name(bl));
+				ShowDebug("Source (Non-NPC type %d): name %s (invisible/not on a map)\n", bl->type, status_get_name(*bl));
 			break;
 	}
 }
@@ -12153,7 +12153,7 @@ BUILDIN_FUNC(getunits)
 		{
 			if( data ){
 				if( is_string_variable( name ) ){
-					set_reg_str( st, sd, reference_uid( id, idx + size ), name, status_get_name( bl ), reference_getref( data ) );
+					set_reg_str( st, sd, reference_uid( id, idx + size ), name, status_get_name( *bl ), reference_getref( data ) );
 				}else{
 					set_reg_num( st, sd, reference_uid( id, idx + size ), name, bl->id, reference_getref( data ) );
 				}
@@ -15632,7 +15632,7 @@ int32 atcommand_sub(struct script_state* st,int32 type) {
 		if( st->oid != 0 ){
 			block_list* bl = map_id2bl( st->oid );
 
-			safestrncpy( dummy_sd->status.name, status_get_name( bl ), sizeof( dummy_sd->status.name ) );
+			safestrncpy( dummy_sd->status.name, status_get_name( *bl ), sizeof( dummy_sd->status.name ) );
 			dummy_sd->bl.m = bl->m;
 			dummy_sd->bl.x = bl->x;
 			dummy_sd->bl.y = bl->y;
@@ -19708,7 +19708,7 @@ BUILDIN_FUNC(getunitname)
 		return SCRIPT_CMD_FAILURE;
 	}
 
-	script_pushstrcopy(st, status_get_name(bl));
+	script_pushstrcopy(st, status_get_name(*bl));
 
 	return SCRIPT_CMD_SUCCESS;
 }

+ 4 - 4
src/map/skill.cpp

@@ -12246,7 +12246,7 @@ int32 skill_castend_nodamage_id (struct block_list *src, struct block_list *bl,
 		if(sd){
 			struct mob_data *md2;
 
-			md2 = mob_once_spawn_sub(src, src->m, src->x, src->y, status_get_name(src), MOBID_ZANZOU, "", SZ_SMALL, AI_NONE);
+			md2 = mob_once_spawn_sub(src, src->m, src->x, src->y, status_get_name(*src), MOBID_ZANZOU, "", SZ_SMALL, AI_NONE);
 			if( md2 )
 			{
 				md2->master_id = src->id;
@@ -12446,7 +12446,7 @@ int32 skill_castend_nodamage_id (struct block_list *src, struct block_list *bl,
 		}
 
 		for(i_slave=0; i_slave<qty[skill_lv - 1]; i_slave++){ //easy way
-			sum_md = mob_once_spawn_sub(src, src->m, src->x, src->y, status_get_name(src), summons[skill_lv - 1], "", SZ_SMALL, AI_ATTACK);
+			sum_md = mob_once_spawn_sub(src, src->m, src->x, src->y, status_get_name(*src), summons[skill_lv - 1], "", SZ_SMALL, AI_ATTACK);
 			if (sum_md) {
 				sum_md->master_id =  src->id;
 				sum_md->special_state.ai = AI_LEGION;
@@ -14125,7 +14125,7 @@ int32 skill_castend_pos2(struct block_list* src, int32 x, int32 y, uint16 skill_
 			struct mob_data *md;
 
 			// Correct info, don't change any of this! [celest]
-			md = mob_once_spawn_sub(src, src->m, x, y, status_get_name(src), class_, "", SZ_SMALL, ai);
+			md = mob_once_spawn_sub(src, src->m, x, y, status_get_name(*src), class_, "", SZ_SMALL, ai);
 			if (md) {
 				md->master_id = src->id;
 				md->special_state.ai = ai;
@@ -14391,7 +14391,7 @@ int32 skill_castend_pos2(struct block_list* src, int32 x, int32 y, uint16 skill_
 		{
 			struct mob_data *md;
 
-			md = mob_once_spawn_sub(src, src->m, x, y, status_get_name(src), MOBID_SILVERSNIPER, "", SZ_SMALL, AI_NONE);
+			md = mob_once_spawn_sub(src, src->m, x, y, status_get_name(*src), MOBID_SILVERSNIPER, "", SZ_SMALL, AI_NONE);
 			if( md ) {
 				md->master_id = src->id;
 				md->special_state.ai = AI_FAW;

+ 32 - 11
src/map/status.cpp

@@ -8559,18 +8559,39 @@ void status_calc_slave_mode(mob_data& md)
  * @param bl: Object whose name to get [PC|MOB|PET|HOM|NPC]
  * @return name or "Unknown" if any other bl->type than noted above
  */
-const char* status_get_name(struct block_list *bl)
-{
-	nullpo_ret(bl);
-	switch (bl->type) {
-		case BL_PC:	return ((TBL_PC *)bl)->fakename[0] != '\0' ? ((TBL_PC*)bl)->fakename : ((TBL_PC*)bl)->status.name;
-		case BL_MOB:	return ((TBL_MOB*)bl)->name;
-		case BL_PET:	return ((TBL_PET*)bl)->pet.name;
-		case BL_HOM:	return ((TBL_HOM*)bl)->homunculus.name;
-		case BL_MER:	return ((TBL_MER *)bl)->db->name.c_str();	// They only have database names which are global, not specific to GID.
-		case BL_NPC:	return ((TBL_NPC*)bl)->name;
-		case BL_ELEM:	return ((TBL_ELEM *)bl)->db->name.c_str(); // They only have database names which are global, not specific to GID.
+const char* status_get_name( block_list& bl ){
+	switch( bl.type ){
+		case BL_PC: {
+				map_session_data& sd = reinterpret_cast<map_session_data&>( bl );
+
+				if( sd.fakename[0] != '\0' ){
+					return sd.fakename;
+				}else{
+					return sd.status.name;
+				}
+			} break;
+
+		case BL_MOB:
+			return reinterpret_cast<mob_data&>( bl ).name;
+
+		case BL_PET:
+			return reinterpret_cast<pet_data&>( bl ).pet.name;
+
+		case BL_HOM:
+			return reinterpret_cast<homun_data&>( bl ).homunculus.name;
+
+		case BL_MER:
+			// They only have database names which are global, not specific to GID.
+			return reinterpret_cast<s_mercenary_data&>( bl ).db->name.c_str();
+
+		case BL_NPC:
+			return reinterpret_cast<npc_data&>( bl ).name;
+
+		case BL_ELEM:
+			// They only have database names which are global, not specific to GID.
+			return reinterpret_cast<s_elemental_data&>( bl ).db->name.c_str();
 	}
+
 	return "Unknown";
 }
 

+ 1 - 1
src/map/status.hpp

@@ -3445,7 +3445,7 @@ int32 status_revive(struct block_list *bl, unsigned char per_hp, unsigned char p
 struct regen_data *status_get_regen_data(struct block_list *bl);
 status_data* status_get_status_data(block_list& bl);
 struct status_data *status_get_base_status(struct block_list *bl);
-const char * status_get_name(struct block_list *bl);
+const char* status_get_name( block_list& bl );
 int32 status_get_class(struct block_list *bl);
 int32 status_get_lv(struct block_list *bl);
 #define status_get_range(bl) status_get_status_data(*bl)->rhw.range

+ 1 - 1
src/map/unit.cpp

@@ -3839,7 +3839,7 @@ static TIMER_FUNC(unit_shadowscar_timer) {
  */
 void unit_addshadowscar(unit_data &ud, int32 interval) {
 	if (ud.shadow_scar_timer.size() >= MAX_SHADOW_SCAR) {
-		ShowWarning("unit_addshadowscar: Unit %s (%d) has reached the maximum amount of Shadow Scars (%d).\n", status_get_name(ud.bl), ud.bl->id, MAX_SHADOW_SCAR);
+		ShowWarning("unit_addshadowscar: Unit %s (%d) has reached the maximum amount of Shadow Scars (%d).\n", status_get_name(*ud.bl), ud.bl->id, MAX_SHADOW_SCAR);
 		return;
 	}