- reviewd script code for spawn calls that did not check their results.

Nothing should ever assume that spawning an actor is unconditionally successful. There can always be some edge cases where this is not the case.
This commit is contained in:
Christoph Oelckers 2016-12-31 15:40:16 +01:00
parent c845fc126a
commit 3d61d2c1f4
24 changed files with 222 additions and 130 deletions

View file

@ -116,12 +116,15 @@ extend class Actor
A_FaceTarget ();
Actor fog = Spawn (fire, target.Pos, ALLOW_REPLACE);
if (fog != null)
{
tracer = fog;
fog.target = self;
fog.tracer = self.target;
fog.A_Fire(0);
}
}
}
void A_VileAttack(sound snd = "vile/stop", int initialdmg = 20, int blastdmg = 70, int blastradius = 70, double thrust = 1.0, name damagetype = "Fire", int flags = 0)
{

View file

@ -188,6 +188,7 @@ extend class Actor
// Now launch mushroom cloud
Actor aimtarget = Spawn("Mapspot", pos, NO_REPLACE); // We need something to aim at.
if (aimtarget == null) return;
Actor owner = (flags & MSF_DontHurt) ? target : self;
aimtarget.Height = Height;

View file

@ -233,10 +233,13 @@ extend class Actor
SpawnPuff ("BulletPuff", pos, angle, angle, 3);
Actor smoke = Spawn ("RevenantTracerSmoke", Vec3Offset(-Vel.X, -Vel.Y, 0.), ALLOW_REPLACE);
if (smoke != null)
{
smoke.Vel.Z = 1.;
smoke.tics -= random[Tracer](0, 3);
if (smoke.tics < 1)
smoke.tics = 1;
}
// The rest of this function was identical with Strife's version, except for the angle being used.
A_Tracer2(16.875);

View file

@ -335,6 +335,8 @@ extend class Actor
for (int i = 0; i < count; i++)
{
Actor mo = Spawn("Feather", pos + (0, 0, 20), NO_REPLACE);
if (mo != null)
{
mo.target = self;
mo.Vel.X = Random2[Feathers]() / 256.;
mo.Vel.Y = Random2[Feathers]() / 256.;
@ -342,5 +344,6 @@ extend class Actor
mo.SetState (mo.SpawnState + (random[Feathers]()&7));
}
}
}
}

View file

@ -166,13 +166,14 @@ class Sorcerer1 : Actor
{
bSolid = false;
Actor mo = Spawn("Sorcerer2", Pos, ALLOW_REPLACE);
if (mo != null)
{
mo.Translation = Translation;
mo.SetStateLabel("Rise");
mo.angle = angle;
mo.CopyFriendliness (self, true);
}
}
}
@ -434,12 +435,15 @@ class Sorcerer2FX1 : Actor
for (int i = 0; i < 2; i++)
{
Actor mo = Spawn("Sorcerer2FXSpark", pos, ALLOW_REPLACE);
if (mo != null)
{
mo.Vel.X = Random2[BlueSpark]() / 128.;
mo.Vel.Y = Random2[BlueSpark]() / 128.;
mo.Vel.Z = 1. + Random[BlueSpark]() / 256.;
}
}
}
}
// Sorcerer 2 FX Spark ------------------------------------------------------

View file

@ -149,7 +149,7 @@ Class ArtiTimeBomb : Inventory
override bool Use (bool pickup)
{
Actor mo = Spawn("ActivatedTimeBomb", Owner.Vec3Angle(24., Owner.angle, - Owner.Floorclip), ALLOW_REPLACE);
mo.target = Owner;
if (mo != null) mo.target = Owner;
return true;
}

View file

