Merge pull request #12497 from pchote/condition-manager

Complete Upgrades -> Condition transition.
This commit is contained in:
Oliver Brakmann
2016-12-24 13:43:15 +01:00
committed by GitHub
90 changed files with 363 additions and 406 deletions

View File

@@ -64,8 +64,8 @@ namespace OpenRA.Mods.Common.Lint
if (ungranted.Any()) if (ungranted.Any())
emitError("Actor type `{0}` consumes conditions that are not granted: {1}".F(actorInfo.Key, ungranted.JoinWith(", "))); emitError("Actor type `{0}` consumes conditions that are not granted: {1}".F(actorInfo.Key, ungranted.JoinWith(", ")));
if ((consumed.Any() || granted.Any()) && actorInfo.Value.TraitInfoOrDefault<UpgradeManagerInfo>() == null) if ((consumed.Any() || granted.Any()) && actorInfo.Value.TraitInfoOrDefault<ConditionManagerInfo>() == null)
emitError("Actor type `{0}` defines conditions but does not include an UpgradeManager".F(actorInfo.Key)); emitError("Actor type `{0}` defines conditions but does not include a ConditionManager".F(actorInfo.Key));
} }
} }
} }

View File

@@ -491,14 +491,14 @@
<Compile Include="Traits\Transforms.cs" /> <Compile Include="Traits\Transforms.cs" />
<Compile Include="Traits\Turreted.cs" /> <Compile Include="Traits\Turreted.cs" />
<Compile Include="Traits\ProducibleWithLevel.cs" /> <Compile Include="Traits\ProducibleWithLevel.cs" />
<Compile Include="Traits\Upgrades\GrantConditionOnDeploy.cs" /> <Compile Include="Traits\Conditions\GrantConditionOnDeploy.cs" />
<Compile Include="Traits\Upgrades\DisableOnCondition.cs" /> <Compile Include="Traits\Conditions\DisableOnCondition.cs" />
<Compile Include="Traits\Upgrades\UpgradableTrait.cs" /> <Compile Include="Traits\Conditions\ConditionalTrait.cs" />
<Compile Include="Traits\Upgrades\ProximityExternalCondition.cs" /> <Compile Include="Traits\Conditions\ProximityExternalCondition.cs" />
<Compile Include="Traits\Upgrades\GrantConditionOnDamageState.cs" /> <Compile Include="Traits\Conditions\GrantConditionOnDamageState.cs" />
<Compile Include="Traits\Upgrades\GrantConditionOnTerrain.cs" /> <Compile Include="Traits\Conditions\GrantConditionOnTerrain.cs" />
<Compile Include="Traits\Upgrades\GrantConditionOnMovement.cs" /> <Compile Include="Traits\Conditions\GrantConditionOnMovement.cs" />
<Compile Include="Traits\Upgrades\UpgradeManager.cs" /> <Compile Include="Traits\Conditions\ConditionManager.cs" />
<Compile Include="Traits\Valued.cs" /> <Compile Include="Traits\Valued.cs" />
<Compile Include="Traits\Voiced.cs" /> <Compile Include="Traits\Voiced.cs" />
<Compile Include="Traits\Wanders.cs" /> <Compile Include="Traits\Wanders.cs" />
@@ -772,9 +772,9 @@
<Compile Include="Traits\AutoCarryable.cs" /> <Compile Include="Traits\AutoCarryable.cs" />
<Compile Include="Traits\AutoCarryall.cs" /> <Compile Include="Traits\AutoCarryall.cs" />
<Compile Include="Traits\World\CliffBackImpassabilityLayer.cs" /> <Compile Include="Traits\World\CliffBackImpassabilityLayer.cs" />
<Compile Include="Traits\Upgrades\GrantCondition.cs" /> <Compile Include="Traits\Conditions\GrantCondition.cs" />
<Compile Include="Traits\Upgrades\ExternalConditions.cs" /> <Compile Include="Traits\Conditions\ExternalConditions.cs" />
<Compile Include="Traits\Upgrades\StackedCondition.cs" /> <Compile Include="Traits\Conditions\StackedCondition.cs" />
<Compile Include="Traits\Buildings\BridgeHut.cs" /> <Compile Include="Traits\Buildings\BridgeHut.cs" />
<Compile Include="Traits\Buildings\BridgePlaceholder.cs" /> <Compile Include="Traits\Buildings\BridgePlaceholder.cs" />
<Compile Include="Traits\Buildings\GroundLevelBridge.cs" /> <Compile Include="Traits\Buildings\GroundLevelBridge.cs" />

View File

@@ -20,15 +20,15 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Scripting namespace OpenRA.Mods.Common.Scripting
{ {
[ScriptPropertyGroup("General")] [ScriptPropertyGroup("General")]
public class ConditionProperties : ScriptActorProperties, Requires<UpgradeManagerInfo> public class ConditionProperties : ScriptActorProperties, Requires<ConditionManagerInfo>
{ {
readonly UpgradeManager um; readonly ConditionManager conditionManager;
readonly Dictionary<string, Stack<int>> legacyShim = new Dictionary<string, Stack<int>>(); readonly Dictionary<string, Stack<int>> legacyShim = new Dictionary<string, Stack<int>>();
public ConditionProperties(ScriptContext context, Actor self) public ConditionProperties(ScriptContext context, Actor self)
: base(context, self) : base(context, self)
{ {
um = self.Trait<UpgradeManager>(); conditionManager = self.Trait<ConditionManager>();
} }
[Desc("Grant an external condition on this actor and return the revocation token.", [Desc("Grant an external condition on this actor and return the revocation token.",
@@ -36,22 +36,22 @@ namespace OpenRA.Mods.Common.Scripting
"If duration > 0 the condition will be automatically revoked after the defined number of ticks")] "If duration > 0 the condition will be automatically revoked after the defined number of ticks")]
public int GrantCondition(string condition, int duration = 0) public int GrantCondition(string condition, int duration = 0)
{ {
if (!um.AcceptsExternalCondition(Self, condition)) if (!conditionManager.AcceptsExternalCondition(Self, condition))
throw new InvalidDataException("Condition `{0}` has not been listed on an ExternalConditions trait".F(condition)); throw new InvalidDataException("Condition `{0}` has not been listed on an ExternalConditions trait".F(condition));
return um.GrantCondition(Self, condition, true, duration); return conditionManager.GrantCondition(Self, condition, true, duration);
} }
[Desc("Revoke a condition using the token returned by GrantCondition.")] [Desc("Revoke a condition using the token returned by GrantCondition.")]
public void RevokeCondition(int token) public void RevokeCondition(int token)
{ {
um.RevokeCondition(Self, token); conditionManager.RevokeCondition(Self, token);
} }
[Desc("Check whether this actor accepts a specific external condition.")] [Desc("Check whether this actor accepts a specific external condition.")]
public bool AcceptsCondition(string condition) public bool AcceptsCondition(string condition)
{ {
return um.AcceptsExternalCondition(Self, condition); return conditionManager.AcceptsExternalCondition(Self, condition);
} }
[Desc("Grant an upgrade to this actor. DEPRECATED! Will be removed.")] [Desc("Grant an upgrade to this actor. DEPRECATED! Will be removed.")]

View File

@@ -14,7 +14,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
public abstract class AffectsShroudInfo : UpgradableTraitInfo public abstract class AffectsShroudInfo : ConditionalTraitInfo
{ {
public readonly WDist Range = WDist.Zero; public readonly WDist Range = WDist.Zero;
@@ -26,7 +26,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly VisibilityType Type = VisibilityType.Footprint; public readonly VisibilityType Type = VisibilityType.Footprint;
} }
public abstract class AffectsShroud : UpgradableTrait<AffectsShroudInfo>, ITick, ISync, INotifyAddedToWorld, INotifyRemovedFromWorld public abstract class AffectsShroud : ConditionalTrait<AffectsShroudInfo>, ITick, ISync, INotifyAddedToWorld, INotifyRemovedFromWorld
{ {
static readonly PPos[] NoCells = { }; static readonly PPos[] NoCells = { };

View File

@@ -105,7 +105,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly AircraftInfo Info; public readonly AircraftInfo Info;
readonly Actor self; readonly Actor self;
UpgradeManager um; ConditionManager conditionManager;
IDisposable reservation; IDisposable reservation;
IEnumerable<int> speedModifiers; IEnumerable<int> speedModifiers;
@@ -119,8 +119,8 @@ namespace OpenRA.Mods.Common.Traits
bool airborne; bool airborne;
bool cruising; bool cruising;
bool firstTick = true; bool firstTick = true;
int airborneToken = UpgradeManager.InvalidConditionToken; int airborneToken = ConditionManager.InvalidConditionToken;
int cruisingToken = UpgradeManager.InvalidConditionToken; int cruisingToken = ConditionManager.InvalidConditionToken;
bool isMoving; bool isMoving;
bool isMovingVertically; bool isMovingVertically;
@@ -146,7 +146,7 @@ namespace OpenRA.Mods.Common.Traits
public void Created(Actor self) public void Created(Actor self)
{ {
um = self.TraitOrDefault<UpgradeManager>(); conditionManager = self.TraitOrDefault<ConditionManager>();
speedModifiers = self.TraitsImplementing<ISpeedModifier>().ToArray().Select(sm => sm.GetSpeedModifier()); speedModifiers = self.TraitsImplementing<ISpeedModifier>().ToArray().Select(sm => sm.GetSpeedModifier());
cachedPosition = self.CenterPosition; cachedPosition = self.CenterPosition;
} }
@@ -661,7 +661,7 @@ namespace OpenRA.Mods.Common.Traits
OnAirborneAltitudeLeft(); OnAirborneAltitudeLeft();
} }
#region Airborne upgrades #region Airborne conditions
void OnAirborneAltitudeReached() void OnAirborneAltitudeReached()
{ {
@@ -669,8 +669,8 @@ namespace OpenRA.Mods.Common.Traits
return; return;
airborne = true; airborne = true;
if (um != null && !string.IsNullOrEmpty(Info.AirborneCondition) && airborneToken == UpgradeManager.InvalidConditionToken) if (conditionManager != null && !string.IsNullOrEmpty(Info.AirborneCondition) && airborneToken == ConditionManager.InvalidConditionToken)
airborneToken = um.GrantCondition(self, Info.AirborneCondition); airborneToken = conditionManager.GrantCondition(self, Info.AirborneCondition);
} }
void OnAirborneAltitudeLeft() void OnAirborneAltitudeLeft()
@@ -679,13 +679,13 @@ namespace OpenRA.Mods.Common.Traits
return; return;
airborne = false; airborne = false;
if (um != null && airborneToken != UpgradeManager.InvalidConditionToken) if (conditionManager != null && airborneToken != ConditionManager.InvalidConditionToken)
airborneToken = um.RevokeCondition(self, airborneToken); airborneToken = conditionManager.RevokeCondition(self, airborneToken);
} }
#endregion #endregion
#region Cruising upgrades #region Cruising conditions
void OnCruisingAltitudeReached() void OnCruisingAltitudeReached()
{ {
@@ -693,8 +693,8 @@ namespace OpenRA.Mods.Common.Traits
return; return;
cruising = true; cruising = true;
if (um != null && !string.IsNullOrEmpty(Info.CruisingCondition) && cruisingToken == UpgradeManager.InvalidConditionToken) if (conditionManager != null && !string.IsNullOrEmpty(Info.CruisingCondition) && cruisingToken == ConditionManager.InvalidConditionToken)
cruisingToken = um.GrantCondition(self, Info.CruisingCondition); cruisingToken = conditionManager.GrantCondition(self, Info.CruisingCondition);
} }
void OnCruisingAltitudeLeft() void OnCruisingAltitudeLeft()
@@ -702,8 +702,8 @@ namespace OpenRA.Mods.Common.Traits
if (!cruising) if (!cruising)
return; return;
cruising = false; cruising = false;
if (um != null && cruisingToken != UpgradeManager.InvalidConditionToken) if (conditionManager != null && cruisingToken != ConditionManager.InvalidConditionToken)
cruisingToken = um.RevokeCondition(self, cruisingToken); cruisingToken = conditionManager.RevokeCondition(self, cruisingToken);
} }
#endregion #endregion

View File

