mirror of https://github.com/OpenTTD/OpenTTD
Change: Use default value for invalid multi-string settings instead of clamping to min or max value. (#7361)
parent
7bd43f7413
commit
bcfc9620b0
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue