From 991f5bbd036b39aef6b45ef938c4923aea1bbf56 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Thu, 12 Oct 2023 22:12:10 +0300 Subject: [PATCH 8/8] Player removal: Clear city border claims See osdn #48837 Signed-off-by: Marko Lindqvist --- client/client_main.c | 1 + common/fc_interface.h | 1 + common/player.c | 6 +++++- server/citytools.c | 9 ++++++--- server/srv_main.c | 1 + server/unittools.c | 8 +++++--- tools/shared/tools_fc_interface.c | 2 ++ 7 files changed, 21 insertions(+), 7 deletions(-) diff --git a/client/client_main.c b/client/client_main.c index a6e49549db..db6d6fd389 100644 --- a/client/client_main.c +++ b/client/client_main.c @@ -1526,6 +1526,7 @@ static void fc_interface_init_client(void) funcs->server_setting_val_bitwise_get = client_ss_val_bitwise_get; funcs->create_extra = NULL; funcs->destroy_extra = NULL; + funcs->destroy_city = NULL; funcs->player_tile_vision_get = client_map_is_known_and_seen; funcs->player_tile_city_id_get = client_plr_tile_city_id_get; funcs->gui_color_free = color_free; diff --git a/common/fc_interface.h b/common/fc_interface.h index bf13601545..be510c9fac 100644 --- a/common/fc_interface.h +++ b/common/fc_interface.h @@ -40,6 +40,7 @@ struct functions { void (*create_extra)(struct tile *ptile, struct extra_type *pextra, struct player *pplayer); void (*destroy_extra)(struct tile *ptile, struct extra_type *pextra); + void (*destroy_city)(struct city *pcity); /* Returns iff the player 'pplayer' has the vision in the layer 'vision' at tile given by 'ptile'. */ bool (*player_tile_vision_get)(const struct tile *ptile, diff --git a/common/player.c b/common/player.c index 1e05c2f3d3..87f3b3e972 100644 --- a/common/player.c +++ b/common/player.c @@ -698,7 +698,11 @@ void player_clear(struct player *pplayer, bool full) } unit_list_iterate_end; city_list_iterate(pplayer->cities, pcity) { - game_remove_city(pcity); + if (fc_funcs->destroy_city != NULL) { + fc_funcs->destroy_city(pcity); + } else { + game_remove_city(pcity); + } } city_list_iterate_end; if (full) { diff --git a/server/citytools.c b/server/citytools.c index c01356f8f2..9676140528 100644 --- a/server/citytools.c +++ b/server/citytools.c @@ -1689,7 +1689,7 @@ void remove_city(struct city *pcity) } } unit_list_iterate_safe_end; - /* make sure ships are not left on land when city is removed. */ + /* Make sure ships are not left on land when city is removed. */ unit_list_iterate_safe(pcenter->units, punit) { bool moved; struct unit_type *punittype = unit_type_get(punit); @@ -1732,6 +1732,7 @@ void remove_city(struct city *pcity) dbv_init(&tile_processed, map_num_tiles()); for (tile_list_append(process_queue, pcenter); tile_list_size(process_queue) > 0;) { struct tile *ptile = tile_list_front(process_queue); + tile_list_pop_front(process_queue); dbv_set(&tile_processed, tile_index(ptile)); adjc_iterate(ptile, piter) { @@ -1855,8 +1856,10 @@ void remove_city(struct city *pcity) } } conn_list_iterate_end; - vision_clear_sight(old_vision); - vision_free(old_vision); + if (old_vision != NULL) { + vision_clear_sight(old_vision); + vision_free(old_vision); + } /* Infrastructures may have changed. */ send_tile_info(NULL, pcenter, FALSE); diff --git a/server/srv_main.c b/server/srv_main.c index 474b00febf..d4f203cdf6 100644 --- a/server/srv_main.c +++ b/server/srv_main.c @@ -3554,6 +3554,7 @@ static void fc_interface_init_server(void) funcs->server_setting_val_bitwise_get = server_ss_val_bitwise_get; funcs->create_extra = create_extra; funcs->destroy_extra = destroy_extra; + funcs->destroy_city = remove_city; funcs->player_tile_vision_get = map_is_known_and_seen; funcs->player_tile_city_id_get = server_plr_tile_city_id_get; funcs->gui_color_free = server_gui_color_free; diff --git a/server/unittools.c b/server/unittools.c index e1fd63fb9f..2c2f79b7e1 100644 --- a/server/unittools.c +++ b/server/unittools.c @@ -3895,9 +3895,11 @@ bool unit_move(struct unit *punit, struct tile *pdesttile, int move_cost, /* Clear old vision. */ unit_move_data_list_iterate(plist, pmove_data) { - vision_clear_sight(pmove_data->old_vision); - vision_free(pmove_data->old_vision); - pmove_data->old_vision = NULL; + if (pmove_data->old_vision != NULL) { + vision_clear_sight(pmove_data->old_vision); + vision_free(pmove_data->old_vision); + pmove_data->old_vision = NULL; + } } unit_move_data_list_iterate_end; /* Move consequences. */ diff --git a/tools/shared/tools_fc_interface.c b/tools/shared/tools_fc_interface.c index f99acbc038..d0f73ec878 100644 --- a/tools/shared/tools_fc_interface.c +++ b/tools/shared/tools_fc_interface.c @@ -61,6 +61,8 @@ void fc_interface_init_tool(void) { struct functions *funcs = fc_interface_funcs(); + memset(funcs, 0, sizeof(*funcs)); + /* May be used when generating help texts */ funcs->server_setting_by_name = server_ss_by_name; funcs->server_setting_name_get = server_ss_name_get; -- 2.42.0