Add facing to DeployToUpgrade

Make the actor turn to a desired facing before starting to deploy (and before granting the upgrade).
This commit is contained in:
Pavel Penev
2015-08-21 16:46:05 +03:00
parent 7d59aaa00c
commit 21f9547fed

View File

@@ -12,6 +12,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using OpenRA.Activities; using OpenRA.Activities;
using OpenRA.Mods.Common.Activities;
using OpenRA.Mods.Common.Orders; using OpenRA.Mods.Common.Orders;
using OpenRA.Traits; using OpenRA.Traits;
@@ -36,6 +37,9 @@ namespace OpenRA.Mods.Common.Traits
[SequenceReference, Desc("Animation to play for deploying/undeploying.")] [SequenceReference, Desc("Animation to play for deploying/undeploying.")]
public readonly string DeployAnimation = null; public readonly string DeployAnimation = null;
[Desc("Facing that the actor must face before deploying. Set to -1 to deploy regardless of facing.")]
public readonly int Facing = -1;
public object Create(ActorInitializer init) { return new DeployToUpgrade(init.Self, this); } public object Create(ActorInitializer init) { return new DeployToUpgrade(init.Self, this); }
} }
@@ -45,6 +49,7 @@ namespace OpenRA.Mods.Common.Traits
readonly DeployToUpgradeInfo info; readonly DeployToUpgradeInfo info;
readonly UpgradeManager manager; readonly UpgradeManager manager;
readonly bool checkTerrainType; readonly bool checkTerrainType;
readonly bool canTurn;
readonly Lazy<ISpriteBody> body; readonly Lazy<ISpriteBody> body;
bool isUpgraded; bool isUpgraded;
@@ -55,6 +60,7 @@ namespace OpenRA.Mods.Common.Traits
this.info = info; this.info = info;
manager = self.Trait<UpgradeManager>(); manager = self.Trait<UpgradeManager>();
checkTerrainType = info.AllowedTerrainTypes.Length > 0; checkTerrainType = info.AllowedTerrainTypes.Length > 0;
canTurn = self.Info.Traits.WithInterface<IFacingInfo>().Any();
body = Exts.Lazy(self.TraitOrDefault<ISpriteBody>); body = Exts.Lazy(self.TraitOrDefault<ISpriteBody>);
} }
@@ -101,6 +107,10 @@ namespace OpenRA.Mods.Common.Traits
{ {
self.CancelActivity(); self.CancelActivity();
// Turn
if (info.Facing != -1 && canTurn)
self.QueueActivity(new Turn(self, info.Facing));
// Grant the upgrade // Grant the upgrade
self.QueueActivity(new CallFunc(GrantUpgrades)); self.QueueActivity(new CallFunc(GrantUpgrades));