From a4893efc45f42e7ed5db4b52129c8c8794eca9c0 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 1 Apr 2023 14:57:06 +0300 Subject: [PATCH 20/20] 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/daicity.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ai/default/daicity.c b/ai/default/daicity.c index 17a4f18ba9..e6ecf843b2 100644 --- a/ai/default/daicity.c +++ b/ai/default/daicity.c @@ -1588,11 +1588,17 @@ static void adjust_improvement_wants_by_effects(struct ai_type *ait, .city = pcity, .building = pimprove, }; + + /* Do NOT pass building here, as the action might be about + * targeting some completely different building, AND + * the check to see if the action is possible before + * the building is there is also ignoring the buildings. + * We don't want those two results to differ for + * an unrelated reason to what we are evaluating. */ const struct req_context actenabler_ctxt = { .player = pplayer, .city = pcity, .tile = city_tile(pcity), - .building = pimprove, }; /* Remove team members from the equation */ @@ -1777,9 +1783,7 @@ static void adjust_improvement_wants_by_effects(struct ai_type *ait, active = FALSE; break; } - } - - if (!is_req_active(&actenabler_ctxt, NULL, preq, RPT_POSSIBLE)) { + } else if (!is_req_active(&actenabler_ctxt, NULL, preq, RPT_POSSIBLE)) { active = FALSE; break; } -- 2.39.2