* Rework min/max cvars to allow for "named" values! They probably won't work if they're inside the range, but...

* Combine the numlaps and usemapnumlaps functionality on the menu into basenumlaps, which numlaps is set to every race start, except when it's map default value (0) in which case it loads the map's lap count.
This commit is contained in:
toaster 2018-06-29 17:49:02 +01:00
parent ef8a5b2a7f
commit cb92c6b679
5 changed files with 81 additions and 39 deletions

View file

@ -1088,32 +1088,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 (!stricmp(var->PossibleValue[i].strvalue, valstr))
{
var->value = var->PossibleValue[i].value;
var->string = var->PossibleValue[i].strvalue;
goto finish;
}
if ((v != INT32_MIN && v < var->PossibleValue[MINVAL].value) || !stricmp(valstr, "MIN"))
{ {
v = var->PossibleValue[0].value; v = var->PossibleValue[MINVAL].value;
valstr = var->PossibleValue[0].strvalue; 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
{ {
@ -1453,7 +1463,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
@ -1490,21 +1499,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"))
{ { // SRB2Kart
// 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;
CV_SetValue(var, newvalue); if (newindice >= max || newindice <= MAXVAL)
#undef MINVAL {
newvalue = var->PossibleValue[((increment > 0) ? MINVAL : MAXVAL)].value;
CV_SetValue(var, newvalue);
}
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;
@ -1514,8 +1542,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
@ -1578,7 +1604,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);
} }
} }

View file

