@@ -15218,42 +15218,46 @@ int get_available_secondary_weapons(object *objp, int *outlist, int *outbanklist
1521815218 return count;
1521915219}
1522015220
15221- void wing_bash_ship_name(SCP_string &ship_name, const char *wing_name, int index )
15221+ void wing_bash_ship_name(SCP_string &ship_name, const char *wing_name, int ordinal )
1522215222{
1522315223 // always create the name this way; display names are handled in the p_object* and ship* functions
15224- sprintf(ship_name, NOX("%s %d"), wing_name, index );
15224+ sprintf(ship_name, NOX("%s %d"), wing_name, ordinal );
1522515225}
1522615226
15227- void wing_bash_ship_name(char *ship_name, const char *wing_name, int index )
15227+ void wing_bash_ship_name(char *ship_name, const char *wing_name, int ordinal )
1522815228{
15229- static_assert(MAX_SHIPS_PER_WING < 10, "If two-digit wingman indexes are possible, this function will need to be modified.");
15230- constexpr size_t max_name_len = NAME_LENGTH - 3;
15229+ char ordinal_str[NAME_LENGTH];
15230+ sprintf(ordinal_str, "%d", ordinal);
15231+
15232+ size_t max_name_len = NAME_LENGTH - 2 - strlen(ordinal_str);
1523115233
1523215234 // truncate name if too long
1523315235 if (strlen(wing_name) > max_name_len)
1523415236 {
1523515237 Warning(LOCATION, "Wing name %s is too long; truncating name for ship", wing_name);
1523615238 strncpy(ship_name, wing_name, max_name_len);
15237- sprintf( ship_name + max_name_len, NOX("%d"), index) ;
15239+ ship_name[ max_name_len] = '\0' ;
1523815240 }
1523915241 else
15240- {
15241- // always create the name this way; display names are handled in the p_object* and ship* functions
15242- sprintf(ship_name, NOX("%s %d"), wing_name, index);
15243- }
15242+ strcpy(ship_name, wing_name);
15243+
15244+ // add the rest
15245+ // always create the name this way; display names are handled in the p_object* and ship* functions
15246+ strcat(ship_name, " ");
15247+ strcat(ship_name, ordinal_str);
1524415248}
1524515249
15246- void wing_bash_ship_name(p_object *p_objp, const wing *wingp, int index , bool reset_display_name_if_normal)
15250+ void wing_bash_ship_name(p_object *p_objp, const wing *wingp, int ordinal , bool reset_display_name_if_normal)
1524715251{
1524815252 // always update the real name
15249- wing_bash_ship_name(p_objp->name, wingp->name, index );
15253+ wing_bash_ship_name(p_objp->name, wingp->name, ordinal );
1525015254
1525115255 // also set up the display name if we have one
1525215256 // (In the unlikely edge case where the ship already has a display name for some reason, it will be overwritten.
1525315257 // This is unavoidable, because if we didn't overwrite display names, all waves would have the display name from the first wave.)
1525415258 if (wingp->has_display_name())
1525515259 {
15256- wing_bash_ship_name(p_objp->display_name, wingp->get_display_name(), index );
15260+ wing_bash_ship_name(p_objp->display_name, wingp->get_display_name(), ordinal );
1525715261 p_objp->flags.set(Mission::Parse_Object_Flags::SF_Has_display_name);
1525815262 }
1525915263 else if (reset_display_name_if_normal)
@@ -15263,18 +15267,28 @@ void wing_bash_ship_name(p_object *p_objp, const wing *wingp, int index, bool re
1526315267 }
1526415268}
1526515269
15266- void wing_bash_ship_name(ship *shipp, const wing *wingp, int index , bool reset_display_name_if_normal)
15270+ void wing_bash_ship_name(ship *shipp, const wing *wingp, int ordinal , bool reset_display_name_if_normal)
1526715271{
1526815272 // always update the real name
15269- wing_bash_ship_name(shipp->ship_name, wingp->name, index );
15273+ wing_bash_ship_name(shipp->ship_name, wingp->name, ordinal );
1527015274
1527115275 // also set up the display name if we have one
1527215276 // (In the unlikely edge case where the ship already has a display name for some reason, it will be overwritten.
1527315277 // This is unavoidable, because if we didn't overwrite display names, all waves would have the display name from the first wave.)
1527415278 if (wingp->has_display_name())
1527515279 {
15276- wing_bash_ship_name(shipp->display_name, wingp->get_display_name(), index);
15277- shipp->flags.set(Ship::Ship_Flags::Has_display_name);
15280+ // in FRED, since the wing display name takes precedence, clear the ship display name
15281+ if (Fred_running)
15282+ {
15283+ shipp->display_name = "";
15284+ shipp->flags.remove(Ship::Ship_Flags::Has_display_name);
15285+ }
15286+ // in FS, set up the ship display name based on the wing display name
15287+ else
15288+ {
15289+ wing_bash_ship_name(shipp->display_name, wingp->get_display_name(), ordinal);
15290+ shipp->flags.set(Ship::Ship_Flags::Has_display_name);
15291+ }
1527815292 }
1527915293 else if (reset_display_name_if_normal)
1528015294 {
0 commit comments