Fix EjectOnDeath pilot spawning.
This commit is contained in:
@@ -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(),
|
|
||||||
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)
|
if (!Info.AllowUnsuitableCell)
|
||||||
{
|
{
|
||||||
pilot.Dispose();
|
var pilotInfo = self.World.Map.Rules.Actors[Info.PilotActor.ToLowerInvariant()];
|
||||||
|
var pilotPositionable = pilotInfo.TraitInfo<IPositionableInfo>();
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user