- cleaned up use of the random function in script files.

Many uses of random() & value have been turned into random(0, value).
This is not only more efficient, it also ensures better random distribution because the parameter-less variant only returns values between 0 and 255.
This commit is contained in:
Christoph Oelckers 2018-12-21 12:32:36 +01:00
parent a44e63babd
commit 0770c0022c
50 changed files with 122 additions and 121 deletions

View file

@ -691,7 +691,7 @@ class Actor : Thinker native
{ {
return false; return false;
} }
movecount = random[TryWalk]() & 15; movecount = random[TryWalk](0, 15);
return true; return true;
} }

View file

@ -495,7 +495,7 @@ extend class Actor
bo.PlaySpawnSound(self); bo.PlaySpawnSound(self);
if (xyvel != 0) if (xyvel != 0)
bo.Speed = xyvel; bo.Speed = xyvel;
bo.Angle = Angle + (((random[grenade]()&7) - 4) * (360./256.)); bo.Angle = Angle + (random[grenade](-4, 3) * (360./256.));
let pitch = -self.Pitch; let pitch = -self.Pitch;
let angle = bo.Angle; let angle = bo.Angle;

View file

@ -47,7 +47,7 @@ extend class Actor
// make fall forwards sometimes // make fall forwards sometimes
if ((damage < 40) && (damage > health) if ((damage < 40) && (damage > health)
&& (pos.Z - origin.pos.Z > 64) && (pos.Z - origin.pos.Z > 64)
&& (random[Kickback]() & 1) && random[Kickback](0, 1)
// [RH] But only if not too fast and not flying // [RH] But only if not too fast and not flying
&& thrust < 10 && thrust < 10
&& !bNoGravity && !bNoGravity

View file

@ -37,7 +37,7 @@ extend class StateProvider
State flash = weap.FindState('Flash'); State flash = weap.FindState('Flash');
if (flash != null) if (flash != null)
{ {
player.SetSafeFlash(weap, flash, random[FireRail]()&1); player.SetSafeFlash(weap, flash, random[FireRail](0, 1));
} }
} }

View file

@ -475,7 +475,7 @@ class ScriptedMarine : Actor
double pitch = AimLineAttack (angle, MISSILERANGE); double pitch = AimLineAttack (angle, MISSILERANGE);
for (int i = 0; i < 20; ++i) for (int i = 0; i < 20; ++i)
{ {
int damage = 5*(random[SMarineFireSSG]()%3+1); int damage = 5*(random[SMarineFireSSG](1, 3));
double ang = angle + Random2[SMarineFireSSG]() * (11.25 / 256); double ang = angle + Random2[SMarineFireSSG]() * (11.25 / 256);
LineAttack (ang, MISSILERANGE, pitch + Random2[SMarineFireSSG]() * (7.097 / 256), damage, 'Hitscan', "BulletPuff"); LineAttack (ang, MISSILERANGE, pitch + Random2[SMarineFireSSG]() * (7.097 / 256), damage, 'Hitscan', "BulletPuff");

View file

@ -120,8 +120,8 @@ extend class StateProvider
double SavedPlayerPitch = pitch; double SavedPlayerPitch = pitch;
for (int i = 0; i < 2; i++) // Spawn two plasma balls in sequence for (int i = 0; i < 2; i++) // Spawn two plasma balls in sequence
{ {
angle += ((random[OldBFG]() & 127) - 64) * (90./768); angle += random[OldBFG](-64, 63) * (90./768);
pitch += ((random[OldBFG]() & 127) - 64) * (90./640); pitch += random[OldBFG](-64, 63) * (90./640);
SpawnPlayerMissile (i == 0? (class<Actor>)("PlasmaBall1") : (class<Actor>)("PlasmaBall2")); SpawnPlayerMissile (i == 0? (class<Actor>)("PlasmaBall1") : (class<Actor>)("PlasmaBall2"));
// Restore saved values // Restore saved values
angle = SavedPlayerAngle; angle = SavedPlayerAngle;

View file

@ -139,7 +139,7 @@ extend class StateProvider
State flash = weap.FindState('Flash'); State flash = weap.FindState('Flash');
if (flash != null) if (flash != null)
{ {
player.SetSafeFlash(weap, flash, random[FirePlasma]()&1); player.SetSafeFlash(weap, flash, random[FirePlasma](0, 1));
} }
} }

View file

@ -331,7 +331,7 @@ extend class Actor
} }
else else
{ // Death { // Death
count = 5 + (random[Feathers]()&3); count = 5 + (random[Feathers](0, 3));
} }
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
@ -342,7 +342,7 @@ extend class Actor
mo.Vel.X = Random2[Feathers]() / 256.; mo.Vel.X = Random2[Feathers]() / 256.;
mo.Vel.Y = Random2[Feathers]() / 256.; mo.Vel.Y = Random2[Feathers]() / 256.;
mo.Vel.Z = 1. + random[Feathers]() / 128.; mo.Vel.Z = 1. + random[Feathers]() / 128.;
mo.SetState (mo.SpawnState + (random[Feathers]()&7)); mo.SetState (mo.SpawnState + (random[Feathers](0, 7)));
} }
} }
} }

View file

@ -283,7 +283,7 @@ class Volcano : Actor
void A_VolcanoSet () void A_VolcanoSet ()
{ {
tics = 105 + (random[VolcanoSet]() & 127); tics = random[VolcanoSet](105, 232);
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------

View file

@ -345,7 +345,7 @@ class Whirlwind : Actor
} }
if ((threshold -= 3) < 0) if ((threshold -= 3) < 0)
{ {
threshold = 58 + (random[WhirlwindSeek]() & 31); threshold = random[WhirlwindSeek](58, 89);
A_PlaySound("ironlich/attack3", CHAN_BODY); A_PlaySound("ironlich/attack3", CHAN_BODY);
} }
if (tracer && tracer.bShadow) if (tracer && tracer.bShadow)