@@ -25,7 +25,7 @@ namespace OpenRA.Mods.Common.Traits
} }
[Desc("Allows you to attach weapons to the unit (use @IdentifierSuffix for > 1)")] [Desc("Allows you to attach weapons to the unit (use @IdentifierSuffix for > 1)")]
public class ArmamentInfo : UpgradableTraitInfo, Requires<AttackBaseInfo> public class ArmamentInfo : ConditionalTraitInfo, Requires<AttackBaseInfo>
{ {
public readonly string Name = "primary"; public readonly string Name = "primary";
@@ -96,7 +96,7 @@ namespace OpenRA.Mods.Common.Traits
} }
} }
public class Armament : UpgradableTrait<ArmamentInfo>, ITick, IExplodeModifier public class Armament : ConditionalTrait<ArmamentInfo>, ITick, IExplodeModifier
{ {
public readonly WeaponInfo Weapon; public readonly WeaponInfo Weapon;
public readonly Barrel[] Barrels; public readonly Barrel[] Barrels;

View File

@@ -12,14 +12,14 @@
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
[Desc("Used to define weapon efficiency modifiers with different percentages per Type.")] [Desc("Used to define weapon efficiency modifiers with different percentages per Type.")]
public class ArmorInfo : UpgradableTraitInfo public class ArmorInfo : ConditionalTraitInfo
{ {
public readonly string Type = null; public readonly string Type = null;
public override object Create(ActorInitializer init) { return new Armor(init.Self, this); } public override object Create(ActorInitializer init) { return new Armor(init.Self, this); }
} }
public class Armor : UpgradableTrait<ArmorInfo> public class Armor : ConditionalTrait<ArmorInfo>
{ {
public Armor(Actor self, ArmorInfo info) public Armor(Actor self, ArmorInfo info)
: base(info) { } : base(info) { }

View File

@@ -19,7 +19,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
public abstract class AttackBaseInfo : UpgradableTraitInfo public abstract class AttackBaseInfo : ConditionalTraitInfo
{ {
[Desc("Armament names")] [Desc("Armament names")]
public readonly string[] Armaments = { "primary", "secondary" }; public readonly string[] Armaments = { "primary", "secondary" };
@@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Traits
public override abstract object Create(ActorInitializer init); public override abstract object Create(ActorInitializer init);
} }
public abstract class AttackBase : UpgradableTrait<AttackBaseInfo>, IIssueOrder, IResolveOrder, IOrderVoice, ISync public abstract class AttackBase : ConditionalTrait<AttackBaseInfo>, IIssueOrder, IResolveOrder, IOrderVoice, ISync
{ {
readonly string attackOrderName = "Attack"; readonly string attackOrderName = "Attack";
readonly string forceAttackOrderName = "ForceAttack"; readonly string forceAttackOrderName = "ForceAttack";

View File

@@ -17,7 +17,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
[Desc("The actor will automatically engage the enemy when it is in range.")] [Desc("The actor will automatically engage the enemy when it is in range.")]
public class AutoTargetInfo : UpgradableTraitInfo, Requires<AttackBaseInfo>, UsesInit<StanceInit> public class AutoTargetInfo : ConditionalTraitInfo, Requires<AttackBaseInfo>, UsesInit<StanceInit>
{ {
[Desc("It will try to hunt down the enemy if it is not set to defend.")] [Desc("It will try to hunt down the enemy if it is not set to defend.")]
public readonly bool AllowMovement = true; public readonly bool AllowMovement = true;
@@ -50,7 +50,7 @@ namespace OpenRA.Mods.Common.Traits
public enum UnitStance { HoldFire, ReturnFire, Defend, AttackAnything } public enum UnitStance { HoldFire, ReturnFire, Defend, AttackAnything }
public class AutoTarget : UpgradableTrait<AutoTargetInfo>, INotifyIdle, INotifyDamage, ITick, IResolveOrder, ISync public class AutoTarget : ConditionalTrait<AutoTargetInfo>, INotifyIdle, INotifyDamage, ITick, IResolveOrder, ISync
{ {
readonly AttackBase[] attackBases; readonly AttackBase[] attackBases;
readonly AttackFollow[] attackFollows; readonly AttackFollow[] attackFollows;

View File

@@ -21,14 +21,14 @@ namespace OpenRA.Mods.Common.Traits
} }
[Desc("This actor blocks bullets and missiles with 'Blockable' property.")] [Desc("This actor blocks bullets and missiles with 'Blockable' property.")]
public class BlocksProjectilesInfo : UpgradableTraitInfo public class BlocksProjectilesInfo : ConditionalTraitInfo
{ {
public readonly WDist Height = WDist.FromCells(1); public readonly WDist Height = WDist.FromCells(1);
public override object Create(ActorInitializer init) { return new BlocksProjectiles(init.Self, this); } public override object Create(ActorInitializer init) { return new BlocksProjectiles(init.Self, this); }
} }
public class BlocksProjectiles : UpgradableTrait<BlocksProjectilesInfo>, IBlocksProjectiles public class BlocksProjectiles : ConditionalTrait<BlocksProjectilesInfo>, IBlocksProjectiles
{ {
public BlocksProjectiles(Actor self, BlocksProjectilesInfo info) public BlocksProjectiles(Actor self, BlocksProjectilesInfo info)
: base(info) { } : base(info) { }

View File

@@ -41,8 +41,8 @@ namespace OpenRA.Mods.Common.Traits
public class PrimaryBuilding : INotifyCreated, IIssueOrder, IResolveOrder public class PrimaryBuilding : INotifyCreated, IIssueOrder, IResolveOrder
{ {
readonly PrimaryBuildingInfo info; readonly PrimaryBuildingInfo info;
UpgradeManager um; ConditionManager conditionManager;
int primaryToken = UpgradeManager.InvalidConditionToken; int primaryToken = ConditionManager.InvalidConditionToken;
public bool IsPrimary { get; private set; } public bool IsPrimary { get; private set; }
@@ -53,7 +53,7 @@ namespace OpenRA.Mods.Common.Traits
void INotifyCreated.Created(Actor self) void INotifyCreated.Created(Actor self)
{ {
um = self.TraitOrDefault<UpgradeManager>(); conditionManager = self.TraitOrDefault<ConditionManager>();
} }
IEnumerable<IOrderTargeter> IIssueOrder.Orders IEnumerable<IOrderTargeter> IIssueOrder.Orders
@@ -95,13 +95,13 @@ namespace OpenRA.Mods.Common.Traits
b.Trait.SetPrimaryProducer(b.Actor, false); b.Trait.SetPrimaryProducer(b.Actor, false);
} }
if (um != null && primaryToken == UpgradeManager.InvalidConditionToken && !string.IsNullOrEmpty(info.PrimaryCondition)) if (conditionManager != null && primaryToken == ConditionManager.InvalidConditionToken && !string.IsNullOrEmpty(info.PrimaryCondition))
primaryToken = um.GrantCondition(self, info.PrimaryCondition); primaryToken = conditionManager.GrantCondition(self, info.PrimaryCondition);
Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", info.SelectionNotification, self.Owner.Faction.InternalName); Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", info.SelectionNotification, self.Owner.Faction.InternalName);
} }
else if (primaryToken != UpgradeManager.InvalidConditionToken) else if (primaryToken != ConditionManager.InvalidConditionToken)
primaryToken = um.RevokeCondition(self, primaryToken); primaryToken = conditionManager.RevokeCondition(self, primaryToken);
} }
} }
} }

View File

@@ -18,7 +18,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
[Desc("Building can be repaired by the repair button.")] [Desc("Building can be repaired by the repair button.")]
public class RepairableBuildingInfo : UpgradableTraitInfo, Requires<HealthInfo> public class RepairableBuildingInfo : ConditionalTraitInfo, Requires<HealthInfo>
{ {
public readonly int RepairPercent = 20; public readonly int RepairPercent = 20;
public readonly int RepairInterval = 24; public readonly int RepairInterval = 24;
@@ -41,7 +41,7 @@ namespace OpenRA.Mods.Common.Traits
public override object Create(ActorInitializer init) { return new RepairableBuilding(init.Self, this); } public override object Create(ActorInitializer init) { return new RepairableBuilding(init.Self, this); }
} }
public class RepairableBuilding : UpgradableTrait<RepairableBuildingInfo>, ITick public class RepairableBuilding : ConditionalTrait<RepairableBuildingInfo>, ITick
{ {
[Sync] [Sync]
public int RepairersHash public int RepairersHash

View File

@@ -88,8 +88,8 @@ namespace OpenRA.Mods.Common.Traits
int totalWeight = 0; int totalWeight = 0;
int reservedWeight = 0; int reservedWeight = 0;
Aircraft aircraft; Aircraft aircraft;
UpgradeManager upgradeManager; ConditionManager conditionManager;
int loadingToken = UpgradeManager.InvalidConditionToken; int loadingToken = ConditionManager.InvalidConditionToken;
Stack<int> loadedTokens = new Stack<int>(); Stack<int> loadedTokens = new Stack<int>();
CPos currentCell; CPos currentCell;
@@ -141,7 +141,7 @@ namespace OpenRA.Mods.Common.Traits
void INotifyCreated.Created(Actor self) void INotifyCreated.Created(Actor self)
{ {
aircraft = self.TraitOrDefault<Aircraft>(); aircraft = self.TraitOrDefault<Aircraft>();
upgradeManager = self.Trait<UpgradeManager>(); conditionManager = self.Trait<ConditionManager>();
} }
static int GetWeight(Actor a) { return a.Info.TraitInfo<PassengerInfo>().Weight; } static int GetWeight(Actor a) { return a.Info.TraitInfo<PassengerInfo>().Weight; }
@@ -208,8 +208,8 @@ namespace OpenRA.Mods.Common.Traits
if (!HasSpace(w)) if (!HasSpace(w))
return false; return false;
if (upgradeManager != null && loadingToken == UpgradeManager.InvalidConditionToken && !string.IsNullOrEmpty(Info.LoadingCondition)) if (conditionManager != null && loadingToken == ConditionManager.InvalidConditionToken && !string.IsNullOrEmpty(Info.LoadingCondition))
loadingToken = upgradeManager.GrantCondition(self, Info.LoadingCondition); loadingToken = conditionManager.GrantCondition(self, Info.LoadingCondition);
reserves.Add(a); reserves.Add(a);
reservedWeight += w; reservedWeight += w;
@@ -225,8 +225,8 @@ namespace OpenRA.Mods.Common.Traits
reservedWeight -= GetWeight(a); reservedWeight -= GetWeight(a);
reserves.Remove(a); reserves.Remove(a);
if (loadingToken != UpgradeManager.InvalidConditionToken) if (loadingToken != ConditionManager.InvalidConditionToken)
loadingToken = upgradeManager.RevokeCondition(self, loadingToken); loadingToken = conditionManager.RevokeCondition(self, loadingToken);
} }
public string CursorForOrder(Actor self, Order order) public string CursorForOrder(Actor self, Order order)
@@ -266,10 +266,10 @@ namespace OpenRA.Mods.Common.Traits
Stack<int> passengerToken; Stack<int> passengerToken;
if (passengerTokens.TryGetValue(a.Info.Name, out passengerToken) && passengerToken.Any()) if (passengerTokens.TryGetValue(a.Info.Name, out passengerToken) && passengerToken.Any())
upgradeManager.RevokeCondition(self, passengerToken.Pop()); conditionManager.RevokeCondition(self, passengerToken.Pop());
if (loadedTokens.Any()) if (loadedTokens.Any())
upgradeManager.RevokeCondition(self, loadedTokens.Pop()); conditionManager.RevokeCondition(self, loadedTokens.Pop());
return a; return a;
} }
@@ -321,8 +321,8 @@ namespace OpenRA.Mods.Common.Traits
reservedWeight -= w; reservedWeight -= w;
reserves.Remove(a); reserves.Remove(a);
if (loadingToken != UpgradeManager.InvalidConditionToken) if (loadingToken != ConditionManager.InvalidConditionToken)
loadingToken = upgradeManager.RevokeCondition(self, loadingToken); loadingToken = conditionManager.RevokeCondition(self, loadingToken);
} }
// If not initialized then this will be notified in the first tick // If not initialized then this will be notified in the first tick
@@ -334,11 +334,11 @@ namespace OpenRA.Mods.Common.Traits
p.Transport = self; p.Transport = self;
string passengerCondition; string passengerCondition;
if (upgradeManager != null && Info.PassengerConditions.TryGetValue(a.Info.Name, out passengerCondition)) if (conditionManager != null && Info.PassengerConditions.TryGetValue(a.Info.Name, out passengerCondition))
passengerTokens.GetOrAdd(a.Info.Name).Push(upgradeManager.GrantCondition(self, passengerCondition)); passengerTokens.GetOrAdd(a.Info.Name).Push(conditionManager.GrantCondition(self, passengerCondition));
if (upgradeManager != null && !string.IsNullOrEmpty(Info.LoadedCondition)) if (conditionManager != null && !string.IsNullOrEmpty(Info.LoadedCondition))
loadedTokens.Push(upgradeManager.GrantCondition(self, Info.LoadedCondition)); loadedTokens.Push(conditionManager.GrantCondition(self, Info.LoadedCondition));
} }
void INotifyKilled.Killed(Actor self, AttackInfo e) void INotifyKilled.Killed(Actor self, AttackInfo e)

View File

@@ -15,7 +15,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
[Desc("Can be carried by actors with the `Carryall` trait.")] [Desc("Can be carried by actors with the `Carryall` trait.")]
public class CarryableInfo : UpgradableTraitInfo public class CarryableInfo : ConditionalTraitInfo
{ {
[GrantedConditionReference] [GrantedConditionReference]
[Desc("The condition to grant to self while a carryall has been reserved.")] [Desc("The condition to grant to self while a carryall has been reserved.")]
@@ -31,11 +31,11 @@ namespace OpenRA.Mods.Common.Traits
public override object Create(ActorInitializer init) { return new Carryable(init.Self, this); } public override object Create(ActorInitializer init) { return new Carryable(init.Self, this); }
} }
public class Carryable : UpgradableTrait<CarryableInfo> public class Carryable : ConditionalTrait<CarryableInfo>
{ {
UpgradeManager upgradeManager; ConditionManager conditionManager;
int reservedToken = UpgradeManager.InvalidConditionToken; int reservedToken = ConditionManager.InvalidConditionToken;
int carriedToken = UpgradeManager.InvalidConditionToken; int carriedToken = ConditionManager.InvalidConditionToken;
public Actor Carrier { get; private set; } public Actor Carrier { get; private set; }
public bool Reserved { get { return state != State.Free; } } public bool Reserved { get { return state != State.Free; } }
@@ -51,7 +51,7 @@ namespace OpenRA.Mods.Common.Traits
protected override void Created(Actor self) protected override void Created(Actor self)
{ {
upgradeManager = self.Trait<UpgradeManager>(); conditionManager = self.Trait<ConditionManager>();
base.Created(self); base.Created(self);
} }
@@ -63,8 +63,8 @@ namespace OpenRA.Mods.Common.Traits
attached = true; attached = true;
if (carriedToken == UpgradeManager.InvalidConditionToken && !string.IsNullOrEmpty(Info.CarriedCondition)) if (carriedToken == ConditionManager.InvalidConditionToken && !string.IsNullOrEmpty(Info.CarriedCondition))
carriedToken = upgradeManager.GrantCondition(self, Info.CarriedCondition); carriedToken = conditionManager.GrantCondition(self, Info.CarriedCondition);
} }
// This gets called by carrier after we touched down // This gets called by carrier after we touched down
@@ -75,8 +75,8 @@ namespace OpenRA.Mods.Common.Traits
attached = false; attached = false;
if (carriedToken != UpgradeManager.InvalidConditionToken) if (carriedToken != ConditionManager.InvalidConditionToken)
carriedToken = upgradeManager.RevokeCondition(self, carriedToken); carriedToken = conditionManager.RevokeCondition(self, carriedToken);
} }
public virtual bool Reserve(Actor self, Actor carrier) public virtual bool Reserve(Actor self, Actor carrier)
@@ -87,8 +87,8 @@ namespace OpenRA.Mods.Common.Traits
state = State.Reserved; state = State.Reserved;
Carrier = carrier; Carrier = carrier;
if (reservedToken == UpgradeManager.InvalidConditionToken && !string.IsNullOrEmpty(Info.ReservedCondition)) if (reservedToken == ConditionManager.InvalidConditionToken && !string.IsNullOrEmpty(Info.ReservedCondition))
reservedToken = upgradeManager.GrantCondition(self, Info.ReservedCondition); reservedToken = conditionManager.GrantCondition(self, Info.ReservedCondition);
return true; return true;
} }
@@ -98,8 +98,8 @@ namespace OpenRA.Mods.Common.Traits
state = State.Free; state = State.Free;
Carrier = null; Carrier = null;
if (reservedToken != UpgradeManager.InvalidConditionToken) if (reservedToken != ConditionManager.InvalidConditionToken)
reservedToken = upgradeManager.RevokeCondition(self, reservedToken); reservedToken = conditionManager.RevokeCondition(self, reservedToken);
} }
// Prepare for transport pickup // Prepare for transport pickup

View File

@@ -33,7 +33,7 @@ namespace OpenRA.Mods.Common.Traits
} }
[Desc("This unit can cloak and uncloak in specific situations.")] [Desc("This unit can cloak and uncloak in specific situations.")]
public class CloakInfo : UpgradableTraitInfo public class CloakInfo : ConditionalTraitInfo
{ {
[Desc("Measured in game ticks.")] [Desc("Measured in game ticks.")]
public readonly int InitialDelay = 10; public readonly int InitialDelay = 10;
@@ -60,17 +60,17 @@ namespace OpenRA.Mods.Common.Traits
public override object Create(ActorInitializer init) { return new Cloak(this); } public override object Create(ActorInitializer init) { return new Cloak(this); }
} }
public class Cloak : UpgradableTrait<CloakInfo>, IRenderModifier, INotifyDamage, public class Cloak : ConditionalTrait<CloakInfo>, IRenderModifier, INotifyDamage,
INotifyAttack, ITick, IVisibilityModifier, IRadarColorModifier, INotifyCreated, INotifyHarvesterAction INotifyAttack, ITick, IVisibilityModifier, IRadarColorModifier, INotifyCreated, INotifyHarvesterAction
{ {
[Sync] int remainingTime; [Sync] int remainingTime;
[Sync] bool damageDisabled; [Sync] bool damageDisabled;
bool isDocking; bool isDocking;
UpgradeManager upgradeManager; ConditionManager conditionManager;
CPos? lastPos; CPos? lastPos;
bool wasCloaked = false; bool wasCloaked = false;
int cloakedToken = UpgradeManager.InvalidConditionToken; int cloakedToken = ConditionManager.InvalidConditionToken;
public Cloak(CloakInfo info) public Cloak(CloakInfo info)
: base(info) : base(info)
@@ -80,13 +80,13 @@ namespace OpenRA.Mods.Common.Traits
void INotifyCreated.Created(Actor self) void INotifyCreated.Created(Actor self)
{ {
upgradeManager = self.TraitOrDefault<UpgradeManager>(); conditionManager = self.TraitOrDefault<ConditionManager>();
if (Cloaked) if (Cloaked)
{ {
wasCloaked = true; wasCloaked = true;
if (upgradeManager != null && cloakedToken == UpgradeManager.InvalidConditionToken && !string.IsNullOrEmpty(Info.CloakedCondition)) if (conditionManager != null && cloakedToken == ConditionManager.InvalidConditionToken && !string.IsNullOrEmpty(Info.CloakedCondition))
cloakedToken = upgradeManager.GrantCondition(self, Info.CloakedCondition); cloakedToken = conditionManager.GrantCondition(self, Info.CloakedCondition);
} }
} }
@@ -144,16 +144,16 @@ namespace OpenRA.Mods.Common.Traits
var isCloaked = Cloaked; var isCloaked = Cloaked;
if (isCloaked && !wasCloaked) if (isCloaked && !wasCloaked)
{ {
if (upgradeManager != null && cloakedToken == UpgradeManager.InvalidConditionToken && !string.IsNullOrEmpty(Info.CloakedCondition)) if (conditionManager != null && cloakedToken == ConditionManager.InvalidConditionToken && !string.IsNullOrEmpty(Info.CloakedCondition))
cloakedToken = upgradeManager.GrantCondition(self, Info.CloakedCondition); cloakedToken = conditionManager.GrantCondition(self, Info.CloakedCondition);
if (!self.TraitsImplementing<Cloak>().Any(a => a != this && a.Cloaked)) if (!self.TraitsImplementing<Cloak>().Any(a => a != this && a.Cloaked))
Game.Sound.Play(SoundType.World, Info.CloakSound, self.CenterPosition); Game.Sound.Play(SoundType.World, Info.CloakSound, self.CenterPosition);
} }
else if (!isCloaked && wasCloaked) else if (!isCloaked && wasCloaked)
{ {
if (cloakedToken != UpgradeManager.InvalidConditionToken) if (cloakedToken != ConditionManager.InvalidConditionToken)
cloakedToken = upgradeManager.RevokeCondition(self, cloakedToken); cloakedToken = conditionManager.RevokeCondition(self, cloakedToken);
if (!self.TraitsImplementing<Cloak>().Any(a => a != this && a.Cloaked)) if (!self.TraitsImplementing<Cloak>().Any(a => a != this && a.Cloaked))
Game.Sound.Play(SoundType.World, Info.UncloakSound, self.CenterPosition); Game.Sound.Play(SoundType.World, Info.UncloakSound, self.CenterPosition);

View File

@@ -24,10 +24,10 @@ namespace OpenRA.Mods.Common.Traits
void Update(int duration, int remaining); void Update(int duration, int remaining);
} }
[Desc("Attach this to a unit to enable dynamic upgrades by warheads, experience, crates, support powers, etc.")] [Desc("Attach this to a unit to enable dynamic conditions by warheads, experience, crates, support powers, etc.")]
public class UpgradeManagerInfo : TraitInfo<UpgradeManager>, Requires<IConditionConsumerInfo> { } public class ConditionManagerInfo : TraitInfo<ConditionManager>, Requires<IConditionConsumerInfo> { }
public class UpgradeManager : INotifyCreated, ITick public class ConditionManager : INotifyCreated, ITick
{ {
/// <summary>Value used to represent an invalid token.</summary> /// <summary>Value used to represent an invalid token.</summary>
public static readonly int InvalidConditionToken = -1; public static readonly int InvalidConditionToken = -1;
@@ -74,9 +74,6 @@ namespace OpenRA.Mods.Common.Traits
int nextToken = 1; int nextToken = 1;
/// <summary>Temporary shim between the old and new upgrade/condition grant and revoke methods.</summary>
readonly Dictionary<Pair<object, string>, int> objectTokenShim = new Dictionary<Pair<object, string>, int>();
/// <summary>Cache of condition -> enabled state for quick evaluation of boolean conditions.</summary> /// <summary>Cache of condition -> enabled state for quick evaluation of boolean conditions.</summary>
readonly Dictionary<string, bool> conditionCache = new Dictionary<string, bool>(); readonly Dictionary<string, bool> conditionCache = new Dictionary<string, bool>();
@@ -267,53 +264,5 @@ namespace OpenRA.Mods.Common.Traits
timersToRemove.Clear(); timersToRemove.Clear();
} }
#region Shim methods for legacy upgrade granting code
void CheckCanManageConditions()
{
if (state == null)
throw new InvalidOperationException("Conditions cannot be managed until the actor has been fully created.");
}
public void GrantTimedUpgrade(Actor self, string upgrade, int duration, object source = null, int dupesAllowed = 1)
{
CheckCanManageConditions();
var token = GrantCondition(self, upgrade, false, duration);
if (source != null)
objectTokenShim[Pair.New(source, upgrade)] = token;
}
public void GrantUpgrade(Actor self, string upgrade, object source)
{
CheckCanManageConditions();
objectTokenShim[Pair.New(source, upgrade)] = GrantCondition(self, upgrade);
}
public void RevokeUpgrade(Actor self, string upgrade, object source)
{
CheckCanManageConditions();
RevokeCondition(self, objectTokenShim[Pair.New(source, upgrade)]);
}
/// <summary>Returns true if the actor uses the given upgrade. Does not check the actual level of the upgrade.</summary>
public bool AcknowledgesUpgrade(Actor self, string upgrade)
{
CheckCanManageConditions();
return state.ContainsKey(upgrade);
}
/// <summary>Returns true only if the actor can accept another level of the upgrade.</summary>
public bool AcceptsUpgrade(Actor self, string upgrade)
{
CheckCanManageConditions();
bool enabled;
if (!conditionCache.TryGetValue(upgrade, out enabled))
return false;
return !enabled;
}
#endregion
} }
} }

