Merge branch 'rng-states-2' into 'master'

RNG classes, take 2

See merge request KartKrew/Kart!686
This commit is contained in:
Sal 2022-09-25 21:18:42 +00:00
commit 13ad2fc4d1
27 changed files with 652 additions and 537 deletions

View file

@ -5020,7 +5020,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)

View file

@ -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"
@ -1225,6 +1226,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();

View file

@ -3012,7 +3012,7 @@ static void Got_Mapcmd(UINT8 **cp, INT32 playernum)
mapnumber = READINT16(*cp);
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.

View file

@ -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));
}
}
}
@ -1134,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
@ -2035,7 +2049,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;
@ -2530,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))
{
@ -2589,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);
@ -2606,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?
@ -2640,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);
@ -2705,7 +2728,7 @@ void G_DoPlayDemo(char *defdemoname)
lumpnum_t l;
char skin[17],color[MAXCOLORNAME+1],follower[17],mapname[MAXMAPLUMPNAME],*n,*pdemoname;
UINT8 version,subversion;
UINT32 randseed;
UINT32 randseed[PRNUMCLASS];
char msg[1024];
boolean spectator;
@ -2914,7 +2937,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
@ -3118,7 +3144,11 @@ 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, gamemap, true, true, false); // Doesn't matter whether you reset or not here, given changes to resetplayer.
for (i = 0; i < MAXPLAYERS; i++)
@ -3272,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
@ -3430,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);
@ -3490,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
@ -3624,7 +3663,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

View file

@ -2570,7 +2570,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_PLAYERSTARTS, FRACUNIT/2))) || players[playernum].ctfteam == 1) //red
{
if (!numredctfstarts)
{
@ -2581,7 +2581,7 @@ mapthing_t *G_FindTeamStart(INT32 playernum)
for (j = 0; j < 32; j++)
{
i = P_RandomKey(numredctfstarts);
i = P_RandomKey(PR_PLAYERSTARTS, numredctfstarts);
if (G_CheckSpot(playernum, redctfstarts[i]))
return redctfstarts[i];
}
@ -2601,7 +2601,7 @@ mapthing_t *G_FindTeamStart(INT32 playernum)
for (j = 0; j < 32; j++)
{
i = P_RandomKey(numbluectfstarts);
i = P_RandomKey(PR_PLAYERSTARTS, numbluectfstarts);
if (G_CheckSpot(playernum, bluectfstarts[i]))
return bluectfstarts[i];
}
@ -2622,7 +2622,7 @@ mapthing_t *G_FindBattleStart(INT32 playernum)
{
for (j = 0; j < 64; j++)
{
i = P_RandomKey(numdmstarts);
i = P_RandomKey(PR_PLAYERSTARTS, numdmstarts);
if (G_CheckSpot(playernum, deathmatchstarts[i]))
return deathmatchstarts[i];
}
@ -4721,7 +4721,7 @@ void G_InitNew(UINT8 pencoremode, INT32 map, boolean resetplayer, boolean skippr
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;

View file

@ -212,7 +212,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_ITEM_ROULETTE) * 180) + angle,
24 * mapobjectscale);
emerald->momz = flip * 24 * mapobjectscale;
@ -269,8 +269,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_ITEM_ROULETTE) * 180) + angle,
P_RandomRange(PR_ITEM_ROULETTE, 4, 12) * mapobjectscale);
drop->momz = flip * 12 * mapobjectscale;
if (drop->eflags & MFE_UNDERWATER)
@ -413,7 +413,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_ITEM_ROULETTE, 0, 359) * FRACUNIT), flip,
firstUnspawnedEmerald
);
}
@ -421,7 +421,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_ITEM_ROULETTE, 0, 359) * FRACUNIT), flip,
0, 0
);
@ -429,7 +429,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_ITEM_ROULETTE, 0, 359) * FRACUNIT), flip,
10
);
}
@ -510,7 +510,7 @@ void K_RunPaperItemSpawners(void)
}
else
{
key = P_RandomKey(spotCount);
key = P_RandomKey(PR_ITEM_ROULETTE, spotCount);
}
r = spotMap[key];
@ -524,7 +524,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_ITEM_ROULETTE, 0, 359) * FRACUNIT), flip,
firstUnspawnedEmerald
);
}
@ -534,7 +534,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_ITEM_ROULETTE, 0, 359) * FRACUNIT), flip,
10
);
K_FlipFromObject(drop, spotList[r]);
@ -542,7 +542,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_ITEM_ROULETTE, 0, 359) * FRACUNIT), flip,
0, 0
);
}

View file

@ -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])

View file

