From ed2041434e71640a3e02b3ba5e8f191910f6745d Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Thu, 12 Oct 2023 22:12:10 +0300 Subject: [PATCH 4/4] 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 | 16 ++++++++++------ 6 files changed, 24 insertions(+), 10 deletions(-) diff --git a/client/client_main.c b/client/client_main.c index 06a2a3e0dc..2016dae533 100644 --- a/client/client_main.c +++ b/client/client_main.c @@ -1369,6 +1369,7 @@ static void fc_interface_init_client(void) funcs->create_extra = NULL; funcs->destroy_extra = NULL; + funcs->destroy_city = NULL; funcs->player_tile_vision_get = client_map_is_known_and_seen; funcs->gui_color_free = color_free; diff --git a/common/fc_interface.h b/common/fc_interface.h index 03d4348498..2661bb9645 100644 --- a/common/fc_interface.h +++ b/common/fc_interface.h @@ -33,6 +33,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 87ea3c3626..f28a04f1b7 100644 --- a/common/player.c +++ b/common/player.c @@ -674,7 +674,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 5e223848c7..48658a8365 100644 --- a/server/citytools.c +++ b/server/citytools.c @@ -1674,7 +1674,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); @@ -1717,6 +1717,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) { @@ -1834,8 +1835,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 536483c8ad..e0f85fa21b 100644 --- a/server/srv_main.c +++ b/server/srv_main.c @@ -3428,6 +3428,7 @@ static void fc_interface_init_server(void) 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->gui_color_free = server_gui_color_free; diff --git a/server/unittools.c b/server/unittools.c index cd67eacec7..6afcbfe401 100644 --- a/server/unittools.c +++ b/server/unittools.c @@ -1588,9 +1588,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. */ @@ -3684,9 +3686,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. */ -- 2.42.0