Introduce ActivateParatroopers Lua API.

SendParatroopers and SendParatroopersFrom are now deprecated.
The paratrooper actors themselves can be accessed using the
Trigger.OnPassengerExited trigger.
This commit is contained in:
Paul Chote
2019-08-21 08:59:19 +00:00
committed by Matthias Mailänder
parent ed415cb637
commit c0587cc568
2 changed files with 48 additions and 23 deletions

View File

@@ -93,17 +93,19 @@ namespace OpenRA.Mods.Common.Traits
{
base.Activate(self, order, manager);
SendParatroopers(self, order.Target.CenterPosition, !info.UseDirectionalTarget || order.ExtraData == uint.MaxValue, (int)order.ExtraData);
var facing = info.UseDirectionalTarget && order.ExtraData != uint.MaxValue ? (int)order.ExtraData : -1;
SendParatroopers(self, order.Target.CenterPosition, facing);
}
public Actor[] SendParatroopers(Actor self, WPos target, bool randomize = true, int dropFacing = 0)
public Pair<Actor[], Actor[]> SendParatroopers(Actor self, WPos target, int facing = -1)
{
var aircraft = new List<Actor>();
var units = new List<Actor>();
var info = Info as ParatroopersPowerInfo;
if (randomize)
dropFacing = 256 * self.World.SharedRandom.Next(info.QuantizedFacings) / info.QuantizedFacings;
if (facing < 0)
facing = 256 * self.World.SharedRandom.Next(info.QuantizedFacings) / info.QuantizedFacings;
var utLower = info.UnitType.ToLowerInvariant();
ActorInfo unitType;
@@ -111,7 +113,7 @@ namespace OpenRA.Mods.Common.Traits
throw new YamlException("Actors ruleset does not include the entry '{0}'".F(utLower));
var altitude = unitType.TraitInfo<AircraftInfo>().CruiseAltitude.Length;
var dropRotation = WRot.FromFacing(dropFacing);
var dropRotation = WRot.FromFacing(facing);
var delta = new WVec(0, -1024, 0).Rotate(dropRotation);
target = target + new WVec(0, 0, altitude);
var startEdge = target - (self.World.Map.DistanceToEdge(target, -delta) + info.Cordon).Length * delta / 1024;
@@ -168,15 +170,31 @@ namespace OpenRA.Mods.Common.Traits
}
};
// Create the units immediately so they can be returned
// Create the actors immediately so they can be returned
for (var i = -info.SquadSize / 2; i <= info.SquadSize / 2; i++)
{
// Even-sized squads skip the lead plane
if (i == 0 && (info.SquadSize & 1) == 0)
continue;
// Includes the 90 degree rotation between body and world coordinates
var so = info.SquadOffset;
var spawnOffset = new WVec(i * so.Y, -Math.Abs(i) * so.X, 0).Rotate(dropRotation);
aircraft.Add(self.World.CreateActor(false, info.UnitType, new TypeDictionary
{
new CenterPositionInit(startEdge + spawnOffset),
new OwnerInit(self.Owner),
new FacingInit(facing),
}));
}
foreach (var p in info.DropItems)
{
var unit = self.World.CreateActor(false, p.ToLowerInvariant(), new TypeDictionary
units.Add(self.World.CreateActor(false, p.ToLowerInvariant(), new TypeDictionary
{
new OwnerInit(self.Owner)
});
units.Add(unit);
}));
}
self.World.AddFrameEndTask(w =>
@@ -187,6 +205,7 @@ namespace OpenRA.Mods.Common.Traits
var passengersPerPlane = (info.DropItems.Length + info.SquadSize - 1) / info.SquadSize;
var added = 0;
var j = 0;
for (var i = -info.SquadSize / 2; i <= info.SquadSize / 2; i++)
{
// Even-sized squads skip the lead plane
@@ -197,13 +216,8 @@ namespace OpenRA.Mods.Common.Traits
var so = info.SquadOffset;
var spawnOffset = new WVec(i * so.Y, -Math.Abs(i) * so.X, 0).Rotate(dropRotation);
var targetOffset = new WVec(i * so.Y, 0, 0).Rotate(dropRotation);
var a = w.CreateActor(info.UnitType, new TypeDictionary
{
new CenterPositionInit(startEdge + spawnOffset),
new OwnerInit(self.Owner),
new FacingInit(dropFacing),
});
var a = aircraft[j++];
w.Add(a);
var drop = a.Trait<ParaDrop>();
drop.SetLZ(w.Map.CellContaining(target + targetOffset), !info.AllowImpassableCells);
@@ -252,7 +266,7 @@ namespace OpenRA.Mods.Common.Traits
}
});
return units.ToArray();
return Pair.New(aircraft.ToArray(), units.ToArray());
}
void RemoveCamera(Actor camera)