From c9dc032c91aaa0128ac6d8eb8990fbe203965f3f Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Wed, 1 Nov 2023 20:32:58 +0200 Subject: [PATCH 20/20] Make can_unit_continue_current_activity() to take map as parameter Unhardcode use of wld.map. See osdn #48929 Signed-off-by: Marko Lindqvist --- common/unit.c | 5 +++-- common/unit.h | 3 ++- server/citytools.c | 2 +- server/sanitycheck.c | 2 +- server/savegame/savegame2.c | 2 +- server/savegame/savegame3.c | 2 +- server/unithand.c | 2 +- server/unittools.c | 6 +++--- 8 files changed, 13 insertions(+), 11 deletions(-) diff --git a/common/unit.c b/common/unit.c index fb92c94436..7a6ea5596d 100644 --- a/common/unit.c +++ b/common/unit.c @@ -855,7 +855,8 @@ bool can_unit_paradrop(const struct unit *punit) /**********************************************************************//** Check if the unit's current activity is actually legal. **************************************************************************/ -bool can_unit_continue_current_activity(struct unit *punit) +bool can_unit_continue_current_activity(struct civ_map *nmap, + struct unit *punit) { enum unit_activity current = punit->activity; struct extra_type *target = punit->activity_target; @@ -866,7 +867,7 @@ bool can_unit_continue_current_activity(struct unit *punit) punit->activity = ACTIVITY_IDLE; punit->activity_target = NULL; - result = can_unit_do_activity_targeted(&(wld.map), punit, current2, target); + result = can_unit_do_activity_targeted(nmap, punit, current2, target); punit->activity = current; punit->activity_target = target; diff --git a/common/unit.h b/common/unit.h index ba76a9fbcb..8631364e34 100644 --- a/common/unit.h +++ b/common/unit.h @@ -330,7 +330,8 @@ bool can_unit_change_homecity_to(const struct unit *punit, const struct city *pcity); bool can_unit_change_homecity(const struct unit *punit); const char *get_activity_text(enum unit_activity activity); -bool can_unit_continue_current_activity(struct unit *punit); +bool can_unit_continue_current_activity(struct civ_map *nmap, + struct unit *punit); bool can_unit_do_activity(const struct civ_map *nmap, const struct unit *punit, enum unit_activity activity); diff --git a/server/citytools.c b/server/citytools.c index f923e9cfec..487273216a 100644 --- a/server/citytools.c +++ b/server/citytools.c @@ -1640,7 +1640,7 @@ void create_city(struct player *pplayer, struct tile *ptile, struct city *home = game_city_by_number(punit->homecity); /* Catch fortress building, transforming into ocean, etc. */ - if (!can_unit_continue_current_activity(punit)) { + if (!can_unit_continue_current_activity(&(wld.map), punit)) { unit_activities_cancel(punit); } diff --git a/server/sanitycheck.c b/server/sanitycheck.c index 62ff9f5434..e8ad0d5ff4 100644 --- a/server/sanitycheck.c +++ b/server/sanitycheck.c @@ -434,7 +434,7 @@ static void check_units(const char *file, const char *function, int line) SANITY_CHECK(player_unit_by_number(unit_owner(punit), punit->id) != NULL); - if (!can_unit_continue_current_activity(punit)) { + if (!can_unit_continue_current_activity(&(wld.map), punit)) { SANITY_FAIL("(%4d,%4d) %s has activity %s, " "but it can't continue at %s", TILE_XY(ptile), unit_rule_name(punit), diff --git a/server/savegame/savegame2.c b/server/savegame/savegame2.c index dadf51ec20..b2a8283274 100644 --- a/server/savegame/savegame2.c +++ b/server/savegame/savegame2.c @@ -3094,7 +3094,7 @@ static void sg_load_players(struct loaddata *loading) /* Make sure everything is consistent. */ players_iterate(pplayer) { unit_list_iterate(pplayer->units, punit) { - if (!can_unit_continue_current_activity(punit)) { + if (!can_unit_continue_current_activity(&(wld.map), punit)) { struct tile *ptile = unit_tile(punit); log_sg("%s doing illegal activity in savegame!", diff --git a/server/savegame/savegame3.c b/server/savegame/savegame3.c index dc8a872ff2..a9289f7eb9 100644 --- a/server/savegame/savegame3.c +++ b/server/savegame/savegame3.c @@ -4040,7 +4040,7 @@ static void sg_load_players(struct loaddata *loading) /* Make sure everything is consistent. */ players_iterate(pplayer) { unit_list_iterate(pplayer->units, punit) { - if (!can_unit_continue_current_activity(punit)) { + if (!can_unit_continue_current_activity(&(wld.map), punit)) { struct tile *ptile = unit_tile(punit); log_sg("%s doing illegal activity in savegame!", diff --git a/server/unithand.c b/server/unithand.c index 36e94751b8..d69f7bab2c 100644 --- a/server/unithand.c +++ b/server/unithand.c @@ -4092,7 +4092,7 @@ void unit_change_homecity_handling(struct unit *punit, struct city *new_pcity, } } - if (!can_unit_continue_current_activity(punit)) { + if (!can_unit_continue_current_activity(&(wld.map), punit)) { /* This is mainly for cases where unit owner changes to one not knowing * Railroad tech when unit is already building railroad. * Does also send_unit_info() */ diff --git a/server/unittools.c b/server/unittools.c index 24f919aac3..65fdfe0dfd 100644 --- a/server/unittools.c +++ b/server/unittools.c @@ -842,7 +842,7 @@ void unit_activities_cancel(struct unit *punit) void unit_activities_cancel_all_illegal_plr(const struct player *pplayer) { unit_list_iterate(pplayer->units, punit) { - if (!can_unit_continue_current_activity(punit)) { + if (!can_unit_continue_current_activity(&(wld.map), punit)) { unit_activities_cancel(punit); } } unit_list_iterate_end; @@ -854,7 +854,7 @@ void unit_activities_cancel_all_illegal_plr(const struct player *pplayer) void unit_activities_cancel_all_illegal_tile(const struct tile *ptile) { unit_list_iterate(ptile->units, punit) { - if (!can_unit_continue_current_activity(punit)) { + if (!can_unit_continue_current_activity(&(wld.map), punit)) { unit_activities_cancel(punit); } } unit_list_iterate_end; @@ -1605,7 +1605,7 @@ void transform_unit(struct unit *punit, const struct unit_type *to_unit, punit->server.current_form_turn = game.info.turn; unit_forget_last_activity(punit); - if (!can_unit_continue_current_activity(punit)) { + if (!can_unit_continue_current_activity(&(wld.map), punit)) { unit_activities_cancel(punit); } -- 2.42.0