From 32eb8ad1d1e49105b447f715901fccfc1d09c132 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Fri, 10 Mar 2023 05:13:43 +0200 Subject: [PATCH 31/31] AI: Create virtualunit in dai_unit_consider_bodyguard() only when needed See osdn #46436 Signed-off-by: Marko Lindqvist --- ai/default/daimilitary.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/ai/default/daimilitary.c b/ai/default/daimilitary.c index 0da56eb7e8..9e4bce8313 100644 --- a/ai/default/daimilitary.c +++ b/ai/default/daimilitary.c @@ -1678,16 +1678,16 @@ static void dai_unit_consider_bodyguard(struct ai_type *ait, struct unit_type *punittype, struct adv_choice *choice) { - struct unit *virtualunit; - struct player *pplayer = city_owner(pcity); - struct unit *aunit = NULL; - struct city *acity = NULL; - - virtualunit = unit_virtual_create(pplayer, pcity, punittype, - city_production_unit_veteran_level(pcity, punittype)); - if (choice->want < DAI_WANT_MILITARY_EMERGENCY) { - const adv_want want = look_for_charge(ait, pplayer, virtualunit, &aunit, &acity); + struct player *pplayer = city_owner(pcity); + struct unit *aunit = NULL; + struct city *acity = NULL; + struct unit *virtualunit + = unit_virtual_create(pplayer, pcity, punittype, + city_production_unit_veteran_level(pcity, + punittype)); + const adv_want want = look_for_charge(ait, pplayer, virtualunit, + &aunit, &acity); if (want > choice->want) { choice->want = want; @@ -1695,9 +1695,9 @@ static void dai_unit_consider_bodyguard(struct ai_type *ait, choice->type = CT_DEFENDER; adv_choice_set_use(choice, "bodyguard"); } - } - unit_virtual_destroy(virtualunit); + unit_virtual_destroy(virtualunit); + } } /**********************************************************************//** -- 2.39.2