@@ -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 */
17931765void 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 ;
0 commit comments