From 8660e81bc2ee60c587747c74db317db7ade0c750 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 16 Sep 2023 22:10:32 +0300 Subject: [PATCH 22/22] Don't tell flagless unit owner on info popup See osdn #48637 Signed-off-by: Marko Lindqvist --- client/text.c | 149 +++++++++++++++++++++++++--------------------- client/tilespec.c | 8 +-- common/unit.c | 24 ++++++++ common/unit.h | 2 + 4 files changed, 108 insertions(+), 75 deletions(-) diff --git a/client/text.c b/client/text.c index ebc29d412e..5a55adfeb5 100644 --- a/client/text.c +++ b/client/text.c @@ -164,6 +164,9 @@ const char *popup_info_text(struct tile *ptile) char nation[2 * MAX_LEN_NAME + 32]; int tile_x, tile_y, nat_x, nat_y; bool first; + struct player *plr = client_player(); + bool flaggy_unit = (punit != nullptr + && !is_flagless_to_player(punit, plr)); astr_clear(&str); index_to_map_pos(&tile_x, &tile_y, tile_index(ptile)); @@ -193,20 +196,20 @@ const char *popup_info_text(struct tile *ptile) } } } extra_type_iterate_end; + if (BORDERS_DISABLED != game.info.borders && !pcity) { struct player *owner = tile_owner(ptile); get_full_username(username, sizeof(username), owner); get_full_nation(nation, sizeof(nation), owner); - if (NULL != client.conn.playing && owner == client.conn.playing) { + if (plr != nullptr && owner == plr) { astr_add_line(&str, _("Our territory")); - } else if (NULL != owner && NULL == client.conn.playing) { + } else if (owner != nullptr && plr == nullptr) { /* TRANS: "Territory of ()" */ astr_add_line(&str, _("Territory of %s (%s)"), username, nation); - } else if (NULL != owner) { - struct player_diplstate *ds = player_diplstate_get(client.conn.playing, - owner); + } else if (owner != nullptr) { + struct player_diplstate *ds = player_diplstate_get(plr, owner); if (ds->type == DS_CEASEFIRE) { int turns = ds->turns_left; @@ -241,7 +244,8 @@ const char *popup_info_text(struct tile *ptile) astr_add_line(&str, _("Unclaimed territory")); } } - if (pcity) { + + if (pcity != nullptr) { /* Look at city owner, not tile owner (the two should be the same, if * borders are in use). */ struct player *owner = city_owner(pcity); @@ -251,13 +255,13 @@ const char *popup_info_text(struct tile *ptile) get_full_username(username, sizeof(username), owner); get_full_nation(nation, sizeof(nation), owner); - if (NULL == client.conn.playing || owner == client.conn.playing) { + if (plr == nullptr || owner == plr) { /* TRANS: "City: | ()" */ astr_add_line(&str, _("City: %s | %s (%s)"), city_name_get(pcity), username, nation); } else { - struct player_diplstate *ds - = player_diplstate_get(client_player(), owner); + struct player_diplstate *ds = player_diplstate_get(plr, owner); + if (ds->type == DS_CEASEFIRE) { int turns = ds->turns_left; @@ -284,7 +288,8 @@ const char *popup_info_text(struct tile *ptile) diplo_city_adjectives[ds->type]); } } - if (can_player_see_units_in_city(client_player(), pcity)) { + + if (can_player_see_units_in_city(plr, pcity)) { int count = unit_list_size(ptile->units); if (count > 0) { @@ -304,6 +309,7 @@ const char *popup_info_text(struct tile *ptile) astr_add(&str, _(" | Not occupied.")); } } + improvement_iterate(pimprove) { if (is_improvement_visible(pimprove) && city_has_building(pcity, pimprove)) { @@ -345,83 +351,87 @@ const char *popup_info_text(struct tile *ptile) if (strlen(activity_text) > 0) { astr_add_line(&str, _("Activity: %s"), activity_text); } - if (punit && !pcity) { + + if (punit != nullptr && pcity == nullptr) { struct player *owner = unit_owner(punit); const struct unit_type *ptype = unit_type_get(punit); - get_full_username(username, sizeof(username), owner); - get_full_nation(nation, sizeof(nation), owner); + if (flaggy_unit) { + get_full_username(username, sizeof(username), owner); + get_full_nation(nation, sizeof(nation), owner); - if (!client_player() || owner == client_player()) { - struct city *hcity = player_city_by_number(owner, punit->homecity); + if (plr == nullptr || owner == plr) { + struct city *hcity = player_city_by_number(owner, punit->homecity); - /* TRANS: "Unit: | ()" */ - astr_add_line(&str, _("Unit: %s | %s (%s)"), - utype_name_translation(ptype), username, nation); + /* TRANS: "Unit: | ()" */ + astr_add_line(&str, _("Unit: %s | %s (%s)"), + utype_name_translation(ptype), username, nation); - if (game.info.citizen_nationality - && unit_nationality(punit) != unit_owner(punit)) { - if (hcity != NULL) { - /* TRANS: on own line immediately following \n, "from | - * people" */ - astr_add_line(&str, _("from %s | %s people"), city_name_get(hcity), - nation_adjective_for_player(unit_nationality(punit))); + if (game.info.citizen_nationality + && unit_nationality(punit) != owner) { + if (hcity != nullptr) { + /* TRANS: on own line immediately following \n, "from | + * people" */ + astr_add_line(&str, _("from %s | %s people"), city_name_get(hcity), + nation_adjective_for_player(unit_nationality(punit))); + } else { + /* TRANS: Nationality of the people comprising a unit, if + * different from owner. */ + astr_add_line(&str, _("%s people"), + nation_adjective_for_player(unit_nationality(punit))); + } + } else if (hcity != nullptr) { + /* TRANS: on own line immediately following \n, ... */ + astr_add_line(&str, _("from %s"), city_name_get(hcity)); + } + } else if (owner != nullptr) { + struct player_diplstate *ds = player_diplstate_get(plr, owner); + + if (ds->type == DS_CEASEFIRE) { + int turns = ds->turns_left; + + /* TRANS: "Unit: | (, + * turn cease-fire)" */ + astr_add_line(&str, PL_("Unit: %s | %s (%s, %d turn cease-fire)", + "Unit: %s | %s (%s, %d turn cease-fire)", + turns), + utype_name_translation(ptype), + username, nation, turns); + } else if (ds->type == DS_ARMISTICE) { + int turns = ds->turns_left; + + /* TRANS: "Unit: | (, + * turn armistice)" */ + astr_add_line(&str, PL_("Unit: %s | %s (%s, %d turn armistice)", + "Unit: %s | %s (%s, %d turn armistice)", + turns), + utype_name_translation(ptype), + username, nation, turns); } else { - /* TRANS: Nationality of the people comprising a unit, if - * different from owner. */ - astr_add_line(&str, _("%s people"), - nation_adjective_for_player(unit_nationality(punit))); + /* TRANS: "Unit: | (, + * )" */ + astr_add_line(&str, _("Unit: %s | %s (%s, %s)"), + utype_name_translation(ptype), username, nation, + diplo_city_adjectives[ds->type]); } - } else if (hcity != NULL) { - /* TRANS: on own line immediately following \n, ... */ - astr_add_line(&str, _("from %s"), city_name_get(hcity)); - } - } else if (NULL != owner) { - struct player_diplstate *ds = player_diplstate_get(client_player(), - owner); - if (ds->type == DS_CEASEFIRE) { - int turns = ds->turns_left; - - /* TRANS: "Unit: | (, - * turn cease-fire)" */ - astr_add_line(&str, PL_("Unit: %s | %s (%s, %d turn cease-fire)", - "Unit: %s | %s (%s, %d turn cease-fire)", - turns), - utype_name_translation(ptype), - username, nation, turns); - } else if (ds->type == DS_ARMISTICE) { - int turns = ds->turns_left; - - /* TRANS: "Unit: | (, - * turn armistice)" */ - astr_add_line(&str, PL_("Unit: %s | %s (%s, %d turn armistice)", - "Unit: %s | %s (%s, %d turn armistice)", - turns), - utype_name_translation(ptype), - username, nation, turns); - } else { - /* TRANS: "Unit: | (, - * )" */ - astr_add_line(&str, _("Unit: %s | %s (%s, %s)"), - utype_name_translation(ptype), username, nation, - diplo_city_adjectives[ds->type]); } + } else { + astr_add_line(&str, _("Unit: %s"), utype_name_translation(ptype)); } combat_odds_to_astr(&str, get_units_in_focus(), ptile, punit, "%%"); - if (unit_owner(punit) == client_player() - || client_is_global_observer()) { + if (owner == plr || client_is_global_observer()) { /* Show bribe cost for own units. */ astr_add_line(&str, _("Probable bribe cost: %d"), - unit_bribe_cost(punit, NULL)); + unit_bribe_cost(punit, nullptr)); } else { /* We can only give an (lower) boundary for units of other players. */ astr_add_line(&str, _("Estimated bribe cost: > %d"), - unit_bribe_cost(punit, client_player())); + unit_bribe_cost(punit, plr)); } - if ((NULL == client.conn.playing || owner == client.conn.playing) + if ((plr == nullptr || owner == plr) && unit_list_size(ptile->units) >= 2) { /* TRANS: "5 more" units on this tile */ astr_add(&str, _(" (%d more)"), unit_list_size(ptile->units) - 1); @@ -429,6 +439,7 @@ const char *popup_info_text(struct tile *ptile) } astr_break_lines(&str, LINE_BREAK); + return astr_str(&str); } @@ -477,8 +488,8 @@ const char *unit_description(struct unit *punit) int pcity_near_dist; struct player *owner = unit_owner(punit); struct player *nationality = unit_nationality(punit); - struct city *pcity = - player_city_by_number(owner, punit->homecity); + struct city *pcity + = player_city_by_number(owner, punit->homecity); struct city *pcity_near = get_nearest_city(punit, &pcity_near_dist); const struct unit_type *ptype = unit_type_get(punit); static struct astring str = ASTRING_INIT; diff --git a/client/tilespec.c b/client/tilespec.c index 13f6731c79..415ec00f71 100644 --- a/client/tilespec.c +++ b/client/tilespec.c @@ -4573,9 +4573,7 @@ static int fill_unit_sprite_array(const struct tileset *t, if (backdrop) { if (!gui_options.solid_color_behind_units) { - if (!unit_has_type_flag(punit, UTYF_FLAGLESS) - || client_is_global_observer() - || unit_owner(punit) == client_player()) { + if (!is_flagless_to_player(punit, client_player())) { ADD_SPRITE(get_unit_nation_flag_sprite(t, punit), TRUE, FULL_TILE_X_OFFSET + t->unit_flag_offset_x, FULL_TILE_Y_OFFSET + t->unit_flag_offset_y); @@ -5840,9 +5838,7 @@ int fill_sprite_array(struct tileset *t, || (gui_options.draw_focus_unit && unit_is_in_focus(punit)))); bool flagless = (do_draw_unit - && unit_has_type_flag(punit, UTYF_FLAGLESS) - && !client_is_global_observer() - && unit_owner(punit) != client_player()); + && is_flagless_to_player(punit, client_player())); bool solid_bg = (gui_options.solid_color_behind_units && ((do_draw_unit && !flagless) || (pcity != nullptr && gui_options.draw_cities) diff --git a/common/unit.c b/common/unit.c index 416ec27bfe..fd1da788f9 100644 --- a/common/unit.c +++ b/common/unit.c @@ -352,6 +352,30 @@ bool is_special_unit(const struct unit *punit) return unit_has_type_flag(punit, UTYF_CIVILIAN); } +/**********************************************************************//** + Does player see flag of the unit? + + @param punit Unit to check flag for + @param pplayer Player whose vision we're interested about, or nullptr + for global observer. + @return Is flag seen +**************************************************************************/ +bool is_flagless_to_player(const struct unit *punit, + const struct player *pplayer) +{ + if (unit_owner(punit) != pplayer + && unit_has_type_flag(punit, UTYF_FLAGLESS)) { + if (pplayer == nullptr) { + /* Global observer always sees the flags */ + return FALSE; + } + + return TRUE; + } + + return FALSE; +} + /**********************************************************************//** Return TRUE iff this unit can do the specified generalized (ruleset defined) action enabler controlled action. diff --git a/common/unit.h b/common/unit.h index c6f4d89cb6..bc1d24829e 100644 --- a/common/unit.h +++ b/common/unit.h @@ -358,6 +358,8 @@ bool is_occupying_unit(const struct unit *punit); bool is_enter_borders_unit(const struct unit *punit); bool is_guard_unit(const struct unit *punit); bool is_special_unit(const struct unit *punit); +bool is_flagless_to_player(const struct unit *punit, + const struct player *pplayer); bool unit_can_do_action(const struct unit *punit, const action_id act_id); bool unit_can_do_action_result(const struct unit *punit, -- 2.40.1