Rework paradrop logic to be more robust.

This commit is contained in:
Paul Chote
2019-05-26 22:19:46 +00:00
committed by reaperrr
parent 829b8cd2e1
commit e2b27328bd
5 changed files with 94 additions and 91 deletions

View File

@@ -63,32 +63,46 @@ namespace OpenRA.Mods.Common.Traits
var pilot = self.World.CreateActor(false, Info.PilotActor.ToLowerInvariant(),
new TypeDictionary { new OwnerInit(self.Owner), new LocationInit(self.Location) });
if (Info.AllowUnsuitableCell || IsSuitableCell(self, pilot))
var pilotPositionable = pilot.TraitOrDefault<IPositionable>();
var pilotCell = self.Location;
var pilotSubCell = pilotPositionable.GetAvailableSubCell(pilotCell);
if (pilotSubCell == SubCell.Invalid)
{
if (inAir)
if (!Info.AllowUnsuitableCell)
{
self.World.AddFrameEndTask(w =>
{
w.Add(pilot);
pilot.QueueActivity(new Parachute(pilot, cp));
});
Game.Sound.Play(SoundType.World, Info.ChuteSound, cp);
pilot.Dispose();
return;
}
else
pilotSubCell = SubCell.Any;
}
if (inAir)
{
self.World.AddFrameEndTask(w =>
{
self.World.AddFrameEndTask(w => w.Add(pilot));
pilotPositionable.SetPosition(pilot, pilotCell, pilotSubCell);
w.Add(pilot);
var dropPosition = pilot.CenterPosition + new WVec(0, 0, self.CenterPosition.Z - pilot.CenterPosition.Z);
pilotPositionable.SetVisualPosition(pilot, dropPosition);
pilot.QueueActivity(new Parachute(pilot));
});
Game.Sound.Play(SoundType.World, Info.ChuteSound, cp);
}
else
{
self.World.AddFrameEndTask(w =>
{
w.Add(pilot);
pilotPositionable.SetPosition(pilot, pilotCell, pilotSubCell);
var pilotMobile = pilot.TraitOrDefault<Mobile>();
if (pilotMobile != null)
pilotMobile.Nudge(pilot, pilot, true);
}
});
}
else
pilot.Dispose();
}
static bool IsSuitableCell(Actor self, Actor actorToDrop)
{
return actorToDrop.Trait<IPositionable>().CanEnterCell(self.Location, self, true);
}
}
}