@ -102,14 +102,20 @@ class HereticImp : Actor
bNoGravity = false;
chunk = Spawn("HereticImpChunk1", pos, ALLOW_REPLACE);
if (chunk != null)
{
chunk.vel.x = random2[ImpExplode]() / 64.;
chunk.vel.y = random2[ImpExplode]() / 64.;
chunk.vel.z = 9;
}
chunk = Spawn("HereticImpChunk2", pos, ALLOW_REPLACE);
if (chunk != null)
{
chunk.vel.x = random2[ImpExplode]() / 64.;
chunk.vel.y = random2[ImpExplode]() / 64.;
chunk.vel.z = 9;
}
if (extremecrash)
{

View file

@ -60,12 +60,15 @@ class Pod : Actor
for (int count = chance > 240 ? 2 : 1; count; count--)
{
Actor goo = Spawn(gootype, pos + (0, 0, 48), ALLOW_REPLACE);
if (goo != null)
{
goo.target = self;
goo.Vel.X = Random2[PodPain]() / 128.;
goo.Vel.Y = Random2[PodPain]() / 128.;
goo.Vel.Z = 0.5 + random[PodPain]() / 128.;
}
}
}
//----------------------------------------------------------------------------
//
@ -295,6 +298,8 @@ class Volcano : Actor
for (int i = 0; i < count; i++)
{
Actor blast = Spawn("VolcanoBlast", pos + (0, 0, 44), ALLOW_REPLACE);
if (blast != null)
{
blast.target = self;
blast.Angle = random[VolcanoBlast]() * (360 / 256.);
blast.VelFromAngle(1.);
@ -304,6 +309,7 @@ class Volcano : Actor
}
}
}
}
// Volcano blast ------------------------------------------------------------

View file

@ -102,6 +102,8 @@ class Ironlich : Actor
{
A_PlaySound ("ironlich/attack1", CHAN_BODY);
}
if (fire != null)
{
fire.target = baseFire.target;
fire.angle = baseFire.angle;
fire.Vel = baseFire.Vel;
@ -111,6 +113,7 @@ class Ironlich : Actor
}
}
}
}
else
{ // Whirlwind
Actor mo = SpawnMissile (target, "Whirlwind");
@ -167,6 +170,8 @@ class HeadFX1 : Actor
for (int i = 0; i < 8; i++)
{
Actor shard = Spawn("HeadFX2", Pos, ALLOW_REPLACE);
if (shard != null)
{
shard.target = target;
shard.angle = i*45.;
shard.VelFromAngle();
@ -175,6 +180,7 @@ class HeadFX1 : Actor
}
}
}
}
// Head FX 2 ----------------------------------------------------------------

View file

@ -163,8 +163,11 @@ class RedAxe : KnightAxe
double xo = random2[DripBlood]() / 32.0;
double yo = random2[DripBlood]() / 32.0;
Actor mo = Spawn ("Blood", Vec3Offset(xo, yo, 0.), ALLOW_REPLACE);
if (mo != null)
{
mo.Vel.X = random2[DripBlood]() / 64.0;
mo.Vel.Y = random2[DripBlood]() / 64.0;
mo.Gravity = 1./8;
}
}
}

View file

@ -160,6 +160,8 @@ class BlasterFX1 : FastProjectile
for(int i = 0; i < 8; i++)
{
Actor ripper = Spawn("Ripper", pos, ALLOW_REPLACE);
if (ripper != null)
{
ripper.target = target;
ripper.angle = i*45;
ripper.VelFromAngle();
@ -167,6 +169,7 @@ class BlasterFX1 : FastProjectile
}
}
}
}
// Blaster smoke ------------------------------------------------------------

View file

@ -60,6 +60,8 @@ class Mace : HereticWeapon
if (random[MaceAtk]() < 28)
{
Actor ball = Spawn("MaceFX2", Pos + (0, 0, 28 - Floorclip), ALLOW_REPLACE);
if (ball != null)
{
ball.Vel.Z = 2 - clamp(tan(pitch), -5, 5);
ball.target = self;
ball.angle = self.angle;
@ -69,6 +71,7 @@ class Mace : HereticWeapon
ball.A_PlaySound ("weapons/maceshoot", CHAN_BODY);
ball.CheckMissileSpawn (radius);
}
}
else
{
player.GetPSprite(PSP_WEAPON).x = ((random[MaceAtk]() & 3) - 2);
@ -260,18 +263,24 @@ class MaceFX2 : MaceFX1
SetState (SpawnState);
Actor tiny = Spawn("MaceFX3", Pos, ALLOW_REPLACE);
if (tiny != null)
{
tiny.target = target;
tiny.angle = angle + 90.;
tiny.VelFromAngle(Vel.Z - 1.);
tiny.Vel += (Vel.XY * .5, Vel.Z);
tiny.CheckMissileSpawn (radius);
}
tiny = Spawn("MaceFX3", Pos, ALLOW_REPLACE);
if (tiny != null)
{
tiny.target = target;
tiny.angle = angle - 90.;
tiny.VelFromAngle(Vel.Z - 1.);
tiny.Vel += (Vel.XY * .5, Vel.Z);
tiny.CheckMissileSpawn (radius);
}
return;
}
}

View file

@ -151,16 +151,19 @@ class PhoenixRodPowered : PhoenixRod
slope += 0.1;
Actor mo = Spawn("PhoenixFX2", spawnpos, ALLOW_REPLACE);
if (mo != null)
{
mo.target = self;
mo.Angle = Angle;
mo.VelFromAngle();
mo.Vel.XY += Vel.XY;
mo.Vel.Z = mo.Speed * slope;
mo.CheckMissileSpawn (radius);
}
if (!player.refire)
{
A_PlaySound("weapons/phoenixpowshoot", CHAN_WEAPON, 1, true);
}
mo.CheckMissileSpawn (radius);
}
//----------------------------------------------------------------------------
@ -239,11 +242,17 @@ class PhoenixFX1 : Actor
//[RH] Heretic never sets the target for seeking
//P_SeekerMissile (self, 5, 10);
Actor puff = Spawn("PhoenixPuff", Pos, ALLOW_REPLACE);
if (puff != null)
{
puff.Vel.XY = AngleToVector(Angle + 90, 1.3);
}
puff = Spawn("PhoenixPuff", Pos, ALLOW_REPLACE);
if (puff != null)
{
puff.Vel.XY = AngleToVector(Angle - 90, 1.3);
}
}
}

View file

@ -70,7 +70,8 @@ extend class Actor
// [RH] Floor and ceiling huggers should not be blasted vertically.
if (!victim.bFloorHugger && !victim.bCeilingHugger)
{
mo.Vel.Z = victim.Vel.Z = 8;
victim.Vel.Z = 8;
if (mo != null) mo.Vel.Z = 8;
}
}
else

View file

@ -567,6 +567,8 @@ class HolyTail : Actor
static void SpawnSpiritTail (Actor spirit)
{
Actor tail = Spawn ("HolyTail", spirit.Pos, ALLOW_REPLACE);
if (tail != null)
{
tail.target = spirit; // parent
for (int i = 1; i < 3; i++)
{
@ -576,6 +578,7 @@ class HolyTail : Actor
}
tail.tracer = null; // last tail bit
}
}
//============================================================================
//

View file

@ -255,10 +255,13 @@ class ArtiPoisonBag : Inventory
}
class<Actor> spawntype = GetFlechetteType(other);
Inventory copy = Inventory(Spawn (spawntype));
let copy = Inventory(Spawn (spawntype));
if (copy != null)
{
copy.Amount = Amount;
copy.MaxAmount = MaxAmount;
GoAwayAndDie ();
}
return copy;
}
}

View file

@ -315,6 +315,8 @@ class Korax : Actor
private void SpawnKoraxMissile (Vector3 pos, Actor dest, Class<Actor> type)
{
Actor th = Spawn (type, pos, ALLOW_REPLACE);
if (th != null)
{
th.target = self; // Originator
double an = th.AngleTo(dest);
if (dest.bShadow)
@ -327,6 +329,7 @@ class Korax : Actor
th.Vel.Z = (dest.pos.z - pos.Z + 30) / dist;
th.CheckMissileSpawn(radius);
}
}
//============================================================================
//

View file

