From 34e542a3a9df80cf29c66e565eaeefb5028b4767 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Mon, 13 Feb 2023 05:26:35 +0200 Subject: [PATCH 06/24] Lua: Call tile_change_side_effects() after tile changes See osdn #46425 Signed-off-by: Marko Lindqvist --- server/citytools.c | 2 +- server/edithand.c | 2 ++ server/maphand.c | 10 ++++++++-- server/maphand.h | 2 +- server/scripting/api_server_edit.c | 21 ++++++++++++++------- server/srv_main.c | 4 ++-- server/unittools.c | 2 +- 7 files changed, 29 insertions(+), 14 deletions(-) diff --git a/server/citytools.c b/server/citytools.c index 28c7506ba4..187e13c304 100644 --- a/server/citytools.c +++ b/server/citytools.c @@ -1927,7 +1927,7 @@ void remove_city(struct city *pcity) /* At least sentried helicopters need to go idle, maybe others. * In alien ruleset, city center might have provided water source * for adjacent tile. */ - tile_change_side_effects(pcenter); + tile_change_side_effects(pcenter, FALSE); } /************************************************************************//** diff --git a/server/edithand.c b/server/edithand.c index 62c648265a..fb61400822 100644 --- a/server/edithand.c +++ b/server/edithand.c @@ -145,6 +145,8 @@ static void check_edited_tile_terrains(void) assign_continent_numbers(); send_all_known_tiles(NULL); need_continents_reassigned = FALSE; + + /* FIXME: adv / ai phase handling like in check_terrain_change() */ } #ifdef SANITY_CHECKING diff --git a/server/maphand.c b/server/maphand.c index 7c90741ac2..bcca8d024a 100644 --- a/server/maphand.c +++ b/server/maphand.c @@ -223,7 +223,7 @@ void climate_change(bool warming, int effect) check_terrain_change(ptile, old); update_tile_knowledge(ptile); - tile_change_side_effects(ptile); + tile_change_side_effects(ptile, FALSE); } else if (old == new) { /* This counts toward a climate change although nothing is changed. */ @@ -2595,8 +2595,9 @@ void give_distorted_map(struct player *pfrom, struct player *pto, after this call. @param ptile tile that has changed + @param refresh_city whether city working the tile should be refreshed **************************************************************************/ -void tile_change_side_effects(struct tile *ptile) +void tile_change_side_effects(struct tile *ptile, bool refresh_city) { struct city *pcity = ptile->worked; @@ -2607,5 +2608,10 @@ void tile_change_side_effects(struct tile *ptile) && get_city_tile_output_bonus(pcity, ptile, NULL, EFT_TILE_WORKABLE) <= 0) { city_map_update_empty(pcity, ptile); pcity->specialists[DEFAULT_SPECIALIST]++; + + if (refresh_city) { + auto_arrange_workers(pcity); + send_city_info(NULL, pcity); + } } } diff --git a/server/maphand.h b/server/maphand.h index 4faa3bc5f1..922c14f1de 100644 --- a/server/maphand.h +++ b/server/maphand.h @@ -141,7 +141,7 @@ void destroy_extra(struct tile *ptile, struct extra_type *pextra); void give_distorted_map(struct player *pfrom, struct player *pto, int prob, bool reveal_cities); -void tile_change_side_effects(struct tile *ptile) +void tile_change_side_effects(struct tile *ptile, bool refresh_city) fc__attribute((nonnull (1))); #endif /* FC__MAPHAND_H */ diff --git a/server/scripting/api_server_edit.c b/server/scripting/api_server_edit.c index 49dcff5a6f..768f9b8492 100644 --- a/server/scripting/api_server_edit.c +++ b/server/scripting/api_server_edit.c @@ -577,19 +577,25 @@ bool api_edit_change_terrain(lua_State *L, Tile *ptile, Terrain *pterr) old_terrain = tile_terrain(ptile); if (old_terrain == pterr - || (terrain_has_flag(pterr, TER_NO_CITIES) && tile_city(ptile) != NULL)) { + || (terrain_has_flag(pterr, TER_NO_CITIES) + && tile_city(ptile) != NULL)) { return FALSE; } - + tile_change_terrain(ptile, pterr); fix_tile_on_terrain_change(ptile, old_terrain, FALSE); if (need_to_reassign_continents(old_terrain, pterr)) { assign_continent_numbers(); + + /* FIXME: adv / ai phase handling like in check_terrain_change() */ + send_all_known_tiles(NULL); } update_tile_knowledge(ptile); + tile_change_side_effects(ptile, TRUE); + return TRUE; } @@ -831,23 +837,23 @@ bool api_edit_trait_mod_set(lua_State *L, Player *pplayer, Create a new owned extra. **************************************************************************/ void api_edit_create_owned_extra(lua_State *L, Tile *ptile, - const char *name, - Player *pplayer) + const char *name, Player *pplayer) { struct extra_type *pextra; LUASCRIPT_CHECK_STATE(L); LUASCRIPT_CHECK_ARG_NIL(L, ptile, 2, Tile); - if (!name) { + if (name == NULL) { return; } pextra = extra_type_by_rule_name(name); - if (pextra) { + if (pextra != NULL) { create_extra(ptile, pextra, pplayer); update_tile_knowledge(ptile); + tile_change_side_effects(ptile, TRUE); } } @@ -886,7 +892,7 @@ void api_edit_remove_extra(lua_State *L, Tile *ptile, const char *name) LUASCRIPT_CHECK_STATE(L); LUASCRIPT_CHECK_ARG_NIL(L, ptile, 2, Tile); - if (!name) { + if (name == NULL) { return; } @@ -895,6 +901,7 @@ void api_edit_remove_extra(lua_State *L, Tile *ptile, const char *name) if (pextra != NULL && tile_has_extra(ptile, pextra)) { tile_extra_rm_apply(ptile, pextra); update_tile_knowledge(ptile); + tile_change_side_effects(ptile, TRUE); } } diff --git a/server/srv_main.c b/server/srv_main.c index 1ef702435e..8b4cfd84c5 100644 --- a/server/srv_main.c +++ b/server/srv_main.c @@ -1716,7 +1716,7 @@ static void end_turn(void) /* Activities at the target tile and its neighbors may now * be illegal because of present reqs. */ - tile_change_side_effects(ptile); + tile_change_side_effects(ptile, FALSE); } } whole_map_iterate_end; } extra_type_by_rmcause_iterate_end; @@ -1744,7 +1744,7 @@ static void end_turn(void) /* Activities at the target tile and its neighbors may now * be illegal because of !present reqs. */ - tile_change_side_effects(ptile); + tile_change_side_effects(ptile, FALSE); } } whole_map_iterate_end; } extra_type_by_cause_iterate_end; diff --git a/server/unittools.c b/server/unittools.c index 140887573c..bd63f3280e 100644 --- a/server/unittools.c +++ b/server/unittools.c @@ -1071,7 +1071,7 @@ static void update_unit_activity(struct unit *punit) } } unit_list_iterate_end; - tile_change_side_effects(ptile); + tile_change_side_effects(ptile, FALSE); } if (activity == ACTIVITY_FORTIFYING) { -- 2.39.1