From ebfb26a73b7d3f3d2775bc355680e08f0bb316f7 Mon Sep 17 00:00:00 2001 From: Dino Date: Mon, 8 Sep 2025 16:14:41 -0400 Subject: [PATCH] #1676 - do ruleset sanity check for hitpoints > 0 --- common/game.h | 10 +++++++--- server/ruleset.c | 17 +++++++++++------ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/common/game.h b/common/game.h index fee05a5b8a..fac098cd08 100644 --- a/common/game.h +++ b/common/game.h @@ -879,9 +879,13 @@ static inline bool is_ruleset_compat_mode(void) #define RS_MIN_UPGRADE_VETERAN_LOSS 0 #define RS_MAX_UPGRADE_VETERAN_LOSS MAX_VET_LEVELS -#define RS_DEFAULT_TECH_UPKEEP_DIVIDER 100 -#define RS_MIN_TECH_UPKEEP_DIVIDER 1 -#define RS_MAX_TECH_UPKEEP_DIVIDER 100000 +#define RS_DEFAULT_TECH_UPKEEP_DIVIDER 100 +#define RS_MIN_TECH_UPKEEP_DIVIDER 1 +#define RS_MAX_TECH_UPKEEP_DIVIDER 100000 + +#define RS_DEFAULT_HP 10 +#define RS_MIN_HP 1 +#define RS_MAX_HP 10000 #define RS_DEFAULT_POISON_EMPTIES_FOOD_STOCK FALSE #define RS_DEFAULT_STEAL_MAP_REVEALS_CITIES TRUE diff --git a/server/ruleset.c b/server/ruleset.c index 541020e121..f77a042290 100644 --- a/server/ruleset.c +++ b/server/ruleset.c @@ -204,6 +204,10 @@ static bool load_ruleset_veteran(struct section_file *file, const char *path, struct veteran_system **vsystem, char *err, size_t err_len); +static int secfile_lookup_int_default_min_max(struct section_file *file, + int def, int min, int max, + const char *path, ...) + fc__attribute((__format__ (__printf__, 5, 6))); char *script_buffer = NULL; char *parser_buffer = NULL; @@ -2367,8 +2371,6 @@ static bool load_ruleset_units(struct section_file *file, "%s.vision_radius_sq", sec_name) || !secfile_lookup_int(file, &u->transport_capacity, "%s.transport_cap", sec_name) - || !secfile_lookup_int(file, &u->hp, - "%s.hitpoints", sec_name) || !secfile_lookup_int(file, &u->firepower, "%s.firepower", sec_name) || !secfile_lookup_int(file, &u->fuel, @@ -2379,6 +2381,13 @@ static bool load_ruleset_units(struct section_file *file, ok = FALSE; break; } + u->hp + = secfile_lookup_int_default_min_max(file, + RS_DEFAULT_HP, + RS_MIN_HP, + RS_MAX_HP, + "%s.hitpoints", sec_name); + u->move_rate *= SINGLE_MOVE; if (u->firepower <= 0) { @@ -6380,10 +6389,6 @@ static bool load_ruleset_effects(struct section_file *file, /**********************************************************************//** Print an error message if the value is out of range. **************************************************************************/ -static int secfile_lookup_int_default_min_max(struct section_file *file, - int def, int min, int max, - const char *path, ...) - fc__attribute((__format__ (__printf__, 5, 6))); static int secfile_lookup_int_default_min_max(struct section_file *file, int def, int min, int max, const char *path, ...) -- 2.31.0