Convert UpgradeOnMovement to conditions.
This commit is contained in:
@@ -496,7 +496,7 @@
|
|||||||
<Compile Include="Traits\Upgrades\ProximityExternalCondition.cs" />
|
<Compile Include="Traits\Upgrades\ProximityExternalCondition.cs" />
|
||||||
<Compile Include="Traits\Upgrades\GrantConditionOnDamageState.cs" />
|
<Compile Include="Traits\Upgrades\GrantConditionOnDamageState.cs" />
|
||||||
<Compile Include="Traits\Upgrades\UpgradeOnTerrain.cs" />
|
<Compile Include="Traits\Upgrades\UpgradeOnTerrain.cs" />
|
||||||
<Compile Include="Traits\Upgrades\UpgradeOnMovement.cs" />
|
<Compile Include="Traits\Upgrades\GrantConditionOnMovement.cs" />
|
||||||
<Compile Include="Traits\Upgrades\UpgradeManager.cs" />
|
<Compile Include="Traits\Upgrades\UpgradeManager.cs" />
|
||||||
<Compile Include="Traits\Valued.cs" />
|
<Compile Include="Traits\Valued.cs" />
|
||||||
<Compile Include="Traits\Voiced.cs" />
|
<Compile Include="Traits\Voiced.cs" />
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
#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.Linq;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.Common.Traits
|
||||||
|
{
|
||||||
|
public class GrantConditionOnMovementInfo : UpgradableTraitInfo, Requires<IMoveInfo>
|
||||||
|
{
|
||||||
|
[FieldLoader.Require]
|
||||||
|
[UpgradeGrantedReference]
|
||||||
|
[Desc("Condition to grant.")]
|
||||||
|
public readonly string Condition = null;
|
||||||
|
|
||||||
|
[Desc("Apply upgrades on straight vertical movement as well.")]
|
||||||
|
public readonly bool ConsiderVerticalMovement = false;
|
||||||
|
|
||||||
|
public override object Create(ActorInitializer init) { return new GrantConditionOnMovement(init.Self, this); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class GrantConditionOnMovement : UpgradableTrait<GrantConditionOnMovementInfo>, ITick
|
||||||
|
{
|
||||||
|
readonly IMove movement;
|
||||||
|
|
||||||
|
UpgradeManager manager;
|
||||||
|
int conditionToken = UpgradeManager.InvalidConditionToken;
|
||||||
|
|
||||||
|
public GrantConditionOnMovement(Actor self, GrantConditionOnMovementInfo info)
|
||||||
|
: base(info)
|
||||||
|
{
|
||||||
|
movement = self.Trait<IMove>();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Created(Actor self)
|
||||||
|
{
|
||||||
|
manager = self.TraitOrDefault<UpgradeManager>();
|
||||||
|
base.Created(self);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ITick.Tick(Actor self)
|
||||||
|
{
|
||||||
|
if (manager == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var isMovingVertically = Info.ConsiderVerticalMovement ? movement.IsMovingVertically : false;
|
||||||
|
var isMoving = !IsTraitDisabled && !self.IsDead && (movement.IsMoving || isMovingVertically);
|
||||||
|
if (isMoving && conditionToken == UpgradeManager.InvalidConditionToken)
|
||||||
|
conditionToken = manager.GrantCondition(self, Info.Condition);
|
||||||
|
else if (!isMoving && conditionToken != UpgradeManager.InvalidConditionToken)
|
||||||
|
conditionToken = manager.RevokeCondition(self, conditionToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
#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.Linq;
|
|
||||||
using OpenRA.Traits;
|
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.Traits
|
|
||||||
{
|
|
||||||
public class UpgradeOnMovementInfo : UpgradableTraitInfo, Requires<UpgradeManagerInfo>, Requires<IMoveInfo>
|
|
||||||
{
|
|
||||||
[UpgradeGrantedReference, FieldLoader.Require]
|
|
||||||
[Desc("The upgrades to grant.")]
|
|
||||||
public readonly string[] Upgrades = { };
|
|
||||||
|
|
||||||
[Desc("Apply upgrades on straight vertical movement as well.")]
|
|
||||||
public readonly bool ConsiderVerticalMovement = false;
|
|
||||||
|
|
||||||
public override object Create(ActorInitializer init) { return new UpgradeOnMovement(init.Self, this); }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class UpgradeOnMovement : UpgradableTrait<UpgradeOnMovementInfo>, ITick
|
|
||||||
{
|
|
||||||
readonly UpgradeManager manager;
|
|
||||||
readonly IMove movement;
|
|
||||||
|
|
||||||
bool granted;
|
|
||||||
|
|
||||||
public UpgradeOnMovement(Actor self, UpgradeOnMovementInfo info)
|
|
||||||
: base(info)
|
|
||||||
{
|
|
||||||
manager = self.Trait<UpgradeManager>();
|
|
||||||
movement = self.Trait<IMove>();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Revoke(Actor self)
|
|
||||||
{
|
|
||||||
if (!granted)
|
|
||||||
return;
|
|
||||||
|
|
||||||
foreach (var up in Info.Upgrades)
|
|
||||||
manager.RevokeUpgrade(self, up, this);
|
|
||||||
|
|
||||||
granted = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ITick.Tick(Actor self)
|
|
||||||
{
|
|
||||||
if (IsTraitDisabled)
|
|
||||||
{
|
|
||||||
Revoke(self);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var isMovingVertically = Info.ConsiderVerticalMovement ? movement.IsMovingVertically : false;
|
|
||||||
var isMoving = !self.IsDead && (movement.IsMoving || isMovingVertically);
|
|
||||||
if (isMoving && !granted)
|
|
||||||
{
|
|
||||||
foreach (var up in Info.Upgrades)
|
|
||||||
manager.GrantUpgrade(self, up, this);
|
|
||||||
|
|
||||||
granted = true;
|
|
||||||
}
|
|
||||||
else if (!isMoving)
|
|
||||||
Revoke(self);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -623,6 +623,12 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
RenameNodeKey(node, "GrantConditionOnDamageState");
|
RenameNodeKey(node, "GrantConditionOnDamageState");
|
||||||
ConvertUpgradesToCondition(parent, node, "Upgrades", "Condition");
|
ConvertUpgradesToCondition(parent, node, "Upgrades", "Condition");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (node.Key.StartsWith("UpgradeOnMovement", StringComparison.Ordinal))
|
||||||
|
{
|
||||||
|
RenameNodeKey(node, "GrantConditionOnMovement");
|
||||||
|
ConvertUpgradesToCondition(parent, node, "Upgrades", "Condition");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
|
UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user