View File

@@ -17,7 +17,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
/// <summary>Use as base class for *Info to subclass of UpgradableTrait. (See UpgradableTrait.)</summary> /// <summary>Use as base class for *Info to subclass of UpgradableTrait. (See UpgradableTrait.)</summary>
public abstract class UpgradableTraitInfo : IConditionConsumerInfo, IRulesetLoaded public abstract class ConditionalTraitInfo : IConditionConsumerInfo, IRulesetLoaded
{ {
static readonly IReadOnlyDictionary<string, bool> NoConditions = new ReadOnlyDictionary<string, bool>(new Dictionary<string, bool>()); static readonly IReadOnlyDictionary<string, bool> NoConditions = new ReadOnlyDictionary<string, bool>(new Dictionary<string, bool>());
@@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.Traits
public abstract object Create(ActorInitializer init); public abstract object Create(ActorInitializer init);
// HACK: A shim for all the ActorPreview code that used to query UpgradeMinEnabledLevel directly // HACK: A shim for all the ActorPreview code that used to query UpgradeMinEnabledLevel directly
// This can go away after we introduce an InitialUpgrades ActorInit and have the traits query the // This can go away after we introduce an InitialConditions ActorInit and have the traits query the
// condition directly // condition directly
public bool EnabledByDefault { get; private set; } public bool EnabledByDefault { get; private set; }
@@ -39,11 +39,11 @@ namespace OpenRA.Mods.Common.Traits
} }
/// <summary> /// <summary>
/// Abstract base for enabling and disabling trait using upgrades. /// Abstract base for enabling and disabling trait using conditions.
/// Requires basing *Info on UpgradableTraitInfo and using base(info) constructor. /// Requires basing *Info on UpgradableTraitInfo and using base(info) constructor.
/// Note that EnabledByUpgrade is not called at creation even if this starts as enabled. /// TraitEnabled will be called at creation if the trait starts enabled or does not use conditions.
/// </summary> /// </summary>
public abstract class UpgradableTrait<InfoType> : IConditionConsumer, IDisabledTrait, INotifyCreated, ISync where InfoType : UpgradableTraitInfo public abstract class ConditionalTrait<InfoType> : IConditionConsumer, IDisabledTrait, INotifyCreated, ISync where InfoType : ConditionalTraitInfo
{ {
public readonly InfoType Info; public readonly InfoType Info;
@@ -60,11 +60,11 @@ namespace OpenRA.Mods.Common.Traits
[Sync] public bool IsTraitDisabled { get; private set; } [Sync] public bool IsTraitDisabled { get; private set; }
public UpgradableTrait(InfoType info) public ConditionalTrait(InfoType info)
{ {
Info = info; Info = info;
// Conditional traits will be enabled (if appropriate) by the UpgradeManager // Conditional traits will be enabled (if appropriate) by the ConditionManager
// calling IConditionConsumer.ConditionsChanged at the end of INotifyCreated. // calling IConditionConsumer.ConditionsChanged at the end of INotifyCreated.
IsTraitDisabled = Info.RequiresCondition != null; IsTraitDisabled = Info.RequiresCondition != null;
} }

View File

@@ -13,13 +13,13 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
[Desc("Disable the actor when this trait is enabled by an upgrade.")] [Desc("Disable the actor when this trait is enabled by a condition.")]
public class DisableOnConditionInfo : UpgradableTraitInfo public class DisableOnConditionInfo : ConditionalTraitInfo
{ {
public override object Create(ActorInitializer init) { return new DisableOnCondition(this); } public override object Create(ActorInitializer init) { return new DisableOnCondition(this); }
} }
public class DisableOnCondition : UpgradableTrait<DisableOnConditionInfo>, IDisable public class DisableOnCondition : ConditionalTrait<DisableOnConditionInfo>, IDisable
{ {
public DisableOnCondition(DisableOnConditionInfo info) public DisableOnCondition(DisableOnConditionInfo info)
: base(info) { } : base(info) { }

View File

@@ -14,7 +14,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
[Desc("Grants a condition while the trait is active.")] [Desc("Grants a condition while the trait is active.")]
class GrantConditionInfo : UpgradableTraitInfo class GrantConditionInfo : ConditionalTraitInfo
{ {
[FieldLoader.Require] [FieldLoader.Require]
[GrantedConditionReference] [GrantedConditionReference]
@@ -24,33 +24,33 @@ namespace OpenRA.Mods.Common.Traits
public override object Create(ActorInitializer init) { return new GrantCondition(this); } public override object Create(ActorInitializer init) { return new GrantCondition(this); }
} }
class GrantCondition : UpgradableTrait<GrantConditionInfo> class GrantCondition : ConditionalTrait<GrantConditionInfo>
{ {
UpgradeManager manager; ConditionManager conditionManager;
int conditionToken = UpgradeManager.InvalidConditionToken; int conditionToken = ConditionManager.InvalidConditionToken;
public GrantCondition(GrantConditionInfo info) public GrantCondition(GrantConditionInfo info)
: base(info) { } : base(info) { }
protected override void Created(Actor self) protected override void Created(Actor self)
{ {
manager = self.Trait<UpgradeManager>(); conditionManager = self.Trait<ConditionManager>();
base.Created(self); base.Created(self);
} }
protected override void TraitEnabled(Actor self) protected override void TraitEnabled(Actor self)
{ {
if (conditionToken == UpgradeManager.InvalidConditionToken) if (conditionToken == ConditionManager.InvalidConditionToken)
conditionToken = manager.GrantCondition(self, Info.Condition); conditionToken = conditionManager.GrantCondition(self, Info.Condition);
} }
protected override void TraitDisabled(Actor self) protected override void TraitDisabled(Actor self)
{ {
if (conditionToken == UpgradeManager.InvalidConditionToken) if (conditionToken == ConditionManager.InvalidConditionToken)
return; return;
conditionToken = manager.RevokeCondition(self, conditionToken); conditionToken = conditionManager.RevokeCondition(self, conditionToken);
} }
} }
} }

View File

@@ -13,7 +13,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
[Desc("Applies an upgrade to the actor at specified damage states.")] [Desc("Applies a condition to the actor at specified damage states.")]
public class GrantConditionOnDamageStateInfo : ITraitInfo, Requires<HealthInfo> public class GrantConditionOnDamageStateInfo : ITraitInfo, Requires<HealthInfo>
{ {
[FieldLoader.Require] [FieldLoader.Require]
@@ -27,7 +27,7 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Play a random sound from this list when disabled.")] [Desc("Play a random sound from this list when disabled.")]
public readonly string[] DisabledSounds = { }; public readonly string[] DisabledSounds = { };
[Desc("Levels of damage at which to grant upgrades.")] [Desc("Levels of damage at which to grant the condition.")]
public readonly DamageState ValidDamageStates = DamageState.Heavy | DamageState.Critical; public readonly DamageState ValidDamageStates = DamageState.Heavy | DamageState.Critical;
[Desc("Is the condition irrevocable once it has been activated?")] [Desc("Is the condition irrevocable once it has been activated?")]
@@ -41,8 +41,8 @@ namespace OpenRA.Mods.Common.Traits
readonly GrantConditionOnDamageStateInfo info; readonly GrantConditionOnDamageStateInfo info;
readonly Health health; readonly Health health;
UpgradeManager manager; ConditionManager conditionManager;
int conditionToken = UpgradeManager.InvalidConditionToken; int conditionToken = ConditionManager.InvalidConditionToken;
public GrantConditionOnDamageState(Actor self, GrantConditionOnDamageStateInfo info) public GrantConditionOnDamageState(Actor self, GrantConditionOnDamageStateInfo info)
{ {
@@ -52,16 +52,16 @@ namespace OpenRA.Mods.Common.Traits
void INotifyCreated.Created(Actor self) void INotifyCreated.Created(Actor self)
{ {
manager = self.TraitOrDefault<UpgradeManager>(); conditionManager = self.TraitOrDefault<ConditionManager>();
GrantUpgradeOnValidDamageState(self, health.DamageState); GrantConditionOnValidDamageState(self, health.DamageState);
} }
void GrantUpgradeOnValidDamageState(Actor self, DamageState state) void GrantConditionOnValidDamageState(Actor self, DamageState state)
{ {
if (!info.ValidDamageStates.HasFlag(state) || conditionToken != UpgradeManager.InvalidConditionToken) if (!info.ValidDamageStates.HasFlag(state) || conditionToken != ConditionManager.InvalidConditionToken)
return; return;
conditionToken = manager.GrantCondition(self, info.Condition); conditionToken = conditionManager.GrantCondition(self, info.Condition);
var sound = info.EnabledSounds.RandomOrDefault(Game.CosmeticRandom); var sound = info.EnabledSounds.RandomOrDefault(Game.CosmeticRandom);
Game.Sound.Play(SoundType.World, sound, self.CenterPosition); Game.Sound.Play(SoundType.World, sound, self.CenterPosition);
@@ -69,15 +69,15 @@ namespace OpenRA.Mods.Common.Traits
void INotifyDamageStateChanged.DamageStateChanged(Actor self, AttackInfo e) void INotifyDamageStateChanged.DamageStateChanged(Actor self, AttackInfo e)
{ {
var granted = conditionToken != UpgradeManager.InvalidConditionToken; var granted = conditionToken != ConditionManager.InvalidConditionToken;
if ((granted && info.GrantPermanently) || manager == null) if ((granted && info.GrantPermanently) || conditionManager == null)
return; return;
if (!granted && !info.ValidDamageStates.HasFlag(e.PreviousDamageState)) if (!granted && !info.ValidDamageStates.HasFlag(e.PreviousDamageState))
GrantUpgradeOnValidDamageState(self, health.DamageState); GrantConditionOnValidDamageState(self, health.DamageState);
else if (granted && !info.ValidDamageStates.HasFlag(e.DamageState) && info.ValidDamageStates.HasFlag(e.PreviousDamageState)) else if (granted && !info.ValidDamageStates.HasFlag(e.DamageState) && info.ValidDamageStates.HasFlag(e.PreviousDamageState))
{ {
conditionToken = manager.RevokeCondition(self, conditionToken); conditionToken = conditionManager.RevokeCondition(self, conditionToken);
var sound = info.DisabledSounds.RandomOrDefault(Game.CosmeticRandom); var sound = info.DisabledSounds.RandomOrDefault(Game.CosmeticRandom);
Game.Sound.Play(SoundType.World, sound, self.CenterPosition); Game.Sound.Play(SoundType.World, sound, self.CenterPosition);

View File

@@ -30,8 +30,7 @@ namespace OpenRA.Mods.Common.Traits
[Desc("The condition to grant after deploying and revoke before undeploying.")] [Desc("The condition to grant after deploying and revoke before undeploying.")]
public readonly string DeployedCondition = null; public readonly string DeployedCondition = null;
[Desc("The terrain types that this actor can deploy on to receive these upgrades. " + [Desc("The terrain types that this actor can deploy on. Leave empty to allow any.")]
"Leave empty to allow any.")]
public readonly HashSet<string> AllowedTerrainTypes = new HashSet<string>(); public readonly HashSet<string> AllowedTerrainTypes = new HashSet<string>();
[Desc("Can this actor deploy on slopes?")] [Desc("Can this actor deploy on slopes?")]
@@ -72,9 +71,9 @@ namespace OpenRA.Mods.Common.Traits
readonly Lazy<WithSpriteBody> body; readonly Lazy<WithSpriteBody> body;
DeployState deployState; DeployState deployState;
UpgradeManager manager; ConditionManager conditionManager;
int deployedToken = UpgradeManager.InvalidConditionToken; int deployedToken = ConditionManager.InvalidConditionToken;
int undeployedToken = UpgradeManager.InvalidConditionToken; int undeployedToken = ConditionManager.InvalidConditionToken;
public GrantConditionOnDeploy(ActorInitializer init, GrantConditionOnDeployInfo info) public GrantConditionOnDeploy(ActorInitializer init, GrantConditionOnDeployInfo info)
{ {
@@ -89,7 +88,7 @@ namespace OpenRA.Mods.Common.Traits
public void Created(Actor self) public void Created(Actor self)
{ {
manager = self.TraitOrDefault<UpgradeManager>(); conditionManager = self.TraitOrDefault<ConditionManager>();
switch (deployState) switch (deployState)
{ {
@@ -119,13 +118,13 @@ namespace OpenRA.Mods.Common.Traits
public IEnumerable<IOrderTargeter> Orders public IEnumerable<IOrderTargeter> Orders
{ {
get { yield return new DeployOrderTargeter("DeployToUpgrade", 5, get { yield return new DeployOrderTargeter("GrantConditionOnDeploy", 5,
() => IsCursorBlocked() ? info.DeployBlockedCursor : info.DeployCursor); } () => IsCursorBlocked() ? info.DeployBlockedCursor : info.DeployCursor); }
} }
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 == "DeployToUpgrade") if (order.OrderID == "GrantConditionOnDeploy")
return new Order(order.OrderID, self, queued); return new Order(order.OrderID, self, queued);
return null; return null;
@@ -133,7 +132,7 @@ namespace OpenRA.Mods.Common.Traits
public void ResolveOrder(Actor self, Order order) public void ResolveOrder(Actor self, Order order)
{ {
if (order.OrderString != "DeployToUpgrade" || deployState == DeployState.Deploying || deployState == DeployState.Undeploying) if (order.OrderString != "GrantConditionOnDeploy" || deployState == DeployState.Deploying || deployState == DeployState.Undeploying)
return; return;
if (!order.Queued) if (!order.Queued)
@@ -207,19 +206,19 @@ namespace OpenRA.Mods.Common.Traits
if (!string.IsNullOrEmpty(info.DeploySound)) if (!string.IsNullOrEmpty(info.DeploySound))
Game.Sound.Play(SoundType.World, info.DeploySound, self.CenterPosition); Game.Sound.Play(SoundType.World, info.DeploySound, self.CenterPosition);
// Revoke upgrades that are used while undeployed. // Revoke condition that is applied while undeployed.
if (!init) if (!init)
OnDeployStarted(); OnDeployStarted();
// If there is no animation to play just grant the upgrades that are used while deployed. // If there is no animation to play just grant the condition that is used while deployed.
// Alternatively, play the deploy animation and then grant the upgrades. // Alternatively, play the deploy animation and then grant the condition.
if (string.IsNullOrEmpty(info.DeployAnimation) || body.Value == null) if (string.IsNullOrEmpty(info.DeployAnimation) || body.Value == null)
OnDeployCompleted(); OnDeployCompleted();
else else
body.Value.PlayCustomAnimation(self, info.DeployAnimation, OnDeployCompleted); body.Value.PlayCustomAnimation(self, info.DeployAnimation, OnDeployCompleted);
} }
/// <summary>Play undeploy sound and animation and after that revoke the upgrades.</summary> /// <summary>Play undeploy sound and animation and after that revoke the condition.</summary>
void Undeploy() { Undeploy(false); } void Undeploy() { Undeploy(false); }
void Undeploy(bool init) void Undeploy(bool init)
{ {
@@ -233,8 +232,8 @@ namespace OpenRA.Mods.Common.Traits
if (!init) if (!init)
OnUndeployStarted(); OnUndeployStarted();
// If there is no animation to play just grant the upgrades that are used while undeployed. // If there is no animation to play just grant the condition that is used while undeployed.
// Alternatively, play the undeploy animation and then grant the upgrades. // Alternatively, play the undeploy animation and then grant the condition.
if (string.IsNullOrEmpty(info.DeployAnimation) || body.Value == null) if (string.IsNullOrEmpty(info.DeployAnimation) || body.Value == null)
OnUndeployCompleted(); OnUndeployCompleted();
else else
@@ -243,32 +242,32 @@ namespace OpenRA.Mods.Common.Traits
void OnDeployStarted() void OnDeployStarted()
{ {
if (undeployedToken != UpgradeManager.InvalidConditionToken) if (undeployedToken != ConditionManager.InvalidConditionToken)
undeployedToken = manager.RevokeCondition(self, undeployedToken); undeployedToken = conditionManager.RevokeCondition(self, undeployedToken);
deployState = DeployState.Deploying; deployState = DeployState.Deploying;
} }
void OnDeployCompleted() void OnDeployCompleted()
{ {
if (manager != null && !string.IsNullOrEmpty(info.DeployedCondition) && deployedToken == UpgradeManager.InvalidConditionToken) if (conditionManager != null && !string.IsNullOrEmpty(info.DeployedCondition) && deployedToken == ConditionManager.InvalidConditionToken)
deployedToken = manager.GrantCondition(self, info.DeployedCondition); deployedToken = conditionManager.GrantCondition(self, info.DeployedCondition);
deployState = DeployState.Deployed; deployState = DeployState.Deployed;
} }
void OnUndeployStarted() void OnUndeployStarted()
{ {
if (deployedToken != UpgradeManager.InvalidConditionToken) if (deployedToken != ConditionManager.InvalidConditionToken)
deployedToken = manager.RevokeCondition(self, deployedToken); deployedToken = conditionManager.RevokeCondition(self, deployedToken);
deployState = DeployState.Deploying; deployState = DeployState.Deploying;
} }
void OnUndeployCompleted() void OnUndeployCompleted()
{ {
if (manager != null && !string.IsNullOrEmpty(info.UndeployedCondition) && undeployedToken == UpgradeManager.InvalidConditionToken) if (conditionManager != null && !string.IsNullOrEmpty(info.UndeployedCondition) && undeployedToken == ConditionManager.InvalidConditionToken)
undeployedToken = manager.GrantCondition(self, info.UndeployedCondition); undeployedToken = conditionManager.GrantCondition(self, info.UndeployedCondition);
deployState = DeployState.Undeployed; deployState = DeployState.Undeployed;
} }

View File

@@ -14,25 +14,25 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
public class GrantConditionOnMovementInfo : UpgradableTraitInfo, Requires<IMoveInfo> public class GrantConditionOnMovementInfo : ConditionalTraitInfo, Requires<IMoveInfo>
{ {
[FieldLoader.Require] [FieldLoader.Require]
[GrantedConditionReference] [GrantedConditionReference]
[Desc("Condition to grant.")] [Desc("Condition to grant.")]
public readonly string Condition = null; public readonly string Condition = null;
[Desc("Apply upgrades on straight vertical movement as well.")] [Desc("Apply condition on straight vertical movement as well.")]
public readonly bool ConsiderVerticalMovement = false; public readonly bool ConsiderVerticalMovement = false;
public override object Create(ActorInitializer init) { return new GrantConditionOnMovement(init.Self, this); } public override object Create(ActorInitializer init) { return new GrantConditionOnMovement(init.Self, this); }
} }
public class GrantConditionOnMovement : UpgradableTrait<GrantConditionOnMovementInfo>, ITick public class GrantConditionOnMovement : ConditionalTrait<GrantConditionOnMovementInfo>, ITick
{ {
readonly IMove movement; readonly IMove movement;
UpgradeManager manager; ConditionManager conditionManager;
int conditionToken = UpgradeManager.InvalidConditionToken; int conditionToken = ConditionManager.InvalidConditionToken;
public GrantConditionOnMovement(Actor self, GrantConditionOnMovementInfo info) public GrantConditionOnMovement(Actor self, GrantConditionOnMovementInfo info)
: base(info) : base(info)
@@ -42,21 +42,21 @@ namespace OpenRA.Mods.Common.Traits
protected override void Created(Actor self) protected override void Created(Actor self)
{ {
manager = self.TraitOrDefault<UpgradeManager>(); conditionManager = self.TraitOrDefault<ConditionManager>();
base.Created(self); base.Created(self);
} }
void ITick.Tick(Actor self) void ITick.Tick(Actor self)
{ {
if (manager == null) if (conditionManager == null)
return; return;
var isMovingVertically = Info.ConsiderVerticalMovement ? movement.IsMovingVertically : false; var isMovingVertically = Info.ConsiderVerticalMovement ? movement.IsMovingVertically : false;
var isMoving = !IsTraitDisabled && !self.IsDead && (movement.IsMoving || isMovingVertically); var isMoving = !IsTraitDisabled && !self.IsDead && (movement.IsMoving || isMovingVertically);
if (isMoving && conditionToken == UpgradeManager.InvalidConditionToken) if (isMoving && conditionToken == ConditionManager.InvalidConditionToken)
conditionToken = manager.GrantCondition(self, Info.Condition); conditionToken = conditionManager.GrantCondition(self, Info.Condition);
else if (!isMoving && conditionToken != UpgradeManager.InvalidConditionToken) else if (!isMoving && conditionToken != ConditionManager.InvalidConditionToken)
conditionToken = manager.RevokeCondition(self, conditionToken); conditionToken = conditionManager.RevokeCondition(self, conditionToken);
} }
} }
} }

View File

@@ -22,7 +22,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly string Condition = null; public readonly string Condition = null;
[FieldLoader.Require] [FieldLoader.Require]
[Desc("Terrain names to trigger the upgrade.")] [Desc("Terrain names to trigger the condition.")]
public readonly string[] TerrainTypes = { }; public readonly string[] TerrainTypes = { };
public object Create(ActorInitializer init) { return new GrantConditionOnTerrain(init, this); } public object Create(ActorInitializer init) { return new GrantConditionOnTerrain(init, this); }
@@ -32,8 +32,8 @@ namespace OpenRA.Mods.Common.Traits
{ {
readonly GrantConditionOnTerrainInfo info; readonly GrantConditionOnTerrainInfo info;
UpgradeManager manager; ConditionManager conditionManager;
int conditionToken = UpgradeManager.InvalidConditionToken; int conditionToken = ConditionManager.InvalidConditionToken;
string previousTerrain; string previousTerrain;
public GrantConditionOnTerrain(ActorInitializer init, GrantConditionOnTerrainInfo info) public GrantConditionOnTerrain(ActorInitializer init, GrantConditionOnTerrainInfo info)
@@ -43,22 +43,22 @@ namespace OpenRA.Mods.Common.Traits
void INotifyCreated.Created(Actor self) void INotifyCreated.Created(Actor self)
{ {
manager = self.TraitOrDefault<UpgradeManager>(); conditionManager = self.TraitOrDefault<ConditionManager>();
} }
public void Tick(Actor self) public void Tick(Actor self)
{ {
if (manager == null) if (conditionManager == null)
return; return;
var currentTerrain = self.World.Map.GetTerrainInfo(self.Location).Type; var currentTerrain = self.World.Map.GetTerrainInfo(self.Location).Type;
var wantsGranted = info.TerrainTypes.Contains(currentTerrain); var wantsGranted = info.TerrainTypes.Contains(currentTerrain);
if (currentTerrain != previousTerrain) if (currentTerrain != previousTerrain)
{ {
if (wantsGranted && conditionToken == UpgradeManager.InvalidConditionToken) if (wantsGranted && conditionToken == ConditionManager.InvalidConditionToken)
conditionToken = manager.GrantCondition(self, info.Condition); conditionToken = conditionManager.GrantCondition(self, info.Condition);
else if (!wantsGranted && conditionToken != UpgradeManager.InvalidConditionToken) else if (!wantsGranted && conditionToken != ConditionManager.InvalidConditionToken)
conditionToken = manager.RevokeCondition(self, conditionToken); conditionToken = conditionManager.RevokeCondition(self, conditionToken);
} }
previousTerrain = currentTerrain; previousTerrain = currentTerrain;

View File

@@ -14,24 +14,24 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
[Desc("Applies an upgrade to actors within a specified range.")] [Desc("Applies a condition to actors within a specified range.")]
public class ProximityExternalConditionInfo : ITraitInfo public class ProximityExternalConditionInfo : ITraitInfo
{ {
[FieldLoader.Require] [FieldLoader.Require]
[Desc("The condition to apply. Must be included in the target actor's ExternalConditions list.")] [Desc("The condition to apply. Must be included in the target actor's ExternalConditions list.")]
public readonly string Condition = null; public readonly string Condition = null;
[Desc("The range to search for actors to upgrade.")] [Desc("The range to search for actors.")]
public readonly WDist Range = WDist.FromCells(3); public readonly WDist Range = WDist.FromCells(3);
[Desc("The maximum vertical range above terrain to search for actors to upgrade.", [Desc("The maximum vertical range above terrain to search for actors.",
"Ignored if 0 (actors are upgraded regardless of vertical distance).")] "Ignored if 0 (actors are selected regardless of vertical distance).")]
public readonly WDist MaximumVerticalOffset = WDist.Zero; public readonly WDist MaximumVerticalOffset = WDist.Zero;
[Desc("What diplomatic stances are affected.")] [Desc("What diplomatic stances are affected.")]
public readonly Stance ValidStances = Stance.Ally; public readonly Stance ValidStances = Stance.Ally;
[Desc("Grant the upgrades apply to this actor.")] [Desc("Condition is applied permanently to this actor.")]
public readonly bool AffectsParent = false; public readonly bool AffectsParent = false;
public readonly string EnableSound = null; public readonly string EnableSound = null;
@@ -108,9 +108,9 @@ namespace OpenRA.Mods.Common.Traits
if (!info.ValidStances.HasStance(stance)) if (!info.ValidStances.HasStance(stance))
return; return;
var um = a.TraitOrDefault<UpgradeManager>(); var cm = a.TraitOrDefault<ConditionManager>();
if (um != null && !tokens.ContainsKey(a) && um.AcceptsExternalCondition(a, info.Condition)) if (cm != null && !tokens.ContainsKey(a) && cm.AcceptsExternalCondition(a, info.Condition))
tokens[a] = um.GrantCondition(a, info.Condition, true); tokens[a] = cm.GrantCondition(a, info.Condition, true);
} }
public void UnitProducedByOther(Actor self, Actor producer, Actor produced) public void UnitProducedByOther(Actor self, Actor producer, Actor produced)
@@ -119,7 +119,7 @@ namespace OpenRA.Mods.Common.Traits
if (produced.OccupiesSpace == null) if (produced.OccupiesSpace == null)
return; return;
// We don't grant upgrades when disabled // We don't grant conditions when disabled
if (self.IsDisabled()) if (self.IsDisabled())
return; return;
@@ -130,9 +130,9 @@ namespace OpenRA.Mods.Common.Traits
if (!info.ValidStances.HasStance(stance)) if (!info.ValidStances.HasStance(stance))
return; return;
var um = produced.TraitOrDefault<UpgradeManager>(); var cm = produced.TraitOrDefault<ConditionManager>();
if (um != null && um.AcceptsExternalCondition(produced, info.Condition)) if (cm != null && cm.AcceptsExternalCondition(produced, info.Condition))
tokens[produced] = um.GrantCondition(produced, info.Condition, true); tokens[produced] = cm.GrantCondition(produced, info.Condition, true);
} }
} }
@@ -146,9 +146,9 @@ namespace OpenRA.Mods.Common.Traits
return; return;
tokens.Remove(a); tokens.Remove(a);
var um = a.TraitOrDefault<UpgradeManager>(); var cm = a.TraitOrDefault<ConditionManager>();
if (um != null) if (cm != null)
um.RevokeCondition(a, token); cm.RevokeCondition(a, token);
} }
} }
} }

View File

@@ -14,14 +14,14 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
[Desc("Grants an upgrade to the collector.")] [Desc("Grants a condition on the collector.")]
public class GrantExternalConditionCrateActionInfo : CrateActionInfo public class GrantExternalConditionCrateActionInfo : CrateActionInfo
{ {
[FieldLoader.Require] [FieldLoader.Require]
[Desc("The condition to apply. Must be included in the target actor's ExternalConditions list.")] [Desc("The condition to apply. Must be included in the target actor's ExternalConditions list.")]
public readonly string Condition = null; public readonly string Condition = null;
[Desc("Duration of the upgrade (in ticks). Set to 0 for a permanent upgrade.")] [Desc("Duration of the condition (in ticks). Set to 0 for a permanent condition.")]
public readonly int Duration = 0; public readonly int Duration = 0;
[Desc("The range to search for extra collectors in.", "Extra collectors will also be granted the crate action.")] [Desc("The range to search for extra collectors in.", "Extra collectors will also be granted the crate action.")]
@@ -47,8 +47,8 @@ namespace OpenRA.Mods.Common.Traits
bool AcceptsCondition(Actor a) bool AcceptsCondition(Actor a)
{ {
var um = a.TraitOrDefault<UpgradeManager>(); var cm = a.TraitOrDefault<ConditionManager>();
return um != null && um.AcceptsExternalCondition(a, info.Condition); return cm != null && cm.AcceptsExternalCondition(a, info.Condition);
} }
public override int GetSelectionShares(Actor collector) public override int GetSelectionShares(Actor collector)
@@ -71,11 +71,11 @@ namespace OpenRA.Mods.Common.Traits
if (!a.IsInWorld || a.IsDead) if (!a.IsInWorld || a.IsDead)
continue; continue;
var um = a.TraitOrDefault<UpgradeManager>(); var cm = a.TraitOrDefault<ConditionManager>();
// Condition token is ignored because we never revoke this condition. // Condition token is ignored because we never revoke this condition.
if (um != null) if (cm != null)
um.GrantCondition(a, info.Condition, true, info.Duration); cm.GrantCondition(a, info.Condition, true, info.Duration);
} }
}); });

View File

@@ -50,11 +50,11 @@ namespace OpenRA.Mods.Common.Traits
{ {
var inRange = self.World.FindActorsInCircle(self.CenterPosition, info.Range).Where(a => var inRange = self.World.FindActorsInCircle(self.CenterPosition, info.Range).Where(a =>
{ {
// Don't upgrade the same unit twice // Don't touch the same unit twice
if (a == collector) if (a == collector)
return false; return false;
// Only upgrade the collecting player's units // Only affect the collecting player's units
// TODO: Also apply to allied units? // TODO: Also apply to allied units?
if (a.Owner != collector.Owner) if (a.Owner != collector.Owner)
return false; return false;

View File

@@ -17,7 +17,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
[Desc("This actor receives damage from the given weapon when on the specified terrain type.")] [Desc("This actor receives damage from the given weapon when on the specified terrain type.")]
class DamagedByTerrainInfo : UpgradableTraitInfo, Requires<HealthInfo> class DamagedByTerrainInfo : ConditionalTraitInfo, Requires<HealthInfo>
{ {
[Desc("Amount of damage received per DamageInterval ticks.")] [Desc("Amount of damage received per DamageInterval ticks.")]
[FieldLoader.Require] public readonly int Damage = 0; [FieldLoader.Require] public readonly int Damage = 0;
@@ -40,7 +40,7 @@ namespace OpenRA.Mods.Common.Traits
public override object Create(ActorInitializer init) { return new DamagedByTerrain(init.Self, this); } public override object Create(ActorInitializer init) { return new DamagedByTerrain(init.Self, this); }
} }
class DamagedByTerrain : UpgradableTrait<DamagedByTerrainInfo>, ITick, ISync, INotifyAddedToWorld class DamagedByTerrain : ConditionalTrait<DamagedByTerrainInfo>, ITick, ISync, INotifyAddedToWorld
{ {
readonly Health health; readonly Health health;

View File

@@ -14,7 +14,7 @@ using System.Collections.Generic;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
[Desc("Actor can reveal Cloak actors in a specified range.")] [Desc("Actor can reveal Cloak actors in a specified range.")]
public class DetectCloakedInfo : UpgradableTraitInfo public class DetectCloakedInfo : ConditionalTraitInfo
{ {
[Desc("Specific cloak classifications I can reveal.")] [Desc("Specific cloak classifications I can reveal.")]
public readonly HashSet<string> CloakTypes = new HashSet<string> { "Cloak" }; public readonly HashSet<string> CloakTypes = new HashSet<string> { "Cloak" };
@@ -24,7 +24,7 @@ namespace OpenRA.Mods.Common.Traits
public override object Create(ActorInitializer init) { return new DetectCloaked(this); } public override object Create(ActorInitializer init) { return new DetectCloaked(this); }
} }
public class DetectCloaked : UpgradableTrait<DetectCloakedInfo> public class DetectCloaked : ConditionalTrait<DetectCloakedInfo>
{ {
public DetectCloaked(DetectCloakedInfo info) : base(info) { } public DetectCloaked(DetectCloakedInfo info) : base(info) { }
} }

View File

@@ -24,7 +24,7 @@ namespace OpenRA.Mods.Common.Traits
[FieldLoader.Require] [FieldLoader.Require]
[Desc("Condition to grant at each level.", [Desc("Condition to grant at each level.",
"Key is the XP requirements for each level as a percentage of our own value.", "Key is the XP requirements for each level as a percentage of our own value.",
"Value is a list of the upgrade types to grant")] "Value is the condition to grant.")]
public readonly Dictionary<int, string> Conditions = null; public readonly Dictionary<int, string> Conditions = null;
[GrantedConditionReference] [GrantedConditionReference]
@@ -46,7 +46,7 @@ namespace OpenRA.Mods.Common.Traits
readonly int initialExperience; readonly int initialExperience;
readonly List<Pair<int, string>> nextLevel = new List<Pair<int, string>>(); readonly List<Pair<int, string>> nextLevel = new List<Pair<int, string>>();
UpgradeManager um; ConditionManager conditionManager;
// Stored as a percentage of our value // Stored as a percentage of our value
[Sync] int experience = 0; [Sync] int experience = 0;
@@ -70,7 +70,7 @@ namespace OpenRA.Mods.Common.Traits
void INotifyCreated.Created(Actor self) void INotifyCreated.Created(Actor self)
{ {
um = self.TraitOrDefault<UpgradeManager>(); conditionManager = self.TraitOrDefault<ConditionManager>();
if (initialExperience > 0) if (initialExperience > 0)
GiveExperience(initialExperience, info.SuppressLevelupAnimation); GiveExperience(initialExperience, info.SuppressLevelupAnimation);
} }
@@ -92,8 +92,8 @@ namespace OpenRA.Mods.Common.Traits
while (Level < MaxLevel && experience >= nextLevel[Level].First) while (Level < MaxLevel && experience >= nextLevel[Level].First)
{ {
if (um != null) if (conditionManager != null)
um.GrantCondition(self, nextLevel[Level].Second); conditionManager.GrantCondition(self, nextLevel[Level].Second);
Level++; Level++;

View File

@@ -34,8 +34,8 @@ namespace OpenRA.Mods.Common.Traits
readonly GrantConditionOnPrerequisiteInfo info; readonly GrantConditionOnPrerequisiteInfo info;
readonly GrantConditionOnPrerequisiteManager globalManager; readonly GrantConditionOnPrerequisiteManager globalManager;
UpgradeManager manager; ConditionManager conditionManager;
int conditionToken = UpgradeManager.InvalidConditionToken; int conditionToken = ConditionManager.InvalidConditionToken;
bool wasAvailable; bool wasAvailable;
@@ -47,7 +47,7 @@ namespace OpenRA.Mods.Common.Traits
void INotifyCreated.Created(Actor self) void INotifyCreated.Created(Actor self)
{ {
manager = self.TraitOrDefault<UpgradeManager>(); conditionManager = self.TraitOrDefault<ConditionManager>();
} }
void INotifyAddedToWorld.AddedToWorld(Actor self) void INotifyAddedToWorld.AddedToWorld(Actor self)
@@ -64,13 +64,13 @@ namespace OpenRA.Mods.Common.Traits
public void PrerequisitesUpdated(Actor self, bool available) public void PrerequisitesUpdated(Actor self, bool available)
{ {
if (available == wasAvailable || manager == null) if (available == wasAvailable || conditionManager == null)
return; return;
if (available && conditionToken == UpgradeManager.InvalidConditionToken) if (available && conditionToken == ConditionManager.InvalidConditionToken)
conditionToken = manager.GrantCondition(self, info.Condition); conditionToken = conditionManager.GrantCondition(self, info.Condition);
else if (!available && conditionToken != UpgradeManager.InvalidConditionToken) else if (!available && conditionToken != ConditionManager.InvalidConditionToken)
conditionToken = manager.RevokeCondition(self, conditionToken); conditionToken = conditionManager.RevokeCondition(self, conditionToken);
wasAvailable = available; wasAvailable = available;
} }

View File

@@ -13,7 +13,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
class KillsSelfInfo : UpgradableTraitInfo class KillsSelfInfo : ConditionalTraitInfo
{ {
[Desc("Remove the actor from the world (and destroy it) instead of killing it.")] [Desc("Remove the actor from the world (and destroy it) instead of killing it.")]
public readonly bool RemoveInstead = false; public readonly bool RemoveInstead = false;
@@ -21,7 +21,7 @@ namespace OpenRA.Mods.Common.Traits
public override object Create(ActorInitializer init) { return new KillsSelf(this); } public override object Create(ActorInitializer init) { return new KillsSelf(this); }
} }
class KillsSelf : UpgradableTrait<KillsSelfInfo>, INotifyAddedToWorld class KillsSelf : ConditionalTrait<KillsSelfInfo>, INotifyAddedToWorld
{ {
public KillsSelf(KillsSelfInfo info) public KillsSelf(KillsSelfInfo info)
: base(info) { } : base(info) { }

View File

@@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Traits
} }
[Desc("Unit is able to move.")] [Desc("Unit is able to move.")]
public class MobileInfo : UpgradableTraitInfo, IMoveInfo, IPositionableInfo, IOccupySpaceInfo, IFacingInfo, public class MobileInfo : ConditionalTraitInfo, IMoveInfo, IPositionableInfo, IOccupySpaceInfo, IFacingInfo,
UsesInit<FacingInit>, UsesInit<LocationInit>, UsesInit<SubCellInit> UsesInit<FacingInit>, UsesInit<LocationInit>, UsesInit<SubCellInit>
{ {
[FieldLoader.LoadUsing("LoadSpeeds", true)] [FieldLoader.LoadUsing("LoadSpeeds", true)]
@@ -317,7 +317,7 @@ namespace OpenRA.Mods.Common.Traits
bool IOccupySpaceInfo.SharesCell { get { return SharesCell; } } bool IOccupySpaceInfo.SharesCell { get { return SharesCell; } }
} }
public class Mobile : UpgradableTrait<MobileInfo>, IIssueOrder, IResolveOrder, IOrderVoice, IPositionable, IMove, IFacing, ISync, public class Mobile : ConditionalTrait<MobileInfo>, IIssueOrder, IResolveOrder, IOrderVoice, IPositionable, IMove, IFacing, ISync,
IDeathActorInitModifier, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyBlockingMove, IActorPreviewInitModifier IDeathActorInitModifier, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyBlockingMove, IActorPreviewInitModifier
{ {
const int AverageTicksBeforePathing = 5; const int AverageTicksBeforePathing = 5;

View File

@@ -16,7 +16,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
[Desc("Display a colored overlay when a timed upgrade is active.")] [Desc("Display a colored overlay when a timed upgrade is active.")]
public class UpgradeOverlayInfo : UpgradableTraitInfo public class UpgradeOverlayInfo : ConditionalTraitInfo
{ {
[Desc("Palette to use when rendering the overlay")] [Desc("Palette to use when rendering the overlay")]
[PaletteReference] public readonly string Palette = "invuln"; [PaletteReference] public readonly string Palette = "invuln";
@@ -24,7 +24,7 @@ namespace OpenRA.Mods.Common.Traits
public override object Create(ActorInitializer init) { return new UpgradeOverlay(this); } public override object Create(ActorInitializer init) { return new UpgradeOverlay(this); }
} }
public class UpgradeOverlay : UpgradableTrait<UpgradeOverlayInfo>, IRenderModifier public class UpgradeOverlay : ConditionalTrait<UpgradeOverlayInfo>, IRenderModifier
{ {
public UpgradeOverlay(UpgradeOverlayInfo info) public UpgradeOverlay(UpgradeOverlayInfo info)
: base(info) { } : base(info) { }

View File

@@ -15,7 +15,7 @@ namespace OpenRA.Mods.Common.Traits
{ {
[Desc("Modifies the damage applied to this actor.", [Desc("Modifies the damage applied to this actor.",
"Use 0 to make actor invulnerable.")] "Use 0 to make actor invulnerable.")]
public class DamageMultiplierInfo : UpgradableTraitInfo public class DamageMultiplierInfo : ConditionalTraitInfo
{ {
[FieldLoader.Require] [FieldLoader.Require]
[Desc("Percentage modifier to apply.")] [Desc("Percentage modifier to apply.")]
@@ -24,7 +24,7 @@ namespace OpenRA.Mods.Common.Traits
public override object Create(ActorInitializer init) { return new DamageMultiplier(this); } public override object Create(ActorInitializer init) { return new DamageMultiplier(this); }
} }
public class DamageMultiplier : UpgradableTrait<DamageMultiplierInfo>, IDamageModifier public class DamageMultiplier : ConditionalTrait<DamageMultiplierInfo>, IDamageModifier
{ {
public DamageMultiplier(DamageMultiplierInfo info) public DamageMultiplier(DamageMultiplierInfo info)
: base(info) { } : base(info) { }

View File

@@ -12,7 +12,7 @@
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
[Desc("Modifies the damage applied by this actor.")] [Desc("Modifies the damage applied by this actor.")]
public class FirepowerMultiplierInfo : UpgradableTraitInfo public class FirepowerMultiplierInfo : ConditionalTraitInfo
{ {
[FieldLoader.Require] [FieldLoader.Require]
[Desc("Percentage modifier to apply.")] [Desc("Percentage modifier to apply.")]
@@ -21,7 +21,7 @@ namespace OpenRA.Mods.Common.Traits
public override object Create(ActorInitializer init) { return new FirepowerMultiplier(this); } public override object Create(ActorInitializer init) { return new FirepowerMultiplier(this); }
} }
public class FirepowerMultiplier : UpgradableTrait<FirepowerMultiplierInfo>, IFirepowerModifier public class FirepowerMultiplier : ConditionalTrait<FirepowerMultiplierInfo>, IFirepowerModifier
{ {
public FirepowerMultiplier(FirepowerMultiplierInfo info) public FirepowerMultiplier(FirepowerMultiplierInfo info)
: base(info) { } : base(info) { }

View File

@@ -12,7 +12,7 @@
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
[Desc("Modifies the inaccuracy of weapons fired by this actor.")] [Desc("Modifies the inaccuracy of weapons fired by this actor.")]
public class InaccuracyMultiplierInfo : UpgradableTraitInfo public class InaccuracyMultiplierInfo : ConditionalTraitInfo
{ {
[FieldLoader.Require] [FieldLoader.Require]
[Desc("Percentage modifier to apply.")] [Desc("Percentage modifier to apply.")]
@@ -21,7 +21,7 @@ namespace OpenRA.Mods.Common.Traits
public override object Create(ActorInitializer init) { return new InaccuracyMultiplier(this); } public override object Create(ActorInitializer init) { return new InaccuracyMultiplier(this); }
} }
public class InaccuracyMultiplier : UpgradableTrait<InaccuracyMultiplierInfo>, IInaccuracyModifier public class InaccuracyMultiplier : ConditionalTrait<InaccuracyMultiplierInfo>, IInaccuracyModifier
{ {
public InaccuracyMultiplier(InaccuracyMultiplierInfo info) public InaccuracyMultiplier(InaccuracyMultiplierInfo info)
: base(info) { } : base(info) { }

View File

@@ -14,7 +14,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
[Desc("Modifies the power usage/output of this actor.")] [Desc("Modifies the power usage/output of this actor.")]
public class PowerMultiplierInfo : UpgradableTraitInfo public class PowerMultiplierInfo : ConditionalTraitInfo
{ {
[FieldLoader.Require] [FieldLoader.Require]
[Desc("Percentage modifier to apply.")] [Desc("Percentage modifier to apply.")]
@@ -23,7 +23,7 @@ namespace OpenRA.Mods.Common.Traits
public override object Create(ActorInitializer init) { return new PowerMultiplier(init.Self, this); } public override object Create(ActorInitializer init) { return new PowerMultiplier(init.Self, this); }
} }
public class PowerMultiplier : UpgradableTrait<PowerMultiplierInfo>, IPowerModifier, INotifyOwnerChanged public class PowerMultiplier : ConditionalTrait<PowerMultiplierInfo>, IPowerModifier, INotifyOwnerChanged
{ {
PowerManager power; PowerManager power;

View File

@@ -12,7 +12,7 @@
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
[Desc("Modifies the range of weapons fired by this actor.")] [Desc("Modifies the range of weapons fired by this actor.")]
public class RangeMultiplierInfo : UpgradableTraitInfo public class RangeMultiplierInfo : ConditionalTraitInfo
{ {
[FieldLoader.Require] [FieldLoader.Require]
[Desc("Percentage modifier to apply.")] [Desc("Percentage modifier to apply.")]
@@ -21,7 +21,7 @@ namespace OpenRA.Mods.Common.Traits
public override object Create(ActorInitializer init) { return new RangeMultiplier(this); } public override object Create(ActorInitializer init) { return new RangeMultiplier(this); }
} }
public class RangeMultiplier : UpgradableTrait<RangeMultiplierInfo>, IRangeModifierInfo public class RangeMultiplier : ConditionalTrait<RangeMultiplierInfo>, IRangeModifierInfo
{ {
public RangeMultiplier(RangeMultiplierInfo info) public RangeMultiplier(RangeMultiplierInfo info)
: base(info) { } : base(info) { }

View File

@@ -12,7 +12,7 @@
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
[Desc("Modifies the reload time of weapons fired by this actor.")] [Desc("Modifies the reload time of weapons fired by this actor.")]
public class ReloadDelayMultiplierInfo : UpgradableTraitInfo public class ReloadDelayMultiplierInfo : ConditionalTraitInfo
{ {
[FieldLoader.Require] [FieldLoader.Require]
[Desc("Percentage modifier to apply.")] [Desc("Percentage modifier to apply.")]
@@ -21,7 +21,7 @@ namespace OpenRA.Mods.Common.Traits
public override object Create(ActorInitializer init) { return new ReloadDelayMultiplier(this); } public override object Create(ActorInitializer init) { return new ReloadDelayMultiplier(this); }
} }
public class ReloadDelayMultiplier : UpgradableTrait<ReloadDelayMultiplierInfo>, IReloadModifier public class ReloadDelayMultiplier : ConditionalTrait<ReloadDelayMultiplierInfo>, IReloadModifier
{ {
public ReloadDelayMultiplier(ReloadDelayMultiplierInfo info) public ReloadDelayMultiplier(ReloadDelayMultiplierInfo info)
: base(info) { } : base(info) { }

View File

@@ -12,7 +12,7 @@
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
[Desc("Modifies the movement speed of this actor.")] [Desc("Modifies the movement speed of this actor.")]
public class SpeedMultiplierInfo : UpgradableTraitInfo public class SpeedMultiplierInfo : ConditionalTraitInfo
{ {
[FieldLoader.Require] [FieldLoader.Require]
[Desc("Percentage modifier to apply.")] [Desc("Percentage modifier to apply.")]
@@ -21,7 +21,7 @@ namespace OpenRA.Mods.Common.Traits
public override object Create(ActorInitializer init) { return new SpeedMultiplier(this); } public override object Create(ActorInitializer init) { return new SpeedMultiplier(this); }
} }
public class SpeedMultiplier : UpgradableTrait<SpeedMultiplierInfo>, ISpeedModifier public class SpeedMultiplier : ConditionalTrait<SpeedMultiplierInfo>, ISpeedModifier
{ {
public SpeedMultiplier(SpeedMultiplierInfo info) public SpeedMultiplier(SpeedMultiplierInfo info)
: base(info) { } : base(info) { }

View File

@@ -50,8 +50,8 @@ namespace OpenRA.Mods.Common.Traits
readonly ParachutableInfo info; readonly ParachutableInfo info;
readonly IPositionable positionable; readonly IPositionable positionable;
UpgradeManager um; ConditionManager conditionManager;
int parachutingToken = UpgradeManager.InvalidConditionToken; int parachutingToken = ConditionManager.InvalidConditionToken;
public Parachutable(Actor self, ParachutableInfo info) public Parachutable(Actor self, ParachutableInfo info)
{ {
@@ -61,19 +61,19 @@ namespace OpenRA.Mods.Common.Traits
void INotifyCreated.Created(Actor self) void INotifyCreated.Created(Actor self)
{ {
um = self.TraitOrDefault<UpgradeManager>(); conditionManager = self.TraitOrDefault<ConditionManager>();
} }
void INotifyParachute.OnParachute(Actor self) void INotifyParachute.OnParachute(Actor self)
{ {
if (um != null && parachutingToken == UpgradeManager.InvalidConditionToken && !string.IsNullOrEmpty(info.ParachutingCondition)) if (conditionManager != null && parachutingToken == ConditionManager.InvalidConditionToken && !string.IsNullOrEmpty(info.ParachutingCondition))
parachutingToken = um.GrantCondition(self, info.ParachutingCondition); parachutingToken = conditionManager.GrantCondition(self, info.ParachutingCondition);
} }
void INotifyParachute.OnLanded(Actor self, Actor ignore) void INotifyParachute.OnLanded(Actor self, Actor ignore)
{ {
if (parachutingToken != UpgradeManager.InvalidConditionToken) if (parachutingToken != ConditionManager.InvalidConditionToken)
parachutingToken = um.RevokeCondition(self, parachutingToken); parachutingToken = conditionManager.RevokeCondition(self, parachutingToken);
if (!info.KilledOnImpassableTerrain) if (!info.KilledOnImpassableTerrain)
return; return;

View File

@@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Traits
static string MakeKey(string[] prerequisites) static string MakeKey(string[] prerequisites)
{ {
return "upgrade_" + string.Join("_", prerequisites.OrderBy(a => a)); return "condition_" + string.Join("_", prerequisites.OrderBy(a => a));
} }
public void Register(Actor actor, GrantConditionOnPrerequisite u, string[] prerequisites) public void Register(Actor actor, GrantConditionOnPrerequisite u, string[] prerequisites)

View File

@@ -16,7 +16,7 @@ namespace OpenRA.Mods.Common.Traits
public class PlugInfo : TraitInfo<Plug> public class PlugInfo : TraitInfo<Plug>
{ {
[FieldLoader.Require] [FieldLoader.Require]
[Desc("Plug type (matched against Upgrades in Pluggable)")] [Desc("Plug type (matched against Conditions in Pluggable)")]
public readonly string Type = null; public readonly string Type = null;
} }

View File

@@ -34,8 +34,8 @@ namespace OpenRA.Mods.Common.Traits
public readonly PluggableInfo Info; public readonly PluggableInfo Info;
readonly string initialPlug; readonly string initialPlug;
UpgradeManager upgradeManager; ConditionManager conditionManager;
int conditionToken = UpgradeManager.InvalidConditionToken; int conditionToken = ConditionManager.InvalidConditionToken;
string active; string active;
@@ -50,7 +50,7 @@ namespace OpenRA.Mods.Common.Traits
public void Created(Actor self) public void Created(Actor self)
{ {
upgradeManager = self.TraitOrDefault<UpgradeManager>(); conditionManager = self.TraitOrDefault<ConditionManager>();
if (!string.IsNullOrEmpty(initialPlug)) if (!string.IsNullOrEmpty(initialPlug))
EnablePlug(self, initialPlug); EnablePlug(self, initialPlug);
@@ -67,7 +67,7 @@ namespace OpenRA.Mods.Common.Traits
if (!Info.Conditions.TryGetValue(type, out condition)) if (!Info.Conditions.TryGetValue(type, out condition))
return; return;
conditionToken = upgradeManager.GrantCondition(self, condition); conditionToken = conditionManager.GrantCondition(self, condition);
active = type; active = type;
} }
@@ -76,8 +76,8 @@ namespace OpenRA.Mods.Common.Traits
if (type != active) if (type != active)
return; return;
if (conditionToken != UpgradeManager.InvalidConditionToken) if (conditionToken != ConditionManager.InvalidConditionToken)
conditionToken = upgradeManager.RevokeCondition(self, conditionToken); conditionToken = conditionManager.RevokeCondition(self, conditionToken);
active = null; active = null;
} }

View File

@@ -15,7 +15,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
[Desc("The player can disable the power individually on this actor.")] [Desc("The player can disable the power individually on this actor.")]
public class CanPowerDownInfo : UpgradableTraitInfo, Requires<PowerInfo> public class CanPowerDownInfo : ConditionalTraitInfo, Requires<PowerInfo>
{ {
[Desc("Restore power when this trait is disabled.")] [Desc("Restore power when this trait is disabled.")]
public readonly bool CancelWhenDisabled = false; public readonly bool CancelWhenDisabled = false;
@@ -34,7 +34,7 @@ namespace OpenRA.Mods.Common.Traits
public override object Create(ActorInitializer init) { return new CanPowerDown(init.Self, this); } public override object Create(ActorInitializer init) { return new CanPowerDown(init.Self, this); }
} }
public class CanPowerDown : UpgradableTrait<CanPowerDownInfo>, IPowerModifier, IResolveOrder, IDisable, INotifyOwnerChanged public class CanPowerDown : ConditionalTrait<CanPowerDownInfo>, IPowerModifier, IResolveOrder, IDisable, INotifyOwnerChanged
{ {
[Sync] bool disabled = false; [Sync] bool disabled = false;
PowerManager power; PowerManager power;

View File

@@ -15,7 +15,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
public class PowerInfo : UpgradableTraitInfo public class PowerInfo : ConditionalTraitInfo
{ {
[Desc("If negative, it will drain power. If positive, it will provide power.")] [Desc("If negative, it will drain power. If positive, it will provide power.")]
public readonly int Amount = 0; public readonly int Amount = 0;
@@ -23,7 +23,7 @@ namespace OpenRA.Mods.Common.Traits
public override object Create(ActorInitializer init) { return new Power(init.Self, this); } public override object Create(ActorInitializer init) { return new Power(init.Self, this); }
} }
public class Power : UpgradableTrait<PowerInfo>, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyOwnerChanged public class Power : ConditionalTrait<PowerInfo>, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyOwnerChanged
{ {
readonly Lazy<IPowerModifier[]> powerModifiers; readonly Lazy<IPowerModifier[]> powerModifiers;

View File

@@ -14,12 +14,12 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
[Desc("Needs power to operate.")] [Desc("Needs power to operate.")]
class RequiresPowerInfo : UpgradableTraitInfo, ITraitInfo class RequiresPowerInfo : ConditionalTraitInfo, ITraitInfo
{ {
public override object Create(ActorInitializer init) { return new RequiresPower(init.Self, this); } public override object Create(ActorInitializer init) { return new RequiresPower(init.Self, this); }
} }
class RequiresPower : UpgradableTrait<RequiresPowerInfo>, IDisable, INotifyOwnerChanged class RequiresPower : ConditionalTrait<RequiresPowerInfo>, IDisable, INotifyOwnerChanged
{ {
PowerManager playerPower; PowerManager playerPower;

View File

@@ -17,7 +17,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
[Desc("Derive facings from sprite body sequence.")] [Desc("Derive facings from sprite body sequence.")]
public class QuantizeFacingsFromSequenceInfo : UpgradableTraitInfo, IQuantizeBodyOrientationInfo, Requires<RenderSpritesInfo> public class QuantizeFacingsFromSequenceInfo : ConditionalTraitInfo, IQuantizeBodyOrientationInfo, Requires<RenderSpritesInfo>
{ {
[Desc("Defines sequence to derive facings from."), SequenceReference] [Desc("Defines sequence to derive facings from."), SequenceReference]
public readonly string Sequence = "idle"; public readonly string Sequence = "idle";
@@ -34,7 +34,7 @@ namespace OpenRA.Mods.Common.Traits
public override object Create(ActorInitializer init) { return new QuantizeFacingsFromSequence(this); } public override object Create(ActorInitializer init) { return new QuantizeFacingsFromSequence(this); }
} }
public class QuantizeFacingsFromSequence : UpgradableTrait<QuantizeFacingsFromSequenceInfo> public class QuantizeFacingsFromSequence : ConditionalTrait<QuantizeFacingsFromSequenceInfo>
{ {
public QuantizeFacingsFromSequence(QuantizeFacingsFromSequenceInfo info) public QuantizeFacingsFromSequence(QuantizeFacingsFromSequenceInfo info)
: base(info) { } : base(info) { }

View File

@@ -15,7 +15,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
[Desc("Can be used to make a unit partly uncontrollable by the player.")] [Desc("Can be used to make a unit partly uncontrollable by the player.")]
public class RejectsOrdersInfo : UpgradableTraitInfo public class RejectsOrdersInfo : ConditionalTraitInfo
{ {
[Desc("Possible values include Attack, AttackMove, Guard, Move.")] [Desc("Possible values include Attack, AttackMove, Guard, Move.")]
public readonly HashSet<string> Except = new HashSet<string>(); public readonly HashSet<string> Except = new HashSet<string>();
@@ -23,7 +23,7 @@ namespace OpenRA.Mods.Common.Traits
public override object Create(ActorInitializer init) { return new RejectsOrders(this); } public override object Create(ActorInitializer init) { return new RejectsOrders(this); }
} }
public class RejectsOrders : UpgradableTrait<RejectsOrdersInfo> public class RejectsOrders : ConditionalTrait<RejectsOrdersInfo>
{ {
public HashSet<string> Except { get { return Info.Except; } } public HashSet<string> Except { get { return Info.Except; } }

View File

@@ -18,7 +18,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render namespace OpenRA.Mods.Common.Traits.Render
{ {
[Desc("Changes the visual Z position periodically.")] [Desc("Changes the visual Z position periodically.")]
public class HoversInfo : UpgradableTraitInfo, Requires<IMoveInfo> public class HoversInfo : ConditionalTraitInfo, Requires<IMoveInfo>
{ {
[Desc("Amount of Z axis changes in world units.")] [Desc("Amount of Z axis changes in world units.")]
public readonly int OffsetModifier = -43; public readonly int OffsetModifier = -43;
@@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.Traits.Render
public override object Create(ActorInitializer init) { return new Hovers(this, init.Self); } public override object Create(ActorInitializer init) { return new Hovers(this, init.Self); }
} }
public class Hovers : UpgradableTrait<HoversInfo>, IRenderModifier public class Hovers : ConditionalTrait<HoversInfo>, IRenderModifier
{ {
readonly HoversInfo info; readonly HoversInfo info;

View File

@@ -18,7 +18,7 @@ namespace OpenRA.Mods.Common.Traits.Render
public enum TrailType { Cell, CenterPosition } public enum TrailType { Cell, CenterPosition }
[Desc("Renders a sprite effect when leaving a cell.")] [Desc("Renders a sprite effect when leaving a cell.")]
public class LeavesTrailsInfo : UpgradableTraitInfo public class LeavesTrailsInfo : ConditionalTraitInfo
{ {
public readonly string Image = null; public readonly string Image = null;
@@ -61,7 +61,7 @@ namespace OpenRA.Mods.Common.Traits.Render
public override object Create(ActorInitializer init) { return new LeavesTrails(init.Self, this); } public override object Create(ActorInitializer init) { return new LeavesTrails(init.Self, this); }
} }
public class LeavesTrails : UpgradableTrait<LeavesTrailsInfo>, ITick public class LeavesTrails : ConditionalTrait<LeavesTrailsInfo>, ITick
{ {
BodyOrientation body; BodyOrientation body;
IFacing facing; IFacing facing;

View File

@@ -14,8 +14,8 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render namespace OpenRA.Mods.Common.Traits.Render
{ {
[Desc("Visualizes the remaining time for an upgrade.")] [Desc("Visualizes the remaining time for a condition.")]
class TimedConditionBarInfo : ITraitInfo, Requires<UpgradeManagerInfo> class TimedConditionBarInfo : ITraitInfo, Requires<ConditionManagerInfo>
{ {
[FieldLoader.Require] [FieldLoader.Require]
[Desc("Condition that this bar corresponds to")] [Desc("Condition that this bar corresponds to")]

View File

@@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.Traits.Render
} }
[Desc("Displays a custom UI overlay relative to the selection box.")] [Desc("Displays a custom UI overlay relative to the selection box.")]
public class WithDecorationInfo : UpgradableTraitInfo public class WithDecorationInfo : ConditionalTraitInfo
{ {
[Desc("Image used for this decoration. Defaults to the actor's type.")] [Desc("Image used for this decoration. Defaults to the actor's type.")]
public readonly string Image = null; public readonly string Image = null;
@@ -55,7 +55,7 @@ namespace OpenRA.Mods.Common.Traits.Render
public override object Create(ActorInitializer init) { return new WithDecoration(init.Self, this); } public override object Create(ActorInitializer init) { return new WithDecoration(init.Self, this); }
} }
public class WithDecoration : UpgradableTrait<WithDecorationInfo>, ITick, IRenderAboveShroud, IRenderAboveShroudWhenSelected public class WithDecoration : ConditionalTrait<WithDecorationInfo>, ITick, IRenderAboveShroud, IRenderAboveShroudWhenSelected
{ {
protected readonly Animation Anim; protected readonly Animation Anim;

View File

@@ -14,20 +14,20 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render namespace OpenRA.Mods.Common.Traits.Render
{ {
[Desc("Periodically plays an idle animation, replacing the default body animation.")] [Desc("Periodically plays an idle animation, replacing the default body animation.")]
public class WithIdleAnimationInfo : UpgradableTraitInfo, Requires<WithSpriteBodyInfo> public class WithIdleAnimationInfo : ConditionalTraitInfo, Requires<WithSpriteBodyInfo>
{ {
[SequenceReference, Desc("Sequence names to use.")] [SequenceReference, Desc("Sequence names to use.")]
public readonly string[] Sequences = { "active" }; public readonly string[] Sequences = { "active" };
public readonly int Interval = 750; public readonly int Interval = 750;
[Desc("Pause when the actor is disabled. Deprecated. Use upgrades instead.")] [Desc("Pause when the actor is disabled. Deprecated. Use conditions instead.")]
public readonly bool PauseOnLowPower = false; public readonly bool PauseOnLowPower = false;
public override object Create(ActorInitializer init) { return new WithIdleAnimation(init.Self, this); } public override object Create(ActorInitializer init) { return new WithIdleAnimation(init.Self, this); }
} }
public class WithIdleAnimation : UpgradableTrait<WithIdleAnimationInfo>, ITick, INotifyBuildComplete, INotifySold public class WithIdleAnimation : ConditionalTrait<WithIdleAnimationInfo>, ITick, INotifyBuildComplete, INotifySold
{ {
readonly WithSpriteBody wsb; readonly WithSpriteBody wsb;
bool buildComplete; bool buildComplete;

View File

@@ -18,7 +18,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render namespace OpenRA.Mods.Common.Traits.Render
{ {
[Desc("Renders a decorative animation on units and buildings.")] [Desc("Renders a decorative animation on units and buildings.")]
public class WithIdleOverlayInfo : UpgradableTraitInfo, IRenderActorPreviewSpritesInfo, Requires<RenderSpritesInfo>, Requires<BodyOrientationInfo> public class WithIdleOverlayInfo : ConditionalTraitInfo, IRenderActorPreviewSpritesInfo, Requires<RenderSpritesInfo>, Requires<BodyOrientationInfo>
{ {
[Desc("Animation to play when the actor is created.")] [Desc("Animation to play when the actor is created.")]
[SequenceReference] public readonly string StartSequence = null; [SequenceReference] public readonly string StartSequence = null;
@@ -72,7 +72,7 @@ namespace OpenRA.Mods.Common.Traits.Render
} }
} }
public class WithIdleOverlay : UpgradableTrait<WithIdleOverlayInfo>, INotifyDamageStateChanged, INotifyBuildComplete, INotifySold, INotifyTransform public class WithIdleOverlay : ConditionalTrait<WithIdleOverlayInfo>, INotifyDamageStateChanged, INotifyBuildComplete, INotifySold, INotifyTransform
{ {
readonly Animation overlay; readonly Animation overlay;
bool buildComplete; bool buildComplete;

View File

@@ -18,7 +18,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render namespace OpenRA.Mods.Common.Traits.Render
{ {
public class WithInfantryBodyInfo : UpgradableTraitInfo, IRenderActorPreviewSpritesInfo, Requires<IMoveInfo>, Requires<RenderSpritesInfo> public class WithInfantryBodyInfo : ConditionalTraitInfo, IRenderActorPreviewSpritesInfo, Requires<IMoveInfo>, Requires<RenderSpritesInfo>
{ {
public readonly int MinIdleDelay = 30; public readonly int MinIdleDelay = 30;
public readonly int MaxIdleDelay = 110; public readonly int MaxIdleDelay = 110;
@@ -52,7 +52,7 @@ namespace OpenRA.Mods.Common.Traits.Render
} }
} }
public class WithInfantryBody : UpgradableTrait<WithInfantryBodyInfo>, ITick, INotifyAttack, INotifyIdle public class WithInfantryBody : ConditionalTrait<WithInfantryBodyInfo>, ITick, INotifyAttack, INotifyIdle
{ {
readonly IMove move; readonly IMove move;
protected readonly Animation DefaultAnimation; protected readonly Animation DefaultAnimation;

View File

@@ -18,7 +18,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render namespace OpenRA.Mods.Common.Traits.Render
{ {
[Desc("Renders the MuzzleSequence from the Armament trait.")] [Desc("Renders the MuzzleSequence from the Armament trait.")]
class WithMuzzleOverlayInfo : UpgradableTraitInfo, Requires<RenderSpritesInfo>, Requires<AttackBaseInfo>, Requires<ArmamentInfo> class WithMuzzleOverlayInfo : ConditionalTraitInfo, Requires<RenderSpritesInfo>, Requires<AttackBaseInfo>, Requires<ArmamentInfo>
{ {
[Desc("Ignore the weapon position, and always draw relative to the center of the actor")] [Desc("Ignore the weapon position, and always draw relative to the center of the actor")]
public readonly bool IgnoreOffset = false; public readonly bool IgnoreOffset = false;
@@ -26,7 +26,7 @@ namespace OpenRA.Mods.Common.Traits.Render
public override object Create(ActorInitializer init) { return new WithMuzzleOverlay(init.Self, this); } public override object Create(ActorInitializer init) { return new WithMuzzleOverlay(init.Self, this); }
} }
class WithMuzzleOverlay : UpgradableTrait<WithMuzzleOverlayInfo>, INotifyAttack, IRender, ITick class WithMuzzleOverlay : ConditionalTrait<WithMuzzleOverlayInfo>, INotifyAttack, IRender, ITick
{ {
readonly Dictionary<Barrel, bool> visible = new Dictionary<Barrel, bool>(); readonly Dictionary<Barrel, bool> visible = new Dictionary<Barrel, bool>();
readonly Dictionary<Barrel, AnimationWithOffset> anims = new Dictionary<Barrel, AnimationWithOffset>(); readonly Dictionary<Barrel, AnimationWithOffset> anims = new Dictionary<Barrel, AnimationWithOffset>();

View File

@@ -19,7 +19,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render namespace OpenRA.Mods.Common.Traits.Render
{ {
[Desc("Renders a parachute on units.")] [Desc("Renders a parachute on units.")]
public class WithParachuteInfo : UpgradableTraitInfo, IRenderActorPreviewSpritesInfo, Requires<RenderSpritesInfo>, Requires<BodyOrientationInfo> public class WithParachuteInfo : ConditionalTraitInfo, IRenderActorPreviewSpritesInfo, Requires<RenderSpritesInfo>, Requires<BodyOrientationInfo>
{ {
[Desc("The image that contains the parachute sequences.")] [Desc("The image that contains the parachute sequences.")]
public readonly string Image = null; public readonly string Image = null;
@@ -94,7 +94,7 @@ namespace OpenRA.Mods.Common.Traits.Render
} }
} }
public class WithParachute : UpgradableTrait<WithParachuteInfo>, ITick, IRender public class WithParachute : ConditionalTrait<WithParachuteInfo>, ITick, IRender
{ {
readonly Animation shadow; readonly Animation shadow;
readonly AnimationWithOffset anim; readonly AnimationWithOffset anim;

View File

@@ -17,7 +17,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render namespace OpenRA.Mods.Common.Traits.Render
{ {
[Desc("Clones the actor sprite with another palette below it.")] [Desc("Clones the actor sprite with another palette below it.")]
public class WithShadowInfo : UpgradableTraitInfo public class WithShadowInfo : ConditionalTraitInfo
{ {
[PaletteReference] public readonly string Palette = "shadow"; [PaletteReference] public readonly string Palette = "shadow";
@@ -30,7 +30,7 @@ namespace OpenRA.Mods.Common.Traits.Render
public override object Create(ActorInitializer init) { return new WithShadow(this); } public override object Create(ActorInitializer init) { return new WithShadow(this); }
} }
public class WithShadow : UpgradableTrait<WithShadowInfo>, IRenderModifier public class WithShadow : ConditionalTrait<WithShadowInfo>, IRenderModifier
{ {
readonly WithShadowInfo info; readonly WithShadowInfo info;

View File

@@ -19,7 +19,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render namespace OpenRA.Mods.Common.Traits.Render
{ {
[Desc("Renders barrels for units with the Turreted trait.")] [Desc("Renders barrels for units with the Turreted trait.")]
public class WithSpriteBarrelInfo : UpgradableTraitInfo, IRenderActorPreviewSpritesInfo, Requires<TurretedInfo>, public class WithSpriteBarrelInfo : ConditionalTraitInfo, IRenderActorPreviewSpritesInfo, Requires<TurretedInfo>,
Requires<ArmamentInfo>, Requires<RenderSpritesInfo>, Requires<BodyOrientationInfo> Requires<ArmamentInfo>, Requires<RenderSpritesInfo>, Requires<BodyOrientationInfo>
{ {
[Desc("Sequence name to use.")] [Desc("Sequence name to use.")]
@@ -61,7 +61,7 @@ namespace OpenRA.Mods.Common.Traits.Render
} }
} }
public class WithSpriteBarrel : UpgradableTrait<WithSpriteBarrelInfo> public class WithSpriteBarrel : ConditionalTrait<WithSpriteBarrelInfo>
{ {
public readonly Animation DefaultAnimation; public readonly Animation DefaultAnimation;
readonly RenderSprites rs; readonly RenderSprites rs;

View File

@@ -18,7 +18,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render namespace OpenRA.Mods.Common.Traits.Render
{ {
[Desc("Default trait for rendering sprite-based actors.")] [Desc("Default trait for rendering sprite-based actors.")]
public class WithSpriteBodyInfo : UpgradableTraitInfo, IRenderActorPreviewSpritesInfo, Requires<RenderSpritesInfo> public class WithSpriteBodyInfo : ConditionalTraitInfo, IRenderActorPreviewSpritesInfo, Requires<RenderSpritesInfo>
{ {
[Desc("Animation to play when the actor is created."), SequenceReference] [Desc("Animation to play when the actor is created."), SequenceReference]
public readonly string StartSequence = null; public readonly string StartSequence = null;
@@ -43,7 +43,7 @@ namespace OpenRA.Mods.Common.Traits.Render
} }
} }
public class WithSpriteBody : UpgradableTrait<WithSpriteBodyInfo>, INotifyDamageStateChanged, INotifyBuildComplete public class WithSpriteBody : ConditionalTrait<WithSpriteBodyInfo>, INotifyDamageStateChanged, INotifyBuildComplete
{ {
public readonly Animation DefaultAnimation; public readonly Animation DefaultAnimation;
@@ -80,7 +80,7 @@ namespace OpenRA.Mods.Common.Traits.Render
DefaultAnimation.PlayRepeating(NormalizeSequence(self, Info.Sequence)); DefaultAnimation.PlayRepeating(NormalizeSequence(self, Info.Sequence));
} }
// TODO: Get rid of INotifyBuildComplete in favor of using the upgrade system // TODO: Get rid of INotifyBuildComplete in favor of using the condition system
void INotifyBuildComplete.BuildingComplete(Actor self) void INotifyBuildComplete.BuildingComplete(Actor self)
{ {
OnBuildComplete(self); OnBuildComplete(self);

View File

@@ -19,7 +19,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render namespace OpenRA.Mods.Common.Traits.Render
{ {
[Desc("Renders turrets for units with the Turreted trait.")] [Desc("Renders turrets for units with the Turreted trait.")]
public class WithSpriteTurretInfo : UpgradableTraitInfo, IRenderActorPreviewSpritesInfo, public class WithSpriteTurretInfo : ConditionalTraitInfo, IRenderActorPreviewSpritesInfo,
Requires<RenderSpritesInfo>, Requires<TurretedInfo>, Requires<BodyOrientationInfo>, Requires<ArmamentInfo> Requires<RenderSpritesInfo>, Requires<TurretedInfo>, Requires<BodyOrientationInfo>, Requires<ArmamentInfo>
{ {
[Desc("Sequence name to use")] [Desc("Sequence name to use")]
@@ -62,7 +62,7 @@ namespace OpenRA.Mods.Common.Traits.Render
} }
} }
public class WithSpriteTurret : UpgradableTrait<WithSpriteTurretInfo>, INotifyBuildComplete, INotifySold, INotifyTransform, ITick, INotifyDamageStateChanged public class WithSpriteTurret : ConditionalTrait<WithSpriteTurretInfo>, INotifyBuildComplete, INotifySold, INotifyTransform, ITick, INotifyDamageStateChanged
{ {
public readonly Animation DefaultAnimation; public readonly Animation DefaultAnimation;
protected readonly AttackBase Attack; protected readonly AttackBase Attack;

View File

@@ -20,7 +20,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render namespace OpenRA.Mods.Common.Traits.Render
{ {
[Desc("Displays a text overlay relative to the selection box.")] [Desc("Displays a text overlay relative to the selection box.")]
public class WithTextDecorationInfo : UpgradableTraitInfo public class WithTextDecorationInfo : ConditionalTraitInfo
{ {
[FieldLoader.Require] [Translate] public readonly string Text = null; [FieldLoader.Require] [Translate] public readonly string Text = null;
@@ -56,7 +56,7 @@ namespace OpenRA.Mods.Common.Traits.Render
} }
} }
public class WithTextDecoration : UpgradableTrait<WithTextDecorationInfo>, IRender, IRenderAboveShroudWhenSelected, INotifyCapture public class WithTextDecoration : ConditionalTrait<WithTextDecorationInfo>, IRender, IRenderAboveShroudWhenSelected, INotifyCapture
{ {
readonly SpriteFont font; readonly SpriteFont font;
Color color; Color color;

View File

@@ -18,7 +18,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render namespace OpenRA.Mods.Common.Traits.Render
{ {
public class WithVoxelBarrelInfo : UpgradableTraitInfo, IRenderActorPreviewVoxelsInfo, Requires<RenderVoxelsInfo>, Requires<ArmamentInfo>, Requires<TurretedInfo> public class WithVoxelBarrelInfo : ConditionalTraitInfo, IRenderActorPreviewVoxelsInfo, Requires<RenderVoxelsInfo>, Requires<ArmamentInfo>, Requires<TurretedInfo>
{ {
[Desc("Voxel sequence name to use")] [Desc("Voxel sequence name to use")]
public readonly string Sequence = "barrel"; public readonly string Sequence = "barrel";
@@ -60,7 +60,7 @@ namespace OpenRA.Mods.Common.Traits.Render
} }
} }
public class WithVoxelBarrel : UpgradableTrait<WithVoxelBarrelInfo>, INotifyBuildComplete, INotifySold, INotifyTransform public class WithVoxelBarrel : ConditionalTrait<WithVoxelBarrelInfo>, INotifyBuildComplete, INotifySold, INotifyTransform
{ {
readonly Actor self; readonly Actor self;
readonly Armament armament; readonly Armament armament;

View File

@@ -19,7 +19,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render namespace OpenRA.Mods.Common.Traits.Render
{ {
[Desc("Also returns a default selection size that is calculated automatically from the voxel dimensions.")] [Desc("Also returns a default selection size that is calculated automatically from the voxel dimensions.")]
public class WithVoxelBodyInfo : UpgradableTraitInfo, IRenderActorPreviewVoxelsInfo, Requires<RenderVoxelsInfo> public class WithVoxelBodyInfo : ConditionalTraitInfo, IRenderActorPreviewVoxelsInfo, Requires<RenderVoxelsInfo>
{ {
public readonly string Sequence = "idle"; public readonly string Sequence = "idle";
@@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Traits.Render
} }
} }
public class WithVoxelBody : UpgradableTrait<WithVoxelBodyInfo>, IAutoSelectionSize public class WithVoxelBody : ConditionalTrait<WithVoxelBodyInfo>, IAutoSelectionSize
{ {
readonly int2 size; readonly int2 size;

View File

@@ -18,7 +18,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render namespace OpenRA.Mods.Common.Traits.Render
{ {
public class WithVoxelTurretInfo : UpgradableTraitInfo, IRenderActorPreviewVoxelsInfo, Requires<RenderVoxelsInfo>, Requires<TurretedInfo> public class WithVoxelTurretInfo : ConditionalTraitInfo, IRenderActorPreviewVoxelsInfo, Requires<RenderVoxelsInfo>, Requires<TurretedInfo>
{ {
[Desc("Voxel sequence name to use")] [Desc("Voxel sequence name to use")]
public readonly string Sequence = "turret"; public readonly string Sequence = "turret";
@@ -51,7 +51,7 @@ namespace OpenRA.Mods.Common.Traits.Render
} }
} }
public class WithVoxelTurret : UpgradableTrait<WithVoxelTurretInfo>, INotifyBuildComplete, INotifySold, INotifyTransform public class WithVoxelTurret : ConditionalTrait<WithVoxelTurretInfo>, INotifyBuildComplete, INotifySold, INotifyTransform
{ {
readonly Actor self; readonly Actor self;
readonly Turreted turreted; readonly Turreted turreted;

View File

@@ -16,7 +16,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
[Desc("Lets the actor spread resources around it in a circle.")] [Desc("Lets the actor spread resources around it in a circle.")]
class SeedsResourceInfo : UpgradableTraitInfo class SeedsResourceInfo : ConditionalTraitInfo
{ {
public readonly int Interval = 75; public readonly int Interval = 75;
public readonly string ResourceType = "Ore"; public readonly string ResourceType = "Ore";
@@ -25,7 +25,7 @@ namespace OpenRA.Mods.Common.Traits
public override object Create(ActorInitializer init) { return new SeedsResource(init.Self, this); } public override object Create(ActorInitializer init) { return new SeedsResource(init.Self, this); }
} }
class SeedsResource : UpgradableTrait<SeedsResourceInfo>, ITick, ISeedableResource class SeedsResource : ConditionalTrait<SeedsResourceInfo>, ITick, ISeedableResource
{ {
readonly SeedsResourceInfo info; readonly SeedsResourceInfo info;

View File

@@ -15,7 +15,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
[Desc("Attach this to actors which should be able to regenerate their health points.")] [Desc("Attach this to actors which should be able to regenerate their health points.")]
class SelfHealingInfo : UpgradableTraitInfo, Requires<HealthInfo> class SelfHealingInfo : ConditionalTraitInfo, Requires<HealthInfo>
{ {
[Desc("Absolute amount of health points added in each step.")] [Desc("Absolute amount of health points added in each step.")]
public readonly int Step = 5; public readonly int Step = 5;
@@ -37,7 +37,7 @@ namespace OpenRA.Mods.Common.Traits
public override object Create(ActorInitializer init) { return new SelfHealing(init.Self, this); } public override object Create(ActorInitializer init) { return new SelfHealing(init.Self, this); }
} }
class SelfHealing : UpgradableTrait<SelfHealingInfo>, ITick, INotifyDamage class SelfHealing : ConditionalTrait<SelfHealingInfo>, ITick, INotifyDamage
{ {
readonly Health health; readonly Health health;

View File

@@ -18,7 +18,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
[Desc("Actor can be sold")] [Desc("Actor can be sold")]
public class SellableInfo : UpgradableTraitInfo public class SellableInfo : ConditionalTraitInfo
{ {
public readonly int RefundPercent = 50; public readonly int RefundPercent = 50;
public readonly string[] SellSounds = { }; public readonly string[] SellSounds = { };
@@ -26,7 +26,7 @@ namespace OpenRA.Mods.Common.Traits
public override object Create(ActorInitializer init) { return new Sellable(init.Self, this); } public override object Create(ActorInitializer init) { return new Sellable(init.Self, this); }
} }
public class Sellable : UpgradableTrait<SellableInfo>, IResolveOrder, IProvideTooltipInfo public class Sellable : ConditionalTrait<SellableInfo>, IResolveOrder, IProvideTooltipInfo
{ {
readonly Actor self; readonly Actor self;
readonly Lazy<Health> health; readonly Lazy<Health> health;

View File

@@ -14,7 +14,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Sound namespace OpenRA.Mods.Common.Traits.Sound
{ {
[Desc("Plays a looping audio file at the actor position. Attach this to the `World` actor to cover the whole map.")] [Desc("Plays a looping audio file at the actor position. Attach this to the `World` actor to cover the whole map.")]
class AmbientSoundInfo : UpgradableTraitInfo class AmbientSoundInfo : ConditionalTraitInfo
{ {
[FieldLoader.Require] [FieldLoader.Require]
public readonly string SoundFile = null; public readonly string SoundFile = null;
@@ -25,7 +25,7 @@ namespace OpenRA.Mods.Common.Traits.Sound
public override object Create(ActorInitializer init) { return new AmbientSound(init.Self, this); } public override object Create(ActorInitializer init) { return new AmbientSound(init.Self, this); }
} }
class AmbientSound : UpgradableTrait<AmbientSoundInfo>, ITick class AmbientSound : ConditionalTrait<AmbientSoundInfo>, ITick
{ {
ISound currentSound; ISound currentSound;
bool wasDisabled = true; bool wasDisabled = true;

View File

@@ -15,7 +15,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Sound namespace OpenRA.Mods.Common.Traits.Sound
{ {
[Desc("Played when preparing for an attack or attacking.")] [Desc("Played when preparing for an attack or attacking.")]
public class AttackSoundsInfo : UpgradableTraitInfo public class AttackSoundsInfo : ConditionalTraitInfo
{ {
[Desc("Play a randomly selected sound from this list when preparing for an attack or attacking.")] [Desc("Play a randomly selected sound from this list when preparing for an attack or attacking.")]
public readonly string[] Sounds = { }; public readonly string[] Sounds = { };
@@ -29,7 +29,7 @@ namespace OpenRA.Mods.Common.Traits.Sound
public override object Create(ActorInitializer init) { return new AttackSounds(init, this); } public override object Create(ActorInitializer init) { return new AttackSounds(init, this); }
} }
public class AttackSounds : UpgradableTrait<AttackSoundsInfo>, INotifyAttack, ITick public class AttackSounds : ConditionalTrait<AttackSoundsInfo>, INotifyAttack, ITick
{ {
readonly AttackSoundsInfo info; readonly AttackSoundsInfo info;
int tick; int tick;

View File

@@ -25,7 +25,7 @@ namespace OpenRA.Mods.Common.Traits
[Desc("The condition to apply. Must be included in the target actor's ExternalConditions list.")] [Desc("The condition to apply. Must be included in the target actor's ExternalConditions list.")]
public readonly string Condition = null; public readonly string Condition = null;
[Desc("Duration of the upgrade (in ticks). Set to 0 for a permanent condition.")] [Desc("Duration of the condition (in ticks). Set to 0 for a permanent condition.")]
public readonly int Duration = 0; public readonly int Duration = 0;
[Desc("Cells - affects whole cells only")] [Desc("Cells - affects whole cells only")]
@@ -54,7 +54,7 @@ namespace OpenRA.Mods.Common.Traits
public override void SelectTarget(Actor self, string order, SupportPowerManager manager) public override void SelectTarget(Actor self, string order, SupportPowerManager manager)
{ {
Game.Sound.PlayToPlayer(SoundType.World, manager.Self.Owner, Info.SelectTargetSound); Game.Sound.PlayToPlayer(SoundType.World, manager.Self.Owner, Info.SelectTargetSound);
self.World.OrderGenerator = new SelectUpgradeTarget(Self.World, order, manager, this); self.World.OrderGenerator = new SelectConditionTarget(Self.World, order, manager, this);
} }
public override void Activate(Actor self, Order order, SupportPowerManager manager) public override void Activate(Actor self, Order order, SupportPowerManager manager)
@@ -69,11 +69,11 @@ namespace OpenRA.Mods.Common.Traits
foreach (var a in UnitsInRange(order.TargetLocation)) foreach (var a in UnitsInRange(order.TargetLocation))
{ {
var um = a.TraitOrDefault<UpgradeManager>(); var cm = a.TraitOrDefault<ConditionManager>();
// Condition token is ignored because we never revoke this condition. // Condition token is ignored because we never revoke this condition.
if (um != null) if (cm != null)
um.GrantCondition(a, info.Condition, true, info.Duration); cm.GrantCondition(a, info.Condition, true, info.Duration);
} }
} }
@@ -90,12 +90,12 @@ namespace OpenRA.Mods.Common.Traits
if (!a.Owner.IsAlliedWith(Self.Owner)) if (!a.Owner.IsAlliedWith(Self.Owner))
return false; return false;
var um = a.TraitOrDefault<UpgradeManager>(); var cm = a.TraitOrDefault<ConditionManager>();
return um != null && um.AcceptsExternalCondition(a, info.Condition); return cm != null && cm.AcceptsExternalCondition(a, info.Condition);
}); });
} }
class SelectUpgradeTarget : IOrderGenerator class SelectConditionTarget : IOrderGenerator
{ {
readonly GrantExternalConditionPower power; readonly GrantExternalConditionPower power;
readonly int range; readonly int range;
@@ -103,7 +103,7 @@ namespace OpenRA.Mods.Common.Traits
readonly SupportPowerManager manager; readonly SupportPowerManager manager;
readonly string order; readonly string order;
public SelectUpgradeTarget(World world, string order, SupportPowerManager manager, GrantExternalConditionPower power) public SelectConditionTarget(World world, string order, SupportPowerManager manager, GrantExternalConditionPower power)
{ {
// Clear selection if using Left-Click Orders // Clear selection if using Left-Click Orders
if (Game.Settings.Game.UseClassicMouseStyle) if (Game.Settings.Game.UseClassicMouseStyle)

View File

@@ -13,7 +13,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
public abstract class SupportPowerInfo : UpgradableTraitInfo public abstract class SupportPowerInfo : ConditionalTraitInfo
{ {
[Desc("Measured in seconds.")] [Desc("Measured in seconds.")]
public readonly int ChargeTime = 0; public readonly int ChargeTime = 0;
@@ -74,7 +74,7 @@ namespace OpenRA.Mods.Common.Traits
public SupportPowerInfo() { OrderName = GetType().Name + "Order"; } public SupportPowerInfo() { OrderName = GetType().Name + "Order"; }
} }
public class SupportPower : UpgradableTrait<SupportPowerInfo> public class SupportPower : ConditionalTrait<SupportPowerInfo>
{ {
public readonly Actor Self; public readonly Actor Self;
readonly SupportPowerInfo info; readonly SupportPowerInfo info;

View File

@@ -160,12 +160,12 @@ namespace OpenRA.Mods.Common.Traits
public int RemainingTime; public int RemainingTime;
public int TotalTime; public int TotalTime;
public bool Active { get; private set; } public bool Active { get; private set; }
public bool Disabled { get { return !prereqsAvailable || !upgradeAvailable; } } public bool Disabled { get { return !prereqsAvailable || !instancesEnabled; } }
public SupportPowerInfo Info { get { return Instances.Select(i => i.Info).FirstOrDefault(); } } public SupportPowerInfo Info { get { return Instances.Select(i => i.Info).FirstOrDefault(); } }
public bool Ready { get { return Active && RemainingTime == 0; } } public bool Ready { get { return Active && RemainingTime == 0; } }
bool upgradeAvailable; bool instancesEnabled;
bool prereqsAvailable = true; bool prereqsAvailable = true;
public SupportPowerInstance(string key, SupportPowerManager manager) public SupportPowerInstance(string key, SupportPowerManager manager)
@@ -188,8 +188,8 @@ namespace OpenRA.Mods.Common.Traits
bool notifiedReady; bool notifiedReady;
public void Tick() public void Tick()
{ {
upgradeAvailable = Instances.Any(i => !i.IsTraitDisabled); instancesEnabled = Instances.Any(i => !i.IsTraitDisabled);
if (!upgradeAvailable) if (!instancesEnabled)
RemainingTime = TotalTime; RemainingTime = TotalTime;
Active = !Disabled && Instances.Any(i => !i.Self.IsDisabled()); Active = !Disabled && Instances.Any(i => !i.Self.IsDisabled());

View File

@@ -16,7 +16,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
[Desc("Actor can be targeted.")] [Desc("Actor can be targeted.")]
public class TargetableInfo : UpgradableTraitInfo, ITargetableInfo public class TargetableInfo : ConditionalTraitInfo, ITargetableInfo
{ {
[Desc("Target type. Used for filtering (in)valid targets.")] [Desc("Target type. Used for filtering (in)valid targets.")]
public readonly HashSet<string> TargetTypes = new HashSet<string>(); public readonly HashSet<string> TargetTypes = new HashSet<string>();
@@ -27,7 +27,7 @@ namespace OpenRA.Mods.Common.Traits
public override object Create(ActorInitializer init) { return new Targetable(init.Self, this); } public override object Create(ActorInitializer init) { return new Targetable(init.Self, this); }
} }
public class Targetable : UpgradableTrait<TargetableInfo>, ITargetable public class Targetable : ConditionalTrait<TargetableInfo>, ITargetable
{ {
protected static readonly string[] None = new string[] { }; protected static readonly string[] None = new string[] { };
protected Cloak[] cloaks; protected Cloak[] cloaks;

View File

@@ -13,7 +13,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
public abstract class TooltipInfoBase : UpgradableTraitInfo public abstract class TooltipInfoBase : ConditionalTraitInfo
{ {
[Translate] public readonly string Name = ""; [Translate] public readonly string Name = "";
} }
@@ -59,7 +59,7 @@ namespace OpenRA.Mods.Common.Traits
public bool IsOwnerRowVisible { get { return ShowOwnerRow; } } public bool IsOwnerRowVisible { get { return ShowOwnerRow; } }
} }
public class Tooltip : UpgradableTrait<TooltipInfo>, ITooltip public class Tooltip : ConditionalTrait<TooltipInfo>, ITooltip
{ {
readonly Actor self; readonly Actor self;
readonly TooltipInfo info; readonly TooltipInfo info;

View File

@@ -15,7 +15,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
[Desc("Wanders around aimlessly while idle.")] [Desc("Wanders around aimlessly while idle.")]
public class WandersInfo : UpgradableTraitInfo, Requires<IMoveInfo> public class WandersInfo : ConditionalTraitInfo, Requires<IMoveInfo>
{ {
public readonly int WanderMoveRadius = 1; public readonly int WanderMoveRadius = 1;
@@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Traits
public override object Create(ActorInitializer init) { return new Wanders(init.Self, this); } public override object Create(ActorInitializer init) { return new Wanders(init.Self, this); }
} }
public class Wanders : UpgradableTrait<WandersInfo>, INotifyIdle, INotifyBecomingIdle public class Wanders : ConditionalTrait<WandersInfo>, INotifyIdle, INotifyBecomingIdle
{ {
readonly Actor self; readonly Actor self;
readonly WandersInfo info; readonly WandersInfo info;

View File

@@ -695,6 +695,15 @@ namespace OpenRA.Mods.Common.UtilityCommands
RenameNodeKey(node, "DisableOnCondition"); RenameNodeKey(node, "DisableOnCondition");
} }
if (engineVersion < 20161223)
{
if (node.Key.StartsWith("UpgradeManager", StringComparison.Ordinal))
RenameNodeKey(node, "ConditionManager");
if (node.Key.StartsWith("-UpgradeManager", StringComparison.Ordinal))
RenameNodeKey(node, "-ConditionManager");
}
UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1); UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
} }

View File

@@ -36,11 +36,11 @@ namespace OpenRA.Mods.Common.Warheads
if (!IsValidAgainst(a, firedBy)) if (!IsValidAgainst(a, firedBy))
continue; continue;
var um = a.TraitOrDefault<UpgradeManager>(); var cm = a.TraitOrDefault<ConditionManager>();
// Condition token is ignored because we never revoke this condition. // Condition token is ignored because we never revoke this condition.
if (um != null && um.AcceptsExternalCondition(a, Condition)) if (cm != null && cm.AcceptsExternalCondition(a, Condition))
um.GrantCondition(a, Condition, true, Duration); cm.GrantCondition(a, Condition, true, Duration);
} }
} }
} }

View File

@@ -125,7 +125,7 @@ namespace OpenRA.Mods.Common.Widgets
PerformKeyboardOrderOnSelection(a => new Order("DeployTransform", a, false)); PerformKeyboardOrderOnSelection(a => new Order("DeployTransform", a, false));
PerformKeyboardOrderOnSelection(a => new Order("Unload", a, false)); PerformKeyboardOrderOnSelection(a => new Order("Unload", a, false));
PerformKeyboardOrderOnSelection(a => new Order("Detonate", a, false)); PerformKeyboardOrderOnSelection(a => new Order("Detonate", a, false));
PerformKeyboardOrderOnSelection(a => new Order("DeployToUpgrade", a, false)); PerformKeyboardOrderOnSelection(a => new Order("GrantConditionOnDeploy", a, false));
return true; return true;
} }

View File

@@ -28,7 +28,7 @@ namespace OpenRA.Mods.D2k.Activities
readonly Target target; readonly Target target;
readonly Sandworm sandworm; readonly Sandworm sandworm;
readonly UpgradeManager manager; readonly ConditionManager conditionManager;
readonly WeaponInfo weapon; readonly WeaponInfo weapon;
readonly RadarPings radarPings; readonly RadarPings radarPings;
readonly AttackSwallow swallow; readonly AttackSwallow swallow;
@@ -37,7 +37,7 @@ namespace OpenRA.Mods.D2k.Activities
int countdown; int countdown;
CPos burrowLocation; CPos burrowLocation;
AttackState stance; AttackState stance;
int attackingToken = UpgradeManager.InvalidConditionToken; int attackingToken = ConditionManager.InvalidConditionToken;
public SwallowActor(Actor self, Target target, WeaponInfo weapon) public SwallowActor(Actor self, Target target, WeaponInfo weapon)
{ {
@@ -46,7 +46,7 @@ namespace OpenRA.Mods.D2k.Activities
sandworm = self.Trait<Sandworm>(); sandworm = self.Trait<Sandworm>();
positionable = self.Trait<Mobile>(); positionable = self.Trait<Mobile>();
swallow = self.Trait<AttackSwallow>(); swallow = self.Trait<AttackSwallow>();
manager = self.TraitOrDefault<UpgradeManager>(); conditionManager = self.TraitOrDefault<ConditionManager>();
radarPings = self.World.WorldActor.TraitOrDefault<RadarPings>(); radarPings = self.World.WorldActor.TraitOrDefault<RadarPings>();
} }
@@ -109,9 +109,9 @@ namespace OpenRA.Mods.D2k.Activities
stance = AttackState.Burrowed; stance = AttackState.Burrowed;
countdown = swallow.Info.AttackDelay; countdown = swallow.Info.AttackDelay;
burrowLocation = self.Location; burrowLocation = self.Location;
if (manager != null && attackingToken == UpgradeManager.InvalidConditionToken && if (conditionManager != null && attackingToken == ConditionManager.InvalidConditionToken &&
!string.IsNullOrEmpty(swallow.Info.AttackingCondition)) !string.IsNullOrEmpty(swallow.Info.AttackingCondition))
attackingToken = manager.GrantCondition(self, swallow.Info.AttackingCondition); attackingToken = conditionManager.GrantCondition(self, swallow.Info.AttackingCondition);
break; break;
case AttackState.Burrowed: case AttackState.Burrowed:
if (--countdown > 0) if (--countdown > 0)
@@ -170,8 +170,8 @@ namespace OpenRA.Mods.D2k.Activities
void RevokeCondition(Actor self) void RevokeCondition(Actor self)
{ {
if (attackingToken != UpgradeManager.InvalidConditionToken) if (attackingToken != ConditionManager.InvalidConditionToken)
attackingToken = manager.RevokeCondition(self, attackingToken); attackingToken = conditionManager.RevokeCondition(self, attackingToken);
} }
} }
} }

View File

@@ -14,7 +14,7 @@ using OpenRA.Mods.Common.Traits;
namespace OpenRA.Mods.D2k.Traits namespace OpenRA.Mods.D2k.Traits
{ {
[Desc("This actor makes noise, which causes them to be targeted by actors with the Sandworm trait.")] [Desc("This actor makes noise, which causes them to be targeted by actors with the Sandworm trait.")]
public class AttractsWormsInfo : UpgradableTraitInfo public class AttractsWormsInfo : ConditionalTraitInfo
{ {
[Desc("How much noise this actor produces.")] [Desc("How much noise this actor produces.")]
public readonly int Intensity = 0; public readonly int Intensity = 0;
@@ -31,7 +31,7 @@ namespace OpenRA.Mods.D2k.Traits
public override object Create(ActorInitializer init) { return new AttractsWorms(init, this); } public override object Create(ActorInitializer init) { return new AttractsWorms(init, this); }
} }
public class AttractsWorms : UpgradableTrait<AttractsWormsInfo> public class AttractsWorms : ConditionalTrait<AttractsWormsInfo>
{ {
readonly Actor self; readonly Actor self;

View File

@@ -83,8 +83,8 @@ namespace OpenRA.Mods.RA.Traits
readonly Actor self; readonly Actor self;
readonly DisguiseInfo info; readonly DisguiseInfo info;
UpgradeManager um; ConditionManager conditionManager;
int disguisedToken = UpgradeManager.InvalidConditionToken; int disguisedToken = ConditionManager.InvalidConditionToken;
public Disguise(Actor self, DisguiseInfo info) public Disguise(Actor self, DisguiseInfo info)
{ {
@@ -94,7 +94,7 @@ namespace OpenRA.Mods.RA.Traits
void INotifyCreated.Created(Actor self) void INotifyCreated.Created(Actor self)
{ {
um = self.TraitOrDefault<UpgradeManager>(); conditionManager = self.TraitOrDefault<ConditionManager>();
} }
public IEnumerable<IOrderTargeter> Orders public IEnumerable<IOrderTargeter> Orders
@@ -187,12 +187,12 @@ namespace OpenRA.Mods.RA.Traits
foreach (var t in self.TraitsImplementing<INotifyEffectiveOwnerChanged>()) foreach (var t in self.TraitsImplementing<INotifyEffectiveOwnerChanged>())
t.OnEffectiveOwnerChanged(self, oldEffectiveOwner, AsPlayer); t.OnEffectiveOwnerChanged(self, oldEffectiveOwner, AsPlayer);
if (Disguised != oldDisguiseSetting && um != null) if (Disguised != oldDisguiseSetting && conditionManager != null)
{ {
if (Disguised && disguisedToken == UpgradeManager.InvalidConditionToken && !string.IsNullOrEmpty(info.DisguisedCondition)) if (Disguised && disguisedToken == ConditionManager.InvalidConditionToken && !string.IsNullOrEmpty(info.DisguisedCondition))
disguisedToken = um.GrantCondition(self, info.DisguisedCondition); disguisedToken = conditionManager.GrantCondition(self, info.DisguisedCondition);
else if (!Disguised && disguisedToken != UpgradeManager.InvalidConditionToken) else if (!Disguised && disguisedToken != ConditionManager.InvalidConditionToken)
disguisedToken = um.RevokeCondition(self, disguisedToken); disguisedToken = conditionManager.RevokeCondition(self, disguisedToken);
} }
} }

View File

@@ -5,7 +5,7 @@
GivesExperience: GivesExperience:
PlayerExperienceModifier: 1 PlayerExperienceModifier: 1
ScriptTriggers: ScriptTriggers:
UpgradeManager: ConditionManager:
RenderDebugState: RenderDebugState:
^SpriteActor: ^SpriteActor:
@@ -605,7 +605,7 @@
^CivBuilding: ^CivBuilding:
Inherits: ^Building Inherits: ^Building
-UpgradeManager: -ConditionManager:
Health: Health:
HP: 400 HP: 400
Tooltip: Tooltip:

View File

@@ -106,7 +106,7 @@ sandworm:
TerrainTypes: Sand, Dune, SpiceSand, Spice TerrainTypes: Sand, Dune, SpiceSand, Spice
MovingInterval: 3 MovingInterval: 3
RequiresCondition: !attacking RequiresCondition: !attacking
UpgradeManager: ConditionManager:
Buildable: Buildable:
Description: Attracted by vibrations in the sand.\nWill eat units whole and has a large appetite. Description: Attracted by vibrations in the sand.\nWill eat units whole and has a large appetite.

View File

@@ -5,7 +5,7 @@
GivesExperience: GivesExperience:
PlayerExperienceModifier: 1 PlayerExperienceModifier: 1
ScriptTriggers: ScriptTriggers:
UpgradeManager: ConditionManager:
RenderDebugState: RenderDebugState:
^SpriteActor: ^SpriteActor:

View File

@@ -4,7 +4,7 @@
GivesExperience: GivesExperience:
PlayerExperienceModifier: 1 PlayerExperienceModifier: 1
ScriptTriggers: ScriptTriggers:
UpgradeManager: ConditionManager:
RenderDebugState: RenderDebugState:
^SpriteActor: ^SpriteActor:
@@ -894,7 +894,7 @@
ShadowImage: parach-shadow ShadowImage: parach-shadow
ShadowSequence: idle ShadowSequence: idle
RequiresCondition: parachute RequiresCondition: parachute
UpgradeManager: ConditionManager:
^Mine: ^Mine:
Inherits: ^SpriteActor Inherits: ^SpriteActor

View File

@@ -5,7 +5,7 @@
GivesExperience: GivesExperience:
PlayerExperienceModifier: 1 PlayerExperienceModifier: 1
ScriptTriggers: ScriptTriggers:
UpgradeManager: ConditionManager:
RenderDebugState: RenderDebugState:
^SpriteActor: ^SpriteActor:
@@ -246,7 +246,7 @@
SellSounds: cashturn.aud SellSounds: cashturn.aud
Demolishable: Demolishable:
ScriptTriggers: ScriptTriggers:
UpgradeManager: ConditionManager:
Health: Health:
Shape: Rectangle Shape: Rectangle
RotateToIsometry: true RotateToIsometry: true