From 11001be5ddd3367ddfacbe9149ca711e0072bf17 Mon Sep 17 00:00:00 2001 From: Dino Date: Sat, 18 Oct 2025 16:36:21 -0400 Subject: [PATCH] #1676 - do ruleset sanity check for hitpoints > 0 --- common/game.h | 10 +++++++--- server/ruleset/ruleload.c | 17 +++++++++++------ tools/ruledit/edit_utype.cpp | 2 +- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/common/game.h b/common/game.h index 5fefdb5294..b02300c43c 100644 --- a/common/game.h +++ b/common/game.h @@ -881,9 +881,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/ruleload.c b/server/ruleset/ruleload.c index 34073a11ac..e6c5f34d74 100644 --- a/server/ruleset/ruleload.c +++ b/server/ruleset/ruleload.c @@ -206,6 +206,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; @@ -2255,8 +2259,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, @@ -2267,6 +2269,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) { @@ -6217,10 +6226,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, ...) diff --git a/tools/ruledit/edit_utype.cpp b/tools/ruledit/edit_utype.cpp index e568bee14d..a6ce88207d 100644 --- a/tools/ruledit/edit_utype.cpp +++ b/tools/ruledit/edit_utype.cpp @@ -110,7 +110,7 @@ edit_utype::edit_utype(ruledit_gui *ui_in, struct unit_type *utype_in) : values_ label->setParent(this); hitpoints = new QSpinBox(this); - hitpoints->setRange(0, 1000); + hitpoints->setRange(1, 1000); connect(hitpoints, SIGNAL(valueChanged(int)), this, SLOT(set_hitpoints(int))); unit_layout->addWidget(label, row, 0); -- 2.31.0