Fix EjectOnDeath pilot spawning.

This commit is contained in:
Paul Chote
2019-10-27 21:47:42 +00:00
committed by abcdefg30
parent 3ee697a54d
commit 230a0b330c

View File

@@ -50,9 +50,7 @@ namespace OpenRA.Mods.Common.Traits
if (IsTraitDisabled || self.Owner.WinState == WinState.Lost || !self.World.Map.Contains(self.Location)) if (IsTraitDisabled || self.Owner.WinState == WinState.Lost || !self.World.Map.Contains(self.Location))
return; return;
var r = self.World.SharedRandom.Next(1, 100); if (self.World.SharedRandom.Next(100) >= Info.SuccessRate)
if (r <= 100 - Info.SuccessRate)
return; return;
var cp = self.CenterPosition; var cp = self.CenterPosition;
@@ -60,48 +58,47 @@ namespace OpenRA.Mods.Common.Traits
if ((inAir && !Info.EjectInAir) || (!inAir && !Info.EjectOnGround)) if ((inAir && !Info.EjectInAir) || (!inAir && !Info.EjectOnGround))
return; return;
var pilot = self.World.CreateActor(false, Info.PilotActor.ToLowerInvariant(), if (!Info.AllowUnsuitableCell)
new TypeDictionary { new OwnerInit(self.Owner), new LocationInit(self.Location) });
var pilotPositionable = pilot.TraitOrDefault<IPositionable>();
var pilotCell = self.Location;
var pilotSubCell = pilotPositionable.GetAvailableSubCell(pilotCell);
if (pilotSubCell == SubCell.Invalid)
{ {
if (!Info.AllowUnsuitableCell) var pilotInfo = self.World.Map.Rules.Actors[Info.PilotActor.ToLowerInvariant()];
{ var pilotPositionable = pilotInfo.TraitInfo<IPositionableInfo>();
pilot.Dispose(); if (!pilotPositionable.CanEnterCell(self.World, null, self.Location))
return; return;
}
pilotSubCell = SubCell.Any;
} }
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) if (inAir)
{ {
self.World.AddFrameEndTask(w => var subCell = self.World.ActorMap.FreeSubCell(self.Location);
if (subCell != SubCell.Invalid)
{ {
pilotPositionable.SetPosition(pilot, pilotCell, pilotSubCell); td.Add(new SubCellInit(subCell));
var dropPosition = pilot.CenterPosition + new WVec(0, 0, self.CenterPosition.Z - pilot.CenterPosition.Z); spawnPos = self.World.Map.CenterOfSubCell(self.Location, subCell) + new WVec(0, 0, spawnPos.Z);
pilotPositionable.SetVisualPosition(pilot, dropPosition); }
w.Add(pilot);
});
Game.Sound.Play(SoundType.World, Info.ChuteSound, cp);
} }
else
td.Add(new CenterPositionInit(spawnPos));
var pilot = self.World.CreateActor(true, Info.PilotActor.ToLowerInvariant(), td);
if (!inAir)
{ {
self.World.AddFrameEndTask(w => self.World.AddFrameEndTask(w =>
{ {
w.Add(pilot);
pilotPositionable.SetPosition(pilot, pilotCell, pilotSubCell);
var pilotMobile = pilot.TraitOrDefault<Mobile>(); var pilotMobile = pilot.TraitOrDefault<Mobile>();
if (pilotMobile != null) if (pilotMobile != null)
pilotMobile.Nudge(pilot); pilotMobile.Nudge(pilot);
}); });
} }
else
Game.Sound.Play(SoundType.World, Info.ChuteSound, cp);
} }
} }
} }