From 8bd852440a0d96c31e204c4360a2f58dd520a65c Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 1 Apr 2023 15:05:24 +0300 Subject: [PATCH 10/10] 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 | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/ai/default/aicity.c b/ai/default/aicity.c index 8f83054a74..671c214792 100644 --- a/ai/default/aicity.c +++ b/ai/default/aicity.c @@ -1559,7 +1559,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 @@ -1580,11 +1582,14 @@ 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, - preq, RPT_POSSIBLE)) { + } else if (!is_req_active(pplayer, NULL, pcity, NULL, + city_tile(pcity), 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