View file

@ -132,7 +132,7 @@ class BlasterFX1 : FastProjectile
{ {
if (target is "Ironlich") if (target is "Ironlich")
{ // Less damage to Ironlich bosses { // Less damage to Ironlich bosses
damage = random[BlasterFX]() & 1; damage = random[BlasterFX](0, 1);
if (!damage) if (!damage)
{ {
return -1; return -1;
@ -224,7 +224,7 @@ class Ripper : Actor
{ {
if (target is "Ironlich") if (target is "Ironlich")
{ // Less damage to Ironlich bosses { // Less damage to Ironlich bosses
damage = random[Ripper]() & 1; damage = random[Ripper](0, 1);
if (!damage) if (!damage)
{ {
return -1; return -1;

View file

@ -67,8 +67,8 @@ class Gauntlets : Weapon
if (!weapon.DepleteAmmo (weapon.bAltFire)) if (!weapon.DepleteAmmo (weapon.bAltFire))
return; return;
player.GetPSprite(PSP_WEAPON).x = ((random[GauntletAtk]() & 3) - 2); player.GetPSprite(PSP_WEAPON).x = ((random[GauntletAtk](0, 3)) - 2);
player.GetPSprite(PSP_WEAPON).y = WEAPONTOP + (random[GauntletAtk]() & 3); player.GetPSprite(PSP_WEAPON).y = WEAPONTOP + (random[GauntletAtk](0, 3));
} }
double ang = angle; double ang = angle;
if (power) if (power)

View file

@ -74,9 +74,9 @@ class Mace : HereticWeapon
} }
else else
{ {
player.GetPSprite(PSP_WEAPON).x = ((random[MaceAtk]() & 3) - 2); player.GetPSprite(PSP_WEAPON).x = random[MaceAtk](-2, 1);
player.GetPSprite(PSP_WEAPON).y = WEAPONTOP + (random[MaceAtk]() & 3); player.GetPSprite(PSP_WEAPON).y = WEAPONTOP + random[MaceAtk](0, 3);
Actor ball = SpawnPlayerMissile("MaceFX1", angle + (((random[MaceAtk]() & 7) - 4) * (360. / 256))); Actor ball = SpawnPlayerMissile("MaceFX1", angle + (random[MaceAtk](-4, 3) * (360. / 256)));
if (ball) if (ball)
{ {
ball.special1 = 16; // tics till dropoff ball.special1 = 16; // tics till dropoff

View file

@ -327,8 +327,8 @@ class HornRodFX2 : Actor
{ // Fudge rain frequency { // Fudge rain frequency
return; return;
} }
double xo = ((Random[SkullRodStorm]() & 127) - 64); double xo = Random[SkullRodStorm](-64, 63);
double yo = ((Random[SkullRodStorm]() & 127) - 64); double yo = Random[SkullRodStorm](-64, 63);
Vector3 spawnpos = Vec2OffsetZ(xo, yo, pos.z); Vector3 spawnpos = Vec2OffsetZ(xo, yo, pos.z);
Actor mo = Spawn("RainPillar", spawnpos, ALLOW_REPLACE); Actor mo = Spawn("RainPillar", spawnpos, ALLOW_REPLACE);
if (!mo) return; if (!mo) return;

View file

@ -59,7 +59,7 @@ class GoldWand : HereticWeapon
return; return;
} }
double pitch = BulletSlope(); double pitch = BulletSlope();
int damage = 7 + (random[FireGoldWand]() & 7); int damage = random[FireGoldWand](7, 14);
double ang = angle; double ang = angle;
if (player.refire) if (player.refire)
{ {

View file

@ -73,7 +73,7 @@ extend class Actor
{ {
piece.Vel = self.Vel + AngleToVector(i * 120., 1); piece.Vel = self.Vel + AngleToVector(i * 120., 1);
piece.bDropped = true; piece.bDropped = true;
j = (j == 0) ? (random[PieceDrop]() & 1) + 1 : 3-j; j = (j == 0) ? random[PieceDrop](1, 2) : 3-j;
} }
} }
} }

View file

@ -51,12 +51,12 @@ class BatSpawner : SwitchableDecoration
int delta = args[1]; int delta = args[1];
if (delta == 0) delta = 1; if (delta == 0) delta = 1;
double ang = Angle + (((random[BatSpawn]() % delta) - (delta >> 1)) * (360 / 256.)); double ang = Angle + ((random[BatSpawn](0, delta-1) - (delta >> 1)) * (360 / 256.));
Actor mo = SpawnMissileAngle ("Bat", ang, 0); Actor mo = SpawnMissileAngle ("Bat", ang, 0);
if (mo) if (mo)
{ {
mo.args[0] = random[BatSpawn]() & 63; // floatbob index mo.args[0] = random[BatSpawn](0, 63); // floatbob index
mo.args[4] = args[4]; // turn degrees mo.args[4] = args[4]; // turn degrees
mo.special2 = args[3] << 3; // Set lifetime mo.special2 = args[3] << 3; // Set lifetime
mo.target = self; mo.target = self;

View file

@ -96,7 +96,7 @@ class Bishop : Actor
targ.TraceBleed (newdam > 0 ? newdam : damage, self); targ.TraceBleed (newdam > 0 ? newdam : damage, self);
return; return;
} }
missilecount = (random[BishopAttack]() & 3) + 5; missilecount = random[BishopAttack](5, 8);
} }
//============================================================================ //============================================================================
@ -145,7 +145,7 @@ class Bishop : Actor
void A_BishopDoBlur() void A_BishopDoBlur()
{ {
missilecount = (random[BishopDoBlur]() & 3) + 3; // Random number of blurs missilecount = random[BishopDoBlur](3, 6); // Random number of blurs
if (random[BishopDoBlur]() < 120) if (random[BishopDoBlur]() < 120)
{ {
Thrust(11, Angle + 90); Thrust(11, Angle + 90);

View file

@ -305,7 +305,7 @@ class CFlameMissile : FastProjectile
mo.VelFromAngle(CircleFlame.FLAMESPEED); mo.VelFromAngle(CircleFlame.FLAMESPEED);
mo.specialf1 = mo.Vel.X; mo.specialf1 = mo.Vel.X;
mo.specialf2 = mo.Vel.Y; mo.specialf2 = mo.Vel.Y;
mo.tics -= random[FlameMissile]()&3; mo.tics -= random[FlameMissile](0, 3);
} }
an += 180; an += 180;
mo = Spawn("CircleFlame", BlockingMobj.Vec3Angle(dist, an, 5), ALLOW_REPLACE); mo = Spawn("CircleFlame", BlockingMobj.Vec3Angle(dist, an, 5), ALLOW_REPLACE);
@ -316,7 +316,7 @@ class CFlameMissile : FastProjectile
mo.VelFromAngle(-CircleFlame.FLAMESPEED); mo.VelFromAngle(-CircleFlame.FLAMESPEED);
mo.specialf1 = mo.Vel.X; mo.specialf1 = mo.Vel.X;
mo.specialf2 = mo.Vel.Y; mo.specialf2 = mo.Vel.Y;
mo.tics -= random[FlameMissile]()&3; mo.tics -= random[FlameMissile](0, 3);
} }
} }
SetState (SpawnState); SetState (SpawnState);

View file

@ -228,17 +228,17 @@ class HolyMissile : Actor
{ // float bob index { // float bob index
case 0: case 0:
mo.WeaveIndexZ = random[HolyAtk2]() & 7; // upper-left mo.WeaveIndexZ = random[HolyAtk2](0, 7); // upper-left
break; break;
case 1: case 1:
mo.WeaveIndexZ = 32 + (random[HolyAtk2]() & 7); // upper-right mo.WeaveIndexZ = random[HolyAtk2](32, 39); // upper-right
break; break;
case 2: case 2:
mo.WeaveIndexXY = 32 + (random[HolyAtk2]() & 7); // lower-left mo.WeaveIndexXY = random[HolyAtk2](32, 39); // lower-left
break; break;
case 3: case 3:
mo.WeaveIndexXY = 32 + (random[HolyAtk2]() & 7); mo.WeaveIndexXY = random[HolyAtk2](32, 39);
mo.WeaveIndexZ = 32 + (random[HolyAtk2]() & 7); mo.WeaveIndexZ = random[HolyAtk2](32, 39);
break; break;
} }
mo.SetZ(pos.z); mo.SetZ(pos.z);
@ -497,7 +497,7 @@ class HolySpirit : Actor
Vel.Y /= 4; Vel.Y /= 4;
Vel.Z = 0; Vel.Z = 0;
SetStateLabel ("Death"); SetStateLabel ("Death");
tics -= random[HolySeeker]()&3; tics -= random[HolySeeker](0, 3);
return; return;
} }
if (tracer) if (tracer)
@ -509,8 +509,8 @@ class HolySpirit : Actor
} }
} }
int xyspeed = (random[HolySeeker]() % 5); int xyspeed = random[HolySeeker](0, 4);
int zspeed = (random[HolySeeker]() % 5); int zspeed = random[HolySeeker](0, 4);
A_Weave(xyspeed, zspeed, 4., 2.); A_Weave(xyspeed, zspeed, 4., 2.);
} }

