From 8b08a4576349c5a988af8dec8af2947cd26a7e7e Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Wed, 14 Jun 2023 03:56:51 +0300 Subject: [PATCH 46/46] rscompat: Add "NoVeteran" as a user flag See osdn #48236 Signed-off-by: Marko Lindqvist --- common/unittype.h | 119 ++++++++++++++++--------------- data/alien/units.ruleset | 2 +- data/civ1/units.ruleset | 2 +- data/civ2/units.ruleset | 2 +- data/civ2civ3/units.ruleset | 2 +- data/classic/units.ruleset | 2 +- data/goldkeep/units.ruleset | 2 +- data/granularity/units.ruleset | 2 +- data/multiplayer/units.ruleset | 2 +- data/ruledit/comments-3.3.txt | 2 +- data/sandbox/units.ruleset | 2 +- data/stub/units.ruleset | 2 +- data/webperimental/units.ruleset | 2 +- server/rscompat.c | 70 +++++++++++++++++- 14 files changed, 139 insertions(+), 74 deletions(-) diff --git a/common/unittype.h b/common/unittype.h index b1b8620183..467b96aacc 100644 --- a/common/unittype.h +++ b/common/unittype.h @@ -326,9 +326,10 @@ struct unit_class { #define SPECENUM_VALUE77 UTYF_USER_FLAG_48 #define SPECENUM_VALUE78 UTYF_USER_FLAG_49 #define SPECENUM_VALUE79 UTYF_USER_FLAG_50 +#define SPECENUM_VALUE80 UTYF_USER_FLAG_51 /* Note that first role must have value next to last flag */ -#define UTYF_LAST_USER_FLAG UTYF_USER_FLAG_50 +#define UTYF_LAST_USER_FLAG UTYF_USER_FLAG_51 #define MAX_NUM_USER_UNIT_FLAGS (UTYF_LAST_USER_FLAG - UTYF_USER_FLAG_1 + 1) #define SPECENUM_NAMEOVERRIDE #define SPECENUM_BITVECTOR bv_unit_type_flags @@ -350,92 +351,92 @@ struct unit_class { #define SPECENUM_NAME unit_role_id /* Built first when city established */ -#define SPECENUM_VALUE80 L_FIRSTBUILD -#define SPECENUM_VALUE80NAME N_("?unitflag:FirstBuild") +#define SPECENUM_VALUE81 L_FIRSTBUILD +#define SPECENUM_VALUE81NAME N_("?unitflag:FirstBuild") /* Explorer unit */ -#define SPECENUM_VALUE81 L_EXPLORER -#define SPECENUM_VALUE81NAME N_("?unitflag:Explorer") +#define SPECENUM_VALUE82 L_EXPLORER +#define SPECENUM_VALUE82NAME N_("?unitflag:Explorer") /* Can be found in hut */ -#define SPECENUM_VALUE82 L_HUT -#define SPECENUM_VALUE82NAME N_("?unitflag:Hut") +#define SPECENUM_VALUE83 L_HUT +#define SPECENUM_VALUE83NAME N_("?unitflag:Hut") /* Can be found in hut, tech required */ -#define SPECENUM_VALUE83 L_HUT_TECH -#define SPECENUM_VALUE83NAME N_("?unitflag:HutTech") +#define SPECENUM_VALUE84 L_HUT_TECH +#define SPECENUM_VALUE84NAME N_("?unitflag:HutTech") /* Created in Partisan circumstances */ -#define SPECENUM_VALUE84 L_PARTISAN -#define SPECENUM_VALUE84NAME N_("?unitflag:Partisan") +#define SPECENUM_VALUE85 L_PARTISAN +#define SPECENUM_VALUE85NAME N_("?unitflag:Partisan") /* Ok on defense (AI) */ -#define SPECENUM_VALUE85 L_DEFEND_OK -#define SPECENUM_VALUE85NAME N_("?unitflag:DefendOk") +#define SPECENUM_VALUE86 L_DEFEND_OK +#define SPECENUM_VALUE86NAME N_("?unitflag:DefendOk") /* Primary purpose is defense (AI) */ -#define SPECENUM_VALUE86 L_DEFEND_GOOD -#define SPECENUM_VALUE86NAME N_("?unitflag:DefendGood") +#define SPECENUM_VALUE87 L_DEFEND_GOOD +#define SPECENUM_VALUE87NAME N_("?unitflag:DefendGood") /* Useful for ferrying (AI) */ -#define SPECENUM_VALUE87 L_FERRYBOAT -#define SPECENUM_VALUE87NAME N_("?unitflag:FerryBoat") +#define SPECENUM_VALUE88 L_FERRYBOAT +#define SPECENUM_VALUE88NAME N_("?unitflag:FerryBoat") /* Barbarians unit, land only */ -#define SPECENUM_VALUE88 L_BARBARIAN -#define SPECENUM_VALUE88NAME N_("?unitflag:Barbarian") +#define SPECENUM_VALUE89 L_BARBARIAN +#define SPECENUM_VALUE89NAME N_("?unitflag:Barbarian") /* Barbarians unit, global tech required */ -#define SPECENUM_VALUE89 L_BARBARIAN_TECH -#define SPECENUM_VALUE89NAME N_("?unitflag:BarbarianTech") +#define SPECENUM_VALUE90 L_BARBARIAN_TECH +#define SPECENUM_VALUE90NAME N_("?unitflag:BarbarianTech") /* Barbarian boat */ -#define SPECENUM_VALUE90 L_BARBARIAN_BOAT -#define SPECENUM_VALUE90NAME N_("?unitflag:BarbarianBoat") +#define SPECENUM_VALUE91 L_BARBARIAN_BOAT +#define SPECENUM_VALUE91NAME N_("?unitflag:BarbarianBoat") /* Barbarians boat, global tech required */ -#define SPECENUM_VALUE91 L_BARBARIAN_BOAT_TECH -#define SPECENUM_VALUE91NAME N_("?unitflag:BarbarianBoatTech") +#define SPECENUM_VALUE92 L_BARBARIAN_BOAT_TECH +#define SPECENUM_VALUE92NAME N_("?unitflag:BarbarianBoatTech") /* What barbarians should build */ -#define SPECENUM_VALUE92 L_BARBARIAN_BUILD -#define SPECENUM_VALUE92NAME N_("?unitflag:BarbarianBuild") +#define SPECENUM_VALUE93 L_BARBARIAN_BUILD +#define SPECENUM_VALUE93NAME N_("?unitflag:BarbarianBuild") /* Barbarians build when global tech */ -#define SPECENUM_VALUE93 L_BARBARIAN_BUILD_TECH -#define SPECENUM_VALUE93NAME N_("?unitflag:BarbarianBuildTech") +#define SPECENUM_VALUE94 L_BARBARIAN_BUILD_TECH +#define SPECENUM_VALUE94NAME N_("?unitflag:BarbarianBuildTech") /* Barbarian leader */ -#define SPECENUM_VALUE94 L_BARBARIAN_LEADER -#define SPECENUM_VALUE94NAME N_("?unitflag:BarbarianLeader") +#define SPECENUM_VALUE95 L_BARBARIAN_LEADER +#define SPECENUM_VALUE95NAME N_("?unitflag:BarbarianLeader") /* Sea raider unit */ -#define SPECENUM_VALUE95 L_BARBARIAN_SEA -#define SPECENUM_VALUE95NAME N_("?unitflag:BarbarianSea") +#define SPECENUM_VALUE96 L_BARBARIAN_SEA +#define SPECENUM_VALUE96NAME N_("?unitflag:BarbarianSea") /* Sea raider unit, global tech required */ -#define SPECENUM_VALUE96 L_BARBARIAN_SEA_TECH -#define SPECENUM_VALUE96NAME N_("?unitflag:BarbarianSeaTech") +#define SPECENUM_VALUE97 L_BARBARIAN_SEA_TECH +#define SPECENUM_VALUE97NAME N_("?unitflag:BarbarianSeaTech") /* StartUnit: Cities */ -#define SPECENUM_VALUE97 L_START_CITIES -#define SPECENUM_VALUE97NAME N_("?unitflag:CitiesStartUnit") +#define SPECENUM_VALUE98 L_START_CITIES +#define SPECENUM_VALUE98NAME N_("?unitflag:CitiesStartUnit") /* StartUnit: Worker */ -#define SPECENUM_VALUE98 L_START_WORKER -#define SPECENUM_VALUE98NAME N_("?unitflag:WorkerStartUnit") +#define SPECENUM_VALUE99 L_START_WORKER +#define SPECENUM_VALUE99NAME N_("?unitflag:WorkerStartUnit") /* StartUnit: Explorer */ -#define SPECENUM_VALUE99 L_START_EXPLORER -#define SPECENUM_VALUE99NAME N_("?unitflag:ExplorerStartUnit") +#define SPECENUM_VALUE100 L_START_EXPLORER +#define SPECENUM_VALUE100NAME N_("?unitflag:ExplorerStartUnit") /* StartUnit: King */ -#define SPECENUM_VALUE100 L_START_KING -#define SPECENUM_VALUE100NAME N_("?unitflag:KingStartUnit") +#define SPECENUM_VALUE101 L_START_KING +#define SPECENUM_VALUE101NAME N_("?unitflag:KingStartUnit") /* StartUnit: Diplomat */ -#define SPECENUM_VALUE101 L_START_DIPLOMAT -#define SPECENUM_VALUE101NAME N_("?unitflag:DiplomatStartUnit") +#define SPECENUM_VALUE102 L_START_DIPLOMAT +#define SPECENUM_VALUE102NAME N_("?unitflag:DiplomatStartUnit") /* StartUnit: Ferryboat */ -#define SPECENUM_VALUE102 L_START_FERRY -#define SPECENUM_VALUE102NAME N_("?unitflag:FerryStartUnit") +#define SPECENUM_VALUE103 L_START_FERRY +#define SPECENUM_VALUE103NAME N_("?unitflag:FerryStartUnit") /* StartUnit: DefendOk */ -#define SPECENUM_VALUE103 L_START_DEFEND_OK -#define SPECENUM_VALUE103NAME N_("?unitflag:DefendOkStartUnit") +#define SPECENUM_VALUE104 L_START_DEFEND_OK +#define SPECENUM_VALUE104NAME N_("?unitflag:DefendOkStartUnit") /* StartUnit: DefendGood */ -#define SPECENUM_VALUE104 L_START_DEFEND_GOOD -#define SPECENUM_VALUE104NAME N_("?unitflag:DefendGoodStartUnit") +#define SPECENUM_VALUE105 L_START_DEFEND_GOOD +#define SPECENUM_VALUE105NAME N_("?unitflag:DefendGoodStartUnit") /* StartUnit: AttackFast */ -#define SPECENUM_VALUE105 L_START_ATTACK_FAST -#define SPECENUM_VALUE105NAME N_("?unitflag:AttackFastStartUnit") +#define SPECENUM_VALUE106 L_START_ATTACK_FAST +#define SPECENUM_VALUE106NAME N_("?unitflag:AttackFastStartUnit") /* StartUnit: AttackStrong */ -#define SPECENUM_VALUE106 L_START_ATTACK_STRONG -#define SPECENUM_VALUE106NAME N_("?unitflag:AttackStrongStartUnit") +#define SPECENUM_VALUE107 L_START_ATTACK_STRONG +#define SPECENUM_VALUE107NAME N_("?unitflag:AttackStrongStartUnit") /* AI hunter type unit */ -#define SPECENUM_VALUE107 L_HUNTER -#define SPECENUM_VALUE107NAME N_("?unitflag:Hunter") +#define SPECENUM_VALUE108 L_HUNTER +#define SPECENUM_VALUE108NAME N_("?unitflag:Hunter") /* Can improve terrain */ -#define SPECENUM_VALUE108 L_SETTLERS -#define SPECENUM_VALUE108NAME N_("?unitflag:Settlers") +#define SPECENUM_VALUE109 L_SETTLERS +#define SPECENUM_VALUE109NAME N_("?unitflag:Settlers") #define L_LAST (L_SETTLERS + 1) #include "specenum_gen.h" diff --git a/data/alien/units.ruleset b/data/alien/units.ruleset index 532dfc6d0b..2855e49bda 100644 --- a/data/alien/units.ruleset +++ b/data/alien/units.ruleset @@ -17,7 +17,7 @@ options = "+Freeciv-ruleset-3.3-Devel-2023.Feb.24" format_version = 40 [control] -; Names for custom unit type flags. There can be up to 50 of these. +; Names for custom unit type flags. There can be up to 51 of these. ; name = rule name; In some circumstances user may see this ; as part of some sentences, so try to make it descriptive ; and sensible. diff --git a/data/civ1/units.ruleset b/data/civ1/units.ruleset index 00a63a285b..85979fe110 100644 --- a/data/civ1/units.ruleset +++ b/data/civ1/units.ruleset @@ -14,7 +14,7 @@ options = "+Freeciv-ruleset-3.3-Devel-2023.Feb.24" format_version = 40 [control] -; Names for custom unit type flags. There can be up to 50 of these. +; Names for custom unit type flags. There can be up to 51 of these. ; name = rule name; In some circumstances user may see this ; as part of some sentences, so try to make it descriptive ; and sensible. diff --git a/data/civ2/units.ruleset b/data/civ2/units.ruleset index 88be6abfb5..7e65aae3de 100644 --- a/data/civ2/units.ruleset +++ b/data/civ2/units.ruleset @@ -14,7 +14,7 @@ options = "+Freeciv-ruleset-3.3-Devel-2023.Feb.24" format_version = 40 [control] -; Names for custom unit type flags. There can be up to 50 of these. +; Names for custom unit type flags. There can be up to 51 of these. ; name = rule name; In some circumstances user may see this ; as part of some sentences, so try to make it descriptive ; and sensible. diff --git a/data/civ2civ3/units.ruleset b/data/civ2civ3/units.ruleset index 6cccebf9f5..9958eec4f4 100644 --- a/data/civ2civ3/units.ruleset +++ b/data/civ2civ3/units.ruleset @@ -20,7 +20,7 @@ options = "+Freeciv-ruleset-3.3-Devel-2023.Feb.24 web-compatible" format_version = 40 [control] -; Names for custom unit type flags. There can be up to 50 of these. +; Names for custom unit type flags. There can be up to 51 of these. ; name = rule name; In some circumstances user may see this ; as part of some sentences, so try to make it descriptive ; and sensible. diff --git a/data/classic/units.ruleset b/data/classic/units.ruleset index 66c6900353..c5a0543d13 100644 --- a/data/classic/units.ruleset +++ b/data/classic/units.ruleset @@ -20,7 +20,7 @@ options = "+Freeciv-ruleset-3.3-Devel-2023.Feb.24 web-compatible" format_version = 40 [control] -; Names for custom unit type flags. There can be up to 50 of these. +; Names for custom unit type flags. There can be up to 51 of these. ; name = rule name; In some circumstances user may see this ; as part of some sentences, so try to make it descriptive ; and sensible. diff --git a/data/goldkeep/units.ruleset b/data/goldkeep/units.ruleset index 624ea07d5d..9cbf0c08f5 100644 --- a/data/goldkeep/units.ruleset +++ b/data/goldkeep/units.ruleset @@ -23,7 +23,7 @@ options = "+Freeciv-ruleset-3.3-Devel-2023.Feb.24" format_version = 40 [control] -; Names for custom unit type flags. There can be up to 50 of these. +; Names for custom unit type flags. There can be up to 51 of these. ; name = rule name; In some circumstances user may see this ; as part of some sentences, so try to make it descriptive ; and sensible. diff --git a/data/granularity/units.ruleset b/data/granularity/units.ruleset index 5536272845..2d87f4e691 100644 --- a/data/granularity/units.ruleset +++ b/data/granularity/units.ruleset @@ -20,7 +20,7 @@ options = "+Freeciv-ruleset-3.3-Devel-2023.Feb.24" format_version = 40 [control] -; Names for custom unit type flags. There can be up to 50 of these. +; Names for custom unit type flags. There can be up to 51 of these. ; name = rule name; In some circumstances user may see this ; as part of some sentences, so try to make it descriptive ; and sensible. diff --git a/data/multiplayer/units.ruleset b/data/multiplayer/units.ruleset index a50dc534e0..02823008b9 100644 --- a/data/multiplayer/units.ruleset +++ b/data/multiplayer/units.ruleset @@ -20,7 +20,7 @@ options = "+Freeciv-ruleset-3.3-Devel-2023.Feb.24 web-compatible" format_version = 40 [control] -; Names for custom unit type flags. There can be up to 50 of these. +; Names for custom unit type flags. There can be up to 51 of these. ; name = rule name; In some circumstances user may see this ; as part of some sentences, so try to make it descriptive ; and sensible. diff --git a/data/ruledit/comments-3.3.txt b/data/ruledit/comments-3.3.txt index 40a1811ef8..63f26838bc 100644 --- a/data/ruledit/comments-3.3.txt +++ b/data/ruledit/comments-3.3.txt @@ -1280,7 +1280,7 @@ counters = "\n\ ; This section has comments documenting user (custom) flag types utype = "\ -; Names for custom unit type flags. There can be up to 50 of these.\n\ +; Names for custom unit type flags. There can be up to 51 of these.\n\ ; name = rule name; In some circumstances user may see this\n\ ; as part of some sentences, so try to make it descriptive\n\ ; and sensible.\n\ diff --git a/data/sandbox/units.ruleset b/data/sandbox/units.ruleset index 130144d00d..16116880e8 100644 --- a/data/sandbox/units.ruleset +++ b/data/sandbox/units.ruleset @@ -20,7 +20,7 @@ options = "+Freeciv-ruleset-3.3-Devel-2023.Feb.24" format_version = 40 [control] -; Names for custom unit type flags. There can be up to 50 of these. +; Names for custom unit type flags. There can be up to 51 of these. ; name = rule name; In some circumstances user may see this ; as part of some sentences, so try to make it descriptive ; and sensible. diff --git a/data/stub/units.ruleset b/data/stub/units.ruleset index f42c0e458d..10a93d6ca6 100644 --- a/data/stub/units.ruleset +++ b/data/stub/units.ruleset @@ -7,7 +7,7 @@ options = "+Freeciv-ruleset-3.3-Devel-2023.Feb.24" format_version = 40 [control] -; Names for custom unit type flags. There can be up to 50 of these. +; Names for custom unit type flags. There can be up to 51 of these. ; name = rule name; In some circumstances user may see this ; as part of some sentences, so try to make it descriptive ; and sensible. diff --git a/data/webperimental/units.ruleset b/data/webperimental/units.ruleset index 01834a5565..96ab3d12ba 100644 --- a/data/webperimental/units.ruleset +++ b/data/webperimental/units.ruleset @@ -20,7 +20,7 @@ options = "+Freeciv-ruleset-3.3-Devel-2023.Feb.24 web-compatible" format_version = 40 [control] -; Names for custom unit type flags. There can be up to 50 of these. +; Names for custom unit type flags. There can be up to 51 of these. ; name = rule name; In some circumstances user may see this ; as part of some sentences, so try to make it descriptive ; and sensible. diff --git a/server/rscompat.c b/server/rscompat.c index 15b1b7f439..998eb0ae94 100644 --- a/server/rscompat.c +++ b/server/rscompat.c @@ -47,9 +47,9 @@ FC_STATIC_ASSERT((ARRAY_SIZE(_new_flags_) \ <= _LAST_USER_FLAG_ - _LAST_USER_FLAG_PREV_), \ not_enough_new_##_name_##_user_flags) -#define UTYF_LAST_USER_FLAG_3_0 UTYF_USER_FLAG_40 -#define UCF_LAST_USER_FLAG_3_0 UCF_USER_FLAG_8 -#define TER_LAST_USER_FLAG_3_0 TER_USER_8 +#define UTYF_LAST_USER_FLAG_3_2 UTYF_USER_FLAG_50 + +static int first_free_unit_type_user_flag(void); /**********************************************************************//** Initialize rscompat information structure @@ -329,6 +329,51 @@ void rscompat_enablers_add_obligatory_hard_reqs(void) **************************************************************************/ bool rscompat_names(struct rscompat_info *info) { + if (info->version < RSFORMAT_3_3) { + int first_free; + int i; + + /* Some unit type flags moved to the ruleset between 3.2 and 3.3. + * Add them back as user flags. + * XXX: ruleset might not need all of these, and may have enough + * flags of its own that these additional ones prevent conversion. */ + const struct { + const char *name; + const char *helptxt; + } new_flags_33[] = { + { N_("NoVeteran"), N_("May acquire veteran status.") } + }; + + enough_new_user_flags(new_flags_33, unit_type, + UTYF_LAST_USER_FLAG, UTYF_LAST_USER_FLAG_3_2); + + /* Unit type flags. */ + first_free = first_free_unit_type_user_flag() + UTYF_USER_FLAG_1; + + for (i = 0; i < ARRAY_SIZE(new_flags_33); i++) { + if (UTYF_USER_FLAG_1 + MAX_NUM_USER_UNIT_FLAGS <= first_free + i) { + /* Can't add the user unit type flags. */ + ruleset_error(NULL, LOG_ERROR, + "Can't upgrade the ruleset. Not enough free unit type " + "user flags to add user flags for the unit type flags " + "that used to be hardcoded."); + return FALSE; + } + /* Shouldn't be possible for valid old ruleset to have flag names that + * clash with these ones */ + if (unit_type_flag_id_by_name(new_flags_33[i].name, fc_strcasecmp) + != unit_type_flag_id_invalid()) { + ruleset_error(NULL, LOG_ERROR, + "Ruleset had illegal user unit type flag '%s'", + new_flags_33[i].name); + return FALSE; + } + set_user_unit_type_flag_name(first_free + i, + new_flags_33[i].name, + new_flags_33[i].helptxt); + } + } + /* No errors encountered. */ return TRUE; } @@ -369,3 +414,22 @@ void rscompat_postprocess(struct rscompat_info *info) * using it risks an unexpected change on the next load and save. */ autoadjust_ruleset_data(); } + +/**********************************************************************//** + Find and return the first unused unit type user flag. If all unit type + user flags are taken MAX_NUM_USER_UNIT_FLAGS is returned. +**************************************************************************/ +static int first_free_unit_type_user_flag(void) +{ + int flag; + + /* Find the first unused user defined unit type flag. */ + for (flag = 0; flag < MAX_NUM_USER_UNIT_FLAGS; flag++) { + if (unit_type_flag_id_name_cb(flag + UTYF_USER_FLAG_1) == NULL) { + return flag; + } + } + + /* All unit type user flags are taken. */ + return MAX_NUM_USER_UNIT_FLAGS; +} -- 2.39.2