From cdd02e65c625c7b270345a10ad1cadff56b976af Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 30 Dec 2023 16:51:24 +0200 Subject: [PATCH 23/23] Stop revealing flagless unit owner in combat messages See osdn #48878 Signed-off-by: Marko Lindqvist --- server/unithand.c | 281 ++++++++++++++++++++++++++++++--------------- server/unittools.c | 280 ++++++++++++++++++++++++++++++++------------ 2 files changed, 399 insertions(+), 162 deletions(-) diff --git a/server/unithand.c b/server/unithand.c index d69f7bab2c..cd1fccd88d 100644 --- a/server/unithand.c +++ b/server/unithand.c @@ -5045,55 +5045,105 @@ static bool do_attack(struct unit *punit, struct tile *def_tile, nation_rule_name(nation_of_unit(pdefender)), unit_rule_name(pdefender)); - notify_player(unit_owner(pwinner), unit_tile(pwinner), - E_UNIT_WIN_DEF, ftc_server, - /* TRANS: "Your green Legion [id:100 ...D:4.0 lost 1 HP, - * 9 HP remaining] survived the pathetic ...attack from the - * green Greek Warriors [id:90 ...A:1.0 HP:10]. */ - _("Your %s %s [id:%d %sD:%.1f lost %d HP, %d HP remaining]" - " survived the pathetic %sattack from the %s %s %s " - "[id:%d %sA:%.1f HP:%d]."), - defender_vet, - winner_link, - pdefender->id, - defender_fp, - (float)def_power/POWER_FACTOR, - def_hp_start - pdefender->hp, - pdefender->hp, - attacker_tired, - nation_adjective_for_player(unit_owner(ploser)), - attacker_vet, - loser_link, - punit->id, - attacker_fp, - (float)att_power/POWER_FACTOR, - att_hp_start); + if (is_flagless_to_player(ploser, unit_owner(pwinner))) { + notify_player(unit_owner(pwinner), unit_tile(pwinner), + E_UNIT_WIN_DEF, ftc_server, + /* TRANS: "Your green Legion [id:100 ...D:4.0 lost 1 HP, + * 9 HP remaining] survived the pathetic ...attack from + * green Warriors [id:90 ...A:1.0 HP:10]. */ + _("Your %s %s [id:%d %sD:%.1f lost %d HP, %d HP remaining]" + " survived the pathetic %sattack from %s %s " + "[id:%d %sA:%.1f HP:%d]."), + defender_vet, + winner_link, + pdefender->id, + defender_fp, + (float)def_power/POWER_FACTOR, + def_hp_start - pdefender->hp, + pdefender->hp, + attacker_tired, + attacker_vet, + loser_link, + punit->id, + attacker_fp, + (float)att_power/POWER_FACTOR, + att_hp_start); + } else { + notify_player(unit_owner(pwinner), unit_tile(pwinner), + E_UNIT_WIN_DEF, ftc_server, + /* TRANS: "Your green Legion [id:100 ...D:4.0 lost 1 HP, + * 9 HP remaining] survived the pathetic ...attack from the + * green Greek Warriors [id:90 ...A:1.0 HP:10]. */ + _("Your %s %s [id:%d %sD:%.1f lost %d HP, %d HP remaining]" + " survived the pathetic %sattack from the %s %s %s " + "[id:%d %sA:%.1f HP:%d]."), + defender_vet, + winner_link, + pdefender->id, + defender_fp, + (float)def_power/POWER_FACTOR, + def_hp_start - pdefender->hp, + pdefender->hp, + attacker_tired, + nation_adjective_for_player(unit_owner(ploser)), + attacker_vet, + loser_link, + punit->id, + attacker_fp, + (float)att_power/POWER_FACTOR, + att_hp_start); + } if (vet) { notify_unit_experience(pwinner); } - notify_player(unit_owner(ploser), def_tile, - E_UNIT_LOST_ATT, ftc_server, - /* TRANS: "Your attacking green Cannon [id:100 ...A:8.0 - * failed against the Greek Polish Destroyer [id:200 lost - * 27 HP, 3 HP remaining%s]!"; - * last %s is either "and ..." or empty string */ - _("Your attacking %s %s [id:%d %sA:%.1f HP:%d] failed " - "against the %s %s %s [id:%d lost %d HP, %d HP " - "remaining%s]!"), - attacker_vet, - loser_link, - punit->id, - attacker_fp, - (float)att_power/POWER_FACTOR, - att_hp_start, - nation_adjective_for_player(unit_owner(pdefender)), - defender_vet, - winner_link, - pdefender->id, - def_hp_start - pdefender->hp, - pdefender->hp, - vet ? unit_achieved_rank_string(pdefender) : ""); + + if (is_flagless_to_player(pdefender, unit_owner(ploser))) { + notify_player(unit_owner(ploser), def_tile, + E_UNIT_LOST_ATT, ftc_server, + /* TRANS: "Your attacking green Cannon [id:100 ...A:8.0 + * failed against green Destroyer [id:200 lost + * 27 HP, 3 HP remaining%s]!"; + * last %s is either "and ..." or empty string */ + _("Your attacking %s %s [id:%d %sA:%.1f HP:%d] failed " + "against %s %s [id:%d lost %d HP, %d HP " + "remaining%s]!"), + attacker_vet, + loser_link, + punit->id, + attacker_fp, + (float)att_power/POWER_FACTOR, + att_hp_start, + defender_vet, + winner_link, + pdefender->id, + def_hp_start - pdefender->hp, + pdefender->hp, + vet ? unit_achieved_rank_string(pdefender) : ""); + } else { + notify_player(unit_owner(ploser), def_tile, + E_UNIT_LOST_ATT, ftc_server, + /* TRANS: "Your attacking green Cannon [id:100 ...A:8.0 + * failed against the Greek Polish Destroyer [id:200 lost + * 27 HP, 3 HP remaining%s]!"; + * last %s is either "and ..." or empty string */ + _("Your attacking %s %s [id:%d %sA:%.1f HP:%d] failed " + "against the %s %s %s [id:%d lost %d HP, %d HP " + "remaining%s]!"), + attacker_vet, + loser_link, + punit->id, + attacker_fp, + (float)att_power/POWER_FACTOR, + att_hp_start, + nation_adjective_for_player(unit_owner(pdefender)), + defender_vet, + winner_link, + pdefender->id, + def_hp_start - pdefender->hp, + pdefender->hp, + vet ? unit_achieved_rank_string(pdefender) : ""); + } wipe_unit(ploser, ULR_KILLED, unit_owner(pwinner)); } else { @@ -5106,52 +5156,101 @@ static bool do_attack(struct unit *punit, struct tile *def_tile, nation_rule_name(nation_of_unit(pdefender)), unit_rule_name(pdefender)); - notify_player(unit_owner(pdefender), unit_tile(pdefender), - E_UNIT_LOST_DEF, ftc_server, - /* TRANS: "Your green Warriors [id:100 ...D:1.0 HP:10] - * lost to an attack by the Greek green Legion - * [id:200 ...A:4.0 lost 1 HP, has 9 HP remaining%s]." - * last %s is either "and ..." or empty string */ - _("Your %s %s [id:%d %sD:%.1f HP:%d] lost to an attack by " - "the %s %s %s [id:%d %sA:%.1f lost %d HP, has %d HP " - "remaining%s]."), - defender_vet, - loser_link, - pdefender->id, - defender_fp, - (float)def_power/POWER_FACTOR, - def_hp_start, - nation_adjective_for_player(unit_owner(punit)), - attacker_vet, - winner_link, - punit->id, - attacker_fp, - (float)att_power/POWER_FACTOR, - att_hp_start - pwinner->hp, - pwinner->hp, - vet ? unit_achieved_rank_string(punit) : ""); - - notify_player(unit_owner(punit), unit_tile(punit), - E_UNIT_WIN_ATT, ftc_server, - /* TRANS: "Your attacking green Legion [id:200 ...A:4.0 - * lost 1 HP, has 9 HP remaining] succeeded against the - * Greek green Warriors [id:100 HP:10]." */ - _("Your attacking %s %s [id:%d %s%sA:%.1f lost %d HP, " - "has %d remaining] succeeded against the %s %s %s " - "[id:%d HP:%d]."), - attacker_vet, - winner_link, - punit->id, - attacker_fp, - attacker_tired, - (float)att_power/POWER_FACTOR, - att_hp_start - pwinner->hp, - pwinner->hp, - nation_adjective_for_player(unit_owner(pdefender)), - defender_vet, - loser_link, - pdefender->id, - def_hp_start); + if (is_flagless_to_player(punit, unit_owner(pdefender))) { + notify_player(unit_owner(pdefender), unit_tile(pdefender), + E_UNIT_LOST_DEF, ftc_server, + /* TRANS: "Your green Warriors [id:100 ...D:1.0 HP:10] + * lost to an attack by green Legion + * [id:200 ...A:4.0 lost 1 HP, has 9 HP remaining%s]." + * last %s is either "and ..." or empty string */ + _("Your %s %s [id:%d %sD:%.1f HP:%d] lost to an attack by " + "%s %s [id:%d %sA:%.1f lost %d HP, has %d HP " + "remaining%s]."), + defender_vet, + loser_link, + pdefender->id, + defender_fp, + (float)def_power/POWER_FACTOR, + def_hp_start, + attacker_vet, + winner_link, + punit->id, + attacker_fp, + (float)att_power/POWER_FACTOR, + att_hp_start - pwinner->hp, + pwinner->hp, + vet ? unit_achieved_rank_string(punit) : ""); + } else { + notify_player(unit_owner(pdefender), unit_tile(pdefender), + E_UNIT_LOST_DEF, ftc_server, + /* TRANS: "Your green Warriors [id:100 ...D:1.0 HP:10] + * lost to an attack by the Greek green Legion + * [id:200 ...A:4.0 lost 1 HP, has 9 HP remaining%s]." + * last %s is either "and ..." or empty string */ + _("Your %s %s [id:%d %sD:%.1f HP:%d] lost to an attack by " + "the %s %s %s [id:%d %sA:%.1f lost %d HP, has %d HP " + "remaining%s]."), + defender_vet, + loser_link, + pdefender->id, + defender_fp, + (float)def_power/POWER_FACTOR, + def_hp_start, + nation_adjective_for_player(unit_owner(punit)), + attacker_vet, + winner_link, + punit->id, + attacker_fp, + (float)att_power/POWER_FACTOR, + att_hp_start - pwinner->hp, + pwinner->hp, + vet ? unit_achieved_rank_string(punit) : ""); + } + + if (is_flagless_to_player(pdefender, unit_owner(punit))) { + notify_player(unit_owner(punit), unit_tile(punit), + E_UNIT_WIN_ATT, ftc_server, + /* TRANS: "Your attacking green Legion [id:200 ...A:4.0 + * lost 1 HP, has 9 HP remaining] succeeded against + * green Warriors [id:100 HP:10]." */ + _("Your attacking %s %s [id:%d %s%sA:%.1f lost %d HP, " + "has %d remaining] succeeded against %s %s " + "[id:%d HP:%d]."), + attacker_vet, + winner_link, + punit->id, + attacker_fp, + attacker_tired, + (float)att_power/POWER_FACTOR, + att_hp_start - pwinner->hp, + pwinner->hp, + defender_vet, + loser_link, + pdefender->id, + def_hp_start); + } else { + notify_player(unit_owner(punit), unit_tile(punit), + E_UNIT_WIN_ATT, ftc_server, + /* TRANS: "Your attacking green Legion [id:200 ...A:4.0 + * lost 1 HP, has 9 HP remaining] succeeded against the + * Greek green Warriors [id:100 HP:10]." */ + _("Your attacking %s %s [id:%d %s%sA:%.1f lost %d HP, " + "has %d remaining] succeeded against the %s %s %s " + "[id:%d HP:%d]."), + attacker_vet, + winner_link, + punit->id, + attacker_fp, + attacker_tired, + (float)att_power/POWER_FACTOR, + att_hp_start - pwinner->hp, + pwinner->hp, + nation_adjective_for_player(unit_owner(pdefender)), + defender_vet, + loser_link, + pdefender->id, + def_hp_start); + } punit->moved = TRUE; /* We moved */ diff --git a/server/unittools.c b/server/unittools.c index a03996c648..6b74ef178b 100644 --- a/server/unittools.c +++ b/server/unittools.c @@ -2294,7 +2294,8 @@ void kill_unit(struct unit *pkiller, struct unit *punit, bool vet) struct tile *deftile = unit_tile(punit); int unitcount = 0; bool escaped; - bool flagless_attacker = unit_has_type_flag(pkiller, UTYF_FLAGLESS); + bool flagless_killer = unit_has_type_flag(pkiller, UTYF_FLAGLESS); + bool flagless_victim = unit_has_type_flag(punit, UTYF_FLAGLESS); sz_strlcpy(pkiller_link, unit_link(pkiller)); sz_strlcpy(punit_link, unit_tile_link(punit)); @@ -2303,7 +2304,7 @@ void kill_unit(struct unit *pkiller, struct unit *punit, bool vet) punit->server.dying = TRUE; unit_list_iterate(deftile->units, vunit) { - if ((flagless_attacker + if ((flagless_killer || pplayers_at_war(pvictor, unit_owner(vunit)) || unit_has_type_flag(vunit, UTYF_FLAGLESS)) && is_unit_reachable_at(vunit, pkiller, deftile)) { @@ -2397,16 +2398,28 @@ void kill_unit(struct unit *pkiller, struct unit *punit, bool vet) /* Inform the destroyer again if more than one unit was killed */ if (unitcount > 1) { - notify_player(pvictor, unit_tile(pkiller), E_UNIT_WIN_ATT, ftc_server, - /* TRANS: "... Cannon ... the Polish Destroyer ...." */ - PL_("Your attacking %s succeeded against the %s %s " - "(and %d other unit)!", - "Your attacking %s succeeded against the %s %s " - "(and %d other units)!", unitcount - 1), - pkiller_link, - nation_adjective_for_player(pvictim), - punit_link, - unitcount - 1); + if (flagless_victim) { + notify_player(pvictor, unit_tile(pkiller), E_UNIT_WIN_ATT, ftc_server, + /* TRANS: "... Cannon ... Destroyer ...." */ + PL_("Your attacking %s succeeded against %s " + "(and %d other unit)!", + "Your attacking %s succeeded against %s " + "(and %d other units)!", unitcount - 1), + pkiller_link, + punit_link, + unitcount - 1); + } else { + notify_player(pvictor, unit_tile(pkiller), E_UNIT_WIN_ATT, ftc_server, + /* TRANS: "... Cannon ... the Polish Destroyer ...." */ + PL_("Your attacking %s succeeded against the %s %s " + "(and %d other unit)!", + "Your attacking %s succeeded against the %s %s " + "(and %d other units)!", unitcount - 1), + pkiller_link, + nation_adjective_for_player(pvictim), + punit_link, + unitcount - 1); + } } if (vet) { @@ -2423,69 +2436,185 @@ void kill_unit(struct unit *pkiller, struct unit *punit, bool vet) if (num_killed[i] == 1) { if (i == player_index(pvictim)) { fc_assert(other_killed[i] == NULL); - notify_player(player_by_number(i), deftile, - E_UNIT_LOST_DEF, ftc_server, - /* TRANS: "Cannon ... the Polish Destroyer." */ - _("%s lost to an attack by the %s %s."), - punit_link, - nation_adjective_for_player(pvictor), - pkiller_link); - } else { - fc_assert(other_killed[i] != punit); - notify_player(player_by_number(i), deftile, - E_UNIT_LOST_DEF, ftc_server, - /* TRANS: "Cannon lost when the Polish Destroyer - * attacked the German Musketeers." */ - _("%s lost when the %s %s attacked the %s %s."), - unit_link(other_killed[i]), - nation_adjective_for_player(pvictor), - pkiller_link, - nation_adjective_for_player(pvictim), - punit_link); - } - } else if (num_killed[i] > 1) { - if (i == player_index(pvictim)) { - int others = num_killed[i] - 1; - if (others == 1) { + if (flagless_killer) { notify_player(player_by_number(i), deftile, E_UNIT_LOST_DEF, ftc_server, - /* TRANS: "Musketeers (and Cannon) lost to an - * attack from the Polish Destroyer." */ - _("%s (and %s) lost to an attack from the %s %s."), + /* TRANS: "Cannon ... Destroyer." */ + _("%s lost to an attack by %s."), punit_link, - unit_link(other_killed[i]), - nation_adjective_for_player(pvictor), pkiller_link); } else { notify_player(player_by_number(i), deftile, E_UNIT_LOST_DEF, ftc_server, - /* TRANS: "Musketeers and 3 other units lost to - * an attack from the Polish Destroyer." - * (only happens with at least 2 other units) */ - PL_("%s and %d other unit lost to an attack " - "from the %s %s.", - "%s and %d other units lost to an attack " - "from the %s %s.", others), + /* TRANS: "Cannon ... the Polish Destroyer." */ + _("%s lost to an attack by the %s %s."), punit_link, - others, nation_adjective_for_player(pvictor), pkiller_link); } } else { - notify_player(player_by_number(i), deftile, - E_UNIT_LOST_DEF, ftc_server, - /* TRANS: "2 units lost when the Polish Destroyer - * attacked the German Musketeers." - * (only happens with at least 2 other units) */ - PL_("%d unit lost when the %s %s attacked the %s %s.", - "%d units lost when the %s %s attacked the %s %s.", - num_killed[i]), - num_killed[i], - nation_adjective_for_player(pvictor), - pkiller_link, - nation_adjective_for_player(pvictim), - punit_link); + fc_assert(other_killed[i] != punit); + + if (flagless_victim) { + if (flagless_killer) { + notify_player(player_by_number(i), deftile, + E_UNIT_LOST_DEF, ftc_server, + /* TRANS: "Cannon lost when Destroyer + * attacked Musketeers." */ + _("%s lost when %s attacked %s."), + unit_link(other_killed[i]), + pkiller_link, + punit_link); + } else { + notify_player(player_by_number(i), deftile, + E_UNIT_LOST_DEF, ftc_server, + /* TRANS: "Cannon lost when the Polish Destroyer + * attacked Musketeers." */ + _("%s lost when the %s %s attacked %s."), + unit_link(other_killed[i]), + nation_adjective_for_player(pvictor), + pkiller_link, + punit_link); + } + } else { + if (flagless_killer) { + notify_player(player_by_number(i), deftile, + E_UNIT_LOST_DEF, ftc_server, + /* TRANS: "Cannon lost when Destroyer + * attacked the German Musketeers." */ + _("%s lost when %s attacked the %s %s."), + unit_link(other_killed[i]), + pkiller_link, + nation_adjective_for_player(pvictim), + punit_link); + } else { + notify_player(player_by_number(i), deftile, + E_UNIT_LOST_DEF, ftc_server, + /* TRANS: "Cannon lost when the Polish Destroyer + * attacked the German Musketeers." */ + _("%s lost when the %s %s attacked the %s %s."), + unit_link(other_killed[i]), + nation_adjective_for_player(pvictor), + pkiller_link, + nation_adjective_for_player(pvictim), + punit_link); + } + } + } + } else if (num_killed[i] > 1) { + if (i == player_index(pvictim)) { + int others = num_killed[i] - 1; + + if (others == 1) { + if (flagless_killer) { + notify_player(player_by_number(i), deftile, + E_UNIT_LOST_DEF, ftc_server, + /* TRANS: "Musketeers (and Cannon) lost to an + * attack from Destroyer." */ + _("%s (and %s) lost to an attack from %s."), + punit_link, + unit_link(other_killed[i]), + pkiller_link); + } else { + notify_player(player_by_number(i), deftile, + E_UNIT_LOST_DEF, ftc_server, + /* TRANS: "Musketeers (and Cannon) lost to an + * attack from the Polish Destroyer." */ + _("%s (and %s) lost to an attack from the %s %s."), + punit_link, + unit_link(other_killed[i]), + nation_adjective_for_player(pvictor), + pkiller_link); + } + } else { + if (flagless_killer) { + notify_player(player_by_number(i), deftile, + E_UNIT_LOST_DEF, ftc_server, + /* TRANS: "Musketeers and 3 other units lost to + * an attack from Destroyer." + * (only happens with at least 2 other units) */ + PL_("%s and %d other unit lost to an attack " + "from %s.", + "%s and %d other units lost to an attack " + "from %s.", others), + punit_link, + others, + pkiller_link); + } else { + notify_player(player_by_number(i), deftile, + E_UNIT_LOST_DEF, ftc_server, + /* TRANS: "Musketeers and 3 other units lost to + * an attack from the Polish Destroyer." + * (only happens with at least 2 other units) */ + PL_("%s and %d other unit lost to an attack " + "from the %s %s.", + "%s and %d other units lost to an attack " + "from the %s %s.", others), + punit_link, + others, + nation_adjective_for_player(pvictor), + pkiller_link); + } + } + } else { + if (flagless_victim) { + if (flagless_killer) { + notify_player(player_by_number(i), deftile, + E_UNIT_LOST_DEF, ftc_server, + /* TRANS: "2 units lost when Destroyer + * attacked Musketeers." + * (only happens with at least 2 other units) */ + PL_("%d unit lost when %s attacked %s.", + "%d units lost when %s attacked %s.", + num_killed[i]), + num_killed[i], + pkiller_link, + punit_link); + } else { + notify_player(player_by_number(i), deftile, + E_UNIT_LOST_DEF, ftc_server, + /* TRANS: "2 units lost when the Polish Destroyer + * attacked Musketeers." + * (only happens with at least 2 other units) */ + PL_("%d unit lost when the %s %s attacked %s.", + "%d units lost when the %s %s attacked %s.", + num_killed[i]), + num_killed[i], + nation_adjective_for_player(pvictor), + pkiller_link, + punit_link); + } + } else { + if (flagless_killer) { + notify_player(player_by_number(i), deftile, + E_UNIT_LOST_DEF, ftc_server, + /* TRANS: "2 units lost when Destroyer + * attacked the German Musketeers." + * (only happens with at least 2 other units) */ + PL_("%d unit lost when %s attacked the %s %s.", + "%d units lost when %s attacked the %s %s.", + num_killed[i]), + num_killed[i], + pkiller_link, + nation_adjective_for_player(pvictim), + punit_link); + } else { + notify_player(player_by_number(i), deftile, + E_UNIT_LOST_DEF, ftc_server, + /* TRANS: "2 units lost when the Polish Destroyer + * attacked the German Musketeers." + * (only happens with at least 2 other units) */ + PL_("%d unit lost when the %s %s attacked the %s %s.", + "%d units lost when the %s %s attacked the %s %s.", + num_killed[i]), + num_killed[i], + nation_adjective_for_player(pvictor), + pkiller_link, + nation_adjective_for_player(pvictim), + punit_link); + } + } } } } @@ -2496,15 +2625,24 @@ void kill_unit(struct unit *pkiller, struct unit *punit, bool vet) * different units escaped to. */ for (i = 0; i < slots; i++) { if (0 < num_escaped[i]) { - notify_player(player_by_number(i), deftile, - E_UNIT_ESCAPED, ftc_server, - PL_("%d unit escaped from attack by %s %s", - "%d units escaped from attack by %s %s", - num_escaped[i]), - num_escaped[i], - pkiller_link, - nation_adjective_for_player(pkiller->nationality) - ); + if (flagless_killer) { + notify_player(player_by_number(i), deftile, + E_UNIT_ESCAPED, ftc_server, + PL_("%d unit escaped from attack by %s", + "%d units escaped from attack by %s", + num_escaped[i]), + num_escaped[i], + pkiller_link); + } else { + notify_player(player_by_number(i), deftile, + E_UNIT_ESCAPED, ftc_server, + PL_("%d unit escaped from attack by %s %s", + "%d units escaped from attack by %s %s", + num_escaped[i]), + num_escaped[i], + pkiller_link, + nation_adjective_for_player(pkiller->nationality)); + } } } -- 2.43.0