From a50f3f3218c618b4d68c5f58c6e1d59d2c84ca15 Mon Sep 17 00:00:00 2001 From: Alina Lenk Date: Mon, 6 May 2024 17:20:48 +0200 Subject: [PATCH 2/2] Don't establish player contact via flagless units See RM #558 Signed-off-by: Alina Lenk --- server/citytools.c | 2 +- server/plrhand.c | 3 +++ server/unithand.c | 2 +- server/unittools.c | 23 ++++++++++++++++++++--- server/unittools.h | 2 ++ 5 files changed, 27 insertions(+), 5 deletions(-) diff --git a/server/citytools.c b/server/citytools.c index 24fc2bad71..aa416e31a1 100644 --- a/server/citytools.c +++ b/server/citytools.c @@ -689,7 +689,7 @@ static void transfer_unit(struct unit *punit, struct city *tocity, return; } - maybe_make_contact(utile, to_player); + unit_make_contact(punit, utile, to_player); } unit_change_homecity_handling(punit, tocity, rehome); } diff --git a/server/plrhand.c b/server/plrhand.c index 2ce80c4366..dcdb431a2d 100644 --- a/server/plrhand.c +++ b/server/plrhand.c @@ -2367,6 +2367,9 @@ void maybe_make_contact(struct tile *ptile, struct player *pplayer) make_contact(pplayer, city_owner(pcity), ptile); } unit_list_iterate_safe(tile1->units, punit) { + if (unit_has_type_flag(punit, UTYF_FLAGLESS)) { + continue; /* Flagless unit can't make contact */ + } make_contact(pplayer, unit_owner(punit), ptile); } unit_list_iterate_safe_end; } square_iterate_end; diff --git a/server/unithand.c b/server/unithand.c index bbfeb3bf05..9e6ae577d9 100644 --- a/server/unithand.c +++ b/server/unithand.c @@ -3032,7 +3032,7 @@ static bool illegal_action_pay_price(struct player *pplayer, * distant target tile and maybe some contacts. */ map_show_circle(pplayer, tgt_tile, unit_type_get(act_unit)->vision_radius_sq); - maybe_make_contact(tgt_tile, pplayer); + unit_make_contact(act_unit, tgt_tile, pplayer); } if (act_unit->hp > 0) { diff --git a/server/unittools.c b/server/unittools.c index 5a00fd27d7..1978ba4f38 100644 --- a/server/unittools.c +++ b/server/unittools.c @@ -1736,7 +1736,7 @@ bool place_unit(struct unit *punit, struct player *pplayer, unit_list_prepend(pplayer->units, punit); unit_list_prepend(ptile->units, punit); - maybe_make_contact(ptile, unit_owner(punit)); + unit_make_contact(punit, ptile, nullptr); if (pcity && !unit_has_type_flag(punit, UTYF_NOHOME)) { fc_assert(punit->homecity == pcity->id); fc_assert(city_owner(pcity) == pplayer); @@ -3219,7 +3219,7 @@ bool do_paradrop(struct unit *punit, struct tile *ptile, char victim_link[MAX_LEN_LINK]; map_show_circle(pplayer, ptile, act_utype->vision_radius_sq); - maybe_make_contact(ptile, pplayer); + unit_make_contact(punit, ptile, pplayer); notify_player(pplayer, ptile, E_UNIT_LOST_MISC, ftc_server, _("Your %s was killed by enemy units at the " "paradrop destination."), @@ -4273,7 +4273,7 @@ bool unit_move(struct unit *punit, struct tile *pdesttile, int move_cost, if (unit_lives) { wakeup_neighbor_sentries(punit); } - maybe_make_contact(pdesttile, pplayer); + unit_make_contact(punit, pdesttile, pplayer); if (unit_lives) { /* Special checks for ground units in the ocean. */ @@ -5164,3 +5164,20 @@ void random_movements(struct player *pplayer) game.server.random_move_time = NULL; } + +/**********************************************************************//** + Make contact between a player and everyone adjacent to a tile via a unit + moving to that tile. Tile and player default to the unit's location and + owner if nullptr, but they may be different. +**************************************************************************/ +void unit_make_contact(const struct unit *punit, + struct tile *ptile, struct player *pplayer) { + fc_assert_ret(punit != nullptr); + + if (unit_has_type_flag(punit, UTYF_FLAGLESS)) { + return; /* Flagless unit can't make contact */ + } + + maybe_make_contact(ptile ? ptile : unit_tile(punit), + pplayer ? pplayer : unit_owner(punit)); +} diff --git a/server/unittools.h b/server/unittools.h index c2f8b60637..59acc4d0c3 100644 --- a/server/unittools.h +++ b/server/unittools.h @@ -124,6 +124,8 @@ void unit_assign_specific_activity_target(struct unit *punit, enum unit_activity *activity, struct extra_type **target); void unit_forget_last_activity(struct unit *punit); +void unit_make_contact(const struct unit *punit, + struct tile *ptile, struct player *pplayer); /* creation/deletion/upgrading */ void transform_unit(struct unit *punit, const struct unit_type *to_unit, -- 2.34.1