mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-04-28 13:00:57 +00:00
Rework min/max cvars to allow for "named" values outside their range!
Kart-port round 3, with the original commit written by me, toaster.
This commit is contained in:
parent
cbcb113d8e
commit
911fd9576b
1 changed files with 50 additions and 24 deletions
|
@ -1123,32 +1123,42 @@ static void Setvalue(consvar_t *var, const char *valstr, boolean stealth)
|
||||||
|
|
||||||
if (var->PossibleValue[0].strvalue && !stricmp(var->PossibleValue[0].strvalue, "MIN")) // bounded cvar
|
if (var->PossibleValue[0].strvalue && !stricmp(var->PossibleValue[0].strvalue, "MIN")) // bounded cvar
|
||||||
{
|
{
|
||||||
|
#define MINVAL 0
|
||||||
|
#define MAXVAL 1
|
||||||
INT32 i;
|
INT32 i;
|
||||||
// search for maximum
|
|
||||||
for (i = 1; var->PossibleValue[i].strvalue; i++)
|
|
||||||
if (!stricmp(var->PossibleValue[i].strvalue, "MAX"))
|
|
||||||
break;
|
|
||||||
#ifdef PARANOIA
|
#ifdef PARANOIA
|
||||||
if (!var->PossibleValue[i].strvalue)
|
if (!var->PossibleValue[MAXVAL].strvalue)
|
||||||
I_Error("Bounded cvar \"%s\" without maximum!\n", var->name);
|
I_Error("Bounded cvar \"%s\" without maximum!\n", var->name);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ((v != INT32_MIN && v < var->PossibleValue[0].value) || !stricmp(valstr, "MIN"))
|
// search for other
|
||||||
|
for (i = MAXVAL+1; var->PossibleValue[i].strvalue; i++)
|
||||||
|
if (v == var->PossibleValue[i].value || !stricmp(var->PossibleValue[i].strvalue, valstr))
|
||||||
{
|
{
|
||||||
v = var->PossibleValue[0].value;
|
var->value = var->PossibleValue[i].value;
|
||||||
valstr = var->PossibleValue[0].strvalue;
|
var->string = var->PossibleValue[i].strvalue;
|
||||||
|
goto finish;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if ((v != INT32_MIN && v < var->PossibleValue[MINVAL].value) || !stricmp(valstr, "MIN"))
|
||||||
|
{
|
||||||
|
v = var->PossibleValue[MINVAL].value;
|
||||||
|
valstr = var->PossibleValue[MINVAL].strvalue;
|
||||||
override = true;
|
override = true;
|
||||||
overrideval = v;
|
overrideval = v;
|
||||||
}
|
}
|
||||||
else if ((v != INT32_MIN && v > var->PossibleValue[i].value) || !stricmp(valstr, "MAX"))
|
else if ((v != INT32_MIN && v > var->PossibleValue[MAXVAL].value) || !stricmp(valstr, "MAX"))
|
||||||
{
|
{
|
||||||
v = var->PossibleValue[i].value;
|
v = var->PossibleValue[MAXVAL].value;
|
||||||
valstr = var->PossibleValue[i].strvalue;
|
valstr = var->PossibleValue[MAXVAL].strvalue;
|
||||||
override = true;
|
override = true;
|
||||||
overrideval = v;
|
overrideval = v;
|
||||||
}
|
}
|
||||||
if (v == INT32_MIN)
|
if (v == INT32_MIN)
|
||||||
goto badinput;
|
goto badinput;
|
||||||
|
#undef MINVAL
|
||||||
|
#undef MAXVAL
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1538,7 +1548,6 @@ void CV_AddValue(consvar_t *var, INT32 increment)
|
||||||
|
|
||||||
if (var->PossibleValue)
|
if (var->PossibleValue)
|
||||||
{
|
{
|
||||||
#define MINVAL 0
|
|
||||||
if (var == &cv_nextmap)
|
if (var == &cv_nextmap)
|
||||||
{
|
{
|
||||||
// Special case for the nextmap variable, used only directly from the menu
|
// Special case for the nextmap variable, used only directly from the menu
|
||||||
|
@ -1575,21 +1584,40 @@ void CV_AddValue(consvar_t *var, INT32 increment)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#define MINVAL 0
|
||||||
|
#define MAXVAL 1
|
||||||
else if (var->PossibleValue[MINVAL].strvalue && !strcmp(var->PossibleValue[MINVAL].strvalue, "MIN"))
|
else if (var->PossibleValue[MINVAL].strvalue && !strcmp(var->PossibleValue[MINVAL].strvalue, "MIN"))
|
||||||
{
|
{
|
||||||
// search the next to last
|
#ifdef PARANOIA
|
||||||
for (max = 0; var->PossibleValue[max+1].strvalue; max++)
|
if (!var->PossibleValue[MAXVAL].strvalue)
|
||||||
;
|
I_Error("Bounded cvar \"%s\" without maximum!\n", var->name);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (newvalue < var->PossibleValue[MINVAL].value) // add the max+1
|
if (newvalue < var->PossibleValue[MINVAL].value || newvalue > var->PossibleValue[MAXVAL].value)
|
||||||
newvalue += var->PossibleValue[max].value - var->PossibleValue[MINVAL].value + 1;
|
{
|
||||||
|
INT32 currentindice = -1, newindice;
|
||||||
|
for (max = MAXVAL+1; var->PossibleValue[max].strvalue; max++)
|
||||||
|
if (var->PossibleValue[max].value == var->value)
|
||||||
|
currentindice = max;
|
||||||
|
|
||||||
newvalue = var->PossibleValue[MINVAL].value + (newvalue - var->PossibleValue[MINVAL].value)
|
if (currentindice == -1 && max != MAXVAL+1)
|
||||||
% (var->PossibleValue[max].value - var->PossibleValue[MINVAL].value + 1);
|
newindice = ((increment > 0) ? MAXVAL : max) + increment;
|
||||||
|
else
|
||||||
|
newindice = currentindice + increment;
|
||||||
|
|
||||||
|
if (newindice >= max || newindice <= MAXVAL)
|
||||||
|
{
|
||||||
|
newvalue = var->PossibleValue[((increment > 0) ? MINVAL : MAXVAL)].value;
|
||||||
CV_SetValue(var, newvalue);
|
CV_SetValue(var, newvalue);
|
||||||
#undef MINVAL
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
CV_Set(var, var->PossibleValue[newindice].strvalue);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
CV_SetValue(var, newvalue);
|
||||||
|
}
|
||||||
|
#undef MINVAL
|
||||||
|
#undef MAXVAL
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
INT32 currentindice = -1, newindice;
|
INT32 currentindice = -1, newindice;
|
||||||
|
@ -1599,8 +1627,6 @@ void CV_AddValue(consvar_t *var, INT32 increment)
|
||||||
if (var->PossibleValue[max].value == var->value)
|
if (var->PossibleValue[max].value == var->value)
|
||||||
currentindice = max;
|
currentindice = max;
|
||||||
|
|
||||||
max--;
|
|
||||||
|
|
||||||
if (var == &cv_chooseskin)
|
if (var == &cv_chooseskin)
|
||||||
{
|
{
|
||||||
// Special case for the chooseskin variable, used only directly from the menu
|
// Special case for the chooseskin variable, used only directly from the menu
|
||||||
|
@ -1632,7 +1658,7 @@ void CV_AddValue(consvar_t *var, INT32 increment)
|
||||||
var->value);
|
var->value);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
newindice = (currentindice + increment + max + 1) % (max+1);
|
newindice = (currentindice + increment + max) % max;
|
||||||
CV_Set(var, var->PossibleValue[newindice].strvalue);
|
CV_Set(var, var->PossibleValue[newindice].strvalue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue