- 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,10 +116,13 @@ extend class Actor
A_FaceTarget ();
Actor fog = Spawn (fire, target.Pos, ALLOW_REPLACE);
tracer = fog;
fog.target = self;
fog.tracer = self.target;
fog.A_Fire(0);
if (fog != null)
{
tracer = fog;
fog.target = self;
fog.tracer = self.target;
fog.A_Fire(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);
smoke.Vel.Z = 1.;
smoke.tics -= random[Tracer](0, 3);
if (smoke.tics < 1)
smoke.tics = 1;
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,11 +335,14 @@ extend class Actor
for (int i = 0; i < count; i++)
{
Actor mo = Spawn("Feather", pos + (0, 0, 20), NO_REPLACE);
mo.target = self;
mo.Vel.X = Random2[Feathers]() / 256.;
mo.Vel.Y = Random2[Feathers]() / 256.;
mo.Vel.Z = 1. + random[Feathers]() / 128.;
mo.SetState (mo.SpawnState + (random[Feathers]()&7));
if (mo != null)
{
mo.target = self;
mo.Vel.X = Random2[Feathers]() / 256.;
mo.Vel.Y = Random2[Feathers]() / 256.;
mo.Vel.Z = 1. + random[Feathers]() / 128.;
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);
mo.Translation = Translation;
mo.SetStateLabel("Rise");
mo.angle = angle;
mo.CopyFriendliness (self, true);
if (mo != null)
{
mo.Translation = Translation;
mo.SetStateLabel("Rise");
mo.angle = angle;
mo.CopyFriendliness (self, true);
}
}
}
@ -434,9 +435,12 @@ class Sorcerer2FX1 : Actor
for (int i = 0; i < 2; i++)
{
Actor mo = Spawn("Sorcerer2FXSpark", pos, ALLOW_REPLACE);
mo.Vel.X = Random2[BlueSpark]() / 128.;
mo.Vel.Y = Random2[BlueSpark]() / 128.;
mo.Vel.Z = 1. + Random[BlueSpark]() / 256.;
if (mo != null)
{
mo.Vel.X = Random2[BlueSpark]() / 128.;
mo.Vel.Y = Random2[BlueSpark]() / 128.;
mo.Vel.Z = 1. + Random[BlueSpark]() / 256.;
}
}
}
}

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);
chunk.vel.x = random2[ImpExplode]() / 64.;
chunk.vel.y = random2[ImpExplode]() / 64.;
chunk.vel.z = 9;
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);
chunk.vel.x = random2[ImpExplode]() / 64.;
chunk.vel.y = random2[ImpExplode]() / 64.;
chunk.vel.z = 9;
if (chunk != null)
{
chunk.vel.x = random2[ImpExplode]() / 64.;
chunk.vel.y = random2[ImpExplode]() / 64.;
chunk.vel.z = 9;
}
if (extremecrash)
{

View file

@ -60,10 +60,13 @@ class Pod : Actor
for (int count = chance > 240 ? 2 : 1; count; count--)
{
Actor goo = Spawn(gootype, pos + (0, 0, 48), ALLOW_REPLACE);
goo.target = self;
goo.Vel.X = Random2[PodPain]() / 128.;
goo.Vel.Y = Random2[PodPain]() / 128.;
goo.Vel.Z = 0.5 + random[PodPain]() / 128.;
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,12 +298,15 @@ class Volcano : Actor
for (int i = 0; i < count; i++)
{
Actor blast = Spawn("VolcanoBlast", pos + (0, 0, 44), ALLOW_REPLACE);
blast.target = self;
blast.Angle = random[VolcanoBlast]() * (360 / 256.);
blast.VelFromAngle(1.);
blast.Vel.Z = 2.5 + random[VolcanoBlast]() / 64.;
blast.A_PlaySound ("world/volcano/shoot", CHAN_BODY);
blast.CheckMissileSpawn (radius);
if (blast != null)
{
blast.target = self;
blast.Angle = random[VolcanoBlast]() * (360 / 256.);
blast.VelFromAngle(1.);
blast.Vel.Z = 2.5 + random[VolcanoBlast]() / 64.;
blast.A_PlaySound ("world/volcano/shoot", CHAN_BODY);
blast.CheckMissileSpawn (radius);
}
}
}
}

View file

