Commit ac03ce39 by Inuyasha

*_Random is now *_RandomByte.

P_RandomChance is now a macro for something that should happen a certain percentage of time. P_SignedRandom was moved to a macro. Nobody cared. # Conflicts: # src/p_inter.c
parent ce2c2de5
......@@ -808,7 +808,7 @@ static boolean IsNameGood(char *name, INT32 playernum)
else if (len == 1) // Agh!
{
// Last ditch effort...
sprintf(name, "%d", M_Random() & 7);
sprintf(name, "%d", M_RandomKey(10));
if (!IsNameGood (name, playernum))
return false;
}
......@@ -3583,7 +3583,7 @@ retryscramble:
for (i = 0; i < playercount; i++)
{
if (repick)
newteam = (INT16)((M_Random() % 2) + 1);
newteam = (INT16)((M_RandomByte() % 2) + 1);
// One team has the most players they can get, assign the rest to the other team.
if (red == maxcomposition || blue == maxcomposition)
......@@ -3628,7 +3628,7 @@ retryscramble:
{
if (repick)
{
newteam = (INT16)((M_Random() % 2) + 1);
newteam = (INT16)((M_RandomByte() % 2) + 1);
repick = false;
}
else
......
......@@ -2331,8 +2331,8 @@ void G_SpawnPlayer(INT32 playernum, boolean starpost)
}
}
P_MovePlayerToSpawn(playernum, spawnpoint);
#ifdef HAVE_BLUA
#ifdef HAVE_BLUA
LUAh_PlayerSpawn(&players[playernum]); // Lua hook for player spawning :)
#endif
......@@ -2349,7 +2349,7 @@ mapthing_t *G_FindCTFStart(INT32 playernum)
return NULL;
}
if ((!players[playernum].ctfteam && numredctfstarts && (!numbluectfstarts || P_Random() & 1)) || players[playernum].ctfteam == 1) //red
if ((!players[playernum].ctfteam && numredctfstarts && (!numbluectfstarts || P_RandomChance(FRACUNIT/2))) || players[playernum].ctfteam == 1) //red
{
if (!numredctfstarts)
{
......@@ -5487,7 +5487,7 @@ ATTRNORETURN void FUNCNORETURN G_StopMetalRecording(void)
UINT8 i;
WRITEUINT8(demo_p, DEMOMARKER); // add the demo end marker
for (i = 0; i < 16; i++, p++)
*p = P_Random(); // This MD5 was chosen by fair dice roll and most likely < 50% correct.
*p = P_RandomByte(); // This MD5 was chosen by fair dice roll and most likely < 50% correct.
#else
WRITEUINT8(demo_p, DEMOMARKER); // add the demo end marker
md5_buffer((char *)p+16, demo_p - (p+16), (void *)p); // make a checksum of everything after the checksum in the file.
......@@ -5569,7 +5569,7 @@ boolean G_CheckDemoStatus(void)
UINT8 i;
WRITEUINT8(demo_p, DEMOMARKER); // add the demo end marker
for (i = 0; i < 16; i++, p++)
*p = P_Random(); // This MD5 was chosen by fair dice roll and most likely < 50% correct.
*p = P_RandomByte(); // This MD5 was chosen by fair dice roll and most likely < 50% correct.
#else
WRITEUINT8(demo_p, DEMOMARKER); // add the demo end marker
md5_buffer((char *)p+16, demo_p - (p+16), p); // make a checksum of everything after the checksum in the file.
......
......@@ -384,12 +384,12 @@ INT32 HW3S_I_StartSound(const void *origin_p, source3D_data_t *source_parm, chan
/*if (gamemode != heretic)
{
if (sfx_id >= sfx_sawup && sfx_id <= sfx_sawhit)
pitch += 8 - (M_Random()&15);
pitch += 8 - (M_RandomByte()&15);
else if (sfx_id != sfx_itemup && sfx_id != sfx_tink)
pitch += 16 - (M_Random()&31);
pitch += 16 - (M_RandomByte()&31);
}
else*/
pitch = 128 + (M_Random() & 7) - (M_Random() & 7);
pitch = 128 + (M_RandomByte() & 7) - (M_RandomByte() & 7);
}
#endif
......
......@@ -871,7 +871,7 @@ void HWR_DoCoronasLighting(FOutVector *outVerts, gr_vissprite_t *spr)
size = p_lspr->corona_radius * ((outVerts[0].z+120.0f)/950.0f); // d'ou vienne ces constante ?
break;
case ROCKET_SPR:
p_lspr->corona_color = (((M_Random()>>1)&0xff)<<24)|0x0040ff;
p_lspr->corona_color = (((M_RandomByte()>>1)&0xff)<<24)|0x0040ff;
// don't need a break
case CORONA_SPR:
size = p_lspr->corona_radius * ((outVerts[0].z+60.0f)/100.0f); // d'ou vienne ces constante ?
......@@ -974,7 +974,7 @@ void HWR_DrawCoronas(void)
size = p_lspr->corona_radius * ((cz+120.0f)/950.0f); // d'ou vienne ces constante ?
break;
case ROCKET_SPR:
Surf.FlatColor.s.alpha = (UINT8)((M_Random()>>1)&0xff);
Surf.FlatColor.s.alpha = (UINT8)((M_RandomByte()>>1)&0xff);
// don't need a break
case CORONA_SPR:
size = p_lspr->corona_radius * ((cz+60.0f)/100.0f); // d'ou vienne ces constante ?
......
......@@ -96,17 +96,17 @@ static int lib_evalMath(lua_State *L)
// M_RANDOM
//////////////
static int lib_pRandom(lua_State *L)
static int lib_pRandomFixed(lua_State *L)
{
NOHUD
lua_pushinteger(L, P_Random());
lua_pushfixed(L, P_RandomFixed());
return 1;
}
static int lib_pSignedRandom(lua_State *L)
static int lib_pRandomByte(lua_State *L)
{
NOHUD
lua_pushinteger(L, P_SignedRandom());
lua_pushinteger(L, P_RandomByte());
return 1;
}
......@@ -134,6 +134,30 @@ static int lib_pRandomRange(lua_State *L)
return 1;
}
// Deprecated, macros, etc.
static int lib_pRandom(lua_State *L)
{
NOHUD
LUA_Deprecated(L, "P_Random", "P_RandomByte");
lua_pushinteger(L, P_RandomByte());
return 1;
}
static int lib_pSignedRandom(lua_State *L)
{
NOHUD
lua_pushinteger(L, P_SignedRandom());
return 1;
}
static int lib_pRandomChance(lua_State *L)
{
fixed_t p = luaL_checkfixed(L, 1);
NOHUD
lua_pushboolean(L, P_RandomChance(p));
return 1;
}
// P_MAPUTIL
///////////////
......@@ -1910,10 +1934,13 @@ static luaL_Reg lib[] = {
{"EvalMath", lib_evalMath},
// m_random
{"P_Random",lib_pRandom},
{"P_SignedRandom",lib_pSignedRandom},
{"P_RandomFixed",lib_pRandomFixed},
{"P_RandomByte",lib_pRandomByte},
{"P_RandomKey",lib_pRandomKey},
{"P_RandomRange",lib_pRandomRange},
{"P_Random",lib_pRandom}, // DEPRECATED
{"P_SignedRandom",lib_pSignedRandom}, // MACRO
{"P_RandomChance",lib_pRandomChance}, // MACRO
// p_maputil
{"P_AproxDistance",lib_pAproxDistance},
......
......@@ -618,9 +618,9 @@ void Command_CauseCfail_f(void)
}
P_UnsetThingPosition(players[consoleplayer].mo);
P_Random();
P_Random();
P_Random();
P_RandomFixed();
P_RandomByte();
P_RandomFixed();
players[consoleplayer].mo->x = 0;
players[consoleplayer].mo->y = 123311; //cfail cansuled kthxbye
players[consoleplayer].mo->z = 123311;
......
......@@ -19,48 +19,51 @@
#include "m_random.h"
#include "m_fixed.h"
// ---------------------------
// RNG functions (not synched)
// ---------------------------
/** Provides a random byte.
* Used outside the p_xxx game code and not synchronized in netgames. This is
* for anything that doesn't need to be synced, e.g. precipitation.
/** Provides a random fixed point number. Distribution is uniform.
* As with all M_Random functions, not synched in netgames.
*
* \return A random byte, 0 to 255.
* \return A random fixed point number from [0,1).
*/
UINT8 M_Random(void)
fixed_t M_RandomFixed(void)
{
return (rand() & 255);
return (rand() & 0xFFFF);
}
/** Provides a random signed byte. Distribution is uniform.
* As with all M_*Random functions, not synched in netgames.
/** Provides a random byte. Distribution is uniform.
* As with all M_Random functions, not synched in netgames.
*
* \return A random byte, -128 to 127.
* \sa M_Random
* \return A random integer from [0, 255].
*/
INT32 M_SignedRandom(void)
UINT8 M_RandomByte(void)
{
return (rand() & 255) - 128;
return (rand() & 0xFF);
}
/** Provides a random number in between 0 and the given number - 1.
* Distribution is uniform. Use for picking random elements from an array.
* As with all M_*Random functions, not synched in netgames.
/** Provides a random integer for picking random elements from an array.
* Distribution is uniform.
* As with all M_Random functions, not synched in netgames.
*
* \return A random number, 0 to arg1-1.
* \param a Number of items in array.
* \return A random integer from [0,a).
*/
INT32 M_RandomKey(INT32 a)
{
return (INT32)((rand()/((unsigned)RAND_MAX+1.0f))*a);
}
/** Provides a random number in between a specific range.
/** Provides a random integer in a given range.
* Distribution is uniform.
* As with all M_*Random functions, not synched in netgames.
* As with all M_Random functions, not synched in netgames.
*
* \return A random number, arg1 to arg2.
* \param a Lower bound.
* \param b Upper bound.
* \return A random integer from [a,b].
*/
INT32 M_RandomRange(INT32 a, INT32 b)
{
......@@ -79,8 +82,7 @@ static UINT32 randomseed = 0;
// Holds the INITIAL seed value. Used for demos, possibly other debugging.
static UINT32 initialseed = 0;
/**
* Provides a random fixed point number.
/** 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).
......@@ -96,62 +98,45 @@ ATTRINLINE static fixed_t FUNCINLINE __internal_prng__(void)
return (randomseed&((FRACUNIT-1)<<9))>>9;
}
/** Provides a random integer from 0 to 255.
* Distribution is uniform.
* If you're curious, (&0xFF00) >> 8 gives the same result
* as a fixed point multiplication by 256.
/** Provides a random fixed point number. Distribution is uniform.
* Literally a wrapper for the internal PRNG function.
*
* \return Random integer from [0, 255].
* \sa __internal_prng__
* \return A random fixed point number from [0,1).
*/
#ifndef DEBUGRANDOM
UINT8 P_Random(void)
fixed_t P_RandomFixed(void)
{
#else
UINT8 P_RandomD(const char *rfile, INT32 rline)
UINT8 P_RandomFixedD(const char *rfile, INT32 rline)
{
CONS_Printf("P_Random() at: %sp %d\n", rfile, rline);
CONS_Printf("P_RandomFixed() at: %sp %d\n", rfile, rline);
#endif
return (UINT8)((__internal_prng__()&0xFF00)>>8);
return __internal_prng__();
}
/** Provides a random integer from -128 to 127.
* Distribution is uniform.
/** Provides a random byte. Distribution is uniform.
* If you're curious, (&0xFF00) >> 8 gives the same result
* as a fixed point multiplication by 256.
*
* \return Random integer from [-128, 127].
* \return Random integer from [0, 255].
* \sa __internal_prng__
*/
#ifndef DEBUGRANDOM
INT32 P_SignedRandom(void)
{
#else
INT32 P_SignedRandomD(const char *rfile, INT32 rline)
{
CONS_Printf("P_SignedRandom() at: %sp %d\n", rfile, rline);
#endif
return (INT32)((__internal_prng__()&0xFF00)>>8) - 128;
}
/**
* Provides a random fixed point number.
* Literally a wrapper for the internal PRNG function.
*
* \return A random fixed point number from [0,1).
*/
#ifndef DEBUGRANDOM
fixed_t P_RandomFixed(void)
UINT8 P_RandomByte(void)
{
#else
UINT8 P_RandomFixedD(const char *rfile, INT32 rline)
UINT8 P_RandomByteD(const char *rfile, INT32 rline)
{
CONS_Printf("P_Random() at: %sp %d\n", rfile, rline);
CONS_Printf("P_RandomByte() at: %sp %d\n", rfile, rline);
#endif
return __internal_prng__();
return (UINT8)((__internal_prng__()&0xFF00)>>8);
}
/** Provides a random integer for picking random elements from an array.
* Distribution is uniform.
* NOTE: Maximum range is 65536.
*
* \param a Number of items in array.
* \return A random integer from [0,a).
* \sa __internal_prng__
*/
......@@ -168,8 +153,11 @@ INT32 P_RandomKeyD(const char *rfile, INT32 rline, INT32 a)
/** Provides a random integer in a given range.
* Distribution is uniform.
* NOTE: Maximum range is 65536.
*
* \return A random integer from [a,b].P_Random
* \param a Lower bound.
* \param b Upper bound.
* \return A random integer from [a,b].
* \sa __internal_prng__
*/
#ifndef DEBUGRANDOM
......
......@@ -25,30 +25,36 @@
// P_Random functions pulls random bytes from a PRNG that is network synced.
// RNG functions
UINT8 M_Random(void);
INT32 M_SignedRandom(void);
INT32 M_RandomKey(INT32 a);
INT32 M_RandomRange(INT32 a, INT32 b);
fixed_t M_RandomFixed(void);
UINT8 M_RandomByte(void);
INT32 M_RandomKey(INT32 a);
INT32 M_RandomRange(INT32 a, INT32 b);
// PRNG functions
#ifdef DEBUGRANDOM
#define P_Random() P_RandomD(__FILE__, __LINE__)
#define P_SignedRandom() P_SignedRandomD(__FILE__, __LINE__)
#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)
UINT8 P_RandomD(const char *rfile, INT32 rline);
INT32 P_SignedRandomD(const char *rfile, INT32 rline);
fixed_t P_RandomFixedD(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);
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);
#else
UINT8 P_Random(void);
INT32 P_SignedRandom(void);
fixed_t P_RandomFixed(void);
INT32 P_RandomKey(INT32 a);
INT32 P_RandomRange(INT32 a, INT32 b);
UINT8 P_RandomByte(void);
INT32 P_RandomKey(INT32 a);
INT32 P_RandomRange(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_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
// Debugging
fixed_t P_RandomPeek(void);
// Working with the seed for PRNG
......
......@@ -1236,7 +1236,7 @@ void P_TouchSpecialThing(mobj_t *special, mobj_t *toucher, boolean heightcheck)
if (special->target && special->target->state == &states[S_BLACKEGG_SHOOT1])
{
if (special->target->health <= 2 && (P_Random() & 1))
if (special->target->health <= 2 && P_RandomChance(FRACUNIT/2))
P_SetMobjState(special->target, special->target->info->missilestate);
else
P_SetMobjState(special->target, special->target->info->raisestate);
......@@ -2186,29 +2186,17 @@ void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source)
default:
if (target->info->doomednum)
prandom = target->info->doomednum%5; // "Random" animal for new enemies.
else
prandom = P_RandomKey(5); // No placable object, just use a random number.
switch(prandom)
{
switch(target->info->doomednum%5)
{
default: item = MT_BUNNY; break;
case 1: item = MT_BIRD; break;
case 2: item = MT_MOUSE; break;
case 3: item = MT_COW; break;
case 4: item = MT_CHICKEN; break;
}
}
else
{
prandom = P_Random();
if (prandom < 51)
item = MT_BUNNY;
else if (prandom < 102)
item = MT_BIRD;
else if (prandom < 153)
item = MT_MOUSE;
else if (prandom < 204)
item = MT_COW;
else
item = MT_CHICKEN;
}
break;
}
......@@ -3086,7 +3074,7 @@ boolean P_DamageMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32 da
// Killing dead. Just for kicks.
// Require source and inflictor be player. Don't hurt for firing rings.
if (cv_killingdead.value && (source && source->player) && (inflictor && inflictor->player) && P_Random() < 80)
if (cv_killingdead.value && (source && source->player) && (inflictor && inflictor->player) && P_RandomChance(5*FRACUNIT/16))
P_DamageMobj(source, target, target, 1);
// do the damage
......@@ -3600,7 +3588,7 @@ void P_PlayerFlagBurst(player_t *player, boolean toss)
P_InstaThrust(flag, player->mo->angle, FixedMul(6*FRACUNIT, player->mo->scale));
else
{
angle_t fa = P_Random()*FINEANGLES/256;
angle_t fa = P_RandomByte()*FINEANGLES/256;
flag->momx = FixedMul(FINECOSINE(fa), FixedMul(6*FRACUNIT, player->mo->scale));
if (!(twodlevel || (player->mo->flags2 & MF2_TWOD)))
flag->momy = FixedMul(FINESINE(fa), FixedMul(6*FRACUNIT, player->mo->scale));
......
......@@ -51,7 +51,7 @@ void T_FireFlicker(fireflicker_t *flick)
if (--flick->count)
return;
amount = (INT16)((UINT8)(P_Random() & 3) * 16);
amount = (INT16)((UINT8)(P_RandomByte() & 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_Random() & 7) + 1;
flash->count = (P_RandomByte() & 7) + 1;
else
flash->count = 1;
......
......@@ -652,9 +652,9 @@ void P_EmeraldManager(void)
break;
if (leveltime < TICRATE) // Start of map
spawnpoints[j]->threshold = 60*TICRATE + P_Random() * (TICRATE/5);
spawnpoints[j]->threshold = 60*TICRATE + P_RandomByte() * (TICRATE/5);
else
spawnpoints[j]->threshold = P_Random() * (TICRATE/5);
spawnpoints[j]->threshold = P_RandomByte() * (TICRATE/5);
break;
}
......@@ -683,26 +683,26 @@ void P_ExplodeMissile(mobj_t *mo)
explodemo = P_SpawnMobj(mo->x, mo->y, mo->z, MT_EXPLODE);
P_SetScale(explodemo, mo->scale);
explodemo->destscale = mo->destscale;
explodemo->momx += (P_Random() % 32) * FixedMul(FRACUNIT/8, explodemo->scale);
explodemo->momy += (P_Random() % 32) * FixedMul(FRACUNIT/8, explodemo->scale);
explodemo->momx += (P_RandomByte() % 32) * FixedMul(FRACUNIT/8, explodemo->scale);
explodemo->momy += (P_RandomByte() % 32) * FixedMul(FRACUNIT/8, explodemo->scale);
S_StartSound(explodemo, sfx_pop);
explodemo = P_SpawnMobj(mo->x, mo->y, mo->z, MT_EXPLODE);
P_SetScale(explodemo, mo->scale);
explodemo->destscale = mo->destscale;
explodemo->momx += (P_Random() % 64) * FixedMul(FRACUNIT/8, explodemo->scale);
explodemo->momy -= (P_Random() % 64) * FixedMul(FRACUNIT/8, explodemo->scale);
explodemo->momx += (P_RandomByte() % 64) * FixedMul(FRACUNIT/8, explodemo->scale);
explodemo->momy -= (P_RandomByte() % 64) * FixedMul(FRACUNIT/8, explodemo->scale);
S_StartSound(explodemo, sfx_dmpain);
explodemo = P_SpawnMobj(mo->x, mo->y, mo->z, MT_EXPLODE);
P_SetScale(explodemo, mo->scale);
explodemo->destscale = mo->destscale;
explodemo->momx -= (P_Random() % 128) * FixedMul(FRACUNIT/8, explodemo->scale);
explodemo->momy += (P_Random() % 128) * FixedMul(FRACUNIT/8, explodemo->scale);
explodemo->momx -= (P_RandomByte() % 128) * FixedMul(FRACUNIT/8, explodemo->scale);
explodemo->momy += (P_RandomByte() % 128) * FixedMul(FRACUNIT/8, explodemo->scale);
S_StartSound(explodemo, sfx_pop);
explodemo = P_SpawnMobj(mo->x, mo->y, mo->z, MT_EXPLODE);
P_SetScale(explodemo, mo->scale);
explodemo->destscale = mo->destscale;
explodemo->momx -= (P_Random() % 96) * FixedMul(FRACUNIT/8, explodemo->scale);
explodemo->momy -= (P_Random() % 96) * FixedMul(FRACUNIT/8, explodemo->scale);
explodemo->momx -= (P_RandomByte() % 96) * FixedMul(FRACUNIT/8, explodemo->scale);
explodemo->momy -= (P_RandomByte() % 96) * FixedMul(FRACUNIT/8, explodemo->scale);
S_StartSound(explodemo, sfx_cybdth);
// Hack: Release an animal.
......@@ -2405,12 +2405,12 @@ static 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_Random() & 1)
if (P_RandomChance(FRACUNIT/2))
mom.x += FixedMul(6*FRACUNIT, mo->scale);
else
mom.x -= FixedMul(6*FRACUNIT, mo->scale);
if (P_Random() & 1)
if (P_RandomChance(FRACUNIT/2))
mom.y += FixedMul(6*FRACUNIT, mo->scale);
else
mom.y -= FixedMul(6*FRACUNIT, mo->scale);
......@@ -2886,7 +2886,7 @@ static boolean P_SceneryZMovement(mobj_t *mo)
for (i = 0; i < 4; ++i) // split into four
{
prandom = P_Random();
prandom = P_RandomByte();
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);
......@@ -3218,13 +3218,13 @@ void P_MobjCheckWater(mobj_t *mobj)
// Create tons of bubbles
for (i = 0; i < bubblecount; i++)
{
// P_Random()s are called individually to allow consistency
// 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_Random();
prandom[1] = P_Random();
prandom[2] = P_Random();
prandom[3] = P_Random();
prandom[0] = P_RandomByte();
prandom[1] = P_RandomByte();
prandom[2] = P_RandomByte();
prandom[3] = P_RandomByte();
bubbletype = MT_SMALLBUBBLE;
if (!(prandom[0] & 0x3)) // medium bubble chance up to 64 from 32
......@@ -3826,7 +3826,7 @@ boolean P_BossTargetPlayer(mobj_t *actor, boolean closest)
// first time init, this allow minimum lastlook changes
if (actor->lastlook < 0)
actor->lastlook = P_Random();
actor->lastlook = P_RandomByte();
actor->lastlook &= PLAYERSMASK;
for( ; ; actor->lastlook = (actor->lastlook+1) & PLAYERSMASK)
......@@ -4707,7 +4707,7 @@ static void P_Boss7Thinker(mobj_t *mobj)
if (mobj->state == &states[S_BLACKEGG_STND] && mobj->tics == mobj->state->tics)
{
mobj->reactiontime += P_Random();
mobj->reactiontime += P_RandomByte();
if (mobj->health <= mobj->info->damage)
mobj->reactiontime /= 4;
......@@ -4901,7 +4901,7 @@ static void P_Boss7Thinker(mobj_t *mobj)
if (mobj->tracer && mobj->tracer->type == MT_BOSS3WAYPOINT
&& mobj->tracer->spawnpoint && (mobj->tracer->spawnpoint->options & 7) == waypointNum)
{
if (P_Random() & 1)
if (P_RandomChance(FRACUNIT/2))
waypointNum++;
else
waypointNum--;
......@@ -4913,7 +4913,7 @@ static void P_Boss7Thinker(mobj_t *mobj)
}
if (waypointNum == 0 && mobj->health <= mobj->info->damage)
waypointNum = 1 + (P_Random() & 1);
waypointNum = 1 + (P_RandomFixed() & 1);
// scan the thinkers to find
// the waypoint to use
......@@ -5013,7 +5013,7 @@ static void P_Boss7Thinker(mobj_t *mobj)
P_SetMobjState(mobj, mobj->info->spawnstate);
}
else if (mobj->state == &states[mobj->info->deathstate] && mobj->tics == mobj->state->tics)
S_StartSound(0, sfx_bedie1 + (P_Random() & 1));
S_StartSound(0, sfx_bedie1 + (P_RandomFixed() & 1));
}
......@@ -5440,7 +5440,7 @@ static void P_Boss9Thinker(mobj_t *mobj)
// An incoming attack is detected! What should we do?!
// Go into vector form!
mobj->movedir = ANGLE_11hh - FixedAngle(FixedMul(AngleFixed(ANGLE_11hh), FixedDiv((mobj->info->spawnhealth - mobj->health)<<FRACBITS, (mobj->info->spawnhealth-1)<<FRACBITS)));
if (P_Random()&1)
if (P_RandomChance(FRACUNIT/2))
mobj->movedir = InvAngle(mobj->movedir);
mobj->threshold = 6 + (FixedMul(24<<FRACBITS, FixedDiv((mobj->info->spawnhealth - mobj->health)<<FRACBITS, (mobj->info->spawnhealth-1)<<FRACBITS))>>FRACBITS);
if (mobj->info->activesound)
......@@ -6042,20 +6042,20 @@ static void P_KoopaThinker(mobj_t *koopa)
P_XYMovement(koopa);
if (P_Random() < 8 && koopa->z <= koopa->floorz)
if (P_RandomChance(FRACUNIT/32) && koopa->z <= koopa->floorz)
koopa->momz = FixedMul(5*FRACUNIT, koopa->scale);
if (koopa->z > koopa->floorz)
koopa->momz += FixedMul(FRACUNIT/4, koopa->scale);
if (P_Random() < 4)
if (P_RandomChance(FRACUNIT/64))
{
mobj_t *flame;
flame = P_SpawnMobj(koopa->x - koopa->radius + FixedMul(5*FRACUNIT, koopa->scale), koopa->y, koopa->z + (P_Random()<<(FRACBITS-2)), MT_KOOPAFLAME);
flame = P_SpawnMobj(koopa->x - koopa->radius + FixedMul(5*FRACUNIT, koopa->scale), koopa->y, koopa->z + (P_RandomByte()<<(FRACBITS-2)), MT_KOOPAFLAME);
flame->momx = -FixedMul(flame->info->speed, flame->scale);
S_StartSound(flame, sfx_koopfr);
}
else if (P_Random() > 250)
else if (P_RandomChance(5*FRACUNIT/256))
{
mobj_t *hammer;
hammer = P_SpawnMobj(koopa->x - koopa->radius, koopa->y, koopa->z + koopa->height, MT_HAMMER);
......@@ -6499,11 +6499,11 @@ void P_MobjThinker(mobj_t *mobj)
fixed_t ns;
mobj_t *mo2;
i = P_Random();
z = mobj->subsector->sector->floorheight + ((P_Random()&63)*FRACUNIT);
i = P_RandomByte();
z = mobj->subsector->sector->floorheight + ((P_RandomByte()&63)*FRACUNIT);
for (j = 0; j < 2; j++)
{
const angle_t fa = (P_Random()*FINEANGLES/16) & FINEMASK;
const angle_t fa = (P_RandomByte()*FINEANGLES/16) & FINEMASK;
ns = 64 * FRACUNIT;
x = mobj->x + FixedMul(FINESINE(fa),ns);
y = mobj->y + FixedMul(FINECOSINE(fa),ns);
......@@ -6513,7 +6513,7 @@ void P_MobjThinker(mobj_t *mobj)
mo2->momx = FixedMul(FINESINE(fa),ns);
mo2->momy = FixedMul(FINECOSINE(fa),ns);
i = P_Random();
i = P_RandomByte();
if (i % 5 == 0)
P_SpawnMobj(x, y, z, MT_CHICKEN);
......@@ -7997,7 +7997,7 @@ void P_SpawnPrecipitation(void)
continue;
rainmo = P_SpawnSnowMobj(x, y, height, MT_SNOWFLAKE);
mrand = M_Random();
mrand = M_RandomByte();
if (mrand < 64)
P_SetPrecipMobjState(rainmo, S_SNOW3);
else if (mrand < 144)
......@@ -9166,12 +9166,12 @@ ML_NOCLIMB : Direction not controllable
{
mobj->momz += FixedMul(16*FRACUNIT, mobj->scale);
if (P_Random() & 1)
if (P_RandomChance(FRACUNIT/2))
mobj->momx += FixedMul(16*FRACUNIT, mobj->scale);
else
mobj->momx -= FixedMul(16*FRACUNIT, mobj->scale);
if (P_Random() & 1)
if (P_RandomChance(FRACUNIT/2))
mobj->momy += FixedMul(16*FRACUNIT, mobj->scale);
else
mobj->momy -= FixedMul(16*FRACUNIT,mobj->scale);
......
......@@ -2057,7 +2057,7 @@ void P_SwitchWeather(INT32 weathernum)
precipmobj = (precipmobj_t *)think;
precipmobj->flags = mobjinfo[MT_SNOWFLAKE].flags;
z = M_Random();
z = M_RandomByte();
if (z < 64)
z = 2;
......
......@@ -363,7 +363,7 @@ static void P_DoAutobalanceTeams(void)
{
if (totalred > totalblue)
{
i = M_Random() % red;
i = M_RandomKey(red);
NetPacket.packet.newteam = 2;
NetPacket.packet.playernum = redarray[i];
NetPacket.packet.verification = true;
......@@ -375,7 +375,7 @@ static void P_DoAutobalanceTeams(void)