Files
OpenRA/OpenRA.Mods.Cnc/Traits/Buildings/ProductionAirdrop.cs
Taryn Hill 4ed53c5952 Simplify return statements.
Remove redundant ‘this’.
Remove unused using directives.
Simplify LINQ chains.
Add some trait property descriptions.
Add readonly where viable.
Add fullstops to some yaml descriptions.
2015-04-01 12:33:17 -05:00

88 lines
2.8 KiB
C#

#region Copyright & License Information
/*
* Copyright 2007-2015 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System.Linq;
using OpenRA.Activities;
using OpenRA.Mods.Common.Activities;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Cnc.Traits
{
[Desc("Deliver the unit in production via skylift.")]
public class ProductionAirdropInfo : ProductionInfo
{
public readonly string ReadyAudio = "Reinforce";
[Desc("Cargo aircraft used.")]
[ActorReference] public readonly string ActorType = "c17";
public override object Create(ActorInitializer init) { return new ProductionAirdrop(init, this); }
}
class ProductionAirdrop : Production
{
public ProductionAirdrop(ActorInitializer init, ProductionAirdropInfo info)
: base(init, info) { }
public override bool Produce(Actor self, ActorInfo producee, string raceVariant)
{
var owner = self.Owner;
// Start a fixed distance away: the width of the map.
// This makes the production timing independent of spawnpoint
var startPos = self.Location + new CVec(owner.World.Map.Bounds.Width, 0);
var endPos = new CPos(owner.World.Map.Bounds.Left - 5, self.Location.Y);
// Assume a single exit point for simplicity
var exit = self.Info.Traits.WithInterface<ExitInfo>().First();
foreach (var tower in self.TraitsImplementing<INotifyDelivery>())
tower.IncomingDelivery(self);
var info = (ProductionAirdropInfo)Info;
var actorType = info.ActorType;
owner.World.AddFrameEndTask(w =>
{
if (!self.IsInWorld || self.IsDead)
return;
var altitude = self.World.Map.Rules.Actors[actorType].Traits.Get<PlaneInfo>().CruiseAltitude;
var actor = w.CreateActor(actorType, new TypeDictionary
{
new CenterPositionInit(w.Map.CenterOfCell(startPos) + new WVec(WRange.Zero, WRange.Zero, altitude)),
new OwnerInit(owner),
new FacingInit(64)
});
actor.QueueActivity(new Fly(actor, Target.FromCell(w, self.Location + new CVec(9, 0))));
actor.QueueActivity(new Land(actor, Target.FromActor(self)));
actor.QueueActivity(new CallFunc(() =>
{
if (!self.IsInWorld || self.IsDead)
return;
foreach (var cargo in self.TraitsImplementing<INotifyDelivery>())
cargo.Delivered(self);
self.World.AddFrameEndTask(ww => DoProduction(self, producee, exit, raceVariant));
Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", info.ReadyAudio, self.Owner.Country.Race);
}));
actor.QueueActivity(new Fly(actor, Target.FromCell(w, endPos)));
actor.QueueActivity(new RemoveSelf());
});
return true;
}
}
}