From 4d8490cfe9ec53d78316e434d40f7666104e0c5f Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Thu, 18 Aug 2022 02:17:47 +0300 Subject: [PATCH 34/34] Stop removing hiding units twice from the client Server was sending removal once for each "hiding" layer; subsurface and stealth, for units in either. Also rename unit_is_visible_on_layer() as unit_is_on_layer() as it does not really reflect unit visibility in layer V_MAIN. See osdn #45347 Signed-off-by: Marko Lindqvist --- server/maphand.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/server/maphand.c b/server/maphand.c index 636c847f82..5f75bc3eef 100644 --- a/server/maphand.c +++ b/server/maphand.c @@ -613,12 +613,15 @@ void send_tile_info(struct conn_list *dest, struct tile *ptile, } /**********************************************************************//** - Assumption: Each unit type is visible on only one layer. + Return whether unit is on this particular layer. + Callers assume that each unit is in just one layer, i.e., + though all units can be seen on V_MAIN, this returns FALSE + for layer V_MAIN for units that are visible ALSO in other layers. **************************************************************************/ -static bool unit_is_visible_on_layer(const struct unit *punit, - enum vision_layer vlayer) +static bool unit_is_on_layer(const struct unit *punit, + enum vision_layer vlayer) { - return XOR(vlayer == V_MAIN, is_hiding_unit(punit)); + return unit_type_get(punit)->vlayer == vlayer; } /**********************************************************************//** @@ -777,7 +780,7 @@ void map_show_tile(struct player *src_player, struct tile *ptile) vision_layer_iterate(v) { if (0 < map_get_seen(pplayer, ptile, v)) { unit_list_iterate(ptile->units, punit) { - if (unit_is_visible_on_layer(punit, v)) { + if (unit_is_on_layer(punit, v)) { send_unit_info(pplayer->connections, punit); } } unit_list_iterate_end; @@ -818,7 +821,7 @@ void map_hide_tile(struct player *src_player, struct tile *ptile) vision_layer_iterate(v) { if (0 < map_get_seen(pplayer, ptile, v)) { unit_list_iterate(ptile->units, punit) { - if (unit_is_visible_on_layer(punit, v)) { + if (unit_is_on_layer(punit, v)) { unit_goes_out_of_sight(pplayer, punit); } } unit_list_iterate_end; @@ -938,7 +941,7 @@ void map_change_seen(struct player *pplayer, TILE_XY(ptile), player_name(pplayer), player_number(pplayer)); unit_list_iterate(ptile->units, punit) { - if (unit_is_visible_on_layer(punit, V_INVIS) + if (unit_is_on_layer(punit, V_INVIS) && can_player_see_unit(pplayer, punit) && (plrtile->seen_count[V_MAIN] + change[V_MAIN] <= 0 || !pplayers_allied(pplayer, unit_owner(punit)))) { @@ -954,7 +957,7 @@ void map_change_seen(struct player *pplayer, TILE_XY(ptile), player_name(pplayer), player_number(pplayer)); unit_list_iterate(ptile->units, punit) { - if (unit_is_visible_on_layer(punit, V_SUBSURFACE) + if (unit_is_on_layer(punit, V_SUBSURFACE) && can_player_see_unit(pplayer, punit)) { unit_goes_out_of_sight(pplayer, punit); } @@ -967,7 +970,7 @@ void map_change_seen(struct player *pplayer, TILE_XY(ptile), player_name(pplayer), player_number(pplayer)); unit_list_iterate(ptile->units, punit) { - if (unit_is_visible_on_layer(punit, V_MAIN) + if (unit_is_on_layer(punit, V_MAIN) && can_player_see_unit(pplayer, punit)) { unit_goes_out_of_sight(pplayer, punit); } @@ -1048,7 +1051,7 @@ void map_change_seen(struct player *pplayer, /* Be sure not to revive dead unit on client when it's not yet * removed from the tile. This could happen when "unit_lost" lua script * somehow causes tile of the dead unit to unfog again. */ - if (unit_is_visible_on_layer(punit, V_MAIN) + if (unit_is_on_layer(punit, V_MAIN) && !punit->server.dying) { send_unit_info(pplayer->connections, punit); } @@ -1070,7 +1073,7 @@ void map_change_seen(struct player *pplayer, player_number(pplayer)); /* Discover units. */ unit_list_iterate(ptile->units, punit) { - if (unit_is_visible_on_layer(punit, V_INVIS)) { + if (unit_is_on_layer(punit, V_INVIS)) { send_unit_info(pplayer->connections, punit); } } unit_list_iterate_end; @@ -1083,7 +1086,7 @@ void map_change_seen(struct player *pplayer, player_number(pplayer)); /* Discover units. */ unit_list_iterate(ptile->units, punit) { - if (unit_is_visible_on_layer(punit, V_SUBSURFACE)) { + if (unit_is_on_layer(punit, V_SUBSURFACE)) { send_unit_info(pplayer->connections, punit); } } unit_list_iterate_end; -- 2.35.1