From 2e5985414fcb1f4be189617f914545619ebe032c Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 28 May 2023 11:46:41 +0300 Subject: [PATCH 38/38] AI: Make dai_unit_..._desirability() return adv_want See osdn #48097 Signed-off-by: Marko Lindqvist --- ai/default/daimilitary.c | 32 +++++++++++++++++++------------- ai/default/daimilitary.h | 4 ---- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/ai/default/daimilitary.c b/ai/default/daimilitary.c index db5ddd8ac6..c9af011198 100644 --- a/ai/default/daimilitary.c +++ b/ai/default/daimilitary.c @@ -78,6 +78,11 @@ static unsigned int assess_danger(struct ai_type *ait, struct city *pcity, const struct civ_map *dmap, player_unit_list_getter ul_cb); +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. **************************************************************************/ @@ -141,8 +146,8 @@ static struct unit_type *dai_choose_attacker(struct ai_type *ait, 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) { @@ -156,7 +161,7 @@ static struct unit_type *dai_choose_attacker(struct ai_type *ait, && 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(pcity, NULL, putype) <= utype_build_shield_cost(pcity, NULL, bestid)))) { best = cur; @@ -183,7 +188,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) { @@ -207,10 +212,10 @@ 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(pcity, NULL, putype) <= + || (ADV_WANTS_EQ(desire, best) && utype_build_shield_cost(pcity, NULL, putype) <= utype_build_shield_cost(pcity, NULL, bestid))) { best = desire; bestid = putype; @@ -965,10 +970,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_pct = 0; @@ -1002,10 +1007,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; @@ -1017,7 +1022,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; @@ -1028,6 +1033,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 6d17e9df14..433a058829 100644 --- a/ai/default/daimilitary.h +++ b/ai/default/daimilitary.h @@ -49,10 +49,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