@ -102,12 +102,15 @@ class Ironlich : Actor
{
A_PlaySound ("ironlich/attack1", CHAN_BODY);
}
fire.target = baseFire.target;
fire.angle = baseFire.angle;
fire.Vel = baseFire.Vel;
fire.SetDamage(0);
fire.health = (i+1) * 2;
fire.CheckMissileSpawn (radius);
if (fire != null)
{
fire.target = baseFire.target;
fire.angle = baseFire.angle;
fire.Vel = baseFire.Vel;
fire.SetDamage(0);
fire.health = (i+1) * 2;
fire.CheckMissileSpawn (radius);
}
}
}
}
@ -167,11 +170,14 @@ class HeadFX1 : Actor
for (int i = 0; i < 8; i++)
{
Actor shard = Spawn("HeadFX2", Pos, ALLOW_REPLACE);
shard.target = target;
shard.angle = i*45.;
shard.VelFromAngle();
shard.Vel.Z = -.6;
shard.CheckMissileSpawn (radius);
if (shard != null)
{
shard.target = target;
shard.angle = i*45.;
shard.VelFromAngle();
shard.Vel.Z = -.6;
shard.CheckMissileSpawn (radius);
}
}
}
}

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);
mo.Vel.X = random2[DripBlood]() / 64.0;
mo.Vel.Y = random2[DripBlood]() / 64.0;
mo.Gravity = 1./8;
if (mo != null)
{
mo.Vel.X = random2[DripBlood]() / 64.0;
mo.Vel.Y = random2[DripBlood]() / 64.0;
mo.Gravity = 1./8;
}
}
}

View file

@ -160,10 +160,13 @@ class BlasterFX1 : FastProjectile
for(int i = 0; i < 8; i++)
{
Actor ripper = Spawn("Ripper", pos, ALLOW_REPLACE);
ripper.target = target;
ripper.angle = i*45;
ripper.VelFromAngle();
ripper.CheckMissileSpawn (radius);
if (ripper != null)
{
ripper.target = target;
ripper.angle = i*45;
ripper.VelFromAngle();
ripper.CheckMissileSpawn (radius);
}
}
}
}

View file

@ -60,14 +60,17 @@ class Mace : HereticWeapon
if (random[MaceAtk]() < 28)
{
Actor ball = Spawn("MaceFX2", Pos + (0, 0, 28 - Floorclip), ALLOW_REPLACE);
ball.Vel.Z = 2 - clamp(tan(pitch), -5, 5);
ball.target = self;
ball.angle = self.angle;
ball.AddZ(ball.Vel.Z);
ball.VelFromAngle();
ball.Vel += Vel.xy / 2;
ball.A_PlaySound ("weapons/maceshoot", CHAN_BODY);
ball.CheckMissileSpawn (radius);
if (ball != null)
{
ball.Vel.Z = 2 - clamp(tan(pitch), -5, 5);
ball.target = self;
ball.angle = self.angle;
ball.AddZ(ball.Vel.Z);
ball.VelFromAngle();
ball.Vel += Vel.xy / 2;
ball.A_PlaySound ("weapons/maceshoot", CHAN_BODY);
ball.CheckMissileSpawn (radius);
}
}
else
{
@ -260,18 +263,24 @@ class MaceFX2 : MaceFX1
SetState (SpawnState);
Actor tiny = Spawn("MaceFX3", Pos, ALLOW_REPLACE);
tiny.target = target;
tiny.angle = angle + 90.;
tiny.VelFromAngle(Vel.Z - 1.);
tiny.Vel += (Vel.XY * .5, Vel.Z);
tiny.CheckMissileSpawn (radius);
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);
tiny.target = target;
tiny.angle = angle - 90.;
tiny.VelFromAngle(Vel.Z - 1.);
tiny.Vel += (Vel.XY * .5, Vel.Z);
tiny.CheckMissileSpawn (radius);
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);
mo.target = self;
mo.Angle = Angle;
mo.VelFromAngle();
mo.Vel.XY += Vel.XY;
mo.Vel.Z = mo.Speed * slope;
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,10 +242,16 @@ class PhoenixFX1 : Actor
//[RH] Heretic never sets the target for seeking
//P_SeekerMissile (self, 5, 10);
Actor puff = Spawn("PhoenixPuff", Pos, ALLOW_REPLACE);
puff.Vel.XY = AngleToVector(Angle + 90, 1.3);
if (puff != null)
{
puff.Vel.XY = AngleToVector(Angle + 90, 1.3);
}
puff = Spawn("PhoenixPuff", Pos, ALLOW_REPLACE);
puff.Vel.XY = AngleToVector(Angle - 90, 1.3);
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,14 +567,17 @@ class HolyTail : Actor
static void SpawnSpiritTail (Actor spirit)
{
Actor tail = Spawn ("HolyTail", spirit.Pos, ALLOW_REPLACE);
tail.target = spirit; // parent
for (int i = 1; i < 3; i++)
if (tail != null)
{
Actor next = Spawn ("HolyTailTrail", spirit.Pos, ALLOW_REPLACE);
tail.tracer = next;
tail = next;
tail.target = spirit; // parent
for (int i = 1; i < 3; i++)
{
Actor next = Spawn ("HolyTailTrail", spirit.Pos, ALLOW_REPLACE);
tail.tracer = next;
tail = next;
}
tail.tracer = null; // last tail bit
}
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));
copy.Amount = Amount;
copy.MaxAmount = MaxAmount;
GoAwayAndDie ();
let copy = Inventory(Spawn (spawntype));
if (copy != null)
{
copy.Amount = Amount;
copy.MaxAmount = MaxAmount;
GoAwayAndDie ();
}
return copy;
}
}

