From 1edafc7e9fe5760ab2048b0cee8037b99e38c23c Mon Sep 17 00:00:00 2001 From: Ihnatus Date: Sat, 26 Jun 2021 02:32:38 +0300 Subject: [PATCH] AI: Manage caravans that only can enter marketplaces See OSDN#42518 Signed-off-by: Ihnatus --- common/actions.c | 2 ++ common/aicore/caravan.c | 19 +++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/common/actions.c b/common/actions.c index 7efd31355a..a2847cd876 100644 --- a/common/actions.c +++ b/common/actions.c @@ -4338,6 +4338,8 @@ struct act_prob action_speculate_unit_on_city(const action_id act_id, return ACTPROB_IMPOSSIBLE; } } else { + /* FIXME: this branch result depends _directly_ on actor's position. + * I.e., like, not adjacent, no action. Other branch ignores radius. */ return action_prob_vs_city_full(actor, actor_home, actor_tile, act_id, target); } diff --git a/common/aicore/caravan.c b/common/aicore/caravan.c index d8ff7ed315..bc2890795e 100644 --- a/common/aicore/caravan.c +++ b/common/aicore/caravan.c @@ -163,6 +163,7 @@ static void caravan_result_init(struct caravan_result *result, result->value = 0; result->help_wonder = FALSE; + /* FIXME: required_boat field is never used. */ if ((src != NULL) && (dest != NULL)) { if (tile_continent(src->tile) != tile_continent(dest->tile)) { result->required_boat = TRUE; @@ -262,7 +263,7 @@ static double windfall_benefit(const struct unit *caravan, int bonus = get_caravan_enter_city_trade_bonus(src, dest, NULL, can_establish); - /* bonus goes to both sci and gold. */ + /* bonus goes to both sci and gold FIXME: not always */ bonus *= 2; return bonus; @@ -472,6 +473,7 @@ static bool get_discounted_reward(const struct unit *caravan, double discount = parameter->discount; struct player *pplayer_src = city_owner(src); struct player *pplayer_dest = city_owner(dest); + int cost = unit_build_shield_cost(caravan); bool consider_wonder; bool consider_trade; bool consider_windfall; @@ -505,8 +507,6 @@ static bool get_discounted_reward(const struct unit *caravan, return FALSE; } - trade = trade_benefit(pplayer_src, src, dest, parameter); - windfall = windfall_benefit(caravan, src, dest, parameter); if (consider_wonder) { wonder = wonder_benefit(caravan, arrival_time, dest, parameter); /* we want to aid for wonder building */ @@ -518,6 +518,7 @@ static bool get_discounted_reward(const struct unit *caravan, } if (consider_trade) { + trade = trade_benefit(pplayer_src, src, dest, parameter); if (parameter->horizon == FC_INFINITY) { trade = perpetuity(trade, discount); } else { @@ -529,12 +530,22 @@ static bool get_discounted_reward(const struct unit *caravan, } if (consider_windfall) { + windfall = windfall_benefit(caravan, src, dest, parameter); windfall = presentvalue(windfall, arrival_time, discount); } else { windfall = 0.0; } - if (consider_trade && trade + windfall >= wonder) { + if ((consider_trade + || (consider_windfall + && (!parameter->consider_trade /* can only enter marketplaces */ + /* (FIXME: test any extra restrictions for trade routes) */ + /* or the result is so big that we are still in plus */ + /* (consider having produced IF_GOLD instead) */ + || windfall + >= presentvalue(cost, -cost + / MAX(src->surplus[O_SHIELD], 2), discount))) + ) && trade + windfall >= wonder) { result->value = trade + windfall; result->help_wonder = FALSE; } else if (consider_wonder) { -- 2.27.0