@ -109,6 +109,7 @@ static void Color4_OnChange(void);
static void DummyConsvar_OnChange(void); static void DummyConsvar_OnChange(void);
static void SoundTest_OnChange(void); static void SoundTest_OnChange(void);
static void BaseNumLaps_OnChange(void);
static void KartFrantic_OnChange(void); static void KartFrantic_OnChange(void);
static void KartSpeed_OnChange(void); static void KartSpeed_OnChange(void);
static void KartMirror_OnChange(void); static void KartMirror_OnChange(void);
@ -408,10 +409,11 @@ consvar_t cv_pointlimit = {"pointlimit", "0", CV_NETVAR|CV_CALL|CV_NOINIT, point
static CV_PossibleValue_t timelimit_cons_t[] = {{0, "MIN"}, {30, "MAX"}, {0, NULL}}; static CV_PossibleValue_t timelimit_cons_t[] = {{0, "MIN"}, {30, "MAX"}, {0, NULL}};
consvar_t cv_timelimit = {"timelimit", "0", CV_NETVAR|CV_CALL|CV_NOINIT, timelimit_cons_t, consvar_t cv_timelimit = {"timelimit", "0", CV_NETVAR|CV_CALL|CV_NOINIT, timelimit_cons_t,
TimeLimit_OnChange, 0, NULL, NULL, 0, 0, NULL}; TimeLimit_OnChange, 0, NULL, NULL, 0, 0, NULL};
static CV_PossibleValue_t numlaps_cons_t[] = {{0, "MIN"}, {50, "MAX"}, {0, NULL}}; static CV_PossibleValue_t numlaps_cons_t[] = {{1, "MIN"}, {50, "MAX"}, {0, NULL}};
consvar_t cv_numlaps = {"numlaps", "3", CV_NETVAR|CV_CALL|CV_NOINIT, numlaps_cons_t, consvar_t cv_numlaps = {"numlaps", "3", CV_NETVAR|CV_CALL|CV_NOINIT, numlaps_cons_t,
NumLaps_OnChange, 0, NULL, NULL, 0, 0, NULL}; NumLaps_OnChange, 0, NULL, NULL, 0, 0, NULL};
consvar_t cv_usemapnumlaps = {"usemaplaps", "Yes", CV_NETVAR|CV_CHEAT, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; static CV_PossibleValue_t basenumlaps_cons_t[] = {{1, "MIN"}, {50, "MAX"}, {0, "Map default"}, {0, NULL}};
consvar_t cv_basenumlaps = {"basenumlaps", "Map default", CV_NETVAR|CV_CALL|CV_CHEAT, basenumlaps_cons_t, BaseNumLaps_OnChange, 0, NULL, NULL, 0, 0, NULL};
// log elemental hazards -- not a netvar, is local to current player // log elemental hazards -- not a netvar, is local to current player
consvar_t cv_hazardlog = {"hazardlog", "Yes", 0, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_hazardlog = {"hazardlog", "Yes", 0, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL};
@ -585,7 +587,7 @@ void D_RegisterServerCommands(void)
CV_RegisterVar(&cv_friendlyfire); CV_RegisterVar(&cv_friendlyfire);
CV_RegisterVar(&cv_pointlimit); CV_RegisterVar(&cv_pointlimit);
CV_RegisterVar(&cv_numlaps); CV_RegisterVar(&cv_numlaps);
CV_RegisterVar(&cv_usemapnumlaps); CV_RegisterVar(&cv_basenumlaps);
CV_RegisterVar(&cv_hazardlog); CV_RegisterVar(&cv_hazardlog);
@ -5197,6 +5199,18 @@ static void Command_ShowTime_f(void)
} }
// SRB2Kart: On change messages // SRB2Kart: On change messages
static void BaseNumLaps_OnChange(void)
{
if (gamestate == GS_LEVEL)
{
if (cv_basenumlaps.value)
CONS_Printf(M_GetText("Number of laps will be changed to map defaults next round.\n"));
else
CONS_Printf(M_GetText("Number of laps will be changed to %d next round.\n"), cv_basenumlaps.value);
}
}
static void KartFrantic_OnChange(void) static void KartFrantic_OnChange(void)
{ {
if (cv_kartfrantic.value != franticitems && gamestate == GS_LEVEL) if (cv_kartfrantic.value != franticitems && gamestate == GS_LEVEL)

View file

@ -77,7 +77,7 @@ extern consvar_t cv_friendlyfire;
extern consvar_t cv_pointlimit; extern consvar_t cv_pointlimit;
extern consvar_t cv_timelimit; extern consvar_t cv_timelimit;
extern consvar_t cv_numlaps; extern consvar_t cv_numlaps;
extern consvar_t cv_usemapnumlaps; extern consvar_t cv_basenumlaps;
extern UINT32 timelimitintics; extern UINT32 timelimitintics;
extern consvar_t cv_allowexitlevel; extern consvar_t cv_allowexitlevel;

View file

@ -1452,16 +1452,15 @@ static menuitem_t OP_GameOptionsMenu[] =
{IT_STRING | IT_CVAR, NULL, "Frantic Items", &cv_kartfrantic, 40}, {IT_STRING | IT_CVAR, NULL, "Frantic Items", &cv_kartfrantic, 40},
{IT_STRING | IT_CVAR, NULL, "Mirror Mode", &cv_kartmirror, 50}, {IT_STRING | IT_CVAR, NULL, "Mirror Mode", &cv_kartmirror, 50},
{IT_STRING | IT_CVAR, NULL, "Number of Laps", &cv_numlaps, 70}, {IT_STRING | IT_CVAR, NULL, "Number of Laps", &cv_basenumlaps, 70},
{IT_STRING | IT_CVAR, NULL, "Use Default Lap Counts", &cv_usemapnumlaps, 80}, {IT_STRING | IT_CVAR, NULL, "Exit Countdown Timer", &cv_countdowntime, 80},
{IT_STRING | IT_CVAR, NULL, "Exit Countdown Timer", &cv_countdowntime, 90},
//{IT_STRING | IT_CVAR, NULL, "Time Limit", &cv_timelimit, 110}, //{IT_STRING | IT_CVAR, NULL, "Time Limit", &cv_timelimit, 100},
{IT_STRING | IT_CVAR, NULL, "Starting Balloons", &cv_kartballoons, 110}, {IT_STRING | IT_CVAR, NULL, "Starting Balloons", &cv_kartballoons, 100},
{IT_STRING | IT_CVAR, NULL, "Karma Comeback", &cv_kartcomeback, 120}, {IT_STRING | IT_CVAR, NULL, "Karma Comeback", &cv_kartcomeback, 110},
{IT_STRING | IT_CVAR, NULL, "Force Character #", &cv_forceskin, 140}, {IT_STRING | IT_CVAR, NULL, "Force Character #", &cv_forceskin, 130},
{IT_STRING | IT_CVAR, NULL, "Restrict Character Changes", &cv_restrictskinchange, 150}, {IT_STRING | IT_CVAR, NULL, "Restrict Character Changes", &cv_restrictskinchange, 140},
}; };
static menuitem_t OP_ServerOptionsMenu[] = static menuitem_t OP_ServerOptionsMenu[] =

View file

@ -2875,8 +2875,11 @@ boolean P_SetupLevel(boolean skipprecip)
CONS_Printf(M_GetText("No player currently available to become IT. Awaiting available players.\n")); CONS_Printf(M_GetText("No player currently available to become IT. Awaiting available players.\n"));
} }
else if (G_RaceGametype() && server && cv_usemapnumlaps.value) else if (G_RaceGametype() && server)
CV_StealthSetValue(&cv_numlaps, mapheaderinfo[gamemap - 1]->numlaps); CV_StealthSetValue(&cv_numlaps,
(cv_basenumlaps.value)
? cv_basenumlaps.value
: mapheaderinfo[gamemap - 1]->numlaps);
// =========== // ===========
// landing point for netgames. // landing point for netgames.