From 50c1eb46479749b8cd4212faeaf1055a7dffeae4 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 10 Sep 2022 02:58:57 +0300 Subject: [PATCH 50/50] AI: Refactor defender unit selection To make future fixes easier. See osdn #45597 Signed-off-by: Marko Lindqvist --- ai/default/daimilitary.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ai/default/daimilitary.c b/ai/default/daimilitary.c index 00f5797e44..3c4d4ea5b4 100644 --- a/ai/default/daimilitary.c +++ b/ai/default/daimilitary.c @@ -1562,6 +1562,7 @@ struct adv_choice *military_advisor_choose_build(struct ai_type *ait, int num_defenders = unit_list_size(ptile->units); int wall_id, danger; bool build_walls = TRUE; + bool def_unit_selected = FALSE; int qdanger = city_data->danger * city_data->danger; /* First determine the danger. It is measured in percents of our @@ -1593,6 +1594,7 @@ struct adv_choice *military_advisor_choose_build(struct ai_type *ait, choice->want = 100 + danger; adv_choice_set_use(choice, "first defender"); build_walls = FALSE; + def_unit_selected = TRUE; CITY_LOG(LOG_DEBUG, pcity, "m_a_c_d wants first defender with " ADV_WANT_PRINTF, choice->want); @@ -1638,6 +1640,10 @@ struct adv_choice *military_advisor_choose_build(struct ai_type *ait, } else { build_walls = FALSE; } + } + + /* If our choice isn't defender unit already, consider one */ + if (!def_unit_selected) { if ((danger > 0 && num_defenders <= urgency) || martial_value > 0) { struct adv_choice uchoice; -- 2.35.1