Skip to content

Commit 859534a

Browse files
authored
Merge pull request #5482 from Goober5000/ship_killer_name_fix
fix some bugs revealed by ships with long display names
2 parents 03e0904 + 5f8234d commit 859534a

File tree

3 files changed

+19
-50
lines changed

3 files changed

+19
-50
lines changed

code/playerman/player.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ class player
179179
int killer_objtype; // type of object that killed player
180180
int killer_species; // Species which killed player
181181
int killer_weapon_index; // weapon used to kill player (if applicable)
182-
char killer_parent_name[NAME_LENGTH]; // name of parent object that killed the player
182+
char killer_parent_name[NAME_LENGTH]; // name of parent object that killed the player. Will be either a callsign, an actual ship name (not display name), or blank
183183

184184
int check_for_all_alone_msg; // timestamp to check for playing of 'all alone' msg
185185

code/playerman/playercontrol.cpp

Lines changed: 14 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1759,84 +1759,54 @@ float player_farthest_weapon_range()
17591759
return MAX(prange,srange);
17601760
}
17611761

1762-
/**
1763-
* Determine text name for the weapon that killed the player.
1764-
*
1765-
* @param weapon_info_index Weapon type that killed the player (can be -1 if no weapon involved)
1766-
* @param killer_species Species of ship that fired weapon
1767-
* @param weapon_name (Output parameter) Stores weapon name generated in this function
1768-
*/
1769-
const char *player_get_killer_weapon_name(int weapon_info_index, int killer_species)
1770-
{
1771-
if ( weapon_info_index < 0 ) {
1772-
return "";
1773-
}
1774-
1775-
#ifndef NDEBUG
1776-
if ( Show_killer_weapon || (killer_species == Ship_info[Player_ship->ship_info_index].species) ) {
1777-
#else
1778-
if (killer_species == Ship_info[Player_ship->ship_info_index].species) {
1779-
#endif
1780-
return Weapon_info[weapon_info_index].get_display_name();
1781-
} else {
1782-
if ( Weapon_info[weapon_info_index].subtype == WP_MISSILE ) {
1783-
return XSTR( "missile", 90);
1784-
} else {
1785-
return XSTR( "laser fire", 91);
1786-
}
1787-
}
1788-
}
1789-
17901762
/**
17911763
* Generates the message for death of a player given the information stored in the player object.
17921764
*/
17931765
void player_generate_death_message(player *player_p)
17941766
{
17951767
SCP_string &msg = player_p->death_message;
1796-
int ship_index;
17971768

1798-
auto weapon_name = player_get_killer_weapon_name(player_p->killer_weapon_index, player_p->killer_species);
1769+
// killer_parent_name is always a ship name or a callsign (or blank). If it's a ship name, get the ship and use the ship's display name
1770+
auto ship_entry = ship_registry_get(player_p->killer_parent_name);
1771+
auto killer_display_name = (ship_entry != nullptr && ship_entry->status == ShipStatus::PRESENT) ? ship_entry->shipp->get_display_name() : player_p->killer_parent_name;
17991772

18001773
switch (player_p->killer_objtype)
18011774
{
18021775
case OBJ_SHOCKWAVE:
1803-
if (weapon_name[0])
1776+
if (player_p->killer_weapon_index >= 0)
18041777
{
18051778
sprintf(msg, XSTR( "%s was killed by a missile shockwave", 92), player_p->callsign);
18061779
}
18071780
else
18081781
{
1809-
sprintf(msg, XSTR( "%s was killed by a shockwave from %s exploding", 93), player_p->callsign, player_p->killer_parent_name);
1782+
sprintf(msg, XSTR( "%s was killed by a shockwave from %s exploding", 93), player_p->callsign, killer_display_name);
18101783
}
18111784
break;
18121785

18131786
case OBJ_WEAPON:
1814-
Assert(weapon_name[0]);
1815-
18161787
// is this from a friendly ship?
1817-
ship_index = ship_name_lookup(player_p->killer_parent_name, 1);
1818-
if ((ship_index >= 0) && (Player_ship != NULL) && (Player_ship->team == Ships[ship_index].team))
1788+
if ((ship_entry != nullptr) && (ship_entry->status == ShipStatus::PRESENT) && (Player_ship != nullptr) && (Player_ship->team == ship_entry->shipp->team))
18191789
{
1820-
sprintf(msg, XSTR( "%s was killed by friendly fire from %s", 1338), player_p->callsign, player_p->killer_parent_name);
1790+
sprintf(msg, XSTR( "%s was killed by friendly fire from %s", 1338), player_p->callsign, killer_display_name);
18211791
}
18221792
else
18231793
{
1824-
sprintf(msg, XSTR( "%s was killed by %s", 94), player_p->callsign, player_p->killer_parent_name);
1794+
sprintf(msg, XSTR( "%s was killed by %s", 94), player_p->callsign, killer_display_name);
18251795
}
18261796
break;
18271797

18281798
case OBJ_SHIP:
18291799
if (player_p->flags & PLAYER_FLAGS_KILLED_BY_EXPLOSION)
18301800
{
1831-
sprintf(msg, XSTR( "%s was killed by a blast from %s exploding", 95), player_p->callsign, player_p->killer_parent_name);
1801+
sprintf(msg, XSTR( "%s was killed by a blast from %s exploding", 95), player_p->callsign, killer_display_name);
18321802
}
18331803
else if (player_p->flags & PLAYER_FLAGS_KILLED_BY_ENGINE_WASH)
18341804
{
1835-
sprintf(msg, XSTR( "%s was killed by engine wash from %s", 1494), player_p->callsign, player_p->killer_parent_name);
1805+
sprintf(msg, XSTR( "%s was killed by engine wash from %s", 1494), player_p->callsign, killer_display_name);
18361806
}
18371807
else
18381808
{
1839-
sprintf(msg, XSTR( "%s was killed by a collision with %s", 96), player_p->callsign, player_p->killer_parent_name);
1809+
sprintf(msg, XSTR( "%s was killed by a collision with %s", 96), player_p->callsign, killer_display_name);
18401810
}
18411811
break;
18421812

@@ -1857,14 +1827,13 @@ void player_generate_death_message(player *player_p)
18571827
else
18581828
{
18591829
// is this from a friendly ship?
1860-
ship_index = ship_name_lookup(player_p->killer_parent_name, 1);
1861-
if ((ship_index >= 0) && (Player_ship != NULL) && (Player_ship->team == Ships[ship_index].team))
1830+
if ((ship_entry != nullptr) && (ship_entry->status == ShipStatus::PRESENT) && (Player_ship != nullptr) && (Player_ship->team == ship_entry->shipp->team))
18621831
{
1863-
sprintf(msg, XSTR( "%s was destroyed by friendly beam fire from %s", 1339), player_p->callsign, player_p->killer_parent_name);
1832+
sprintf(msg, XSTR( "%s was destroyed by friendly beam fire from %s", 1339), player_p->callsign, killer_display_name);
18641833
}
18651834
else
18661835
{
1867-
sprintf(msg, XSTR( "%s was destroyed by a beam from %s", 1082), player_p->callsign, player_p->killer_parent_name);
1836+
sprintf(msg, XSTR( "%s was destroyed by a beam from %s", 1082), player_p->callsign, killer_display_name);
18681837
}
18691838
}
18701839
break;

code/ship/shiphit.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,7 @@ static void shiphit_record_player_killer(object *killer_objp, player *p)
10501050
nprintf(("Network", "Couldn't find player object of weapon for killer of %s\n", p->callsign));
10511051
}
10521052
} else {
1053-
strcpy_s(p->killer_parent_name, Ships[Objects[killer_objp->parent].instance].get_display_name());
1053+
strcpy_s(p->killer_parent_name, Ships[Objects[killer_objp->parent].instance].ship_name);
10541054
}
10551055
} else {
10561056
p->killer_species = -1;
@@ -1078,7 +1078,7 @@ static void shiphit_record_player_killer(object *killer_objp, player *p)
10781078
nprintf(("Network", "Couldn't find player object of shockwave for killer of %s\n", p->callsign));
10791079
}
10801080
} else {
1081-
strcpy_s(p->killer_parent_name, Ships[Objects[killer_objp->parent].instance].get_display_name());
1081+
strcpy_s(p->killer_parent_name, Ships[Objects[killer_objp->parent].instance].ship_name);
10821082
}
10831083
break;
10841084

@@ -1106,7 +1106,7 @@ static void shiphit_record_player_killer(object *killer_objp, player *p)
11061106
nprintf(("Network", "Couldn't find player object for killer of %s\n", p->callsign));
11071107
}
11081108
} else {
1109-
strcpy_s(p->killer_parent_name, Ships[killer_objp->instance].get_display_name());
1109+
strcpy_s(p->killer_parent_name, Ships[killer_objp->instance].ship_name);
11101110
}
11111111
break;
11121112

@@ -1129,7 +1129,7 @@ static void shiphit_record_player_killer(object *killer_objp, player *p)
11291129
p->killer_objtype = OBJ_BEAM;
11301130
if(beam_obj != -1){
11311131
if((Objects[beam_obj].type == OBJ_SHIP) && (Objects[beam_obj].instance >= 0)){
1132-
strcpy_s(p->killer_parent_name, Ships[Objects[beam_obj].instance].get_display_name());
1132+
strcpy_s(p->killer_parent_name, Ships[Objects[beam_obj].instance].ship_name);
11331133
}
11341134
p->killer_species = Ship_info[Ships[Objects[beam_obj].instance].ship_info_index].species;
11351135
} else {

0 commit comments

Comments
 (0)