Skip to content

Commit

Permalink
Replace dai_choice_rule_name() with adv_choice_rule_name()
Browse files Browse the repository at this point in the history
- 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 <cazfi74@gmail.com>
  • Loading branch information
cazfi committed Jul 18, 2023
1 parent 9abcdc0 commit daa37ef
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 39 deletions.
31 changes: 5 additions & 26 deletions ai/default/aitools.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,41 +100,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)
Expand Down
1 change: 0 additions & 1 deletion ai/default/aitools.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions ai/default/daicity.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,14 +316,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) {
Expand Down Expand Up @@ -652,7 +652,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);
Expand All @@ -661,7 +661,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);
Expand Down
2 changes: 1 addition & 1 deletion ai/default/daimilitary.c
Original file line number Diff line number Diff line change
Expand Up @@ -2002,7 +2002,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);
}

Expand Down
30 changes: 23 additions & 7 deletions server/advisors/advchoice.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -166,13 +188,7 @@ void adv_choice_log_info(struct adv_choice *choice,
use = "<unknown>";
}

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, "
Expand Down
2 changes: 2 additions & 0 deletions server/advisors/advchoice.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit daa37ef

Please sign in to comment.