From 6b1e81a7b52e2e55b153ec13323a4e9c3c5fa248 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 16 Nov 2019 20:08:57 +0000 Subject: [PATCH] Spawn ejected pilots inside a FrameEndTask. --- OpenRA.Mods.Common/Traits/EjectOnDeath.cs | 62 +++++++++++------------ 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/EjectOnDeath.cs b/OpenRA.Mods.Common/Traits/EjectOnDeath.cs index 648eab6524..9ab03da495 100644 --- a/OpenRA.Mods.Common/Traits/EjectOnDeath.cs +++ b/OpenRA.Mods.Common/Traits/EjectOnDeath.cs @@ -58,47 +58,47 @@ namespace OpenRA.Mods.Common.Traits 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(); - if (!pilotPositionable.CanEnterCell(self.World, null, self.Location)) - return; - } - - 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 (!Info.AllowUnsuitableCell) { - td.Add(new SubCellInit(subCell)); - spawnPos = self.World.Map.CenterOfSubCell(self.Location, subCell) + new WVec(0, 0, spawnPos.Z); + var pilotInfo = self.World.Map.Rules.Actors[Info.PilotActor.ToLowerInvariant()]; + var pilotPositionable = pilotInfo.TraitInfo(); + if (!pilotPositionable.CanEnterCell(self.World, null, self.Location)) + return; } - } - td.Add(new CenterPositionInit(spawnPos)); + var td = new TypeDictionary + { + new OwnerInit(self.Owner), + new LocationInit(self.Location), + }; - var pilot = self.World.CreateActor(true, Info.PilotActor.ToLowerInvariant(), td); + // 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) + { + td.Add(new SubCellInit(subCell)); + spawnPos = self.World.Map.CenterOfSubCell(self.Location, subCell) + new WVec(0, 0, spawnPos.Z); + } + } - if (!inAir) - { - self.World.AddFrameEndTask(w => + td.Add(new CenterPositionInit(spawnPos)); + + var pilot = self.World.CreateActor(true, Info.PilotActor.ToLowerInvariant(), td); + + if (!inAir) { var pilotMobile = pilot.TraitOrDefault(); if (pilotMobile != null) pilotMobile.Nudge(pilot); - }); - } - else - Game.Sound.Play(SoundType.World, Info.ChuteSound, cp); + } + else + Game.Sound.Play(SoundType.World, Info.ChuteSound, cp); + }); } } }