Merge pull request #11004 from obrakmann/pr10266_paradrop-production
Paradrop Production
This commit is contained in:
@@ -22,8 +22,8 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
public class ProductionAirdropInfo : ProductionInfo
|
||||
{
|
||||
public readonly string ReadyAudio = "Reinforce";
|
||||
[Desc("Cargo aircraft used.")]
|
||||
[ActorReference] public readonly string ActorType = "c17";
|
||||
[Desc("Cargo aircraft used for delivery. Must have the `Aircraft` trait.")]
|
||||
[ActorReference(typeof(AircraftInfo))] public readonly string ActorType = "c17";
|
||||
|
||||
public override object Create(ActorInitializer init) { return new ProductionAirdrop(init, this); }
|
||||
}
|
||||
|
||||
@@ -21,15 +21,17 @@ namespace OpenRA.Mods.Common.Activities
|
||||
readonly IPositionable pos;
|
||||
readonly ParachutableInfo para;
|
||||
readonly WVec fallVector;
|
||||
readonly Actor ignore;
|
||||
|
||||
WPos dropPosition;
|
||||
WPos currentPosition;
|
||||
bool triggered = false;
|
||||
|
||||
public Parachute(Actor self, WPos dropPosition)
|
||||
public Parachute(Actor self, WPos dropPosition, Actor ignoreActor = null)
|
||||
{
|
||||
um = self.TraitOrDefault<UpgradeManager>();
|
||||
pos = self.TraitOrDefault<IPositionable>();
|
||||
ignore = ignoreActor;
|
||||
|
||||
// Parachutable trait is a prerequisite for running this activity
|
||||
para = self.Info.TraitInfo<ParachutableInfo>();
|
||||
@@ -61,7 +63,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
um.RevokeUpgrade(self, u, this);
|
||||
|
||||
foreach (var npl in self.TraitsImplementing<INotifyParachuteLanded>())
|
||||
npl.OnLanded();
|
||||
npl.OnLanded(ignore);
|
||||
|
||||
return NextActivity;
|
||||
}
|
||||
|
||||
@@ -400,6 +400,8 @@
|
||||
<Compile Include="Traits\Power\RequiresPower.cs" />
|
||||
<Compile Include="Traits\Power\ScalePowerWithHealth.cs" />
|
||||
<Compile Include="Traits\Production.cs" />
|
||||
<Compile Include="Traits\ProductionFromMapEdge.cs" />
|
||||
<Compile Include="Traits\ProductionParadrop.cs" />
|
||||
<Compile Include="Traits\ProductionQueueFromSelection.cs" />
|
||||
<Compile Include="Traits\ProvidesRadar.cs" />
|
||||
<Compile Include="Traits\ProximityCaptor.cs" />
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
OnCrushInner(crusher);
|
||||
}
|
||||
|
||||
public void OnLanded()
|
||||
void INotifyParachuteLanded.OnLanded(Actor ignore)
|
||||
{
|
||||
// Check whether the crate landed on anything
|
||||
var landedOn = self.World.ActorMap.GetActorsAt(self.Location)
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.Common.Effects;
|
||||
using OpenRA.Traits;
|
||||
|
||||
@@ -54,7 +55,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
positionable = self.TraitOrDefault<IPositionable>();
|
||||
}
|
||||
|
||||
public void OnLanded()
|
||||
void INotifyParachuteLanded.OnLanded(Actor ignore)
|
||||
{
|
||||
if (!info.KilledOnImpassableTerrain)
|
||||
return;
|
||||
@@ -62,6 +63,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (positionable.CanEnterCell(self.Location, self))
|
||||
return;
|
||||
|
||||
if (ignore != null && self.World.ActorMap.GetActorsAt(self.Location).Any(a => a != ignore))
|
||||
return;
|
||||
|
||||
var terrain = self.World.Map.GetTerrainInfo(self.Location);
|
||||
|
||||
var sound = terrain.IsWater ? info.WaterImpactSound : info.GroundImpactSound;
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
Faction = init.Contains<FactionInit>() ? init.Get<FactionInit, string>() : init.Self.Owner.Faction.InternalName;
|
||||
}
|
||||
|
||||
public void DoProduction(Actor self, ActorInfo producee, ExitInfo exitinfo, string factionVariant)
|
||||
public virtual void DoProduction(Actor self, ActorInfo producee, ExitInfo exitinfo, string factionVariant)
|
||||
{
|
||||
var exit = CPos.Zero;
|
||||
var exitLocation = CPos.Zero;
|
||||
|
||||
@@ -11,11 +11,10 @@
|
||||
|
||||
using System.Drawing;
|
||||
using OpenRA;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.D2k.Traits
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Produce a unit on the closest map edge cell and move into the world.")]
|
||||
class ProductionFromMapEdgeInfo : ProductionInfo, UsesInit<ProductionSpawnLocationInit>
|
||||
171
OpenRA.Mods.Common/Traits/ProductionParadrop.cs
Normal file
171
OpenRA.Mods.Common/Traits/ProductionParadrop.cs
Normal file
@@ -0,0 +1,171 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2016 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, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.Activities;
|
||||
using OpenRA.Mods.Common.Activities;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Deliver the unit in production via paradrop.")]
|
||||
public class ProductionParadropInfo : ProductionInfo, Requires<ExitInfo>
|
||||
{
|
||||
[Desc("Cargo aircraft used. Must have Aircraft trait.")]
|
||||
[ActorReference(typeof(AircraftInfo))] public readonly string ActorType = "badr";
|
||||
|
||||
[Desc("Sound to play when dropping the unit.")]
|
||||
public readonly string ChuteSound = "chute1.aud";
|
||||
|
||||
[Desc("Notification to play when dropping the unit.")]
|
||||
public readonly string ReadyAudio = null;
|
||||
|
||||
public override object Create(ActorInitializer init) { return new ProductionParadrop(init, this); }
|
||||
}
|
||||
|
||||
class ProductionParadrop : Production
|
||||
{
|
||||
readonly Lazy<RallyPoint> rp;
|
||||
|
||||
public ProductionParadrop(ActorInitializer init, ProductionParadropInfo info)
|
||||
: base(init, info)
|
||||
{
|
||||
rp = Exts.Lazy(() => init.Self.IsDead ? null : init.Self.TraitOrDefault<RallyPoint>());
|
||||
}
|
||||
|
||||
public override bool Produce(Actor self, ActorInfo producee, string factionVariant)
|
||||
{
|
||||
var owner = self.Owner;
|
||||
|
||||
// Assume a single exit point for simplicity
|
||||
var exit = self.Info.TraitInfos<ExitInfo>().First();
|
||||
|
||||
// Start a fixed distance away: the width of the map.
|
||||
// This makes the production timing independent of spawnpoint
|
||||
var dropPos = self.Location + exit.ExitCell;
|
||||
var startPos = dropPos + new CVec(owner.World.Map.Bounds.Width, 0);
|
||||
var endPos = new CPos(owner.World.Map.Bounds.Left - 5, dropPos.Y);
|
||||
|
||||
foreach (var notify in self.TraitsImplementing<INotifyDelivery>())
|
||||
notify.IncomingDelivery(self);
|
||||
|
||||
var info = (ProductionParadropInfo)Info;
|
||||
var actorType = info.ActorType;
|
||||
|
||||
owner.World.AddFrameEndTask(w =>
|
||||
{
|
||||
if (!self.IsInWorld || self.IsDead)
|
||||
return;
|
||||
|
||||
var altitude = self.World.Map.Rules.Actors[actorType].TraitInfo<AircraftInfo>().CruiseAltitude;
|
||||
var actor = w.CreateActor(actorType, new TypeDictionary
|
||||
{
|
||||
new CenterPositionInit(w.Map.CenterOfCell(startPos) + new WVec(WDist.Zero, WDist.Zero, altitude)),
|
||||
new OwnerInit(owner),
|
||||
new FacingInit(64)
|
||||
});
|
||||
|
||||
actor.QueueActivity(new Fly(actor, Target.FromCell(w, dropPos)));
|
||||
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, factionVariant));
|
||||
Game.Sound.Play(info.ChuteSound, self.CenterPosition);
|
||||
Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", info.ReadyAudio, self.Owner.Faction.InternalName);
|
||||
}));
|
||||
|
||||
actor.QueueActivity(new Fly(actor, Target.FromCell(w, endPos)));
|
||||
actor.QueueActivity(new RemoveSelf());
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void DoProduction(Actor self, ActorInfo producee, ExitInfo exitinfo, string factionVariant)
|
||||
{
|
||||
var exit = CPos.Zero;
|
||||
var exitLocation = CPos.Zero;
|
||||
var target = Target.Invalid;
|
||||
|
||||
var info = (ProductionParadropInfo)Info;
|
||||
var actorType = info.ActorType;
|
||||
|
||||
var bi = producee.TraitInfoOrDefault<BuildableInfo>();
|
||||
if (bi != null && bi.ForceFaction != null)
|
||||
factionVariant = bi.ForceFaction;
|
||||
|
||||
var altitude = self.World.Map.Rules.Actors[actorType].TraitInfo<AircraftInfo>().CruiseAltitude;
|
||||
var td = new TypeDictionary
|
||||
{
|
||||
new OwnerInit(self.Owner),
|
||||
};
|
||||
|
||||
if (self.OccupiesSpace != null)
|
||||
{
|
||||
exit = self.Location + exitinfo.ExitCell;
|
||||
var spawn = self.World.Map.CenterOfCell(exit) + new WVec(WDist.Zero, WDist.Zero, altitude);
|
||||
var to = self.World.Map.CenterOfCell(exit);
|
||||
|
||||
var initialFacing = exitinfo.Facing < 0 ? (to - spawn).Yaw.Facing : exitinfo.Facing;
|
||||
|
||||
exitLocation = rp.Value != null ? rp.Value.Location : exit;
|
||||
target = Target.FromCell(self.World, exitLocation);
|
||||
|
||||
td.Add(new LocationInit(exit));
|
||||
td.Add(new CenterPositionInit(spawn));
|
||||
td.Add(new FacingInit(initialFacing));
|
||||
}
|
||||
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
if (factionVariant != null)
|
||||
td.Add(new FactionInit(factionVariant));
|
||||
|
||||
var newUnit = self.World.CreateActor(producee.Name, td);
|
||||
|
||||
newUnit.QueueActivity(new Parachute(newUnit, newUnit.CenterPosition, self));
|
||||
var move = newUnit.TraitOrDefault<IMove>();
|
||||
if (move != null)
|
||||
{
|
||||
if (exitinfo.MoveIntoWorld)
|
||||
{
|
||||
if (exitinfo.ExitDelay > 0)
|
||||
newUnit.QueueActivity(new Wait(exitinfo.ExitDelay, false));
|
||||
|
||||
newUnit.QueueActivity(move.MoveIntoWorld(newUnit, exit));
|
||||
newUnit.QueueActivity(new AttackMoveActivity(newUnit, move.MoveTo(exitLocation, 1)));
|
||||
}
|
||||
}
|
||||
|
||||
newUnit.SetTargetLine(target, rp.Value != null ? Color.Red : Color.Green, false);
|
||||
|
||||
if (!self.IsDead)
|
||||
foreach (var t in self.TraitsImplementing<INotifyProduction>())
|
||||
t.UnitProduced(self, newUnit, exit);
|
||||
|
||||
var notifyOthers = self.World.ActorsWithTrait<INotifyOtherProduction>();
|
||||
foreach (var notify in notifyOthers)
|
||||
notify.Trait.UnitProducedByOther(notify.Actor, self, newUnit);
|
||||
|
||||
foreach (var t in newUnit.TraitsImplementing<INotifyBuildComplete>())
|
||||
t.BuildingComplete(newUnit);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,7 +67,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
PlaySequence();
|
||||
}
|
||||
|
||||
void INotifyParachuteLanded.OnLanded()
|
||||
void INotifyParachuteLanded.OnLanded(Actor ignore)
|
||||
{
|
||||
PlaySequence();
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public interface INotifyAttack { void Attacking(Actor self, Target target, Armament a, Barrel barrel); }
|
||||
public interface INotifyCharging { void Charging(Actor self, Target target); }
|
||||
public interface INotifyChat { bool OnChat(string from, string message); }
|
||||
public interface INotifyParachuteLanded { void OnLanded(); }
|
||||
public interface INotifyParachuteLanded { void OnLanded(Actor ignore); }
|
||||
public interface IRenderActorPreviewInfo : ITraitInfo { IEnumerable<IActorPreview> RenderPreview(ActorPreviewInitializer init); }
|
||||
public interface ICruiseAltitudeInfo : ITraitInfo { WDist GetCruiseAltitude(); }
|
||||
|
||||
|
||||
@@ -84,7 +84,6 @@
|
||||
<Compile Include="Traits\AttackSwallow.cs" />
|
||||
<Compile Include="Traits\Carryall.cs" />
|
||||
<Compile Include="Traits\Buildings\FreeActorWithDelivery.cs" />
|
||||
<Compile Include="Traits\Buildings\ProductionFromMapEdge.cs" />
|
||||
<Compile Include="Traits\Buildings\DamagedWithoutFoundation.cs" />
|
||||
<Compile Include="Traits\Buildings\LaysTerrain.cs" />
|
||||
<Compile Include="Traits\Carryable.cs" />
|
||||
|
||||
Reference in New Issue
Block a user