@ -262,7 +262,7 @@ class Minotaur : Actor
type = "PunchPuff";
}
Actor puff = Spawn (type, Pos, ALLOW_REPLACE);
puff.Vel.Z = 2;
if (puff != null) puff.Vel.Z = 2;
special1--;
}
else
@ -710,11 +710,14 @@ class MinotaurFX2 : MinotaurFX1
double y = Random2[MntrFloorFire]() / 64.;
Actor mo = Spawn("MinotaurFX3", Vec2OffsetZ(x, y, floorz), ALLOW_REPLACE);
if (mo != null)
{
mo.target = target;
mo.Vel.X = MinVel; // Force block checking
mo.CheckMissileSpawn (radius);
}
}
}
// Minotaur FX 3 ------------------------------------------------------------

View file

@ -202,11 +202,14 @@ class EntityBoss : SpectralMonster
Vector3 pos = spot.Vec3Angle(secondRadius, an, tracer ? 70. : 0.);
second = Spawn("EntitySecond", pos, ALLOW_REPLACE);
if (second != null)
{
second.CopyFriendliness(self, true);
second.A_FaceTarget();
second.VelFromAngle(i == 0? 4.8828125 : secondRadius * 4., an);
}
}
}
}

View file

@ -171,10 +171,13 @@ class Inquisitor : Actor
void A_TossArm ()
{
Actor foo = Spawn("InquisitorArm", Pos + (0,0,24), ALLOW_REPLACE);
if (foo != null)
{
foo.angle = angle - 90. + Random2[Inquisitor]() * (360./1024.);
foo.VelFromAngle(foo.Speed / 8);
foo.Vel.Z = random[Inquisitor]() / 64.;
}
}
}

View file

@ -163,6 +163,10 @@ class TeleporterBeacon : Inventory
{
Actor owner = target;
Actor rebel = Spawn("Rebel1", (pos.xy, floorz), ALLOW_REPLACE);
if (rebel == null)
{
return;
}
if (!rebel.TryMove (rebel.Pos.xy, true))
{
rebel.Destroy ();

View file

@ -268,7 +268,7 @@ class Sigil : Weapon
action void A_FireSigil1 ()
{
Actor spot;
Actor spot = null;
FTranslatedLineTarget t;
if (player == null || player.ReadyWeapon == null)

View file

@ -62,11 +62,13 @@ class SpectralMonster : Actor
return;
Actor foo = Spawn("SpectralLightningV2", Pos + (0, 0, 32), ALLOW_REPLACE);
if (foo != null)
{
foo.Vel.Z = -12;
foo.target = self;
foo.FriendPlayer = 0;
foo.tracer = target;
}
Angle -= 90.;
for (int i = 0; i < 20; ++i)
@ -217,11 +219,13 @@ class SpectralLightningH1 : SpectralLightningBase
void A_SpectralLightningTail ()
{
Actor foo = Spawn("SpectralLightningHTail", Vec3Offset(-Vel.X, -Vel.Y, 0.), ALLOW_REPLACE);
if (foo != null)
{
foo.Angle = Angle;
foo.FriendPlayer = FriendPlayer;
}
}
}
// Spectral Lightning (Horizontal #2) -------------------------------------
@ -386,16 +390,22 @@ class SpectralLightningSpot : SpectralLightningDeath1
Actor flash = Spawn (cls, Vec2OffsetZ(xo, yo, ONCEILINGZ), ALLOW_REPLACE);
if (flash != null)
{
flash.target = target;
flash.Vel.Z = -18;
flash.FriendPlayer = FriendPlayer;
}
flash = Spawn("SpectralLightningV2", (pos.xy, ONCEILINGZ), ALLOW_REPLACE);
if (flash != null)
{
flash.target = target;
flash.Vel.Z = -18;
flash.FriendPlayer = FriendPlayer;
}
}
}

View file

@ -133,7 +133,10 @@ extend class Actor
void A_DropFire()
{
Actor drop = Spawn("FireDroplet", pos + (0,0,24), ALLOW_REPLACE);
if (drop != null)
{
drop.Vel.Z = -1.;
}
A_Explode(64, 64, XF_NOSPLASH, damagetype: 'Fire');
}