Skip to content

Commit

Permalink
Spawn ejected pilots inside a FrameEndTask.
Browse files Browse the repository at this point in the history
  • Loading branch information
pchote authored and abcdefg30 committed Nov 16, 2019
1 parent 33b1e74 commit a47969b
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions OpenRA.Mods.Common/Traits/EjectOnDeath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,47 +58,47 @@ void INotifyKilled.Killed(Actor self, AttackInfo e)
if ((inAir && !Info.EjectInAir) || (!inAir && !Info.EjectOnGround))
return;

if (!Info.AllowUnsuitableCell)
self.World.AddFrameEndTask(w =>
{
var pilotInfo = self.World.Map.Rules.Actors[Info.PilotActor.ToLowerInvariant()];
var pilotPositionable = pilotInfo.TraitInfo<IPositionableInfo>();
if (!pilotPositionable.CanEnterCell(self.World, null, self.Location))
return;
}
if (!Info.AllowUnsuitableCell)
{
var pilotInfo = self.World.Map.Rules.Actors[Info.PilotActor.ToLowerInvariant()];
var pilotPositionable = pilotInfo.TraitInfo<IPositionableInfo>();
if (!pilotPositionable.CanEnterCell(self.World, null, self.Location))
return;
}
var td = new TypeDictionary
{
new OwnerInit(self.Owner),
new LocationInit(self.Location),
};
var td = new TypeDictionary
{
new OwnerInit(self.Owner),
new LocationInit(self.Location),
};
// If airborne, offset the spawn location so the pilot doesn't drop on another infantry's head
var spawnPos = cp;
if (inAir)
{
var subCell = self.World.ActorMap.FreeSubCell(self.Location);
if (subCell != SubCell.Invalid)
// If airborne, offset the spawn location so the pilot doesn't drop on another infantry's head
var spawnPos = cp;
if (inAir)
{
td.Add(new SubCellInit(subCell));
spawnPos = self.World.Map.CenterOfSubCell(self.Location, subCell) + new WVec(0, 0, spawnPos.Z);
var subCell = self.World.ActorMap.FreeSubCell(self.Location);
if (subCell != SubCell.Invalid)
{
td.Add(new SubCellInit(subCell));
spawnPos = self.World.Map.CenterOfSubCell(self.Location, subCell) + new WVec(0, 0, spawnPos.Z);
}
}
}
td.Add(new CenterPositionInit(spawnPos));
td.Add(new CenterPositionInit(spawnPos));
var pilot = self.World.CreateActor(true, Info.PilotActor.ToLowerInvariant(), td);
var pilot = self.World.CreateActor(true, Info.PilotActor.ToLowerInvariant(), td);
if (!inAir)
{
self.World.AddFrameEndTask(w =>
if (!inAir)
{
var pilotMobile = pilot.TraitOrDefault<Mobile>();
if (pilotMobile != null)
pilotMobile.Nudge(pilot, pilot, true);
});
}
else
Game.Sound.Play(SoundType.World, Info.ChuteSound, cp);
}
else
Game.Sound.Play(SoundType.World, Info.ChuteSound, cp);
});
}
}
}

0 comments on commit a47969b

Please sign in to comment.