diff --git a/OpenRA.Mods.D2k/OpenRA.Mods.D2k.csproj b/OpenRA.Mods.D2k/OpenRA.Mods.D2k.csproj index 6d4e14284f..94b7de4d18 100644 --- a/OpenRA.Mods.D2k/OpenRA.Mods.D2k.csproj +++ b/OpenRA.Mods.D2k/OpenRA.Mods.D2k.csproj @@ -73,6 +73,7 @@ + diff --git a/OpenRA.Mods.D2k/Traits/Buildings/ProductionFromMapEdge.cs b/OpenRA.Mods.D2k/Traits/Buildings/ProductionFromMapEdge.cs new file mode 100644 index 0000000000..6e6cb3b00c --- /dev/null +++ b/OpenRA.Mods.D2k/Traits/Buildings/ProductionFromMapEdge.cs @@ -0,0 +1,82 @@ +#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.Drawing; +using OpenRA.Activities; +using OpenRA.Mods.Common.Traits; +using OpenRA.Primitives; +using OpenRA.Traits; + +namespace OpenRA.Mods.D2k.Traits +{ + [Desc("Produce a unit on the closest map edge cell and move into the world.")] + class ProductionFromMapEdgeInfo : ProductionInfo + { + public override object Create(ActorInitializer init) { return new ProductionFromMapEdge(init, this); } + } + + class ProductionFromMapEdge : Production + { + public ProductionFromMapEdge(ActorInitializer init, ProductionInfo info) + : base(init, info) { } + + public override bool Produce(Actor self, ActorInfo producee, string raceVariant) + { + var location = self.World.Map.ChooseClosestEdgeCell(self.Location); + var pos = self.World.Map.CenterOfCell(location); + + // If aircraft, spawn at cruise altitude + var aircraftInfo = producee.Traits.GetOrDefault(); + if (aircraftInfo != null) + pos += new WVec(0, 0, aircraftInfo.CruiseAltitude.Range); + + var initialFacing = self.World.Map.FacingBetween(location, self.Location, 0); + + self.World.AddFrameEndTask(w => + { + var td = new TypeDictionary + { + new OwnerInit(self.Owner), + new LocationInit(location), + new CenterPositionInit(pos), + new FacingInit(initialFacing) + }; + + if (raceVariant != null) + td.Add(new RaceInit(raceVariant)); + + var newUnit = self.World.CreateActor(producee.Name, td); + + var move = newUnit.TraitOrDefault(); + if (move != null) + newUnit.QueueActivity(move.MoveIntoWorld(newUnit, self.Location)); + + newUnit.SetTargetLine(Target.FromCell(self.World, self.Location), Color.Green, false); + + if (!self.IsDead) + foreach (var t in self.TraitsImplementing()) + t.UnitProduced(self, newUnit, self.Location); + + var notifyOthers = self.World.ActorsWithTrait(); + foreach (var notify in notifyOthers) + notify.Trait.UnitProducedByOther(notify.Actor, self, newUnit); + + var bi = newUnit.Info.Traits.GetOrDefault(); + if (bi != null && bi.InitialActivity != null) + newUnit.QueueActivity(Game.CreateObject(bi.InitialActivity)); + + foreach (var t in newUnit.TraitsImplementing()) + t.BuildingComplete(newUnit); + }); + + return true; + } + } +} diff --git a/mods/d2k/rules/structures.yaml b/mods/d2k/rules/structures.yaml index 496819e39e..b7ce2f1bc8 100644 --- a/mods/d2k/rules/structures.yaml +++ b/mods/d2k/rules/structures.yaml @@ -668,7 +668,7 @@ hightech: Tooltip: Name: High Tech Facility Description: Unlocks advanced technology - Production: + ProductionFromMapEdge: Produces: Aircraft Exit: SpawnOffset: 0,0,728