diff --git a/src/command.c b/src/command.c index 664eb950c..625065120 100644 --- a/src/command.c +++ b/src/command.c @@ -68,12 +68,12 @@ CV_PossibleValue_t CV_YesNo[] = {{0, "No"}, {1, "Yes"}, {0, NULL}}; CV_PossibleValue_t CV_Unsigned[] = {{0, "MIN"}, {999999999, "MAX"}, {0, NULL}}; CV_PossibleValue_t CV_Natural[] = {{1, "MIN"}, {999999999, "MAX"}, {0, NULL}}; -//SRB2kart +// SRB2kart CV_PossibleValue_t kartspeed_cons_t[] = { - {-1, "Auto"}, - {0, "Easy"}, - {1, "Normal"}, - {2, "Hard"}, + {KARTSPEED_AUTO, "Auto"}, + {KARTSPEED_EASY, "Easy"}, + {KARTSPEED_NORMAL, "Normal"}, + {KARTSPEED_HARD, "Hard"}, {0, NULL} }; diff --git a/src/command.h b/src/command.h index 6b5d513ef..33d232bcb 100644 --- a/src/command.h +++ b/src/command.h @@ -131,6 +131,10 @@ extern CV_PossibleValue_t CV_Unsigned[]; extern CV_PossibleValue_t CV_Natural[]; // SRB2kart +#define KARTSPEED_AUTO -1 +#define KARTSPEED_EASY 0 +#define KARTSPEED_NORMAL 1 +#define KARTSPEED_HARD 2 extern CV_PossibleValue_t kartspeed_cons_t[]; extern consvar_t cv_execversion; diff --git a/src/d_main.c b/src/d_main.c index 597eea87c..dee752107 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1536,10 +1536,11 @@ void D_SRB2Main(void) newskill = (INT16)kartspeed_cons_t[j].value; break; } + if (!kartspeed_cons_t[j].strvalue) // reached end of the list with no match { j = atoi(sskill); // assume they gave us a skill number, which is okay too - if (j >= 0 && j <= 2) + if (j >= KARTSPEED_EASY && j <= KARTSPEED_HARD) newskill = (INT16)j; } diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 51ec3b980..db0c00086 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -5779,7 +5779,7 @@ static void KartFrantic_OnChange(void) static void KartSpeed_OnChange(void) { - if (!M_SecretUnlocked(SECRET_HARDSPEED) && cv_kartspeed.value == 2) + if (!M_SecretUnlocked(SECRET_HARDSPEED) && cv_kartspeed.value == KARTSPEED_HARD) { CONS_Printf(M_GetText("You haven't earned this yet.\n")); CV_StealthSet(&cv_kartspeed, cv_kartspeed.defaultvalue); @@ -5788,13 +5788,15 @@ static void KartSpeed_OnChange(void) if (G_RaceGametype()) { - if ((UINT8)cv_kartspeed.value != gamespeed && gamestate == GS_LEVEL && leveltime > starttime) - CONS_Printf(M_GetText("Game speed will be changed to \"%s\" next round.\n"), cv_kartspeed.string); - else + if ((gamestate == GS_LEVEL && leveltime < starttime) && (cv_kartspeed.value != KARTSPEED_AUTO)) { CONS_Printf(M_GetText("Game speed has been changed to \"%s\".\n"), cv_kartspeed.string); gamespeed = (UINT8)cv_kartspeed.value; } + else if (cv_kartspeed.value != (signed)gamespeed) + { + CONS_Printf(M_GetText("Game speed will be changed to \"%s\" next round.\n"), cv_kartspeed.string); + } } } diff --git a/src/g_game.c b/src/g_game.c index d5ed9af7d..5a0960c36 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -3687,6 +3687,7 @@ static void G_DoCompleted(void) { INT32 i, j = 0; boolean gottoken = false; + SINT8 powertype = PWRLV_DISABLED; tokenlist = 0; // Reset the list @@ -3825,13 +3826,23 @@ static void G_DoCompleted(void) nextmap = G_RandMap(G_TOLFlag(gametype), prevmap, false, 0, false, NULL); } - // We are committed to this map now. // We may as well allocate its header if it doesn't exist // (That is, if it's a real map) if (nextmap < NUMMAPS && !mapheaderinfo[nextmap]) P_AllocMapHeader(nextmap); + // Set up power level gametype scrambles + if (netgame && cv_kartusepwrlv.value) + { + if (G_RaceGametype()) + powertype = PWRLV_RACE; + else if (G_BattleGametype()) + powertype = PWRLV_BATTLE; + } + + K_SetPowerLevelScrambles(powertype); + demointermission: if (skipstats && !modeattacking) // Don't skip stats if we're in record attack @@ -4104,7 +4115,11 @@ void G_LoadGameData(void) matchesplayed = READUINT32(save_p); for (i = 0; i < PWRLV_NUMTYPES; i++) + { vspowerlevel[i] = READUINT16(save_p); + if (vspowerlevel[i] < PWRLVRECORD_MIN || vspowerlevel[i] > PWRLVRECORD_MAX) + goto datacorrupt; + } modded = READUINT8(save_p); @@ -6896,7 +6911,7 @@ void G_LoadDemoInfo(menudemo_t *pdemo) extrainfo_p = infobuffer + READUINT32(info_p); // Pared down version of CV_LoadNetVars to find the kart speed - pdemo->kartspeed = 1; // Default to normal speed + pdemo->kartspeed = KARTSPEED_NORMAL; // Default to normal speed count = READUINT16(info_p); while (count--) { diff --git a/src/g_game.h b/src/g_game.h index a69f91421..de482fe7f 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -80,7 +80,7 @@ typedef struct menudemo_s { UINT16 map; UINT8 addonstatus; // What do we need to do addon-wise to play this demo? UINT8 gametype; - UINT8 kartspeed; // Add OR DF_ENCORE for encore mode, idk + SINT8 kartspeed; // Add OR DF_ENCORE for encore mode, idk UINT8 numlaps; struct { diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 6126f7bec..1afa133b3 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -3017,7 +3017,7 @@ static void HU_DrawRankings(void) } V_DrawCenteredString(256, 8, 0, "GAME SPEED"); - V_DrawCenteredString(256, 16, hilicol, kartspeed_cons_t[gamespeed].strvalue); + V_DrawCenteredString(256, 16, hilicol, kartspeed_cons_t[1+gamespeed].strvalue); } // When you play, you quickly see your score because your name is displayed in white. diff --git a/src/k_pwrlv.c b/src/k_pwrlv.c index 257b8ad06..b1848f04b 100644 --- a/src/k_pwrlv.c +++ b/src/k_pwrlv.c @@ -83,7 +83,10 @@ INT16 K_CalculatePowerLevelAvg(void) UINT8 i; if (!netgame || !cv_kartusepwrlv.value) + { + CONS_Printf("Not in a netgame, or not using power levels -- no average.\n"); return 0; // No average. + } if (G_RaceGametype()) t = PWRLV_RACE; @@ -91,7 +94,10 @@ INT16 K_CalculatePowerLevelAvg(void) t = PWRLV_BATTLE; if (t == PWRLV_DISABLED) + { + CONS_Printf("Could not set a power level type -- no average.\n"); return 0; // Hmm?! + } for (i = 0; i < MAXPLAYERS; i++) { @@ -99,12 +105,15 @@ INT16 K_CalculatePowerLevelAvg(void) || clientpowerlevels[i][t] == 0) // splitscreen player continue; - avg += clientpowerlevels[i][t]; + avg += (clientpowerlevels[i][t] << FRACBITS); div++; } if (!div) + { + CONS_Printf("Found no players -- no average.\n"); return 0; // No average. + } avg /= div; @@ -120,19 +129,32 @@ void K_SetPowerLevelScrambles(SINT8 powertype) case PWRLV_RACE: if (cv_kartspeed.value == -1 || cv_kartencore.value == -1) { - UINT8 speed = atoi(cv_kartspeed.defaultvalue); + UINT8 speed = KARTSPEED_NORMAL; boolean encore = false; INT16 avg = 0, min = 0; - UINT8 i, t = 0; + UINT8 i, t = 1; avg = K_CalculatePowerLevelAvg(); for (i = 0; i < MAXPLAYERS; i++) { + if (!playeringame[i] || players[i].spectator + || clientpowerlevels[i][t] == 0) // splitscreen player + continue; + if (min == 0 || clientpowerlevels[i][0] < min) min = clientpowerlevels[i][0]; } + CONS_Printf("Min: %d, Avg: %d\n", min, avg); + + if (avg == 0 || min == 0) + { + CONS_Printf("No average/minimum, no scramblin'.\n"); + speedscramble = encorescramble = -1; + return; + } + if (min >= 7800) { if (avg >= 8200) @@ -161,6 +183,10 @@ void K_SetPowerLevelScrambles(SINT8 powertype) else t = 1; } +#if 1 + else + t = 1; +#else else if (min >= 1800) { if (avg >= 2200) @@ -170,35 +196,41 @@ void K_SetPowerLevelScrambles(SINT8 powertype) } else t = 0; +#endif + + CONS_Printf("Table position: %d\n", t); switch (t) { case 5: - speed = 2; + speed = KARTSPEED_HARD; encore = true; break; case 4: - speed = M_RandomChance((7<>1); + speed = P_RandomChance((7<>1); break; case 3: - speed = M_RandomChance((3<>2); + speed = P_RandomChance((3<>2); break; case 2: speed = 1; - encore = M_RandomChance(FRACUNIT>>3); + encore = P_RandomChance(FRACUNIT>>3); break; case 1: default: - speed = 1; + speed = KARTSPEED_NORMAL; encore = false; break; case 0: - speed = M_RandomChance((3<x+128, S_LINEY(i)+8, globalflags, va("(%s)", spd)); } diff --git a/src/p_saveg.c b/src/p_saveg.c index eb7d2900e..b81cc0f50 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -3290,6 +3290,9 @@ static void P_NetArchiveMisc(void) WRITEUINT8(save_p, franticitems); WRITEUINT8(save_p, comeback); + WRITESINT8(save_p, speedscramble); + WRITESINT8(save_p, encorescramble); + for (i = 0; i < 4; i++) WRITESINT8(save_p, battlewanted[i]); @@ -3410,6 +3413,9 @@ static inline boolean P_NetUnArchiveMisc(void) franticitems = (boolean)READUINT8(save_p); comeback = (boolean)READUINT8(save_p); + speedscramble = READSINT8(save_p); + encorescramble = READSINT8(save_p); + for (i = 0; i < 4; i++) battlewanted[i] = READSINT8(save_p); diff --git a/src/p_setup.c b/src/p_setup.c index 5ec0f97e6..5acc72746 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -2388,18 +2388,18 @@ static void P_LevelInitStuff(void) // SRB2Kart: map load variables if (modeattacking) // Just play it safe and set everything { - gamespeed = 2; + gamespeed = KARTSPEED_HARD; franticitems = false; comeback = true; } else { if (G_BattleGametype()) - gamespeed = 0; + gamespeed = KARTSPEED_EASY; else { - if (cv_kartspeed.value == -1) - gamespeed = ((speedscramble == -1) ? atoi(cv_kartspeed.defaultvalue) : (UINT8)speedscramble); + if (cv_kartspeed.value == KARTSPEED_AUTO) + gamespeed = ((speedscramble == -1) ? KARTSPEED_NORMAL : (UINT8)speedscramble); else gamespeed = (UINT8)cv_kartspeed.value; } diff --git a/src/y_inter.c b/src/y_inter.c index c51ac1e3f..f5380d565 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -605,7 +605,7 @@ dotimer: V_DrawCenteredString(BASEVIDWIDTH/2, BASEVIDHEIGHT/2, hilicol, M_GetText("Teams will be scrambled next round!"));*/ if (speedscramble != -1 && speedscramble != gamespeed) V_DrawCenteredString(BASEVIDWIDTH/2, BASEVIDHEIGHT-24, hilicol|V_ALLOWLOWERCASE|V_SNAPTOBOTTOM, - va(M_GetText("Next race will be %s Speed!"), kartspeed_cons_t[speedscramble].strvalue)); + va(M_GetText("Next race will be %s Speed!"), kartspeed_cons_t[1+speedscramble].strvalue)); //} } @@ -1000,8 +1000,6 @@ void Y_StartIntermission(void) powertype = PWRLV_BATTLE; } - K_SetPowerLevelScrambles(powertype); - if (!multiplayer) { timer = 0; @@ -1078,7 +1076,7 @@ void Y_StartIntermission(void) break; } - if (powertype != -1) + if (powertype != PWRLV_DISABLED) K_UpdatePowerLevels(); //if (intertype == int_race || intertype == int_match)