From 5d2943ddff5be928baa3687adf0bb37f81d22c6a Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 20 Aug 2023 12:40:53 +0300 Subject: [PATCH 4/4] Tex: Maintain player specific cities lists See osdn #48523 Signed-off-by: Marko Lindqvist --- ai/tex/texaiplayer.c | 5 ++++- ai/tex/texaiplayer.h | 3 ++- ai/tex/texaiworld.c | 7 +++++++ server/advisors/infracache.c | 2 +- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/ai/tex/texaiplayer.c b/ai/tex/texaiplayer.c index cb967f3a5e..468117b41f 100644 --- a/ai/tex/texaiplayer.c +++ b/ai/tex/texaiplayer.c @@ -197,7 +197,8 @@ static enum texai_abort_msg_class texai_check_messages(struct ai_type *ait) if (tex_city != NULL) { choice = military_advisor_choose_build(ait, msg->plr, tex_city, - texai_map_get(), texai_player_units); + texai_map_get(), + texai_player_units); choice_req->city_id = tex_city->id; adv_choice_copy(&(choice_req->choice), choice); adv_free_choice(choice); @@ -284,6 +285,7 @@ void texai_player_alloc(struct ai_type *ait, struct player *pplayer) dai_data_init(ait, pplayer); player_data->units = unit_list_new(); + player_data->cities = city_list_new(); } /**********************************************************************//** @@ -299,6 +301,7 @@ void texai_player_free(struct ai_type *ait, struct player *pplayer) if (player_data != NULL) { player_set_ai_data(pplayer, ait, NULL); unit_list_destroy(player_data->units); + city_list_destroy(player_data->cities); FC_FREE(player_data); } } diff --git a/ai/tex/texaiplayer.h b/ai/tex/texaiplayer.h index c2c6030ce8..91d022d952 100644 --- a/ai/tex/texaiplayer.h +++ b/ai/tex/texaiplayer.h @@ -41,8 +41,9 @@ struct texai_reqs struct texai_plr { - struct ai_plr defai; /* Keep this first so default ai finds it */ + struct ai_plr defai; /* Keep this first so default AI finds it */ struct unit_list *units; + struct city_list *cities; }; struct ai_type *texai_get_self(void); /* Actually in texai.c */ diff --git a/ai/tex/texaiworld.c b/ai/tex/texaiworld.c index 8a314d773a..353fb1e72b 100644 --- a/ai/tex/texaiworld.c +++ b/ai/tex/texaiworld.c @@ -182,6 +182,7 @@ void texai_city_info_recv(void *data, enum texaimsgtype msgtype) if (msgtype == TEXAI_MSG_CITY_CREATED) { struct tile *ptile; + struct texai_plr *plr_data; if (idex_lookup_city(&texai_world, info->id) != NULL) { return; @@ -194,6 +195,8 @@ void texai_city_info_recv(void *data, enum texaimsgtype msgtype) pcity->id = info->id; idex_register_city(&texai_world, pcity); + plr_data = player_ai_data(pplayer, texai_get_self()); + city_list_prepend(plr_data->cities, pcity); tile_set_worked(ptile, pcity); } else { pcity = idex_lookup_city(&texai_world, info->id); @@ -240,8 +243,12 @@ void texai_city_destruction_recv(void *data) struct city *pcity = idex_lookup_city(&texai_world, info->id); if (pcity != NULL) { + struct texai_plr *plr_data; + adv_city_free(pcity); tile_set_worked(city_tile(pcity), NULL); + plr_data = player_ai_data(city_owner(pcity), texai_get_self()); + city_list_remove(plr_data->cities, pcity); idex_unregister_city(&texai_world, pcity); destroy_city_virtual(pcity); } else { diff --git a/server/advisors/infracache.c b/server/advisors/infracache.c index ad644cd4b7..ae00c1a05c 100644 --- a/server/advisors/infracache.c +++ b/server/advisors/infracache.c @@ -481,7 +481,7 @@ void adv_city_alloc(struct city *pcity) pcity->server.adv->act_cache = NULL; pcity->server.adv->act_cache_radius_sq = -1; - /* allocate memory for pcity->ai->act_cache */ + /* Allocate memory for pcity->ai->act_cache */ adv_city_update(pcity); } -- 2.40.1