From a60d4a13a1aca0f27dec75e94dd68b674f2306ac Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Mon, 19 Sep 2022 00:04:57 -0400 Subject: [PATCH 01/10] RNG classes, take 2 Redone version of my old branch --- src/d_clisrv.c | 14 ++- src/d_netcmd.c | 6 +- src/g_demo.c | 41 +++++--- src/g_game.c | 10 +- src/k_battle.c | 20 ++-- src/k_grandprix.c | 2 +- src/k_kart.c | 140 ++++++++++++------------- src/k_menufunc.c | 10 +- src/k_pwrlv.c | 14 +-- src/k_terrain.c | 14 +-- src/lua_baselib.c | 15 +-- src/m_cheat.c | 6 +- src/m_random.c | 117 +++++++++++++-------- src/m_random.h | 55 +++++----- src/objects/shrink.c | 6 +- src/p_enemy.c | 236 +++++++++++++++++++++---------------------- src/p_floor.c | 2 +- src/p_inter.c | 30 +++--- src/p_lights.c | 4 +- src/p_mobj.c | 162 ++++++++++++++--------------- src/p_saveg.c | 21 +++- src/p_spec.c | 10 +- src/p_user.c | 16 +-- src/st_stuff.c | 10 +- 24 files changed, 525 insertions(+), 436 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index ebd58844e..f945b50ca 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5019,7 +5019,19 @@ static INT16 Consistancy(void) // I give up // Coop desynching enemies is painful if (gamestate == GS_LEVEL) - ret += P_GetRandSeed(); + { + for (i = 0; i < PRNUMCLASS; i++) + { + if (i & 1) + { + ret -= P_GetRandSeed(i); + } + else + { + ret += P_GetRandSeed(i); + } + } + } #ifdef MOBJCONSISTANCY if (gamestate == GS_LEVEL) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 9dcc990a9..c87356618 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -3012,7 +3012,7 @@ static void Got_Mapcmd(UINT8 **cp, INT32 playernum) READSTRINGN(*cp, mapname, MAX_WADPATH); if (netgame) - P_SetRandSeed(READUINT32(*cp)); + P_ClearRandom(READUINT32(*cp)); if (!skipprecutscene) { @@ -3266,7 +3266,9 @@ static void Got_RandomSeed(UINT8 **cp, INT32 playernum) if (playernum != serverplayer) // it's not from the server, wtf? return; - P_SetRandSeed(seed); + // Sal: this seems unused, so this is probably fine? + // If it needs specific RNG classes, then it should be easy to add. + P_ClearRandom(seed); } /** Clears all players' scores in a netgame. diff --git a/src/g_demo.c b/src/g_demo.c index 1e2d5e2f3..6afabe42f 100644 --- a/src/g_demo.c +++ b/src/g_demo.c @@ -392,14 +392,18 @@ void G_ReadDemoExtraData(void) switch (p) { case DW_RNG: - rng = READUINT32(demo_p); - if (P_GetRandSeed() != rng) + for (i = 0; i < PRNUMCLASS; i++) { - P_SetRandSeed(rng); + rng = READUINT32(demo_p); - if (demosynced) - CONS_Alert(CONS_WARNING, M_GetText("Demo playback has desynced (RNG)!\n")); - demosynced = false; + if (P_GetRandSeed(i) != rng) + { + P_SetRandSeed(i, rng); + + if (demosynced) + CONS_Alert(CONS_WARNING, M_GetText("Demo playback has desynced (RNG)!\n")); + demosynced = false; + } } } @@ -514,7 +518,11 @@ void G_WriteDemoExtraData(void) demo_writerng = 0; timeout = 16; WRITEUINT8(demo_p, DW_RNG); - WRITEUINT32(demo_p, P_GetRandSeed()); + + for (i = 0; i < PRNUMCLASS; i++) + { + WRITEUINT32(demo_p, P_GetRandSeed(i)); + } } } @@ -2035,7 +2043,10 @@ void G_BeginRecording(void) break; } - WRITEUINT32(demo_p,P_GetInitSeed()); + for (i = 0; i < PRNUMCLASS; i++) + { + WRITEUINT32(demo_p, P_GetInitSeed(i)); + } // Reserved for extrainfo location from start of file demoinfo_p = demo_p; @@ -2705,7 +2716,7 @@ void G_DoPlayDemo(char *defdemoname) lumpnum_t l; char skin[17],color[MAXCOLORNAME+1],follower[17],*n,*pdemoname; UINT8 version,subversion; - UINT32 randseed; + UINT32 randseed[PRNUMCLASS]; char msg[1024]; boolean spectator; @@ -2913,7 +2924,10 @@ void G_DoPlayDemo(char *defdemoname) } // Random seed - randseed = READUINT32(demo_p); + for (i = 0; i < PRNUMCLASS; i++) + { + randseed[i] = READUINT32(demo_p); + } demo_p += 4; // Extrainfo location @@ -3117,7 +3131,10 @@ void G_DoPlayDemo(char *defdemoname) R_ExecuteSetViewSize(); - P_SetRandSeed(randseed); + for (i = 0; i < PRNUMCLASS; i++) + { + P_SetRandSeed(i, randseed[i]); + } G_InitNew(demoflags & DF_ENCORE, G_BuildMapName(gamemap), true, true, false); // Doesn't matter whether you reset or not here, given changes to resetplayer. for (i = 0; i < MAXPLAYERS; i++) @@ -3622,7 +3639,7 @@ static void WriteDemoChecksum(void) #ifdef NOMD5 UINT8 i; for (i = 0; i < 16; i++, p++) - *p = P_RandomByte(); // This MD5 was chosen by fair dice roll and most likely < 50% correct. + *p = P_RandomByte(PR_UNDEFINED); // This MD5 was chosen by fair dice roll and most likely < 50% correct. #else md5_buffer((char *)p+16, demo_p - (p+16), p); // make a checksum of everything after the checksum in the file. #endif diff --git a/src/g_game.c b/src/g_game.c index 4d98256f1..03a3c08fa 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -2546,7 +2546,7 @@ mapthing_t *G_FindTeamStart(INT32 playernum) return NULL; } - if ((!players[playernum].ctfteam && numredctfstarts && (!numbluectfstarts || P_RandomChance(FRACUNIT/2))) || players[playernum].ctfteam == 1) //red + if ((!players[playernum].ctfteam && numredctfstarts && (!numbluectfstarts || P_RandomChance(PR_UNDEFINED, FRACUNIT/2))) || players[playernum].ctfteam == 1) //red { if (!numredctfstarts) { @@ -2557,7 +2557,7 @@ mapthing_t *G_FindTeamStart(INT32 playernum) for (j = 0; j < 32; j++) { - i = P_RandomKey(numredctfstarts); + i = P_RandomKey(PR_UNDEFINED, numredctfstarts); if (G_CheckSpot(playernum, redctfstarts[i])) return redctfstarts[i]; } @@ -2577,7 +2577,7 @@ mapthing_t *G_FindTeamStart(INT32 playernum) for (j = 0; j < 32; j++) { - i = P_RandomKey(numbluectfstarts); + i = P_RandomKey(PR_UNDEFINED, numbluectfstarts); if (G_CheckSpot(playernum, bluectfstarts[i])) return bluectfstarts[i]; } @@ -2598,7 +2598,7 @@ mapthing_t *G_FindBattleStart(INT32 playernum) { for (j = 0; j < 64; j++) { - i = P_RandomKey(numdmstarts); + i = P_RandomKey(PR_UNDEFINED, numdmstarts); if (G_CheckSpot(playernum, deathmatchstarts[i])) return deathmatchstarts[i]; } @@ -4585,7 +4585,7 @@ void G_InitNew(UINT8 pencoremode, const char *mapname, boolean resetplayer, bool comebackshowninfo = false; if (!demo.playback && !netgame) // Netgame sets random seed elsewhere, demo playback sets seed just before us! - P_SetRandSeed(M_RandomizedSeed()); // Use a more "Random" random seed + P_ClearRandom(M_RandomizedSeed()); // Use a more "Random" random seed // Clear a bunch of variables redscore = bluescore = lastmap = 0; diff --git a/src/k_battle.c b/src/k_battle.c index 14ecfabf5..ed8c2af3a 100644 --- a/src/k_battle.c +++ b/src/k_battle.c @@ -211,7 +211,7 @@ mobj_t *K_SpawnChaosEmerald(fixed_t x, fixed_t y, fixed_t z, angle_t angle, SINT mobj_t *overlay; P_Thrust(emerald, - FixedAngle(P_RandomFixed() * 180) + angle, + FixedAngle(P_RandomFixed(PR_UNDEFINED) * 180) + angle, 24 * mapobjectscale); emerald->momz = flip * 24 * mapobjectscale; @@ -268,8 +268,8 @@ mobj_t *K_SpawnSphereBox(fixed_t x, fixed_t y, fixed_t z, angle_t angle, SINT8 f P_InitAngle(drop, angle); P_Thrust(drop, - FixedAngle(P_RandomFixed() * 180) + angle, - P_RandomRange(4, 12) * mapobjectscale); + FixedAngle(P_RandomFixed(PR_UNDEFINED) * 180) + angle, + P_RandomRange(PR_UNDEFINED, 4, 12) * mapobjectscale); drop->momz = flip * 12 * mapobjectscale; if (drop->eflags & MFE_UNDERWATER) @@ -412,7 +412,7 @@ void K_RunPaperItemSpawners(void) { K_SpawnChaosEmerald( battleovertime.x, battleovertime.y, battleovertime.z + (128 * mapobjectscale * flip), - FixedAngle(P_RandomRange(0, 359) * FRACUNIT), flip, + FixedAngle(P_RandomRange(PR_UNDEFINED, 0, 359) * FRACUNIT), flip, firstUnspawnedEmerald ); } @@ -420,7 +420,7 @@ void K_RunPaperItemSpawners(void) { K_CreatePaperItem( battleovertime.x, battleovertime.y, battleovertime.z + (128 * mapobjectscale * flip), - FixedAngle(P_RandomRange(0, 359) * FRACUNIT), flip, + FixedAngle(P_RandomRange(PR_UNDEFINED, 0, 359) * FRACUNIT), flip, 0, 0 ); @@ -428,7 +428,7 @@ void K_RunPaperItemSpawners(void) { K_SpawnSphereBox( battleovertime.x, battleovertime.y, battleovertime.z + (128 * mapobjectscale * flip), - FixedAngle(P_RandomRange(0, 359) * FRACUNIT), flip, + FixedAngle(P_RandomRange(PR_UNDEFINED, 0, 359) * FRACUNIT), flip, 10 ); } @@ -509,7 +509,7 @@ void K_RunPaperItemSpawners(void) } else { - key = P_RandomKey(spotCount); + key = P_RandomKey(PR_UNDEFINED, spotCount); } r = spotMap[key]; @@ -523,7 +523,7 @@ void K_RunPaperItemSpawners(void) { drop = K_SpawnChaosEmerald( spotList[r]->x, spotList[r]->y, spotList[r]->z + (128 * mapobjectscale * flip), - FixedAngle(P_RandomRange(0, 359) * FRACUNIT), flip, + FixedAngle(P_RandomRange(PR_UNDEFINED, 0, 359) * FRACUNIT), flip, firstUnspawnedEmerald ); } @@ -533,7 +533,7 @@ void K_RunPaperItemSpawners(void) { drop = K_SpawnSphereBox( spotList[r]->x, spotList[r]->y, spotList[r]->z + (128 * mapobjectscale * flip), - FixedAngle(P_RandomRange(0, 359) * FRACUNIT), flip, + FixedAngle(P_RandomRange(PR_UNDEFINED, 0, 359) * FRACUNIT), flip, 10 ); K_FlipFromObject(drop, spotList[r]); @@ -541,7 +541,7 @@ void K_RunPaperItemSpawners(void) drop = K_CreatePaperItem( spotList[r]->x, spotList[r]->y, spotList[r]->z + (128 * mapobjectscale * flip), - FixedAngle(P_RandomRange(0, 359) * FRACUNIT), flip, + FixedAngle(P_RandomRange(PR_UNDEFINED, 0, 359) * FRACUNIT), flip, 0, 0 ); } diff --git a/src/k_grandprix.c b/src/k_grandprix.c index 077532fa3..9b4da706f 100644 --- a/src/k_grandprix.c +++ b/src/k_grandprix.c @@ -590,7 +590,7 @@ void K_RetireBots(void) if (bot->pflags & PF_NOCONTEST) { - UINT8 skinnum = P_RandomKey(numskins); + UINT8 skinnum = P_RandomKey(PR_UNDEFINED, numskins); UINT8 loops = 0; while (!skinusable[skinnum]) diff --git a/src/k_kart.c b/src/k_kart.c index 11cafc46d..a4d6c136f 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -1086,7 +1086,7 @@ static void K_KartItemRoulette(player_t *player, ticcmd_t *cmd) if (!(gametyperules & GTR_SPHERES) && mashed && player->rings < 0 && cv_superring.value) { INT32 debtamount = min(20, abs(player->rings)); - if (P_RandomChance((debtamount*FRACUNIT)/20)) + if (P_RandomChance(PR_UNDEFINED, (debtamount*FRACUNIT)/20)) { K_KartGetItemResult(player, KITEM_SUPERRING); player->karthud[khud_itemblink] = TICRATE; @@ -1136,7 +1136,7 @@ static void K_KartItemRoulette(player_t *player, ticcmd_t *cmd) // Award the player whatever power is rolled if (totalspawnchance > 0) { - totalspawnchance = P_RandomKey(totalspawnchance); + totalspawnchance = P_RandomKey(PR_UNDEFINED, totalspawnchance); for (i = 0; i < NUMKARTRESULTS && spawnchance[i] <= totalspawnchance; i++); K_KartGetItemResult(player, i); @@ -1720,9 +1720,9 @@ static void K_DrawDraftCombiring(player_t *player, player_t *victim, fixed_t cur { if (offset == 0) { - mobj_t *band = P_SpawnMobj(curx + (P_RandomRange(-12,12)*mapobjectscale), - cury + (P_RandomRange(-12,12)*mapobjectscale), - curz + (P_RandomRange(24,48)*mapobjectscale), + mobj_t *band = P_SpawnMobj(curx + (P_RandomRange(PR_UNDEFINED, -12, 12)*mapobjectscale), + cury + (P_RandomRange(PR_UNDEFINED, -12, 12)*mapobjectscale), + curz + (P_RandomRange(PR_UNDEFINED, 24, 48)*mapobjectscale), MT_SIGNSPARKLE); if (maxdist == 0) @@ -2191,7 +2191,7 @@ void K_SpawnDriftBoostClip(player_t *player) clip->momz += momz; P_InstaThrust(clip, player->mo->angle + - P_RandomFlip(P_RandomRange(FRACUNIT/2, FRACUNIT)), + P_RandomFlip(P_RandomRange(PR_UNDEFINED, FRACUNIT/2, FRACUNIT)), FixedMul(scale, player->speed)); } @@ -2211,9 +2211,9 @@ void K_SpawnDriftBoostClipSpark(mobj_t *clip) void K_SpawnNormalSpeedLines(player_t *player) { - mobj_t *fast = P_SpawnMobj(player->mo->x + (P_RandomRange(-36,36) * player->mo->scale), - player->mo->y + (P_RandomRange(-36,36) * player->mo->scale), - player->mo->z + (player->mo->height/2) + (P_RandomRange(-20,20) * player->mo->scale), + mobj_t *fast = P_SpawnMobj(player->mo->x + (P_RandomRange(PR_UNDEFINED,-36,36) * player->mo->scale), + player->mo->y + (P_RandomRange(PR_UNDEFINED,-36,36) * player->mo->scale), + player->mo->z + (player->mo->height/2) + (P_RandomRange(PR_UNDEFINED,-20,20) * player->mo->scale), MT_FASTLINE); P_SetTarget(&fast->target, player->mo); @@ -2261,9 +2261,9 @@ void K_SpawnNormalSpeedLines(player_t *player) void K_SpawnInvincibilitySpeedLines(mobj_t *mo) { mobj_t *fast = P_SpawnMobjFromMobj(mo, - P_RandomRange(-48, 48) * FRACUNIT, - P_RandomRange(-48, 48) * FRACUNIT, - P_RandomRange(0, 64) * FRACUNIT, + P_RandomRange(PR_UNDEFINED, -48, 48) * FRACUNIT, + P_RandomRange(PR_UNDEFINED, -48, 48) * FRACUNIT, + P_RandomRange(PR_UNDEFINED, 0, 64) * FRACUNIT, MT_FASTLINE); P_SetMobjState(fast, S_KARTINVLINES1); @@ -2321,9 +2321,9 @@ static void K_SpawnGrowShrinkParticles(mobj_t *mo, INT32 timer) particle = P_SpawnMobjFromMobj( mo, - P_RandomRange(-32, 32) * FRACUNIT, - P_RandomRange(-32, 32) * FRACUNIT, - (P_RandomRange(0, 24) + (shrink ? 48 : 0)) * FRACUNIT, + P_RandomRange(PR_UNDEFINED, -32, 32) * FRACUNIT, + P_RandomRange(PR_UNDEFINED, -32, 32) * FRACUNIT, + (P_RandomRange(PR_UNDEFINED, 0, 24) + (shrink ? 48 : 0)) * FRACUNIT, MT_GROW_PARTICLE ); @@ -2849,7 +2849,7 @@ static void K_RegularVoiceTimers(player_t *player) void K_PlayAttackTaunt(mobj_t *source) { - sfxenum_t pick = P_RandomKey(2); // Gotta roll the RNG every time this is called for sync reasons + sfxenum_t pick = P_RandomKey(PR_UNDEFINED, 2); // Gotta roll the RNG every time this is called for sync reasons boolean tasteful = (!source->player || !source->player->karthud[khud_tauntvoices]); if (cv_kartvoices.value && (tasteful || cv_kartvoices.value == 2)) @@ -2863,7 +2863,7 @@ void K_PlayAttackTaunt(mobj_t *source) void K_PlayBoostTaunt(mobj_t *source) { - sfxenum_t pick = P_RandomKey(2); // Gotta roll the RNG every time this is called for sync reasons + sfxenum_t pick = P_RandomKey(PR_UNDEFINED, 2); // Gotta roll the RNG every time this is called for sync reasons boolean tasteful = (!source->player || !source->player->karthud[khud_tauntvoices]); if (cv_kartvoices.value && (tasteful || cv_kartvoices.value == 2)) @@ -2897,7 +2897,7 @@ void K_PlayOvertakeSound(mobj_t *source) void K_PlayPainSound(mobj_t *source, mobj_t *other) { - sfxenum_t pick = P_RandomKey(2); // Gotta roll the RNG every time this is called for sync reasons + sfxenum_t pick = P_RandomKey(PR_UNDEFINED, 2); // Gotta roll the RNG every time this is called for sync reasons sfxenum_t sfx_id = ((skin_t *)source->skin)->soundsid[S_sfx[sfx_khurt1 + pick].skinsound]; boolean alwaysHear = false; @@ -4148,18 +4148,18 @@ void K_SpawnMineExplosion(mobj_t *source, UINT8 color) dust->scalespeed = source->scale/12; P_InstaThrust(dust, dust->angle, FixedMul(20*FRACUNIT, source->scale)); - truc = P_SpawnMobj(source->x + P_RandomRange(-radius, radius)*FRACUNIT, - source->y + P_RandomRange(-radius, radius)*FRACUNIT, - source->z + P_RandomRange(0, height)*FRACUNIT, MT_BOOMEXPLODE); + truc = P_SpawnMobj(source->x + P_RandomRange(PR_UNDEFINED, -radius, radius)*FRACUNIT, + source->y + P_RandomRange(PR_UNDEFINED, -radius, radius)*FRACUNIT, + source->z + P_RandomRange(PR_UNDEFINED, 0, height)*FRACUNIT, MT_BOOMEXPLODE); K_MatchGenericExtraFlags(truc, source); P_SetScale(truc, source->scale); truc->destscale = source->scale*6; truc->scalespeed = source->scale/12; speed = FixedMul(10*FRACUNIT, source->scale)>>FRACBITS; - truc->momx = P_RandomRange(-speed, speed)*FRACUNIT; - truc->momy = P_RandomRange(-speed, speed)*FRACUNIT; + truc->momx = P_RandomRange(PR_UNDEFINED, -speed, speed)*FRACUNIT; + truc->momy = P_RandomRange(PR_UNDEFINED, -speed, speed)*FRACUNIT; speed = FixedMul(20*FRACUNIT, source->scale)>>FRACBITS; - truc->momz = P_RandomRange(-speed, speed)*FRACUNIT*P_MobjFlip(truc); + truc->momz = P_RandomRange(PR_UNDEFINED, -speed, speed)*FRACUNIT*P_MobjFlip(truc); if (truc->eflags & MFE_UNDERWATER) truc->momz = (117 * truc->momz) / 200; truc->color = color; @@ -4167,30 +4167,30 @@ void K_SpawnMineExplosion(mobj_t *source, UINT8 color) for (i = 0; i < 16; i++) { - dust = P_SpawnMobj(source->x + P_RandomRange(-radius, radius)*FRACUNIT, - source->y + P_RandomRange(-radius, radius)*FRACUNIT, - source->z + P_RandomRange(0, height)*FRACUNIT, MT_SMOKE); + dust = P_SpawnMobj(source->x + P_RandomRange(PR_UNDEFINED, -radius, radius)*FRACUNIT, + source->y + P_RandomRange(PR_UNDEFINED, -radius, radius)*FRACUNIT, + source->z + P_RandomRange(PR_UNDEFINED, 0, height)*FRACUNIT, MT_SMOKE); P_SetMobjState(dust, S_OPAQUESMOKE1); P_SetScale(dust, source->scale); dust->destscale = source->scale*10; dust->scalespeed = source->scale/12; dust->tics = 30; - dust->momz = P_RandomRange(FixedMul(3*FRACUNIT, source->scale)>>FRACBITS, FixedMul(7*FRACUNIT, source->scale)>>FRACBITS)*FRACUNIT; + dust->momz = P_RandomRange(PR_UNDEFINED, FixedMul(3*FRACUNIT, source->scale)>>FRACBITS, FixedMul(7*FRACUNIT, source->scale)>>FRACBITS)*FRACUNIT; - truc = P_SpawnMobj(source->x + P_RandomRange(-radius, radius)*FRACUNIT, - source->y + P_RandomRange(-radius, radius)*FRACUNIT, - source->z + P_RandomRange(0, height)*FRACUNIT, MT_BOOMPARTICLE); + truc = P_SpawnMobj(source->x + P_RandomRange(PR_UNDEFINED, -radius, radius)*FRACUNIT, + source->y + P_RandomRange(PR_UNDEFINED, -radius, radius)*FRACUNIT, + source->z + P_RandomRange(PR_UNDEFINED, 0, height)*FRACUNIT, MT_BOOMPARTICLE); K_MatchGenericExtraFlags(truc, source); P_SetScale(truc, source->scale); truc->destscale = source->scale*5; truc->scalespeed = source->scale/12; speed = FixedMul(20*FRACUNIT, source->scale)>>FRACBITS; - truc->momx = P_RandomRange(-speed, speed)*FRACUNIT; - truc->momy = P_RandomRange(-speed, speed)*FRACUNIT; + truc->momx = P_RandomRange(PR_UNDEFINED, -speed, speed)*FRACUNIT; + truc->momy = P_RandomRange(PR_UNDEFINED, -speed, speed)*FRACUNIT; speed = FixedMul(15*FRACUNIT, source->scale)>>FRACBITS; speed2 = FixedMul(45*FRACUNIT, source->scale)>>FRACBITS; - truc->momz = P_RandomRange(speed, speed2)*FRACUNIT*P_MobjFlip(truc); - if (P_RandomChance(FRACUNIT/2)) + truc->momz = P_RandomRange(PR_UNDEFINED, speed, speed2)*FRACUNIT*P_MobjFlip(truc); + if (P_RandomChance(PR_UNDEFINED, FRACUNIT/2)) truc->momz = -truc->momz; if (truc->eflags & MFE_UNDERWATER) truc->momz = (117 * truc->momz) / 200; @@ -4798,9 +4798,9 @@ void K_SpawnSparkleTrail(mobj_t *mo) //CONS_Printf("%d\n", index); - newx = mo->x + (P_RandomRange(-rad, rad)*FRACUNIT); - newy = mo->y + (P_RandomRange(-rad, rad)*FRACUNIT); - newz = mo->z + (P_RandomRange(0, mo->height>>FRACBITS)*FRACUNIT); + newx = mo->x + (P_RandomRange(PR_UNDEFINED, -rad, rad)*FRACUNIT); + newy = mo->y + (P_RandomRange(PR_UNDEFINED, -rad, rad)*FRACUNIT); + newz = mo->z + (P_RandomRange(PR_UNDEFINED, 0, mo->height>>FRACBITS)*FRACUNIT); sparkle = P_SpawnMobj(newx, newy, newz, MT_SPARKLETRAIL); @@ -4810,8 +4810,8 @@ void K_SpawnSparkleTrail(mobj_t *mo) //CONS_Printf("movefactor: %d\n", sparkle->movefactor/FRACUNIT); sparkle->extravalue1 = (sparkle->z - mo->z); // Keep track of our Z position relative to the player's, I suppose. - sparkle->extravalue2 = P_RandomRange(0, 1) ? 1 : -1; // Rotation direction? - sparkle->cvmem = P_RandomRange(-25, 25)*mo->scale; // Vertical "angle" + sparkle->extravalue2 = P_RandomRange(PR_UNDEFINED, 0, 1) ? 1 : -1; // Rotation direction? + sparkle->cvmem = P_RandomRange(PR_UNDEFINED, -25, 25)*mo->scale; // Vertical "angle" K_FlipFromObject(sparkle, mo); P_SetTarget(&sparkle->target, mo); @@ -4849,8 +4849,8 @@ void K_SpawnWipeoutTrail(mobj_t *mo) else aoff += ANGLE_45; - dust = P_SpawnMobj(mo->x + FixedMul(24*mo->scale, FINECOSINE(aoff>>ANGLETOFINESHIFT)) + (P_RandomRange(-8,8) << FRACBITS), - mo->y + FixedMul(24*mo->scale, FINESINE(aoff>>ANGLETOFINESHIFT)) + (P_RandomRange(-8,8) << FRACBITS), + dust = P_SpawnMobj(mo->x + FixedMul(24*mo->scale, FINECOSINE(aoff>>ANGLETOFINESHIFT)) + (P_RandomRange(PR_UNDEFINED,-8,8) << FRACBITS), + mo->y + FixedMul(24*mo->scale, FINESINE(aoff>>ANGLETOFINESHIFT)) + (P_RandomRange(PR_UNDEFINED,-8,8) << FRACBITS), mo->z, MT_WIPEOUTTRAIL); P_SetTarget(&dust->target, mo); @@ -4988,13 +4988,13 @@ void K_DriftDustHandling(mobj_t *spawner) if (anglediff > ANG10*4) // Trying to turn further than 40 degrees { - fixed_t spawnx = P_RandomRange(-spawnrange, spawnrange) << FRACBITS; - fixed_t spawny = P_RandomRange(-spawnrange, spawnrange) << FRACBITS; + fixed_t spawnx = P_RandomRange(PR_UNDEFINED, -spawnrange, spawnrange) << FRACBITS; + fixed_t spawny = P_RandomRange(PR_UNDEFINED, -spawnrange, spawnrange) << FRACBITS; INT32 speedrange = 2; mobj_t *dust = P_SpawnMobj(spawner->x + spawnx, spawner->y + spawny, spawner->z, MT_DRIFTDUST); - dust->momx = FixedMul(spawner->momx + (P_RandomRange(-speedrange, speedrange) * spawner->scale), 3*FRACUNIT/4); - dust->momy = FixedMul(spawner->momy + (P_RandomRange(-speedrange, speedrange) * spawner->scale), 3*FRACUNIT/4); - dust->momz = P_MobjFlip(spawner) * (P_RandomRange(1, 4) * (spawner->scale)); + dust->momx = FixedMul(spawner->momx + (P_RandomRange(PR_UNDEFINED, -speedrange, speedrange) * spawner->scale), 3*FRACUNIT/4); + dust->momy = FixedMul(spawner->momy + (P_RandomRange(PR_UNDEFINED, -speedrange, speedrange) * spawner->scale), 3*FRACUNIT/4); + dust->momz = P_MobjFlip(spawner) * (P_RandomRange(PR_UNDEFINED, 1, 4) * (spawner->scale)); P_SetScale(dust, spawner->scale/2); dust->destscale = spawner->scale * 3; dust->scalespeed = spawner->scale/12; @@ -5456,8 +5456,8 @@ static void K_DoLightningShield(player_t *player) for (i=0; i<7; i++) { mo = P_SpawnMobj(player->mo->x, player->mo->y, player->mo->z, MT_THOK); - P_InitAngle(mo, P_RandomRange(0, 359)*ANG1); - mo->fuse = P_RandomRange(20, 50); + P_InitAngle(mo, P_RandomRange(PR_UNDEFINED, 0, 359)*ANG1); + mo->fuse = P_RandomRange(PR_UNDEFINED, 20, 50); P_SetTarget(&mo->target, player->mo); P_SetMobjState(mo, S_KLIT1); } @@ -5496,8 +5496,8 @@ static void K_FlameDashLeftoverSmoke(mobj_t *src) smoke->momy = 3*src->momy/4; smoke->momz = 3*P_GetMobjZMovement(src)/4; - P_Thrust(smoke, src->angle + FixedAngle(P_RandomRange(135, 225)<scale); - smoke->momz += P_RandomRange(0, 4) * src->scale; + P_Thrust(smoke, src->angle + FixedAngle(P_RandomRange(PR_UNDEFINED, 135, 225)<scale); + smoke->momz += P_RandomRange(PR_UNDEFINED, 0, 4) * src->scale; } } @@ -5508,7 +5508,7 @@ static void K_DoHyudoroSteal(player_t *player) INT32 playerswappable[MAXPLAYERS]; INT32 stealplayer = -1; // The player that's getting stolen from INT32 prandom = 0; - boolean sink = P_RandomChance(FRACUNIT/64); + boolean sink = P_RandomChance(PR_UNDEFINED, FRACUNIT/64); INT32 hyu = hyudorotime; if (gametype == GT_RACE) @@ -5533,7 +5533,7 @@ static void K_DoHyudoroSteal(player_t *player) } } - prandom = P_RandomFixed(); + prandom = P_RandomFixed(PR_UNDEFINED); S_StartSound(player->mo, sfx_s3k92); if (sink && numplayers > 0 && cv_kitchensink.value) // BEHOLD THE KITCHEN SINK @@ -6079,7 +6079,7 @@ mobj_t *K_CreatePaperItem(fixed_t x, fixed_t y, fixed_t z, angle_t angle, SINT8 P_InitAngle(drop, angle); P_Thrust(drop, - FixedAngle(P_RandomFixed() * 180) + angle, + FixedAngle(P_RandomFixed(PR_UNDEFINED) * 180) + angle, 16*mapobjectscale); drop->momz = flip * 3 * mapobjectscale; @@ -6113,7 +6113,7 @@ mobj_t *K_CreatePaperItem(fixed_t x, fixed_t y, fixed_t z, angle_t angle, SINT8 UINT8 newType; UINT8 newAmount; - totalspawnchance = P_RandomKey(totalspawnchance); + totalspawnchance = P_RandomKey(PR_UNDEFINED, totalspawnchance); for (i = 0; i < NUMKARTRESULTS && spawnchance[i] <= totalspawnchance; i++); // TODO: this is bad! @@ -6635,7 +6635,7 @@ static void K_MoveHeldObjects(player_t *player) /* if (P_IsObjectOnGround(player->mo) && player->speed > 0 && player->bananadrag > TICRATE - && P_RandomChance(min(FRACUNIT/2, FixedDiv(player->speed, K_GetKartSpeed(player, false, false))/2))) + && P_RandomChance(PR_UNDEFINED, min(FRACUNIT/2, FixedDiv(player->speed, K_GetKartSpeed(player, false, false))/2))) { if (leveltime & 1) targz += 8*(2*FRACUNIT)/7; @@ -7213,7 +7213,7 @@ static inline BlockItReturn_t PIT_AttractingRings(mobj_t *thing) thing->info = &mobjinfo[thing->type]; thing->flags = thing->info->flags; - P_InstaThrust(thing, P_RandomRange(0,7) * ANGLE_45, 2 * thing->scale); + P_InstaThrust(thing, P_RandomRange(PR_UNDEFINED,0,7) * ANGLE_45, 2 * thing->scale); P_SetObjectMomZ(thing, 8<fuse = 120*TICRATE; @@ -7410,9 +7410,9 @@ void K_KartPlayerThink(player_t *player, ticcmd_t *cmd) if (player->springstars && (leveltime & 1)) { - fixed_t randx = P_RandomRange(-40, 40) * player->mo->scale; - fixed_t randy = P_RandomRange(-40, 40) * player->mo->scale; - fixed_t randz = P_RandomRange(0, player->mo->height >> FRACBITS) << FRACBITS; + fixed_t randx = P_RandomRange(PR_UNDEFINED, -40, 40) * player->mo->scale; + fixed_t randy = P_RandomRange(PR_UNDEFINED, -40, 40) * player->mo->scale; + fixed_t randz = P_RandomRange(PR_UNDEFINED, 0, player->mo->height >> FRACBITS) << FRACBITS; mobj_t *star = P_SpawnMobj( player->mo->x + randx, player->mo->y + randy, @@ -9142,8 +9142,8 @@ void K_KartEbrakeVisuals(player_t *p) if (!p->spindash) { // Spawn downwards fastline - sx = p->mo->x + P_RandomRange(-48, 48)*p->mo->scale; - sy = p->mo->y + P_RandomRange(-48, 48)*p->mo->scale; + sx = p->mo->x + P_RandomRange(PR_UNDEFINED, -48, 48)*p->mo->scale; + sy = p->mo->y + P_RandomRange(PR_UNDEFINED, -48, 48)*p->mo->scale; spdl = P_SpawnMobj(sx, sy, p->mo->z, MT_DOWNLINE); spdl->colorized = true; @@ -9225,8 +9225,8 @@ static void K_KartSpindashDust(mobj_t *parent) for (i = 0; i < 2; i++) { - fixed_t hmomentum = P_RandomRange(6, 12) * parent->scale; - fixed_t vmomentum = P_RandomRange(2, 6) * parent->scale; + fixed_t hmomentum = P_RandomRange(PR_UNDEFINED, 6, 12) * parent->scale; + fixed_t vmomentum = P_RandomRange(PR_UNDEFINED, 2, 6) * parent->scale; angle_t ang = parent->player->drawangle + ANGLE_180; SINT8 flip = 1; @@ -9254,9 +9254,9 @@ static void K_KartSpindashDust(mobj_t *parent) static void K_KartSpindashWind(mobj_t *parent) { mobj_t *wind = P_SpawnMobjFromMobj(parent, - P_RandomRange(-36,36) * FRACUNIT, - P_RandomRange(-36,36) * FRACUNIT, - FixedDiv(parent->height / 2, parent->scale) + (P_RandomRange(-20,20) * FRACUNIT), + P_RandomRange(PR_UNDEFINED,-36,36) * FRACUNIT, + P_RandomRange(PR_UNDEFINED,-36,36) * FRACUNIT, + FixedDiv(parent->height / 2, parent->scale) + (P_RandomRange(PR_UNDEFINED,-20,20) * FRACUNIT), MT_SPINDASHWIND ); @@ -10386,9 +10386,9 @@ void K_MoveKartPlayer(player_t *player, boolean onground) { for (n=0; n < maxlines; n++) { - sx = player->mo->x + P_RandomRange(-24, 24)*player->mo->scale; - sy = player->mo->y + P_RandomRange(-24, 24)*player->mo->scale; - sz = player->mo->z + P_RandomRange(0, 48)*player->mo->scale; + sx = player->mo->x + P_RandomRange(PR_UNDEFINED, -24, 24)*player->mo->scale; + sy = player->mo->y + P_RandomRange(PR_UNDEFINED, -24, 24)*player->mo->scale; + sz = player->mo->z + P_RandomRange(PR_UNDEFINED, 0, 48)*player->mo->scale; spdl = P_SpawnMobj(sx, sy, sz, MT_FASTLINE); P_SetTarget(&spdl->target, player->mo); diff --git a/src/k_menufunc.c b/src/k_menufunc.c index 753a9b767..083749e73 100644 --- a/src/k_menufunc.c +++ b/src/k_menufunc.c @@ -4205,17 +4205,17 @@ void M_ServerListFillDebug(void) serverlist[i].info.numberofplayer = min(i, 8); serverlist[i].info.maxplayer = 8; - serverlist[i].info.avgpwrlv = P_RandomRange(500, 1500); - serverlist[i].info.time = P_RandomRange(16, 500); // ping + serverlist[i].info.avgpwrlv = P_RandomRange(PR_UNDEFINED, 500, 1500); + serverlist[i].info.time = P_RandomRange(PR_UNDEFINED, 1, 8); // ping strcpy(serverlist[i].info.servername, va("Serv %d", i+1)); strcpy(serverlist[i].info.gametypename, i & 1 ? "Race" : "Battle"); - P_RandomRange(0, 5); // change results... - serverlist[i].info.kartvars = P_RandomRange(0, 3) & SV_SPEEDMASK; + P_RandomRange(PR_UNDEFINED, 0, 5); // change results... + serverlist[i].info.kartvars = P_RandomRange(PR_UNDEFINED, 0, 3) & SV_SPEEDMASK; - serverlist[i].info.modifiedgame = P_RandomRange(0, 1); + serverlist[i].info.modifiedgame = P_RandomRange(PR_UNDEFINED, 0, 1); CONS_Printf("Serv %d | %d...\n", i, serverlist[i].info.modifiedgame); } diff --git a/src/k_pwrlv.c b/src/k_pwrlv.c index d699db2b5..17252acbf 100644 --- a/src/k_pwrlv.c +++ b/src/k_pwrlv.c @@ -515,26 +515,26 @@ void K_SetPowerLevelScrambles(SINT8 powertype) { case 5: speed = KARTSPEED_HARD; - encore = P_RandomChance(FRACUNIT>>1); + encore = P_RandomChance(PR_UNDEFINED, FRACUNIT>>1); break; case 4: - speed = P_RandomChance((7<>1); + speed = P_RandomChance(PR_UNDEFINED, (7<>1); break; case 3: - speed = P_RandomChance((3<>2); + speed = P_RandomChance(PR_UNDEFINED, (3<>2); break; case 2: speed = KARTSPEED_NORMAL; - encore = P_RandomChance(FRACUNIT>>3); + encore = P_RandomChance(PR_UNDEFINED, FRACUNIT>>3); break; case 1: default: speed = KARTSPEED_NORMAL; encore = false; break; case 0: - speed = P_RandomChance((3<frequency) / 2) & 1) { tireAngle -= ANGLE_45; - tireAngle -= P_RandomRange(0, fs->cone / ANG1) * ANG1; - pushAngle -= P_RandomRange(0, fs->cone / ANG1) * ANG1; + tireAngle -= P_RandomRange(PR_UNDEFINED, 0, fs->cone / ANG1) * ANG1; + pushAngle -= P_RandomRange(PR_UNDEFINED, 0, fs->cone / ANG1) * ANG1; } else { tireAngle += ANGLE_45; - tireAngle += P_RandomRange(0, fs->cone / ANG1) * ANG1; - pushAngle += P_RandomRange(0, fs->cone / ANG1) * ANG1; + tireAngle += P_RandomRange(PR_UNDEFINED, 0, fs->cone / ANG1) * ANG1; + pushAngle += P_RandomRange(PR_UNDEFINED, 0, fs->cone / ANG1) * ANG1; } if (fs->spread > 0) { - xOff = P_RandomRange(-fs->spread / FRACUNIT, fs->spread / FRACUNIT) * FRACUNIT; - yOff = P_RandomRange(-fs->spread / FRACUNIT, fs->spread / FRACUNIT) * FRACUNIT; + xOff = P_RandomRange(PR_UNDEFINED, -fs->spread / FRACUNIT, fs->spread / FRACUNIT) * FRACUNIT; + yOff = P_RandomRange(PR_UNDEFINED, -fs->spread / FRACUNIT, fs->spread / FRACUNIT) * FRACUNIT; } dust = P_SpawnMobjFromMobj( diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 190a7f701..ed6b395fb 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -398,10 +398,13 @@ static int lib_mMapNumber(lua_State *L) // M_RANDOM ////////////// +// TODO: Lua needs a way to set RNG class, which will break compatibility. +// It will be more desireable to do it when RNG classes can be freeslotted. + static int lib_pRandomFixed(lua_State *L) { NOHUD - lua_pushfixed(L, P_RandomFixed()); + lua_pushfixed(L, P_RandomFixed(PR_UNDEFINED)); demo_writerng = 2; return 1; } @@ -409,7 +412,7 @@ static int lib_pRandomFixed(lua_State *L) static int lib_pRandomByte(lua_State *L) { NOHUD - lua_pushinteger(L, P_RandomByte()); + lua_pushinteger(L, P_RandomByte(PR_UNDEFINED)); demo_writerng = 2; return 1; } @@ -421,7 +424,7 @@ static int lib_pRandomKey(lua_State *L) NOHUD if (a > 65536) LUA_UsageWarning(L, "P_RandomKey: range > 65536 is undefined behavior"); - lua_pushinteger(L, P_RandomKey(a)); + lua_pushinteger(L, P_RandomKey(PR_UNDEFINED, a)); demo_writerng = 2; return 1; } @@ -439,7 +442,7 @@ static int lib_pRandomRange(lua_State *L) } if ((b-a+1) > 65536) LUA_UsageWarning(L, "P_RandomRange: range > 65536 is undefined behavior"); - lua_pushinteger(L, P_RandomRange(a, b)); + lua_pushinteger(L, P_RandomRange(PR_UNDEFINED, a, b)); demo_writerng = 2; return 1; } @@ -448,7 +451,7 @@ static int lib_pRandomRange(lua_State *L) static int lib_pSignedRandom(lua_State *L) { NOHUD - lua_pushinteger(L, P_SignedRandom()); + lua_pushinteger(L, P_SignedRandom(PR_UNDEFINED)); demo_writerng = 2; return 1; } @@ -457,7 +460,7 @@ static int lib_pRandomChance(lua_State *L) { fixed_t p = luaL_checkfixed(L, 1); NOHUD - lua_pushboolean(L, P_RandomChance(p)); + lua_pushboolean(L, P_RandomChance(PR_UNDEFINED, p)); demo_writerng = 2; return 1; } diff --git a/src/m_cheat.c b/src/m_cheat.c index 5eddbce4a..4a135a53c 100644 --- a/src/m_cheat.c +++ b/src/m_cheat.c @@ -682,9 +682,9 @@ void Command_CauseCfail_f(void) } P_UnsetThingPosition(players[consoleplayer].mo); - P_RandomFixed(); - P_RandomByte(); - P_RandomFixed(); + P_RandomFixed(PR_UNDEFINED); + P_RandomByte(PR_UNDEFINED); + P_RandomFixed(PR_UNDEFINED); players[consoleplayer].mo->x = 0; players[consoleplayer].mo->y = 123311; //cfail cansuled kthxbye players[consoleplayer].mo->z = 123311; diff --git a/src/m_random.c b/src/m_random.c index 481fdb72b..8a59db7c1 100644 --- a/src/m_random.c +++ b/src/m_random.c @@ -82,23 +82,27 @@ INT32 M_RandomRange(INT32 a, INT32 b) // PRNG functions (synched) // ------------------------ -// Holds the current seed. -static UINT32 randomseed = 0xBADE4404; +#define DEFAULT_SEED (0xBADE4404) -// Holds the INITIAL seed value. Used for demos, possibly other debugging. -static UINT32 initialseed = 0xBADE4404; +typedef struct +{ + UINT32 seed[PRNUMCLASS]; // Holds each block's current seed. + UINT32 init[PRNUMCLASS]; // Holds the INITIAL seed value. Used for demos, possibly other debugging +} rng_t; + +static rng_t rng; // The entire PRNG state /** Provides a random fixed point number. * This is a variant of an xorshift PRNG; state fits in a 32 bit integer structure. * * \return A random fixed point number from [0,1). */ -ATTRINLINE static fixed_t FUNCINLINE __internal_prng__(void) +ATTRINLINE static fixed_t FUNCINLINE __internal_prng__(pr_class_t pr_class) { - randomseed ^= randomseed >> 13; - randomseed ^= randomseed >> 11; - randomseed ^= randomseed << 21; - return ( (randomseed*36548569) >> 4) & (FRACUNIT-1); + rng.seed[pr_class] ^= rng.seed[pr_class] >> 13; + rng.seed[pr_class] ^= rng.seed[pr_class] >> 11; + rng.seed[pr_class] ^= rng.seed[pr_class] << 21; + return ( (rng.seed[pr_class] * 36548569) >> 4) & (FRACUNIT-1); } /** Provides a random fixed point number. Distribution is uniform. @@ -107,14 +111,14 @@ ATTRINLINE static fixed_t FUNCINLINE __internal_prng__(void) * \return A random fixed point number from [0,1). */ #ifndef DEBUGRANDOM -fixed_t P_RandomFixed(void) +fixed_t P_RandomFixed(pr_class_t pr_class) { #else -fixed_t P_RandomFixedD(const char *rfile, INT32 rline) +fixed_t P_RandomFixedD(const char *rfile, INT32 rline, pr_class_t pr_class) { - CONS_Printf("P_RandomFixed() at: %sp %d\n", rfile, rline); + CONS_Printf("P_RandomFixed(%u) at: %sp %d\n", pr_class, rfile, rline); #endif - return __internal_prng__(); + return __internal_prng__(pr_class); } /** Provides a random byte. Distribution is uniform. @@ -125,14 +129,14 @@ fixed_t P_RandomFixedD(const char *rfile, INT32 rline) * \sa __internal_prng__ */ #ifndef DEBUGRANDOM -UINT8 P_RandomByte(void) +UINT8 P_RandomByte(pr_class_t pr_class) { #else -UINT8 P_RandomByteD(const char *rfile, INT32 rline) +UINT8 P_RandomByteD(const char *rfile, INT32 rline, pr_class_t pr_class) { - CONS_Printf("P_RandomByte() at: %sp %d\n", rfile, rline); + CONS_Printf("P_RandomByte(%u) at: %sp %d\n", pr_class, rfile, rline); #endif - return (UINT8)((__internal_prng__()&0xFF00)>>8); + return (UINT8)((__internal_prng__(pr_class) & 0xFF00) >> 8); } /** Provides a random integer for picking random elements from an array. @@ -144,14 +148,14 @@ UINT8 P_RandomByteD(const char *rfile, INT32 rline) * \sa __internal_prng__ */ #ifndef DEBUGRANDOM -INT32 P_RandomKey(INT32 a) +INT32 P_RandomKey(pr_class_t pr_class, INT32 a) { #else -INT32 P_RandomKeyD(const char *rfile, INT32 rline, INT32 a) +INT32 P_RandomKeyD(const char *rfile, INT32 rline, pr_class_t pr_class, INT32 a) { - CONS_Printf("P_RandomKey() at: %sp %d\n", rfile, rline); + CONS_Printf("P_RandomKey(%u) at: %sp %d\n", pr_class, rfile, rline); #endif - return (INT32)(((INT64)__internal_prng__() * a) >> FRACBITS); + return (INT32)(((INT64)__internal_prng__(pr_class) * a) >> FRACBITS); } /** Provides a random integer in a given range. @@ -164,14 +168,14 @@ INT32 P_RandomKeyD(const char *rfile, INT32 rline, INT32 a) * \sa __internal_prng__ */ #ifndef DEBUGRANDOM -INT32 P_RandomRange(INT32 a, INT32 b) +INT32 P_RandomRange(pr_class_t pr_class, INT32 a, INT32 b) { #else -INT32 P_RandomRangeD(const char *rfile, INT32 rline, INT32 a, INT32 b) +INT32 P_RandomRangeD(const char *rfile, INT32 rline, pr_class_t pr_class, INT32 a, INT32 b) { - CONS_Printf("P_RandomRange() at: %sp %d\n", rfile, rline); + CONS_Printf("P_RandomRange(%u) at: %sp %d\n", pr_class, rfile, rline); #endif - return (INT32)(((INT64)__internal_prng__() * (b-a+1)) >> FRACBITS) + a; + return (INT32)(((INT64)__internal_prng__(pr_class) * (b - a + 1)) >> FRACBITS) + a; } @@ -186,11 +190,11 @@ INT32 P_RandomRangeD(const char *rfile, INT32 rline, INT32 a, INT32 b) * \return A 'random' fixed point number from [0,1). * \sa __internal_prng__ */ -fixed_t P_RandomPeek(void) +fixed_t P_RandomPeek(pr_class_t pr_class) { - UINT32 r = randomseed; - fixed_t ret = __internal_prng__(); - randomseed = r; + UINT32 r = rng.seed[pr_class]; + fixed_t ret = __internal_prng__(pr_class); + rng.seed[pr_class] = r; return ret; } @@ -200,14 +204,14 @@ fixed_t P_RandomPeek(void) * \sa P_SetRandSeed */ #ifndef DEBUGRANDOM -UINT32 P_GetRandSeed(void) +UINT32 P_GetRandSeed(pr_class_t pr_class) { #else -UINT32 P_GetRandSeedD(const char *rfile, INT32 rline) +UINT32 P_GetRandSeedD(const char *rfile, INT32 rline, pr_class_t pr_class) { - CONS_Printf("P_GetRandSeed() at: %sp %d\n", rfile, rline); + CONS_Printf("P_GetRandSeed(%u) at: %sp %d\n", pr_class, rfile, rline); #endif - return randomseed; + return rng.seed[pr_class]; } /** Gets the initial random seed. Used by demos. @@ -216,34 +220,59 @@ UINT32 P_GetRandSeedD(const char *rfile, INT32 rline) * \sa P_SetRandSeed */ #ifndef DEBUGRANDOM -UINT32 P_GetInitSeed(void) +UINT32 P_GetInitSeed(pr_class_t pr_class) { #else -UINT32 P_GetInitSeedD(const char *rfile, INT32 rline) +UINT32 P_GetInitSeedD(const char *rfile, INT32 rline, pr_class_t pr_class) { - CONS_Printf("P_GetInitSeed() at: %sp %d\n", rfile, rline); + CONS_Printf("P_GetInitSeed(%u) at: %sp %d\n", pr_class, rfile, rline); #endif - return initialseed; + return rng.init[pr_class]; } /** Sets the random seed. * Used at the beginning of the game, and also for netgames. * - * \param rindex New random index. + * \param pr_class RNG class to adjust. + * \param seed New random seed. * \sa P_GetRandSeed */ #ifndef DEBUGRANDOM -void P_SetRandSeed(UINT32 seed) +void P_SetRandSeed(pr_class_t pr_class, UINT32 seed) { #else -void P_SetRandSeedD(const char *rfile, INT32 rline, UINT32 seed) +void P_SetRandSeedD(const char *rfile, INT32 rline, pr_class_t pr_class, UINT32 seed) { - CONS_Printf("P_SetRandSeed() at: %sp %d\n", rfile, rline); + CONS_Printf("P_SetRandSeed(%u) at: %sp %d\n", pr_class, rfile, rline); #endif // xorshift requires a nonzero seed // this should never happen, but just in case it DOES, we check - if (!seed) seed = 0xBADE4404; - randomseed = initialseed = seed; + if (!seed) seed = DEFAULT_SEED; + rng.seed[pr_class] = rng.init[pr_class] = seed; +} + +/** Initializes random seeds for all classes. + * Used at the beginning of the game. + * + * \param rindex New random index. + * \sa P_SetRandSeed + */ +void P_ClearRandom(UINT32 seed) +{ + size_t i; + + if (!seed) seed = DEFAULT_SEED; + + for (i = 0; i < PRNUMCLASS; i++) + { + P_SetRandSeed(i, seed); + + // Different XOR from __internal_prng__ + // so that it's not as predictable. + seed ^= seed >> 13; + seed ^= seed << 25; + seed ^= seed >> 11; + } } /** Gets a randomized seed for setting the random seed. @@ -252,5 +281,5 @@ void P_SetRandSeedD(const char *rfile, INT32 rline, UINT32 seed) */ UINT32 M_RandomizedSeed(void) { - return ((totalplaytime & 0xFFFF) << 16)|M_RandomFixed(); + return ((totalplaytime & 0xFFFF) << 16) | M_RandomFixed(); } diff --git a/src/m_random.h b/src/m_random.h index 01190e046..c811fa87e 100644 --- a/src/m_random.h +++ b/src/m_random.h @@ -20,6 +20,11 @@ //#define DEBUGRANDOM +typedef enum +{ + PR_UNDEFINED, // Before release, cases of this RNG class should be removed, only kept as the default for Lua. + PRNUMCLASS +} pr_class_t; // M_Random functions pull random numbers of various types that aren't network synced. // P_Random functions pulls random bytes from a PRNG that is network synced. @@ -32,44 +37,46 @@ INT32 M_RandomRange(INT32 a, INT32 b); // PRNG functions #ifdef DEBUGRANDOM -#define P_RandomFixed() P_RandomFixedD(__FILE__, __LINE__) -#define P_RandomByte() P_RandomByteD(__FILE__, __LINE__) -#define P_RandomKey(c) P_RandomKeyD(__FILE__, __LINE__, c) -#define P_RandomRange(c, d) P_RandomRangeD(__FILE__, __LINE__, c, d) -fixed_t P_RandomFixedD(const char *rfile, INT32 rline); -UINT8 P_RandomByteD(const char *rfile, INT32 rline); -INT32 P_RandomKeyD(const char *rfile, INT32 rline, INT32 a); -INT32 P_RandomRangeD(const char *rfile, INT32 rline, INT32 a, INT32 b); +#define P_RandomFixed(c) P_RandomFixedD(__FILE__, __LINE__, c) +#define P_RandomByte(c) P_RandomByteD(__FILE__, __LINE__, c) +#define P_RandomKey(c, d) P_RandomKeyD(__FILE__, __LINE__, c, d) +#define P_RandomRange(c, d, e) P_RandomRangeD(__FILE__, __LINE__, c, d, e) +fixed_t P_RandomFixedD(const char *rfile, INT32 rline, pr_class_t pr_class); +UINT8 P_RandomByteD(const char *rfile, INT32 rline, pr_class_t pr_class); +INT32 P_RandomKeyD(const char *rfile, INT32 rline, pr_class_t pr_class, INT32 a); +INT32 P_RandomRangeD(const char *rfile, INT32 rline, pr_class_t pr_class, INT32 a, INT32 b); #else -fixed_t P_RandomFixed(void); -UINT8 P_RandomByte(void); -INT32 P_RandomKey(INT32 a); -INT32 P_RandomRange(INT32 a, INT32 b); +fixed_t P_RandomFixed(pr_class_t pr_class); +UINT8 P_RandomByte(pr_class_t pr_class); +INT32 P_RandomKey(pr_class_t pr_class, INT32 a); +INT32 P_RandomRange(pr_class_t pr_class, INT32 a, INT32 b); #endif // Macros for other functions #define M_SignedRandom() ((INT32)M_RandomByte() - 128) // [-128, 127] signed byte, originally a -#define P_SignedRandom() ((INT32)P_RandomByte() - 128) // function of its own, moved to a macro +#define P_SignedRandom(pr) ((INT32)P_RandomByte(pr) - 128) // function of its own, moved to a macro #define M_RandomChance(p) (M_RandomFixed() < p) // given fixed point probability, p, between 0 (0%) -#define P_RandomChance(p) (P_RandomFixed() < p) // and FRACUNIT (100%), returns true p% of the time +#define P_RandomChance(pr, p) (P_RandomFixed(pr) < p) // and FRACUNIT (100%), returns true p% of the time // Debugging -fixed_t P_RandomPeek(void); +fixed_t P_RandomPeek(pr_class_t pr_class); // Working with the seed for PRNG #ifdef DEBUGRANDOM -#define P_GetRandSeed() P_GetRandSeedD(__FILE__, __LINE__) -#define P_GetInitSeed() P_GetInitSeedD(__FILE__, __LINE__) -#define P_SetRandSeed(s) P_SetRandSeedD(__FILE__, __LINE__, s) -UINT32 P_GetRandSeedD(const char *rfile, INT32 rline); -UINT32 P_GetInitSeedD(const char *rfile, INT32 rline); -void P_SetRandSeedD(const char *rfile, INT32 rline, UINT32 seed); +#define P_GetRandSeed(pr) P_GetRandSeedD(__FILE__, __LINE__, pr) +#define P_GetInitSeed(pr) P_GetInitSeedD(__FILE__, __LINE__, pr) +#define P_SetRandSeed(pr, s) P_SetRandSeedD(__FILE__, __LINE__, pr, s) +UINT32 P_GetRandSeedD(const char *rfile, INT32 rline, pr_class_t pr_class); +UINT32 P_GetInitSeedD(const char *rfile, INT32 rline, pr_class_t pr_class); +void P_SetRandSeedD(const char *rfile, INT32 rline, pr_class_t pr_class, UINT32 seed); #else -UINT32 P_GetRandSeed(void); -UINT32 P_GetInitSeed(void); -void P_SetRandSeed(UINT32 seed); +UINT32 P_GetRandSeed(pr_class_t pr_class); +UINT32 P_GetInitSeed(pr_class_t pr_class); +void P_SetRandSeed(pr_class_t pr_class, UINT32 seed); #endif + +void P_ClearRandom(UINT32 seed); UINT32 M_RandomizedSeed(void); #endif diff --git a/src/objects/shrink.c b/src/objects/shrink.c index 241164aa7..38e510a7b 100644 --- a/src/objects/shrink.c +++ b/src/objects/shrink.c @@ -332,8 +332,8 @@ static void ShrinkLaserThinker(mobj_t *pohbee, mobj_t *gun, mobj_t *laser) particle = P_SpawnMobjFromMobj( laser, - P_RandomRange(-16, 16) * FRACUNIT, - P_RandomRange(-16, 16) * FRACUNIT, + P_RandomRange(PR_UNDEFINED, -16, 16) * FRACUNIT, + P_RandomRange(PR_UNDEFINED, -16, 16) * FRACUNIT, 0, MT_SHRINK_PARTICLE ); @@ -694,7 +694,7 @@ static void CreatePohbee(player_t *owner, waypoint_t *start, waypoint_t *end, UI P_SetTarget(&pohbee_guns(prevGun), gun); gun_numsegs(gun) = numSegs; - gun_offset(gun) = P_RandomKey(GUN_SWINGTIME); + gun_offset(gun) = P_RandomKey(PR_UNDEFINED, GUN_SWINGTIME); overlay = P_SpawnMobjFromMobj(gun, 0, 0, 0, MT_OVERLAY); diff --git a/src/p_enemy.c b/src/p_enemy.c index d5f999624..c33c87cca 100644 --- a/src/p_enemy.c +++ b/src/p_enemy.c @@ -478,7 +478,7 @@ boolean P_CheckMissileRange(mobj_t *actor) if (actor->type == MT_EGGMOBILE && dist > 160) dist = 160; - if (P_RandomByte() < dist) + if (P_RandomByte(PR_UNDEFINED) < dist) return false; return true; @@ -575,7 +575,7 @@ static boolean P_TryWalk(mobj_t *actor) { if (!P_Move(actor, actor->info->speed)) return false; - actor->movecount = P_RandomByte() & 15; + actor->movecount = P_RandomByte(PR_UNDEFINED) & 15; return true; } @@ -626,7 +626,7 @@ void P_NewChaseDir(mobj_t *actor) } // try other directions - if (P_RandomChance(25*FRACUNIT/32) || abs(deltay) > abs(deltax)) + if (P_RandomChance(PR_UNDEFINED, 25*FRACUNIT/32) || abs(deltay) > abs(deltax)) { tdir = d[1]; d[1] = d[2]; @@ -664,7 +664,7 @@ void P_NewChaseDir(mobj_t *actor) } // randomly determine direction of search - if (P_RandomChance(FRACUNIT/2)) + if (P_RandomChance(PR_UNDEFINED, FRACUNIT/2)) { for (tdir = DI_EAST; tdir <= DI_SOUTHEAST; tdir++) { @@ -719,7 +719,7 @@ boolean P_LookForPlayers(mobj_t *actor, boolean allaround, boolean tracer, fixed // BP: first time init, this allow minimum lastlook changes if (actor->lastlook < 0) - actor->lastlook = P_RandomByte(); + actor->lastlook = P_RandomByte(PR_UNDEFINED); actor->lastlook %= MAXPLAYERS; @@ -1013,7 +1013,7 @@ static void P_SharpDust(mobj_t *actor, mobjtype_t type, angle_t ang) -P_ReturnThrustX(actor, ang, 16<z, actor->height); dust = P_SpawnMobj(px, py, pz, MT_ARIDDUST); - P_SetMobjState(dust, (statenum_t)(dust->state - states + P_RandomRange(0, 2))); + P_SetMobjState(dust, (statenum_t)(dust->state - states + P_RandomRange(PR_UNDEFINED, 0, 2))); P_Thrust(dust, angle, FixedDiv(12*FRACUNIT, max(FRACUNIT, fdist/2))); dust->momx += actor->momx; dust->momy += actor->momy; @@ -2298,7 +2298,7 @@ void A_VultureFly(mobj_t *actor) P_VultureHoverParticle(actor); - dust = P_SpawnMobj(actor->x + P_RandomFixed() - FRACUNIT/2, actor->y + P_RandomFixed() - FRACUNIT/2, actor->z + actor->height/2 + P_RandomFixed() - FRACUNIT/2, MT_PARTICLE); + dust = P_SpawnMobj(actor->x + P_RandomFixed(PR_UNDEFINED) - FRACUNIT/2, actor->y + P_RandomFixed(PR_UNDEFINED) - FRACUNIT/2, actor->z + actor->height/2 + P_RandomFixed(PR_UNDEFINED) - FRACUNIT/2, MT_PARTICLE); P_SetScale(dust, 2*FRACUNIT); dust->destscale = FRACUNIT/3; dust->scalespeed = FRACUNIT/40; @@ -2934,8 +2934,8 @@ void A_Boss1Laser(mobj_t *actor) UINT8 size = 3; mobj_t *steam = P_SpawnMobj(x, y, point->watertop - size*mobjinfo[MT_DUST].height, MT_DUST); P_SetScale(steam, size*actor->scale); - P_SetObjectMomZ(steam, FRACUNIT + 2*P_RandomFixed(), true); - P_InstaThrust(steam, FixedAngle(P_RandomKey(360)*FRACUNIT), 2*P_RandomFixed()); + P_SetObjectMomZ(steam, FRACUNIT + 2*P_RandomFixed(PR_UNDEFINED), true); + P_InstaThrust(steam, FixedAngle(P_RandomKey(PR_UNDEFINED, 360)*FRACUNIT), 2*P_RandomFixed(PR_UNDEFINED)); if (point->info->painsound) S_StartSound(steam, point->info->painsound); } @@ -3134,7 +3134,7 @@ void A_SkullAttack(mobj_t *actor) if (locvar1 == 1) actor->angle += ANGLE_180; else if (locvar1 == 2) - actor->angle += (P_RandomChance(FRACUNIT/2)) ? ANGLE_90 : -ANGLE_90; + actor->angle += (P_RandomChance(PR_UNDEFINED, FRACUNIT/2)) ? ANGLE_90 : -ANGLE_90; else if (locvar1 == 3) { statenum_t oldspawnstate = mobjinfo[MT_RAY].spawnstate; @@ -3150,7 +3150,7 @@ void A_SkullAttack(mobj_t *actor) mobjinfo[MT_RAY].radius = mobjinfo[actor->type].radius; mobjinfo[MT_RAY].height = mobjinfo[actor->type].height; - if (P_RandomChance(FRACUNIT/2)) // port priority 1? + if (P_RandomChance(PR_UNDEFINED, FRACUNIT/2)) // port priority 1? { i = 9; j = 27; @@ -3168,7 +3168,7 @@ void A_SkullAttack(mobj_t *actor) P_ReturnThrustY(actor, testang, dist + 2*actor->radius),\ true)) break; - if (P_RandomChance(FRACUNIT/2)) // port priority 2? + if (P_RandomChance(PR_UNDEFINED, FRACUNIT/2)) // port priority 2? { for (k = 0; k < 9; k++) { @@ -3272,7 +3272,7 @@ void A_BossScream(mobj_t *actor) return; if (locvar1 & 1) - fa = (FixedAngle(P_RandomKey(360)*FRACUNIT)>>ANGLETOFINESHIFT) & FINEMASK; + fa = (FixedAngle(P_RandomKey(PR_UNDEFINED, 360)*FRACUNIT)>>ANGLETOFINESHIFT) & FINEMASK; else { actor->movecount += 4*16; @@ -3289,11 +3289,11 @@ void A_BossScream(mobj_t *actor) explodetype = (mobjtype_t)locvar2; if (locvar1 & 2) - z = actor->z + (P_RandomKey((actor->height - mobjinfo[explodetype].height)>>FRACBITS)<z + (P_RandomKey(PR_UNDEFINED, (actor->height - mobjinfo[explodetype].height)>>FRACBITS)<eflags & MFE_VERTICALFLIP) - z = actor->z + actor->height - mobjinfo[explodetype].height - FixedMul((P_RandomByte()<<(FRACBITS-2)) - 8*FRACUNIT, actor->scale); + z = actor->z + actor->height - mobjinfo[explodetype].height - FixedMul((P_RandomByte(PR_UNDEFINED)<<(FRACBITS-2)) - 8*FRACUNIT, actor->scale); else - z = actor->z + FixedMul((P_RandomByte()<<(FRACBITS-2)) - 8*FRACUNIT, actor->scale); + z = actor->z + FixedMul((P_RandomByte(PR_UNDEFINED)<<(FRACBITS-2)) - 8*FRACUNIT, actor->scale); mo = P_SpawnMobj(x, y, z, explodetype); if (actor->eflags & MFE_VERTICALFLIP) @@ -3810,7 +3810,7 @@ void A_BubbleSpawn(mobj_t *actor) return; // don't make bubble! } - prandom = P_RandomByte(); + prandom = P_RandomByte(PR_UNDEFINED); if (leveltime % (3*TICRATE) < 8) bubble = P_SpawnMobj(actor->x, actor->y, actor->z + (actor->height / 2), MT_EXTRALARGEBUBBLE); @@ -3858,7 +3858,7 @@ void A_FanBubbleSpawn(mobj_t *actor) return; // don't make bubble! } - prandom = P_RandomByte(); + prandom = P_RandomByte(PR_UNDEFINED); if ((prandom & 0x7) == 0x7) bubble = P_SpawnMobj(actor->x, actor->y, hz, MT_SMALLBUBBLE); @@ -3898,7 +3898,7 @@ void A_BubbleRise(mobj_t *actor) // Move around slightly to make it look like it's bending around the water if (!locvar1) { - UINT8 prandom = P_RandomByte(); + UINT8 prandom = P_RandomByte(PR_UNDEFINED); if (!(prandom & 0x7)) // *****000 { P_InstaThrust(actor, prandom & 0x70 ? actor->angle + ANGLE_90 : actor->angle, @@ -4106,7 +4106,7 @@ void A_AttractChase(mobj_t *actor) #if 0 // old mobj_t *newring; newring = P_SpawnMobj(actor->x, actor->y, actor->z, actor->info->reactiontime); - P_InstaThrust(newring, P_RandomRange(0,7) * ANGLE_45, 2<momz = 8<fuse = 120*TICRATE; P_RemoveMobj(actor); @@ -4116,7 +4116,7 @@ void A_AttractChase(mobj_t *actor) actor->info = &mobjinfo[actor->type]; actor->flags = actor->info->flags; - P_InstaThrust(actor, P_RandomRange(0,7) * ANGLE_45, 2 * actor->scale); + P_InstaThrust(actor, P_RandomRange(PR_UNDEFINED,0,7) * ANGLE_45, 2 * actor->scale); P_SetObjectMomZ(actor, 8<fuse = 120*TICRATE; #endif @@ -4205,7 +4205,7 @@ void A_FishJump(mobj_t *actor) if (i < MAXPLAYERS) { fixed_t rad = actor->radius>>FRACBITS; - P_SpawnMobjFromMobj(actor, P_RandomRange(rad, -rad)<flags2 & MF2_AMBUSH)) { - if (P_RandomChance(FRACUNIT/8)) + if (P_RandomChance(PR_UNDEFINED, FRACUNIT/8)) { if (actor->info->deathsound) S_StartSound(actor, actor->info->deathsound); // Hiss! @@ -4357,7 +4357,7 @@ void A_JetChase(mobj_t *actor) if (actor->reactiontime) actor->reactiontime--; - if (P_RandomChance(FRACUNIT/32)) + if (P_RandomChance(PR_UNDEFINED, FRACUNIT/32)) { actor->momx = actor->momx / 2; actor->momy = actor->momy / 2; @@ -4598,8 +4598,8 @@ void A_MinusDigging(mobj_t *actor) INT32 rad = 32; angle_t fa = (actor->angle >> ANGLETOFINESHIFT) & FINEMASK; fixed_t dis = actor->info->speed*4; - fixed_t x = FINECOSINE(fa)*dis + actor->x + FRACUNIT*P_RandomRange(-rad, rad); - fixed_t y = FINESINE(fa)*dis + actor->y + FRACUNIT*P_RandomRange(-rad, rad); + fixed_t x = FINECOSINE(fa)*dis + actor->x + FRACUNIT*P_RandomRange(PR_UNDEFINED, -rad, rad); + fixed_t y = FINESINE(fa)*dis + actor->y + FRACUNIT*P_RandomRange(PR_UNDEFINED, -rad, rad); fixed_t mz = (actor->eflags & MFE_VERTICALFLIP) ? actor->ceilingz : actor->floorz; mobj_t *par; @@ -4792,7 +4792,7 @@ void A_JetgThink(mobj_t *actor) if (actor->target) { - if (P_RandomChance(FRACUNIT/8) && !actor->reactiontime) + if (P_RandomChance(PR_UNDEFINED, FRACUNIT/8) && !actor->reactiontime) P_SetMobjState(actor, actor->info->missilestate); else A_JetChase (actor); @@ -4841,7 +4841,7 @@ void A_MouseThink(mobj_t *actor) || (actor->eflags & MFE_VERTICALFLIP && actor->z + actor->height == actor->ceilingz)) && !actor->reactiontime) { - if (P_RandomChance(FRACUNIT/2)) + if (P_RandomChance(PR_UNDEFINED, FRACUNIT/2)) actor->angle += ANGLE_90; else actor->angle -= ANGLE_90; @@ -5248,7 +5248,7 @@ void A_RockSpawn(mobj_t *actor) type = MT_ROCKCRUMBLE1 + (sides[line->sidenum[0]].rowoffset >> FRACBITS); if (line->flags & ML_NOCLIMB) - randomoomph = P_RandomByte() * (FRACUNIT/32); + randomoomph = P_RandomByte(PR_UNDEFINED) * (FRACUNIT/32); else randomoomph = 0; @@ -5410,7 +5410,7 @@ void A_CrawlaCommanderThink(mobj_t *actor) if (locvar1) { - if (actor->health < 2 && P_RandomChance(FRACUNIT/128)) + if (actor->health < 2 && P_RandomChance(PR_UNDEFINED, FRACUNIT/128)) P_SpawnMissile(actor, actor->target, locvar1); } @@ -5425,8 +5425,8 @@ void A_CrawlaCommanderThink(mobj_t *actor) actor->threshold = 0; // Roam around, somewhat in the player's direction. - actor->angle += (P_RandomByte()<<10); - actor->angle -= (P_RandomByte()<<10); + actor->angle += (P_RandomByte(PR_UNDEFINED)<<10); + actor->angle -= (P_RandomByte(PR_UNDEFINED)<<10); if (hovermode) { @@ -5454,7 +5454,7 @@ void A_CrawlaCommanderThink(mobj_t *actor) S_StartSound(actor, actor->info->attacksound); } } - actor->reactiontime = 3*TICRATE + (P_RandomByte()>>2); + actor->reactiontime = 3*TICRATE + (P_RandomByte(PR_UNDEFINED)>>2); } if (actor->health == 1) @@ -5475,8 +5475,8 @@ void A_CrawlaCommanderThink(mobj_t *actor) } else { - UINT8 prandom = P_RandomByte(); - actor->angle = R_PointToAngle2(actor->x, actor->y, actor->target->x, actor->target->y) + (P_RandomChance(FRACUNIT/2) ? -prandom : +prandom); + UINT8 prandom = P_RandomByte(PR_UNDEFINED); + actor->angle = R_PointToAngle2(actor->x, actor->y, actor->target->x, actor->target->y) + (P_RandomChance(PR_UNDEFINED, FRACUNIT/2) ? -prandom : +prandom); P_InstaThrust(actor, actor->angle, FixedDiv(FixedMul(locvar2, actor->scale), 3*FRACUNIT/2)); actor->momz = FixedMul(locvar2, actor->scale); // Bounce up in air } @@ -5796,7 +5796,7 @@ void A_MixUp(mobj_t *actor) { if (counter > 255) // fail-safe to avoid endless loop break; - prandom = P_RandomByte(); + prandom = P_RandomByte(PR_UNDEFINED); prandom %= numplayers; // I love modular arithmetic, don't you? if (prandom) // Make sure it's not a useless mix break; @@ -5914,7 +5914,7 @@ void A_Boss1Chase(mobj_t *actor) { if (actor->health > actor->info->damage) { - if (P_RandomChance(FRACUNIT/2)) + if (P_RandomChance(PR_UNDEFINED, FRACUNIT/2)) P_SetMobjState(actor, actor->info->missilestate); else P_SetMobjState(actor, actor->info->meleestate); @@ -5936,7 +5936,7 @@ void A_Boss1Chase(mobj_t *actor) // ? nomissile: // possibly choose another target - if (multiplayer && P_RandomChance(FRACUNIT/128)) + if (multiplayer && P_RandomChance(PR_UNDEFINED, FRACUNIT/128)) { if (P_LookForPlayers(actor, true, false, 0)) return; // got a new target @@ -5974,7 +5974,7 @@ nomissile: deltay = actor->target->y - actor->y; actor->movedir = diags[((deltay < 0)<<1) + (deltax > 0)]; - actor->movecount = P_RandomByte() & 15; + actor->movecount = P_RandomByte(PR_UNDEFINED) & 15; } } @@ -5999,13 +5999,13 @@ void A_Boss2Chase(mobj_t *actor) // Startup randomness if (actor->reactiontime <= -666) - actor->reactiontime = 2*TICRATE + P_RandomByte(); + actor->reactiontime = 2*TICRATE + P_RandomByte(PR_UNDEFINED); // When reactiontime hits zero, he will go the other way if (--actor->reactiontime <= 0) { reverse = true; - actor->reactiontime = 2*TICRATE + P_RandomByte(); + actor->reactiontime = 2*TICRATE + P_RandomByte(PR_UNDEFINED); } P_SetTarget(&actor->target, P_GetClosestAxis(actor)); @@ -6092,12 +6092,12 @@ void A_Boss2Chase(mobj_t *actor) if (actor->info->attacksound) S_StartAttackSound(actor, actor->info->attacksound); - if (P_RandomChance(FRACUNIT/2)) + if (P_RandomChance(PR_UNDEFINED, FRACUNIT/2)) { goop->momx *= 2; goop->momy *= 2; } - else if (P_RandomChance(129*FRACUNIT/256)) + else if (P_RandomChance(PR_UNDEFINED, 129*FRACUNIT/256)) { goop->momx *= 3; goop->momy *= 3; @@ -6231,8 +6231,8 @@ void A_Boss2PogoSFX(mobj_t *actor) } else { - UINT8 prandom = P_RandomByte(); - actor->angle = R_PointToAngle2(actor->x, actor->y, actor->target->x, actor->target->y) + (P_RandomChance(FRACUNIT/2) ? -prandom : +prandom); + UINT8 prandom = P_RandomByte(PR_UNDEFINED); + actor->angle = R_PointToAngle2(actor->x, actor->y, actor->target->x, actor->target->y) + (P_RandomChance(PR_UNDEFINED, FRACUNIT/2) ? -prandom : +prandom); P_InstaThrust(actor, actor->angle, FixedMul(FixedMul(actor->info->speed,(locvar2)), actor->scale)); } if (actor->info->activesound) S_StartSound(actor, actor->info->activesound); @@ -6270,10 +6270,10 @@ void A_Boss2PogoTarget(mobj_t *actor) // Target hit, retreat! if ((actor->target->player && actor->target->player->flashing > TICRATE) || actor->flags2 & MF2_FRET) { - UINT8 prandom = P_RandomByte(); + UINT8 prandom = P_RandomByte(PR_UNDEFINED); actor->z++; // unstick from the floor actor->momz = FixedMul(locvar1, actor->scale); // Bounce up in air - actor->angle = R_PointToAngle2(actor->x, actor->y, actor->target->x, actor->target->y) + (P_RandomChance(FRACUNIT/2) ? -prandom : +prandom); // Pick a direction, and randomize it. + actor->angle = R_PointToAngle2(actor->x, actor->y, actor->target->x, actor->target->y) + (P_RandomChance(PR_UNDEFINED, FRACUNIT/2) ? -prandom : +prandom); // Pick a direction, and randomize it. P_InstaThrust(actor, actor->angle+ANGLE_180, FixedMul(FixedMul(actor->info->speed,(locvar2)), actor->scale)); // Move at wandering speed } // Try to land on top of the player. @@ -6310,10 +6310,10 @@ void A_Boss2PogoTarget(mobj_t *actor) // Wander semi-randomly towards the player to get closer. else { - UINT8 prandom = P_RandomByte(); + UINT8 prandom = P_RandomByte(PR_UNDEFINED); actor->z++; // unstick from the floor actor->momz = FixedMul(locvar1, actor->scale); // Bounce up in air - actor->angle = R_PointToAngle2(actor->x, actor->y, actor->target->x, actor->target->y) + (P_RandomChance(FRACUNIT/2) ? -prandom : +prandom); // Pick a direction, and randomize it. + actor->angle = R_PointToAngle2(actor->x, actor->y, actor->target->x, actor->target->y) + (P_RandomChance(PR_UNDEFINED, FRACUNIT/2) ? -prandom : +prandom); // Pick a direction, and randomize it. P_InstaThrust(actor, actor->angle, FixedMul(FixedMul(actor->info->speed,(locvar2)), actor->scale)); // Move at wandering speed } // Boing! @@ -7121,7 +7121,7 @@ void A_SmokeTrailer(mobj_t *actor) P_SetObjectMomZ(th, FRACUNIT, false); th->destscale = actor->scale; P_SetScale(th, actor->scale); - th->tics -= P_RandomByte() & 3; + th->tics -= P_RandomByte(PR_UNDEFINED) & 3; if (th->tics < 1) th->tics = 1; } @@ -7219,7 +7219,7 @@ void A_ChangeAngleRelative(mobj_t *actor) // rather than the ranges, so <0 and >360 work as possible values. -Red INT32 locvar1 = var1; INT32 locvar2 = var2; - //angle_t angle = (P_RandomByte()+1)<<24; + //angle_t angle = (P_RandomByte(PR_UNDEFINED)+1)<<24; const fixed_t amin = locvar1*FRACUNIT; const fixed_t amax = locvar2*FRACUNIT; //const angle_t amin = FixedAngle(locvar1*FRACUNIT); @@ -7238,7 +7238,7 @@ void A_ChangeAngleRelative(mobj_t *actor) if (angle > amax) angle = amax;*/ - actor->angle += FixedAngle(P_RandomRange(amin, amax)); + actor->angle += FixedAngle(P_RandomRange(PR_UNDEFINED, amin, amax)); } // Function: A_ChangeAngleAbsolute @@ -7252,7 +7252,7 @@ void A_ChangeAngleAbsolute(mobj_t *actor) { INT32 locvar1 = var1; INT32 locvar2 = var2; - //angle_t angle = (P_RandomByte()+1)<<24; + //angle_t angle = (P_RandomByte(PR_UNDEFINED)+1)<<24; const fixed_t amin = locvar1*FRACUNIT; const fixed_t amax = locvar2*FRACUNIT; //const angle_t amin = FixedAngle(locvar1*FRACUNIT); @@ -7271,7 +7271,7 @@ void A_ChangeAngleAbsolute(mobj_t *actor) if (angle > amax) angle = amax;*/ - actor->angle = FixedAngle(P_RandomRange(amin, amax)); + actor->angle = FixedAngle(P_RandomRange(PR_UNDEFINED, amin, amax)); } // Function: A_RollAngle @@ -7320,7 +7320,7 @@ void A_ChangeRollAngleRelative(mobj_t *actor) I_Error("A_ChangeRollAngleRelative: var1 is greater than var2"); #endif - actor->rollangle += FixedAngle(P_RandomRange(amin, amax)); + actor->rollangle += FixedAngle(P_RandomRange(PR_UNDEFINED, amin, amax)); } // Function: A_ChangeRollAngleAbsolute @@ -7345,7 +7345,7 @@ void A_ChangeRollAngleAbsolute(mobj_t *actor) I_Error("A_ChangeRollAngleAbsolute: var1 is greater than var2"); #endif - actor->rollangle = FixedAngle(P_RandomRange(amin, amax)); + actor->rollangle = FixedAngle(P_RandomRange(PR_UNDEFINED, amin, amax)); } // Function: A_PlaySound @@ -7535,7 +7535,7 @@ void A_SetRandomTics(mobj_t *actor) if (LUA_CallAction(A_SETRANDOMTICS, actor)) return; - actor->tics = P_RandomRange(locvar1, locvar2); + actor->tics = P_RandomRange(PR_UNDEFINED, locvar1, locvar2); } // Function: A_ChangeColorRelative @@ -7980,7 +7980,7 @@ void A_RandomState(mobj_t *actor) if (LUA_CallAction(A_RANDOMSTATE, actor)) return; - P_SetMobjState(actor, P_RandomChance(FRACUNIT/2) ? locvar1 : locvar2); + P_SetMobjState(actor, P_RandomChance(PR_UNDEFINED, FRACUNIT/2) ? locvar1 : locvar2); } // Function: A_RandomStateRange @@ -7998,7 +7998,7 @@ void A_RandomStateRange(mobj_t *actor) if (LUA_CallAction(A_RANDOMSTATERANGE, actor)) return; - P_SetMobjState(actor, P_RandomRange(locvar1, locvar2)); + P_SetMobjState(actor, P_RandomRange(PR_UNDEFINED, locvar1, locvar2)); } // Function: A_StateRangeByAngle @@ -8570,8 +8570,8 @@ void A_MultiShot(mobj_t *actor) z = actor->z + actor->height - FixedMul(48*FRACUNIT + locvar2*FRACUNIT, actor->scale); else z = actor->z + FixedMul(48*FRACUNIT + locvar2*FRACUNIT, actor->scale); - xr = FixedMul((P_SignedRandom()/3)<scale); // please note p_mobj.c's P_Rand() abuse - yr = FixedMul((P_SignedRandom()/3)<scale); // of rand(), RAND_MAX and signness mess + xr = FixedMul((P_SignedRandom(PR_UNDEFINED)/3)<scale); // please note p_mobj.c's P_Rand() abuse + yr = FixedMul((P_SignedRandom(PR_UNDEFINED)/3)<scale); // of rand(), RAND_MAX and signness mess while(count <= loc1lw && loc1lw >= 1) { @@ -8752,7 +8752,7 @@ void A_CheckRandom(mobj_t *actor) chance *= (locvar1 >> 16); chance /= (locvar1 & 0xFFFF); - if (P_RandomChance(chance)) + if (P_RandomChance(PR_UNDEFINED, chance)) P_SetMobjState(actor, locvar2); } @@ -10052,7 +10052,7 @@ void A_BrakChase(mobj_t *actor) { // Check if we should use "melee" attack first. (Yes, this still runs outside of melee range. Quiet, you.) if (actor->info->meleestate - && actor->health <= P_RandomRange(actor->info->spawnhealth/4, (actor->info->spawnhealth * 3)/4)) // Guaranteed true if <= 1/4 health, guaranteed false if > 3/4 health + && actor->health <= P_RandomRange(PR_UNDEFINED, actor->info->spawnhealth/4, (actor->info->spawnhealth * 3)/4)) // Guaranteed true if <= 1/4 health, guaranteed false if > 3/4 health { if (actor->info->attacksound) S_StartAttackSound(actor, actor->info->attacksound); @@ -10084,7 +10084,7 @@ void A_BrakChase(mobj_t *actor) S_StartSound(actor, (sfxenum_t)locvar2); // make active sound - if (actor->info->activesound && P_RandomChance(3*FRACUNIT/256)) + if (actor->info->activesound && P_RandomChance(PR_UNDEFINED, 3*FRACUNIT/256)) { S_StartSound(actor, actor->info->activesound); } @@ -10352,7 +10352,7 @@ mobj_t *P_InternalFlickySpawn(mobj_t *actor, mobjtype_t flickytype, fixed_t momz return NULL; else { - INT32 prandom = P_RandomKey(mapheaderinfo[gamemap-1]->numFlickies); + INT32 prandom = P_RandomKey(PR_UNDEFINED, mapheaderinfo[gamemap-1]->numFlickies); flickytype = mapheaderinfo[gamemap-1]->flickies[prandom]; } } @@ -10374,8 +10374,8 @@ mobj_t *P_InternalFlickySpawn(mobj_t *actor, mobjtype_t flickytype, fixed_t momz momz = FixedDiv(momz, FixedSqrt(3*FRACUNIT)); P_SetObjectMomZ(flicky, momz, false); - flicky->movedir = (P_RandomChance(FRACUNIT/2) ? -1 : 1); - flicky->fuse = P_RandomRange(595, 700); // originally 300, 350 + flicky->movedir = (P_RandomChance(PR_UNDEFINED, FRACUNIT/2) ? -1 : 1); + flicky->fuse = P_RandomRange(PR_UNDEFINED, 595, 700); // originally 300, 350 flicky->threshold = 0; if (lookforplayers) @@ -10438,7 +10438,7 @@ void P_InternalFlickySetColor(mobj_t *actor, UINT8 extrainfo) if (extrainfo == 0) // until we can customize flicky colors by level header, just stick to SRB2's defaults - actor->color = flickycolors[P_RandomKey(2)]; //flickycolors[P_RandomKey(sizeof(flickycolors))]; + actor->color = flickycolors[P_RandomKey(PR_UNDEFINED, 2)]; //flickycolors[P_RandomKey(sizeof(flickycolors))]; else actor->color = flickycolors[min(extrainfo-1, 14)]; // sizeof(flickycolors)-1 } @@ -10515,7 +10515,7 @@ void A_FlickyCenter(mobj_t *actor) else if (actor->flags & MF_SLIDEME) // aimless { actor->tracer->fuse = 0; // less than 2*TICRATE means move aimlessly. - P_InitAngle(actor->tracer, P_RandomKey(180)*ANG2); + P_InitAngle(actor->tracer, P_RandomKey(PR_UNDEFINED, 180)*ANG2); } else //orbit actor->tracer->fuse = FRACUNIT; @@ -10607,7 +10607,7 @@ void A_FlickyAim(mobj_t *actor) if (!actor->target) { P_LookForPlayers(actor, true, false, 0); - actor->angle = P_RandomKey(36)*ANG10; + actor->angle = P_RandomKey(PR_UNDEFINED, 36)*ANG10; return; } @@ -10631,9 +10631,9 @@ void A_FlickyAim(mobj_t *actor) else if (flickyhitwall) { if (actor->target && P_IsFlickyCenter(actor->target->type)) - actor->angle = R_PointToAngle2(actor->target->x, actor->target->y, actor->x, actor->y) + P_RandomRange(112, 248) * ANG1; + actor->angle = R_PointToAngle2(actor->target->x, actor->target->y, actor->x, actor->y) + P_RandomRange(PR_UNDEFINED, 112, 248) * ANG1; else - actor->angle += P_RandomRange(112, 248)*ANG1; + actor->angle += P_RandomRange(PR_UNDEFINED, 112, 248)*ANG1; actor->threshold = 0; } } @@ -10805,9 +10805,9 @@ void A_FlickyFlounder(mobj_t *actor) if (LUA_CallAction(A_FLICKYFLOUNDER, actor)) return; - locvar1 *= (P_RandomKey(2) + 1); - locvar2 *= (P_RandomKey(2) + 1); - hopangle = (actor->angle + (P_RandomKey(9) - 4)*ANG2); + locvar1 *= (P_RandomKey(PR_UNDEFINED, 2) + 1); + locvar2 *= (P_RandomKey(PR_UNDEFINED, 2) + 1); + hopangle = (actor->angle + (P_RandomKey(PR_UNDEFINED, 9) - 4)*ANG2); P_InternalFlickyHop(actor, locvar1, locvar2, hopangle); } @@ -10936,9 +10936,9 @@ void A_FlameParticle(mobj_t *actor) rad = actor->radius>>FRACBITS; hei = actor->height>>FRACBITS; particle = P_SpawnMobjFromMobj(actor, - P_RandomRange(rad, -rad)<destscale = FRACUNIT + P_SignedRandom()*FRACUNIT/256; + actor->destscale = FRACUNIT + P_SignedRandom(PR_UNDEFINED)*FRACUNIT/256; P_SetScale(actor, actor->destscale); if (!actor->spawnpoint) return; // this can't work properly welp - actor->momx = -(P_SignedRandom()*FINESINE(((actor->spawnpoint->angle*ANG1)>>ANGLETOFINESHIFT) & FINEMASK))/128; - actor->momy = (P_SignedRandom()*FINECOSINE(((actor->spawnpoint->angle*ANG1)>>ANGLETOFINESHIFT) & FINEMASK))/128; - actor->momz = (P_SignedRandom()*FRACUNIT)/128; + actor->momx = -(P_SignedRandom(PR_UNDEFINED)*FINESINE(((actor->spawnpoint->angle*ANG1)>>ANGLETOFINESHIFT) & FINEMASK))/128; + actor->momy = (P_SignedRandom(PR_UNDEFINED)*FINECOSINE(((actor->spawnpoint->angle*ANG1)>>ANGLETOFINESHIFT) & FINEMASK))/128; + actor->momz = (P_SignedRandom(PR_UNDEFINED)*FRACUNIT)/128; P_SetOrigin(actor, - actor->spawnpoint->x*FRACUNIT - (P_SignedRandom()*FINESINE(((actor->spawnpoint->angle*ANG1)>>ANGLETOFINESHIFT) & FINEMASK))/2, - actor->spawnpoint->y*FRACUNIT + (P_SignedRandom()*FINECOSINE(((actor->spawnpoint->angle*ANG1)>>ANGLETOFINESHIFT) & FINEMASK))/2, - actor->spawnpoint->z*FRACUNIT + (P_SignedRandom()*FRACUNIT)/2); + actor->spawnpoint->x*FRACUNIT - (P_SignedRandom(PR_UNDEFINED)*FINESINE(((actor->spawnpoint->angle*ANG1)>>ANGLETOFINESHIFT) & FINEMASK))/2, + actor->spawnpoint->y*FRACUNIT + (P_SignedRandom(PR_UNDEFINED)*FINECOSINE(((actor->spawnpoint->angle*ANG1)>>ANGLETOFINESHIFT) & FINEMASK))/2, + actor->spawnpoint->z*FRACUNIT + (P_SignedRandom(PR_UNDEFINED)*FRACUNIT)/2); } // Function: A_MineExplode @@ -11124,9 +11124,9 @@ void A_MineExplode(mobj_t *actor) P_SpawnMobj(actor->x, actor->y, actor->z, type); for (i = 0; i < 16; i++) { - mobj_t *b = P_SpawnMobj(actor->x+P_RandomRange(-dist, dist)*FRACUNIT, - actor->y+P_RandomRange(-dist, dist)*FRACUNIT, - actor->z+P_RandomRange(((actor->eflags & MFE_UNDERWATER) ? -dist : 0), dist)*FRACUNIT, + mobj_t *b = P_SpawnMobj(actor->x+P_RandomRange(PR_UNDEFINED, -dist, dist)*FRACUNIT, + actor->y+P_RandomRange(PR_UNDEFINED, -dist, dist)*FRACUNIT, + actor->z+P_RandomRange(PR_UNDEFINED, ((actor->eflags & MFE_UNDERWATER) ? -dist : 0), dist)*FRACUNIT, type); fixed_t dx = b->x - actor->x, dy = b->y - actor->y, dz = b->z - actor->z; fixed_t dm = P_AproxDistance(dz, P_AproxDistance(dy, dx)); @@ -11613,7 +11613,7 @@ void A_Boss5FindWaypoint(mobj_t *actor) goto nowaypoints; // ??? } - key = P_RandomKey(numfangwaypoints); + key = P_RandomKey(PR_UNDEFINED, numfangwaypoints); P_SetTarget(&actor->tracer, fangwaypoints[key]); if (actor->tracer->type == MT_FANGWAYPOINT) @@ -11787,7 +11787,7 @@ void A_Boss5ExtraRepeat(mobj_t *actor) calc = (locvar1*(locspawn - lochealth))/locspawn; if (calc > 2) - actor->extravalue2 = 1 + calc/2 + P_RandomKey(calc/2); + actor->extravalue2 = 1 + calc/2 + P_RandomKey(PR_UNDEFINED, calc/2); else actor->extravalue2 = 1 + calc; @@ -11997,7 +11997,7 @@ void A_Boss5MakeJunk(mobj_t *actor) return; } - ang = FixedAngle((P_RandomKey(36)*10)<fuse = (((locvar2 & 1) ? 4 : 2)*TICRATE)/3; P_InitAngle(broked, ang); P_InstaThrust(broked, ang, ((locvar2 & 2) ? 8 : 5)*actor->scale); - P_SetObjectMomZ(broked, (((locvar2) ? 4 : 0) + P_RandomRange(2, 5))< 0) P_SetMobjState(broked, locvar1); if (!P_MobjWasRemoved(broked)) @@ -12086,10 +12086,10 @@ static void P_DustRing(mobjtype_t mobjtype, UINT32 div, fixed_t x, fixed_t y, fi P_InitAngle(dust, ang*i + ANGLE_90); P_SetScale(dust, FixedMul(initscale, scale)); - dust->destscale = FixedMul(4*FRACUNIT + P_RandomFixed(), scale); + dust->destscale = FixedMul(4*FRACUNIT + P_RandomFixed(PR_UNDEFINED), scale); dust->scalespeed = scale/24; - P_Thrust(dust, ang*i, speed + FixedMul(P_RandomFixed(), scale)); - dust->momz = P_SignedRandom()*scale/64; + P_Thrust(dust, ang*i, speed + FixedMul(P_RandomFixed(PR_UNDEFINED), scale)); + dust->momz = P_SignedRandom(PR_UNDEFINED)*scale/64; } } @@ -12276,7 +12276,7 @@ void A_DebrisRandom(mobj_t *actor) if (LUA_CallAction(A_DEBRISRANDOM, actor)) return; - actor->frame |= P_RandomRange(0, locvar1); + actor->frame |= P_RandomRange(PR_UNDEFINED, 0, locvar1); var1 = 0; var2 = 359; A_ChangeAngleAbsolute(actor); @@ -12595,7 +12595,7 @@ void A_SnapperThinker(mobj_t *actor) if (actor->reactiontime < 4) { mobj_t *dust = P_SpawnMobj(x0, y0, actor->z, MT_SPINDUST); - P_Thrust(dust, ang + ANGLE_180 + FixedAngle(P_RandomRange(-20, 20)*FRACUNIT), speed*FRACUNIT); + P_Thrust(dust, ang + ANGLE_180 + FixedAngle(P_RandomRange(PR_UNDEFINED, -20, 20)*FRACUNIT), speed*FRACUNIT); } if (actor->extravalue2 == 0) @@ -12694,7 +12694,7 @@ void A_MinecartSparkThink(mobj_t *actor) return; if (actor->momz == 0 && P_IsObjectOnGround(actor)) - actor->momz = P_RandomRange(2, 4)*FRACUNIT; + actor->momz = P_RandomRange(PR_UNDEFINED, 2, 4)*FRACUNIT; dz = actor->momz; dm = FixedHypot(FixedHypot(dx, dy), dz); @@ -12754,8 +12754,8 @@ void A_LavafallRocks(mobj_t *actor) if (i < MAXPLAYERS) { - angle_t fa = (FixedAngle(P_RandomKey(360) << FRACBITS) >> ANGLETOFINESHIFT) & FINEMASK; - fixed_t offset = P_RandomRange(4, 12) << FRACBITS; + angle_t fa = (FixedAngle(P_RandomKey(PR_UNDEFINED, 360) << FRACBITS) >> ANGLETOFINESHIFT) & FINEMASK; + fixed_t offset = P_RandomRange(PR_UNDEFINED, 4, 12) << FRACBITS; fixed_t xoffs = FixedMul(FINECOSINE(fa), actor->radius + offset); fixed_t yoffs = FixedMul(FINESINE(fa), actor->radius + offset); P_SpawnMobjFromMobj(actor, xoffs, yoffs, 0, MT_LAVAFALLROCK); @@ -13388,17 +13388,17 @@ void A_JawzExplode(mobj_t *actor) { INT32 speed, speed2; - truc = P_SpawnMobj(actor->x + P_RandomRange(-8, 8)*FRACUNIT, actor->y + P_RandomRange(-8, 8)*FRACUNIT, - actor->z + P_RandomRange(0, 8)*FRACUNIT, MT_BOOMPARTICLE); + truc = P_SpawnMobj(actor->x + P_RandomRange(PR_UNDEFINED, -8, 8)*FRACUNIT, actor->y + P_RandomRange(PR_UNDEFINED, -8, 8)*FRACUNIT, + actor->z + P_RandomRange(PR_UNDEFINED, 0, 8)*FRACUNIT, MT_BOOMPARTICLE); truc->scale = actor->scale*2; speed = FixedMul(7*FRACUNIT, actor->scale)>>FRACBITS; - truc->momx = P_RandomRange(-speed, speed)*FRACUNIT; - truc->momy = P_RandomRange(-speed, speed)*FRACUNIT; + truc->momx = P_RandomRange(PR_UNDEFINED, -speed, speed)*FRACUNIT; + truc->momy = P_RandomRange(PR_UNDEFINED, -speed, speed)*FRACUNIT; speed = FixedMul(5*FRACUNIT, actor->scale)>>FRACBITS; speed2 = FixedMul(15*FRACUNIT, actor->scale)>>FRACBITS; - truc->momz = P_RandomRange(speed, speed2)*FRACUNIT; + truc->momz = P_RandomRange(PR_UNDEFINED, speed, speed2)*FRACUNIT; truc->tics = TICRATE*2; truc->color = SKINCOLOR_KETCHUP; @@ -13505,9 +13505,9 @@ static void SpawnSPBAIZDust(mobj_t *mo, INT32 dir) // Used for seeking and when SPB is trailing its target from way too close! static void SpawnSPBSpeedLines(mobj_t *actor) { - mobj_t *fast = P_SpawnMobj(actor->x + (P_RandomRange(-24,24) * actor->scale), - actor->y + (P_RandomRange(-24,24) * actor->scale), - actor->z + (actor->height/2) + (P_RandomRange(-24,24) * actor->scale), + mobj_t *fast = P_SpawnMobj(actor->x + (P_RandomRange(PR_UNDEFINED,-24,24) * actor->scale), + actor->y + (P_RandomRange(PR_UNDEFINED,-24,24) * actor->scale), + actor->z + (actor->height/2) + (P_RandomRange(PR_UNDEFINED,-24,24) * actor->scale), MT_FASTLINE); P_SetTarget(&fast->target, actor); @@ -13988,8 +13988,8 @@ void A_LandMineExplode(mobj_t *actor) //K_MatchGenericExtraFlags(expl, actor); P_SetScale(expl, actor->scale*4); - expl->momx = P_RandomRange(-3, 3)*actor->scale/2; - expl->momy = P_RandomRange(-3, 3)*actor->scale/2; + expl->momx = P_RandomRange(PR_UNDEFINED, -3, 3)*actor->scale/2; + expl->momy = P_RandomRange(PR_UNDEFINED, -3, 3)*actor->scale/2; // 100/45 = 2.22 fu/t expl->momz = ((i+1)*actor->scale*5/2)*P_MobjFlip(expl); @@ -14073,11 +14073,11 @@ void A_FZBoomSmoke(mobj_t *actor) for (i = 0; i < 8+(4*var1); i++) { - mobj_t *smoke = P_SpawnMobj(actor->x + (P_RandomRange(-rad, rad)*actor->scale), actor->y + (P_RandomRange(-rad, rad)*actor->scale), - actor->z + (P_RandomRange(0, 72)*actor->scale), MT_THOK); + mobj_t *smoke = P_SpawnMobj(actor->x + (P_RandomRange(PR_UNDEFINED, -rad, rad)*actor->scale), actor->y + (P_RandomRange(PR_UNDEFINED, -rad, rad)*actor->scale), + actor->z + (P_RandomRange(PR_UNDEFINED, 0, 72)*actor->scale), MT_THOK); P_SetMobjState(smoke, S_FZEROSMOKE1); - smoke->tics += P_RandomRange(-3, 4); + smoke->tics += P_RandomRange(PR_UNDEFINED, -3, 4); smoke->scale = actor->scale*3; } return; @@ -14097,7 +14097,7 @@ void A_RandomShadowFrame(mobj_t *actor) { fake = P_SpawnMobj(actor->x, actor->y, actor->z, MT_THOK); fake->sprite = SPR_ENM1; - fake->frame = P_RandomRange(0, 6); + fake->frame = P_RandomRange(PR_UNDEFINED, 0, 6); P_SetScale(fake, FRACUNIT*3/2); fake->scale = FRACUNIT*3/2; fake->destscale = FRACUNIT*3/2; @@ -14200,7 +14200,7 @@ void A_MayonakaArrow(mobj_t *actor) iswarning = actor->spawnpoint->options & MTF_OBJECTSPECIAL; // is our object a warning sign? // "animtimer" is replaced by "extravalue1" here. - actor->extravalue1 = ((actor->extravalue1) ? (actor->extravalue1+1) : (P_RandomRange(0, (iswarning) ? (TICRATE/2) : TICRATE*3))); + actor->extravalue1 = ((actor->extravalue1) ? (actor->extravalue1+1) : (P_RandomRange(PR_UNDEFINED, 0, (iswarning) ? (TICRATE/2) : TICRATE*3))); flip = ((actor->spawnpoint->options & 1) ? (3) : (0)); // flip adds 3 frames, which is the flipped version of the sign. // special warning behavior: if (iswarning) @@ -14240,7 +14240,7 @@ void A_MementosTPParticles(mobj_t *actor) for (; i<4; i++) { - particle = P_SpawnMobj(actor->x + (P_RandomRange(-256, 256)<y + (P_RandomRange(-256, 256)<z + (P_RandomRange(48, 256)<x + (P_RandomRange(PR_UNDEFINED, -256, 256)<y + (P_RandomRange(PR_UNDEFINED, -256, 256)<z + (P_RandomRange(PR_UNDEFINED, 48, 256)<frame = 0; particle->color = ((i%2) ? (SKINCOLOR_RED) : (SKINCOLOR_BLACK)); particle->destscale = 1; @@ -14303,7 +14303,7 @@ void A_ReaperThinker(mobj_t *actor) // Spawn particles as we grow out of the floor, ゴ ゴ ゴ ゴ for (; i<16; i++) { - particle = P_SpawnMobj(actor->x + (P_RandomRange(-60, 60)<y + (P_RandomRange(-60, 60)<z, MT_THOK); + particle = P_SpawnMobj(actor->x + (P_RandomRange(PR_UNDEFINED, -60, 60)<y + (P_RandomRange(PR_UNDEFINED, -60, 60)<z, MT_THOK); particle->momz = 20<color = ((i%2 !=0) ? (SKINCOLOR_RED) : (SKINCOLOR_BLACK)); particle->frame = 0; diff --git a/src/p_floor.c b/src/p_floor.c index 76fd476af..8578c33a9 100644 --- a/src/p_floor.c +++ b/src/p_floor.c @@ -2202,7 +2202,7 @@ void EV_CrumbleChain(sector_t *sec, ffloor_t *rover) for (c = topz; c > bottomz; c -= spacing) { spawned = P_SpawnMobj(a, b, c, type); - spawned->angle += P_RandomKey(36)*ANG10; // irrelevant for default objects but might make sense for some custom ones + spawned->angle += P_RandomKey(PR_UNDEFINED, 36)*ANG10; // irrelevant for default objects but might make sense for some custom ones if (flags & ML_EFFECT1) { diff --git a/src/p_inter.c b/src/p_inter.c index 438909980..1e195086f 100644 --- a/src/p_inter.c +++ b/src/p_inter.c @@ -447,8 +447,8 @@ void P_TouchSpecialThing(mobj_t *special, mobj_t *toucher, boolean heightcheck) firework->momx = toucher->momx; firework->momy = toucher->momy; firework->momz = toucher->momz; - P_Thrust(firework, FixedAngle((72*i)<scale); - P_SetObjectMomZ(firework, P_RandomRange(1,8)*special->scale, false); + P_Thrust(firework, FixedAngle((72*i)<scale); + P_SetObjectMomZ(firework, P_RandomRange(PR_UNDEFINED, 1,8)*special->scale, false); firework->color = toucher->color; } @@ -567,7 +567,7 @@ void P_TouchSpecialThing(mobj_t *special, mobj_t *toucher, boolean heightcheck) special->momz = 0; special->flags |= MF_NOGRAVITY; P_SetMobjState (special, special->info->deathstate); - S_StartSound (special, special->info->deathsound+(P_RandomKey(special->info->mass))); + S_StartSound (special, special->info->deathsound+(P_RandomKey(PR_UNDEFINED, special->info->mass))); } return; @@ -1205,7 +1205,7 @@ void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, UINT8 damaget mo->destscale = mo->scale/8; mo->scalespeed = (mo->scale - mo->destscale)/(2*TICRATE); mo->momz = mo->info->speed; - mo->angle = FixedAngle((P_RandomKey(36)*10)<angle = FixedAngle((P_RandomKey(PR_UNDEFINED, 36)*10)<angle); @@ -1294,7 +1294,7 @@ void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, UINT8 damaget { flingAngle = target->angle + ANGLE_180; - if (P_RandomByte() & 1) + if (P_RandomByte(PR_UNDEFINED) & 1) { flingAngle -= ANGLE_45; } @@ -1337,7 +1337,7 @@ void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, UINT8 damaget UINT8 i; mobj_t *attacker = inflictor ? inflictor : source; mobj_t *part = target->hnext; - angle_t angle = FixedAngle(360*P_RandomFixed()); + angle_t angle = FixedAngle(360*P_RandomFixed(PR_UNDEFINED)); INT16 spacing = (target->radius >> 1) / target->scale; // set respawn fuse @@ -1362,9 +1362,9 @@ void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, UINT8 damaget { mobj_t *puff = P_SpawnMobjFromMobj( target, - P_RandomRange(-spacing, spacing) * FRACUNIT, - P_RandomRange(-spacing, spacing) * FRACUNIT, - P_RandomRange(0, 4*spacing) * FRACUNIT, + P_RandomRange(PR_UNDEFINED, -spacing, spacing) * FRACUNIT, + P_RandomRange(PR_UNDEFINED, -spacing, spacing) * FRACUNIT, + P_RandomRange(PR_UNDEFINED, 0, 4*spacing) * FRACUNIT, MT_SPINDASHDUST ); @@ -1644,7 +1644,7 @@ void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, UINT8 damaget if (target->info->xdeathstate != S_NULL) { - sprflip = P_RandomChance(FRACUNIT/2); + sprflip = P_RandomChance(PR_UNDEFINED, FRACUNIT/2); #define makechunk(angtweak, xmov, ymov) \ chunk = P_SpawnMobjFromMobj(target, 0, 0, 0, MT_WALLSPIKE);\ @@ -1657,7 +1657,7 @@ void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, UINT8 damaget chunk->y += ymov - forwardyoffs;\ P_SetThingPosition(chunk);\ P_InstaThrust(chunk, angtweak, 4*scale);\ - chunk->momz = P_RandomRange(5, 7)*scale;\ + chunk->momz = P_RandomRange(PR_UNDEFINED, 5, 7)*scale;\ if (flip)\ chunk->momz *= -1;\ if (sprflip)\ @@ -1670,7 +1670,7 @@ void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, UINT8 damaget #undef makechunk } - sprflip = P_RandomChance(FRACUNIT/2); + sprflip = P_RandomChance(PR_UNDEFINED, FRACUNIT/2); chunk = P_SpawnMobjFromMobj(target, 0, 0, 0, MT_WALLSPIKE); @@ -1683,7 +1683,7 @@ void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, UINT8 damaget chunk->y += forwardyoffs - yoffs; P_SetThingPosition(chunk); P_InstaThrust(chunk, ang + ANGLE_180, 2*scale); - chunk->momz = P_RandomRange(5, 7)*scale; + chunk->momz = P_RandomRange(PR_UNDEFINED, 5, 7)*scale; if (flip) chunk->momz *= -1; if (sprflip) @@ -1697,7 +1697,7 @@ void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, UINT8 damaget target->y += forwardyoffs + yoffs; P_SetThingPosition(target); P_InstaThrust(target, ang, 2*scale); - target->momz = P_RandomRange(5, 7)*scale; + target->momz = P_RandomRange(PR_UNDEFINED, 5, 7)*scale; if (flip) target->momz *= -1; if (!sprflip) @@ -2244,7 +2244,7 @@ void P_PlayerRingBurst(player_t *player, INT32 num_rings) num_fling_rings = num_rings+min(0, player->rings); // determine first angle - fa = player->mo->angle + ((P_RandomByte() & 1) ? -ANGLE_90 : ANGLE_90); + fa = player->mo->angle + ((P_RandomByte(PR_UNDEFINED) & 1) ? -ANGLE_90 : ANGLE_90); for (i = 0; i < num_fling_rings; i++) { diff --git a/src/p_lights.c b/src/p_lights.c index 3fc8e6c10..2fa4e6822 100644 --- a/src/p_lights.c +++ b/src/p_lights.c @@ -51,7 +51,7 @@ void T_FireFlicker(fireflicker_t *flick) if (--flick->count) return; - amount = (INT16)((UINT8)(P_RandomByte() & 3) * 16); + amount = (INT16)((UINT8)(P_RandomByte(PR_UNDEFINED) & 3) * 16); if (flick->sector->lightlevel - amount < flick->minlight) flick->sector->lightlevel = (INT16)flick->minlight; @@ -235,7 +235,7 @@ strobe_t *P_SpawnAdjustableStrobeFlash(sector_t *minsector, sector_t *maxsector, flash->minlight = 0; if (!inSync) - flash->count = (P_RandomByte() & 7) + 1; + flash->count = (P_RandomByte(PR_UNDEFINED) & 7) + 1; else flash->count = 1; diff --git a/src/p_mobj.c b/src/p_mobj.c index 0505d6bda..5bcd78fb1 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -92,7 +92,7 @@ static inline INT32 randomframe (mobj_t *mobj, INT32 n) { // Only mobj thinkers should use synced RNG if (mobj->thinker.function.acp1 == (actionf_p1)P_MobjThinker) - return P_RandomKey(n); + return P_RandomKey(PR_UNDEFINED, n); else return M_RandomKey(n); } @@ -316,7 +316,7 @@ boolean P_SetPlayerMobjState(mobj_t *mobj, statenum_t state) } else if (mobj->sprite2 != spr2) { - if ((st->frame & FF_SPR2MIDSTART) && numframes && P_RandomChance(FRACUNIT/2)) + if ((st->frame & FF_SPR2MIDSTART) && numframes && P_RandomChance(PR_UNDEFINED, FRACUNIT/2)) frame = numframes/2; else frame = 0; @@ -442,7 +442,7 @@ boolean P_SetMobjState(mobj_t *mobj, statenum_t state) } else if (mobj->sprite2 != spr2) { - if ((st->frame & FF_SPR2MIDSTART) && numframes && P_RandomChance(FRACUNIT/2)) + if ((st->frame & FF_SPR2MIDSTART) && numframes && P_RandomChance(PR_UNDEFINED, FRACUNIT/2)) frame = numframes/2; else frame = 0; @@ -2485,12 +2485,12 @@ boolean P_ZMovement(mobj_t *mo) // If deafed, give the tumbleweed another random kick if it runs out of steam. mom.z += P_MobjFlip(mo)*FixedMul(6*FRACUNIT, mo->scale); - if (P_RandomChance(FRACUNIT/2)) + if (P_RandomChance(PR_UNDEFINED, FRACUNIT/2)) mom.x += FixedMul(6*FRACUNIT, mo->scale); else mom.x -= FixedMul(6*FRACUNIT, mo->scale); - if (P_RandomChance(FRACUNIT/2)) + if (P_RandomChance(PR_UNDEFINED, FRACUNIT/2)) mom.y += FixedMul(6*FRACUNIT, mo->scale); else mom.y -= FixedMul(6*FRACUNIT, mo->scale); @@ -2513,7 +2513,7 @@ boolean P_ZMovement(mobj_t *mo) else if (mo->type == MT_FALLINGROCK) { if (P_MobjFlip(mo)*mom.z > FixedMul(2*FRACUNIT, mo->scale)) - S_StartSound(mo, mo->info->activesound + P_RandomKey(mo->info->reactiontime)); + S_StartSound(mo, mo->info->activesound + P_RandomKey(PR_UNDEFINED, mo->info->reactiontime)); mom.z /= 2; // Rocks not so bouncy @@ -2920,7 +2920,7 @@ boolean P_SceneryZMovement(mobj_t *mo) for (i = 0; i < 4; ++i) // split into four { - prandom = P_RandomByte(); + prandom = P_RandomByte(PR_UNDEFINED); explodemo = P_SpawnMobj(mo->x, mo->y, mo->z, MT_SMALLBUBBLE); explodemo->momx += ((prandom & 0x0F) << (FRACBITS-2)) * (i & 2 ? -1 : 1); explodemo->momy += ((prandom & 0xF0) << (FRACBITS-6)) * (i & 1 ? -1 : 1); @@ -2929,7 +2929,7 @@ boolean P_SceneryZMovement(mobj_t *mo) } if (mo->threshold != 42) // Don't make pop sound if threshold is 42. - S_StartSound(explodemo, sfx_bubbl1 + P_RandomKey(5)); + S_StartSound(explodemo, sfx_bubbl1 + P_RandomKey(PR_UNDEFINED, 5)); //note that we assign the bubble sound to one of the new bubbles. // in other words, IT ACTUALLY GETS USED YAAAAAAAY @@ -2952,7 +2952,7 @@ boolean P_SceneryZMovement(mobj_t *mo) if ((!(mo->eflags & MFE_VERTICALFLIP) && mo->z <= mo->floorz) || (mo->eflags & MFE_VERTICALFLIP && mo->z+mo->height >= mo->ceilingz)) { - mobjtype_t flowertype = ((P_RandomChance(FRACUNIT/2)) ? MT_GFZFLOWER1 : MT_GFZFLOWER3); + mobjtype_t flowertype = ((P_RandomChance(PR_UNDEFINED, FRACUNIT/2)) ? MT_GFZFLOWER1 : MT_GFZFLOWER3); mobj_t *flower = P_SpawnMobjFromMobj(mo, 0, 0, 0, flowertype); if (flower) { @@ -3315,10 +3315,10 @@ void P_MobjCheckWater(mobj_t *mobj) // P_RandomByte()s are called individually to allow consistency // across various compilers, since the order of function calls // in C is not part of the ANSI specification. - prandom[0] = P_RandomByte(); - prandom[1] = P_RandomByte(); - prandom[2] = P_RandomByte(); - prandom[3] = P_RandomByte(); + prandom[0] = P_RandomByte(PR_UNDEFINED); + prandom[1] = P_RandomByte(PR_UNDEFINED); + prandom[2] = P_RandomByte(PR_UNDEFINED); + prandom[3] = P_RandomByte(PR_UNDEFINED); bubbletype = MT_SMALLBUBBLE; if (!(prandom[0] & 0x3)) // medium bubble chance up to 64 from 32 @@ -4249,7 +4249,7 @@ boolean P_BossTargetPlayer(mobj_t *actor, boolean closest) // first time init, this allow minimum lastlook changes if (actor->lastlook < 0) - actor->lastlook = P_RandomByte(); + actor->lastlook = P_RandomByte(PR_UNDEFINED); actor->lastlook &= PLAYERSMASK; for( ; ; actor->lastlook = (actor->lastlook+1) & PLAYERSMASK) @@ -4324,7 +4324,7 @@ boolean P_SupermanLook4Players(mobj_t *actor) if (!stop) return false; - P_SetTarget(&actor->target, playersinthegame[P_RandomKey(stop)]->mo); + P_SetTarget(&actor->target, playersinthegame[P_RandomKey(PR_UNDEFINED, stop)]->mo); return true; } @@ -5345,7 +5345,7 @@ static boolean P_ParticleGenSceneryThink(mobj_t *mobj) spawn->scalespeed = spawn->scale/mobj->health; spawn->tics = (tic_t)mobj->health; spawn->flags2 |= (mobj->flags2 & MF2_OBJECTFLIP); - spawn->angle += P_RandomKey(36)*ANG10; // irrelevant for default objects but might make sense for some custom ones + spawn->angle += P_RandomKey(PR_UNDEFINED, 36)*ANG10; // irrelevant for default objects but might make sense for some custom ones mobj->angle += mobj->movedir; } @@ -5456,7 +5456,7 @@ static void P_MobjSceneryThink(mobj_t *mobj) { mobj->health = 0; P_SetMobjState(mobj, mobj->info->deathstate); - S_StartSound(mobj, mobj->info->deathsound + P_RandomKey(mobj->info->mass)); + S_StartSound(mobj, mobj->info->deathsound + P_RandomKey(PR_UNDEFINED, mobj->info->mass)); return; } break; @@ -5609,22 +5609,22 @@ static void P_MobjSceneryThink(mobj_t *mobj) case MT_SMOLDERING: if (leveltime % 2 == 0) { - fixed_t x = P_RandomRange(-35, 35)*mobj->scale; - fixed_t y = P_RandomRange(-35, 35)*mobj->scale; - fixed_t z = P_RandomRange(0, 70)*mobj->scale; + fixed_t x = P_RandomRange(PR_UNDEFINED, -35, 35)*mobj->scale; + fixed_t y = P_RandomRange(PR_UNDEFINED, -35, 35)*mobj->scale; + fixed_t z = P_RandomRange(PR_UNDEFINED, 0, 70)*mobj->scale; mobj_t *smoke = P_SpawnMobj(mobj->x + x, mobj->y + y, mobj->z + z, MT_SMOKE); P_SetMobjState(smoke, S_OPAQUESMOKE1); K_MatchGenericExtraFlags(smoke, mobj); smoke->scale = mobj->scale * 2; smoke->destscale = mobj->scale * 6; - smoke->momz = P_RandomRange(4, 9)*FRACUNIT*P_MobjFlip(smoke); + smoke->momz = P_RandomRange(PR_UNDEFINED, 4, 9)*FRACUNIT*P_MobjFlip(smoke); } break; case MT_BOOMPARTICLE: { - fixed_t x = P_RandomRange(-16, 16)*mobj->scale; - fixed_t y = P_RandomRange(-16, 16)*mobj->scale; - fixed_t z = P_RandomRange(0, 32)*mobj->scale*P_MobjFlip(mobj); + fixed_t x = P_RandomRange(PR_UNDEFINED, -16, 16)*mobj->scale; + fixed_t y = P_RandomRange(PR_UNDEFINED, -16, 16)*mobj->scale; + fixed_t z = P_RandomRange(PR_UNDEFINED, 0, 32)*mobj->scale*P_MobjFlip(mobj); if (leveltime % 2 == 0) { mobj_t *smoke = P_SpawnMobj(mobj->x + x, mobj->y + y, mobj->z + z, MT_BOSSEXPLODE); @@ -5709,9 +5709,9 @@ static void P_MobjSceneryThink(mobj_t *mobj) { mobj_t *debris = P_SpawnMobjFromMobj( mobj, - P_RandomRange(-spacing, spacing) * FRACUNIT, - P_RandomRange(-spacing, spacing) * FRACUNIT, - P_RandomRange(-spacing, spacing) * FRACUNIT, + P_RandomRange(PR_UNDEFINED, -spacing, spacing) * FRACUNIT, + P_RandomRange(PR_UNDEFINED, -spacing, spacing) * FRACUNIT, + P_RandomRange(PR_UNDEFINED, -spacing, spacing) * FRACUNIT, MT_BATTLEBUMPER_DEBRIS ); @@ -5740,9 +5740,9 @@ static void P_MobjSceneryThink(mobj_t *mobj) { mobj_t *puff = P_SpawnMobjFromMobj( mobj, - P_RandomRange(-spacing, spacing) * FRACUNIT, - P_RandomRange(-spacing, spacing) * FRACUNIT, - P_RandomRange(-spacing, spacing) * FRACUNIT, + P_RandomRange(PR_UNDEFINED, -spacing, spacing) * FRACUNIT, + P_RandomRange(PR_UNDEFINED, -spacing, spacing) * FRACUNIT, + P_RandomRange(PR_UNDEFINED, -spacing, spacing) * FRACUNIT, MT_SPINDASHDUST ); @@ -6310,9 +6310,9 @@ static boolean P_MobjDeadThink(mobj_t *mobj) { fixed_t r = mobj->radius >> FRACBITS; mobj_t *explosion = P_SpawnMobj( - mobj->x + (P_RandomRange(r, -r) << FRACBITS), - mobj->y + (P_RandomRange(r, -r) << FRACBITS), - mobj->z + (P_RandomKey(mobj->height >> FRACBITS) << FRACBITS), + mobj->x + (P_RandomRange(PR_UNDEFINED, r, -r) << FRACBITS), + mobj->y + (P_RandomRange(PR_UNDEFINED, r, -r) << FRACBITS), + mobj->z + (P_RandomKey(PR_UNDEFINED, mobj->height >> FRACBITS) << FRACBITS), MT_SONIC3KBOSSEXPLODE); S_StartSound(explosion, sfx_s3kb4); } @@ -6405,9 +6405,9 @@ static boolean P_MobjDeadThink(mobj_t *mobj) for (i = 0; i < 2; i++) { - fixed_t xoffset = P_RandomRange(-amt, amt) * mobj->scale; - fixed_t yoffset = P_RandomRange(-amt, amt) * mobj->scale; - fixed_t zoffset = P_RandomRange(-(amt >> 1), (amt >> 1)) * mobj->scale; + fixed_t xoffset = P_RandomRange(PR_UNDEFINED, -amt, amt) * mobj->scale; + fixed_t yoffset = P_RandomRange(PR_UNDEFINED, -amt, amt) * mobj->scale; + fixed_t zoffset = P_RandomRange(PR_UNDEFINED, -(amt >> 1), (amt >> 1)) * mobj->scale; dust = P_SpawnMobj(mobj->x + xoffset, mobj->y + yoffset, mobj->z + (mobj->height >> 1) + zoffset, MT_EXPLODE); @@ -7063,9 +7063,9 @@ static boolean P_MobjRegularThink(mobj_t *mobj) { mobj_t *sparkle = P_SpawnMobjFromMobj( mobj, - P_RandomRange(-48, 48) * FRACUNIT, - P_RandomRange(-48, 48) * FRACUNIT, - P_RandomRange(0, 64) * FRACUNIT, + P_RandomRange(PR_UNDEFINED, -48, 48) * FRACUNIT, + P_RandomRange(PR_UNDEFINED, -48, 48) * FRACUNIT, + P_RandomRange(PR_UNDEFINED, 0, 64) * FRACUNIT, MT_EMERALDSPARK ); @@ -7301,7 +7301,7 @@ static boolean P_MobjRegularThink(mobj_t *mobj) smoke->momy = mobj->target->momy/2; smoke->momz = mobj->target->momz/2; - P_Thrust(smoke, mobj->angle+FixedAngle(P_RandomRange(135, 225)<target->scale); + P_Thrust(smoke, mobj->angle+FixedAngle(P_RandomRange(PR_UNDEFINED, 135, 225)<target->scale); } break; case MT_INVULNFLASH: @@ -7758,9 +7758,9 @@ static boolean P_MobjRegularThink(mobj_t *mobj) for (i = 0; i < nl; i++) { - mobj_t *fast = P_SpawnMobj(mobj->x + (P_RandomRange(-36,36) * mobj->scale), - mobj->y + (P_RandomRange(-36,36) * mobj->scale), - mobj->z + (mobj->height/2) + (P_RandomRange(-20,20) * mobj->scale), + mobj_t *fast = P_SpawnMobj(mobj->x + (P_RandomRange(PR_UNDEFINED, -36,36) * mobj->scale), + mobj->y + (P_RandomRange(PR_UNDEFINED, -36,36) * mobj->scale), + mobj->z + (mobj->height/2) + (P_RandomRange(PR_UNDEFINED, -20,20) * mobj->scale), MT_FASTLINE); P_InitAngle(fast, mobj->angle); @@ -8022,7 +8022,7 @@ static boolean P_MobjRegularThink(mobj_t *mobj) else { // Pick another player in the server! - player_t *p = &players[plist[P_RandomKey(plistlen)]]; + player_t *p = &players[plist[P_RandomKey(PR_UNDEFINED, plistlen)]]; newskin = ((skin_t*)p->mo->skin) - skins; newcolor = p->skincolor; } @@ -8094,7 +8094,7 @@ static boolean P_MobjRegularThink(mobj_t *mobj) mobj->movecount = 3; { - angle_t facing = P_RandomRange(0, 90); + angle_t facing = P_RandomRange(PR_UNDEFINED, 0, 90); if (facing >= 45) facing = InvAngle((facing - 45)*ANG1); else @@ -8127,23 +8127,23 @@ static boolean P_MobjRegularThink(mobj_t *mobj) else // fire + smoke pillar { UINT8 i; - mobj_t *fire = P_SpawnMobj(mobj->x + (P_RandomRange(-32, 32)*mobj->scale), mobj->y + (P_RandomRange(-32, 32)*mobj->scale), mobj->z, MT_THOK); + mobj_t *fire = P_SpawnMobj(mobj->x + (P_RandomRange(PR_UNDEFINED, -32, 32)*mobj->scale), mobj->y + (P_RandomRange(PR_UNDEFINED, -32, 32)*mobj->scale), mobj->z, MT_THOK); fire->sprite = SPR_FPRT; fire->frame = FF_FULLBRIGHT|FF_TRANS30; fire->scale = mobj->scale*4; - fire->momz = P_RandomRange(2, 3)*mobj->scale; + fire->momz = P_RandomRange(PR_UNDEFINED, 2, 3)*mobj->scale; fire->scalespeed = mobj->scale/12; fire->destscale = 1; fire->tics = TICRATE; for (i = 0; i < 2; i++) { - mobj_t *smoke = P_SpawnMobj(mobj->x + (P_RandomRange(-16, 16)*mobj->scale), mobj->y + (P_RandomRange(-16, 16)*mobj->scale), mobj->z, MT_SMOKE); + mobj_t *smoke = P_SpawnMobj(mobj->x + (P_RandomRange(PR_UNDEFINED, -16, 16)*mobj->scale), mobj->y + (P_RandomRange(PR_UNDEFINED, -16, 16)*mobj->scale), mobj->z, MT_SMOKE); P_SetMobjState(smoke, S_FZSLOWSMOKE1); smoke->scale = mobj->scale; - smoke->momz = P_RandomRange(3, 10)*mobj->scale; + smoke->momz = P_RandomRange(PR_UNDEFINED, 3, 10)*mobj->scale; smoke->destscale = mobj->scale*4; smoke->scalespeed = mobj->scale/24; } @@ -8200,7 +8200,7 @@ static boolean P_MobjRegularThink(mobj_t *mobj) { if (mobj->flags2 & MF2_AMBUSH) { - mobj->momz = P_RandomRange(12, 16)<momz = P_RandomRange(PR_UNDEFINED, 12, 16)<extravalue2) - mobj->extravalue2 = P_RandomRange(64, 192); + mobj->extravalue2 = P_RandomRange(PR_UNDEFINED, 64, 192); } if (mobj->reactiontime) @@ -8363,11 +8363,11 @@ static boolean P_MobjRegularThink(mobj_t *mobj) if ((mobj->tracer && !P_MobjWasRemoved(mobj->tracer)) && !(leveltime % 10)) { - mobj_t *dust = P_SpawnMobj(mobj->x + (P_RandomRange(-4, 4)<y + (P_RandomRange(-4, 4)<z + (P_RandomRange(0, 2)<x + (P_RandomRange(PR_UNDEFINED, -4, 4)<y + (P_RandomRange(PR_UNDEFINED, -4, 4)<z + (P_RandomRange(PR_UNDEFINED, 0, 2)<scale/2); - P_InstaThrust(dust, FixedAngle(P_RandomRange(0,359)<tracer->momz)/2); + P_InstaThrust(dust, FixedAngle(P_RandomRange(PR_UNDEFINED, 0,359)<tracer->momz)/2); if (abs(mobj->tracer->momz) >= 2<mo->y + P_ReturnThrustY(NULL, player->mo->angle, player->mo->radius) + P_ReturnThrustY(NULL, player->mo->angle+ANGLE_90, (mobj->threshold)<mo->z + (player->mo->height/2 * P_MobjFlip(player->mo)) - + (P_RandomRange(-abs(mobj->threshold), abs(mobj->threshold))<threshold), abs(mobj->threshold))<threshold /= 2; mobj->momz = 0; @@ -8570,7 +8570,7 @@ static boolean P_MobjRegularThink(mobj_t *mobj) { mobj_t *dust = P_SpawnMobj(mobj->x, mobj->y, mobj->z, MT_DRIFTDUST); P_InstaThrust(dust, FixedAngle(((360*FRACUNIT)/8) * i), mobj->info->speed/8); - dust->momz = P_MobjFlip(mobj) * (P_RandomRange(1,4)<momz = P_MobjFlip(mobj) * (P_RandomRange(PR_UNDEFINED, 1,4)<scale = mobj->scale/2; dust->destscale = mobj->scale*3; } @@ -8639,7 +8639,7 @@ static boolean P_MobjRegularThink(mobj_t *mobj) P_MoveOrigin(mobj, mobj->tracer->x + P_ReturnThrustX(NULL, mobj->tracer->angle+ANGLE_90, (mobj->cvmem)<tracer->y + P_ReturnThrustY(NULL, mobj->tracer->angle+ANGLE_90, (mobj->cvmem)<tracer->z - (4*mobj->tracer->scale) + (P_RandomRange(-abs(mobj->cvmem), abs(mobj->cvmem))<tracer->z - (4*mobj->tracer->scale) + (P_RandomRange(PR_UNDEFINED, -abs(mobj->cvmem), abs(mobj->cvmem))<movecount > 4*TICRATE) { @@ -9140,7 +9140,7 @@ for (i = ((mobj->flags2 & MF2_STRONGBOX) ? strongboxamt : weakboxamt); i; --i) s #undef SETMONITORCHANCES - i = P_RandomKey(numchoices); // Gotta love those random numbers! + i = P_RandomKey(PR_UNDEFINED, numchoices); // Gotta love those random numbers! newmobj = P_SpawnMobj(mobj->x, mobj->y, mobj->z, spawnchance[i]); } else @@ -9256,9 +9256,9 @@ static boolean P_FuseThink(mobj_t *mobj) for (i = 0; i < 5; i++) { mobj_t *debris = P_SpawnMobj(mobj->x, mobj->y, mobj->z, MT_SMK_ICEBLOCK_DEBRIS); - P_InitAngle(debris, FixedAngle(P_RandomRange(0,360)<angle, P_RandomRange(3,18)*(FRACUNIT/4)); - debris->momz = P_RandomRange(4,8)<angle, P_RandomRange(PR_UNDEFINED, 3,18)*(FRACUNIT/4)); + debris->momz = P_RandomRange(PR_UNDEFINED, 4,8)<flags2 |= MF2_INVERTAIMABLE; break; case MT_FLICKY_08: - mobj->color = (P_RandomChance(FRACUNIT/2) ? SKINCOLOR_RED : SKINCOLOR_AQUAMARINE); + mobj->color = (P_RandomChance(PR_UNDEFINED, FRACUNIT/2) ? SKINCOLOR_RED : SKINCOLOR_AQUAMARINE); break; case MT_BALLOON: { @@ -10138,7 +10138,7 @@ mobj_t *P_SpawnMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type) SKINCOLOR_JET }; - mobj->color = BALLOONCOLORS[P_RandomKey(sizeof(BALLOONCOLORS))]; + mobj->color = BALLOONCOLORS[P_RandomKey(PR_UNDEFINED, sizeof(BALLOONCOLORS))]; } break; case MT_POGOSPRING: @@ -10148,8 +10148,8 @@ mobj_t *P_SpawnMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type) mobj->color = SKINCOLOR_RED; break; case MT_EGGROBO1: - mobj->movecount = P_RandomKey(13); - mobj->color = FIRSTRAINBOWCOLOR + P_RandomKey(FIRSTSUPERCOLOR - FIRSTRAINBOWCOLOR); + mobj->movecount = P_RandomKey(PR_UNDEFINED, 13); + mobj->color = FIRSTRAINBOWCOLOR + P_RandomKey(PR_UNDEFINED, FIRSTSUPERCOLOR - FIRSTRAINBOWCOLOR); break; case MT_HIVEELEMENTAL: mobj->extravalue1 = 5; @@ -10245,15 +10245,15 @@ mobj_t *P_SpawnMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type) { // set default item & count #if 0 // set to 1 to test capsules with random items, e.g. with objectplace - if (P_RandomChance(FRACUNIT/3)) + if (P_RandomChance(PR_UNDEFINED, FRACUNIT/3)) mobj->threshold = KITEM_SUPERRING; - else if (P_RandomChance(FRACUNIT/3)) + else if (P_RandomChance(PR_UNDEFINED, FRACUNIT/3)) mobj->threshold = KITEM_SPB; - else if (P_RandomChance(FRACUNIT/3)) + else if (P_RandomChance(PR_UNDEFINED, FRACUNIT/3)) mobj->threshold = KITEM_ORBINAUT; else - mobj->threshold = P_RandomRange(1, NUMKARTITEMS - 1); - mobj->movecount = P_RandomChance(FRACUNIT/3) ? 1 : P_RandomKey(32) + 1; + mobj->threshold = P_RandomRange(PR_UNDEFINED, 1, NUMKARTITEMS - 1); + mobj->movecount = P_RandomChance(PR_UNDEFINED, FRACUNIT/3) ? 1 : P_RandomKey(PR_UNDEFINED, 32) + 1; #else mobj->threshold = KITEM_SUPERRING; // default item is super ring mobj->movecount = 1; @@ -10300,7 +10300,7 @@ mobj_t *P_SpawnMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type) break; case MT_RANDOMAUDIENCE: { - fixed_t randu = P_RandomFixed(); + fixed_t randu = P_RandomFixed(PR_UNDEFINED); P_SetScale(mobj, (mobj->destscale <<= 1)); if (randu < (FRACUNIT/9)) // a fan of someone? { @@ -10317,7 +10317,7 @@ mobj_t *P_SpawnMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type) if (pcount) { - mobj->threshold = pnum[P_RandomKey(pcount)]; + mobj->threshold = pnum[P_RandomKey(PR_UNDEFINED, pcount)]; mobj->color = players[mobj->threshold].skincolor; mobj->colorized = true; break; @@ -10326,7 +10326,7 @@ mobj_t *P_SpawnMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type) if (randu > (FRACUNIT/2)) { - mobj->color = P_RandomKey(numskincolors-1)+1; + mobj->color = P_RandomKey(PR_UNDEFINED, numskincolors-1)+1; break; } @@ -10397,8 +10397,8 @@ mobj_t *P_SpawnMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type) UINT16 i; for (i = 0; i < mobj->info->mass; i++) { - fixed_t newx = mobj->x + (P_RandomRange(-mobj->info->mass, mobj->info->mass)<y + (P_RandomRange(-mobj->info->mass, mobj->info->mass)<x + (P_RandomRange(PR_UNDEFINED, -mobj->info->mass, mobj->info->mass)<y + (P_RandomRange(PR_UNDEFINED, -mobj->info->mass, mobj->info->mass)<z, 8<z) P_SpawnMobj(newx, newy, mobj->z, MT_EERIEFOG); @@ -10412,10 +10412,10 @@ mobj_t *P_SpawnMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type) mobj->renderflags |= RF_FULLBRIGHT; break; case MT_SMK_MOLE: - mobj->reactiontime = P_RandomRange(0, 3*mobj->info->reactiontime/2); // Random delay on start of level + mobj->reactiontime = P_RandomRange(PR_UNDEFINED, 0, 3*mobj->info->reactiontime/2); // Random delay on start of level break; case MT_SMK_THWOMP: - mobj->reactiontime = P_RandomRange(0, 3*mobj->info->reactiontime); // Random delay on start of level + mobj->reactiontime = P_RandomRange(PR_UNDEFINED, 0, 3*mobj->info->reactiontime); // Random delay on start of level if (mobj->z == mobj->floorz) mobj->z += (256<movefactor = mobj->z + (256<options & MTF_AMBUSH) { fixed_t offset = FixedMul(16*FRACUNIT, mobj->scale); - mobj->momx += P_RandomChance(FRACUNIT/2) ? offset : -offset; - mobj->momy += P_RandomChance(FRACUNIT/2) ? offset : -offset; + mobj->momx += P_RandomChance(PR_UNDEFINED, FRACUNIT/2) ? offset : -offset; + mobj->momy += P_RandomChance(PR_UNDEFINED, FRACUNIT/2) ? offset : -offset; mobj->momz += offset; } break; diff --git a/src/p_saveg.c b/src/p_saveg.c index 5620178e1..bd1cb9dea 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -4448,7 +4448,10 @@ static void P_NetArchiveMisc(boolean resending) WRITEUINT32(save_p, pig); } - WRITEUINT32(save_p, P_GetRandSeed()); + for (i = 0; i < PRNUMCLASS; i++) + { + WRITEUINT32(save_p, P_GetRandSeed(i)); + } WRITEUINT32(save_p, tokenlist); @@ -4607,7 +4610,10 @@ static inline boolean P_NetUnArchiveMisc(boolean reloading) } } - P_SetRandSeed(READUINT32(save_p)); + for (i = 0; i < PRNUMCLASS; i++) + { + P_SetRandSeed(i, READUINT32(save_p)); + } tokenlist = READUINT32(save_p); @@ -4859,10 +4865,15 @@ boolean P_LoadGame(INT16 mapoverride) boolean P_LoadNetGame(boolean reloading) { + size_t i; + CV_LoadNetVars(&save_p); + if (!P_NetUnArchiveMisc(reloading)) return false; + P_NetUnArchivePlayers(); + if (gamestate == GS_LEVEL) { P_NetUnArchiveWorld(); @@ -4875,10 +4886,14 @@ boolean P_LoadNetGame(boolean reloading) P_RelinkPointers(); P_FinishMobjs(); } + LUA_UnArchive(&save_p); // This is stupid and hacky, but maybe it'll work! - P_SetRandSeed(P_GetInitSeed()); + for (i = 0; i < PRNUMCLASS; i++) + { + P_SetRandSeed(i, P_GetInitSeed(i)); + } // The precipitation would normally be spawned in P_SetupLevel, which is called by // P_NetUnArchiveMisc above. However, that would place it up before P_NetUnArchiveThinkers, diff --git a/src/p_spec.c b/src/p_spec.c index 681e5e8e9..834d3a6f5 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -3298,9 +3298,9 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) INT32 result; if (rvalue1 <= rvalue2) - result = P_RandomRange(rvalue1, rvalue2); + result = P_RandomRange(PR_UNDEFINED, rvalue1, rvalue2); else - result = P_RandomRange(rvalue2, rvalue1); + result = P_RandomRange(PR_UNDEFINED, rvalue2, rvalue1); P_LinedefExecute((INT16)result, mo, NULL); break; @@ -3696,9 +3696,9 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) { if (line->sidenum[1] != 0xffff) // Make sure the linedef has a back side { - x = P_RandomRange(sides[line->sidenum[0]].textureoffset>>FRACBITS, sides[line->sidenum[1]].textureoffset>>FRACBITS)<sidenum[0]].rowoffset>>FRACBITS, sides[line->sidenum[1]].rowoffset>>FRACBITS)<frontsector->floorheight>>FRACBITS, line->frontsector->ceilingheight>>FRACBITS)<sidenum[0]].textureoffset>>FRACBITS, sides[line->sidenum[1]].textureoffset>>FRACBITS)<sidenum[0]].rowoffset>>FRACBITS, sides[line->sidenum[1]].rowoffset>>FRACBITS)<frontsector->floorheight>>FRACBITS, line->frontsector->ceilingheight>>FRACBITS)<charflags & SF_MACHINE) { - if (P_RandomChance(FRACUNIT/5)) + if (P_RandomChance(PR_UNDEFINED, FRACUNIT/5)) { fixed_t r = player->mo->radius>>FRACBITS; - x += (P_RandomRange(r, -r)<mo->height>>FRACBITS)<mo->height>>FRACBITS)<mo->height,5*(FRACUNIT/4)); - if (P_RandomChance(FRACUNIT/16)) + if (P_RandomChance(PR_UNDEFINED, FRACUNIT/16)) bubble = P_SpawnMobj(x, y, z, MT_SMALLBUBBLE); - else if (P_RandomChance(3*FRACUNIT/256)) + else if (P_RandomChance(PR_UNDEFINED, 3*FRACUNIT/256)) bubble = P_SpawnMobj(x, y, z, MT_MEDIUMBUBBLE); } @@ -2358,7 +2358,7 @@ void P_MovePlayer(player_t *player) // Little water sound while touching water - just a nicety. if ((player->mo->eflags & MFE_TOUCHWATER) && !(player->mo->eflags & MFE_UNDERWATER) && !player->spectator) { - if (P_RandomChance(FRACUNIT/2) && leveltime % TICRATE == 0) + if (P_RandomChance(PR_UNDEFINED, FRACUNIT/2) && leveltime % TICRATE == 0) S_StartSound(player->mo, sfx_floush); } @@ -3694,7 +3694,7 @@ boolean P_SpectatorJoinGame(player_t *player) else if (redscore > bluescore) changeto = 2; else - changeto = (P_RandomFixed() & 1) + 1; + changeto = (P_RandomFixed(PR_UNDEFINED) & 1) + 1; if (!LUA_HookTeamSwitch(player, changeto, true, false, false)) return false; diff --git a/src/st_stuff.c b/src/st_stuff.c index af18b1441..138c0e64b 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -406,12 +406,16 @@ static void ST_drawDebugInfo(void) if (cv_debug & DBG_RANDOMIZER) // randomizer testing { - fixed_t peekres = P_RandomPeek(); + // TODO: this only accounts for the undefined class, + // which should be phased out as much as possible anyway. + // Figure out some other way to display all of the RNG classes. + + fixed_t peekres = P_RandomPeek(PR_UNDEFINED); peekres *= 10000; // Change from fixed point peekres >>= FRACBITS; // to displayable decimal - V_DrawRightAlignedString(320, height - 16, V_MONOSPACE, va("Init: %08x", P_GetInitSeed())); - V_DrawRightAlignedString(320, height - 8, V_MONOSPACE, va("Seed: %08x", P_GetRandSeed())); + V_DrawRightAlignedString(320, height - 16, V_MONOSPACE, va("Init: %08x", P_GetInitSeed(PR_UNDEFINED))); + V_DrawRightAlignedString(320, height - 8, V_MONOSPACE, va("Seed: %08x", P_GetRandSeed(PR_UNDEFINED))); V_DrawRightAlignedString(320, height, V_MONOSPACE, va("== : .%04d", peekres)); height -= 32; From 1563660a393736f32ea682f710b1503c104357a1 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Mon, 19 Sep 2022 00:55:11 -0400 Subject: [PATCH 02/10] Add a few RNG classes - PR_ITEM_ROULETTE: Used for item results - PR_ITEM_RINGS: Flung ring direction - PR_ITEM_SHRINK: Shrink gun offsets - PR_PLAYERSTARTS: Battle mode player starts - PR_TERRAIN: TERRAIN particles - PR_DECORATION: Generic decoration - PR_VOICES: Player voice sounds --- src/g_game.c | 8 +- src/k_battle.c | 20 ++-- src/k_kart.c | 214 ++++++++++++++----------------------------- src/k_terrain.c | 14 +-- src/m_random.h | 31 ++++++- src/objects/shrink.c | 13 +-- src/p_enemy.c | 4 +- 7 files changed, 122 insertions(+), 182 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index 03a3c08fa..54f991e68 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -2546,7 +2546,7 @@ mapthing_t *G_FindTeamStart(INT32 playernum) return NULL; } - if ((!players[playernum].ctfteam && numredctfstarts && (!numbluectfstarts || P_RandomChance(PR_UNDEFINED, FRACUNIT/2))) || players[playernum].ctfteam == 1) //red + if ((!players[playernum].ctfteam && numredctfstarts && (!numbluectfstarts || P_RandomChance(PR_PLAYERSTARTS, FRACUNIT/2))) || players[playernum].ctfteam == 1) //red { if (!numredctfstarts) { @@ -2557,7 +2557,7 @@ mapthing_t *G_FindTeamStart(INT32 playernum) for (j = 0; j < 32; j++) { - i = P_RandomKey(PR_UNDEFINED, numredctfstarts); + i = P_RandomKey(PR_PLAYERSTARTS, numredctfstarts); if (G_CheckSpot(playernum, redctfstarts[i])) return redctfstarts[i]; } @@ -2577,7 +2577,7 @@ mapthing_t *G_FindTeamStart(INT32 playernum) for (j = 0; j < 32; j++) { - i = P_RandomKey(PR_UNDEFINED, numbluectfstarts); + i = P_RandomKey(PR_PLAYERSTARTS, numbluectfstarts); if (G_CheckSpot(playernum, bluectfstarts[i])) return bluectfstarts[i]; } @@ -2598,7 +2598,7 @@ mapthing_t *G_FindBattleStart(INT32 playernum) { for (j = 0; j < 64; j++) { - i = P_RandomKey(PR_UNDEFINED, numdmstarts); + i = P_RandomKey(PR_PLAYERSTARTS, numdmstarts); if (G_CheckSpot(playernum, deathmatchstarts[i])) return deathmatchstarts[i]; } diff --git a/src/k_battle.c b/src/k_battle.c index ed8c2af3a..15267664c 100644 --- a/src/k_battle.c +++ b/src/k_battle.c @@ -211,7 +211,7 @@ mobj_t *K_SpawnChaosEmerald(fixed_t x, fixed_t y, fixed_t z, angle_t angle, SINT mobj_t *overlay; P_Thrust(emerald, - FixedAngle(P_RandomFixed(PR_UNDEFINED) * 180) + angle, + FixedAngle(P_RandomFixed(PR_ITEM_ROULETTE) * 180) + angle, 24 * mapobjectscale); emerald->momz = flip * 24 * mapobjectscale; @@ -268,8 +268,8 @@ mobj_t *K_SpawnSphereBox(fixed_t x, fixed_t y, fixed_t z, angle_t angle, SINT8 f P_InitAngle(drop, angle); P_Thrust(drop, - FixedAngle(P_RandomFixed(PR_UNDEFINED) * 180) + angle, - P_RandomRange(PR_UNDEFINED, 4, 12) * mapobjectscale); + FixedAngle(P_RandomFixed(PR_ITEM_ROULETTE) * 180) + angle, + P_RandomRange(PR_ITEM_ROULETTE, 4, 12) * mapobjectscale); drop->momz = flip * 12 * mapobjectscale; if (drop->eflags & MFE_UNDERWATER) @@ -412,7 +412,7 @@ void K_RunPaperItemSpawners(void) { K_SpawnChaosEmerald( battleovertime.x, battleovertime.y, battleovertime.z + (128 * mapobjectscale * flip), - FixedAngle(P_RandomRange(PR_UNDEFINED, 0, 359) * FRACUNIT), flip, + FixedAngle(P_RandomRange(PR_ITEM_ROULETTE, 0, 359) * FRACUNIT), flip, firstUnspawnedEmerald ); } @@ -420,7 +420,7 @@ void K_RunPaperItemSpawners(void) { K_CreatePaperItem( battleovertime.x, battleovertime.y, battleovertime.z + (128 * mapobjectscale * flip), - FixedAngle(P_RandomRange(PR_UNDEFINED, 0, 359) * FRACUNIT), flip, + FixedAngle(P_RandomRange(PR_ITEM_ROULETTE, 0, 359) * FRACUNIT), flip, 0, 0 ); @@ -428,7 +428,7 @@ void K_RunPaperItemSpawners(void) { K_SpawnSphereBox( battleovertime.x, battleovertime.y, battleovertime.z + (128 * mapobjectscale * flip), - FixedAngle(P_RandomRange(PR_UNDEFINED, 0, 359) * FRACUNIT), flip, + FixedAngle(P_RandomRange(PR_ITEM_ROULETTE, 0, 359) * FRACUNIT), flip, 10 ); } @@ -509,7 +509,7 @@ void K_RunPaperItemSpawners(void) } else { - key = P_RandomKey(PR_UNDEFINED, spotCount); + key = P_RandomKey(PR_ITEM_ROULETTE, spotCount); } r = spotMap[key]; @@ -523,7 +523,7 @@ void K_RunPaperItemSpawners(void) { drop = K_SpawnChaosEmerald( spotList[r]->x, spotList[r]->y, spotList[r]->z + (128 * mapobjectscale * flip), - FixedAngle(P_RandomRange(PR_UNDEFINED, 0, 359) * FRACUNIT), flip, + FixedAngle(P_RandomRange(PR_ITEM_ROULETTE, 0, 359) * FRACUNIT), flip, firstUnspawnedEmerald ); } @@ -533,7 +533,7 @@ void K_RunPaperItemSpawners(void) { drop = K_SpawnSphereBox( spotList[r]->x, spotList[r]->y, spotList[r]->z + (128 * mapobjectscale * flip), - FixedAngle(P_RandomRange(PR_UNDEFINED, 0, 359) * FRACUNIT), flip, + FixedAngle(P_RandomRange(PR_ITEM_ROULETTE, 0, 359) * FRACUNIT), flip, 10 ); K_FlipFromObject(drop, spotList[r]); @@ -541,7 +541,7 @@ void K_RunPaperItemSpawners(void) drop = K_CreatePaperItem( spotList[r]->x, spotList[r]->y, spotList[r]->z + (128 * mapobjectscale * flip), - FixedAngle(P_RandomRange(PR_UNDEFINED, 0, 359) * FRACUNIT), flip, + FixedAngle(P_RandomRange(PR_ITEM_ROULETTE, 0, 359) * FRACUNIT), flip, 0, 0 ); } diff --git a/src/k_kart.c b/src/k_kart.c index a4d6c136f..2c7426dec 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -1086,7 +1086,7 @@ static void K_KartItemRoulette(player_t *player, ticcmd_t *cmd) if (!(gametyperules & GTR_SPHERES) && mashed && player->rings < 0 && cv_superring.value) { INT32 debtamount = min(20, abs(player->rings)); - if (P_RandomChance(PR_UNDEFINED, (debtamount*FRACUNIT)/20)) + if (P_RandomChance(PR_ITEM_ROULETTE, (debtamount*FRACUNIT)/20)) { K_KartGetItemResult(player, KITEM_SUPERRING); player->karthud[khud_itemblink] = TICRATE; @@ -1136,7 +1136,7 @@ static void K_KartItemRoulette(player_t *player, ticcmd_t *cmd) // Award the player whatever power is rolled if (totalspawnchance > 0) { - totalspawnchance = P_RandomKey(PR_UNDEFINED, totalspawnchance); + totalspawnchance = P_RandomKey(PR_ITEM_ROULETTE, totalspawnchance); for (i = 0; i < NUMKARTRESULTS && spawnchance[i] <= totalspawnchance; i++); K_KartGetItemResult(player, i); @@ -1720,9 +1720,9 @@ static void K_DrawDraftCombiring(player_t *player, player_t *victim, fixed_t cur { if (offset == 0) { - mobj_t *band = P_SpawnMobj(curx + (P_RandomRange(PR_UNDEFINED, -12, 12)*mapobjectscale), - cury + (P_RandomRange(PR_UNDEFINED, -12, 12)*mapobjectscale), - curz + (P_RandomRange(PR_UNDEFINED, 24, 48)*mapobjectscale), + mobj_t *band = P_SpawnMobj(curx + (P_RandomRange(PR_DECORATION, -12, 12)*mapobjectscale), + cury + (P_RandomRange(PR_DECORATION, -12, 12)*mapobjectscale), + curz + (P_RandomRange(PR_DECORATION, 24, 48)*mapobjectscale), MT_SIGNSPARKLE); if (maxdist == 0) @@ -2191,7 +2191,7 @@ void K_SpawnDriftBoostClip(player_t *player) clip->momz += momz; P_InstaThrust(clip, player->mo->angle + - P_RandomFlip(P_RandomRange(PR_UNDEFINED, FRACUNIT/2, FRACUNIT)), + P_RandomFlip(P_RandomRange(PR_DECORATION, FRACUNIT/2, FRACUNIT)), FixedMul(scale, player->speed)); } @@ -2211,9 +2211,9 @@ void K_SpawnDriftBoostClipSpark(mobj_t *clip) void K_SpawnNormalSpeedLines(player_t *player) { - mobj_t *fast = P_SpawnMobj(player->mo->x + (P_RandomRange(PR_UNDEFINED,-36,36) * player->mo->scale), - player->mo->y + (P_RandomRange(PR_UNDEFINED,-36,36) * player->mo->scale), - player->mo->z + (player->mo->height/2) + (P_RandomRange(PR_UNDEFINED,-20,20) * player->mo->scale), + mobj_t *fast = P_SpawnMobj(player->mo->x + (P_RandomRange(PR_DECORATION,-36,36) * player->mo->scale), + player->mo->y + (P_RandomRange(PR_DECORATION,-36,36) * player->mo->scale), + player->mo->z + (player->mo->height/2) + (P_RandomRange(PR_DECORATION,-20,20) * player->mo->scale), MT_FASTLINE); P_SetTarget(&fast->target, player->mo); @@ -2261,9 +2261,9 @@ void K_SpawnNormalSpeedLines(player_t *player) void K_SpawnInvincibilitySpeedLines(mobj_t *mo) { mobj_t *fast = P_SpawnMobjFromMobj(mo, - P_RandomRange(PR_UNDEFINED, -48, 48) * FRACUNIT, - P_RandomRange(PR_UNDEFINED, -48, 48) * FRACUNIT, - P_RandomRange(PR_UNDEFINED, 0, 64) * FRACUNIT, + P_RandomRange(PR_DECORATION, -48, 48) * FRACUNIT, + P_RandomRange(PR_DECORATION, -48, 48) * FRACUNIT, + P_RandomRange(PR_DECORATION, 0, 64) * FRACUNIT, MT_FASTLINE); P_SetMobjState(fast, S_KARTINVLINES1); @@ -2321,9 +2321,9 @@ static void K_SpawnGrowShrinkParticles(mobj_t *mo, INT32 timer) particle = P_SpawnMobjFromMobj( mo, - P_RandomRange(PR_UNDEFINED, -32, 32) * FRACUNIT, - P_RandomRange(PR_UNDEFINED, -32, 32) * FRACUNIT, - (P_RandomRange(PR_UNDEFINED, 0, 24) + (shrink ? 48 : 0)) * FRACUNIT, + P_RandomRange(PR_DECORATION, -32, 32) * FRACUNIT, + P_RandomRange(PR_DECORATION, -32, 32) * FRACUNIT, + (P_RandomRange(PR_DECORATION, 0, 24) + (shrink ? 48 : 0)) * FRACUNIT, MT_GROW_PARTICLE ); @@ -2849,7 +2849,7 @@ static void K_RegularVoiceTimers(player_t *player) void K_PlayAttackTaunt(mobj_t *source) { - sfxenum_t pick = P_RandomKey(PR_UNDEFINED, 2); // Gotta roll the RNG every time this is called for sync reasons + sfxenum_t pick = P_RandomKey(PR_VOICES, 2); // Gotta roll the RNG every time this is called for sync reasons boolean tasteful = (!source->player || !source->player->karthud[khud_tauntvoices]); if (cv_kartvoices.value && (tasteful || cv_kartvoices.value == 2)) @@ -2863,7 +2863,7 @@ void K_PlayAttackTaunt(mobj_t *source) void K_PlayBoostTaunt(mobj_t *source) { - sfxenum_t pick = P_RandomKey(PR_UNDEFINED, 2); // Gotta roll the RNG every time this is called for sync reasons + sfxenum_t pick = P_RandomKey(PR_VOICES, 2); // Gotta roll the RNG every time this is called for sync reasons boolean tasteful = (!source->player || !source->player->karthud[khud_tauntvoices]); if (cv_kartvoices.value && (tasteful || cv_kartvoices.value == 2)) @@ -2897,7 +2897,7 @@ void K_PlayOvertakeSound(mobj_t *source) void K_PlayPainSound(mobj_t *source, mobj_t *other) { - sfxenum_t pick = P_RandomKey(PR_UNDEFINED, 2); // Gotta roll the RNG every time this is called for sync reasons + sfxenum_t pick = P_RandomKey(PR_VOICES, 2); // Gotta roll the RNG every time this is called for sync reasons sfxenum_t sfx_id = ((skin_t *)source->skin)->soundsid[S_sfx[sfx_khurt1 + pick].skinsound]; boolean alwaysHear = false; @@ -4148,18 +4148,18 @@ void K_SpawnMineExplosion(mobj_t *source, UINT8 color) dust->scalespeed = source->scale/12; P_InstaThrust(dust, dust->angle, FixedMul(20*FRACUNIT, source->scale)); - truc = P_SpawnMobj(source->x + P_RandomRange(PR_UNDEFINED, -radius, radius)*FRACUNIT, - source->y + P_RandomRange(PR_UNDEFINED, -radius, radius)*FRACUNIT, - source->z + P_RandomRange(PR_UNDEFINED, 0, height)*FRACUNIT, MT_BOOMEXPLODE); + truc = P_SpawnMobj(source->x + P_RandomRange(PR_EXPLOSION, -radius, radius)*FRACUNIT, + source->y + P_RandomRange(PR_EXPLOSION, -radius, radius)*FRACUNIT, + source->z + P_RandomRange(PR_EXPLOSION, 0, height)*FRACUNIT, MT_BOOMEXPLODE); K_MatchGenericExtraFlags(truc, source); P_SetScale(truc, source->scale); truc->destscale = source->scale*6; truc->scalespeed = source->scale/12; speed = FixedMul(10*FRACUNIT, source->scale)>>FRACBITS; - truc->momx = P_RandomRange(PR_UNDEFINED, -speed, speed)*FRACUNIT; - truc->momy = P_RandomRange(PR_UNDEFINED, -speed, speed)*FRACUNIT; + truc->momx = P_RandomRange(PR_EXPLOSION, -speed, speed)*FRACUNIT; + truc->momy = P_RandomRange(PR_EXPLOSION, -speed, speed)*FRACUNIT; speed = FixedMul(20*FRACUNIT, source->scale)>>FRACBITS; - truc->momz = P_RandomRange(PR_UNDEFINED, -speed, speed)*FRACUNIT*P_MobjFlip(truc); + truc->momz = P_RandomRange(PR_EXPLOSION, -speed, speed)*FRACUNIT*P_MobjFlip(truc); if (truc->eflags & MFE_UNDERWATER) truc->momz = (117 * truc->momz) / 200; truc->color = color; @@ -4167,30 +4167,30 @@ void K_SpawnMineExplosion(mobj_t *source, UINT8 color) for (i = 0; i < 16; i++) { - dust = P_SpawnMobj(source->x + P_RandomRange(PR_UNDEFINED, -radius, radius)*FRACUNIT, - source->y + P_RandomRange(PR_UNDEFINED, -radius, radius)*FRACUNIT, - source->z + P_RandomRange(PR_UNDEFINED, 0, height)*FRACUNIT, MT_SMOKE); + dust = P_SpawnMobj(source->x + P_RandomRange(PR_EXPLOSION, -radius, radius)*FRACUNIT, + source->y + P_RandomRange(PR_EXPLOSION, -radius, radius)*FRACUNIT, + source->z + P_RandomRange(PR_EXPLOSION, 0, height)*FRACUNIT, MT_SMOKE); P_SetMobjState(dust, S_OPAQUESMOKE1); P_SetScale(dust, source->scale); dust->destscale = source->scale*10; dust->scalespeed = source->scale/12; dust->tics = 30; - dust->momz = P_RandomRange(PR_UNDEFINED, FixedMul(3*FRACUNIT, source->scale)>>FRACBITS, FixedMul(7*FRACUNIT, source->scale)>>FRACBITS)*FRACUNIT; + dust->momz = P_RandomRange(PR_EXPLOSION, FixedMul(3*FRACUNIT, source->scale)>>FRACBITS, FixedMul(7*FRACUNIT, source->scale)>>FRACBITS)*FRACUNIT; - truc = P_SpawnMobj(source->x + P_RandomRange(PR_UNDEFINED, -radius, radius)*FRACUNIT, - source->y + P_RandomRange(PR_UNDEFINED, -radius, radius)*FRACUNIT, - source->z + P_RandomRange(PR_UNDEFINED, 0, height)*FRACUNIT, MT_BOOMPARTICLE); + truc = P_SpawnMobj(source->x + P_RandomRange(PR_EXPLOSION, -radius, radius)*FRACUNIT, + source->y + P_RandomRange(PR_EXPLOSION, -radius, radius)*FRACUNIT, + source->z + P_RandomRange(PR_EXPLOSION, 0, height)*FRACUNIT, MT_BOOMPARTICLE); K_MatchGenericExtraFlags(truc, source); P_SetScale(truc, source->scale); truc->destscale = source->scale*5; truc->scalespeed = source->scale/12; speed = FixedMul(20*FRACUNIT, source->scale)>>FRACBITS; - truc->momx = P_RandomRange(PR_UNDEFINED, -speed, speed)*FRACUNIT; - truc->momy = P_RandomRange(PR_UNDEFINED, -speed, speed)*FRACUNIT; + truc->momx = P_RandomRange(PR_EXPLOSION, -speed, speed)*FRACUNIT; + truc->momy = P_RandomRange(PR_EXPLOSION, -speed, speed)*FRACUNIT; speed = FixedMul(15*FRACUNIT, source->scale)>>FRACBITS; speed2 = FixedMul(45*FRACUNIT, source->scale)>>FRACBITS; - truc->momz = P_RandomRange(PR_UNDEFINED, speed, speed2)*FRACUNIT*P_MobjFlip(truc); - if (P_RandomChance(PR_UNDEFINED, FRACUNIT/2)) + truc->momz = P_RandomRange(PR_EXPLOSION, speed, speed2)*FRACUNIT*P_MobjFlip(truc); + if (P_RandomChance(PR_EXPLOSION, FRACUNIT/2)) truc->momz = -truc->momz; if (truc->eflags & MFE_UNDERWATER) truc->momz = (117 * truc->momz) / 200; @@ -4798,9 +4798,9 @@ void K_SpawnSparkleTrail(mobj_t *mo) //CONS_Printf("%d\n", index); - newx = mo->x + (P_RandomRange(PR_UNDEFINED, -rad, rad)*FRACUNIT); - newy = mo->y + (P_RandomRange(PR_UNDEFINED, -rad, rad)*FRACUNIT); - newz = mo->z + (P_RandomRange(PR_UNDEFINED, 0, mo->height>>FRACBITS)*FRACUNIT); + newx = mo->x + (P_RandomRange(PR_DECORATION, -rad, rad)*FRACUNIT); + newy = mo->y + (P_RandomRange(PR_DECORATION, -rad, rad)*FRACUNIT); + newz = mo->z + (P_RandomRange(PR_DECORATION, 0, mo->height>>FRACBITS)*FRACUNIT); sparkle = P_SpawnMobj(newx, newy, newz, MT_SPARKLETRAIL); @@ -4810,8 +4810,8 @@ void K_SpawnSparkleTrail(mobj_t *mo) //CONS_Printf("movefactor: %d\n", sparkle->movefactor/FRACUNIT); sparkle->extravalue1 = (sparkle->z - mo->z); // Keep track of our Z position relative to the player's, I suppose. - sparkle->extravalue2 = P_RandomRange(PR_UNDEFINED, 0, 1) ? 1 : -1; // Rotation direction? - sparkle->cvmem = P_RandomRange(PR_UNDEFINED, -25, 25)*mo->scale; // Vertical "angle" + sparkle->extravalue2 = P_RandomRange(PR_DECORATION, 0, 1) ? 1 : -1; // Rotation direction? + sparkle->cvmem = P_RandomRange(PR_DECORATION, -25, 25)*mo->scale; // Vertical "angle" K_FlipFromObject(sparkle, mo); P_SetTarget(&sparkle->target, mo); @@ -4849,8 +4849,8 @@ void K_SpawnWipeoutTrail(mobj_t *mo) else aoff += ANGLE_45; - dust = P_SpawnMobj(mo->x + FixedMul(24*mo->scale, FINECOSINE(aoff>>ANGLETOFINESHIFT)) + (P_RandomRange(PR_UNDEFINED,-8,8) << FRACBITS), - mo->y + FixedMul(24*mo->scale, FINESINE(aoff>>ANGLETOFINESHIFT)) + (P_RandomRange(PR_UNDEFINED,-8,8) << FRACBITS), + dust = P_SpawnMobj(mo->x + FixedMul(24*mo->scale, FINECOSINE(aoff>>ANGLETOFINESHIFT)) + (P_RandomRange(PR_DECORATION,-8,8) << FRACBITS), + mo->y + FixedMul(24*mo->scale, FINESINE(aoff>>ANGLETOFINESHIFT)) + (P_RandomRange(PR_DECORATION,-8,8) << FRACBITS), mo->z, MT_WIPEOUTTRAIL); P_SetTarget(&dust->target, mo); @@ -4988,13 +4988,13 @@ void K_DriftDustHandling(mobj_t *spawner) if (anglediff > ANG10*4) // Trying to turn further than 40 degrees { - fixed_t spawnx = P_RandomRange(PR_UNDEFINED, -spawnrange, spawnrange) << FRACBITS; - fixed_t spawny = P_RandomRange(PR_UNDEFINED, -spawnrange, spawnrange) << FRACBITS; + fixed_t spawnx = P_RandomRange(PR_DECORATION, -spawnrange, spawnrange) << FRACBITS; + fixed_t spawny = P_RandomRange(PR_DECORATION, -spawnrange, spawnrange) << FRACBITS; INT32 speedrange = 2; mobj_t *dust = P_SpawnMobj(spawner->x + spawnx, spawner->y + spawny, spawner->z, MT_DRIFTDUST); - dust->momx = FixedMul(spawner->momx + (P_RandomRange(PR_UNDEFINED, -speedrange, speedrange) * spawner->scale), 3*FRACUNIT/4); - dust->momy = FixedMul(spawner->momy + (P_RandomRange(PR_UNDEFINED, -speedrange, speedrange) * spawner->scale), 3*FRACUNIT/4); - dust->momz = P_MobjFlip(spawner) * (P_RandomRange(PR_UNDEFINED, 1, 4) * (spawner->scale)); + dust->momx = FixedMul(spawner->momx + (P_RandomRange(PR_DECORATION, -speedrange, speedrange) * spawner->scale), 3*FRACUNIT/4); + dust->momy = FixedMul(spawner->momy + (P_RandomRange(PR_DECORATION, -speedrange, speedrange) * spawner->scale), 3*FRACUNIT/4); + dust->momz = P_MobjFlip(spawner) * (P_RandomRange(PR_DECORATION, 1, 4) * (spawner->scale)); P_SetScale(dust, spawner->scale/2); dust->destscale = spawner->scale * 3; dust->scalespeed = spawner->scale/12; @@ -5456,8 +5456,8 @@ static void K_DoLightningShield(player_t *player) for (i=0; i<7; i++) { mo = P_SpawnMobj(player->mo->x, player->mo->y, player->mo->z, MT_THOK); - P_InitAngle(mo, P_RandomRange(PR_UNDEFINED, 0, 359)*ANG1); - mo->fuse = P_RandomRange(PR_UNDEFINED, 20, 50); + P_InitAngle(mo, P_RandomRange(PR_DECORATION, 0, 359)*ANG1); + mo->fuse = P_RandomRange(PR_DECORATION, 20, 50); P_SetTarget(&mo->target, player->mo); P_SetMobjState(mo, S_KLIT1); } @@ -5496,91 +5496,11 @@ static void K_FlameDashLeftoverSmoke(mobj_t *src) smoke->momy = 3*src->momy/4; smoke->momz = 3*P_GetMobjZMovement(src)/4; - P_Thrust(smoke, src->angle + FixedAngle(P_RandomRange(PR_UNDEFINED, 135, 225)<scale); - smoke->momz += P_RandomRange(PR_UNDEFINED, 0, 4) * src->scale; + P_Thrust(smoke, src->angle + FixedAngle(P_RandomRange(PR_DECORATION, 135, 225)<scale); + smoke->momz += P_RandomRange(PR_DECORATION, 0, 4) * src->scale; } } -#if 0 -static void K_DoHyudoroSteal(player_t *player) -{ - INT32 i, numplayers = 0; - INT32 playerswappable[MAXPLAYERS]; - INT32 stealplayer = -1; // The player that's getting stolen from - INT32 prandom = 0; - boolean sink = P_RandomChance(PR_UNDEFINED, FRACUNIT/64); - INT32 hyu = hyudorotime; - - if (gametype == GT_RACE) - hyu *= 2; // double in race - - for (i = 0; i < MAXPLAYERS; i++) - { - if (playeringame[i] && players[i].mo && players[i].mo->health > 0 && players[i].playerstate == PST_LIVE - && player != &players[i] && !players[i].exiting && !players[i].spectator // Player in-game - - // Can steal from this player - && (gametype == GT_RACE //&& players[i].position < player->position) - || ((gametyperules & GTR_BUMPERS) && players[i].bumpers > 0)) - - // Has an item - && (players[i].itemtype - && players[i].itemamount - && !(players[i].pflags & PF_ITEMOUT))) - { - playerswappable[numplayers] = i; - numplayers++; - } - } - - prandom = P_RandomFixed(PR_UNDEFINED); - S_StartSound(player->mo, sfx_s3k92); - - if (sink && numplayers > 0 && cv_kitchensink.value) // BEHOLD THE KITCHEN SINK - { - player->hyudorotimer = hyu; - player->stealingtimer = stealtime; - - player->itemtype = KITEM_KITCHENSINK; - player->itemamount = 1; - K_UnsetItemOut(player); - return; - } - else if ((gametype == GT_RACE && player->position == 1) || numplayers == 0) // No-one can be stolen from? Oh well... - { - player->hyudorotimer = hyu; - player->stealingtimer = stealtime; - return; - } - else if (numplayers == 1) // With just 2 players, we just need to set the other player to be the one to steal from - { - stealplayer = playerswappable[numplayers-1]; - } - else if (numplayers > 1) // We need to choose between the available candidates for the 2nd player - { - stealplayer = playerswappable[prandom%(numplayers-1)]; - } - - if (stealplayer > -1) // Now here's where we do the stealing, has to be done here because we still know the player we're stealing from - { - player->hyudorotimer = hyu; - player->stealingtimer = stealtime; - players[stealplayer].stealingtimer = -stealtime; - - player->itemtype = players[stealplayer].itemtype; - player->itemamount = players[stealplayer].itemamount; - K_UnsetItemOut(player); - - players[stealplayer].itemtype = KITEM_NONE; - players[stealplayer].itemamount = 0; - K_UnsetItemOut(&players[stealplayer]); - - if (P_IsDisplayPlayer(&players[stealplayer]) && !r_splitscreen) - S_StartSound(NULL, sfx_s3k92); - } -} -#endif - void K_DoSneaker(player_t *player, INT32 type) { const fixed_t intendedboost = FRACUNIT/2; @@ -6079,7 +5999,7 @@ mobj_t *K_CreatePaperItem(fixed_t x, fixed_t y, fixed_t z, angle_t angle, SINT8 P_InitAngle(drop, angle); P_Thrust(drop, - FixedAngle(P_RandomFixed(PR_UNDEFINED) * 180) + angle, + FixedAngle(P_RandomFixed(PR_ITEM_ROULETTE) * 180) + angle, 16*mapobjectscale); drop->momz = flip * 3 * mapobjectscale; @@ -6113,7 +6033,7 @@ mobj_t *K_CreatePaperItem(fixed_t x, fixed_t y, fixed_t z, angle_t angle, SINT8 UINT8 newType; UINT8 newAmount; - totalspawnchance = P_RandomKey(PR_UNDEFINED, totalspawnchance); + totalspawnchance = P_RandomKey(PR_ITEM_ROULETTE, totalspawnchance); for (i = 0; i < NUMKARTRESULTS && spawnchance[i] <= totalspawnchance; i++); // TODO: this is bad! @@ -7213,7 +7133,7 @@ static inline BlockItReturn_t PIT_AttractingRings(mobj_t *thing) thing->info = &mobjinfo[thing->type]; thing->flags = thing->info->flags; - P_InstaThrust(thing, P_RandomRange(PR_UNDEFINED,0,7) * ANGLE_45, 2 * thing->scale); + P_InstaThrust(thing, P_RandomRange(PR_ITEM_RINGS, 0, 7) * ANGLE_45, 2 * thing->scale); P_SetObjectMomZ(thing, 8<fuse = 120*TICRATE; @@ -7410,9 +7330,9 @@ void K_KartPlayerThink(player_t *player, ticcmd_t *cmd) if (player->springstars && (leveltime & 1)) { - fixed_t randx = P_RandomRange(PR_UNDEFINED, -40, 40) * player->mo->scale; - fixed_t randy = P_RandomRange(PR_UNDEFINED, -40, 40) * player->mo->scale; - fixed_t randz = P_RandomRange(PR_UNDEFINED, 0, player->mo->height >> FRACBITS) << FRACBITS; + fixed_t randx = P_RandomRange(PR_DECORATION, -40, 40) * player->mo->scale; + fixed_t randy = P_RandomRange(PR_DECORATION, -40, 40) * player->mo->scale; + fixed_t randz = P_RandomRange(PR_DECORATION, 0, player->mo->height >> FRACBITS) << FRACBITS; mobj_t *star = P_SpawnMobj( player->mo->x + randx, player->mo->y + randy, @@ -9142,8 +9062,8 @@ void K_KartEbrakeVisuals(player_t *p) if (!p->spindash) { // Spawn downwards fastline - sx = p->mo->x + P_RandomRange(PR_UNDEFINED, -48, 48)*p->mo->scale; - sy = p->mo->y + P_RandomRange(PR_UNDEFINED, -48, 48)*p->mo->scale; + sx = p->mo->x + P_RandomRange(PR_DECORATION, -48, 48)*p->mo->scale; + sy = p->mo->y + P_RandomRange(PR_DECORATION, -48, 48)*p->mo->scale; spdl = P_SpawnMobj(sx, sy, p->mo->z, MT_DOWNLINE); spdl->colorized = true; @@ -9225,8 +9145,8 @@ static void K_KartSpindashDust(mobj_t *parent) for (i = 0; i < 2; i++) { - fixed_t hmomentum = P_RandomRange(PR_UNDEFINED, 6, 12) * parent->scale; - fixed_t vmomentum = P_RandomRange(PR_UNDEFINED, 2, 6) * parent->scale; + fixed_t hmomentum = P_RandomRange(PR_DECORATION, 6, 12) * parent->scale; + fixed_t vmomentum = P_RandomRange(PR_DECORATION, 2, 6) * parent->scale; angle_t ang = parent->player->drawangle + ANGLE_180; SINT8 flip = 1; @@ -9254,9 +9174,9 @@ static void K_KartSpindashDust(mobj_t *parent) static void K_KartSpindashWind(mobj_t *parent) { mobj_t *wind = P_SpawnMobjFromMobj(parent, - P_RandomRange(PR_UNDEFINED,-36,36) * FRACUNIT, - P_RandomRange(PR_UNDEFINED,-36,36) * FRACUNIT, - FixedDiv(parent->height / 2, parent->scale) + (P_RandomRange(PR_UNDEFINED,-20,20) * FRACUNIT), + P_RandomRange(PR_DECORATION,-36,36) * FRACUNIT, + P_RandomRange(PR_DECORATION,-36,36) * FRACUNIT, + FixedDiv(parent->height / 2, parent->scale) + (P_RandomRange(PR_DECORATION,-20,20) * FRACUNIT), MT_SPINDASHWIND ); @@ -10386,9 +10306,9 @@ void K_MoveKartPlayer(player_t *player, boolean onground) { for (n=0; n < maxlines; n++) { - sx = player->mo->x + P_RandomRange(PR_UNDEFINED, -24, 24)*player->mo->scale; - sy = player->mo->y + P_RandomRange(PR_UNDEFINED, -24, 24)*player->mo->scale; - sz = player->mo->z + P_RandomRange(PR_UNDEFINED, 0, 48)*player->mo->scale; + sx = player->mo->x + P_RandomRange(PR_DECORATION, -24, 24)*player->mo->scale; + sy = player->mo->y + P_RandomRange(PR_DECORATION, -24, 24)*player->mo->scale; + sz = player->mo->z + P_RandomRange(PR_DECORATION, 0, 48)*player->mo->scale; spdl = P_SpawnMobj(sx, sy, sz, MT_FASTLINE); P_SetTarget(&spdl->target, player->mo); diff --git a/src/k_terrain.c b/src/k_terrain.c index 238f8ec23..d65eb0019 100644 --- a/src/k_terrain.c +++ b/src/k_terrain.c @@ -539,7 +539,7 @@ static void K_SpawnSplashParticles(mobj_t *mo, t_splash_t *s, fixed_t impact) if (numParticles == 1) { // Random angle. - pushAngle = P_RandomRange(PR_UNDEFINED, 0, ANGLE_MAX); + pushAngle = P_RandomRange(PR_TERRAIN, 0, ANGLE_MAX); } dust = P_SpawnMobjFromMobj( @@ -668,20 +668,20 @@ static void K_SpawnFootstepParticle(mobj_t *mo, t_footstep_t *fs, tic_t timer) if (((timer / fs->frequency) / 2) & 1) { tireAngle -= ANGLE_45; - tireAngle -= P_RandomRange(PR_UNDEFINED, 0, fs->cone / ANG1) * ANG1; - pushAngle -= P_RandomRange(PR_UNDEFINED, 0, fs->cone / ANG1) * ANG1; + tireAngle -= P_RandomRange(PR_TERRAIN, 0, fs->cone / ANG1) * ANG1; + pushAngle -= P_RandomRange(PR_TERRAIN, 0, fs->cone / ANG1) * ANG1; } else { tireAngle += ANGLE_45; - tireAngle += P_RandomRange(PR_UNDEFINED, 0, fs->cone / ANG1) * ANG1; - pushAngle += P_RandomRange(PR_UNDEFINED, 0, fs->cone / ANG1) * ANG1; + tireAngle += P_RandomRange(PR_TERRAIN, 0, fs->cone / ANG1) * ANG1; + pushAngle += P_RandomRange(PR_TERRAIN, 0, fs->cone / ANG1) * ANG1; } if (fs->spread > 0) { - xOff = P_RandomRange(PR_UNDEFINED, -fs->spread / FRACUNIT, fs->spread / FRACUNIT) * FRACUNIT; - yOff = P_RandomRange(PR_UNDEFINED, -fs->spread / FRACUNIT, fs->spread / FRACUNIT) * FRACUNIT; + xOff = P_RandomRange(PR_TERRAIN, -fs->spread / FRACUNIT, fs->spread / FRACUNIT) * FRACUNIT; + yOff = P_RandomRange(PR_TERRAIN, -fs->spread / FRACUNIT, fs->spread / FRACUNIT) * FRACUNIT; } dust = P_SpawnMobjFromMobj( diff --git a/src/m_random.h b/src/m_random.h index c811fa87e..bf016507d 100644 --- a/src/m_random.h +++ b/src/m_random.h @@ -22,7 +22,30 @@ typedef enum { - PR_UNDEFINED, // Before release, cases of this RNG class should be removed, only kept as the default for Lua. + // Before release, cases of this RNG class should + // be removed, only kept as the default for Lua. + PR_UNDEFINED, + + // The rule for RNG classes: + // Don't mix up gameplay & decorative RNG. + + // Decorative RNG is a lot less important + // and can be lumped together. If it's used enough, + // it might be nice to give it's own, though. + + // However each instance of RNG being used for + // gameplay should be split up as much as possible. + + PR_ITEM_ROULETTE, // Item results + PR_ITEM_RINGS, // Flung ring direction + PR_ITEM_SHRINK, // Shrink gun offsets + PR_PLAYERSTARTS, // Player starts + PR_TERRAIN, // TERRAIN particles + + PR_DECORATION, // Generic decoration + PR_VOICES, // Player voice sounds + PR_EXPLOSION, // Explosion VFX + PRNUMCLASS } pr_class_t; @@ -53,10 +76,10 @@ INT32 P_RandomRange(pr_class_t pr_class, INT32 a, INT32 b); #endif // Macros for other functions -#define M_SignedRandom() ((INT32)M_RandomByte() - 128) // [-128, 127] signed byte, originally a -#define P_SignedRandom(pr) ((INT32)P_RandomByte(pr) - 128) // function of its own, moved to a macro +#define M_SignedRandom() ((INT32)M_RandomByte() - 128) // [-128, 127] signed byte, originally a +#define P_SignedRandom(pr) ((INT32)P_RandomByte(pr) - 128) // function of its own, moved to a macro -#define M_RandomChance(p) (M_RandomFixed() < p) // given fixed point probability, p, between 0 (0%) +#define M_RandomChance(p) (M_RandomFixed() < p) // given fixed point probability, p, between 0 (0%) #define P_RandomChance(pr, p) (P_RandomFixed(pr) < p) // and FRACUNIT (100%), returns true p% of the time // Debugging diff --git a/src/objects/shrink.c b/src/objects/shrink.c index 38e510a7b..6b52fc4ca 100644 --- a/src/objects/shrink.c +++ b/src/objects/shrink.c @@ -330,13 +330,10 @@ static void ShrinkLaserThinker(mobj_t *pohbee, mobj_t *gun, mobj_t *laser) laser->spriteyscale = FixedDiv(FixedDiv(gunZ - gun->floorz, mapobjectscale), laser->info->height); - particle = P_SpawnMobjFromMobj( - laser, - P_RandomRange(PR_UNDEFINED, -16, 16) * FRACUNIT, - P_RandomRange(PR_UNDEFINED, -16, 16) * FRACUNIT, - 0, - MT_SHRINK_PARTICLE - ); + particle = P_SpawnMobjFromMobj(laser, 0, 0, 0, MT_SHRINK_PARTICLE); + + particle->sprxoff = P_RandomRange(PR_DECORATION, -16, 16) * laser->scale; + particle->spryoff = P_RandomRange(PR_DECORATION, -16, 16) * laser->scale; P_SetTarget(&gun_pohbee(particle), pohbee); @@ -694,7 +691,7 @@ static void CreatePohbee(player_t *owner, waypoint_t *start, waypoint_t *end, UI P_SetTarget(&pohbee_guns(prevGun), gun); gun_numsegs(gun) = numSegs; - gun_offset(gun) = P_RandomKey(PR_UNDEFINED, GUN_SWINGTIME); + gun_offset(gun) = P_RandomKey(PR_ITEM_SHRINK, GUN_SWINGTIME); overlay = P_SpawnMobjFromMobj(gun, 0, 0, 0, MT_OVERLAY); diff --git a/src/p_enemy.c b/src/p_enemy.c index c33c87cca..f51732db8 100644 --- a/src/p_enemy.c +++ b/src/p_enemy.c @@ -4106,7 +4106,7 @@ void A_AttractChase(mobj_t *actor) #if 0 // old mobj_t *newring; newring = P_SpawnMobj(actor->x, actor->y, actor->z, actor->info->reactiontime); - P_InstaThrust(newring, P_RandomRange(PR_UNDEFINED,0,7) * ANGLE_45, 2<momz = 8<fuse = 120*TICRATE; P_RemoveMobj(actor); @@ -4116,7 +4116,7 @@ void A_AttractChase(mobj_t *actor) actor->info = &mobjinfo[actor->type]; actor->flags = actor->info->flags; - P_InstaThrust(actor, P_RandomRange(PR_UNDEFINED,0,7) * ANGLE_45, 2 * actor->scale); + P_InstaThrust(actor, P_RandomRange(PR_ITEM_RINGS, 0, 7) * ANGLE_45, 2 * actor->scale); P_SetObjectMomZ(actor, 8<fuse = 120*TICRATE; #endif From 04d4158ff66cf4181fdb10e1010129a1e43385f1 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Mon, 19 Sep 2022 00:55:33 -0400 Subject: [PATCH 03/10] Init RNG state on engine load --- src/d_main.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/d_main.c b/src/d_main.c index d7092a901..fab6f6b31 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -74,6 +74,7 @@ #include "k_grandprix.h" #include "k_boss.h" #include "doomstat.h" +#include "m_random.h" // P_ClearRandom #ifdef CMAKECONFIG #include "config.h" @@ -1232,6 +1233,11 @@ void D_SRB2Main(void) // initialise locale code M_StartupLocale(); + // This will be done more properly on + // level load, but for now at least make + // sure that it is initalized at all + P_ClearRandom(0); + // get parameters from a response file (eg: srb2 @parms.txt) M_FindResponseFile(); From 569021ba91f05a75d70bee9ecbc41bc2b5b3b960 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Fri, 23 Sep 2022 11:30:10 -0400 Subject: [PATCH 04/10] Update item debris for rng states --- src/objects/item-debris.c | 6 +++--- src/p_enemy.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/objects/item-debris.c b/src/objects/item-debris.c index a5ddd5842..6e810a3ad 100644 --- a/src/objects/item-debris.c +++ b/src/objects/item-debris.c @@ -95,9 +95,9 @@ spawn_cloud { mobj_t *puff = P_SpawnMobjFromMobj( collectible, - P_RandomRange(-spacing, spacing) * FRACUNIT, - P_RandomRange(-spacing, spacing) * FRACUNIT, - P_RandomRange(0, 4 * spacing) * FRACUNIT, + P_RandomRange(PR_UNDEFINED, -spacing, spacing) * FRACUNIT, + P_RandomRange(PR_UNDEFINED, -spacing, spacing) * FRACUNIT, + P_RandomRange(PR_UNDEFINED, 0, 4 * spacing) * FRACUNIT, MT_SPINDASHDUST ); diff --git a/src/p_enemy.c b/src/p_enemy.c index d4be2db04..9997f50e8 100644 --- a/src/p_enemy.c +++ b/src/p_enemy.c @@ -14543,9 +14543,9 @@ A_SpawnItemDebrisCloud (mobj_t *actor) mobj_t *puff = P_SpawnMobjFromMobj( target, - P_RandomRange(-spacing, spacing) * FRACUNIT, - P_RandomRange(-spacing, spacing) * FRACUNIT, - P_RandomRange(0, 4 * spacing) * FRACUNIT, + P_RandomRange(PR_UNDEFINED, -spacing, spacing) * FRACUNIT, + P_RandomRange(PR_UNDEFINED, -spacing, spacing) * FRACUNIT, + P_RandomRange(PR_UNDEFINED, 0, 4 * spacing) * FRACUNIT, MT_SPINDASHDUST ); From cb54d9bb30284acf4e04a9f372e31d3c251398a6 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Fri, 23 Sep 2022 11:55:15 -0400 Subject: [PATCH 05/10] Use PR_ITEM_RINGS in P_PlayerRingBurst --- src/p_inter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/p_inter.c b/src/p_inter.c index 601bdce72..916771f28 100644 --- a/src/p_inter.c +++ b/src/p_inter.c @@ -2251,7 +2251,7 @@ void P_PlayerRingBurst(player_t *player, INT32 num_rings) num_fling_rings = num_rings+min(0, player->rings); // determine first angle - fa = player->mo->angle + ((P_RandomByte(PR_UNDEFINED) & 1) ? -ANGLE_90 : ANGLE_90); + fa = player->mo->angle + ((P_RandomByte(PR_ITEM_RINGS) & 1) ? -ANGLE_90 : ANGLE_90); for (i = 0; i < num_fling_rings; i++) { From 6ab24e6055ad49281d468d7f3b1489bf662f5f93 Mon Sep 17 00:00:00 2001 From: toaster Date: Sat, 24 Sep 2022 22:01:00 +0100 Subject: [PATCH 06/10] Add extra categories and apply based on non-blocking review - PR_RANDOMANIM // FF_ANIMATE|FF_RANDOMANIM - PR_BUBBLE // Decorative air bubbles - PR_RULESCRAMBLE // Netgame rule scrambing events - PR_ITEM_DEBRIS // Item debris - PR_ITEM_BUBBLE // Item bubbles - PR_ITEM_BOOST // Boost - PR_SMOLDERING // Smoldering particles - PR_SPARKLE // Endsign and/or Emerald - PR_MOVINGTARGET // Randomised moving targets --- src/k_pwrlv.c | 14 +++--- src/m_random.h | 26 ++++++++--- src/p_enemy.c | 98 ++++++++++++++++++++-------------------- src/p_floor.c | 2 +- src/p_inter.c | 26 +++++------ src/p_mobj.c | 120 ++++++++++++++++++++++++------------------------- src/p_spec.c | 4 +- src/p_user.c | 16 +++---- 8 files changed, 161 insertions(+), 145 deletions(-) diff --git a/src/k_pwrlv.c b/src/k_pwrlv.c index 17252acbf..32a4b8ecd 100644 --- a/src/k_pwrlv.c +++ b/src/k_pwrlv.c @@ -515,26 +515,26 @@ void K_SetPowerLevelScrambles(SINT8 powertype) { case 5: speed = KARTSPEED_HARD; - encore = P_RandomChance(PR_UNDEFINED, FRACUNIT>>1); + encore = P_RandomChance(PR_RULESCRAMBLE, FRACUNIT>>1); break; case 4: - speed = P_RandomChance(PR_UNDEFINED, (7<>1); + speed = P_RandomChance(PR_RULESCRAMBLE, (7<>1); break; case 3: - speed = P_RandomChance(PR_UNDEFINED, (3<>2); + speed = P_RandomChance(PR_RULESCRAMBLE, (3<>2); break; case 2: speed = KARTSPEED_NORMAL; - encore = P_RandomChance(PR_UNDEFINED, FRACUNIT>>3); + encore = P_RandomChance(PR_RULESCRAMBLE, FRACUNIT>>3); break; case 1: default: speed = KARTSPEED_NORMAL; encore = false; break; case 0: - speed = P_RandomChance(PR_UNDEFINED, (3<>ANGLETOFINESHIFT) & FINEMASK; + fa = (FixedAngle(P_RandomKey(PR_EXPLOSION, 360)*FRACUNIT)>>ANGLETOFINESHIFT) & FINEMASK; else { actor->movecount += 4*16; @@ -3290,11 +3290,11 @@ void A_BossScream(mobj_t *actor) explodetype = (mobjtype_t)locvar2; if (locvar1 & 2) - z = actor->z + (P_RandomKey(PR_UNDEFINED, (actor->height - mobjinfo[explodetype].height)>>FRACBITS)<z + (P_RandomKey(PR_EXPLOSION, (actor->height - mobjinfo[explodetype].height)>>FRACBITS)<eflags & MFE_VERTICALFLIP) - z = actor->z + actor->height - mobjinfo[explodetype].height - FixedMul((P_RandomByte(PR_UNDEFINED)<<(FRACBITS-2)) - 8*FRACUNIT, actor->scale); + z = actor->z + actor->height - mobjinfo[explodetype].height - FixedMul((P_RandomByte(PR_EXPLOSION)<<(FRACBITS-2)) - 8*FRACUNIT, actor->scale); else - z = actor->z + FixedMul((P_RandomByte(PR_UNDEFINED)<<(FRACBITS-2)) - 8*FRACUNIT, actor->scale); + z = actor->z + FixedMul((P_RandomByte(PR_EXPLOSION)<<(FRACBITS-2)) - 8*FRACUNIT, actor->scale); mo = P_SpawnMobj(x, y, z, explodetype); if (actor->eflags & MFE_VERTICALFLIP) @@ -3811,7 +3811,7 @@ void A_BubbleSpawn(mobj_t *actor) return; // don't make bubble! } - prandom = P_RandomByte(PR_UNDEFINED); + prandom = P_RandomByte(PR_BUBBLE); if (leveltime % (3*TICRATE) < 8) bubble = P_SpawnMobj(actor->x, actor->y, actor->z + (actor->height / 2), MT_EXTRALARGEBUBBLE); @@ -3859,7 +3859,7 @@ void A_FanBubbleSpawn(mobj_t *actor) return; // don't make bubble! } - prandom = P_RandomByte(PR_UNDEFINED); + prandom = P_RandomByte(PR_BUBBLE); if ((prandom & 0x7) == 0x7) bubble = P_SpawnMobj(actor->x, actor->y, hz, MT_SMALLBUBBLE); @@ -3899,7 +3899,7 @@ void A_BubbleRise(mobj_t *actor) // Move around slightly to make it look like it's bending around the water if (!locvar1) { - UINT8 prandom = P_RandomByte(PR_UNDEFINED); + UINT8 prandom = P_RandomByte(PR_BUBBLE); if (!(prandom & 0x7)) // *****000 { P_InstaThrust(actor, prandom & 0x70 ? actor->angle + ANGLE_90 : actor->angle, @@ -4246,7 +4246,7 @@ void A_SetSolidSteam(mobj_t *actor) if (!(actor->flags2 & MF2_AMBUSH)) { - if (P_RandomChance(PR_UNDEFINED, FRACUNIT/8)) + if (P_RandomChance(PR_DECORATION, FRACUNIT/8)) { if (actor->info->deathsound) S_StartSound(actor, actor->info->deathsound); // Hiss! @@ -5249,7 +5249,7 @@ void A_RockSpawn(mobj_t *actor) type = MT_ROCKCRUMBLE1 + (sides[line->sidenum[0]].rowoffset >> FRACBITS); if (line->flags & ML_NOCLIMB) - randomoomph = P_RandomByte(PR_UNDEFINED) * (FRACUNIT/32); + randomoomph = P_RandomByte(PR_DECORATION) * (FRACUNIT/32); else randomoomph = 0; @@ -5797,7 +5797,7 @@ void A_MixUp(mobj_t *actor) { if (counter > 255) // fail-safe to avoid endless loop break; - prandom = P_RandomByte(PR_UNDEFINED); + prandom = P_RandomByte(PR_PLAYERSTARTS); prandom %= numplayers; // I love modular arithmetic, don't you? if (prandom) // Make sure it's not a useless mix break; @@ -7122,7 +7122,7 @@ void A_SmokeTrailer(mobj_t *actor) P_SetObjectMomZ(th, FRACUNIT, false); th->destscale = actor->scale; P_SetScale(th, actor->scale); - th->tics -= P_RandomByte(PR_UNDEFINED) & 3; + th->tics -= P_RandomByte(PR_SMOLDERING) & 3; if (th->tics < 1) th->tics = 1; } @@ -7239,7 +7239,7 @@ void A_ChangeAngleRelative(mobj_t *actor) if (angle > amax) angle = amax;*/ - actor->angle += FixedAngle(P_RandomRange(PR_UNDEFINED, amin, amax)); + actor->angle += FixedAngle(P_RandomRange(PR_RANDOMANIM, amin, amax)); } // Function: A_ChangeAngleAbsolute @@ -7272,7 +7272,7 @@ void A_ChangeAngleAbsolute(mobj_t *actor) if (angle > amax) angle = amax;*/ - actor->angle = FixedAngle(P_RandomRange(PR_UNDEFINED, amin, amax)); + actor->angle = FixedAngle(P_RandomRange(PR_RANDOMANIM, amin, amax)); } // Function: A_RollAngle @@ -7321,7 +7321,7 @@ void A_ChangeRollAngleRelative(mobj_t *actor) I_Error("A_ChangeRollAngleRelative: var1 is greater than var2"); #endif - actor->rollangle += FixedAngle(P_RandomRange(PR_UNDEFINED, amin, amax)); + actor->rollangle += FixedAngle(P_RandomRange(PR_RANDOMANIM, amin, amax)); } // Function: A_ChangeRollAngleAbsolute @@ -7346,7 +7346,7 @@ void A_ChangeRollAngleAbsolute(mobj_t *actor) I_Error("A_ChangeRollAngleAbsolute: var1 is greater than var2"); #endif - actor->rollangle = FixedAngle(P_RandomRange(PR_UNDEFINED, amin, amax)); + actor->rollangle = FixedAngle(P_RandomRange(PR_RANDOMANIM, amin, amax)); } // Function: A_PlaySound @@ -7536,7 +7536,7 @@ void A_SetRandomTics(mobj_t *actor) if (LUA_CallAction(A_SETRANDOMTICS, actor)) return; - actor->tics = P_RandomRange(PR_UNDEFINED, locvar1, locvar2); + actor->tics = P_RandomRange(PR_RANDOMANIM, locvar1, locvar2); } // Function: A_ChangeColorRelative @@ -7981,7 +7981,7 @@ void A_RandomState(mobj_t *actor) if (LUA_CallAction(A_RANDOMSTATE, actor)) return; - P_SetMobjState(actor, P_RandomChance(PR_UNDEFINED, FRACUNIT/2) ? locvar1 : locvar2); + P_SetMobjState(actor, P_RandomChance(PR_RANDOMANIM, FRACUNIT/2) ? locvar1 : locvar2); } // Function: A_RandomStateRange @@ -7999,7 +7999,7 @@ void A_RandomStateRange(mobj_t *actor) if (LUA_CallAction(A_RANDOMSTATERANGE, actor)) return; - P_SetMobjState(actor, P_RandomRange(PR_UNDEFINED, locvar1, locvar2)); + P_SetMobjState(actor, P_RandomRange(PR_RANDOMANIM, locvar1, locvar2)); } // Function: A_StateRangeByAngle @@ -8753,7 +8753,7 @@ void A_CheckRandom(mobj_t *actor) chance *= (locvar1 >> 16); chance /= (locvar1 & 0xFFFF); - if (P_RandomChance(PR_UNDEFINED, chance)) + if (P_RandomChance(PR_RANDOMANIM, chance)) P_SetMobjState(actor, locvar2); } @@ -10937,9 +10937,9 @@ void A_FlameParticle(mobj_t *actor) rad = actor->radius>>FRACBITS; hei = actor->height>>FRACBITS; particle = P_SpawnMobjFromMobj(actor, - P_RandomRange(PR_UNDEFINED, rad, -rad)<destscale = FRACUNIT + P_SignedRandom(PR_UNDEFINED)*FRACUNIT/256; + actor->destscale = FRACUNIT + P_SignedRandom(PR_DECORATION)*FRACUNIT/256; P_SetScale(actor, actor->destscale); if (!actor->spawnpoint) return; // this can't work properly welp - actor->momx = -(P_SignedRandom(PR_UNDEFINED)*FINESINE(((actor->spawnpoint->angle*ANG1)>>ANGLETOFINESHIFT) & FINEMASK))/128; - actor->momy = (P_SignedRandom(PR_UNDEFINED)*FINECOSINE(((actor->spawnpoint->angle*ANG1)>>ANGLETOFINESHIFT) & FINEMASK))/128; - actor->momz = (P_SignedRandom(PR_UNDEFINED)*FRACUNIT)/128; + actor->momx = -(P_SignedRandom(PR_DECORATION)*FINESINE(((actor->spawnpoint->angle*ANG1)>>ANGLETOFINESHIFT) & FINEMASK))/128; + actor->momy = (P_SignedRandom(PR_DECORATION)*FINECOSINE(((actor->spawnpoint->angle*ANG1)>>ANGLETOFINESHIFT) & FINEMASK))/128; + actor->momz = (P_SignedRandom(PR_DECORATION)*FRACUNIT)/128; P_SetOrigin(actor, - actor->spawnpoint->x*FRACUNIT - (P_SignedRandom(PR_UNDEFINED)*FINESINE(((actor->spawnpoint->angle*ANG1)>>ANGLETOFINESHIFT) & FINEMASK))/2, - actor->spawnpoint->y*FRACUNIT + (P_SignedRandom(PR_UNDEFINED)*FINECOSINE(((actor->spawnpoint->angle*ANG1)>>ANGLETOFINESHIFT) & FINEMASK))/2, - actor->spawnpoint->z*FRACUNIT + (P_SignedRandom(PR_UNDEFINED)*FRACUNIT)/2); + actor->spawnpoint->x*FRACUNIT - (P_SignedRandom(PR_DECORATION)*FINESINE(((actor->spawnpoint->angle*ANG1)>>ANGLETOFINESHIFT) & FINEMASK))/2, + actor->spawnpoint->y*FRACUNIT + (P_SignedRandom(PR_DECORATION)*FINECOSINE(((actor->spawnpoint->angle*ANG1)>>ANGLETOFINESHIFT) & FINEMASK))/2, + actor->spawnpoint->z*FRACUNIT + (P_SignedRandom(PR_DECORATION)*FRACUNIT)/2); } // Function: A_MineExplode @@ -11125,9 +11125,9 @@ void A_MineExplode(mobj_t *actor) P_SpawnMobj(actor->x, actor->y, actor->z, type); for (i = 0; i < 16; i++) { - mobj_t *b = P_SpawnMobj(actor->x+P_RandomRange(PR_UNDEFINED, -dist, dist)*FRACUNIT, - actor->y+P_RandomRange(PR_UNDEFINED, -dist, dist)*FRACUNIT, - actor->z+P_RandomRange(PR_UNDEFINED, ((actor->eflags & MFE_UNDERWATER) ? -dist : 0), dist)*FRACUNIT, + mobj_t *b = P_SpawnMobj(actor->x+P_RandomRange(PR_EXPLOSION, -dist, dist)*FRACUNIT, + actor->y+P_RandomRange(PR_EXPLOSION, -dist, dist)*FRACUNIT, + actor->z+P_RandomRange(PR_EXPLOSION, ((actor->eflags & MFE_UNDERWATER) ? -dist : 0), dist)*FRACUNIT, type); fixed_t dx = b->x - actor->x, dy = b->y - actor->y, dz = b->z - actor->z; fixed_t dm = P_AproxDistance(dz, P_AproxDistance(dy, dx)); @@ -13349,17 +13349,17 @@ void A_JawzExplode(mobj_t *actor) { INT32 speed, speed2; - truc = P_SpawnMobj(actor->x + P_RandomRange(PR_UNDEFINED, -8, 8)*FRACUNIT, actor->y + P_RandomRange(PR_UNDEFINED, -8, 8)*FRACUNIT, - actor->z + P_RandomRange(PR_UNDEFINED, 0, 8)*FRACUNIT, MT_BOOMPARTICLE); + truc = P_SpawnMobj(actor->x + P_RandomRange(PR_EXPLOSION, -8, 8)*FRACUNIT, actor->y + P_RandomRange(PR_EXPLOSION, -8, 8)*FRACUNIT, + actor->z + P_RandomRange(PR_EXPLOSION, 0, 8)*FRACUNIT, MT_BOOMPARTICLE); truc->scale = actor->scale*2; speed = FixedMul(7*FRACUNIT, actor->scale)>>FRACBITS; - truc->momx = P_RandomRange(PR_UNDEFINED, -speed, speed)*FRACUNIT; - truc->momy = P_RandomRange(PR_UNDEFINED, -speed, speed)*FRACUNIT; + truc->momx = P_RandomRange(PR_EXPLOSION, -speed, speed)*FRACUNIT; + truc->momy = P_RandomRange(PR_EXPLOSION, -speed, speed)*FRACUNIT; speed = FixedMul(5*FRACUNIT, actor->scale)>>FRACBITS; speed2 = FixedMul(15*FRACUNIT, actor->scale)>>FRACBITS; - truc->momz = P_RandomRange(PR_UNDEFINED, speed, speed2)*FRACUNIT; + truc->momz = P_RandomRange(PR_EXPLOSION, speed, speed2)*FRACUNIT; truc->tics = TICRATE*2; truc->color = SKINCOLOR_KETCHUP; @@ -13439,8 +13439,8 @@ void A_LandMineExplode(mobj_t *actor) //K_MatchGenericExtraFlags(expl, actor); P_SetScale(expl, actor->scale*4); - expl->momx = P_RandomRange(PR_UNDEFINED, -3, 3)*actor->scale/2; - expl->momy = P_RandomRange(PR_UNDEFINED, -3, 3)*actor->scale/2; + expl->momx = P_RandomRange(PR_EXPLOSION, -3, 3)*actor->scale/2; + expl->momy = P_RandomRange(PR_EXPLOSION, -3, 3)*actor->scale/2; // 100/45 = 2.22 fu/t expl->momz = ((i+1)*actor->scale*5/2)*P_MobjFlip(expl); @@ -13524,11 +13524,11 @@ void A_FZBoomSmoke(mobj_t *actor) for (i = 0; i < 8+(4*var1); i++) { - mobj_t *smoke = P_SpawnMobj(actor->x + (P_RandomRange(PR_UNDEFINED, -rad, rad)*actor->scale), actor->y + (P_RandomRange(PR_UNDEFINED, -rad, rad)*actor->scale), - actor->z + (P_RandomRange(PR_UNDEFINED, 0, 72)*actor->scale), MT_THOK); + mobj_t *smoke = P_SpawnMobj(actor->x + (P_RandomRange(PR_SMOLDERING, -rad, rad)*actor->scale), actor->y + (P_RandomRange(PR_SMOLDERING, -rad, rad)*actor->scale), + actor->z + (P_RandomRange(PR_SMOLDERING, 0, 72)*actor->scale), MT_THOK); P_SetMobjState(smoke, S_FZEROSMOKE1); - smoke->tics += P_RandomRange(PR_UNDEFINED, -3, 4); + smoke->tics += P_RandomRange(PR_SMOLDERING, -3, 4); smoke->scale = actor->scale*3; } return; @@ -13548,7 +13548,7 @@ void A_RandomShadowFrame(mobj_t *actor) { fake = P_SpawnMobj(actor->x, actor->y, actor->z, MT_THOK); fake->sprite = SPR_ENM1; - fake->frame = P_RandomRange(PR_UNDEFINED, 0, 6); + fake->frame = P_RandomRange(PR_DECORATION, 0, 6); P_SetScale(fake, FRACUNIT*3/2); fake->scale = FRACUNIT*3/2; fake->destscale = FRACUNIT*3/2; @@ -13651,7 +13651,7 @@ void A_MayonakaArrow(mobj_t *actor) iswarning = actor->spawnpoint->options & MTF_OBJECTSPECIAL; // is our object a warning sign? // "animtimer" is replaced by "extravalue1" here. - actor->extravalue1 = ((actor->extravalue1) ? (actor->extravalue1+1) : (P_RandomRange(PR_UNDEFINED, 0, (iswarning) ? (TICRATE/2) : TICRATE*3))); + actor->extravalue1 = ((actor->extravalue1) ? (actor->extravalue1+1) : (P_RandomRange(PR_DECORATION, 0, (iswarning) ? (TICRATE/2) : TICRATE*3))); flip = ((actor->spawnpoint->options & 1) ? (3) : (0)); // flip adds 3 frames, which is the flipped version of the sign. // special warning behavior: if (iswarning) @@ -13691,7 +13691,7 @@ void A_MementosTPParticles(mobj_t *actor) for (; i<4; i++) { - particle = P_SpawnMobj(actor->x + (P_RandomRange(PR_UNDEFINED, -256, 256)<y + (P_RandomRange(PR_UNDEFINED, -256, 256)<z + (P_RandomRange(PR_UNDEFINED, 48, 256)<x + (P_RandomRange(PR_DECORATION, -256, 256)<y + (P_RandomRange(PR_DECORATION, -256, 256)<z + (P_RandomRange(PR_DECORATION, 48, 256)<frame = 0; particle->color = ((i%2) ? (SKINCOLOR_RED) : (SKINCOLOR_BLACK)); particle->destscale = 1; @@ -13754,7 +13754,7 @@ void A_ReaperThinker(mobj_t *actor) // Spawn particles as we grow out of the floor, ゴ ゴ ゴ ゴ for (; i<16; i++) { - particle = P_SpawnMobj(actor->x + (P_RandomRange(PR_UNDEFINED, -60, 60)<y + (P_RandomRange(PR_UNDEFINED, -60, 60)<z, MT_THOK); + particle = P_SpawnMobj(actor->x + (P_RandomRange(PR_DECORATION, -60, 60)<y + (P_RandomRange(PR_DECORATION, -60, 60)<z, MT_THOK); particle->momz = 20<color = ((i%2 !=0) ? (SKINCOLOR_RED) : (SKINCOLOR_BLACK)); particle->frame = 0; @@ -14030,9 +14030,9 @@ A_SpawnItemDebrisCloud (mobj_t *actor) mobj_t *puff = P_SpawnMobjFromMobj( target, - P_RandomRange(PR_UNDEFINED, -spacing, spacing) * FRACUNIT, - P_RandomRange(PR_UNDEFINED, -spacing, spacing) * FRACUNIT, - P_RandomRange(PR_UNDEFINED, 0, 4 * spacing) * FRACUNIT, + P_RandomRange(PR_ITEM_DEBRIS, -spacing, spacing) * FRACUNIT, + P_RandomRange(PR_ITEM_DEBRIS, -spacing, spacing) * FRACUNIT, + P_RandomRange(PR_ITEM_DEBRIS, 0, 4 * spacing) * FRACUNIT, MT_SPINDASHDUST ); diff --git a/src/p_floor.c b/src/p_floor.c index 8578c33a9..581e83740 100644 --- a/src/p_floor.c +++ b/src/p_floor.c @@ -2202,7 +2202,7 @@ void EV_CrumbleChain(sector_t *sec, ffloor_t *rover) for (c = topz; c > bottomz; c -= spacing) { spawned = P_SpawnMobj(a, b, c, type); - spawned->angle += P_RandomKey(PR_UNDEFINED, 36)*ANG10; // irrelevant for default objects but might make sense for some custom ones + spawned->angle += P_RandomKey(PR_TERRAIN, 36)*ANG10; // irrelevant for default objects but might make sense for some custom ones if (flags & ML_EFFECT1) { diff --git a/src/p_inter.c b/src/p_inter.c index 001e4eb55..20a0c5e2a 100644 --- a/src/p_inter.c +++ b/src/p_inter.c @@ -416,8 +416,8 @@ void P_TouchSpecialThing(mobj_t *special, mobj_t *toucher, boolean heightcheck) firework->momx = toucher->momx; firework->momy = toucher->momy; firework->momz = toucher->momz; - P_Thrust(firework, FixedAngle((72*i)<scale); - P_SetObjectMomZ(firework, P_RandomRange(PR_UNDEFINED, 1,8)*special->scale, false); + P_Thrust(firework, FixedAngle((72*i)<scale); + P_SetObjectMomZ(firework, P_RandomRange(PR_ITEM_DEBRIS, 1,8)*special->scale, false); firework->color = toucher->color; } @@ -536,7 +536,7 @@ void P_TouchSpecialThing(mobj_t *special, mobj_t *toucher, boolean heightcheck) special->momz = 0; special->flags |= MF_NOGRAVITY; P_SetMobjState (special, special->info->deathstate); - S_StartSound (special, special->info->deathsound+(P_RandomKey(PR_UNDEFINED, special->info->mass))); + S_StartSound (special, special->info->deathsound+(P_RandomKey(PR_DECORATION, special->info->mass))); } return; @@ -1270,7 +1270,7 @@ void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, UINT8 damaget { flingAngle = target->angle + ANGLE_180; - if (P_RandomByte(PR_UNDEFINED) & 1) + if (P_RandomByte(PR_ITEM_RINGS) & 1) { flingAngle -= ANGLE_45; } @@ -1313,7 +1313,7 @@ void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, UINT8 damaget UINT8 i; mobj_t *attacker = inflictor ? inflictor : source; mobj_t *part = target->hnext; - angle_t angle = FixedAngle(360*P_RandomFixed(PR_UNDEFINED)); + angle_t angle = FixedAngle(360*P_RandomFixed(PR_ITEM_DEBRIS)); INT16 spacing = (target->radius >> 1) / target->scale; // set respawn fuse @@ -1338,9 +1338,9 @@ void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, UINT8 damaget { mobj_t *puff = P_SpawnMobjFromMobj( target, - P_RandomRange(PR_UNDEFINED, -spacing, spacing) * FRACUNIT, - P_RandomRange(PR_UNDEFINED, -spacing, spacing) * FRACUNIT, - P_RandomRange(PR_UNDEFINED, 0, 4*spacing) * FRACUNIT, + P_RandomRange(PR_ITEM_DEBRIS, -spacing, spacing) * FRACUNIT, + P_RandomRange(PR_ITEM_DEBRIS, -spacing, spacing) * FRACUNIT, + P_RandomRange(PR_ITEM_DEBRIS, 0, 4*spacing) * FRACUNIT, MT_SPINDASHDUST ); @@ -1620,7 +1620,7 @@ void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, UINT8 damaget if (target->info->xdeathstate != S_NULL) { - sprflip = P_RandomChance(PR_UNDEFINED, FRACUNIT/2); + sprflip = P_RandomChance(PR_DECORATION, FRACUNIT/2); #define makechunk(angtweak, xmov, ymov) \ chunk = P_SpawnMobjFromMobj(target, 0, 0, 0, MT_WALLSPIKE);\ @@ -1633,7 +1633,7 @@ void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, UINT8 damaget chunk->y += ymov - forwardyoffs;\ P_SetThingPosition(chunk);\ P_InstaThrust(chunk, angtweak, 4*scale);\ - chunk->momz = P_RandomRange(PR_UNDEFINED, 5, 7)*scale;\ + chunk->momz = P_RandomRange(PR_DECORATION, 5, 7)*scale;\ if (flip)\ chunk->momz *= -1;\ if (sprflip)\ @@ -1646,7 +1646,7 @@ void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, UINT8 damaget #undef makechunk } - sprflip = P_RandomChance(PR_UNDEFINED, FRACUNIT/2); + sprflip = P_RandomChance(PR_DECORATION, FRACUNIT/2); chunk = P_SpawnMobjFromMobj(target, 0, 0, 0, MT_WALLSPIKE); @@ -1659,7 +1659,7 @@ void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, UINT8 damaget chunk->y += forwardyoffs - yoffs; P_SetThingPosition(chunk); P_InstaThrust(chunk, ang + ANGLE_180, 2*scale); - chunk->momz = P_RandomRange(PR_UNDEFINED, 5, 7)*scale; + chunk->momz = P_RandomRange(PR_DECORATION, 5, 7)*scale; if (flip) chunk->momz *= -1; if (sprflip) @@ -1673,7 +1673,7 @@ void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, UINT8 damaget target->y += forwardyoffs + yoffs; P_SetThingPosition(target); P_InstaThrust(target, ang, 2*scale); - target->momz = P_RandomRange(PR_UNDEFINED, 5, 7)*scale; + target->momz = P_RandomRange(PR_DECORATION, 5, 7)*scale; if (flip) target->momz *= -1; if (!sprflip) diff --git a/src/p_mobj.c b/src/p_mobj.c index 72512d3df..363efd8f5 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -92,7 +92,7 @@ static inline INT32 randomframe (mobj_t *mobj, INT32 n) { // Only mobj thinkers should use synced RNG if (mobj->thinker.function.acp1 == (actionf_p1)P_MobjThinker) - return P_RandomKey(PR_UNDEFINED, n); + return P_RandomKey(PR_RANDOMANIM, n); else return M_RandomKey(n); } @@ -316,7 +316,7 @@ boolean P_SetPlayerMobjState(mobj_t *mobj, statenum_t state) } else if (mobj->sprite2 != spr2) { - if ((st->frame & FF_SPR2MIDSTART) && numframes && P_RandomChance(PR_UNDEFINED, FRACUNIT/2)) + if ((st->frame & FF_SPR2MIDSTART) && numframes && P_RandomChance(PR_RANDOMANIM, FRACUNIT/2)) frame = numframes/2; else frame = 0; @@ -442,7 +442,7 @@ boolean P_SetMobjState(mobj_t *mobj, statenum_t state) } else if (mobj->sprite2 != spr2) { - if ((st->frame & FF_SPR2MIDSTART) && numframes && P_RandomChance(PR_UNDEFINED, FRACUNIT/2)) + if ((st->frame & FF_SPR2MIDSTART) && numframes && P_RandomChance(PR_RANDOMANIM, FRACUNIT/2)) frame = numframes/2; else frame = 0; @@ -2503,12 +2503,12 @@ boolean P_ZMovement(mobj_t *mo) // If deafed, give the tumbleweed another random kick if it runs out of steam. mom.z += P_MobjFlip(mo)*FixedMul(6*FRACUNIT, mo->scale); - if (P_RandomChance(PR_UNDEFINED, FRACUNIT/2)) + if (P_RandomChance(PR_DECORATION, FRACUNIT/2)) mom.x += FixedMul(6*FRACUNIT, mo->scale); else mom.x -= FixedMul(6*FRACUNIT, mo->scale); - if (P_RandomChance(PR_UNDEFINED, FRACUNIT/2)) + if (P_RandomChance(PR_DECORATION, FRACUNIT/2)) mom.y += FixedMul(6*FRACUNIT, mo->scale); else mom.y -= FixedMul(6*FRACUNIT, mo->scale); @@ -2531,7 +2531,7 @@ boolean P_ZMovement(mobj_t *mo) else if (mo->type == MT_FALLINGROCK) { if (P_MobjFlip(mo)*mom.z > FixedMul(2*FRACUNIT, mo->scale)) - S_StartSound(mo, mo->info->activesound + P_RandomKey(PR_UNDEFINED, mo->info->reactiontime)); + S_StartSound(mo, mo->info->activesound + P_RandomKey(PR_DECORATION, mo->info->reactiontime)); mom.z /= 2; // Rocks not so bouncy @@ -2983,7 +2983,7 @@ boolean P_SceneryZMovement(mobj_t *mo) for (i = 0; i < 4; ++i) // split into four { - prandom = P_RandomByte(PR_UNDEFINED); + prandom = P_RandomByte(PR_BUBBLE); explodemo = P_SpawnMobj(mo->x, mo->y, mo->z, MT_SMALLBUBBLE); explodemo->momx += ((prandom & 0x0F) << (FRACBITS-2)) * (i & 2 ? -1 : 1); explodemo->momy += ((prandom & 0xF0) << (FRACBITS-6)) * (i & 1 ? -1 : 1); @@ -2992,7 +2992,7 @@ boolean P_SceneryZMovement(mobj_t *mo) } if (mo->threshold != 42) // Don't make pop sound if threshold is 42. - S_StartSound(explodemo, sfx_bubbl1 + P_RandomKey(PR_UNDEFINED, 5)); + S_StartSound(explodemo, sfx_bubbl1 + P_RandomKey(PR_BUBBLE, 5)); //note that we assign the bubble sound to one of the new bubbles. // in other words, IT ACTUALLY GETS USED YAAAAAAAY @@ -3378,10 +3378,10 @@ void P_MobjCheckWater(mobj_t *mobj) // P_RandomByte()s are called individually to allow consistency // across various compilers, since the order of function calls // in C is not part of the ANSI specification. - prandom[0] = P_RandomByte(PR_UNDEFINED); - prandom[1] = P_RandomByte(PR_UNDEFINED); - prandom[2] = P_RandomByte(PR_UNDEFINED); - prandom[3] = P_RandomByte(PR_UNDEFINED); + prandom[0] = P_RandomByte(PR_BUBBLE); + prandom[1] = P_RandomByte(PR_BUBBLE); + prandom[2] = P_RandomByte(PR_BUBBLE); + prandom[3] = P_RandomByte(PR_BUBBLE); bubbletype = MT_SMALLBUBBLE; if (!(prandom[0] & 0x3)) // medium bubble chance up to 64 from 32 @@ -5408,7 +5408,7 @@ static boolean P_ParticleGenSceneryThink(mobj_t *mobj) spawn->scalespeed = spawn->scale/mobj->health; spawn->tics = (tic_t)mobj->health; spawn->flags2 |= (mobj->flags2 & MF2_OBJECTFLIP); - spawn->angle += P_RandomKey(PR_UNDEFINED, 36)*ANG10; // irrelevant for default objects but might make sense for some custom ones + spawn->angle += P_RandomKey(PR_DECORATION, 36)*ANG10; // irrelevant for default objects but might make sense for some custom ones mobj->angle += mobj->movedir; } @@ -5519,7 +5519,7 @@ static void P_MobjSceneryThink(mobj_t *mobj) { mobj->health = 0; P_SetMobjState(mobj, mobj->info->deathstate); - S_StartSound(mobj, mobj->info->deathsound + P_RandomKey(PR_UNDEFINED, mobj->info->mass)); + S_StartSound(mobj, mobj->info->deathsound + P_RandomKey(PR_DECORATION, mobj->info->mass)); return; } break; @@ -5672,22 +5672,22 @@ static void P_MobjSceneryThink(mobj_t *mobj) case MT_SMOLDERING: if (leveltime % 2 == 0) { - fixed_t x = P_RandomRange(PR_UNDEFINED, -35, 35)*mobj->scale; - fixed_t y = P_RandomRange(PR_UNDEFINED, -35, 35)*mobj->scale; - fixed_t z = P_RandomRange(PR_UNDEFINED, 0, 70)*mobj->scale; + fixed_t x = P_RandomRange(PR_SMOLDERING, -35, 35)*mobj->scale; + fixed_t y = P_RandomRange(PR_SMOLDERING, -35, 35)*mobj->scale; + fixed_t z = P_RandomRange(PR_SMOLDERING, 0, 70)*mobj->scale; mobj_t *smoke = P_SpawnMobj(mobj->x + x, mobj->y + y, mobj->z + z, MT_SMOKE); P_SetMobjState(smoke, S_OPAQUESMOKE1); K_MatchGenericExtraFlags(smoke, mobj); smoke->scale = mobj->scale * 2; smoke->destscale = mobj->scale * 6; - smoke->momz = P_RandomRange(PR_UNDEFINED, 4, 9)*FRACUNIT*P_MobjFlip(smoke); + smoke->momz = P_RandomRange(PR_SMOLDERING, 4, 9)*FRACUNIT*P_MobjFlip(smoke); } break; case MT_BOOMPARTICLE: { - fixed_t x = P_RandomRange(PR_UNDEFINED, -16, 16)*mobj->scale; - fixed_t y = P_RandomRange(PR_UNDEFINED, -16, 16)*mobj->scale; - fixed_t z = P_RandomRange(PR_UNDEFINED, 0, 32)*mobj->scale*P_MobjFlip(mobj); + fixed_t x = P_RandomRange(PR_EXPLOSION, -16, 16)*mobj->scale; + fixed_t y = P_RandomRange(PR_EXPLOSION, -16, 16)*mobj->scale; + fixed_t z = P_RandomRange(PR_EXPLOSION, 0, 32)*mobj->scale*P_MobjFlip(mobj); if (leveltime % 2 == 0) { mobj_t *smoke = P_SpawnMobj(mobj->x + x, mobj->y + y, mobj->z + z, MT_BOSSEXPLODE); @@ -5772,9 +5772,9 @@ static void P_MobjSceneryThink(mobj_t *mobj) { mobj_t *debris = P_SpawnMobjFromMobj( mobj, - P_RandomRange(PR_UNDEFINED, -spacing, spacing) * FRACUNIT, - P_RandomRange(PR_UNDEFINED, -spacing, spacing) * FRACUNIT, - P_RandomRange(PR_UNDEFINED, -spacing, spacing) * FRACUNIT, + P_RandomRange(PR_ITEM_RINGS, -spacing, spacing) * FRACUNIT, + P_RandomRange(PR_ITEM_RINGS, -spacing, spacing) * FRACUNIT, + P_RandomRange(PR_ITEM_RINGS, -spacing, spacing) * FRACUNIT, MT_BATTLEBUMPER_DEBRIS ); @@ -5803,9 +5803,9 @@ static void P_MobjSceneryThink(mobj_t *mobj) { mobj_t *puff = P_SpawnMobjFromMobj( mobj, - P_RandomRange(PR_UNDEFINED, -spacing, spacing) * FRACUNIT, - P_RandomRange(PR_UNDEFINED, -spacing, spacing) * FRACUNIT, - P_RandomRange(PR_UNDEFINED, -spacing, spacing) * FRACUNIT, + P_RandomRange(PR_ITEM_RINGS, -spacing, spacing) * FRACUNIT, + P_RandomRange(PR_ITEM_RINGS, -spacing, spacing) * FRACUNIT, + P_RandomRange(PR_ITEM_RINGS, -spacing, spacing) * FRACUNIT, MT_SPINDASHDUST ); @@ -6396,9 +6396,9 @@ static boolean P_MobjDeadThink(mobj_t *mobj) for (i = 0; i < 2; i++) { - fixed_t xoffset = P_RandomRange(PR_UNDEFINED, -amt, amt) * mobj->scale; - fixed_t yoffset = P_RandomRange(PR_UNDEFINED, -amt, amt) * mobj->scale; - fixed_t zoffset = P_RandomRange(PR_UNDEFINED, -(amt >> 1), (amt >> 1)) * mobj->scale; + fixed_t xoffset = P_RandomRange(PR_ITEM_DEBRIS, -amt, amt) * mobj->scale; + fixed_t yoffset = P_RandomRange(PR_ITEM_DEBRIS, -amt, amt) * mobj->scale; + fixed_t zoffset = P_RandomRange(PR_ITEM_DEBRIS, -(amt >> 1), (amt >> 1)) * mobj->scale; dust = P_SpawnMobj(mobj->x + xoffset, mobj->y + yoffset, mobj->z + (mobj->height >> 1) + zoffset, MT_EXPLODE); @@ -7066,9 +7066,9 @@ static boolean P_MobjRegularThink(mobj_t *mobj) { mobj_t *sparkle = P_SpawnMobjFromMobj( mobj, - P_RandomRange(PR_UNDEFINED, -48, 48) * FRACUNIT, - P_RandomRange(PR_UNDEFINED, -48, 48) * FRACUNIT, - P_RandomRange(PR_UNDEFINED, 0, 64) * FRACUNIT, + P_RandomRange(PR_SPARKLE, -48, 48) * FRACUNIT, + P_RandomRange(PR_SPARKLE, -48, 48) * FRACUNIT, + P_RandomRange(PR_SPARKLE, 0, 64) * FRACUNIT, MT_EMERALDSPARK ); @@ -7304,7 +7304,7 @@ static boolean P_MobjRegularThink(mobj_t *mobj) smoke->momy = mobj->target->momy/2; smoke->momz = mobj->target->momz/2; - P_Thrust(smoke, mobj->angle+FixedAngle(P_RandomRange(PR_UNDEFINED, 135, 225)<target->scale); + P_Thrust(smoke, mobj->angle+FixedAngle(P_RandomRange(PR_ITEM_BOOST, 135, 225)<target->scale); } break; case MT_INVULNFLASH: @@ -7761,9 +7761,9 @@ static boolean P_MobjRegularThink(mobj_t *mobj) for (i = 0; i < nl; i++) { - mobj_t *fast = P_SpawnMobj(mobj->x + (P_RandomRange(PR_UNDEFINED, -36,36) * mobj->scale), - mobj->y + (P_RandomRange(PR_UNDEFINED, -36,36) * mobj->scale), - mobj->z + (mobj->height/2) + (P_RandomRange(PR_UNDEFINED, -20,20) * mobj->scale), + mobj_t *fast = P_SpawnMobj(mobj->x + (P_RandomRange(PR_ITEM_BOOST, -36,36) * mobj->scale), + mobj->y + (P_RandomRange(PR_ITEM_BOOST, -36,36) * mobj->scale), + mobj->z + (mobj->height/2) + (P_RandomRange(PR_ITEM_BOOST, -20,20) * mobj->scale), MT_FASTLINE); P_InitAngle(fast, mobj->angle); @@ -8030,7 +8030,7 @@ static boolean P_MobjRegularThink(mobj_t *mobj) else { // Pick another player in the server! - player_t *p = &players[plist[P_RandomKey(PR_UNDEFINED, plistlen)]]; + player_t *p = &players[plist[P_RandomKey(PR_SPARKLE, plistlen)]]; newskin = ((skin_t*)p->mo->skin) - skins; newcolor = p->skincolor; } @@ -8102,7 +8102,7 @@ static boolean P_MobjRegularThink(mobj_t *mobj) mobj->movecount = 3; { - angle_t facing = P_RandomRange(PR_UNDEFINED, 0, 90); + angle_t facing = P_RandomRange(PR_MOVINGTARGET, 0, 90); if (facing >= 45) facing = InvAngle((facing - 45)*ANG1); else @@ -8135,23 +8135,23 @@ static boolean P_MobjRegularThink(mobj_t *mobj) else // fire + smoke pillar { UINT8 i; - mobj_t *fire = P_SpawnMobj(mobj->x + (P_RandomRange(PR_UNDEFINED, -32, 32)*mobj->scale), mobj->y + (P_RandomRange(PR_UNDEFINED, -32, 32)*mobj->scale), mobj->z, MT_THOK); + mobj_t *fire = P_SpawnMobj(mobj->x + (P_RandomRange(PR_SMOLDERING, -32, 32)*mobj->scale), mobj->y + (P_RandomRange(PR_SMOLDERING, -32, 32)*mobj->scale), mobj->z, MT_THOK); fire->sprite = SPR_FPRT; fire->frame = FF_FULLBRIGHT|FF_TRANS30; fire->scale = mobj->scale*4; - fire->momz = P_RandomRange(PR_UNDEFINED, 2, 3)*mobj->scale; + fire->momz = P_RandomRange(PR_SMOLDERING, 2, 3)*mobj->scale; fire->scalespeed = mobj->scale/12; fire->destscale = 1; fire->tics = TICRATE; for (i = 0; i < 2; i++) { - mobj_t *smoke = P_SpawnMobj(mobj->x + (P_RandomRange(PR_UNDEFINED, -16, 16)*mobj->scale), mobj->y + (P_RandomRange(PR_UNDEFINED, -16, 16)*mobj->scale), mobj->z, MT_SMOKE); + mobj_t *smoke = P_SpawnMobj(mobj->x + (P_RandomRange(PR_SMOLDERING, -16, 16)*mobj->scale), mobj->y + (P_RandomRange(PR_SMOLDERING, -16, 16)*mobj->scale), mobj->z, MT_SMOKE); P_SetMobjState(smoke, S_FZSLOWSMOKE1); smoke->scale = mobj->scale; - smoke->momz = P_RandomRange(PR_UNDEFINED, 3, 10)*mobj->scale; + smoke->momz = P_RandomRange(PR_SMOLDERING, 3, 10)*mobj->scale; smoke->destscale = mobj->scale*4; smoke->scalespeed = mobj->scale/24; } @@ -8647,7 +8647,7 @@ static boolean P_MobjRegularThink(mobj_t *mobj) P_MoveOrigin(mobj, mobj->tracer->x + P_ReturnThrustX(NULL, mobj->tracer->angle+ANGLE_90, (mobj->cvmem)<tracer->y + P_ReturnThrustY(NULL, mobj->tracer->angle+ANGLE_90, (mobj->cvmem)<tracer->z - (4*mobj->tracer->scale) + (P_RandomRange(PR_UNDEFINED, -abs(mobj->cvmem), abs(mobj->cvmem))<tracer->z - (4*mobj->tracer->scale) + (P_RandomRange(PR_ITEM_BUBBLE, -abs(mobj->cvmem), abs(mobj->cvmem))<movecount > 4*TICRATE) { @@ -9264,9 +9264,9 @@ static boolean P_FuseThink(mobj_t *mobj) for (i = 0; i < 5; i++) { mobj_t *debris = P_SpawnMobj(mobj->x, mobj->y, mobj->z, MT_SMK_ICEBLOCK_DEBRIS); - P_InitAngle(debris, FixedAngle(P_RandomRange(PR_UNDEFINED, 0,360)<angle, P_RandomRange(PR_UNDEFINED, 3,18)*(FRACUNIT/4)); - debris->momz = P_RandomRange(PR_UNDEFINED, 4,8)<angle, P_RandomRange(PR_DECORATION, 3,18)*(FRACUNIT/4)); + debris->momz = P_RandomRange(PR_DECORATION, 4,8)<color = BALLOONCOLORS[P_RandomKey(PR_UNDEFINED, sizeof(BALLOONCOLORS))]; + mobj->color = BALLOONCOLORS[P_RandomKey(PR_DECORATION, sizeof(BALLOONCOLORS))]; } break; case MT_POGOSPRING: @@ -10163,8 +10163,8 @@ mobj_t *P_SpawnMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type) mobj->color = SKINCOLOR_RED; break; case MT_EGGROBO1: - mobj->movecount = P_RandomKey(PR_UNDEFINED, 13); - mobj->color = FIRSTRAINBOWCOLOR + P_RandomKey(PR_UNDEFINED, FIRSTSUPERCOLOR - FIRSTRAINBOWCOLOR); + mobj->movecount = P_RandomKey(PR_DECORATION, 13); + mobj->color = FIRSTRAINBOWCOLOR + P_RandomKey(PR_DECORATION, FIRSTSUPERCOLOR - FIRSTRAINBOWCOLOR); break; case MT_HIVEELEMENTAL: mobj->extravalue1 = 5; @@ -10260,15 +10260,15 @@ mobj_t *P_SpawnMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type) { // set default item & count #if 0 // set to 1 to test capsules with random items, e.g. with objectplace - if (P_RandomChance(PR_UNDEFINED, FRACUNIT/3)) + if (P_RandomChance(PR_ITEM_ROULETTE, FRACUNIT/3)) mobj->threshold = KITEM_SUPERRING; - else if (P_RandomChance(PR_UNDEFINED, FRACUNIT/3)) + else if (P_RandomChance(PR_ITEM_ROULETTE, FRACUNIT/3)) mobj->threshold = KITEM_SPB; - else if (P_RandomChance(PR_UNDEFINED, FRACUNIT/3)) + else if (P_RandomChance(PR_ITEM_ROULETTE, FRACUNIT/3)) mobj->threshold = KITEM_ORBINAUT; else - mobj->threshold = P_RandomRange(PR_UNDEFINED, 1, NUMKARTITEMS - 1); - mobj->movecount = P_RandomChance(PR_UNDEFINED, FRACUNIT/3) ? 1 : P_RandomKey(PR_UNDEFINED, 32) + 1; + mobj->threshold = P_RandomRange(PR_ITEM_ROULETTE, 1, NUMKARTITEMS - 1); + mobj->movecount = P_RandomChance(PR_ITEM_ROULETTE, FRACUNIT/3) ? 1 : P_RandomKey(PR_ITEM_ROULETTE, 32) + 1; #else mobj->threshold = KITEM_SUPERRING; // default item is super ring mobj->movecount = 1; @@ -10412,8 +10412,8 @@ mobj_t *P_SpawnMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type) UINT16 i; for (i = 0; i < mobj->info->mass; i++) { - fixed_t newx = mobj->x + (P_RandomRange(PR_UNDEFINED, -mobj->info->mass, mobj->info->mass)<y + (P_RandomRange(PR_UNDEFINED, -mobj->info->mass, mobj->info->mass)<x + (P_RandomRange(PR_DECORATION, -mobj->info->mass, mobj->info->mass)<y + (P_RandomRange(PR_DECORATION, -mobj->info->mass, mobj->info->mass)<z, 8<z) P_SpawnMobj(newx, newy, mobj->z, MT_EERIEFOG); @@ -10956,7 +10956,7 @@ void P_PrecipitationEffects(void) // with global rain and switched players to anything else ... // If the global weather has lightning strikes, // EVERYONE gets them at the SAME time! - thunderchance = (P_RandomKey(PR_UNDEFINED, 8192)); + thunderchance = (P_RandomKey(PR_DECORATION, 8192)); } else if (sounds_thunder || effects_lightning) { @@ -12548,8 +12548,8 @@ static boolean P_SetupSpawnedMapThing(mapthing_t *mthing, mobj_t *mobj, boolean if (mthing->options & MTF_AMBUSH) { fixed_t offset = FixedMul(16*FRACUNIT, mobj->scale); - mobj->momx += P_RandomChance(PR_UNDEFINED, FRACUNIT/2) ? offset : -offset; - mobj->momy += P_RandomChance(PR_UNDEFINED, FRACUNIT/2) ? offset : -offset; + mobj->momx += P_RandomChance(PR_DECORATION, FRACUNIT/2) ? offset : -offset; + mobj->momy += P_RandomChance(PR_DECORATION, FRACUNIT/2) ? offset : -offset; mobj->momz += offset; } break; diff --git a/src/p_spec.c b/src/p_spec.c index a626e9f2b..103feeaf3 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -3298,9 +3298,9 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) INT32 result; if (rvalue1 <= rvalue2) - result = P_RandomRange(PR_UNDEFINED, rvalue1, rvalue2); + result = P_RandomRange(PR_EXECUTOR, rvalue1, rvalue2); else - result = P_RandomRange(PR_UNDEFINED, rvalue2, rvalue1); + result = P_RandomRange(PR_EXECUTOR, rvalue2, rvalue1); P_LinedefExecute((INT16)result, mo, NULL); break; diff --git a/src/p_user.c b/src/p_user.c index 6da4e9a9c..bac399ab4 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -1746,12 +1746,12 @@ static void P_DoBubbleBreath(player_t *player) if (player->charflags & SF_MACHINE) { - if (P_RandomChance(PR_UNDEFINED, FRACUNIT/5)) + if (P_RandomChance(PR_BUBBLE, FRACUNIT/5)) { fixed_t r = player->mo->radius>>FRACBITS; - x += (P_RandomRange(PR_UNDEFINED, r, -r)<mo->height>>FRACBITS)<mo->height>>FRACBITS)<mo->height,5*(FRACUNIT/4)); - if (P_RandomChance(PR_UNDEFINED, FRACUNIT/16)) + if (P_RandomChance(PR_BUBBLE, FRACUNIT/16)) bubble = P_SpawnMobj(x, y, z, MT_SMALLBUBBLE); - else if (P_RandomChance(PR_UNDEFINED, 3*FRACUNIT/256)) + else if (P_RandomChance(PR_BUBBLE, 3*FRACUNIT/256)) bubble = P_SpawnMobj(x, y, z, MT_MEDIUMBUBBLE); } @@ -2381,7 +2381,7 @@ void P_MovePlayer(player_t *player) // Little water sound while touching water - just a nicety. if ((player->mo->eflags & MFE_TOUCHWATER) && !(player->mo->eflags & MFE_UNDERWATER) && !player->spectator) { - if (P_RandomChance(PR_UNDEFINED, FRACUNIT/2) && leveltime % TICRATE == 0) + if (P_RandomChance(PR_BUBBLE, FRACUNIT/2) && leveltime % TICRATE == 0) S_StartSound(player->mo, sfx_floush); } @@ -3717,7 +3717,7 @@ boolean P_SpectatorJoinGame(player_t *player) else if (redscore > bluescore) changeto = 2; else - changeto = (P_RandomFixed(PR_UNDEFINED) & 1) + 1; + changeto = (P_RandomFixed(PR_RULESCRAMBLE) & 1) + 1; if (!LUA_HookTeamSwitch(player, changeto, true, false, false)) return false; From 3e4edc534d0943433548fdf110e3724ebbf8fb41 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Sun, 25 Sep 2022 07:02:39 -0400 Subject: [PATCH 07/10] Remove strange RNG sync hack Previously it was using P_SetRandSeed, which sets both initial and current seed to the same thing, since it's meant for level load init. It first set all RNG seeds to the current seed, and then it set all of the seeds to their initial value. The comment about this just says its "stupid and hacky", and I have no idea how it even worked before. Now we send over both init seed and current seed independently and set them both. Hopefully this will fix the desyncs. --- src/m_random.c | 27 +++++++++++++++++++++++++-- src/m_random.h | 3 +++ src/p_saveg.c | 42 ++++++++++++++++++++++++++---------------- 3 files changed, 54 insertions(+), 18 deletions(-) diff --git a/src/m_random.c b/src/m_random.c index 8a59db7c1..166c6bf2e 100644 --- a/src/m_random.c +++ b/src/m_random.c @@ -231,7 +231,7 @@ UINT32 P_GetInitSeedD(const char *rfile, INT32 rline, pr_class_t pr_class) } /** Sets the random seed. - * Used at the beginning of the game, and also for netgames. + * Used at the beginning of a game. * * \param pr_class RNG class to adjust. * \param seed New random seed. @@ -251,8 +251,31 @@ void P_SetRandSeedD(const char *rfile, INT32 rline, pr_class_t pr_class, UINT32 rng.seed[pr_class] = rng.init[pr_class] = seed; } +/** Sets both the initial seed and the current seed. + * Used for netgame sync. + * + * \param pr_class RNG class to adjust. + * \param init Sent initial seed. + * \param seed Sent current seed. + * \sa P_SetRandSeed + */ +#ifndef DEBUGRANDOM +void P_SetRandSeedNet(pr_class_t pr_class, UINT32 init, UINT32 seed) +{ +#else +void P_SetRandSeedNetD(const char *rfile, INT32 rline, pr_class_t pr_class, UINT32 init, UINT32 seed) +{ + CONS_Printf("P_SetRandSeedNet(%u) at: %sp %d\n", pr_class, rfile, rline); +#endif + if (!init) init = DEFAULT_SEED; + rng.init[pr_class] = init; + + if (!seed) seed = DEFAULT_SEED; + rng.seed[pr_class] = seed; +} + /** Initializes random seeds for all classes. - * Used at the beginning of the game. + * Used at the beginning of a game. * * \param rindex New random index. * \sa P_SetRandSeed diff --git a/src/m_random.h b/src/m_random.h index bf3884eec..6f534b219 100644 --- a/src/m_random.h +++ b/src/m_random.h @@ -106,13 +106,16 @@ fixed_t P_RandomPeek(pr_class_t pr_class); #define P_GetRandSeed(pr) P_GetRandSeedD(__FILE__, __LINE__, pr) #define P_GetInitSeed(pr) P_GetInitSeedD(__FILE__, __LINE__, pr) #define P_SetRandSeed(pr, s) P_SetRandSeedD(__FILE__, __LINE__, pr, s) +#define P_SetRandSeedNet(pr, i, s) P_SetRandSeedD(__FILE__, __LINE__, pr, i, s) UINT32 P_GetRandSeedD(const char *rfile, INT32 rline, pr_class_t pr_class); UINT32 P_GetInitSeedD(const char *rfile, INT32 rline, pr_class_t pr_class); void P_SetRandSeedD(const char *rfile, INT32 rline, pr_class_t pr_class, UINT32 seed); +void P_SetRandSeedNetD(const char *rfile, INT32 rline, pr_class_t pr_class, UINT32 init, UINT32 seed); #else UINT32 P_GetRandSeed(pr_class_t pr_class); UINT32 P_GetInitSeed(pr_class_t pr_class); void P_SetRandSeed(pr_class_t pr_class, UINT32 seed); +void P_SetRandSeedNet(pr_class_t pr_class, UINT32 init, UINT32 seed); #endif void P_ClearRandom(UINT32 seed); diff --git a/src/p_saveg.c b/src/p_saveg.c index d7756f0f7..b668c322b 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -4452,6 +4452,17 @@ static inline void P_UnArchiveSPGame(INT16 mapoverride) playeringame[consoleplayer] = true; } +static void P_NetArchiveRNG(void) +{ + size_t i; + + for (i = 0; i < PRNUMCLASS; i++) + { + WRITEUINT32(save_p, P_GetInitSeed(i)); + WRITEUINT32(save_p, P_GetRandSeed(i)); + } +} + static void P_NetArchiveMisc(boolean resending) { size_t i; @@ -4475,10 +4486,7 @@ static void P_NetArchiveMisc(boolean resending) WRITEUINT32(save_p, pig); } - for (i = 0; i < PRNUMCLASS; i++) - { - WRITEUINT32(save_p, P_GetRandSeed(i)); - } + P_NetArchiveRNG(); WRITEUINT32(save_p, tokenlist); @@ -4602,6 +4610,19 @@ static void P_NetArchiveMisc(boolean resending) } } +static inline void P_NetUnArchiveRNG(void) +{ + size_t i; + + for (i = 0; i < PRNUMCLASS; i++) + { + UINT32 init = READUINT32(save_p); + UINT32 seed = READUINT32(save_p); + + P_SetRandSeedNet(i, init, seed); + } +} + static inline boolean P_NetUnArchiveMisc(boolean reloading) { size_t i; @@ -4638,10 +4659,7 @@ static inline boolean P_NetUnArchiveMisc(boolean reloading) } } - for (i = 0; i < PRNUMCLASS; i++) - { - P_SetRandSeed(i, READUINT32(save_p)); - } + P_NetUnArchiveRNG(); tokenlist = READUINT32(save_p); @@ -4894,8 +4912,6 @@ boolean P_LoadGame(INT16 mapoverride) boolean P_LoadNetGame(boolean reloading) { - size_t i; - CV_LoadNetVars(&save_p); if (!P_NetUnArchiveMisc(reloading)) @@ -4918,12 +4934,6 @@ boolean P_LoadNetGame(boolean reloading) LUA_UnArchive(&save_p); - // This is stupid and hacky, but maybe it'll work! - for (i = 0; i < PRNUMCLASS; i++) - { - P_SetRandSeed(i, P_GetInitSeed(i)); - } - // The precipitation would normally be spawned in P_SetupLevel, which is called by // P_NetUnArchiveMisc above. However, that would place it up before P_NetUnArchiveThinkers, // so the thinkers would be deleted later. Therefore, P_SetupLevel will *not* spawn From 4c3c588e3ab0a5cdd975921d2ac851cf66760e13 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Sun, 25 Sep 2022 15:30:50 -0400 Subject: [PATCH 08/10] Fix compile --- src/g_demo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/g_demo.c b/src/g_demo.c index 5f1d8377f..c039d80d1 100644 --- a/src/g_demo.c +++ b/src/g_demo.c @@ -3137,7 +3137,7 @@ void G_DoPlayDemo(char *defdemoname) P_SetRandSeed(i, randseed[i]); } - G_InitNew(demoflags & DF_ENCORE, G_BuildMapName(gamemap), true, true, false); // Doesn't matter whether you reset or not here, given changes to resetplayer. + G_InitNew(demoflags & DF_ENCORE, gamemap, true, true, false); // Doesn't matter whether you reset or not here, given changes to resetplayer. for (i = 0; i < MAXPLAYERS; i++) { From ba62851a852d660dbb798bce67fc5653fbddc843 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Sun, 25 Sep 2022 15:50:41 -0400 Subject: [PATCH 09/10] Make entire archive block for RNG Also moved after Lua to remove the desyncs. --- src/p_saveg.c | 62 ++++++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/src/p_saveg.c b/src/p_saveg.c index 13f417414..284eb8956 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -53,6 +53,7 @@ UINT8 *save_p; #define ARCHIVEBLOCK_THINKERS 0x7F37037C #define ARCHIVEBLOCK_SPECIALS 0x7F228378 #define ARCHIVEBLOCK_WAYPOINTS 0x7F46498F +#define ARCHIVEBLOCK_RNG 0x7FAAB5BD // Note: This cannot be bigger // than an UINT16 @@ -4452,17 +4453,6 @@ static inline void P_UnArchiveSPGame(INT16 mapoverride) playeringame[consoleplayer] = true; } -static void P_NetArchiveRNG(void) -{ - size_t i; - - for (i = 0; i < PRNUMCLASS; i++) - { - WRITEUINT32(save_p, P_GetInitSeed(i)); - WRITEUINT32(save_p, P_GetRandSeed(i)); - } -} - static void P_NetArchiveMisc(boolean resending) { size_t i; @@ -4486,8 +4476,6 @@ static void P_NetArchiveMisc(boolean resending) WRITEUINT32(save_p, pig); } - P_NetArchiveRNG(); - WRITEUINT32(save_p, tokenlist); WRITEUINT8(save_p, encoremode); @@ -4605,19 +4593,6 @@ static void P_NetArchiveMisc(boolean resending) } } -static inline void P_NetUnArchiveRNG(void) -{ - size_t i; - - for (i = 0; i < PRNUMCLASS; i++) - { - UINT32 init = READUINT32(save_p); - UINT32 seed = READUINT32(save_p); - - P_SetRandSeedNet(i, init, seed); - } -} - static inline boolean P_NetUnArchiveMisc(boolean reloading) { size_t i; @@ -4654,8 +4629,6 @@ static inline boolean P_NetUnArchiveMisc(boolean reloading) } } - P_NetUnArchiveRNG(); - tokenlist = READUINT32(save_p); encoremode = (boolean)READUINT8(save_p); @@ -4832,6 +4805,35 @@ static inline boolean P_UnArchiveLuabanksAndConsistency(void) return true; } +static void P_NetArchiveRNG(void) +{ + size_t i; + + WRITEUINT32(save_p, ARCHIVEBLOCK_RNG); + + for (i = 0; i < PRNUMCLASS; i++) + { + WRITEUINT32(save_p, P_GetInitSeed(i)); + WRITEUINT32(save_p, P_GetRandSeed(i)); + } +} + +static inline void P_NetUnArchiveRNG(void) +{ + size_t i; + + if (READUINT32(save_p) != ARCHIVEBLOCK_RNG) + I_Error("Bad $$$.sav at archive block RNG"); + + for (i = 0; i < PRNUMCLASS; i++) + { + UINT32 init = READUINT32(save_p); + UINT32 seed = READUINT32(save_p); + + P_SetRandSeedNet(i, init, seed); + } +} + void P_SaveGame(INT16 mapnum) { P_ArchiveMisc(mapnum); @@ -4876,6 +4878,8 @@ void P_SaveNetGame(boolean resending) } LUA_Archive(&save_p); + P_NetArchiveRNG(); + P_ArchiveLuabanksAndConsistency(); } @@ -4924,6 +4928,8 @@ boolean P_LoadNetGame(boolean reloading) LUA_UnArchive(&save_p); + P_NetUnArchiveRNG(); + // The precipitation would normally be spawned in P_SetupLevel, which is called by // P_NetUnArchiveMisc above. However, that would place it up before P_NetUnArchiveThinkers, // so the thinkers would be deleted later. Therefore, P_SetupLevel will *not* spawn From 5fb37b634f00d42788de52459f78c0bd5c0036d2 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Sun, 25 Sep 2022 17:05:59 -0400 Subject: [PATCH 10/10] Fix RNG + map reads in demo code --- src/g_demo.c | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/g_demo.c b/src/g_demo.c index c039d80d1..09e5a9bdd 100644 --- a/src/g_demo.c +++ b/src/g_demo.c @@ -1142,7 +1142,13 @@ void G_GhostTicker(void) g->p++; // ditto } else if (ziptic == DW_RNG) - g->p += 4; // RNG seed + { + INT32 i; + for (i = 0; i < PRNUMCLASS; i++) + { + g->p += 4; // RNG seed + } + } else I_Error("Ghost is not a record attack ghost DXD"); //@TODO lmao don't blow up like this @@ -2541,6 +2547,8 @@ void G_LoadDemoInfo(menudemo_t *pdemo) UINT8 *infobuffer, *info_p, *extrainfo_p; UINT8 version, subversion, pdemoflags; UINT16 pdemoversion, count; + char mapname[MAXMAPLUMPNAME]; + INT32 i; if (!FIL_ReadFile(pdemo->filepath, &infobuffer)) { @@ -2600,7 +2608,8 @@ void G_LoadDemoInfo(menudemo_t *pdemo) return; } info_p += 4; // "PLAY" - pdemo->map = READINT16(info_p); + READSTRINGN(info_p, mapname, sizeof(mapname)); + pdemo->map = G_MapNumber(mapname); info_p += 16; // mapmd5 pdemoflags = READUINT8(info_p); @@ -2617,7 +2626,11 @@ void G_LoadDemoInfo(menudemo_t *pdemo) pdemo->numlaps = READUINT8(info_p); pdemo->addonstatus = G_CheckDemoExtraFiles(&info_p, true); - info_p += 4; // RNG seed + + for (i = 0; i < PRNUMCLASS; i++) + { + info_p += 4; // RNG seed + } extrainfo_p = infobuffer + READUINT32(info_p); // The extra UINT32 read is for a blank 4 bytes? @@ -2651,7 +2664,6 @@ void G_LoadDemoInfo(menudemo_t *pdemo) while (READUINT8(extrainfo_p) == DW_STANDING) // Assume standings are always first in the extrainfo { - INT32 i; char temp[16]; pdemo->standings[count].ranking = READUINT8(extrainfo_p); @@ -3290,7 +3302,11 @@ void G_AddGhost(char *defdemoname) break; } - p += 4; // random seed + for (i = 0; i < PRNUMCLASS; i++) + { + p += 4; // random seed + } + p += 4; // Extra data location reference // net var data @@ -3448,6 +3464,7 @@ void G_UpdateStaffGhostName(lumpnum_t l) UINT8 *buffer,*p; UINT16 ghostversion; UINT8 flags; + INT32 i; buffer = p = W_CacheLumpNum(l, PU_CACHE); @@ -3508,7 +3525,11 @@ void G_UpdateStaffGhostName(lumpnum_t l) break; } - p += 4; // random seed + for (i = 0; i < PRNUMCLASS; i++) + { + p += 4; // random seed + } + p += 4; // Extrainfo location marker // Ehhhh don't need ghostversion here (?) so I'll reuse the var here