From f5be5e23f805c51d25f544703cff3c995150b129 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Thu, 13 Jul 2023 03:18:25 +0300 Subject: [PATCH 35/35] Replace dai_choice_rule_name() with adv_choice_rule_name() - Introduce adv_choice_rule_name() - Make adv_choice_log_info() to use adv_choice_rule_name() - Change dai_choice_rule_name() users to use adv_choice_rule_name() - Drop dai_choice_rule_name() See osdn #47808 Signed-off-by: Marko Lindqvist --- ai/default/daicity.c | 8 ++++---- ai/default/daimilitary.c | 2 +- ai/default/daitools.c | 31 +++++-------------------------- ai/default/daitools.h | 1 - server/advisors/advchoice.c | 30 +++++++++++++++++++++++------- server/advisors/advchoice.h | 2 ++ 6 files changed, 35 insertions(+), 39 deletions(-) diff --git a/ai/default/daicity.c b/ai/default/daicity.c index a5df56bae1..31a0b78368 100644 --- a/ai/default/daicity.c +++ b/ai/default/daicity.c @@ -315,14 +315,14 @@ static void dai_city_choose_build(struct ai_type *ait, struct player *pplayer, if (city_data->choice.log_if_chosen) { log_normal("%s wants %s for %s with desire " ADV_WANT_PRINTF ".", city_name_get(pcity), - dai_choice_rule_name(&city_data->choice), + adv_choice_rule_name(&city_data->choice), city_data->choice.use, city_data->choice.want); } #endif /* ADV_CHOICE_TRACK */ CITY_LOG(LOG_DEBUG, pcity, "wants %s with desire " ADV_WANT_PRINTF ".", - dai_choice_rule_name(&city_data->choice), + adv_choice_rule_name(&city_data->choice), city_data->choice.want); switch (city_data->choice.type) { @@ -651,7 +651,7 @@ static void dai_spend_gold(struct ai_type *ait, struct player *pplayer) || (bestchoice.want > 200 && city_data->urgency > 1))) { /* Buy stuff */ CITY_LOG(LOG_BUY, pcity, "Crash buy of %s for %d (want " ADV_WANT_PRINTF ")", - dai_choice_rule_name(&bestchoice), + adv_choice_rule_name(&bestchoice), buycost, bestchoice.want); really_handle_city_buy(pplayer, pcity); @@ -660,7 +660,7 @@ static void dai_spend_gold(struct ai_type *ait, struct player *pplayer) && assess_defense(ait, pcity) == 0) { /* We have no gold but MUST have a defender */ CITY_LOG(LOG_BUY, pcity, "must have %s but can't afford it (%d < %d)!", - dai_choice_rule_name(&bestchoice), + adv_choice_rule_name(&bestchoice), pplayer->economic.gold, buycost); try_to_sell_stuff(pplayer, pcity); diff --git a/ai/default/daimilitary.c b/ai/default/daimilitary.c index 25e213e935..ce2cdb8ffc 100644 --- a/ai/default/daimilitary.c +++ b/ai/default/daimilitary.c @@ -2033,7 +2033,7 @@ struct adv_choice *military_advisor_choose_build(struct ai_type *ait, } else { CITY_LOG(LOGLEVEL_BUILD, pcity, "military advisor choice: %s (want " ADV_WANT_PRINTF ")", - dai_choice_rule_name(choice), + adv_choice_rule_name(choice), choice->want); } diff --git a/ai/default/daitools.c b/ai/default/daitools.c index c481facd54..9a4cd2070c 100644 --- a/ai/default/daitools.c +++ b/ai/default/daitools.c @@ -99,41 +99,20 @@ const char *dai_unit_task_rule_name(const enum ai_unit_task task) case AIUNIT_WONDER: return "Wonder"; } - /* no default, ensure all types handled somehow */ + + /* No default, ensure all types handled somehow */ log_error("Unsupported ai_unit_task %d.", task); - return NULL; -} -/**********************************************************************//** - Return the (untranslated) rule name of the adv_choice. - You don't have to free the return pointer. -**************************************************************************/ -const char *dai_choice_rule_name(const struct adv_choice *choice) -{ - switch (choice->type) { - case CT_NONE: - return "(nothing)"; - case CT_BUILDING: - return improvement_rule_name(choice->value.building); - case CT_CIVILIAN: - case CT_ATTACKER: - case CT_DEFENDER: - return utype_rule_name(choice->value.utype); - case CT_LAST: - return "(unknown)"; - }; - /* no default, ensure all types handled somehow */ - log_error("Unsupported ai_unit_task %d.", choice->type); return NULL; } /**********************************************************************//** Amortize a want modified by the shields (build_cost) we risk losing. - We add the build time of the unit(s) we risk to amortize delay. The - build time is calculated as the build cost divided by the production + We add the build time of the unit(s) we risk to amortize delay. + The build time is calculated as the build cost divided by the production output of the unit's homecity or the city where we want to produce the unit. If the city has less than average shield output, we - instead use the average, to encourage long-term thinking. + use the average instead, to encourage long-term thinking. **************************************************************************/ adv_want military_amortize(struct player *pplayer, struct city *pcity, adv_want value, int delay, int build_cost) diff --git a/ai/default/daitools.h b/ai/default/daitools.h index d62562f48a..38dd2e3cc5 100644 --- a/ai/default/daitools.h +++ b/ai/default/daitools.h @@ -33,7 +33,6 @@ struct adv_risk_cost; #define DAI_WANT_DOMESTIC_MAX (DAI_WANT_MILITARY_EMERGENCY / 4 * 3) const char *dai_unit_task_rule_name(const enum ai_unit_task task); -const char *dai_choice_rule_name(const struct adv_choice *choice); adv_want military_amortize(struct player *pplayer, struct city *pcity, adv_want value, int delay, int build_cost); diff --git a/server/advisors/advchoice.c b/server/advisors/advchoice.c index ed1edad379..6a6810575f 100644 --- a/server/advisors/advchoice.c +++ b/server/advisors/advchoice.c @@ -117,6 +117,28 @@ bool is_unit_choice_type(enum choice_type type) return type == CT_CIVILIAN || type == CT_ATTACKER || type == CT_DEFENDER; } +/**********************************************************************//** + Return the (untranslated) rule name of the adv_choice. + You don't have to free the return pointer. +**************************************************************************/ +const char *adv_choice_rule_name(const struct adv_choice *choice) +{ + switch (choice->type) { + case CT_BUILDING: + return improvement_rule_name(choice->value.building); + case CT_NONE: + return "None"; + case CT_CIVILIAN: + case CT_ATTACKER: + case CT_DEFENDER: + return utype_rule_name(choice->value.utype); + case CT_LAST: + break; + } + + return "(unknown)"; +} + #ifdef ADV_CHOICE_TRACK /**********************************************************************//** Copy contents of one choice structure to the other @@ -166,13 +188,7 @@ void adv_choice_log_info(struct adv_choice *choice, use = ""; } - if (choice->type == CT_BUILDING) { - name = improvement_rule_name(choice->value.building); - } else if (choice->type == CT_NONE) { - name = "None"; - } else { - name = utype_rule_name(choice->value.utype); - } + name = adv_choice_rule_name(choice); if (loc2 != NULL) { log_base(ADV_CHOICE_LOG_LEVEL, "Choice at \"%s:%s\": %s, " diff --git a/server/advisors/advchoice.h b/server/advisors/advchoice.h index c143adeff7..307abf3e5d 100644 --- a/server/advisors/advchoice.h +++ b/server/advisors/advchoice.h @@ -66,6 +66,8 @@ struct adv_choice *adv_better_choice_free(struct adv_choice *first, bool is_unit_choice_type(enum choice_type type); +const char *adv_choice_rule_name(const struct adv_choice *choice); + #ifdef ADV_CHOICE_TRACK void adv_choice_copy(struct adv_choice *dest, struct adv_choice *src); void adv_choice_set_use(struct adv_choice *choice, const char *use); -- 2.40.1