Skip to content

Commit

Permalink
Add ship display name feature
Browse files Browse the repository at this point in the history
This adds a mission file option for ships which allows specifying a
different string which should be used for displaying the name of the
ship to the user. This name will not be used in SEXPs or other ship
lookup functions so it can be freely translated and two ships can also
have the same display name.

The new feature can be used by adding $Display name: <string> after $Name
for a ship in a mission file. I think I added proper support for FRED
(and qtFRED) so that this new value is properly saved but it would be
great if someone could test that.

This implements one of the features requested in scp-fs2open#1730.
  • Loading branch information
asarium committed Jul 22, 2018
1 parent 7f03ac3 commit c13cb44
Show file tree
Hide file tree
Showing 21 changed files with 302 additions and 167 deletions.
2 changes: 1 addition & 1 deletion code/hud/hudescort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ void HudGaugeEscort::renderIcon(int x, int y, int index)
}

// print out ship name
strcpy_s(buf, sp->ship_name);
strcpy_s(buf, sp->get_display_string());
font::force_fit_string(buf, 255, ship_name_max_width);

end_string_at_first_hash_symbol(buf);
Expand Down
2 changes: 1 addition & 1 deletion code/hud/hudmessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ void HUD_ship_sent_printf(int sh, const char *format, ...)
tmp[sizeof(tmp)-1] = '\0';
size_t len;

snprintf(tmp, sizeof(tmp)-1, NOX("%s: "), Ships[sh].ship_name);
snprintf(tmp, sizeof(tmp)-1, NOX("%s: "), Ships[sh].get_display_string());
len = strlen(tmp);

