From c24e7f4ad7901d2592b862f181cfed56494b5b2e Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Thu, 29 Dec 2022 21:24:54 +0200 Subject: [PATCH 33/33] Add ruleset setting how pop_cost unit nationality gets chosen Requested anonymously See osdn #45932 Signed-off-by: Marko Lindqvist --- common/networking/packets.def | 1 + data/alien/cities.ruleset | 2 ++ data/civ1/cities.ruleset | 2 ++ data/civ2/cities.ruleset | 2 ++ data/civ2civ3/cities.ruleset | 2 ++ data/classic/cities.ruleset | 2 ++ data/goldkeep/cities.ruleset | 2 ++ data/granularity/cities.ruleset | 2 ++ data/multiplayer/cities.ruleset | 2 ++ data/sandbox/cities.ruleset | 2 ++ data/stub/cities.ruleset | 2 ++ data/webperimental/cities.ruleset | 2 ++ server/cityturn.c | 14 +++++++++++--- server/ruleset.c | 14 ++++++++++++-- server/ruleset.h | 6 ++++-- tools/ruleutil/rulesave.c | 22 +++++++++++++--------- 16 files changed, 63 insertions(+), 16 deletions(-) diff --git a/common/networking/packets.def b/common/networking/packets.def index 9a75f5c329..2cddc4a8cd 100644 --- a/common/networking/packets.def +++ b/common/networking/packets.def @@ -503,6 +503,7 @@ PACKET_GAME_INFO = 16; sc, is-info BOOL changable_tax; UINT8 pop_report_zeroes; BOOL citizen_nationality; + BOOL unit_builders_nationality; UINT16 citizen_convert_speed; UINT8 conquest_convert_pct; UINT8 citizen_partisans_pct; diff --git a/data/alien/cities.ruleset b/data/alien/cities.ruleset index d5477fdc15..d909cb82ad 100644 --- a/data/alien/cities.ruleset +++ b/data/alien/cities.ruleset @@ -105,6 +105,8 @@ pop_report_zeroes = 2 ; Population in reports in hundreds [citizen] nationality = TRUE ; account for the nationality of the citizens +ubuilder_nationality = FALSE ; does pop_cost unit get builder`s nationality, + ; or that of the majority of the citizens in the city convert_speed = 50 ; base probability 50/1000 -> once every 20 turns partisans_pct = 0 ; percentage of own nationality to inspire partisans ; if 0, original city owner information is used instead diff --git a/data/civ1/cities.ruleset b/data/civ1/cities.ruleset index afda100e9a..91f400ac1c 100644 --- a/data/civ1/cities.ruleset +++ b/data/civ1/cities.ruleset @@ -105,6 +105,8 @@ pop_report_zeroes = 4 ; Population in reports in tens of thousands [citizen] nationality = FALSE ; account for the nationality of the citizens +ubuilder_nationality = FALSE ; does pop_cost unit get builder`s nationality, + ; or that of the majority of the citizens in the city convert_speed = 50 ; base probability 50/1000 -> once every 20 turns partisans_pct = 0 ; percentage of own nationality to inspire partisans ; if 0, original city owner information is used instead diff --git a/data/civ2/cities.ruleset b/data/civ2/cities.ruleset index afda100e9a..91f400ac1c 100644 --- a/data/civ2/cities.ruleset +++ b/data/civ2/cities.ruleset @@ -105,6 +105,8 @@ pop_report_zeroes = 4 ; Population in reports in tens of thousands [citizen] nationality = FALSE ; account for the nationality of the citizens +ubuilder_nationality = FALSE ; does pop_cost unit get builder`s nationality, + ; or that of the majority of the citizens in the city convert_speed = 50 ; base probability 50/1000 -> once every 20 turns partisans_pct = 0 ; percentage of own nationality to inspire partisans ; if 0, original city owner information is used instead diff --git a/data/civ2civ3/cities.ruleset b/data/civ2civ3/cities.ruleset index a15aa3daf3..782512e442 100644 --- a/data/civ2civ3/cities.ruleset +++ b/data/civ2civ3/cities.ruleset @@ -107,6 +107,8 @@ pop_report_zeroes = 4 ; Population in reports in tens of thousands [citizen] nationality = TRUE ; account for the nationality of the citizens +ubuilder_nationality = FALSE ; does pop_cost unit get builder`s nationality, + ; or that of the majority of the citizens in the city convert_speed = 50 ; base probability 50/1000 -> once every 20 turns partisans_pct = 75 ; percentage of own nationality to inspire partisans ; if 0, original city owner information is used instead diff --git a/data/classic/cities.ruleset b/data/classic/cities.ruleset index 22b65a0298..e80ac1ec33 100644 --- a/data/classic/cities.ruleset +++ b/data/classic/cities.ruleset @@ -104,6 +104,8 @@ pop_report_zeroes = 4 ; Population in reports in tens of thousands [citizen] nationality = TRUE ; account for the nationality of the citizens +ubuilder_nationality = FALSE ; does pop_cost unit get builder`s nationality, + ; or that of the majority of the citizens in the city convert_speed = 50 ; base probability 50/1000 -> once every 20 turns partisans_pct = 0 ; percentage of own nationality to inspire partisans ; if 0, original city owner information is used instead diff --git a/data/goldkeep/cities.ruleset b/data/goldkeep/cities.ruleset index 61dc0baf08..6db755da67 100644 --- a/data/goldkeep/cities.ruleset +++ b/data/goldkeep/cities.ruleset @@ -106,6 +106,8 @@ pop_report_zeroes = 4 ; Population in reports in tens of thousands [citizen] nationality = TRUE ; account for the nationality of the citizens +ubuilder_nationality = FALSE ; does pop_cost unit get builder`s nationality, + ; or that of the majority of the citizens in the city convert_speed = 50 ; base probability 50/1000 -> once every 20 turns partisans_pct = 75 ; percentage of own nationality to inspire partisans ; if 0, original city owner information is used instead diff --git a/data/granularity/cities.ruleset b/data/granularity/cities.ruleset index 28e3973a49..6027d33cd9 100644 --- a/data/granularity/cities.ruleset +++ b/data/granularity/cities.ruleset @@ -70,6 +70,8 @@ pop_report_zeroes = 1 ; Population in reports in tens [citizen] nationality = FALSE ; account for the nationality of the citizens +ubuilder_nationality = FALSE ; does pop_cost unit get builder`s nationality, + ; or that of the majority of the citizens in the city convert_speed = 50 ; base probability 50/1000 -> once every 20 turns partisans_pct = 0 ; percentage of own nationality to inspire partisans ; if 0, original city owner information is used instead diff --git a/data/multiplayer/cities.ruleset b/data/multiplayer/cities.ruleset index fe63eafbe0..ee34596f38 100644 --- a/data/multiplayer/cities.ruleset +++ b/data/multiplayer/cities.ruleset @@ -103,6 +103,8 @@ pop_report_zeroes = 4 ; Population in reports in tens of thousands [citizen] nationality = FALSE ; account for the nationality of the citizens +ubuilder_nationality = FALSE ; does pop_cost unit get builder`s nationality, + ; or that of the majority of the citizens in the city convert_speed = 50 ; base probability 50/1000 -> once every 20 turns partisans_pct = 0 ; percentage of own nationality to inspire partisans ; if 0, original city owner information is used instead diff --git a/data/sandbox/cities.ruleset b/data/sandbox/cities.ruleset index 6b36b6ffcf..bb91cb2ead 100644 --- a/data/sandbox/cities.ruleset +++ b/data/sandbox/cities.ruleset @@ -107,6 +107,8 @@ pop_report_zeroes = 4 ; Population in reports in tens of thousands [citizen] nationality = TRUE ; account for the nationality of the citizens +ubuilder_nationality = FALSE ; does pop_cost unit get builder`s nationality, + ; or that of the majority of the citizens in the city convert_speed = 50 ; base probability 50/1000 -> once every 20 turns partisans_pct = 75 ; percentage of own nationality to inspire partisans ; if 0, original city owner information is used instead diff --git a/data/stub/cities.ruleset b/data/stub/cities.ruleset index e8a28b2108..f61d0f24e9 100644 --- a/data/stub/cities.ruleset +++ b/data/stub/cities.ruleset @@ -64,6 +64,8 @@ pop_report_zeroes = 1 ; Population in reports in tens [citizen] nationality = FALSE ; account for the nationality of the citizens +ubuilder_nationality = FALSE ; does pop_cost unit get builder`s nationality, + ; or that of the majority of the citizens in the city convert_speed = 50 ; base probability 50/1000 -> once every 20 turns partisans_pct = 0 ; percentage of own nationality to inspire partisans ; if 0, original city owner information is used instead diff --git a/data/webperimental/cities.ruleset b/data/webperimental/cities.ruleset index 6f59cc3f84..3e6a6c13be 100644 --- a/data/webperimental/cities.ruleset +++ b/data/webperimental/cities.ruleset @@ -104,6 +104,8 @@ pop_report_zeroes = 4 ; Population in reports in tens of thousands [citizen] nationality = TRUE ; account for the nationality of the citizens +ubuilder_nationality = FALSE ; does pop_cost unit get builder`s nationality, + ; or that of the majority of the citizens in the city convert_speed = 50 ; base probability 50/1000 -> once every 20 turns partisans_pct = 0 ; percentage of own nationality to inspire partisans ; if 0, original city owner information is used instead diff --git a/server/cityturn.c b/server/cityturn.c index 873f9d6671..2eb28a67b2 100644 --- a/server/cityturn.c +++ b/server/cityturn.c @@ -2576,13 +2576,21 @@ static struct unit *city_create_unit(struct city *pcity, city_production_unit_veteran_level(pcity, utype), pcity->id, -1, -1); pplayer->score.units_built++; - if (pop_cost > 0 && pcity->nationality) { + + if (pop_cost > 0 && pcity->nationality != NULL) { /* We don't reduce city size in-place to keep it correct and - * existing at all while we call the following callback */ - punit->nationality = citizens_unit_nationality(pcity, pop_cost, red); + * existing at all while we call the following callback. + * We want citizens_unit_nationality() to adjust 'red' even when + * we are not setting unit nationality based on the return */ + struct player *nat = citizens_unit_nationality(pcity, pop_cost, red); + + if (!game.info.unit_builders_nationality) { + punit->nationality = nat; + } } else if (red) { red->change = 0; } + (void) place_unit(punit, pplayer, pcity, NULL, FALSE); saved_unit_id = punit->id; diff --git a/server/ruleset.c b/server/ruleset.c index a72672bb39..ad2cc5f5fd 100644 --- a/server/ruleset.c +++ b/server/ruleset.c @@ -6027,6 +6027,8 @@ static bool load_ruleset_cities(struct section_file *file, } if (ok) { + bool def_ubuild_nat = RS_DEFAULT_UBUILD_NAT; + /* civ1 & 2 didn't reveal tiles */ game.server.vision_reveal_tiles = secfile_lookup_bool_default(file, GAME_DEFAULT_VISION_REVEAL_TILES, @@ -6037,10 +6039,18 @@ static bool load_ruleset_cities(struct section_file *file, /* Citizens configuration. */ game.info.citizen_nationality = - secfile_lookup_bool_default(file, GAME_DEFAULT_NATIONALITY, + secfile_lookup_bool_default(file, RS_DEFAULT_NATIONALITY, "citizen.nationality"); + + if (compat->compat_mode && compat->version < RSFORMAT_3_2) { + /* Same as old hardcoded behavior */ + def_ubuild_nat = TRUE; + } + game.info.unit_builders_nationality = + secfile_lookup_bool_default(file, def_ubuild_nat, + "citizen.ubuilder_nationality"); game.info.citizen_convert_speed = - secfile_lookup_int_default(file, GAME_DEFAULT_CONVERT_SPEED, + secfile_lookup_int_default(file, RS_DEFAULT_CONVERT_SPEED, "citizen.convert_speed"); game.info.citizen_partisans_pct = secfile_lookup_int_default(file, 0, "citizen.partisans_pct"); diff --git a/server/ruleset.h b/server/ruleset.h index d6093e5de4..a98b3fad46 100644 --- a/server/ruleset.h +++ b/server/ruleset.h @@ -71,8 +71,6 @@ int ruleset_purge_redundant_reqs(void); #define GAME_DEFAULT_ADDTOSIZE 9 #define GAME_DEFAULT_CHANGABLE_TAX TRUE #define GAME_DEFAULT_VISION_REVEAL_TILES FALSE -#define GAME_DEFAULT_NATIONALITY FALSE -#define GAME_DEFAULT_CONVERT_SPEED 50 #define GAME_DEFAULT_DISASTER_FREQ 10 #define GAME_DEFAULT_ACH_UNIQUE TRUE #define GAME_DEFAULT_ACH_VALUE 1 @@ -116,6 +114,10 @@ int ruleset_purge_redundant_reqs(void); #define RS_MIN_MIN_TECH_COST 0 #define RS_MAX_MIN_TECH_COST 20000 +#define RS_DEFAULT_NATIONALITY FALSE +#define RS_DEFAULT_UBUILD_NAT FALSE +#define RS_DEFAULT_CONVERT_SPEED 50 + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/tools/ruleutil/rulesave.c b/tools/ruleutil/rulesave.c index aff30f6169..09084293d0 100644 --- a/tools/ruleutil/rulesave.c +++ b/tools/ruleutil/rulesave.c @@ -83,7 +83,8 @@ static struct section_file *create_ruleset_file(const char *rsname, Save int value that has default applied upon loading. **************************************************************************/ static bool save_default_int(struct section_file *sfile, int value, - int default_value, const char *path, const char *entry) + int default_value, const char *path, + const char *entry) { if (value != default_value) { if (entry != NULL) { @@ -710,18 +711,21 @@ static bool save_cities_ruleset(const char *filename, const char *name) secfile_insert_int(sfile, game.info.pop_report_zeroes, "parameters.pop_report_zeroes"); } - if (game.info.citizen_nationality != GAME_DEFAULT_NATIONALITY) { - secfile_insert_bool(sfile, game.info.citizen_nationality, - "citizen.nationality"); - } - if (game.info.citizen_convert_speed != GAME_DEFAULT_CONVERT_SPEED) { - secfile_insert_int(sfile, game.info.citizen_convert_speed, - "citizen.convert_speed"); - } + + save_default_bool(sfile, game.info.citizen_nationality, + RS_DEFAULT_NATIONALITY, + "citizen.nationality", NULL); + save_default_bool(sfile, game.info.unit_builders_nationality, + RS_DEFAULT_UBUILD_NAT, + "citizen.ubuilder_nationality", NULL); + save_default_int(sfile, game.info.citizen_convert_speed, + RS_DEFAULT_CONVERT_SPEED, + "citizen.convert_speed", NULL); if (game.info.conquest_convert_pct != 0) { secfile_insert_int(sfile, game.info.conquest_convert_pct, "citizen.conquest_convert_pct"); } + if (game.info.citizen_partisans_pct != 0) { secfile_insert_int(sfile, game.info.citizen_partisans_pct, "citizen.partisans_pct"); -- 2.39.0