@ -1280,7 +1280,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_ITEM_ROULETTE, (debtamount*FRACUNIT)/20))
{
K_KartGetItemResult(player, KITEM_SUPERRING);
player->karthud[khud_itemblink] = TICRATE;
@ -1328,7 +1328,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_ITEM_ROULETTE, totalspawnchance);
for (i = 0; i < NUMKARTRESULTS && spawnchance[i] <= totalspawnchance; i++);
K_KartGetItemResult(player, i);
@ -1911,9 +1911,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_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)
@ -2382,7 +2382,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_DECORATION, FRACUNIT/2, FRACUNIT)),
FixedMul(scale, player->speed));
}
@ -2402,9 +2402,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_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);
@ -2452,9 +2452,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_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);
@ -2512,9 +2512,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_DECORATION, -32, 32) * FRACUNIT,
P_RandomRange(PR_DECORATION, -32, 32) * FRACUNIT,
(P_RandomRange(PR_DECORATION, 0, 24) + (shrink ? 48 : 0)) * FRACUNIT,
MT_GROW_PARTICLE
);
@ -3040,7 +3040,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_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))
@ -3054,7 +3054,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_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))
@ -3088,7 +3088,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_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;
@ -4605,18 +4605,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_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(-speed, speed)*FRACUNIT;
truc->momy = P_RandomRange(-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(-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;
@ -4624,30 +4624,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_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(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(-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_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(-speed, speed)*FRACUNIT;
truc->momy = P_RandomRange(-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(speed, speed2)*FRACUNIT*P_MobjFlip(truc);
if (P_RandomChance(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;
@ -5246,9 +5246,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_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);
@ -5258,8 +5258,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_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);
@ -5297,8 +5297,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_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);
@ -5436,13 +5436,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_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(-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_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;
@ -5879,8 +5879,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_DECORATION, 0, 359)*ANG1);
mo->fuse = P_RandomRange(PR_DECORATION, 20, 50);
P_SetTarget(&mo->target, player->mo);
P_SetMobjState(mo, S_KLIT1);
}
@ -5919,91 +5919,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(135, 225)<<FRACBITS), P_RandomRange(0, 8) * src->scale);
smoke->momz += P_RandomRange(0, 4) * src->scale;
P_Thrust(smoke, src->angle + FixedAngle(P_RandomRange(PR_DECORATION, 135, 225)<<FRACBITS), P_RandomRange(PR_DECORATION, 0, 8) * src->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(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();
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;
@ -6507,7 +6427,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_ITEM_ROULETTE) * 180) + angle,
16*mapobjectscale);
drop->momz = flip * 3 * mapobjectscale;
@ -6540,7 +6460,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_ITEM_ROULETTE, totalspawnchance);
for (i = 0; i < NUMKARTRESULTS && spawnchance[i] <= totalspawnchance; i++);
// TODO: this is bad!
@ -6964,7 +6884,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;
@ -7558,7 +7478,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_ITEM_RINGS, 0, 7) * ANGLE_45, 2 * thing->scale);
P_SetObjectMomZ(thing, 8<<FRACBITS, false);
thing->fuse = 120*TICRATE;
@ -7756,9 +7676,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_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,
@ -9532,8 +9452,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_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;
@ -9615,8 +9535,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_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;
@ -9644,9 +9564,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_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
);
@ -10825,9 +10745,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_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);

View file

@ -4207,17 +4207,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);
}

View file

@ -515,26 +515,26 @@ void K_SetPowerLevelScrambles(SINT8 powertype)
{
case 5:
speed = KARTSPEED_HARD;
encore = P_RandomChance(FRACUNIT>>1);
encore = P_RandomChance(PR_RULESCRAMBLE, FRACUNIT>>1);
break;
case 4:
speed = P_RandomChance((7<<FRACBITS)/10) ? KARTSPEED_HARD : KARTSPEED_NORMAL;
encore = P_RandomChance(FRACUNIT>>1);
speed = P_RandomChance(PR_RULESCRAMBLE, (7<<FRACBITS)/10) ? KARTSPEED_HARD : KARTSPEED_NORMAL;
encore = P_RandomChance(PR_RULESCRAMBLE, FRACUNIT>>1);
break;
case 3:
speed = P_RandomChance((3<<FRACBITS)/10) ? KARTSPEED_HARD : KARTSPEED_NORMAL;
encore = P_RandomChance(FRACUNIT>>2);
speed = P_RandomChance(PR_RULESCRAMBLE, (3<<FRACBITS)/10) ? KARTSPEED_HARD : KARTSPEED_NORMAL;
encore = P_RandomChance(PR_RULESCRAMBLE, FRACUNIT>>2);
break;
case 2:
speed = KARTSPEED_NORMAL;
encore = P_RandomChance(FRACUNIT>>3);
encore = P_RandomChance(PR_RULESCRAMBLE, FRACUNIT>>3);
break;
case 1: default:
speed = KARTSPEED_NORMAL;
encore = false;
break;
case 0:
speed = P_RandomChance((3<<FRACBITS)/10) ? KARTSPEED_EASY : KARTSPEED_NORMAL;
speed = P_RandomChance(PR_RULESCRAMBLE, (3<<FRACBITS)/10) ? KARTSPEED_EASY : KARTSPEED_NORMAL;
encore = false;
break;
}

View file

@ -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(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(0, fs->cone / ANG1) * ANG1;
pushAngle -= P_RandomRange(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(0, fs->cone / ANG1) * ANG1;
pushAngle += P_RandomRange(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(-fs->spread / FRACUNIT, fs->spread / FRACUNIT) * FRACUNIT;
yOff = P_RandomRange(-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(

View file

@ -380,10 +380,13 @@ static int lib_pGetEffectiveFollowerColor(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;
}
@ -391,7 +394,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;
}
@ -403,7 +406,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;
}
@ -421,7 +424,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;
}
@ -430,7 +433,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;
}
@ -439,7 +442,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;
}

View file

@ -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;

View file

