summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeterN <peter@fuzzle.org>2019-03-16 16:52:07 +0000
committerCharles Pigott <charlespigott@googlemail.com>2019-03-16 16:52:07 +0000
commitbcfc9620b0b94e05d732ddc0cede71141d590efc (patch)
tree92d3e04e3a07cb059297d901081a4aac51b43c13 /src
parent7bd43f7413aed2dc544f0f9ec269c5693ef2c69f (diff)
downloadopenttd-bcfc9620b0b94e05d732ddc0cede71141d590efc.tar.xz
Change: Use default value for invalid multi-string settings instead of clamping to min or max value. (#7361)
Diffstat (limited to 'src')
-rw-r--r--src/settings.cpp23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/settings.cpp b/src/settings.cpp
index d324ffc29..1fc2682cd 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -448,13 +448,30 @@ static void Write_ValidateSetting(void *ptr, const SettingDesc *sd, int32 val)
case SLE_VAR_U16:
case SLE_VAR_I32: {
/* Override the minimum value. No value below sdb->min, except special value 0 */
- if (!(sdb->flags & SGF_0ISDISABLED) || val != 0) val = Clamp(val, sdb->min, sdb->max);
+ if (!(sdb->flags & SGF_0ISDISABLED) || val != 0) {
+ if (!(sdb->flags & SGF_MULTISTRING)) {
+ /* Clamp value-type setting to its valid range */
+ val = Clamp(val, sdb->min, sdb->max);
+ } else if (val < sdb->min || val > (int32)sdb->max) {
+ /* Reset invalid discrete setting (where different values change gameplay) to its default value */
+ val = (int32)(size_t)sdb->def;
+ }
+ }
break;
}
case SLE_VAR_U32: {
/* Override the minimum value. No value below sdb->min, except special value 0 */
- uint min = ((sdb->flags & SGF_0ISDISABLED) && (uint)val <= (uint)sdb->min) ? 0 : sdb->min;
- WriteValue(ptr, SLE_VAR_U32, (int64)ClampU(val, min, sdb->max));
+ uint32 uval = (uint32)val;
+ if (!(sdb->flags & SGF_0ISDISABLED) || uval != 0) {
+ if (!(sdb->flags & SGF_MULTISTRING)) {
+ /* Clamp value-type setting to its valid range */
+ uval = ClampU(uval, sdb->min, sdb->max);
+ } else if (uval < (uint)sdb->min || uval > sdb->max) {
+ /* Reset invalid discrete setting to its default value */
+ uval = (uint32)(size_t)sdb->def;
+ }
+ }
+ WriteValue(ptr, SLE_VAR_U32, (int64)uval);
return;
}
case SLE_VAR_I64: