diff --git a/server/maphand.cpp b/server/maphand.cpp index 23b0d2d556..1e3f29d7e5 100644 --- a/server/maphand.cpp +++ b/server/maphand.cpp @@ -199,13 +199,7 @@ void climate_change(bool warming, int effect) update_tile_knowledge(ptile); // Check the unit activities. - unit_list_iterate(ptile->units, punit) - { - if (!can_unit_continue_current_activity(punit)) { - unit_activity_handling(punit, ACTIVITY_IDLE); - } - } - unit_list_iterate_end; + unit_activities_cancel_all_illegal_area(ptile); } else if (old == tnew) { // This counts toward a climate change although nothing is changed. effect--; diff --git a/server/srv_main.cpp b/server/srv_main.cpp index b1b8a05319..423e41339a 100644 --- a/server/srv_main.cpp +++ b/server/srv_main.cpp @@ -1712,12 +1712,7 @@ void end_turn() /* Unit activities at the target tile and its neighbors may now * be illegal because of present reqs. */ - unit_activities_cancel_all_illegal(ptile); - adjc_iterate(&(wld.map), ptile, n_tile) - { - unit_activities_cancel_all_illegal(n_tile); - } - adjc_iterate_end; + unit_activities_cancel_all_illegal_area(ptile); } } whole_map_iterate_end; @@ -1747,12 +1742,7 @@ void end_turn() /* Unit activities at the target tile and its neighbors may now * be illegal because of !present reqs. */ - unit_activities_cancel_all_illegal(ptile); - adjc_iterate(&(wld.map), ptile, n_tile) - { - unit_activities_cancel_all_illegal(n_tile); - } - adjc_iterate_end; + unit_activities_cancel_all_illegal_area(ptile); } } whole_map_iterate_end; diff --git a/server/unittools.cpp b/server/unittools.cpp index 819c4c72d1..e8a94487bc 100644 --- a/server/unittools.cpp +++ b/server/unittools.cpp @@ -792,6 +792,22 @@ void unit_activities_cancel_all_illegal(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(ptile); + adjc_iterate(&wld.map, ptile, ptile2) + { + unit_activities_cancel_all_illegal(ptile2); + } + adjc_iterate_end; +} + /** Progress settlers in their current tasks, and units that is pillaging. @@ -934,21 +950,10 @@ static void unit_activity_complete(struct unit *punit) unit_list_iterate_end; } - 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(ptile2); - } - adjc_iterate_end; - break; - } - } - tile_changing_activities_iterate_end; + // 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. + unit_activities_cancel_all_illegal_area(ptile); } if (activity == ACTIVITY_FORTIFYING) { diff --git a/server/unittools.h b/server/unittools.h index 585c1d2506..6f78efcb86 100644 --- a/server/unittools.h +++ b/server/unittools.h @@ -171,6 +171,7 @@ void unit_did_action(struct unit *punit); bool unit_can_be_retired(struct unit *punit); void unit_activities_cancel_all_illegal(const struct tile *ptile); +void unit_activities_cancel_all_illegal_area(const struct tile *ptile); void unit_get_goods(struct unit *punit);