From 3984c658929e557f944f0eec0be3604507344afd Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 19 Jun 2022 23:19:51 +0300 Subject: [PATCH 46/46] 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 | 29 ++++++++++++++++------------- server/unittools.h | 1 + 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/server/maphand.c b/server/maphand.c index 7f24c474ab..9e346e08c2 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 11b217bcd5..5148edb89d 100644 --- a/server/srv_main.c +++ b/server/srv_main.c @@ -1661,10 +1661,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(&(wld.map), 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; @@ -1692,10 +1689,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(&(wld.map), 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 39f2d15570..bb88363ca8 100644 --- a/server/unittools.c +++ b/server/unittools.c @@ -842,6 +842,21 @@ void unit_activities_cancel_all_illegal_tile(const struct tile *ptile) } unit_list_iterate_end; } +/**********************************************************************//** + 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(&(wld.map), ptile, ptile2) { + unit_activities_cancel_all_illegal_tile(ptile2); + } adjc_iterate_end; +} + /**********************************************************************//** Progress settlers in their current tasks, and units that is pillaging. @@ -1015,19 +1030,7 @@ static void update_unit_activity(struct unit *punit) } } unit_list_iterate_end; - unit_activities_cancel_all_illegal_tile(ptile); - - tile_changing_activities_iterate(act) { - if (act == 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(&(wld.map), ptile, ptile2) { - unit_activities_cancel_all_illegal_tile(ptile2); - } adjc_iterate_end; - break; - } - } tile_changing_activities_iterate_end; + unit_activities_cancel_all_illegal_area(ptile); } if (activity == ACTIVITY_FORTIFYING) { diff --git a/server/unittools.h b/server/unittools.h index b060593d30..02f30567d7 100644 --- a/server/unittools.h +++ b/server/unittools.h @@ -183,6 +183,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