From 51ca924a3a11a5609736fc596f65401dfb22efd5 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Wed, 1 May 2024 10:24:03 +0300 Subject: [PATCH 46/46] Add goods select_priority Requested by bard See osdn #48250 Signed-off-by: Marko Lindqvist --- client/packhand.c | 1 + common/networking/packets.def | 1 + common/traderoutes.c | 17 +++++++++++++++-- common/traderoutes.h | 1 + data/alien/game.ruleset | 2 ++ data/civ1/game.ruleset | 2 ++ data/civ2/game.ruleset | 2 ++ data/civ2civ3/game.ruleset | 2 ++ data/classic/game.ruleset | 2 ++ data/goldkeep/game.ruleset | 2 ++ data/granularity/game.ruleset | 2 ++ data/multiplayer/game.ruleset | 2 ++ data/ruledit/comments-3.3.txt | 2 ++ data/sandbox/game.ruleset | 2 ++ data/stub/game.ruleset | 2 ++ data/webperimental/game.ruleset | 2 ++ server/ruleset/ruleload.c | 7 +++++-- tools/ruleutil/rulesave.c | 1 + 18 files changed, 48 insertions(+), 4 deletions(-) diff --git a/client/packhand.c b/client/packhand.c index e877ac059b..b84ae9715e 100644 --- a/client/packhand.c +++ b/client/packhand.c @@ -4391,6 +4391,7 @@ void handle_ruleset_goods(const struct packet_ruleset_goods *p) pgood->from_pct = p->from_pct; pgood->to_pct = p->to_pct; pgood->onetime_pct = p->onetime_pct; + pgood->select_priority = p->select_priority; pgood->flags = p->flags; PACKET_STRVEC_EXTRACT(pgood->helptext, p->helptext); diff --git a/common/networking/packets.def b/common/networking/packets.def index 1bcced9b0f..3d139b3d89 100644 --- a/common/networking/packets.def +++ b/common/networking/packets.def @@ -1844,6 +1844,7 @@ PACKET_RULESET_GOODS = 248; sc, lsend UINT16 from_pct; UINT16 to_pct; UINT16 onetime_pct; + UINT16 select_priority; BV_GOODS_FLAGS flags; STRVEC helptext; end diff --git a/common/traderoutes.c b/common/traderoutes.c index c9e996162c..883aa1dc8f 100644 --- a/common/traderoutes.c +++ b/common/traderoutes.c @@ -729,17 +729,30 @@ bool city_receives_goods(const struct city *pcity, } /*********************************************************************//** - Return goods type for the new trade route between given cities. + Fond out goods type for the new trade route + + @param src City to start traderoute from + @param punit Unit to carry the goods + @return Goods to carry *************************************************************************/ struct goods_type *goods_from_city_to_unit(const struct city *src, const struct unit *punit) { int i = 0; + int prio = -1; struct goods_type *potential[MAX_GOODS_TYPES]; goods_type_iterate(pgood) { if (goods_can_be_provided(src, pgood, punit)) { - potential[i++] = pgood; + if (pgood->select_priority >= prio) { + if (pgood->select_priority > prio) { + /* New highest priority */ + i = 0; + prio = pgood->select_priority; + } + + potential[i++] = pgood; + } } } goods_type_iterate_end; diff --git a/common/traderoutes.h b/common/traderoutes.h index d826b1fc9c..a9631e56bb 100644 --- a/common/traderoutes.h +++ b/common/traderoutes.h @@ -195,6 +195,7 @@ struct goods_type int to_pct; int onetime_pct; + int select_priority; int priority; bv_goods_flags flags; diff --git a/data/alien/game.ruleset b/data/alien/game.ruleset index 791cbb3328..1df6f623c0 100644 --- a/data/alien/game.ruleset +++ b/data/alien/game.ruleset @@ -549,6 +549,8 @@ goods_selection = "Arrival" ; to_pct = Income for the receiving end of the trade route. Default is 100% ; This value is not used at all in case of bidirectional routes. ; onetime_pct = Onetime bonuses when trade route gets established. Default is 100% +; select_priority = Available good with highest select_priority get selected for +; the traderoute, random among the same select_pririty. ; priority = Trade routes get replaced by higher priority goods, or higher ; trade value when priority is the same. ; flags diff --git a/data/civ1/game.ruleset b/data/civ1/game.ruleset index 5469b5b621..77840c7937 100644 --- a/data/civ1/game.ruleset +++ b/data/civ1/game.ruleset @@ -581,6 +581,8 @@ goods_selection = "Arrival" ; to_pct = Income for the receiving end of the trade route. Default is 100% ; This value is not used at all in case of bidirectional routes. ; onetime_pct = Onetime bonuses when trade route gets established. Default is 100% +; select_priority = Available good with highest select_priority get selected for +; the traderoute, random among the same select_pririty. ; priority = Trade routes get replaced by higher priority goods, or higher ; trade value when priority is the same. ; flags diff --git a/data/civ2/game.ruleset b/data/civ2/game.ruleset index b83db3a5bd..f2902abfd6 100644 --- a/data/civ2/game.ruleset +++ b/data/civ2/game.ruleset @@ -512,6 +512,8 @@ goods_selection = "Arrival" ; to_pct = Income for the receiving end of the trade route. Default is 100% ; This value is not used at all in case of bidirectional routes. ; onetime_pct = Onetime bonuses when trade route gets established. Default is 100% +; select_priority = Available good with highest select_priority get selected for +; the traderoute, random among the same select_pririty. ; priority = Trade routes get replaced by higher priority goods, or higher ; trade value when priority is the same. ; flags diff --git a/data/civ2civ3/game.ruleset b/data/civ2civ3/game.ruleset index 456c9d995f..72497079e9 100644 --- a/data/civ2civ3/game.ruleset +++ b/data/civ2civ3/game.ruleset @@ -651,6 +651,8 @@ goods_selection = "Leaving" ; to_pct = Income for the receiving end of the trade route. Default is 100% ; This value is not used at all in case of bidirectional routes. ; onetime_pct = Onetime bonuses when trade route gets established. Default is 100% +; select_priority = Available good with highest select_priority get selected for +; the traderoute, random among the same select_pririty. ; priority = Trade routes get replaced by higher priority goods, or higher ; trade value when priority is the same. ; flags diff --git a/data/classic/game.ruleset b/data/classic/game.ruleset index d6d60d5cc5..169ccae33a 100644 --- a/data/classic/game.ruleset +++ b/data/classic/game.ruleset @@ -564,6 +564,8 @@ goods_selection = "Arrival" ; to_pct = Income for the receiving end of the trade route. Default is 100% ; This value is not used at all in case of bidirectional routes. ; onetime_pct = Onetime bonuses when trade route gets established. Default is 100% +; select_priority = Available good with highest select_priority get selected for +; the traderoute, random among the same select_pririty. ; priority = Trade routes get replaced by higher priority goods, or higher ; trade value when priority is the same. ; flags diff --git a/data/goldkeep/game.ruleset b/data/goldkeep/game.ruleset index 3e1a9a3d9d..64c7183d95 100644 --- a/data/goldkeep/game.ruleset +++ b/data/goldkeep/game.ruleset @@ -582,6 +582,8 @@ goods_selection = "Leaving" ; to_pct = Income for the receiving end of the trade route. Default is 100% ; This value is not used at all in case of bidirectional routes. ; onetime_pct = Onetime bonuses when trade route gets established. Default is 100% +; select_priority = Available good with highest select_priority get selected for +; the traderoute, random among the same select_pririty. ; priority = Trade routes get replaced by higher priority goods, or higher ; trade value when priority is the same. ; flags diff --git a/data/granularity/game.ruleset b/data/granularity/game.ruleset index 0b6fac5470..99f6aa9924 100644 --- a/data/granularity/game.ruleset +++ b/data/granularity/game.ruleset @@ -536,6 +536,8 @@ goods_selection = "Leaving" ; to_pct = Income for the receiving end of the trade route. Default is 100% ; This value is not used at all in case of bidirectional routes. ; onetime_pct = Onetime bonuses when trade route gets established. Default is 100% +; select_priority = Available good with highest select_priority get selected for +; the traderoute, random among the same select_pririty. ; priority = Trade routes get replaced by higher priority goods, or higher ; trade value when priority is the same. ; flags diff --git a/data/multiplayer/game.ruleset b/data/multiplayer/game.ruleset index e003ee57e0..4a5852d69f 100644 --- a/data/multiplayer/game.ruleset +++ b/data/multiplayer/game.ruleset @@ -531,6 +531,8 @@ goods_selection = "Arrival" ; to_pct = Income for the receiving end of the trade route. Default is 100% ; This value is not used at all in case of bidirectional routes. ; onetime_pct = Onetime bonuses when trade route gets established. Default is 100% +; select_priority = Available good with highest select_priority get selected for +; the traderoute, random among the same select_pririty. ; priority = Trade routes get replaced by higher priority goods, or higher ; trade value when priority is the same. ; flags diff --git a/data/ruledit/comments-3.3.txt b/data/ruledit/comments-3.3.txt index 5403ea9069..69f8217661 100644 --- a/data/ruledit/comments-3.3.txt +++ b/data/ruledit/comments-3.3.txt @@ -1121,6 +1121,8 @@ goods = "\ ; to_pct = Income for the receiving end of the trade route. Default is 100\%\n\ ; This value is not used at all in case of bidirectional routes.\n\ ; onetime_pct = Onetime bonuses when trade route gets established. Default is 100\%\n\ +; select_priority = Available good with highest select_priority get selected for\n\ +; the traderoute, random among the same select_pririty.\n\ ; priority = Trade routes get replaced by higher priority goods, or higher\n\ ; trade value when priority is the same.\n\ ; flags\n\ diff --git a/data/sandbox/game.ruleset b/data/sandbox/game.ruleset index 8c4c12edf3..857e1e74be 100644 --- a/data/sandbox/game.ruleset +++ b/data/sandbox/game.ruleset @@ -649,6 +649,8 @@ goods_selection = "Leaving" ; to_pct = Income for the receiving end of the trade route. Default is 100% ; This value is not used at all in case of bidirectional routes. ; onetime_pct = Onetime bonuses when trade route gets established. Default is 100% +; select_priority = Available good with highest select_priority get selected for +; the traderoute, random among the same select_pririty. ; priority = Trade routes get replaced by higher priority goods, or higher ; trade value when priority is the same. ; flags diff --git a/data/stub/game.ruleset b/data/stub/game.ruleset index c9b644d7ca..dfb99f7d78 100644 --- a/data/stub/game.ruleset +++ b/data/stub/game.ruleset @@ -524,6 +524,8 @@ goods_selection = "Leaving" ; to_pct = Income for the receiving end of the trade route. Default is 100% ; This value is not used at all in case of bidirectional routes. ; onetime_pct = Onetime bonuses when trade route gets established. Default is 100% +; select_priority = Available good with highest select_priority get selected for +; the traderoute, random among the same select_pririty. ; priority = Trade routes get replaced by higher priority goods, or higher ; trade value when priority is the same. ; flags diff --git a/data/webperimental/game.ruleset b/data/webperimental/game.ruleset index 6178afe3ee..52acb06d6c 100644 --- a/data/webperimental/game.ruleset +++ b/data/webperimental/game.ruleset @@ -568,6 +568,8 @@ goods_selection = "Leaving" ; to_pct = Income for the receiving end of the trade route. Default is 100% ; This value is not used at all in case of bidirectional routes. ; onetime_pct = Onetime bonuses when trade route gets established. Default is 100% +; select_priority = Available good with highest select_priority get selected for +; the traderoute, random among the same select_pririty. ; priority = Trade routes get replaced by higher priority goods, or higher ; trade value when priority is the same. ; flags diff --git a/server/ruleset/ruleload.c b/server/ruleset/ruleload.c index dbd52e1983..84242f9467 100644 --- a/server/ruleset/ruleload.c +++ b/server/ruleset/ruleload.c @@ -7411,6 +7411,8 @@ static bool load_ruleset_game(struct section_file *file, bool act, "%s.to_pct", sec_name); pgood->onetime_pct = secfile_lookup_int_default(file, 100, "%s.onetime_pct", sec_name); + pgood->select_priority = secfile_lookup_int_default(file, 1, + "%s.select_priority", sec_name); pgood->priority = secfile_lookup_int_default(file, 1, "%s.priority", sec_name); @@ -8624,6 +8626,7 @@ static void send_ruleset_goods(struct conn_list *dest) packet.from_pct = g->from_pct; packet.to_pct = g->to_pct; packet.onetime_pct = g->onetime_pct; + packet.select_priority = g->select_priority; packet.flags = g->flags; PACKET_STRVEC_INSERT(packet.helptext, g->helptext); @@ -8633,8 +8636,8 @@ static void send_ruleset_goods(struct conn_list *dest) } /**********************************************************************//** - Send the disaster ruleset information (all individual disaster types) to the - specified connections. + Send the disaster ruleset information (all individual disaster types) + to the specified connections. **************************************************************************/ static void send_ruleset_disasters(struct conn_list *dest) { diff --git a/tools/ruleutil/rulesave.c b/tools/ruleutil/rulesave.c index 837e57bdfa..240359c400 100644 --- a/tools/ruleutil/rulesave.c +++ b/tools/ruleutil/rulesave.c @@ -1776,6 +1776,7 @@ static bool save_game_ruleset(const char *filename, const char *name) save_default_int(sfile, pgood->from_pct, 100, path, "from_pct"); save_default_int(sfile, pgood->to_pct, 100, path, "to_pct"); save_default_int(sfile, pgood->onetime_pct, 100, path, "onetime_pct"); + save_default_int(sfile, pgood->select_priority, 1, path, "select_priority"); save_default_int(sfile, pgood->priority, 1, path, "priority"); set_count = 0; -- 2.43.0