From 37c6e65ac6513ec1352a04eb190e34c39ec12668 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Mon, 7 Feb 2022 20:25:21 +0200 Subject: [PATCH 22/22] Add minimum trade route output ruleset setting Requested by ddeanbrown See osdn #43011 Signed-off-by: Marko Lindqvist --- common/networking/packets.def | 1 + common/traderoutes.c | 16 ++++++++++++++-- data/alien/game.ruleset | 4 ++++ data/civ1/game.ruleset | 4 ++++ data/civ2/game.ruleset | 4 ++++ data/civ2civ3/game.ruleset | 4 ++++ data/classic/game.ruleset | 4 ++++ data/experimental/game.ruleset | 4 ++++ data/granularity/game.ruleset | 4 ++++ data/multiplayer/game.ruleset | 4 ++++ data/sandbox/game.ruleset | 4 ++++ data/stub/game.ruleset | 4 ++++ data/webperimental/game.ruleset | 4 ++++ fc_version | 2 +- server/ruleset.c | 11 ++++++++--- tools/ruleutil/rulesave.c | 3 +++ 16 files changed, 71 insertions(+), 6 deletions(-) diff --git a/common/networking/packets.def b/common/networking/packets.def index 782c8171b2..749383a50f 100644 --- a/common/networking/packets.def +++ b/common/networking/packets.def @@ -511,6 +511,7 @@ PACKET_GAME_INFO = 16; sc, is-info UINT8 forced_science; UINT8 fulltradesize; UINT8 trade_world_rel_pct; + UINT8 min_trade_route_val; GOODS_SELECTION goods_selection; /* True if at least one civilization has researched a tech */ UINT16 global_advance_count; diff --git a/common/traderoutes.c b/common/traderoutes.c index bc6112b8fb..39e581a740 100644 --- a/common/traderoutes.c +++ b/common/traderoutes.c @@ -358,11 +358,23 @@ 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 val; + if (route->dir == RDIR_TO) { - return base * route->goods->to_pct / 100; + val = base * route->goods->to_pct / 100; + + if (route->goods->to_pct > 0) { + val = MAX(val, game.info.min_trade_route_val); + } + } else { + val = base * route->goods->from_pct / 100; + + if (route->goods->from_pct > 0) { + val = MAX(val, game.info.min_trade_route_val); + } } - return base * route->goods->from_pct / 100; + return val; } /*********************************************************************//** diff --git a/data/alien/game.ruleset b/data/alien/game.ruleset index bded1f0d14..68513dc797 100644 --- a/data/alien/game.ruleset +++ b/data/alien/game.ruleset @@ -1498,6 +1498,10 @@ settings = "TeamIC", 300, "Cancel", "Both" } +; Minimum trade a trade route produces, as long as the good has nonzero income +; for the relevant direction (from_pct / to_pct) +min_trade_route_val = 0 + ; When are goods for the trade route chosen. ; "Leaving" - Goods to carry are assigned to unit when it`s built, or it changes homecity ; "Arrival" - Goods are chosen when trade route is established, when unit arrives to destination diff --git a/data/civ1/game.ruleset b/data/civ1/game.ruleset index eb7a11419c..51ffa784ed 100644 --- a/data/civ1/game.ruleset +++ b/data/civ1/game.ruleset @@ -1315,6 +1315,10 @@ settings = "TeamIC", 400, "Cancel", "Gold" } +; Minimum trade a trade route produces, as long as the good has nonzero income +; for the relevant direction (from_pct / to_pct) +min_trade_route_val = 0 + ; When are goods for the trade route chosen. ; "Leaving" - Goods to carry are assigned to unit when it`s built, or it changes homecity ; "Arrival" - Goods are chosen when trade route is established, when unit arrives to destination diff --git a/data/civ2/game.ruleset b/data/civ2/game.ruleset index 8d59bbbf3f..af9f8dcf0f 100644 --- a/data/civ2/game.ruleset +++ b/data/civ2/game.ruleset @@ -1560,6 +1560,10 @@ settings = "TeamIC", 400, "Cancel", "Both" } +; Minimum trade a trade route produces, as long as the good has nonzero income +; for the relevant direction (from_pct / to_pct) +min_trade_route_val = 0 + ; When are goods for the trade route chosen. ; "Leaving" - Goods to carry are assigned to unit when it`s built, or it changes homecity ; "Arrival" - Goods are chosen when trade route is established, when unit arrives to destination diff --git a/data/civ2civ3/game.ruleset b/data/civ2civ3/game.ruleset index 63baad1e9d..8b9a2aaf0d 100644 --- a/data/civ2civ3/game.ruleset +++ b/data/civ2civ3/game.ruleset @@ -2010,6 +2010,10 @@ settings = "TeamIC", 200, "Cancel", "Gold" } +; Minimum trade a trade route produces, as long as the good has nonzero income +; for the relevant direction (from_pct / to_pct) +min_trade_route_val = 0 + ; When are goods for the trade route chosen. ; "Leaving" - Goods to carry are assigned to unit when it`s built, or it changes homecity ; "Arrival" - Goods are chosen when trade route is established, when unit arrives to destination diff --git a/data/classic/game.ruleset b/data/classic/game.ruleset index 04ec9d29cd..c2c22ee2f7 100644 --- a/data/classic/game.ruleset +++ b/data/classic/game.ruleset @@ -1805,6 +1805,10 @@ settings = "TeamIC", 400, "Cancel", "Both" } +; Minimum trade a trade route produces, as long as the good has nonzero income +; for the relevant direction (from_pct / to_pct) +min_trade_route_val = 0 + ; When are goods for the trade route chosen. ; "Leaving" - Goods to carry are assigned to unit when it`s built, or it changes homecity ; "Arrival" - Goods are chosen when trade route is established, when unit arrives to destination diff --git a/data/experimental/game.ruleset b/data/experimental/game.ruleset index 95d4ababd2..bb0c386358 100644 --- a/data/experimental/game.ruleset +++ b/data/experimental/game.ruleset @@ -1892,6 +1892,10 @@ settings = "TeamIC", 400, "Cancel", "Both" } +; Minimum trade a trade route produces, as long as the good has nonzero income +; for the relevant direction (from_pct / to_pct) +min_trade_route_val = 0 + ; When are goods for the trade route chosen. ; "Leaving" - Goods to carry are assigned to unit when it`s built, or it changes homecity ; "Arrival" - Goods are chosen when trade route is established, when unit arrives to destination diff --git a/data/granularity/game.ruleset b/data/granularity/game.ruleset index 097285c6f9..e9f8a0773e 100644 --- a/data/granularity/game.ruleset +++ b/data/granularity/game.ruleset @@ -800,6 +800,10 @@ settings = "TeamIC", 0, "Cancel", "None" } +; Minimum trade a trade route produces, as long as the good has nonzero income +; for the relevant direction (from_pct / to_pct) +min_trade_route_val = 0 + ; When are goods for the trade route chosen. ; "Leaving" - Goods to carry are assigned to unit when it`s built, or it changes homecity ; "Arrival" - Goods are chosen when trade route is established, when unit arrives to destination diff --git a/data/multiplayer/game.ruleset b/data/multiplayer/game.ruleset index 978b64a61c..1ec6a7ed21 100644 --- a/data/multiplayer/game.ruleset +++ b/data/multiplayer/game.ruleset @@ -1765,6 +1765,10 @@ settings = "TeamIC", 0, "Cancel", "Both" } +; Minimum trade a trade route produces, as long as the good has nonzero income +; for the relevant direction (from_pct / to_pct) +min_trade_route_val = 0 + ; When are goods for the trade route chosen. ; "Leaving" - Goods to carry are assigned to unit when it`s built, or it changes homecity ; "Arrival" - Goods are chosen when trade route is established, when unit arrives to destination diff --git a/data/sandbox/game.ruleset b/data/sandbox/game.ruleset index eb474f6501..53c2cfb64d 100644 --- a/data/sandbox/game.ruleset +++ b/data/sandbox/game.ruleset @@ -3243,6 +3243,10 @@ settings = "TeamIC", 200, "Cancel", "Gold" } +; Minimum trade a trade route produces, as long as the good has nonzero income +; for the relevant direction (from_pct / to_pct) +min_trade_route_val = 0 + ; When are goods for the trade route chosen. ; "Leaving" - Goods to carry are assigned to unit when it`s built, or it changes homecity ; "Arrival" - Goods are chosen when trade route is established, when unit arrives to destination diff --git a/data/stub/game.ruleset b/data/stub/game.ruleset index 765a0fe064..ca177e6800 100644 --- a/data/stub/game.ruleset +++ b/data/stub/game.ruleset @@ -661,6 +661,10 @@ settings = "TeamIC", 0, "Cancel", "None" } +; Minimum trade a trade route produces, as long as the good has nonzero income +; for the relevant direction (from_pct / to_pct) +min_trade_route_val = 0 + ; When are goods for the trade route chosen. ; "Leaving" - Goods to carry are assigned to unit when it`s built, or it changes homecity ; "Arrival" - Goods are chosen when trade route is established, when unit arrives to destination diff --git a/data/webperimental/game.ruleset b/data/webperimental/game.ruleset index 954ab29265..79915eedf3 100644 --- a/data/webperimental/game.ruleset +++ b/data/webperimental/game.ruleset @@ -2057,6 +2057,10 @@ settings = "TeamIC", 400, "Cancel", "Both" } +; Minimum trade a trade route produces, as long as the good has nonzero income +; for the relevant direction (from_pct / to_pct) +min_trade_route_val = 0 + ; When are goods for the trade route chosen. ; "Leaving" - Goods to carry are assigned to unit when it`s built, or it changes homecity ; "Arrival" - Goods are chosen when trade route is established, when unit arrives to destination diff --git a/fc_version b/fc_version index bb0928207e..b3bdc88934 100755 --- a/fc_version +++ b/fc_version @@ -56,7 +56,7 @@ DEFAULT_FOLLOW_TAG=S3_1 # - No new mandatory capabilities can be added to the release branch; doing # so would break network capability of supposedly "compatible" releases. # -NETWORK_CAPSTRING="+Freeciv.Devel-3.1-2022.Feb.01" +NETWORK_CAPSTRING="+Freeciv.Devel-3.1-2022.Feb.07" FREECIV_DISTRIBUTOR="" diff --git a/server/ruleset.c b/server/ruleset.c index a15ace6b5b..4dbdec8314 100644 --- a/server/ruleset.c +++ b/server/ruleset.c @@ -7749,9 +7749,14 @@ static bool load_ruleset_game(struct section_file *file, bool act, } if (ok) { - const char *str = secfile_lookup_str_default(file, - goods_selection_method_name(RS_DEFAULT_GOODS_SELECTION), - "trade.goods_selection"); + const char *str; + + game.info.min_trade_route_val + = secfile_lookup_int_default(file, 0, "trade.min_trade_route_val"); + + str = secfile_lookup_str_default(file, + goods_selection_method_name(RS_DEFAULT_GOODS_SELECTION), + "trade.goods_selection"); game.info.goods_selection = goods_selection_method_by_name(str, fc_strcasecmp); diff --git a/tools/ruleutil/rulesave.c b/tools/ruleutil/rulesave.c index 0c0c347ddb..00b0ec8c91 100644 --- a/tools/ruleutil/rulesave.c +++ b/tools/ruleutil/rulesave.c @@ -1547,6 +1547,9 @@ static bool save_game_ruleset(const char *filename, const char *name) } } + save_default_int(sfile, game.info.min_trade_route_val, + 0, "trade.min_trade_route_val", NULL); + if (game.info.goods_selection != RS_DEFAULT_GOODS_SELECTION) { secfile_insert_str(sfile, goods_selection_method_name(game.info.goods_selection), "trade.goods_selection"); -- 2.34.1