va_start(args, format);
Expand Down
1 change: 1 addition & 0 deletions code/hud/hudobserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ void hud_observer_init(ship *shipp, ai_info *aip)
// (we used to do a memcpy here, but that doesn't work any longer, so let's just assign the values we need)
Hud_obs_ship.clear();
strcpy_s(Hud_obs_ship.ship_name, shipp->ship_name);
Hud_obs_ship.display_name = shipp->display_name;
Hud_obs_ship.team = shipp->team;
Hud_obs_ship.ai_index = shipp->ai_index;
Hud_obs_ship.flags = shipp->flags;
Expand Down
2 changes: 1 addition & 1 deletion code/hud/hudsquadmsg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ int hud_squadmsg_count_ships(int add_to_menu)
if (add_to_menu)
{
Assert ( Num_menu_items < MAX_MENU_ITEMS );
strcpy_s( MsgItems[Num_menu_items].text, shipp->ship_name );
strcpy_s( MsgItems[Num_menu_items].text, shipp->get_display_string() );
end_string_at_first_hash_symbol(MsgItems[Num_menu_items].text); // truncate the name if it has a # in it
MsgItems[Num_menu_items].instance = SHIP_INDEX(shipp);
MsgItems[Num_menu_items].active = 1;
Expand Down
2 changes: 1 addition & 1 deletion code/hud/hudtarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5293,7 +5293,7 @@ void hud_stuff_ship_name(char *ship_name_text, ship *shipp)
if ( ((Iff_info[shipp->team].flags & IFFF_WING_NAME_HIDDEN) && (shipp->wingnum != -1)) || (shipp->flags[Ship::Ship_Flags::Hide_ship_name]) ) {
*ship_name_text = 0;
} else {
strcpy(ship_name_text, shipp->ship_name);
strcpy(ship_name_text, shipp->get_display_string());

// handle hash symbol
end_string_at_first_hash_symbol(ship_name_text);
Expand Down
24 changes: 15 additions & 9 deletions code/hud/hudtargetbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1405,7 +1405,7 @@ void HudGaugeExtraTargetData::pageIn()
*/
void HudGaugeExtraTargetData::render(float /*frametime*/)
{
char outstr[256], tmpbuf[256];
char tmpbuf[256];
int has_orders = 0;
int not_training;
int extra_data_shown=0;
Expand Down Expand Up @@ -1440,17 +1440,22 @@ void HudGaugeExtraTargetData::render(float /*frametime*/)
!(Iff_info[target_shipp->team].flags & IFFF_ORDERS_HIDDEN)))
&& Ship_info[target_shipp->ship_info_index].is_flyable()) {
extra_data_shown = 1;
if (ship_return_orders(outstr, target_shipp)) {
auto orders = ship_return_orders(target_shipp);
if (!orders.empty()) {
char outstr[256];
strcpy_s(outstr, orders.c_str());
font::force_fit_string(outstr, 255, order_max_w);
orders = outstr;
has_orders = 1;
} else {
strcpy_s(outstr, XSTR("no orders", 337));
orders = XSTR("no orders", 337);
}

renderString(position[0] + order_offsets[0], position[1] + order_offsets[1], EG_TBOX_EXTRA1, outstr);
renderString(position[0] + order_offsets[0], position[1] + order_offsets[1], EG_TBOX_EXTRA1, orders.c_str());
}

if ( has_orders ) {
char outstr[256];
strcpy_s(outstr, XSTR( "time to: ", 338));
if ( ship_return_time_to_goal(tmpbuf, target_shipp) ) {
strcat_s(outstr, tmpbuf);
Expand All @@ -1471,10 +1476,11 @@ void HudGaugeExtraTargetData::render(float /*frametime*/)
// count the objects directly docked to me
int dock_count = dock_count_direct_docked_objects(target_objp);

char outstr[256];
// docked to only one object
if (dock_count == 1)
{
sprintf(outstr, XSTR("Docked: %s", 339), Ships[dock_get_first_docked_object(target_objp)->instance].ship_name);
sprintf(outstr, XSTR("Docked: %s", 339), Ships[dock_get_first_docked_object(target_objp)->instance].get_display_string());
end_string_at_first_hash_symbol(outstr);
}
// docked to multiple objects
Expand Down Expand Up @@ -2040,10 +2046,10 @@ void HudGaugeTargetBox::showTargetData(float /*frametime*/)
float dot, dist;
vec3d v2t;

if (aip->target_objnum == Player_obj-Objects)
if (aip->target_objnum == OBJ_INDEX(Player_obj))
strcpy_s(target_str, "Player!");
else
sprintf(target_str, "%s", Ships[Objects[aip->target_objnum].instance].ship_name);
sprintf(target_str, "%s", Ships[Objects[aip->target_objnum].instance].get_display_string());

gr_printf_no_resize(sx, sy, "Targ: %s", target_str);
sy += dy;
Expand Down Expand Up @@ -2091,14 +2097,14 @@ void HudGaugeTargetBox::showTargetData(float /*frametime*/)
eshipp = &Ships[Enemy_attacker->instance];
eaip = &Ai_info[eshipp->ai_index];

if (eaip->target_objnum == Player_obj-Objects) {
if (eaip->target_objnum == OBJ_INDEX(Player_obj)) {
found = 1;
dist = vm_vec_dist_quick(&Enemy_attacker->pos, &Player_obj->pos);
vm_vec_normalized_dir(&v2t,&Objects[eaip->target_objnum].pos, &Enemy_attacker->pos);

dot = vm_vec_dot(&v2t, &Enemy_attacker->orient.vec.fvec);

gr_printf_no_resize(sx, sy, "#%i: %s", OBJ_INDEX(Enemy_attacker), Ships[Enemy_attacker->instance].ship_name);
gr_printf_no_resize(sx, sy, "#%i: %s", OBJ_INDEX(Enemy_attacker), Ships[Enemy_attacker->instance].get_display_string());
sy += dy;
gr_printf_no_resize(sx, sy, "Targ dist: %5.1f", dist);
sy += dy;
Expand Down
9 changes: 5 additions & 4 deletions code/io/keycontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ void process_debug_keys(int k)
object *objp = &Objects[Player_ai->target_objnum];

objp->flags.toggle(Object::Object_Flags::Invulnerable);
HUD_sourced_printf(HUD_SOURCE_HIDDEN, XSTR( "Player's target [%s] is %s", 13), Ships[objp->instance].ship_name, objp->flags[Object::Object_Flags::Invulnerable] ? XSTR( "now INVULNERABLE!", 11) : XSTR( "no longer invulnerable...", 12));
HUD_sourced_printf(HUD_SOURCE_HIDDEN, XSTR( "Player's target [%s] is %s", 13), Ships[objp->instance].get_display_string(), objp->flags[Object::Object_Flags::Invulnerable] ? XSTR( "now INVULNERABLE!", 11) : XSTR( "no longer invulnerable...", 12));
}
break;

Expand Down Expand Up @@ -1066,12 +1066,12 @@ void process_debug_keys(int k)

if (is_support_allowed(obj_to_rearm))
{
HUD_sourced_printf(HUD_SOURCE_HIDDEN, XSTR("Issuing rearm request for %s", 1610), Ships[obj_to_rearm->instance].ship_name);
HUD_sourced_printf(HUD_SOURCE_HIDDEN, XSTR("Issuing rearm request for %s", 1610), Ships[obj_to_rearm->instance].get_display_string());
ai_issue_rearm_request(obj_to_rearm);
}
else
{
HUD_sourced_printf(HUD_SOURCE_HIDDEN, XSTR("Cannot issue rearm request for %s", 1611), Ships[obj_to_rearm->instance].ship_name);
HUD_sourced_printf(HUD_SOURCE_HIDDEN, XSTR("Cannot issue rearm request for %s", 1611), Ships[obj_to_rearm->instance].get_display_string());
}

break;
Expand Down Expand Up @@ -1325,7 +1325,7 @@ void ppsk_hotkeys(int k)
HUD_sourced_printf(HUD_SOURCE_HIDDEN, XSTR( "No target to add/remove from set %d.", 26), hotkey_set+1);
else {
hud_target_hotkey_add_remove( hotkey_set, &Objects[Player_ai->target_objnum], HOTKEY_USER_ADDED);
HUD_sourced_printf(HUD_SOURCE_HIDDEN, XSTR( "%s added to set %d. (F%d)", 27), Ships[Objects[Player_ai->target_objnum].instance].ship_name, hotkey_set, 4+hotkey_set+1);
HUD_sourced_printf(HUD_SOURCE_HIDDEN, XSTR( "%s added to set %d. (F%d)", 27), Ships[Objects[Player_ai->target_objnum].instance].get_display_string(), hotkey_set, 4+hotkey_set+1);
}

break;
Expand Down Expand Up @@ -1569,6 +1569,7 @@ void game_process_cheats(int k)

ship *shipp = &Ships[Objects[objnum].instance];
shipp->ship_name[0] = '\0';
shipp->display_name.clear();
shipp->orders_accepted = (1<<NUM_COMM_ORDER_ITEMS)-1;

// Goober5000 - stolen from support ship creation
Expand Down
16 changes: 8 additions & 8 deletions code/mission/missionhotkey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ static UI_XSTR Hotkey_text[GR_NUM_RESOLUTIONS][HOTKEY_NUM_TEXT] = {


static struct {
const char *label;
SCP_string label;
int type;
int index;
int y; // Y coordinate of line
Expand Down Expand Up @@ -524,7 +524,7 @@ int hotkey_line_add(const char *text, int type, int index, int y)
}

// insert a line of hotkey smuck before line 'n'.
int hotkey_line_insert(int n, char *text, int type, int index)
int hotkey_line_insert(int n, const char *text, int type, int index)
{
int z;

Expand All @@ -545,15 +545,15 @@ int hotkey_line_insert(int n, char *text, int type, int index)

// insert a line of hotkey smuck somewhere between 'start' and end of list such that it is
// sorted by name
int hotkey_line_add_sorted(char *text, int type, int index, int start)
int hotkey_line_add_sorted(const char *text, int type, int index, int start)
{
int z;

if (Num_lines >= MAX_LINES)
return -1;

z = Num_lines - 1;
while ((z >= start) && ((Hotkey_lines[z].type == HOTKEY_LINE_SUBSHIP) || (stricmp(text, Hotkey_lines[z].label) < 0)))
while ((z >= start) && ((Hotkey_lines[z].type == HOTKEY_LINE_SUBSHIP) || (stricmp(text, Hotkey_lines[z].label.c_str()) < 0)))
z--;

z++;
Expand Down Expand Up @@ -620,7 +620,7 @@ int hotkey_build_team_listing(int enemy_team_mask, int y, bool list_enemies)

// be sure this ship isn't in a wing, and that the teams match
if ( iff_matches_mask(Ships[shipnum].team, team_mask) && (Ships[shipnum].wingnum < 0) ) {
hotkey_line_add_sorted(Ships[shipnum].ship_name, HOTKEY_LINE_SHIP, shipnum, start);
hotkey_line_add_sorted(Ships[shipnum].get_display_string(), HOTKEY_LINE_SHIP, shipnum, start);
}
}

Expand Down Expand Up @@ -652,7 +652,7 @@ int hotkey_build_team_listing(int enemy_team_mask, int y, bool list_enemies)
if (Wings[i].flags[Ship::Wing_Flags::Expanded]) {
for (j=0; j<Wings[i].current_count; j++) {
s = Wings[i].ship_index[j];
z = hotkey_line_insert(z + 1, Ships[s].ship_name, HOTKEY_LINE_SUBSHIP, s);
z = hotkey_line_insert(z + 1, Ships[s].get_display_string(), HOTKEY_LINE_SUBSHIP, s);
}
}
}
Expand Down Expand Up @@ -1172,7 +1172,7 @@ void mission_hotkey_do_frame(float /*frametime*/)
case HOTKEY_LINE_HEADING:
gr_set_color_fast(&Color_text_heading);

gr_get_string_size(&w, &h, Hotkey_lines[line].label);
gr_get_string_size(&w, &h, Hotkey_lines[line].label.c_str());
i = y + h / 2 - 1;
gr_line(Hotkey_list_coords[gr_screen.res][0], i, Hotkey_ship_x[gr_screen.res] - 2, i, GR_RESIZE_MENU);
gr_line(Hotkey_ship_x[gr_screen.res] + w + 1, i, Hotkey_list_coords[gr_screen.res][0] + Hotkey_list_coords[gr_screen.res][2], i, GR_RESIZE_MENU);
Expand Down Expand Up @@ -1251,7 +1251,7 @@ void mission_hotkey_do_frame(float /*frametime*/)
}

// draw ship/wing name
strcpy_s(buf, Hotkey_lines[line].label);
strcpy_s(buf, Hotkey_lines[line].label.c_str());
end_string_at_first_hash_symbol(buf);
if (Hotkey_lines[line].type == HOTKEY_LINE_SUBSHIP) {
// indent
Expand Down
Loading

0 comments on commit c13cb44

Please sign in to comment.