From 5d5d32ad0ee4626f55a08b592b6bbda7945ab9ff Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 28 May 2023 11:52:38 +0300 Subject: [PATCH 9/9] AI: Make dai_unit_..._desirability() return adv_want See osdn #48097 Signed-off-by: Marko Lindqvist --- ai/default/daimilitary.c | 36 +++++++++++++++++++++--------------- ai/default/daimilitary.h | 4 ---- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/ai/default/daimilitary.c b/ai/default/daimilitary.c index accb0c9c0f..943be01a5e 100644 --- a/ai/default/daimilitary.c +++ b/ai/default/daimilitary.c @@ -76,6 +76,11 @@ static unsigned int assess_danger(struct ai_type *ait, struct city *pcity); +static adv_want dai_unit_attack_desirability(struct ai_type *ait, + const struct unit_type *punittype); +static adv_want dai_unit_defense_desirability(struct ai_type *ait, + const struct unit_type *punittype); + /************************************************************************** Choose the best unit the city can build to defend against attacker v. **************************************************************************/ @@ -135,8 +140,8 @@ static struct unit_type *dai_choose_attacker(struct ai_type *ait, struct city *p enum terrain_class tc, bool allow_gold_upkeep) { struct unit_type *bestid = NULL; - int best = -1; - int cur; + adv_want best = -1; + adv_want cur; struct player *pplayer = city_owner(pcity); simple_ai_unit_type_iterate(putype) { @@ -150,7 +155,7 @@ static struct unit_type *dai_choose_attacker(struct ai_type *ait, struct city *p && utype_class(putype)->adv.sea_move != MOVE_NONE)) { if (can_city_build_unit_now(pcity, putype) && (cur > best - || (cur == best + || (ADV_WANTS_EQ(cur, best) && utype_build_shield_cost(putype) <= utype_build_shield_cost(bestid)))) { best = cur; @@ -177,7 +182,7 @@ static struct unit_type *dai_choose_bodyguard(struct ai_type *ait, bool allow_gold_upkeep) { struct unit_type *bestid = NULL; - int best = 0; + adv_want best = 0; struct player *pplayer = city_owner(pcity); simple_ai_unit_type_iterate(putype) { @@ -201,11 +206,11 @@ static struct unit_type *dai_choose_bodyguard(struct ai_type *ait, /* Now find best */ if (can_city_build_unit_now(pcity, putype)) { - const int desire = dai_unit_defense_desirability(ait, putype); + const adv_want desire = dai_unit_defense_desirability(ait, putype); if (desire > best - || (desire == best && utype_build_shield_cost(putype) <= - utype_build_shield_cost(bestid))) { + || (ADV_WANTS_EQ(desire, best) && utype_build_shield_cost(putype) <= + utype_build_shield_cost(bestid))) { best = desire; bestid = putype; } @@ -216,7 +221,7 @@ static struct unit_type *dai_choose_bodyguard(struct ai_type *ait, } /********************************************************************** -Helper for assess_defense_quadratic and assess_defense_unit. + Helper for assess_defense_quadratic() and assess_defense_unit(). ***********************************************************************/ static int base_assess_defense_unit(struct city *pcity, struct unit *punit, bool igwall, bool quadratic, @@ -663,10 +668,10 @@ static unsigned int assess_danger(struct ai_type *ait, struct city *pcity) How much we would want that unit to defend a city? (Do not use this function to find bodyguards for ships or air units.) **************************************************************************/ -int dai_unit_defense_desirability(struct ai_type *ait, - const struct unit_type *punittype) +static adv_want dai_unit_defense_desirability(struct ai_type *ait, + const struct unit_type *punittype) { - int desire = punittype->hp; + adv_want desire = punittype->hp; int attack = punittype->attack_strength; int defense = punittype->defense_strength; int maxbonus = 0; @@ -698,10 +703,10 @@ int dai_unit_defense_desirability(struct ai_type *ait, /************************************************************************** How much we would want that unit to attack with? **************************************************************************/ -int dai_unit_attack_desirability(struct ai_type *ait, - const struct unit_type *punittype) +static adv_want dai_unit_attack_desirability(struct ai_type *ait, + const struct unit_type *punittype) { - int desire = punittype->hp; + adv_want desire = punittype->hp; int attack = punittype->attack_strength; int defense = punittype->defense_strength; @@ -713,7 +718,7 @@ int dai_unit_attack_desirability(struct ai_type *ait, desire += desire / 2; } if (utype_has_flag(punittype, UTYF_GAMELOSS)) { - desire /= 10; /* but might actually be worth it */ + desire /= 10; /* But might actually be worth it */ } if (utype_has_flag(punittype, UTYF_CITYBUSTER)) { desire += desire / 2; @@ -724,6 +729,7 @@ int dai_unit_attack_desirability(struct ai_type *ait, if (punittype->adv.igwall) { desire += desire / 4; } + return desire; } diff --git a/ai/default/daimilitary.h b/ai/default/daimilitary.h index 49e9d0dd64..bf7c827a1a 100644 --- a/ai/default/daimilitary.h +++ b/ai/default/daimilitary.h @@ -37,10 +37,6 @@ int assess_defense_quadratic(struct ai_type *ait, struct city *pcity); int assess_defense_unit(struct ai_type *ait, struct city *pcity, struct unit *punit, bool igwall); int assess_defense(struct ai_type *ait, struct city *pcity); -int dai_unit_defense_desirability(struct ai_type *ait, - const struct unit_type *punittype); -int dai_unit_attack_desirability(struct ai_type *ait, - const struct unit_type *punittype); bool dai_process_defender_want(struct ai_type *ait, struct player *pplayer, struct city *pcity, unsigned int danger, struct adv_choice *choice, adv_want extra_want); -- 2.39.2