From 5ce9398f15bbf79efffe61149ab863bdcadcb90c Mon Sep 17 00:00:00 2001 From: Ihnatus Date: Tue, 8 Nov 2022 18:57:28 +0300 Subject: [PATCH] AI: consider logarithmic trade revenue bonus See OSDN#46049 Signed-off-by: Ihnatus --- ai/default/daidomestic.c | 12 ++++++++++-- common/traderoutes.c | 2 +- common/traderoutes.h | 1 + 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/ai/default/daidomestic.c b/ai/default/daidomestic.c index a272766dd5..fd875cdffb 100644 --- a/ai/default/daidomestic.c +++ b/ai/default/daidomestic.c @@ -351,8 +351,16 @@ static void dai_choose_trade_route(struct ai_type *ait, struct city *pcity, * duplicated here because the city traded with is imaginary. */ /* We assume that we are creating trade route to city with 75% of - * pcitys trade 10 squares away. */ - income = (10 + 10) * (1.75 * pcity->surplus[O_TRADE]) / 24; + * pcitys trade 10 squares away (FIXME: another estimation?). */ + if (CBS_LOGARITHMIC == game.info.caravan_bonus_style) { + int wd = ((100 - game.info.trade_world_rel_pct) * 10 + + game.info.trade_world_rel_pct + * (10 * 40 / MAX(wld.map.xsize, wld.map.ysize))) / 100; + + income = pow(log(wd + 20 + 1.75 * max_trade_prod(pcity)) * 2, 2); + } else /* assume CBS_CLASSIC */ { + income = (10 + 10) * (1.75 * pcity->surplus[O_TRADE]) / 24; + } /* A ruleset may use the Trade_Revenue_Bonus effect to reduce the one * time bonus if no trade route is established. Make sure it gets the diff --git a/common/traderoutes.c b/common/traderoutes.c index 7cbf914e24..fc2e8d6ee0 100644 --- a/common/traderoutes.c +++ b/common/traderoutes.c @@ -440,7 +440,7 @@ static int max_tile_trade(const struct city *pcity) /*********************************************************************//** Returns the maximum trade production of a city. *************************************************************************/ -static int max_trade_prod(const struct city *pcity) +int max_trade_prod(const struct city *pcity) { /* Trade tile base */ int trade_prod = max_tile_trade(pcity); diff --git a/common/traderoutes.h b/common/traderoutes.h index 23eb6e4505..0de9fdb7e2 100644 --- a/common/traderoutes.h +++ b/common/traderoutes.h @@ -118,6 +118,7 @@ int trade_base_between_cities(const struct city *pc1, const struct city *pc2); int trade_from_route(const struct city *pc1, const struct trade_route *route, int base); int city_num_trade_routes(const struct city *pcity); +int max_trade_prod(const struct city *pcity); int get_caravan_enter_city_trade_bonus(const struct city *pc1, const struct city *pc2, const struct unit_type *ut, -- 2.34.1