View file

@ -60,7 +60,7 @@ class CWeapMace : ClericWeapon
return; return;
} }
int damage = 25+(random[MaceAtk]()&15); int damage = random[MaceAtk](25, 40);
for (int i = 0; i < 16; i++) for (int i = 0; i < 16; i++)
{ {
for (int j = 1; j >= -1; j -= 2) for (int j = 1; j >= -1; j -= 2)

View file

@ -67,7 +67,7 @@ class CWeapStaff : ClericWeapon
} }
Weapon weapon = player.ReadyWeapon; Weapon weapon = player.ReadyWeapon;
int damage = 20 + (random[StaffCheck]() & 15); int damage = random[StaffCheck](20, 35);
int max = player.mo.GetMaxHealth(); int max = player.mo.GetMaxHealth();
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
{ {

View file

@ -224,8 +224,8 @@ class FWeapAxe : FighterWeapon
return; return;
} }
int damage = 40+(random[AxeAtk]() & 15); int damage = random[AxeAtk](40, 55);
damage += random[AxeAtk]() & 7; damage += random[AxeAtk](0, 7);
int power = 0; int power = 0;
Weapon weapon = player.ReadyWeapon; Weapon weapon = player.ReadyWeapon;
class<Actor> pufftype; class<Actor> pufftype;

View file

