From 0eb8821d6930e3d772d88e8e0a04c09c69a118c8 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Thu, 12 Oct 2023 22:05:17 +0300 Subject: [PATCH 20/26] 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 | 8 ++++++-- server/srv_main.c | 1 + server/unittools.c | 16 ++++++++++------ tools/shared/tools_fc_interface.c | 2 ++ 7 files changed, 26 insertions(+), 9 deletions(-) diff --git a/client/client_main.c b/client/client_main.c index 03c8159b61..800d73a31e 100644 --- a/client/client_main.c +++ b/client/client_main.c @@ -1524,6 +1524,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 75df5902b8..6bd5946637 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 1017eee669..e49d59a9b1 100644 --- a/common/player.c +++ b/common/player.c @@ -707,7 +707,11 @@ void player_clear(struct player *pplayer, bool full) } unit_list_iterate_end; city_list_iterate(pplayer->cities, pcity) { - game_remove_city(&wld, pcity); + if (fc_funcs->destroy_city != NULL) { + fc_funcs->destroy_city(pcity); + } else { + game_remove_city(&wld, pcity); + } } city_list_iterate_end; if (full) { diff --git a/server/citytools.c b/server/citytools.c index 197b15262f..982a2c5a7a 100644 --- a/server/citytools.c +++ b/server/citytools.c @@ -1748,6 +1748,7 @@ void remove_city(struct city *pcity) moved = FALSE; adjc_iterate(&(wld.map), pcenter, tile1) { struct unit *ptrans; + if (!moved && is_native_tile(punittype, tile1)) { if (adv_could_unit_move_to_tile(punit, tile1) == 1) { /* Move */ @@ -1792,6 +1793,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(&(wld.map), ptile, piter) { @@ -1914,8 +1916,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(nullptr, pcenter, FALSE); diff --git a/server/srv_main.c b/server/srv_main.c index 94a15e7280..a704497d03 100644 --- a/server/srv_main.c +++ b/server/srv_main.c @@ -3706,6 +3706,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 b7328c7cc1..05567041ae 100644 --- a/server/unittools.c +++ b/server/unittools.c @@ -1850,9 +1850,11 @@ static void server_remove_unit_full(struct unit *punit, bool transported, /* Clear the vision before sending unit remove. Else, we might duplicate * the PACKET_UNIT_REMOVE if we lose vision of the unit tile. */ - vision_clear_sight(punit->server.vision); - vision_free(punit->server.vision); - punit->server.vision = NULL; + if (punit->server.vision != NULL) { + vision_clear_sight(punit->server.vision); + vision_free(punit->server.vision); + punit->server.vision = NULL; + } packet.unit_id = punit->id; /* Send to onlookers. */ @@ -4124,9 +4126,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 a90444ea4c..0cf0d613c4 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