From 9a36505d2a83031c022549dde7e535743cc61019 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 19 Jun 2022 23:24:57 +0300 Subject: [PATCH 19/19] Climate change: Check unit activities on tiles surrounding changed one See osdn #44155 Signed-off-by: Marko Lindqvist --- server/maphand.c | 2 +- server/srv_main.c | 10 ++-------- server/unittools.c | 37 +++++++++++++++++-------------------- server/unittools.h | 1 + 4 files changed, 21 insertions(+), 29 deletions(-) diff --git a/server/maphand.c b/server/maphand.c index 08f860f345..21be151e1d 100644 --- a/server/maphand.c +++ b/server/maphand.c @@ -220,7 +220,7 @@ void climate_change(bool warming, int effect) update_tile_knowledge(ptile); /* Check the unit activities. */ - unit_activities_cancel_all_illegal_tile(ptile); + unit_activities_cancel_all_illegal_area(ptile); } else if (old == new) { /* This counts toward a climate change although nothing is changed. */ diff --git a/server/srv_main.c b/server/srv_main.c index 0e16b5b440..57e3965994 100644 --- a/server/srv_main.c +++ b/server/srv_main.c @@ -1586,10 +1586,7 @@ static void end_turn(void) /* Unit activities at the target tile and its neighbors may now * be illegal because of present reqs. */ - unit_activities_cancel_all_illegal_tile(ptile); - adjc_iterate(ptile, n_tile) { - unit_activities_cancel_all_illegal_tile(n_tile); - } adjc_iterate_end; + unit_activities_cancel_all_illegal_area(ptile); } } whole_map_iterate_end; } extra_type_by_rmcause_iterate_end; @@ -1617,10 +1614,7 @@ static void end_turn(void) /* Unit activities at the target tile and its neighbors may now * be illegal because of !present reqs. */ - unit_activities_cancel_all_illegal_tile(ptile); - adjc_iterate(ptile, n_tile) { - unit_activities_cancel_all_illegal_tile(n_tile); - } adjc_iterate_end; + unit_activities_cancel_all_illegal_area(ptile); } } whole_map_iterate_end; } extra_type_by_cause_iterate_end; diff --git a/server/unittools.c b/server/unittools.c index 938aa9a0bd..c6ddb60c81 100644 --- a/server/unittools.c +++ b/server/unittools.c @@ -792,7 +792,22 @@ void unit_activities_cancel(struct unit *punit) send_unit_info(NULL, punit); } -/**********************************************************************//** +/************************************************************************** + Cancel all illegal activities done by units at the specified tile, + and surrounding tiles. For most rulesets this is for cancelling + irrigation on surrounding tiles when the central tile was the only + source of water, but does not provide water any more. +**************************************************************************/ +void unit_activities_cancel_all_illegal_area(const struct tile *ptile) +{ + unit_activities_cancel_all_illegal_tile(ptile); + + adjc_iterate(ptile, ptile2) { + unit_activities_cancel_all_illegal_tile(ptile2); + } adjc_iterate_end; +} + +/************************************************************************** Cancel all illegal activities done by units of the specified owner. **************************************************************************/ void unit_activities_cancel_all_illegal_plr(const struct player *pplayer) @@ -824,16 +839,10 @@ void unit_activities_cancel_all_illegal_tile(const struct tile *ptile) **************************************************************************/ static void update_unit_activity(struct unit *punit) { - const enum unit_activity tile_changing_actions[] = - { ACTIVITY_PILLAGE, ACTIVITY_GEN_ROAD, ACTIVITY_IRRIGATE, ACTIVITY_MINE, - ACTIVITY_BASE, ACTIVITY_TRANSFORM, ACTIVITY_POLLUTION, - ACTIVITY_FALLOUT, ACTIVITY_LAST }; - struct player *pplayer = unit_owner(punit); bool unit_activity_done = FALSE; enum unit_activity activity = punit->activity; struct tile *ptile = unit_tile(punit); - int i; switch (activity) { case ACTIVITY_IDLE: @@ -1004,19 +1013,7 @@ static void update_unit_activity(struct unit *punit) } unit_list_iterate_end; } - unit_activities_cancel_all_illegal_tile(ptile); - - for (i = 0; tile_changing_actions[i] != ACTIVITY_LAST; i++) { - if (tile_changing_actions[i] == activity) { - /* Some units nearby may not be able to continue their action, - * such as building irrigation if we removed the only source - * of water from them. */ - adjc_iterate(ptile, ptile2) { - unit_activities_cancel_all_illegal_tile(ptile2); - } adjc_iterate_end; - break; - } - } + unit_activities_cancel_all_illegal_area(ptile); } if (activity == ACTIVITY_FORTIFYING) { diff --git a/server/unittools.h b/server/unittools.h index 1161847c2e..bd554c3d36 100644 --- a/server/unittools.h +++ b/server/unittools.h @@ -169,6 +169,7 @@ bool unit_can_be_retired(struct unit *punit); void unit_activities_cancel(struct unit *punit); void unit_activities_cancel_all_illegal_plr(const struct player *pplayer); void unit_activities_cancel_all_illegal_tile(const struct tile *ptile); +void unit_activities_cancel_all_illegal_area(const struct tile *ptile); void unit_get_goods(struct unit *punit); -- 2.35.1