Cache unitTypes
And rename variables to names that more sense
This commit is contained in:
committed by
Matthias Mailänder
parent
4eb683ab46
commit
9845306b68
@@ -79,43 +79,44 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
public class DropPodsPower : SupportPower
|
||||
{
|
||||
readonly DropPodsPowerInfo info;
|
||||
readonly string[] unitTypes;
|
||||
|
||||
public DropPodsPower(Actor self, DropPodsPowerInfo info)
|
||||
: base(self, info)
|
||||
{
|
||||
this.info = info;
|
||||
|
||||
unitTypes = info.UnitTypes.Select(unit => unit.ToLowerInvariant()).ToArray();
|
||||
}
|
||||
|
||||
public override void Activate(Actor self, Order order, SupportPowerManager manager)
|
||||
{
|
||||
base.Activate(self, order, manager);
|
||||
|
||||
SendDropPods(self, order, info.PodFacing);
|
||||
SendDropPods(self, self.World.Map.CellContaining(order.Target.CenterPosition), info.PodFacing);
|
||||
}
|
||||
|
||||
public void SendDropPods(Actor self, Order order, WAngle facing)
|
||||
public void SendDropPods(Actor self, CPos targetCell, WAngle facing)
|
||||
{
|
||||
var actorInfo = self.World.Map.Rules.Actors[info.UnitTypes.First().ToLowerInvariant()];
|
||||
var actorInfo = self.World.Map.Rules.Actors[unitTypes.First()];
|
||||
var aircraftInfo = actorInfo.TraitInfo<AircraftInfo>();
|
||||
var altitude = aircraftInfo.CruiseAltitude.Length;
|
||||
var approachRotation = WRot.FromYaw(facing);
|
||||
var fallsToEarthInfo = actorInfo.TraitInfo<FallsToEarthInfo>();
|
||||
var delta = new WVec(0, -altitude * aircraftInfo.Speed / fallsToEarthInfo.Velocity.Length, 0).Rotate(approachRotation);
|
||||
|
||||
self.World.AddFrameEndTask(w =>
|
||||
self.World.AddFrameEndTask(world =>
|
||||
{
|
||||
var target = order.Target.CenterPosition;
|
||||
var targetCell = self.World.Map.CellContaining(target);
|
||||
var podLocations = self.World.Map.FindTilesInCircle(targetCell, info.PodScatter)
|
||||
.Where(c => aircraftInfo.LandableTerrainTypes.Contains(w.Map.GetTerrainInfo(c).Type)
|
||||
var dropLocations = self.World.Map.FindTilesInCircle(targetCell, info.PodScatter)
|
||||
.Where(c => aircraftInfo.LandableTerrainTypes.Contains(world.Map.GetTerrainInfo(c).Type)
|
||||
&& !self.World.ActorMap.GetActorsAt(c).Any());
|
||||
|
||||
if (!podLocations.Any())
|
||||
if (!dropLocations.Any())
|
||||
return;
|
||||
|
||||
if (info.CameraActor != null)
|
||||
{
|
||||
var camera = w.CreateActor(info.CameraActor, new TypeDictionary
|
||||
var camera = world.CreateActor(info.CameraActor, new TypeDictionary
|
||||
{
|
||||
new LocationInit(targetCell),
|
||||
new OwnerInit(self.Owner),
|
||||
@@ -131,25 +132,25 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
for (var i = 0; i < drops; i++)
|
||||
{
|
||||
var unitType = info.UnitTypes.Random(self.World.SharedRandom);
|
||||
var podLocation = podLocations.Random(self.World.SharedRandom);
|
||||
var podTarget = Target.FromCell(w, podLocation);
|
||||
var location = self.World.Map.CenterOfCell(podLocation) - delta + new WVec(0, 0, altitude);
|
||||
var dropLocation = dropLocations.Random(self.World.SharedRandom);
|
||||
var podTarget = Target.FromCell(world, dropLocation);
|
||||
var launchLocation = self.World.Map.CenterOfCell(dropLocation) - delta + new WVec(0, 0, altitude);
|
||||
|
||||
var pod = w.CreateActor(false, unitType, new TypeDictionary
|
||||
var pod = world.CreateActor(false, unitType, new TypeDictionary
|
||||
{
|
||||
new CenterPositionInit(location),
|
||||
new CenterPositionInit(launchLocation),
|
||||
new OwnerInit(self.Owner),
|
||||
new FacingInit(facing)
|
||||
});
|
||||
|
||||
var aircraft = pod.Trait<Aircraft>();
|
||||
if (!aircraft.CanLand(podLocation))
|
||||
if (!aircraft.CanLand(dropLocation))
|
||||
pod.Dispose();
|
||||
else
|
||||
{
|
||||
w.Add(new DropPodImpact(self.Owner, info.WeaponInfo, w, location, podTarget, info.WeaponDelay,
|
||||
world.Add(new DropPodImpact(self.Owner, info.WeaponInfo, world, launchLocation, podTarget, info.WeaponDelay,
|
||||
info.EntryEffect, info.EntryEffectSequence, info.EntryEffectPalette));
|
||||
w.Add(pod);
|
||||
world.Add(pod);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user