@ -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,82 @@ 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.
* Used at the beginning of a game.
*
* \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;
}
/** 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 a 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 +304,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();
}

View file

@ -20,6 +20,50 @@
//#define DEBUGRANDOM
typedef enum
{
// 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_EXECUTOR, // Linedef executor
PR_DECORATION, // Generic decoration
PR_TERRAIN, // TERRAIN particles
PR_BUBBLE, // Decorative air bubbles
PR_RANDOMANIM, // FF_ANIMATE|FF_RANDOMANIM
PR_PLAYERSTARTS, // Player starts
PR_VOICES, // Player voice sounds
PR_RULESCRAMBLE, // Netgame rule scrambing events
PR_ITEM_ROULETTE, // Item results
PR_ITEM_RINGS, // Flung ring/bumper/player (on death)
PR_ITEM_SHRINK, // Shrink gun offsets
PR_ITEM_BUBBLE, // Item bubbles
PR_ITEM_DEBRIS, // Item debris
PR_ITEM_BOOST, // Boost
PR_EXPLOSION, // Explosion VFX
PR_SMOLDERING, // Smoldering particles
PR_SPARKLE, // Endsign and/or Emerald
PR_MOVINGTARGET, // Randomised moving targets
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 +76,49 @@ 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 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 P_RandomChance(p) (P_RandomFixed() < p) // and FRACUNIT (100%), returns true p% of the time
#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
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)
#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(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);
void P_SetRandSeedNet(pr_class_t pr_class, UINT32 init, UINT32 seed);
#endif
void P_ClearRandom(UINT32 seed);
UINT32 M_RandomizedSeed(void);
#endif

View file

@ -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
);

View file

@ -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(-16, 16) * FRACUNIT,
P_RandomRange(-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);
@ -702,7 +699,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_ITEM_SHRINK, GUN_SWINGTIME);
overlay = P_SpawnMobjFromMobj(gun, 0, 0, 0, MT_OVERLAY);

View file

@ -209,9 +209,9 @@ static void SpawnSPBSliptide(mobj_t *spb, SINT8 dir)
static void SpawnSPBSpeedLines(mobj_t *spb)
{
mobj_t *fast = P_SpawnMobjFromMobj(spb,
P_RandomRange(-24, 24) * FRACUNIT,
P_RandomRange(-24, 24) * FRACUNIT,
(spb->info->height / 2) + (P_RandomRange(-24, 24) * FRACUNIT),
P_RandomRange(PR_DECORATION, -24, 24) * FRACUNIT,
P_RandomRange(PR_DECORATION, -24, 24) * FRACUNIT,
(spb->info->height / 2) + (P_RandomRange(PR_DECORATION, -24, 24) * FRACUNIT),
MT_FASTLINE
);

View file

@ -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<<FRACBITS),
-P_ReturnThrustY(actor, ang, 16<<FRACBITS),
0, type);
P_SetObjectMomZ(dust, P_RandomRange(1, 4)<<FRACBITS, false);
P_SetObjectMomZ(dust, P_RandomRange(PR_UNDEFINED, 1, 4)<<FRACBITS, false);
}
static void P_FaceStabFlume(mobj_t *actor)
@ -2132,7 +2132,7 @@ static void P_VultureHoverParticle(mobj_t *actor)
fixed_t pz = P_FloorzAtPos(px, py, actor->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_EXPLOSION, 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)<<FRACBITS);
z = actor->z + (P_RandomKey(PR_EXPLOSION, (actor->height - mobjinfo[explodetype].height)>>FRACBITS)<<FRACBITS);
else if (actor->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_EXPLOSION)<<(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_EXPLOSION)<<(FRACBITS-2)) - 8*FRACUNIT, actor->scale);
mo = P_SpawnMobj(x, y, z, explodetype);
if (actor->eflags & MFE_VERTICALFLIP)
@ -3788,7 +3788,7 @@ void A_BubbleSpawn(mobj_t *actor)
return; // don't make bubble!
}
prandom = P_RandomByte();
prandom = P_RandomByte(PR_BUBBLE);
if (leveltime % (3*TICRATE) < 8)
bubble = P_SpawnMobj(actor->x, actor->y, actor->z + (actor->height / 2), MT_EXTRALARGEBUBBLE);
@ -3836,7 +3836,7 @@ void A_FanBubbleSpawn(mobj_t *actor)
return; // don't make bubble!
}
prandom = P_RandomByte();
prandom = P_RandomByte(PR_BUBBLE);
if ((prandom & 0x7) == 0x7)
bubble = P_SpawnMobj(actor->x, actor->y, hz, MT_SMALLBUBBLE);
@ -3876,7 +3876,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_BUBBLE);
if (!(prandom & 0x7)) // *****000
{
P_InstaThrust(actor, prandom & 0x70 ? actor->angle + ANGLE_90 : actor->angle,
@ -4084,7 +4084,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<<FRACBITS);
P_InstaThrust(newring, P_RandomRange(PR_ITEM_RINGS, 0, 7) * ANGLE_45, 2<<FRACBITS);
newring->momz = 8<<FRACBITS;
newring->fuse = 120*TICRATE;
P_RemoveMobj(actor);
@ -4094,7 +4094,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_ITEM_RINGS, 0, 7) * ANGLE_45, 2 * actor->scale);
P_SetObjectMomZ(actor, 8<<FRACBITS, false);
actor->fuse = 120*TICRATE;
#endif
@ -4183,7 +4183,7 @@ void A_FishJump(mobj_t *actor)
if (i < MAXPLAYERS)
{
fixed_t rad = actor->radius>>FRACBITS;
P_SpawnMobjFromMobj(actor, P_RandomRange(rad, -rad)<<FRACBITS, P_RandomRange(rad, -rad)<<FRACBITS, 0, (mobjtype_t)locvar2);
P_SpawnMobjFromMobj(actor, P_RandomRange(PR_UNDEFINED, rad, -rad)<<FRACBITS, P_RandomRange(PR_UNDEFINED, rad, -rad)<<FRACBITS, 0, (mobjtype_t)locvar2);
}
}
@ -4223,7 +4223,7 @@ void A_SetSolidSteam(mobj_t *actor)
if (!(actor->flags2 & MF2_AMBUSH))
{
if (P_RandomChance(FRACUNIT/8))
if (P_RandomChance(PR_DECORATION, FRACUNIT/8))
{
if (actor->info->deathsound)
S_StartSound(actor, actor->info->deathsound); // Hiss!
@ -4335,7 +4335,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;
@ -4576,8 +4576,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;
@ -4770,7 +4770,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);
@ -4819,7 +4819,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;
@ -5226,7 +5226,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_DECORATION) * (FRACUNIT/32);
else
randomoomph = 0;
@ -5388,7 +5388,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);
}
@ -5403,8 +5403,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)
{
@ -5432,7 +5432,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)
@ -5453,8 +5453,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
}
@ -5774,7 +5774,7 @@ void A_MixUp(mobj_t *actor)
{
if (counter > 255) // fail-safe to avoid endless loop
break;
prandom = P_RandomByte();
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;
@ -5892,7 +5892,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);
@ -5914,7 +5914,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
@ -5952,7 +5952,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;
}
}
@ -5977,13 +5977,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));
@ -6070,12 +6070,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;
@ -6209,8 +6209,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);
@ -6248,10 +6248,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.
@ -6288,10 +6288,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!
@ -7099,7 +7099,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_SMOLDERING) & 3;
if (th->tics < 1)
th->tics = 1;
}
@ -7197,7 +7197,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);
@ -7216,7 +7216,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_RANDOMANIM, amin, amax));
}
// Function: A_ChangeAngleAbsolute
@ -7230,7 +7230,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);
@ -7249,7 +7249,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_RANDOMANIM, amin, amax));
}
// Function: A_RollAngle
@ -7298,7 +7298,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_RANDOMANIM, amin, amax));
}
// Function: A_ChangeRollAngleAbsolute
@ -7323,7 +7323,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_RANDOMANIM, amin, amax));
}
// Function: A_PlaySound
@ -7513,7 +7513,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_RANDOMANIM, locvar1, locvar2);
}
// Function: A_ChangeColorRelative
@ -7958,7 +7958,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_RANDOMANIM, FRACUNIT/2) ? locvar1 : locvar2);
}
// Function: A_RandomStateRange
@ -7976,7 +7976,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_RANDOMANIM, locvar1, locvar2));
}
// Function: A_StateRangeByAngle
@ -8548,8 +8548,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)<<FRACBITS, actor->scale); // please note p_mobj.c's P_Rand() abuse
yr = FixedMul((P_SignedRandom()/3)<<FRACBITS, actor->scale); // of rand(), RAND_MAX and signness mess
xr = FixedMul((P_SignedRandom(PR_UNDEFINED)/3)<<FRACBITS, actor->scale); // please note p_mobj.c's P_Rand() abuse
yr = FixedMul((P_SignedRandom(PR_UNDEFINED)/3)<<FRACBITS, actor->scale); // of rand(), RAND_MAX and signness mess
while(count <= loc1lw && loc1lw >= 1)
{
@ -8730,7 +8730,7 @@ void A_CheckRandom(mobj_t *actor)
chance *= (locvar1 >> 16);
chance /= (locvar1 & 0xFFFF);
if (P_RandomChance(chance))
if (P_RandomChance(PR_RANDOMANIM, chance))
P_SetMobjState(actor, locvar2);
}
@ -10030,7 +10030,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);
@ -10062,7 +10062,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);
}
@ -10330,7 +10330,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];
}
}
@ -10352,8 +10352,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)
@ -10416,7 +10416,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
}
@ -10493,7 +10493,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;
@ -10585,7 +10585,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;
}
@ -10609,9 +10609,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;
}
}
@ -10783,9 +10783,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);
}
@ -10914,9 +10914,9 @@ void A_FlameParticle(mobj_t *actor)
rad = actor->radius>>FRACBITS;
hei = actor->height>>FRACBITS;
particle = P_SpawnMobjFromMobj(actor,
P_RandomRange(rad, -rad)<<FRACBITS,
P_RandomRange(rad, -rad)<<FRACBITS,
P_RandomRange(hei/2, hei)<<FRACBITS,
P_RandomRange(PR_DECORATION, rad, -rad)<<FRACBITS,
P_RandomRange(PR_DECORATION, rad, -rad)<<FRACBITS,
P_RandomRange(PR_DECORATION, hei/2, hei)<<FRACBITS,
type);
P_SetObjectMomZ(particle, 2<<FRACBITS, false);
}
@ -11050,20 +11050,20 @@ void A_LightBeamReset(mobj_t *actor)
if (LUA_CallAction(A_LIGHTBEAMRESET, actor))
return;
actor->destscale = FRACUNIT + P_SignedRandom()*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()*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_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()*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_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
@ -11102,9 +11102,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_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));
@ -11591,7 +11591,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)
@ -11765,7 +11765,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;
@ -11975,7 +11975,7 @@ void A_Boss5MakeJunk(mobj_t *actor)
return;
}
ang = FixedAngle((P_RandomKey(36)*10)<<FRACBITS);
ang = FixedAngle((P_RandomKey(PR_UNDEFINED, 36)*10)<<FRACBITS);
while (i--)
{
broked = P_SpawnMobjFromMobj(actor, 0, 0, FRACUNIT, MT_BROKENROBOT);
@ -11985,7 +11985,7 @@ void A_Boss5MakeJunk(mobj_t *actor)
broked->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))<<FRACBITS, false);
P_SetObjectMomZ(broked, (((locvar2) ? 4 : 0) + P_RandomRange(PR_UNDEFINED, 2, 5))<<FRACBITS, false);
if (locvar1 > 0)
P_SetMobjState(broked, locvar1);
if (!P_MobjWasRemoved(broked))
@ -12064,10 +12064,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;
}
}
@ -12254,7 +12254,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);
@ -12573,7 +12573,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)
@ -12672,7 +12672,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);
@ -12732,8 +12732,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);
@ -13200,17 +13200,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_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(-speed, speed)*FRACUNIT;
truc->momy = P_RandomRange(-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(speed, speed2)*FRACUNIT;
truc->momz = P_RandomRange(PR_EXPLOSION, speed, speed2)*FRACUNIT;
truc->tics = TICRATE*2;
truc->color = SKINCOLOR_KETCHUP;
@ -13290,8 +13290,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_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);
@ -13375,11 +13375,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_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(-3, 4);
smoke->tics += P_RandomRange(PR_SMOLDERING, -3, 4);
smoke->scale = actor->scale*3;
}
return;
@ -13399,7 +13399,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_DECORATION, 0, 6);
P_SetScale(fake, FRACUNIT*3/2);
fake->scale = FRACUNIT*3/2;
fake->destscale = FRACUNIT*3/2;
@ -13502,7 +13502,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_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)
@ -13542,7 +13542,7 @@ void A_MementosTPParticles(mobj_t *actor)
for (; i<4; i++)
{
particle = P_SpawnMobj(actor->x + (P_RandomRange(-256, 256)<<FRACBITS), actor->y + (P_RandomRange(-256, 256)<<FRACBITS), actor->z + (P_RandomRange(48, 256)<<FRACBITS), MT_MEMENTOSPARTICLE);
particle = P_SpawnMobj(actor->x + (P_RandomRange(PR_DECORATION, -256, 256)<<FRACBITS), actor->y + (P_RandomRange(PR_DECORATION, -256, 256)<<FRACBITS), actor->z + (P_RandomRange(PR_DECORATION, 48, 256)<<FRACBITS), MT_MEMENTOSPARTICLE);
particle->frame = 0;
particle->color = ((i%2) ? (SKINCOLOR_RED) : (SKINCOLOR_BLACK));
particle->destscale = 1;
@ -13605,7 +13605,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)<<FRACBITS), actor->y + (P_RandomRange(-60, 60)<<FRACBITS), actor->z, MT_THOK);
particle = P_SpawnMobj(actor->x + (P_RandomRange(PR_DECORATION, -60, 60)<<FRACBITS), actor->y + (P_RandomRange(PR_DECORATION, -60, 60)<<FRACBITS), actor->z, MT_THOK);
particle->momz = 20<<FRACBITS;
particle->color = ((i%2 !=0) ? (SKINCOLOR_RED) : (SKINCOLOR_BLACK));
particle->frame = 0;
@ -13881,9 +13881,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_ITEM_DEBRIS, -spacing, spacing) * FRACUNIT,
P_RandomRange(PR_ITEM_DEBRIS, -spacing, spacing) * FRACUNIT,
P_RandomRange(PR_ITEM_DEBRIS, 0, 4 * spacing) * FRACUNIT,
MT_SPINDASHDUST
);

View file

@ -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_TERRAIN, 36)*ANG10; // irrelevant for default objects but might make sense for some custom ones
if (flags & ML_EFFECT1)
{

View file

@ -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)<<FRACBITS), P_RandomRange(1,8)*special->scale);
P_SetObjectMomZ(firework, P_RandomRange(1,8)*special->scale, false);
P_Thrust(firework, FixedAngle((72*i)<<FRACBITS), P_RandomRange(PR_ITEM_DEBRIS, 1,8)*special->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(special->info->mass)));
S_StartSound (special, special->info->deathsound+(P_RandomKey(PR_DECORATION, special->info->mass)));
}
return;
@ -1181,7 +1181,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)<<FRACBITS);
mo->angle = FixedAngle((P_RandomKey(PR_UNDEFINED, 36)*10)<<FRACBITS);
mo2 = P_SpawnMobjFromMobj(mo, 0, 0, 0, MT_BOSSJUNK);
P_InitAngle(mo2, mo->angle);
@ -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() & 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());
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(-spacing, spacing) * FRACUNIT,
P_RandomRange(-spacing, spacing) * FRACUNIT,
P_RandomRange(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(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(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(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(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(5, 7)*scale;
target->momz = P_RandomRange(PR_DECORATION, 5, 7)*scale;
if (flip)
target->momz *= -1;
if (!sprflip)
@ -2221,7 +2221,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_ITEM_RINGS) & 1) ? -ANGLE_90 : ANGLE_90);
for (i = 0; i < num_fling_rings; i++)
{

View file

@ -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;

View file

@ -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_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(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(FRACUNIT/2))
if ((st->frame & FF_SPR2MIDSTART) && numframes && P_RandomChance(PR_RANDOMANIM, FRACUNIT/2))
frame = numframes/2;
else
frame = 0;
@ -2501,12 +2501,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_DECORATION, 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_DECORATION, FRACUNIT/2))
mom.y += FixedMul(6*FRACUNIT, mo->scale);
else
mom.y -= FixedMul(6*FRACUNIT, mo->scale);
@ -2529,7 +2529,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_DECORATION, mo->info->reactiontime));
mom.z /= 2; // Rocks not so bouncy
@ -2981,7 +2981,7 @@ boolean P_SceneryZMovement(mobj_t *mo)
for (i = 0; i < 4; ++i) // split into four
{
prandom = P_RandomByte();
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);
@ -2990,7 +2990,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_BUBBLE, 5));
//note that we assign the bubble sound to one of the new bubbles.
// in other words, IT ACTUALLY GETS USED YAAAAAAAY
@ -3013,7 +3013,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)
{
@ -3376,10 +3376,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_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
@ -4310,7 +4310,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)
@ -4385,7 +4385,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;
}
@ -5406,7 +5406,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_DECORATION, 36)*ANG10; // irrelevant for default objects but might make sense for some custom ones
mobj->angle += mobj->movedir;
}
@ -5517,7 +5517,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_DECORATION, mobj->info->mass));
return;
}
break;
@ -5670,22 +5670,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_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(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(-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_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);
@ -5770,9 +5770,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_ITEM_RINGS, -spacing, spacing) * FRACUNIT,
P_RandomRange(PR_ITEM_RINGS, -spacing, spacing) * FRACUNIT,
P_RandomRange(PR_ITEM_RINGS, -spacing, spacing) * FRACUNIT,
MT_BATTLEBUMPER_DEBRIS
);
@ -5801,9 +5801,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_ITEM_RINGS, -spacing, spacing) * FRACUNIT,
P_RandomRange(PR_ITEM_RINGS, -spacing, spacing) * FRACUNIT,
P_RandomRange(PR_ITEM_RINGS, -spacing, spacing) * FRACUNIT,
MT_SPINDASHDUST
);
@ -6299,9 +6299,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);
}
@ -6393,9 +6393,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_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);
@ -6911,9 +6911,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_SPARKLE, -48, 48) * FRACUNIT,
P_RandomRange(PR_SPARKLE, -48, 48) * FRACUNIT,
P_RandomRange(PR_SPARKLE, 0, 64) * FRACUNIT,
MT_EMERALDSPARK
);
@ -7149,7 +7149,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)<<FRACBITS), P_RandomRange(0, 8) * mobj->target->scale);
P_Thrust(smoke, mobj->angle+FixedAngle(P_RandomRange(PR_ITEM_BOOST, 135, 225)<<FRACBITS), P_RandomRange(PR_ITEM_BOOST, 0, 8) * mobj->target->scale);
}
break;
case MT_INVULNFLASH:
@ -7606,9 +7606,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_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);
@ -7875,7 +7875,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_SPARKLE, plistlen)]];
newskin = ((skin_t*)p->mo->skin) - skins;
newcolor = p->skincolor;
}
@ -7947,7 +7947,7 @@ static boolean P_MobjRegularThink(mobj_t *mobj)
mobj->movecount = 3;
{
angle_t facing = P_RandomRange(0, 90);
angle_t facing = P_RandomRange(PR_MOVINGTARGET, 0, 90);
if (facing >= 45)
facing = InvAngle((facing - 45)*ANG1);
else
@ -7980,23 +7980,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_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(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(-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_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(3, 10)*mobj->scale;
smoke->momz = P_RandomRange(PR_SMOLDERING, 3, 10)*mobj->scale;
smoke->destscale = mobj->scale*4;
smoke->scalespeed = mobj->scale/24;
}
@ -8053,7 +8053,7 @@ static boolean P_MobjRegularThink(mobj_t *mobj)
{
if (mobj->flags2 & MF2_AMBUSH)
{
mobj->momz = P_RandomRange(12, 16)<<FRACBITS;
mobj->momz = P_RandomRange(PR_UNDEFINED, 12, 16)<<FRACBITS;
S_StartSound(mobj, sfx_s3kb1);
P_SetMobjState(mobj, S_FROGGER_JUMP);
}
@ -8183,7 +8183,7 @@ static boolean P_MobjRegularThink(mobj_t *mobj)
else
{
if (!mobj->extravalue2)
mobj->extravalue2 = P_RandomRange(64, 192);
mobj->extravalue2 = P_RandomRange(PR_UNDEFINED, 64, 192);
}
if (mobj->reactiontime)
@ -8216,11 +8216,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)<<FRACBITS),
mobj->y + (P_RandomRange(-4, 4)<<FRACBITS),
mobj->z + (P_RandomRange(0, 2)<<FRACBITS), MT_BBZDUST);
mobj_t *dust = P_SpawnMobj(mobj->x + (P_RandomRange(PR_UNDEFINED, -4, 4)<<FRACBITS),
mobj->y + (P_RandomRange(PR_UNDEFINED, -4, 4)<<FRACBITS),
mobj->z + (P_RandomRange(PR_UNDEFINED, 0, 2)<<FRACBITS), MT_BBZDUST);
P_SetScale(dust, mobj->scale/2);
P_InstaThrust(dust, FixedAngle(P_RandomRange(0,359)<<FRACBITS), abs(mobj->tracer->momz)/2);
P_InstaThrust(dust, FixedAngle(P_RandomRange(PR_UNDEFINED, 0,359)<<FRACBITS), abs(mobj->tracer->momz)/2);
if (abs(mobj->tracer->momz) >= 2<<FRACBITS)
S_StartSound(mobj, sfx_s3k7e);
@ -8334,7 +8334,7 @@ static boolean P_MobjRegularThink(mobj_t *mobj)
player->mo->y + P_ReturnThrustY(NULL, player->mo->angle, player->mo->radius)
+ P_ReturnThrustY(NULL, player->mo->angle+ANGLE_90, (mobj->threshold)<<FRACBITS),
player->mo->z + (player->mo->height/2 * P_MobjFlip(player->mo))
+ (P_RandomRange(-abs(mobj->threshold), abs(mobj->threshold))<<FRACBITS));
+ (P_RandomRange(PR_UNDEFINED, -abs(mobj->threshold), abs(mobj->threshold))<<FRACBITS));
mobj->threshold /= 2;
mobj->momz = 0;
@ -8423,7 +8423,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)<<FRACBITS);
dust->momz = P_MobjFlip(mobj) * (P_RandomRange(PR_UNDEFINED, 1,4)<<FRACBITS);
dust->scale = mobj->scale/2;
dust->destscale = mobj->scale*3;
}
@ -8492,7 +8492,7 @@ static boolean P_MobjRegularThink(mobj_t *mobj)
P_MoveOrigin(mobj,
mobj->tracer->x + P_ReturnThrustX(NULL, mobj->tracer->angle+ANGLE_90, (mobj->cvmem)<<FRACBITS),
mobj->tracer->y + P_ReturnThrustY(NULL, mobj->tracer->angle+ANGLE_90, (mobj->cvmem)<<FRACBITS),
mobj->tracer->z - (4*mobj->tracer->scale) + (P_RandomRange(-abs(mobj->cvmem), abs(mobj->cvmem))<<FRACBITS));
mobj->tracer->z - (4*mobj->tracer->scale) + (P_RandomRange(PR_ITEM_BUBBLE, -abs(mobj->cvmem), abs(mobj->cvmem))<<FRACBITS));
if (mobj->movecount > 4*TICRATE)
{
@ -8993,7 +8993,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
@ -9109,9 +9109,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)<<FRACBITS));
P_InstaThrust(debris, debris->angle, P_RandomRange(3,18)*(FRACUNIT/4));
debris->momz = P_RandomRange(4,8)<<FRACBITS;
P_InitAngle(debris, FixedAngle(P_RandomRange(PR_DECORATION, 0,360)<<FRACBITS));
P_InstaThrust(debris, debris->angle, P_RandomRange(PR_DECORATION, 3,18)*(FRACUNIT/4));
debris->momz = P_RandomRange(PR_DECORATION, 4,8)<<FRACBITS;
if (!i) // kinda hacky :V
S_StartSound(debris, sfx_s3k82);
}
@ -9985,7 +9985,7 @@ mobj_t *P_SpawnMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type)
mobj->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:
{
@ -9997,7 +9997,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_DECORATION, sizeof(BALLOONCOLORS))];
}
break;
case MT_POGOSPRING:
@ -10007,8 +10007,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_DECORATION, 13);
mobj->color = FIRSTRAINBOWCOLOR + P_RandomKey(PR_DECORATION, FIRSTSUPERCOLOR - FIRSTRAINBOWCOLOR);
break;
case MT_HIVEELEMENTAL:
mobj->extravalue1 = 5;
@ -10104,15 +10104,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_ITEM_ROULETTE, FRACUNIT/3))
mobj->threshold = KITEM_SUPERRING;
else if (P_RandomChance(FRACUNIT/3))
else if (P_RandomChance(PR_ITEM_ROULETTE, FRACUNIT/3))
mobj->threshold = KITEM_SPB;
else if (P_RandomChance(FRACUNIT/3))
else if (P_RandomChance(PR_ITEM_ROULETTE, 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_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;
@ -10159,7 +10159,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?
{
@ -10176,7 +10176,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;
@ -10185,7 +10185,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;
}
@ -10256,8 +10256,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)<<FRACBITS);
fixed_t newy = mobj->y + (P_RandomRange(-mobj->info->mass, mobj->info->mass)<<FRACBITS);
fixed_t newx = mobj->x + (P_RandomRange(PR_DECORATION, -mobj->info->mass, mobj->info->mass)<<FRACBITS);
fixed_t newy = mobj->y + (P_RandomRange(PR_DECORATION, -mobj->info->mass, mobj->info->mass)<<FRACBITS);
if (P_FloorzAtPos(newx, newy, mobj->z, 8<<FRACBITS) == mobj->z)
P_SpawnMobj(newx, newy, mobj->z, MT_EERIEFOG);
@ -10271,10 +10271,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<<FRACBITS);
mobj->movefactor = mobj->z + (256<<FRACBITS);
@ -10800,7 +10800,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(8192));
thunderchance = (P_RandomKey(PR_DECORATION, 8192));
}
else if (sounds_thunder || effects_lightning)
{
@ -12392,8 +12392,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(FRACUNIT/2) ? offset : -offset;
mobj->momy += P_RandomChance(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;

View file

@ -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
@ -4475,8 +4476,6 @@ static void P_NetArchiveMisc(boolean resending)
WRITEUINT32(save_p, pig);
}
WRITEUINT32(save_p, P_GetRandSeed());
WRITEUINT32(save_p, tokenlist);
WRITEUINT8(save_p, encoremode);
@ -4630,8 +4629,6 @@ static inline boolean P_NetUnArchiveMisc(boolean reloading)
}
}
P_SetRandSeed(READUINT32(save_p));
tokenlist = READUINT32(save_p);
encoremode = (boolean)READUINT8(save_p);
@ -4808,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);
@ -4852,6 +4878,8 @@ void P_SaveNetGame(boolean resending)
}
LUA_Archive(&save_p);
P_NetArchiveRNG();
P_ArchiveLuabanksAndConsistency();
}
@ -4879,9 +4907,12 @@ boolean P_LoadGame(INT16 mapoverride)
boolean P_LoadNetGame(boolean reloading)
{
CV_LoadNetVars(&save_p);
if (!P_NetUnArchiveMisc(reloading))
return false;
P_NetUnArchivePlayers();
if (gamestate == GS_LEVEL)
{
P_NetUnArchiveWorld();
@ -4894,10 +4925,10 @@ 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());
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,

View file

@ -3302,9 +3302,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_EXECUTOR, rvalue1, rvalue2);
else
result = P_RandomRange(rvalue2, rvalue1);
result = P_RandomRange(PR_EXECUTOR, rvalue2, rvalue1);
P_LinedefExecute((INT16)result, mo, NULL);
break;
@ -3700,9 +3700,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)<<FRACBITS;
y = P_RandomRange(sides[line->sidenum[0]].rowoffset>>FRACBITS, sides[line->sidenum[1]].rowoffset>>FRACBITS)<<FRACBITS;
z = P_RandomRange(line->frontsector->floorheight>>FRACBITS, line->frontsector->ceilingheight>>FRACBITS)<<FRACBITS;
x = P_RandomRange(PR_UNDEFINED, sides[line->sidenum[0]].textureoffset>>FRACBITS, sides[line->sidenum[1]].textureoffset>>FRACBITS)<<FRACBITS;
y = P_RandomRange(PR_UNDEFINED, sides[line->sidenum[0]].rowoffset>>FRACBITS, sides[line->sidenum[1]].rowoffset>>FRACBITS)<<FRACBITS;
z = P_RandomRange(PR_UNDEFINED, line->frontsector->floorheight>>FRACBITS, line->frontsector->ceilingheight>>FRACBITS)<<FRACBITS;
}
else
{

View file

@ -1750,12 +1750,12 @@ static void P_DoBubbleBreath(player_t *player)
if (player->charflags & SF_MACHINE)
{
if (P_RandomChance(FRACUNIT/5))
if (P_RandomChance(PR_BUBBLE, FRACUNIT/5))
{
fixed_t r = player->mo->radius>>FRACBITS;
x += (P_RandomRange(r, -r)<<FRACBITS);
y += (P_RandomRange(r, -r)<<FRACBITS);
z += (P_RandomKey(player->mo->height>>FRACBITS)<<FRACBITS);
x += (P_RandomRange(PR_BUBBLE, r, -r)<<FRACBITS);
y += (P_RandomRange(PR_BUBBLE, r, -r)<<FRACBITS);
z += (P_RandomKey(PR_BUBBLE, player->mo->height>>FRACBITS)<<FRACBITS);
bubble = P_SpawnMobj(x, y, z, MT_WATERZAP);
S_StartSound(bubble, sfx_beelec);
}
@ -1767,9 +1767,9 @@ static void P_DoBubbleBreath(player_t *player)
else
z += FixedDiv(player->mo->height,5*(FRACUNIT/4));
if (P_RandomChance(FRACUNIT/16))
if (P_RandomChance(PR_BUBBLE, FRACUNIT/16))
bubble = P_SpawnMobj(x, y, z, MT_SMALLBUBBLE);
else if (P_RandomChance(3*FRACUNIT/256))
else if (P_RandomChance(PR_BUBBLE, 3*FRACUNIT/256))
bubble = P_SpawnMobj(x, y, z, MT_MEDIUMBUBBLE);
}
@ -2382,7 +2382,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_BUBBLE, FRACUNIT/2) && leveltime % TICRATE == 0)
S_StartSound(player->mo, sfx_floush);
}
@ -3718,7 +3718,7 @@ boolean P_SpectatorJoinGame(player_t *player)
else if (redscore > bluescore)
changeto = 2;
else
changeto = (P_RandomFixed() & 1) + 1;
changeto = (P_RandomFixed(PR_RULESCRAMBLE) & 1) + 1;
if (!LUA_HookTeamSwitch(player, changeto, true, false, false))
return false;

View file

@ -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;