@ -99,7 +99,7 @@ class FWeapFist : FighterWeapon
return; return;
} }
int damage = 40 + (random[FighterAtk]() & 15); int damage = random[FighterAtk](40, 55);
for (int i = 0; i < 16; i++) for (int i = 0; i < 16; i++)
{ {
if (TryPunch(angle + i*(45./16), damage, 2) || if (TryPunch(angle + i*(45./16), damage, 2) ||

View file

@ -65,7 +65,7 @@ class FWeapHammer : FighterWeapon
return; return;
} }
int damage = 60+(random[HammerAtk]() & 63); int damage = random[HammerAtk](60, 123);
for (int i = 0; i < 16; i++) for (int i = 0; i < 16; i++)
{ {
for (int j = 1; j >= -1; j -= 2) for (int j = 1; j >= -1; j -= 2)

View file

@ -208,7 +208,7 @@ class FSwordMissile : Actor
void A_FSwordFlames() void A_FSwordFlames()
{ {
for (int i = 1+(random[FSwordFlame]()&3); i; i--) for (int i = random[FSwordFlame](1, 4); i; i--)
{ {
double xo = (random[FSwordFlame]() - 128) / 16.; double xo = (random[FSwordFlame]() - 128) / 16.;
double yo = (random[FSwordFlame]() - 128) / 16.; double yo = (random[FSwordFlame]() - 128) / 16.;

View file

@ -333,7 +333,7 @@ class ArtiPoisonBag3 : ArtiPoisonBag
Actor mo = Spawn("ThrowingBomb", Owner.Pos + (0,0,35. - Owner.Floorclip + (Owner.player? Owner.player.crouchoffset : 0)), ALLOW_REPLACE); Actor mo = Spawn("ThrowingBomb", Owner.Pos + (0,0,35. - Owner.Floorclip + (Owner.player? Owner.player.crouchoffset : 0)), ALLOW_REPLACE);
if (mo) if (mo)
{ {
mo.angle = Owner.angle + (((random[PoisonBag]() & 7) - 4) * (360./256.)); mo.angle = Owner.angle + (random[PoisonBag](-4, 3) * (360./256.));
/* Original flight code from Hexen /* Original flight code from Hexen
* mo.momz = 4*F.RACUNIT+((player.lookdir)<<(F.RACBITS-4)); * mo.momz = 4*F.RACUNIT+((player.lookdir)<<(F.RACBITS-4));
@ -358,7 +358,7 @@ class ArtiPoisonBag3 : ArtiPoisonBag
mo.AddZ(mo.Speed * sin(modpitch)); mo.AddZ(mo.Speed * sin(modpitch));
mo.target = Owner; mo.target = Owner;
mo.tics -= random[PoisonBag]()&3; mo.tics -= random[PoisonBag](0, 3);
mo.CheckMissileSpawn(Owner.radius); mo.CheckMissileSpawn(Owner.radius);
return true; return true;
} }
@ -467,7 +467,7 @@ class PoisonCloud : Actor
override void BeginPlay () override void BeginPlay ()
{ {
Vel.X = MinVel; // missile objects must move to impact other objects Vel.X = MinVel; // missile objects must move to impact other objects
special1 = 24+(random[PoisonCloud]() & 7); special1 = random[PoisonCloud](24, 31);
special2 = 0; special2 = 0;
} }
@ -495,7 +495,7 @@ class PoisonCloud : Actor
if (dopoison) if (dopoison)
{ {
damage = 15 + (random[PoisonCloud]() & 15); damage = random[PoisonCloud](15, 30);
if (mate) if (mate)
{ {
damage = (int)(damage * level.teamdamage); damage = (int)(damage * level.teamdamage);
@ -506,7 +506,7 @@ class PoisonCloud : Actor
damage = victim.ApplyDamageFactor(damagetype, damage); damage = victim.ApplyDamageFactor(damagetype, damage);
if (damage > 0) if (damage > 0)
{ {
victim.player.PoisonDamage (self, 15 + (random[PoisonCloud]() & 15), false); // Don't play painsound victim.player.PoisonDamage (self, random[PoisonCloud](15, 30), false); // Don't play painsound
// If successful, play the poison sound. // If successful, play the poison sound.
if (victim.player.PoisonPlayer (self, self.target, 50)) if (victim.player.PoisonPlayer (self, self.target, 50))

View file

@ -59,10 +59,10 @@ class FogSpawner : Actor
{ {
int delta = args[1]; int delta = args[1];
if (delta == 0) delta = 1; if (delta == 0) delta = 1;
mo.angle = angle + (((random[FogSpawn]() % delta) - (delta >> 1)) * (360 / 256.)); mo.angle = angle + ((random[FogSpawn](0, delta-1) - (delta >> 1)) * (360 / 256.));
mo.target = self; mo.target = self;
if (args[0] < 1) args[0] = 1; if (args[0] < 1) args[0] = 1;
mo.args[0] = (random[FogSpawn]() % (args[0]))+1; // Random speed mo.args[0] = random[FogSpawn](1, args[0]); // Random speed
mo.args[3] = args[3]; // Set lifetime mo.args[3] = args[3]; // Set lifetime
mo.args[4] = 1; // Set to moving mo.args[4] = 1; // Set to moving
mo.WeaveIndexZ = random[FogSpawn](0, 63); mo.WeaveIndexZ = random[FogSpawn](0, 63);

View file

@ -67,7 +67,7 @@ class ArtiHealingRadius : Inventory
case 'Mana': case 'Mana':
{ {
int amount = 50 + (random[HealRadius]() % 50); int amount = random[HealRadius](50, 99);
if (mo.GiveAmmo ("Mana1", amount) || if (mo.GiveAmmo ("Mana1", amount) ||
mo.GiveAmmo ("Mana2", amount)) mo.GiveAmmo ("Mana2", amount))
@ -79,7 +79,7 @@ class ArtiHealingRadius : Inventory
default: default:
//case NAME_Health: //case NAME_Health:
gotsome = mo.GiveBody (50 + (random[HealRadius]() % 50)); gotsome = mo.GiveBody (random[HealRadius](50, 99));
break; break;
} }
if (gotsome) if (gotsome)

View file

@ -245,9 +245,9 @@ class Heresiarch : Actor
Actor mo = Spawn("SorcSpark1", pos, ALLOW_REPLACE); Actor mo = Spawn("SorcSpark1", pos, ALLOW_REPLACE);
if (mo) if (mo)
{ {
double rangle = Angle + (random[Heresiarch]() % 5) * (4096 / 360.); double rangle = Angle + random[Heresiarch](0, 4) * (4096 / 360.);
mo.Vel.X = (random[Heresiarch]() % speed) * cos(rangle); mo.Vel.X = random[Heresiarch](0, speed - 1) * cos(rangle);
mo.Vel.Y = (random[Heresiarch]() % speed) * sin(rangle); mo.Vel.Y = random[Heresiarch](0, speed - 1) * sin(rangle);
mo.Vel.Z = 2; mo.Vel.Z = 2;
} }
} }
@ -529,9 +529,9 @@ class SorcBall : Actor
bNoGravity = false; bNoGravity = false;
Gravity = 1. / 8; Gravity = 1. / 8;
Vel.X = ((random[Heresiarch]()%10)-5); Vel.X = random[Heresiarch](-5, 4);
Vel.Y = ((random[Heresiarch]()%10)-5); Vel.Y = random[Heresiarch](-5, 4);
Vel.Z = (2+(random[Heresiarch]()%3)); Vel.Z = random[Heresiarch](2, 4);
args[4] = Heresiarch.BOUNCE_TIME_UNIT; // Bounce time unit args[4] = Heresiarch.BOUNCE_TIME_UNIT; // Bounce time unit
args[3] = 5; // Bounce time in seconds args[3] = 5; // Bounce time in seconds
} }

View file

@ -117,15 +117,15 @@ class Pottery1 : Actor
Actor mo = null; Actor mo = null;
int i; int i;
for(i = (random[Pottery]()&3)+3; i; i--) for(i = random[Pottery](3, 6); i; i--)
{ {
mo = Spawn ("PotteryBit", Pos, ALLOW_REPLACE); mo = Spawn ("PotteryBit", Pos, ALLOW_REPLACE);
if (mo) if (mo)
{ {
mo.SetState (mo.SpawnState + (random[Pottery]()%5)); mo.SetState (mo.SpawnState + random[Pottery](0, 4));
mo.Vel.X = random2[Pottery]() / 64.; mo.Vel.X = random2[Pottery]() / 64.;
mo.Vel.Y = random2[Pottery]() / 64.; mo.Vel.Y = random2[Pottery]() / 64.;
mo.Vel.Z = ((random[Pottery]() & 7) + 5) * 0.75; mo.Vel.Z = random[Pottery](5, 12) * 0.75;
} }
} }
mo.A_PlaySound ("PotteryExplode", CHAN_BODY); mo.A_PlaySound ("PotteryExplode", CHAN_BODY);
@ -227,7 +227,7 @@ class PotteryBit : Actor
void A_PotteryChooseBit() void A_PotteryChooseBit()
{ {
static const statelabel bits[] = { "Pottery1", "Pottery2", "Pottery3", "Pottery4", "Pottery5" }; static const statelabel bits[] = { "Pottery1", "Pottery2", "Pottery3", "Pottery4", "Pottery5" };
LoopState = FindState(bits[random[PotteryBit]() % 5]); // Save the state for jumping back to. LoopState = FindState(bits[random[PotteryBit](0, 4)]); // Save the state for jumping back to.
SetState (LoopState); SetState (LoopState);
tics = 256 + (random[PotteryBit]() << 1); tics = 256 + (random[PotteryBit]() << 1);
} }
@ -395,15 +395,15 @@ class ZCorpseSitting : Actor
{ {
Actor mo; Actor mo;
for (int i = (random[CorpseExplode]() & 3) + 3; i; i--) for (int i = random[CorpseExplode](3, 6); i; i--)
{ {
mo = Spawn ("CorpseBit", Pos, ALLOW_REPLACE); mo = Spawn ("CorpseBit", Pos, ALLOW_REPLACE);
if (mo) if (mo)
{ {
mo.SetState (mo.SpawnState + (random[CorpseExplode]() % 3)); mo.SetState (mo.SpawnState + random[CorpseExplode](0, 2));
mo.Vel.X = random2[CorpseExplode]() / 64.; mo.Vel.X = random2[CorpseExplode]() / 64.;
mo.Vel.Y = random2[CorpseExplode]() / 64.; mo.Vel.Y = random2[CorpseExplode]() / 64.;
mo.Vel.Z = ((random[CorpseExplode]() & 7) + 5) * 0.75; mo.Vel.Z = random[CorpseExplode](5, 12) * 0.75;
} }
} }
// Spawn a skull // Spawn a skull
@ -413,7 +413,7 @@ class ZCorpseSitting : Actor
mo.SetState (mo.SpawnState + 3); mo.SetState (mo.SpawnState + 3);
mo.Vel.X = random2[CorpseExplode]() / 64.; mo.Vel.X = random2[CorpseExplode]() / 64.;
mo.Vel.Y = random2[CorpseExplode]() / 64.; mo.Vel.Y = random2[CorpseExplode]() / 64.;
mo.Vel.Z = ((random[CorpseExplode]() & 7) + 5) * 0.75; mo.Vel.Z = random[CorpseExplode](5, 12) * 0.75;
} }
A_PlaySound (DeathSound, CHAN_BODY); A_PlaySound (DeathSound, CHAN_BODY);
Destroy (); Destroy ();
@ -449,12 +449,12 @@ class LeafSpawner : Actor
{ {
static const class<Actor> leaves[] = { "Leaf1", "Leaf2" }; static const class<Actor> leaves[] = { "Leaf1", "Leaf2" };
for (int i = (random[LeafSpawn]() & 3) + 1; i; i--) for (int i = random[LeafSpawn](1, 4); i; i--)
{ {
double xo = random2[LeafSpawn]() / 4.; double xo = random2[LeafSpawn]() / 4.;
double yo = random2[LeafSpawn]() / 4.; double yo = random2[LeafSpawn]() / 4.;
double zo = random[LeafSpawn]() / 4.; double zo = random[LeafSpawn]() / 4.;
Actor mo = Spawn (leaves[random[LeafSpawn]()&1], Vec3Offset(xo, yo, zo), ALLOW_REPLACE); Actor mo = Spawn (leaves[random[LeafSpawn](0, 1)], Vec3Offset(xo, yo, zo), ALLOW_REPLACE);
if (mo) if (mo)
{ {
@ -769,7 +769,7 @@ class ZSuitOfArmor : Actor
mo.SetState (mo.SpawnState + i); mo.SetState (mo.SpawnState + i);
mo.Vel.X = random2[SoAExplode]() / 64.; mo.Vel.X = random2[SoAExplode]() / 64.;
mo.Vel.Y = random2[SoAExplode]() / 64.; mo.Vel.Y = random2[SoAExplode]() / 64.;
mo.Vel.Z = (random[SoAExplode]() & 7) + 5; mo.Vel.Z = random[SoAExplode](5, 12);
} }
} }
// Spawn an item? // Spawn an item?

View file

@ -62,7 +62,7 @@ class IceGuy : Actor
double dist = (random[IceGuyLook]() - 128) * radius / 128.; double dist = (random[IceGuyLook]() - 128) * radius / 128.;
double an = angle + 90; double an = angle + 90;
Actor mo = Spawn(WispTypes[random[IceGuyLook]() & 1], Vec3Angle(dist, an, 60.), ALLOW_REPLACE); Actor mo = Spawn(WispTypes[random[IceGuyLook](0, 1)], Vec3Angle(dist, an, 60.), ALLOW_REPLACE);
if (mo) if (mo)
{ {
mo.Vel = Vel; mo.Vel = Vel;

View file

@ -229,7 +229,7 @@ class Korax : Actor
spirit.health = KORAX_SPIRIT_LIFETIME; spirit.health = KORAX_SPIRIT_LIFETIME;
spirit.tracer = self; // Swarm around korax spirit.tracer = self; // Swarm around korax
spirit.WeaveIndexZ = 32 + (random[Kspiritnit]() & 7); // Float bob index spirit.WeaveIndexZ = random[Kspiritnit](32, 39); // Float bob index
spirit.args[0] = 10; // initial turn value spirit.args[0] = 10; // initial turn value
spirit.args[1] = 0; // initial look angle spirit.args[1] = 0; // initial look angle
@ -258,7 +258,7 @@ class Korax : Actor
{ {
"WraithMissileFire", "DemonMissileFire", "DemonMissileFire", "FireDemonAttack", "CentaurLeaderAttack", "SerpentLeaderAttack" "WraithMissileFire", "DemonMissileFire", "DemonMissileFire", "FireDemonAttack", "CentaurLeaderAttack", "SerpentLeaderAttack"
}; };
int type = random[KoraxMissile]() % 6; int type = random[KoraxMissile](0, 5);
A_PlaySound("KoraxAttack", CHAN_VOICE); A_PlaySound("KoraxAttack", CHAN_VOICE);
@ -370,7 +370,7 @@ class Korax : Actor
numcommands = 4; numcommands = 4;
} }
ACS_Execute(250 + (random[KoraxCommand]()%numcommands), 0); ACS_Execute(250 + (random[KoraxCommand](0, numcommands)), 0);
} }
} }
@ -471,8 +471,8 @@ class KoraxSpirit : Actor
{ {
KSpiritSeeker(args[0], args[0] * 2.); KSpiritSeeker(args[0], args[0] * 2.);
} }
int xyspeed = (random[KoraxRoam]() % 5); int xyspeed = random[KoraxRoam](0, 4);
int zspeed = (random[KoraxRoam]() % 5); int zspeed = random[KoraxRoam](0, 4);
A_Weave(xyspeed, zspeed, 4., 2.); A_Weave(xyspeed, zspeed, 4., 2.);
if (random[KoraxRoam]() < 50) if (random[KoraxRoam]() < 50)

View file

@ -68,7 +68,7 @@ class MWeapFrost : MageWeapon
} }
A_PlaySound ("MageShardsFire", CHAN_WEAPON); A_PlaySound ("MageShardsFire", CHAN_WEAPON);
int damage = 90+(random[MageCone]() & 15); int damage = random[MageCone](90, 105);
for (int i = 0; i < 16; i++) for (int i = 0; i < 16; i++)
{ {
double ang = angle + i*(45./16); double ang = angle + i*(45./16);

View file

@ -911,7 +911,7 @@ class PowerTorch : PowerLightAmp
} }
else else
{ {
NewTorch = (random[torch]() & 7) + 1; NewTorch = random[torch](1, 8);
NewTorchDelta = (NewTorch == Owner.player.fixedlightlevel) ? NewTorchDelta = (NewTorch == Owner.player.fixedlightlevel) ?
0 : ((NewTorch > player.fixedlightlevel) ? 1 : -1); 0 : ((NewTorch > player.fixedlightlevel) ? 1 : -1);
} }

View file

@ -409,13 +409,13 @@ class Minotaur : Actor
if (random[MinotaurRoam]() < 6) if (random[MinotaurRoam]() < 6)
{ {
//Choose new direction //Choose new direction
movedir = random[MinotaurRoam]() % 8; movedir = random[MinotaurRoam](0, 7);
FaceMovementDirection (); FaceMovementDirection ();
} }
if (!MonsterMove()) if (!MonsterMove())
{ {
// Turn // Turn
if (random[MinotaurRoam]() & 1) if (random[MinotaurRoam](0, 1))
movedir = (movedir + 1) % 8; movedir = (movedir + 1) % 8;
else else
movedir = (movedir + 7) % 8; movedir = (movedir + 7) % 8;

View file

@ -24,7 +24,7 @@ class IceChunk : Actor
void A_IceSetTics () void A_IceSetTics ()
{ {
tics = 70 + (random[IceTics]() & 63); tics = random[IceTics](70, 133);
Name dtype = GetFloorTerrain().DamageMOD; Name dtype = GetFloorTerrain().DamageMOD;
if (dtype == 'Fire') if (dtype == 'Fire')
{ {
@ -134,7 +134,7 @@ extend class Actor
// things break up into more shards than smaller things. // things break up into more shards than smaller things.
// An actor with radius 20 and height 64 creates ~40 chunks. // An actor with radius 20 and height 64 creates ~40 chunks.
int numChunks = max(4, int(radius * Height)/32); int numChunks = max(4, int(radius * Height)/32);
int i = Random[FreezeDeathChunks]() % (numChunks/4); int i = Random[FreezeDeathChunks](0, numChunks/4 - 1);
for (i = max(24, numChunks + i); i >= 0; i--) for (i = max(24, numChunks + i); i >= 0; i--)
{ {
double xo = (random[FreezeDeathChunks]() - 128)*radius / 128; double xo = (random[FreezeDeathChunks]() - 128)*radius / 128;
@ -144,7 +144,7 @@ extend class Actor
Actor mo = Spawn("IceChunk", Vec3Offset(xo, yo, zo), ALLOW_REPLACE); Actor mo = Spawn("IceChunk", Vec3Offset(xo, yo, zo), ALLOW_REPLACE);
if (mo) if (mo)
{ {
mo.SetState (mo.SpawnState + (random[FreezeDeathChunks]()%3)); mo.SetState (mo.SpawnState + random[FreezeDeathChunks](0, 2));
mo.Vel.X = random2[FreezeDeathChunks]() / 128.; mo.Vel.X = random2[FreezeDeathChunks]() / 128.;
mo.Vel.Y = random2[FreezeDeathChunks]() / 128.; mo.Vel.Y = random2[FreezeDeathChunks]() / 128.;
mo.Vel.Z = (mo.pos.Z - pos.Z) / Height * 4; mo.Vel.Z = (mo.pos.Z - pos.Z) / Height * 4;

View file

@ -160,7 +160,7 @@ class EntityBoss : SpectralMonster
{ {
// Apparent Strife bug: Case 5 was unreachable because they used % 5 instead of % 6. // Apparent Strife bug: Case 5 was unreachable because they used % 5 instead of % 6.
// I've fixed that by making case 1 duplicate it, since case 1 did nothing. // I've fixed that by making case 1 duplicate it, since case 1 did nothing.
switch (random[Entity]() % 5) switch (random[Entity](0, 4))
{ {
case 0: case 0:
A_SpotLightning(); A_SpotLightning();

View file

@ -94,7 +94,7 @@ class Programmer : Actor
A_PlaySound("programmer/clank", CHAN_WEAPON); A_PlaySound("programmer/clank", CHAN_WEAPON);
int damage = ((random[Programmer]() % 10) + 1) * 6; int damage = random[Programmer](1, 10) * 6;
int newdam = target.DamageMobj (self, self, damage, 'Melee'); int newdam = target.DamageMobj (self, self, damage, 'Melee');
target.TraceBleed (newdam > 0 ? newdam : damage, self); target.TraceBleed (newdam > 0 ? newdam : damage, self);
} }

View file

@ -79,7 +79,7 @@ extend class Actor
for (int i = 0; i < 3; ++i) for (int i = 0; i < 3; ++i)
{ {
double ang = bangle + Random2[ReaverAttack]() * (22.5 / 256); double ang = bangle + Random2[ReaverAttack]() * (22.5 / 256);
int damage = ((random[ReaverAttack]() & 7) + 1) * 3; int damage = random[ReaverAttack](1, 8) * 3;
LineAttack (ang, MISSILERANGE, pitch, damage, 'Hitscan', "StrifePuff"); LineAttack (ang, MISSILERANGE, pitch, damage, 'Hitscan', "StrifePuff");
} }
} }

View file

@ -28,13 +28,13 @@ class SpectralMonster : Actor
{ {
int t; int t;
t = random[SpectreChunk]() & 15; t = random[SpectreChunk](0, 7);
foo.Vel.X = (t - (random[SpectreChunk]() & 7)); foo.Vel.X = t - random[SpectreChunk](0, 15);
t = random[SpectreChunk]() & 15; t = random[SpectreChunk](0, 7);
foo.Vel.Y = (t - (random[SpectreChunk]() & 7)); foo.Vel.Y = t - random[SpectreChunk](0, 15);
foo.Vel.Z = (random[SpectreChunk]() & 15); foo.Vel.Z = random[SpectreChunk](0, 15);
} }
} }
@ -46,13 +46,13 @@ class SpectralMonster : Actor
{ {
int t; int t;
t = random[SpectreChunk]() & 7; t = random[SpectreChunk](0, 7);
foo.Vel.X = (t - (random[SpectreChunk]() & 15)); foo.Vel.X = t - random[SpectreChunk](0, 15);
t = random[SpectreChunk]() & 7; t = random[SpectreChunk](0, 7);
foo.Vel.Y = (t - (random[SpectreChunk]() & 15)); foo.Vel.Y = t - random[SpectreChunk](0, 15);
foo.Vel.Z = (random[SpectreChunk]() & 7); foo.Vel.Z = random[SpectreChunk](0, 7);
} }
} }

View file

@ -118,7 +118,7 @@ class Stalker : Actor
if (CheckMeleeRange ()) if (CheckMeleeRange ())
{ {
let targ = target; let targ = target;
int damage = (random[Stalker]() & 7) * 2 + 2; int damage = random[Stalker](1, 8) * 2;
int newdam = targ.DamageMobj (self, self, damage, 'Melee'); int newdam = targ.DamageMobj (self, self, damage, 'Melee');
targ.TraceBleed (newdam > 0 ? newdam : damage, self); targ.TraceBleed (newdam > 0 ? newdam : damage, self);

View file

@ -66,9 +66,9 @@ extend class Actor
return; return;
} }
gib.Angle = random[GibTosser]() * (360 / 256.f); gib.Angle = random[GibTosser]() * (360 / 256.);
gib.VelFromAngle(random[GibTosser]() & 15); gib.VelFromAngle(random[GibTosser](0, 15));
gib.Vel.Z = random[GibTosser]() & 15; gib.Vel.Z = random[GibTosser](0, 15);
} }
//========================================================================== //==========================================================================
@ -83,7 +83,7 @@ extend class Actor
A_PlaySound ("monsters/rifle", CHAN_WEAPON); A_PlaySound ("monsters/rifle", CHAN_WEAPON);
A_FaceTarget (); A_FaceTarget ();
double pitch = AimLineAttack (angle, MISSILERANGE); double pitch = AimLineAttack (angle, MISSILERANGE);
LineAttack (Angle + Random2[ShootGun]() * (11.25 / 256), MISSILERANGE, pitch, 3*(random[ShootGun]() % 5 + 1), 'Hitscan', "StrifePuff"); LineAttack (Angle + Random2[ShootGun]() * (11.25 / 256), MISSILERANGE, pitch, 3*random[ShootGun](1, 5), 'Hitscan', "StrifePuff");
} }
//========================================================================== //==========================================================================
@ -113,7 +113,7 @@ extend class Actor
void A_GetHurt() void A_GetHurt()
{ {
bInCombat = true; bInCombat = true;
if ((random[HurtMe]() % 5) == 0) if (random[HurtMe](0, 4) == 0)
{ {
A_PlaySound (PainSound, CHAN_VOICE); A_PlaySound (PainSound, CHAN_VOICE);
health--; health--;

View file

@ -1927,7 +1927,7 @@ class Meat : Actor
override void BeginPlay () override void BeginPlay ()
{ {
// Strife used mod 19, but there are 20 states. Hmm. // Strife used mod 19, but there are 20 states. Hmm.
SetState (SpawnState + random[GibTosser]() % 20); SetState (SpawnState + random[GibTosser](0, 19));
} }
} }

View file

@ -74,7 +74,7 @@ class Templar : Actor
for (int i = 0; i < 10; ++i) for (int i = 0; i < 10; ++i)
{ {
int damage = (random[Templar]() & 4) * 2; int damage = random[Templar](1, 4) * 2;
double ang = angle + random2[Templar]() * (11.25 / 256); double ang = angle + random2[Templar]() * (11.25 / 256);
LineAttack (ang, MISSILERANGE+64., pitch + random2[Templar]() * (7.097 / 256), damage, 'Hitscan', "MaulerPuff"); LineAttack (ang, MISSILERANGE+64., pitch + random2[Templar]() * (7.097 / 256), damage, 'Hitscan', "MaulerPuff");
} }

View file

@ -3,8 +3,8 @@ extend class Actor
void A_Bang4Cloud() void A_Bang4Cloud()
{ {
double xo = (random[Bang4Cloud]() & 3) * (10. / 64); double xo = random[Bang4Cloud](0, 3) * (10. / 64);
double yo = (random[Bang4Cloud]() & 3) * (10. / 64); double yo = random[Bang4Cloud](0, 3) * (10. / 64);
Spawn("Bang4Cloud", Vec3Offset(xo, yo, 0.), ALLOW_REPLACE); Spawn("Bang4Cloud", Vec3Offset(xo, yo, 0.), ALLOW_REPLACE);
} }
@ -221,10 +221,11 @@ class PowerCrystal : Actor
Actor foo = Spawn("Rubble1", Pos, ALLOW_REPLACE); Actor foo = Spawn("Rubble1", Pos, ALLOW_REPLACE);
if (foo != NULL) if (foo != NULL)
{ {
int t = random[LightOut]() & 15; int t = random[LightOut](0, 7);
foo.Vel.X = t - (random[LightOut]() & 7); foo.Vel.X = t - random[LightOut](0, 15);
foo.Vel.Y = random2[LightOut]() & 7; t = random[LightOut](0, 7);
foo.Vel.Z = 7 + (random[LightOut]() & 3); foo.Vel.Y = t - random[LightOut](0, 15);
foo.Vel.Z = random[LightOut](7, 10);
} }
} }
} }

View file

@ -62,7 +62,7 @@ extend class StateProvider
} }
player.mo.PlayAttacking2 (); player.mo.PlayAttacking2 ();
int damage = 4*(random[StrifeGun]() % 3 + 1); int damage = 4 * random[StrifeGun](1, 3);
double ang = angle; double ang = angle;
if (player.refire) if (player.refire)

View file

@ -49,7 +49,7 @@ class PunchDagger : StrifeWeapon
else else
{ {
int power = MIN(10, stamina / 10); int power = MIN(10, stamina / 10);
damage = (random[JabDagger]() % (power + 8)) * (power + 2); damage = random[JabDagger](0, power + 7) * (power + 2);
if (FindInventory("PowerStrength")) if (FindInventory("PowerStrength"))
{ {

View file

@ -113,7 +113,7 @@ class FlameMissile : Actor
void A_FlameDie () void A_FlameDie ()
{ {
bNoGravity = true; bNoGravity = true;
Vel.Z = random[FlameDie]() & 3; Vel.Z = random[FlameDie](0, 3);
} }
} }

View file

@ -312,7 +312,7 @@ class PhosphorousFire : Actor
drop.Vel.X = Vel.X + random2[PHBurn] (7); drop.Vel.X = Vel.X + random2[PHBurn] (7);
drop.Vel.Y = Vel.Y + random2[PHBurn] (7); drop.Vel.Y = Vel.Y + random2[PHBurn] (7);
drop.Vel.Z = Vel.Z - 1; drop.Vel.Z = Vel.Z - 1;
drop.reactiontime = (random[PHBurn]() & 3) + 2; drop.reactiontime = random[PHBurn](2, 5);
drop.bDropped = true; drop.bDropped = true;
} }
} }