Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions code/hud/hudsquadmsg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,7 @@ int hud_squadmsg_count_wings( int add_to_menu )
count++;
if ( add_to_menu ) {
Assert ( Num_menu_items < MAX_MENU_ITEMS );
MsgItems[Num_menu_items].text = Wings[wingnum].name;
end_string_at_first_hash_symbol(MsgItems[Num_menu_items].text);
MsgItems[Num_menu_items].text = Wings[wingnum].get_display_name();
MsgItems[Num_menu_items].instance = wingnum;
MsgItems[Num_menu_items].active = 1;
Num_menu_items++;
Expand All @@ -454,8 +453,7 @@ int hud_squadmsg_count_wings( int add_to_menu )
count++;
if ( add_to_menu ) {
Assert ( Num_menu_items < MAX_MENU_ITEMS );
MsgItems[Num_menu_items].text = Wings[i].name;
end_string_at_first_hash_symbol(MsgItems[Num_menu_items].text);
MsgItems[Num_menu_items].text = Wings[i].get_display_name();
MsgItems[Num_menu_items].instance = i;
MsgItems[Num_menu_items].active = 1;
Num_menu_items++;
Expand Down Expand Up @@ -2059,7 +2057,6 @@ void hud_squadmsg_reinforcement_select()
Num_menu_items = 0;
for (i = 0; i < Num_reinforcements; i++) {
rp = &Reinforcements[i];
SCP_string rp_name = rp->name;

// don't put reinforcements onto the list that have already been used up.
if ( rp->num_uses >= rp->uses ){
Expand All @@ -2075,14 +2072,15 @@ void hud_squadmsg_reinforcement_select()
// Goober5000 - if it can't arrive, it doesn't count. This should check
// for SEXP_FALSE as well as SEXP_KNOWN_FALSE, otherwise you end up with
// a reinforcement menu containing no valid selections.
SCP_string rp_name;
if ( (wingnum = wing_name_lookup(rp->name, 1)) != -1 ) {
Assert ( Wings[wingnum].arrival_cue >= 0 );
if ( Sexp_nodes[Wings[wingnum].arrival_cue].value == SEXP_FALSE
|| Sexp_nodes[Wings[wingnum].arrival_cue].value == SEXP_KNOWN_FALSE ){
continue;
}

end_string_at_first_hash_symbol(rp_name);
rp_name = Wings[wingnum].get_display_name(); // this will handle getting rid of the hash if necessary
} else {
p_object *p_objp;

Expand Down
15 changes: 8 additions & 7 deletions code/hud/hudwingmanstatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,18 +582,19 @@ void HudGaugeWingmanStatus::renderDots(int wing_index, int screen_index, int num

// check if using full names or default abbreviations before rendering text
char wingstr[NAME_LENGTH];
auto wing_name = config
? HC_wingam_gauge_status_names[wing_index]
: (Squadron_wings[wing_index] >= 0)
? Wings[Squadron_wings[wing_index]].get_display_name()
: Squadron_wing_names[wing_index];

if (use_full_wingnames) {
// wookieejedi - use full wing name with unaltered capitalization
strcpy_s(wingstr, config ? HC_wingam_gauge_status_names[wing_index] : Squadron_wing_names[wing_index]);
strncpy_s(wingstr, wing_name, NAME_LENGTH-1);
} else {
// Goober5000 - get the lowercase abbreviation
char abbrev[4];
abbrev[0] = SCP_tolower(config ? HC_wingam_gauge_status_names[wing_index][0] : Squadron_wing_names[wing_index][0]);
abbrev[1] = SCP_tolower(config ? HC_wingam_gauge_status_names[wing_index][1] : Squadron_wing_names[wing_index][1]);
abbrev[2] = SCP_tolower(config ? HC_wingam_gauge_status_names[wing_index][2] : Squadron_wing_names[wing_index][2]);
abbrev[3] = '\0';
strncpy(wingstr, abbrev, 4);
strncpy_s(wingstr, wing_name, 3);
SCP_tolower(wingstr);
}

int wingstr_width;
Expand Down
4 changes: 1 addition & 3 deletions code/mission/missionhotkey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,6 @@ int hotkey_build_team_listing(int enemy_team_mask, int y, bool list_enemies)

for (int i=0; i<Num_wings; i++) {
bool add_it;
char wing_name[NAME_LENGTH];

// the wing has to be valid
if (Wings[i].current_count && Wings[i].ship_index[Wings[i].special_ship] >= 0) {
Expand Down Expand Up @@ -677,8 +676,7 @@ int hotkey_build_team_listing(int enemy_team_mask, int y, bool list_enemies)
if ( j < Wings[i].current_count )
continue;

strcpy_s(wing_name, Wings[i].name);
end_string_at_first_hash_symbol(wing_name);
auto wing_name = Wings[i].get_display_name();

int z = hotkey_line_add_sorted(wing_name, HotkeyLineType::WING, i, start);
if (Wings[i].flags[Ship::Wing_Flags::Expanded]) {
Expand Down
2 changes: 2 additions & 0 deletions code/mission/missionlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ void mission_log_add_entry(LogType type, const char *pname, const char *sname, i
Assert(index != -1);
Assert(info_index != -1); // this is the team value

entry.pname_display = Wings[index].get_display_name();

// get the team value for this wing. Departed or destroyed wings will pass the team
// value in info_index parameter. For arriving wings, get the team value from the
// first ship in the list because the info_index contains the wave count
Expand Down
40 changes: 26 additions & 14 deletions code/mission/missionparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4643,18 +4643,7 @@ int parse_wing_create_ships( wing *wingp, int num_to_create, bool force_create,
wingp->total_arrived_count++;
if (wingp->num_waves > 1)
{
bool needs_display_name;
wing_bash_ship_name(p_objp->name, wingp->name, wingp->total_arrived_count + wingp->red_alert_skipped_ships, &needs_display_name);

// set up display name if we need to
// (In the unlikely edge case where the ship already has a display name for some reason, it will be overwritten.
// This is unavoidable, because if we didn't overwrite display names, all waves would have the display name from the first wave.)
if (needs_display_name)
{
p_objp->display_name = p_objp->name;
end_string_at_first_hash_symbol(p_objp->display_name);
p_objp->flags.set(Mission::Parse_Object_Flags::SF_Has_display_name);
}
wing_bash_ship_name(p_objp, wingp, wingp->total_arrived_count + wingp->red_alert_skipped_ships);

// subsequent waves of ships will not be in the ship registry, so add them
if (!ship_registry_exists(p_objp->name))
Expand Down Expand Up @@ -4838,6 +4827,20 @@ void parse_wing(mission *pm)
error_display(0, NOX("Redundant wing name: %s\n"), wingp->name);
wingnum = Num_wings;

// if this name has a hash, create a default display name
if (get_pointer_to_first_hash_symbol(wingp->name))
{
wingp->display_name = wingp->name;
end_string_at_first_hash_symbol(wingp->display_name);
wingp->flags.set(Ship::Wing_Flags::Has_display_name);
}

if (optional_string("$Display Name:"))
{
stuff_string(wingp->display_name, F_NAME);
wingp->flags.set(Ship::Wing_Flags::Has_display_name);
}

// squad logo - Goober5000
if (optional_string("+Squad Logo:"))
{
Expand Down Expand Up @@ -9580,8 +9583,17 @@ bool check_for_25_1_data()
return true;
}

return std::any_of(Jump_nodes.begin(), Jump_nodes.end(), [defaultLayer](const auto& jn) {
if (std::any_of(Jump_nodes.begin(), Jump_nodes.end(), [defaultLayer](const auto& jn) {
const auto& layer = jn.GetFredLayer();
return !layer.empty() && !lcase_equal(layer, defaultLayer);
});
}))
return true;

for (int wingnum = 0; wingnum < Num_wings; wingnum++)
{
if (Wings[wingnum].has_display_name())
return true;
}

return false;
}
25 changes: 23 additions & 2 deletions code/missioneditor/missionsave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3454,7 +3454,8 @@ int Fred_mission_save::save_objects()
count++;

// Display name
// The display name is only written if there was one at the start to avoid introducing inconsistencies
// (If we are always saving display names, the "only/not written" comments do not apply)
// The display name is only written if it currently exists and the ship is not part of a wing, to avoid introducing inconsistencies
if (save_config.save_format != MissionFormat::RETAIL && ((save_config.always_save_display_names && shipp->wingnum < 0) || shipp->has_display_name())) {
char truncated_name[NAME_LENGTH];
strcpy_s(truncated_name, shipp->ship_name);
Expand Down Expand Up @@ -4803,7 +4804,8 @@ int Fred_mission_save::save_waypoints()

if (save_config.save_format != MissionFormat::RETAIL) {

// The display name is only written if there was one at the start to avoid introducing inconsistencies
// (If we are always saving display names, the "only/not written" comments do not apply)
// The display name is only written if it currently exists, to avoid introducing inconsistencies
if (save_config.always_save_display_names || jnp->HasDisplayName()) {
char truncated_name[NAME_LENGTH];
strcpy_s(truncated_name, jnp->GetName());
Expand Down Expand Up @@ -4957,6 +4959,25 @@ int Fred_mission_save::save_wings()

count++;

// Display name
// (If we are always saving display names, the "only/not written" comments do not apply)
// The display name is only written if it currently exists, to avoid introducing inconsistencies
if (save_config.save_format != MissionFormat::RETAIL && (save_config.always_save_display_names || w.has_display_name())) {
char truncated_name[NAME_LENGTH];
strcpy_s(truncated_name, w.name);
end_string_at_first_hash_symbol(truncated_name);

// Also, the display name is not written if it's just the truncation of the name at the hash
if (save_config.always_save_display_names || strcmp(w.get_display_name(), truncated_name) != 0) {
if (optional_string_fred("$Display name:", "$Waves:")) {
parse_comments();
} else {
fout("\n$Display name:");
}
fout_ext(" ", "%s", w.get_display_name());
}
}

// squad logo - Goober5000
if (save_config.save_format != MissionFormat::RETAIL) {
if (strlen(w.wing_squad_filename) > 0) //-V805
Expand Down
8 changes: 3 additions & 5 deletions code/missionui/missionshipchoice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2173,14 +2173,12 @@ void draw_wing_block(int wb_num, int hot_slot, int selected_slot, int class_sele

// print the wing name under the wing
wp = &Wings[wb->wingnum];
char name[NAME_LENGTH];
strcpy_s(name, wp->name);
end_string_at_first_hash_symbol(name);
gr_get_string_size(&w, &h, name);
auto wing_name = wp->get_display_name();
gr_get_string_size(&w, &h, wing_name);
sx = Wing_icon_coords[gr_screen.res][wb_num*MAX_WING_SLOTS][0] + 16 - w/2;
sy = Wing_icon_coords[gr_screen.res][wb_num*MAX_WING_SLOTS + 3][1] + 32 + h;
gr_set_color_fast(&Color_normal);
gr_string(sx, sy, name, GR_RESIZE_MENU);
gr_string(sx, sy, wing_name, GR_RESIZE_MENU);

for ( i = 0; i < MAX_WING_SLOTS; i++ ) {
GR_DEBUG_SCOPE("Single ship");
Expand Down
2 changes: 1 addition & 1 deletion code/missionui/redalert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ void red_alert_bash_ship_status()

// give the ship its name from the latest wave
// (this will make the ship match to the correct red-alert data)
wing_bash_ship_name(shipp->ship_name, wingp->name, ((rws->latest_wave - 1) * wingp->wave_count) + 1 + pos_in_wing);
wing_bash_ship_name(shipp, wingp, ((rws->latest_wave - 1) * wingp->wave_count) + 1 + pos_in_wing);
// need to update the ship registry too
strcpy_s(Ship_registry[ship_entry_index].name, shipp->ship_name);
Ship_registry_map[shipp->ship_name] = ship_entry_index;
Expand Down
2 changes: 1 addition & 1 deletion code/network/multi_ingame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1332,7 +1332,7 @@ void process_ingame_wings_packet( ubyte *data, header *hinfo )
// kind of stupid, but bash the name since it won't get recreated properly from
// the parse_wing_create_ships call.
shipp = &Ships[shipnum];
wing_bash_ship_name(shipp->ship_name, wingp->name, which_one + 1);
wing_bash_ship_name(shipp, wingp, which_one + 1);
nprintf(("Network", "Created %s\n", shipp->ship_name));

objp = &Objects[shipp->objnum];
Expand Down
8 changes: 3 additions & 5 deletions code/network/multiteamselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ void multi_ts_sync_interface()
void multi_ts_assign_players_all()
{
int idx,team_index,slot_index,found,player_count,shipnum;
char name_lookup[100];
char name_lookup[NAME_LENGTH];
object *objp;

// set all player ship indices to -1
Expand All @@ -833,12 +833,10 @@ void multi_ts_assign_players_all()
// always assign the host to the wing leader of one of the TVT wings
// this is valid for coop games as well because the first starting wing
// and the first tvt wing must have the same name
memset(name_lookup,0,100);

if(Netgame.type_flags & NG_TYPE_TEAM) {
sprintf(name_lookup, "%s 1", TVT_wing_names[Netgame.host->p_info.team]);
}
else {
wing_bash_ship_name(name_lookup, TVT_wing_names[Netgame.host->p_info.team], 1);
} else {
// To account for cases where <Wingname> 1 is not a player ship
for (int i = 0; i < MAX_SHIPS_PER_WING; i++) {
wing_bash_ship_name(name_lookup, TVT_wing_names[0], i + 1);
Expand Down
37 changes: 36 additions & 1 deletion code/scripting/api/objs/wing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ ADE_FUNC(__len, l_Wing, NULL, "Gets the number of ships in the wing", "number",
return ade_set_args(L, "i", Wings[wdx].current_count);
}

ADE_VIRTVAR(Name, l_Wing, "string", "Name of Wing", "string", "Wing name, or empty string if handle is invalid")
ADE_VIRTVAR(Name, l_Wing, "string", "Wing name. This is the actual name of the wing. Use <i>getDisplayString</i> to get the string which should be displayed to the player.", "string", "Wing name, or empty string if handle is invalid")
{
int wdx;
const char* s = nullptr;
Expand All @@ -63,6 +63,29 @@ ADE_VIRTVAR(Name, l_Wing, "string", "Name of Wing", "string", "Wing name, or emp
return ade_set_args(L, "s", Wings[wdx].name);
}

ADE_VIRTVAR(DisplayName, l_Wing, "string", "Wing display name", "string", "The display name of the wing or empty if there is no display string")
{
int wingnum = -1;
const char* s = nullptr;
if (!ade_get_args(L, "o|s", l_Wing.Get(&wingnum), &s))
return ade_set_error(L, "s", "");

if (wingnum < 0 || wingnum >= Num_wings)
return ade_set_error(L, "s", "");

auto wingp = &Wings[wingnum];

if (ADE_SETTING_VAR && s != nullptr)
{
wingp->display_name = s;

// for compatibility reasons, if we are setting this to the empty string, clear the flag
wingp->flags.set(Ship::Wing_Flags::Has_display_name, s[0] != 0);
}

return ade_set_args(L, "s", wingp->display_name.c_str());
}

ADE_FUNC(isValid, l_Wing, NULL, "Detects whether handle is valid", "boolean", "true if valid, false if handle is invalid, nil if a syntax/type error occurs")
{
int idx;
Expand Down Expand Up @@ -374,6 +397,18 @@ ADE_VIRTVAR(WaveDelayMaximum, l_Wing, "number", "The wing's maximum wave delay",
return wing_getset_helper(L, &wing::wave_delay_max, true);
}

ADE_FUNC(getDisplayString, l_Wing, nullptr, "Returns the string which should be used when displaying the name of the wing to the player", "string", "The display string or empty if handle is invalid")
{
int wingnum = -1;
if (!ade_get_args(L, "o", l_Wing.Get(&wingnum)))
return ade_set_error(L, "s", "");

if (wingnum < 0 || wingnum >= Num_wings)
return ade_set_error(L, "s", "");

return ade_set_args(L, "s", Wings[wingnum].get_display_name());
}


}
}
Loading
Loading