Tidy transformation trait/activity.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* Copyright 2007-2014 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,
|
||||
@@ -16,21 +16,22 @@ namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
class Transform : Activity
|
||||
{
|
||||
public readonly string ToActor = null;
|
||||
public CVec Offset = new CVec(0, 0);
|
||||
public readonly string ToActor;
|
||||
public CVec Offset = CVec.Zero;
|
||||
public int Facing = 96;
|
||||
public string[] Sounds = {};
|
||||
public string[] Sounds = { };
|
||||
public int ForceHealthPercentage = 0;
|
||||
public bool SkipMakeAnims = false;
|
||||
|
||||
public Transform(Actor self, string toActor)
|
||||
{
|
||||
this.ToActor = toActor;
|
||||
ToActor = toActor;
|
||||
}
|
||||
|
||||
public override Activity Tick( Actor self )
|
||||
public override Activity Tick(Actor self)
|
||||
{
|
||||
if (IsCanceled) return NextActivity;
|
||||
if (IsCanceled)
|
||||
return NextActivity;
|
||||
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
@@ -48,12 +49,13 @@ namespace OpenRA.Mods.RA.Activities
|
||||
|
||||
var init = new TypeDictionary
|
||||
{
|
||||
new LocationInit( self.Location + Offset ),
|
||||
new OwnerInit( self.Owner ),
|
||||
new FacingInit( Facing ),
|
||||
new LocationInit(self.Location + Offset),
|
||||
new OwnerInit(self.Owner),
|
||||
new FacingInit(Facing),
|
||||
};
|
||||
|
||||
if (SkipMakeAnims) init.Add(new SkipMakeAnimsInit());
|
||||
if (SkipMakeAnims)
|
||||
init.Add(new SkipMakeAnimsInit());
|
||||
|
||||
var health = self.TraitOrDefault<Health>();
|
||||
if (health != null)
|
||||
@@ -62,15 +64,14 @@ namespace OpenRA.Mods.RA.Activities
|
||||
? ForceHealthPercentage / 100f
|
||||
: (float)health.HP / health.MaxHP;
|
||||
|
||||
init.Add( new HealthInit(newHP) );
|
||||
init.Add(new HealthInit(newHP));
|
||||
}
|
||||
|
||||
var cargo = self.TraitOrDefault<Cargo>();
|
||||
if (cargo != null)
|
||||
init.Add( new RuntimeCargoInit( cargo.Passengers.ToArray() ) );
|
||||
|
||||
var a = w.CreateActor( ToActor, init );
|
||||
init.Add(new RuntimeCargoInit(cargo.Passengers.ToArray()));
|
||||
|
||||
var a = w.CreateActor(ToActor, init);
|
||||
foreach (var nt in self.TraitsImplementing<INotifyTransformed>())
|
||||
nt.OnTransformed(a);
|
||||
|
||||
|
||||
@@ -22,22 +22,22 @@ namespace OpenRA.Mods.RA
|
||||
[ActorReference] public readonly string IntoActor = null;
|
||||
public readonly int2 Offset = int2.Zero;
|
||||
public readonly int Facing = 96;
|
||||
public readonly string[] TransformSounds = {};
|
||||
public readonly string[] NoTransformSounds = {};
|
||||
public readonly string[] TransformSounds = { };
|
||||
public readonly string[] NoTransformSounds = { };
|
||||
|
||||
public virtual object Create(ActorInitializer init) { return new Transforms(init.self, this); }
|
||||
}
|
||||
|
||||
class Transforms : IIssueOrder, IResolveOrder, IOrderVoice
|
||||
{
|
||||
Actor self;
|
||||
TransformsInfo Info;
|
||||
BuildingInfo bi;
|
||||
readonly Actor self;
|
||||
readonly TransformsInfo info;
|
||||
readonly BuildingInfo bi;
|
||||
|
||||
public Transforms(Actor self, TransformsInfo info)
|
||||
{
|
||||
this.self = self;
|
||||
Info = info;
|
||||
this.info = info;
|
||||
bi = self.World.Map.Rules.Actors[info.IntoActor].Traits.GetOrDefault<BuildingInfo>();
|
||||
}
|
||||
|
||||
@@ -52,18 +52,18 @@ namespace OpenRA.Mods.RA
|
||||
if (b != null && b.Locked)
|
||||
return false;
|
||||
|
||||
return (bi == null || self.World.CanPlaceBuilding(Info.IntoActor, bi, self.Location + (CVec)Info.Offset, self));
|
||||
return bi == null || self.World.CanPlaceBuilding(info.IntoActor, bi, self.Location + (CVec)info.Offset, self);
|
||||
}
|
||||
|
||||
public IEnumerable<IOrderTargeter> Orders
|
||||
{
|
||||
get { yield return new DeployOrderTargeter( "DeployTransform", 5, () => CanDeploy() ); }
|
||||
get { yield return new DeployOrderTargeter("DeployTransform", 5, () => CanDeploy()); }
|
||||
}
|
||||
|
||||
public Order IssueOrder( Actor self, IOrderTargeter order, Target target, bool queued )
|
||||
public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
|
||||
{
|
||||
if( order.OrderID == "DeployTransform" )
|
||||
return new Order( order.OrderID, self, queued );
|
||||
if (order.OrderID == "DeployTransform")
|
||||
return new Order(order.OrderID, self, queued);
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -74,8 +74,9 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
if (!CanDeploy() || (b != null && !b.Lock()))
|
||||
{
|
||||
foreach (var s in Info.NoTransformSounds)
|
||||
foreach (var s in info.NoTransformSounds)
|
||||
Sound.PlayToPlayer(self.Owner, s);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -83,16 +84,16 @@ namespace OpenRA.Mods.RA
|
||||
self.CancelActivity();
|
||||
|
||||
if (self.HasTrait<IFacing>())
|
||||
self.QueueActivity(new Turn(Info.Facing));
|
||||
self.QueueActivity(new Turn(info.Facing));
|
||||
|
||||
var rb = self.TraitOrDefault<RenderBuilding>();
|
||||
if (rb != null && self.Info.Traits.Get<RenderBuildingInfo>().HasMakeAnimation)
|
||||
self.QueueActivity(new MakeAnimation(self, true, () => rb.PlayCustomAnim(self, "make")));
|
||||
|
||||
self.QueueActivity(new Transform(self, Info.IntoActor) { Offset = (CVec)Info.Offset, Facing = Info.Facing, Sounds = Info.TransformSounds });
|
||||
self.QueueActivity(new Transform(self, info.IntoActor) { Offset = (CVec)info.Offset, Facing = info.Facing, Sounds = info.TransformSounds });
|
||||
}
|
||||
|
||||
public void ResolveOrder( Actor self, Order order )
|
||||
public void ResolveOrder(Actor self, Order order)
|
||||
{
|
||||
if (order.OrderString == "DeployTransform")
|
||||
DeployTransform(order.Queued);
|
||||
|
||||
Reference in New Issue
Block a user