View file

@ -315,17 +315,20 @@ class Korax : Actor
private void SpawnKoraxMissile (Vector3 pos, Actor dest, Class<Actor> type)
{
Actor th = Spawn (type, pos, ALLOW_REPLACE);
th.target = self; // Originator
double an = th.AngleTo(dest);
if (dest.bShadow)
{ // Invisible target
an += Random2[KoraxMissile]() * (45/256.);
if (th != null)
{
th.target = self; // Originator
double an = th.AngleTo(dest);
if (dest.bShadow)
{ // Invisible target
an += Random2[KoraxMissile]() * (45/256.);
}
th.angle = an;
th.VelFromAngle();
double dist = dest.DistanceBySpeed(th, th.Speed);
th.Vel.Z = (dest.pos.z - pos.Z + 30) / dist;
th.CheckMissileSpawn(radius);
}
th.angle = an;
th.VelFromAngle();
double dist = dest.DistanceBySpeed(th, th.Speed);
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,9 +710,12 @@ class MinotaurFX2 : MinotaurFX1
double y = Random2[MntrFloorFire]() / 64.;
Actor mo = Spawn("MinotaurFX3", Vec2OffsetZ(x, y, floorz), ALLOW_REPLACE);
mo.target = target;
mo.Vel.X = MinVel; // Force block checking
mo.CheckMissileSpawn (radius);
if (mo != null)
{
mo.target = target;
mo.Vel.X = MinVel; // Force block checking
mo.CheckMissileSpawn (radius);
}
}
}

View file

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

View file

@ -171,9 +171,12 @@ class Inquisitor : Actor
void A_TossArm ()
{
Actor foo = Spawn("InquisitorArm", Pos + (0,0,24), ALLOW_REPLACE);
foo.angle = angle - 90. + Random2[Inquisitor]() * (360./1024.);
foo.VelFromAngle(foo.Speed / 8);
foo.Vel.Z = random[Inquisitor]() / 64.;
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);
foo.Vel.Z = -12;
foo.target = self;
foo.FriendPlayer = 0;
foo.tracer = target;
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,9 +219,11 @@ class SpectralLightningH1 : SpectralLightningBase
void A_SpectralLightningTail ()
{
Actor foo = Spawn("SpectralLightningHTail", Vec3Offset(-Vel.X, -Vel.Y, 0.), ALLOW_REPLACE);
foo.Angle = Angle;
foo.FriendPlayer = FriendPlayer;
if (foo != null)
{
foo.Angle = Angle;
foo.FriendPlayer = FriendPlayer;
}
}
}
@ -386,15 +390,21 @@ class SpectralLightningSpot : SpectralLightningDeath1
Actor flash = Spawn (cls, Vec2OffsetZ(xo, yo, ONCEILINGZ), ALLOW_REPLACE);
flash.target = target;
flash.Vel.Z = -18;
flash.FriendPlayer = FriendPlayer;
if (flash != null)
{
flash.target = target;
flash.Vel.Z = -18;
flash.FriendPlayer = FriendPlayer;
}
flash = Spawn("SpectralLightningV2", (pos.xy, ONCEILINGZ), ALLOW_REPLACE);
flash.target = target;
flash.Vel.Z = -18;
flash.FriendPlayer = FriendPlayer;
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);
drop.Vel.Z = -1.;
if (drop != null)
{
drop.Vel.Z = -1.;
}
A_Explode(64, 64, XF_NOSPLASH, damagetype: 'Fire');
}