From 79ead157610325ecf7f61ce214c08d680f1065b6 Mon Sep 17 00:00:00 2001 From: Ihnatus Date: Tue, 8 Nov 2022 20:40:04 +0300 Subject: [PATCH] AI: consider logarithmic trade revenue bonus See OSDN#46049 Signed-off-by: Ihnatus --- ai/default/daidomestic.c | 11 ++++++++++- common/traderoutes.c | 2 +- common/traderoutes.h | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ai/default/daidomestic.c b/ai/default/daidomestic.c index f682d366e9..e487b80028 100644 --- a/ai/default/daidomestic.c +++ b/ai/default/daidomestic.c @@ -353,7 +353,16 @@ static void dai_choose_trade_route(struct ai_type *ait, struct city *pcity, /* 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; + 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; + + /* not bothering calculating maximal trade output, just 1.75 -> 2 */ + income = pow(log(wd + 20 + 2 * pcity->surplus[O_TRADE]) * 2, 2); + } else { + 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 e83ee937db..78156bb6d1 100644 --- a/common/traderoutes.c +++ b/common/traderoutes.c @@ -428,7 +428,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 085170d78b..e12c295a2f 100644 --- a/common/traderoutes.h +++ b/common/traderoutes.h @@ -116,6 +116,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, struct goods_type *pgood, -- 2.34.1