by NeuralStunner » Sat Jun 30, 2012 5:05 pm
I'm trying to implement some custom inaccuracy code and keep running into a snag: FRandom only evaluates as a float when used alone. Even multiple FRandoms have to each be multiplied by 1.0 for the resulting expression to remain a float.
Here's some test code. I recommend E1M1, right across from the start is a wide flat wall.
Use TimeFreeze so you can see the shot patterns. The first gun (Slot 3) simply uses 10 degrees in either direction. The second (Slot 4) adds together two random results of 5 degrees, giving it a 10 degree spread but making the extremes less likely.
With both guns, primary fire will give a desired result (an irregular but continuous line of puffs) while alternate fire gives a bad result (only on whole angles, giving a uniform dotted-line of puffs).
Spoiler: Decorate.txt
Code: Select all
Actor CastingGun1 : Shotgun Replaces Shotgun
{
Weapon.SlotNumber 3
States
{
Fire:
SHTG A 3
Hold:
SHTG AAAAAAAAAA 0 A_FireBullets (FRandom(-10,10), 0, 7, 5, "BulletPuff", FBF_ExplicitAngle)
Fire1:
SHTG A 0 A_PlaySound ("weapons/shotgf", Chan_Weapon)
SHTG A 7 A_GunFlash
SHTG A 0 A_Refire
SHTG BC 5
SHTG D 4
SHTG CB 5
SHTG A 3
SHTG A 7 A_ReFire
Goto Ready
AltFire:
SHTG A 3
AltHold:
SHTG AAAAAAAAAA 0 A_FireBullets (FRandom(-10,10) * 1, 0, 7, 5, "BulletPuff", FBF_ExplicitAngle)
Goto Fire1
}
}
Actor CastingGun2 : Shotgun Replaces Chaingun
{
Weapon.SlotNumber 4
States
{
Fire:
SHTG A 3
Hold:
SHTG AAAAAAAAAA 0 A_FireBullets ((FRandom(-5,5) * 1.0) + (FRandom(-5,5) * 1.0), 0, 7, 5, "BulletPuff", FBF_ExplicitAngle)
Fire1:
SHTG A 0 A_PlaySound ("weapons/shotgf", Chan_Weapon)
SHTG A 7 A_GunFlash
SHTG A 0 A_Refire
SHTG BC 5
SHTG D 4
SHTG CB 5
SHTG A 3
SHTG A 7 A_ReFire
Goto Ready
AltFire:
SHTG A 3
AltHold:
SHTG AAAAAAAAAA 0 A_FireBullets (FRandom(-5,5) + FRandom(-5,5), 0, 7, 5, "BulletPuff", FBF_ExplicitAngle)
Goto Fire1
}
}
In short: If I want to use FRandom() more than once in an expression, I have to replace it with (FRandom() * 1.0), which is really bizarre.
I hope I explained well enough.
I'm trying to implement some custom inaccuracy code and keep running into a snag: FRandom only evaluates as a float when used alone. Even multiple FRandoms have to each be multiplied by 1.0 for the resulting expression to remain a float.
Here's some test code. I recommend E1M1, right across from the start is a wide flat wall.
Use TimeFreeze so you can see the shot patterns. The first gun (Slot 3) simply uses 10 degrees in either direction. The second (Slot 4) adds together two random results of 5 degrees, giving it a 10 degree spread but making the extremes less likely.
With both guns, primary fire will give a desired result (an irregular but continuous line of puffs) while alternate fire gives a bad result (only on whole angles, giving a uniform dotted-line of puffs).
[spoiler=Decorate.txt][code]
Actor CastingGun1 : Shotgun Replaces Shotgun
{
Weapon.SlotNumber 3
States
{
Fire:
SHTG A 3
Hold:
SHTG AAAAAAAAAA 0 A_FireBullets (FRandom(-10,10), 0, 7, 5, "BulletPuff", FBF_ExplicitAngle)
Fire1:
SHTG A 0 A_PlaySound ("weapons/shotgf", Chan_Weapon)
SHTG A 7 A_GunFlash
SHTG A 0 A_Refire
SHTG BC 5
SHTG D 4
SHTG CB 5
SHTG A 3
SHTG A 7 A_ReFire
Goto Ready
AltFire:
SHTG A 3
AltHold:
SHTG AAAAAAAAAA 0 A_FireBullets (FRandom(-10,10) * 1, 0, 7, 5, "BulletPuff", FBF_ExplicitAngle)
Goto Fire1
}
}
Actor CastingGun2 : Shotgun Replaces Chaingun
{
Weapon.SlotNumber 4
States
{
Fire:
SHTG A 3
Hold:
SHTG AAAAAAAAAA 0 A_FireBullets ((FRandom(-5,5) * 1.0) + (FRandom(-5,5) * 1.0), 0, 7, 5, "BulletPuff", FBF_ExplicitAngle)
Fire1:
SHTG A 0 A_PlaySound ("weapons/shotgf", Chan_Weapon)
SHTG A 7 A_GunFlash
SHTG A 0 A_Refire
SHTG BC 5
SHTG D 4
SHTG CB 5
SHTG A 3
SHTG A 7 A_ReFire
Goto Ready
AltFire:
SHTG A 3
AltHold:
SHTG AAAAAAAAAA 0 A_FireBullets (FRandom(-5,5) + FRandom(-5,5), 0, 7, 5, "BulletPuff", FBF_ExplicitAngle)
Goto Fire1
}
}
[/code][/spoiler]
In short: If I want to use FRandom() more than once in an expression, I have to replace it with (FRandom() * 1.0), which is really bizarre.
I hope I explained well enough.