From 588be54a45950e9667c417501dce5f7a05aab147 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 4 Sep 2022 06:06:58 +0300 Subject: [PATCH 62/62] AI: Switch from future tech research to real tech when possible Start researching real tech, if one becomes available during future tech research. Typically would happen when one loses previously known tech. Reported anonymously See osdn #44419 Signed-off-by: Marko Lindqvist --- ai/default/aitech.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/ai/default/aitech.c b/ai/default/aitech.c index cb38e50b7b..305b464604 100644 --- a/ai/default/aitech.c +++ b/ai/default/aitech.c @@ -83,20 +83,31 @@ static void dai_select_tech(struct ai_type *ait, goal_values[A_UNSET] = -1; goal_values[A_NONE] = -1; - /* if we are researching future techs, then simply continue with that. - * we don't need to do anything below. */ + /* if we are researching future techs, then simply continue with that + * when possible. */ if (is_future_tech(presearch->researching)) { - if (choice) { - choice->choice = presearch->researching; - choice->want = 1; - choice->current_want = 1; - } - if (goal) { - goal->choice = A_UNSET; - goal->want = 1; - goal->current_want = 1; + bool real_found = FALSE; + + advance_index_iterate(A_FIRST, i) { + if (research_invention_state(presearch, i) == TECH_PREREQS_KNOWN) { + real_found = TRUE; + break; + } + } advance_index_iterate_end; + + if (!real_found) { + if (choice) { + choice->choice = presearch->researching; + choice->want = 1; + choice->current_want = 1; + } + if (goal) { + goal->choice = A_UNSET; + goal->want = 1; + goal->current_want = 1; + } + return; } - return; } /* Fill in values for the techs: want of the tech -- 2.35.1