From 6ba9d13c85781d23bcb90e6914b00df19e17b2f0 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 1 Apr 2023 14:38:51 +0300 Subject: [PATCH 12/12] AI: Fix check if new building enables/disables actions Check if an action is possible now, and the check if action will be possible with a new building, were not equivalent, causing their results to differ when they should have not. Changes made to the with-building check: - Stop passing the improvement to be built as parameter to every requirement check. The requirement is likely about some other building - Stop making also real check for any requirements that the building in question is present Originally reported by alain_bkr See osdn #42169 Signed-off-by: Marko Lindqvist --- ai/default/aicity.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/ai/default/aicity.c b/ai/default/aicity.c index 8070e788a7..f8e63d4fcc 100644 --- a/ai/default/aicity.c +++ b/ai/default/aicity.c @@ -1681,7 +1681,9 @@ static void adjust_improvement_wants_by_effects(struct ai_type *ait, /* Is it possible to do the action to the city right now? * - * (DiplRel requirements are ignored since actor_player is NULL) */ + * (DiplRel requirements are ignored since actor_player is NULL) + * + * See TODO below about keeping this in sync with 'will_be_possible' */ is_possible = is_action_possible_on_city(act_id, NULL, pcity); /* Will it be possible to do the action to the city if the building is @@ -1702,12 +1704,15 @@ static void adjust_improvement_wants_by_effects(struct ai_type *ait, active = FALSE; break; } - } - - if (!is_req_active(pplayer, NULL, pcity, pimprove, - city_tile(pcity), NULL, NULL, NULL, NULL, - NULL, - preq, RPT_POSSIBLE)) { + } else if (!is_req_active(pplayer, NULL, pcity, NULL, + city_tile(pcity), NULL, NULL, NULL, NULL, + NULL, + preq, RPT_POSSIBLE)) { + /* TODO: Make this more robust! Now we must be really careful + * that 'is_possible' is checked by exatly similar context + * to this 'will_be_possible' or either one may trip on + * a requirement that the other one does not, causing + * them to differ when they should not. */ active = FALSE; break; } -- 2.39.2