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())
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)
emitError("Actor type `{0}` defines conditions but does not include an UpgradeManager".F(actorInfo.Key));
if ((consumed.Any() || granted.Any()) && actorInfo.Value.TraitInfoOrDefault<ConditionManagerInfo>() == null)
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\Turreted.cs" />
<Compile Include="Traits\ProducibleWithLevel.cs" />
<Compile Include="Traits\Upgrades\GrantConditionOnDeploy.cs" />
<Compile Include="Traits\Upgrades\DisableOnCondition.cs" />
<Compile Include="Traits\Upgrades\UpgradableTrait.cs" />
<Compile Include="Traits\Upgrades\ProximityExternalCondition.cs" />
<Compile Include="Traits\Upgrades\GrantConditionOnDamageState.cs" />
<Compile Include="Traits\Upgrades\GrantConditionOnTerrain.cs" />
<Compile Include="Traits\Upgrades\GrantConditionOnMovement.cs" />
<Compile Include="Traits\Upgrades\UpgradeManager.cs" />
<Compile Include="Traits\Conditions\GrantConditionOnDeploy.cs" />
<Compile Include="Traits\Conditions\DisableOnCondition.cs" />
<Compile Include="Traits\Conditions\ConditionalTrait.cs" />
<Compile Include="Traits\Conditions\ProximityExternalCondition.cs" />
<Compile Include="Traits\Conditions\GrantConditionOnDamageState.cs" />
<Compile Include="Traits\Conditions\GrantConditionOnTerrain.cs" />
<Compile Include="Traits\Conditions\GrantConditionOnMovement.cs" />
<Compile Include="Traits\Conditions\ConditionManager.cs" />
<Compile Include="Traits\Valued.cs" />
<Compile Include="Traits\Voiced.cs" />
<Compile Include="Traits\Wanders.cs" />
@@ -772,9 +772,9 @@
<Compile Include="Traits\AutoCarryable.cs" />
<Compile Include="Traits\AutoCarryall.cs" />
<Compile Include="Traits\World\CliffBackImpassabilityLayer.cs" />
<Compile Include="Traits\Upgrades\GrantCondition.cs" />
<Compile Include="Traits\Upgrades\ExternalConditions.cs" />
<Compile Include="Traits\Upgrades\StackedCondition.cs" />
<Compile Include="Traits\Conditions\GrantCondition.cs" />
<Compile Include="Traits\Conditions\ExternalConditions.cs" />
<Compile Include="Traits\Conditions\StackedCondition.cs" />
<Compile Include="Traits\Buildings\BridgeHut.cs" />
<Compile Include="Traits\Buildings\BridgePlaceholder.cs" />
<Compile Include="Traits\Buildings\GroundLevelBridge.cs" />

View File

@@ -20,15 +20,15 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Scripting
{
[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>>();
public ConditionProperties(ScriptContext context, Actor 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.",
@@ -36,22 +36,22 @@ namespace OpenRA.Mods.Common.Scripting
"If duration > 0 the condition will be automatically revoked after the defined number of ticks")]
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));
return um.GrantCondition(Self, condition, true, duration);
return conditionManager.GrantCondition(Self, condition, true, duration);
}
[Desc("Revoke a condition using the token returned by GrantCondition.")]
public void RevokeCondition(int token)
{
um.RevokeCondition(Self, token);
conditionManager.RevokeCondition(Self, token);
}
[Desc("Check whether this actor accepts a specific external 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.")]

View File

@@ -14,7 +14,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
public abstract class AffectsShroudInfo : UpgradableTraitInfo
public abstract class AffectsShroudInfo : ConditionalTraitInfo
{
public readonly WDist Range = WDist.Zero;
@@ -26,7 +26,7 @@ namespace OpenRA.Mods.Common.Traits
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 = { };

View File

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

View File

@@ -12,14 +12,14 @@
namespace OpenRA.Mods.Common.Traits
{
[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 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)
: base(info) { }

View File

@@ -19,7 +19,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
public abstract class AttackBaseInfo : UpgradableTraitInfo
public abstract class AttackBaseInfo : ConditionalTraitInfo
{
[Desc("Armament names")]
public readonly string[] Armaments = { "primary", "secondary" };
@@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Traits
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 forceAttackOrderName = "ForceAttack";

View File

@@ -17,7 +17,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[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.")]
public readonly bool AllowMovement = true;
@@ -50,7 +50,7 @@ namespace OpenRA.Mods.Common.Traits
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 AttackFollow[] attackFollows;

View File

@@ -21,14 +21,14 @@ namespace OpenRA.Mods.Common.Traits
}
[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 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)
: base(info) { }

View File

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

View File

@@ -18,7 +18,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[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 RepairInterval = 24;
@@ -41,7 +41,7 @@ namespace OpenRA.Mods.Common.Traits
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]
public int RepairersHash

View File

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

View File

@@ -15,7 +15,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Can be carried by actors with the `Carryall` trait.")]
public class CarryableInfo : UpgradableTraitInfo
public class CarryableInfo : ConditionalTraitInfo
{
[GrantedConditionReference]
[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 class Carryable : UpgradableTrait<CarryableInfo>
public class Carryable : ConditionalTrait<CarryableInfo>
{
UpgradeManager upgradeManager;
int reservedToken = UpgradeManager.InvalidConditionToken;
int carriedToken = UpgradeManager.InvalidConditionToken;
ConditionManager conditionManager;
int reservedToken = ConditionManager.InvalidConditionToken;
int carriedToken = ConditionManager.InvalidConditionToken;
public Actor Carrier { get; private set; }
public bool Reserved { get { return state != State.Free; } }
@@ -51,7 +51,7 @@ namespace OpenRA.Mods.Common.Traits
protected override void Created(Actor self)
{
upgradeManager = self.Trait<UpgradeManager>();
conditionManager = self.Trait<ConditionManager>();
base.Created(self);
}
@@ -63,8 +63,8 @@ namespace OpenRA.Mods.Common.Traits
attached = true;
if (carriedToken == UpgradeManager.InvalidConditionToken && !string.IsNullOrEmpty(Info.CarriedCondition))
carriedToken = upgradeManager.GrantCondition(self, Info.CarriedCondition);
if (carriedToken == ConditionManager.InvalidConditionToken && !string.IsNullOrEmpty(Info.CarriedCondition))
carriedToken = conditionManager.GrantCondition(self, Info.CarriedCondition);
}
// This gets called by carrier after we touched down
@@ -75,8 +75,8 @@ namespace OpenRA.Mods.Common.Traits
attached = false;
if (carriedToken != UpgradeManager.InvalidConditionToken)
carriedToken = upgradeManager.RevokeCondition(self, carriedToken);
if (carriedToken != ConditionManager.InvalidConditionToken)
carriedToken = conditionManager.RevokeCondition(self, carriedToken);
}
public virtual bool Reserve(Actor self, Actor carrier)
@@ -87,8 +87,8 @@ namespace OpenRA.Mods.Common.Traits
state = State.Reserved;
Carrier = carrier;
if (reservedToken == UpgradeManager.InvalidConditionToken && !string.IsNullOrEmpty(Info.ReservedCondition))
reservedToken = upgradeManager.GrantCondition(self, Info.ReservedCondition);
if (reservedToken == ConditionManager.InvalidConditionToken && !string.IsNullOrEmpty(Info.ReservedCondition))
reservedToken = conditionManager.GrantCondition(self, Info.ReservedCondition);
return true;
}
@@ -98,8 +98,8 @@ namespace OpenRA.Mods.Common.Traits
state = State.Free;
Carrier = null;
if (reservedToken != UpgradeManager.InvalidConditionToken)
reservedToken = upgradeManager.RevokeCondition(self, reservedToken);
if (reservedToken != ConditionManager.InvalidConditionToken)
reservedToken = conditionManager.RevokeCondition(self, reservedToken);
}
// 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.")]
public class CloakInfo : UpgradableTraitInfo
public class CloakInfo : ConditionalTraitInfo
{
[Desc("Measured in game ticks.")]
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 class Cloak : UpgradableTrait<CloakInfo>, IRenderModifier, INotifyDamage,
public class Cloak : ConditionalTrait<CloakInfo>, IRenderModifier, INotifyDamage,
INotifyAttack, ITick, IVisibilityModifier, IRadarColorModifier, INotifyCreated, INotifyHarvesterAction
{
[Sync] int remainingTime;
[Sync] bool damageDisabled;
bool isDocking;
UpgradeManager upgradeManager;
ConditionManager conditionManager;
CPos? lastPos;
bool wasCloaked = false;
int cloakedToken = UpgradeManager.InvalidConditionToken;
int cloakedToken = ConditionManager.InvalidConditionToken;
public Cloak(CloakInfo info)
: base(info)
@@ -80,13 +80,13 @@ namespace OpenRA.Mods.Common.Traits
void INotifyCreated.Created(Actor self)
{
upgradeManager = self.TraitOrDefault<UpgradeManager>();
conditionManager = self.TraitOrDefault<ConditionManager>();
if (Cloaked)
{
wasCloaked = true;
if (upgradeManager != null && cloakedToken == UpgradeManager.InvalidConditionToken && !string.IsNullOrEmpty(Info.CloakedCondition))
cloakedToken = upgradeManager.GrantCondition(self, Info.CloakedCondition);
if (conditionManager != null && cloakedToken == ConditionManager.InvalidConditionToken && !string.IsNullOrEmpty(Info.CloakedCondition))
cloakedToken = conditionManager.GrantCondition(self, Info.CloakedCondition);
}
}
@@ -144,16 +144,16 @@ namespace OpenRA.Mods.Common.Traits
var isCloaked = Cloaked;
if (isCloaked && !wasCloaked)
{
if (upgradeManager != null && cloakedToken == UpgradeManager.InvalidConditionToken && !string.IsNullOrEmpty(Info.CloakedCondition))
cloakedToken = upgradeManager.GrantCondition(self, Info.CloakedCondition);
if (conditionManager != null && cloakedToken == ConditionManager.InvalidConditionToken && !string.IsNullOrEmpty(Info.CloakedCondition))
cloakedToken = conditionManager.GrantCondition(self, Info.CloakedCondition);
if (!self.TraitsImplementing<Cloak>().Any(a => a != this && a.Cloaked))
Game.Sound.Play(SoundType.World, Info.CloakSound, self.CenterPosition);
}
else if (!isCloaked && wasCloaked)
{
if (cloakedToken != UpgradeManager.InvalidConditionToken)
cloakedToken = upgradeManager.RevokeCondition(self, cloakedToken);
if (cloakedToken != ConditionManager.InvalidConditionToken)
cloakedToken = conditionManager.RevokeCondition(self, cloakedToken);
if (!self.TraitsImplementing<Cloak>().Any(a => a != this && a.Cloaked))
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);
}
[Desc("Attach this to a unit to enable dynamic upgrades by warheads, experience, crates, support powers, etc.")]
public class UpgradeManagerInfo : TraitInfo<UpgradeManager>, Requires<IConditionConsumerInfo> { }
[Desc("Attach this to a unit to enable dynamic conditions by warheads, experience, crates, support powers, etc.")]
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>
public static readonly int InvalidConditionToken = -1;
@@ -74,9 +74,6 @@ namespace OpenRA.Mods.Common.Traits
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>
readonly Dictionary<string, bool> conditionCache = new Dictionary<string, bool>();
@@ -267,53 +264,5 @@ namespace OpenRA.Mods.Common.Traits
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
{
/// <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>());
@@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.Traits
public abstract object Create(ActorInitializer init);
// 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
public bool EnabledByDefault { get; private set; }
@@ -39,11 +39,11 @@ namespace OpenRA.Mods.Common.Traits
}
/// <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.
/// 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>
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;
@@ -60,11 +60,11 @@ namespace OpenRA.Mods.Common.Traits
[Sync] public bool IsTraitDisabled { get; private set; }
public UpgradableTrait(InfoType info)
public ConditionalTrait(InfoType 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.
IsTraitDisabled = Info.RequiresCondition != null;
}

View File

@@ -13,13 +13,13 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Disable the actor when this trait is enabled by an upgrade.")]
public class DisableOnConditionInfo : UpgradableTraitInfo
[Desc("Disable the actor when this trait is enabled by a condition.")]
public class DisableOnConditionInfo : ConditionalTraitInfo
{
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)
: base(info) { }

View File

@@ -14,7 +14,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Grants a condition while the trait is active.")]
class GrantConditionInfo : UpgradableTraitInfo
class GrantConditionInfo : ConditionalTraitInfo
{
[FieldLoader.Require]
[GrantedConditionReference]
@@ -24,33 +24,33 @@ namespace OpenRA.Mods.Common.Traits
public override object Create(ActorInitializer init) { return new GrantCondition(this); }
}
class GrantCondition : UpgradableTrait<GrantConditionInfo>
class GrantCondition : ConditionalTrait<GrantConditionInfo>
{
UpgradeManager manager;
int conditionToken = UpgradeManager.InvalidConditionToken;
ConditionManager conditionManager;
int conditionToken = ConditionManager.InvalidConditionToken;
public GrantCondition(GrantConditionInfo info)
: base(info) { }
protected override void Created(Actor self)
{
manager = self.Trait<UpgradeManager>();
conditionManager = self.Trait<ConditionManager>();
base.Created(self);
}
protected override void TraitEnabled(Actor self)
{
if (conditionToken == UpgradeManager.InvalidConditionToken)
conditionToken = manager.GrantCondition(self, Info.Condition);
if (conditionToken == ConditionManager.InvalidConditionToken)
conditionToken = conditionManager.GrantCondition(self, Info.Condition);
}
protected override void TraitDisabled(Actor self)
{
if (conditionToken == UpgradeManager.InvalidConditionToken)
if (conditionToken == ConditionManager.InvalidConditionToken)
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
{
[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>
{
[FieldLoader.Require]
@@ -27,7 +27,7 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Play a random sound from this list when disabled.")]
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;
[Desc("Is the condition irrevocable once it has been activated?")]
@@ -41,8 +41,8 @@ namespace OpenRA.Mods.Common.Traits
readonly GrantConditionOnDamageStateInfo info;
readonly Health health;
UpgradeManager manager;
int conditionToken = UpgradeManager.InvalidConditionToken;
ConditionManager conditionManager;
int conditionToken = ConditionManager.InvalidConditionToken;
public GrantConditionOnDamageState(Actor self, GrantConditionOnDamageStateInfo info)
{
@@ -52,16 +52,16 @@ namespace OpenRA.Mods.Common.Traits
void INotifyCreated.Created(Actor self)
{
manager = self.TraitOrDefault<UpgradeManager>();
GrantUpgradeOnValidDamageState(self, health.DamageState);
conditionManager = self.TraitOrDefault<ConditionManager>();
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;
conditionToken = manager.GrantCondition(self, info.Condition);
conditionToken = conditionManager.GrantCondition(self, info.Condition);
var sound = info.EnabledSounds.RandomOrDefault(Game.CosmeticRandom);
Game.Sound.Play(SoundType.World, sound, self.CenterPosition);
@@ -69,15 +69,15 @@ namespace OpenRA.Mods.Common.Traits
void INotifyDamageStateChanged.DamageStateChanged(Actor self, AttackInfo e)
{
var granted = conditionToken != UpgradeManager.InvalidConditionToken;
if ((granted && info.GrantPermanently) || manager == null)
var granted = conditionToken != ConditionManager.InvalidConditionToken;
if ((granted && info.GrantPermanently) || conditionManager == null)
return;
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))
{
conditionToken = manager.RevokeCondition(self, conditionToken);
conditionToken = conditionManager.RevokeCondition(self, conditionToken);
var sound = info.DisabledSounds.RandomOrDefault(Game.CosmeticRandom);
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.")]
public readonly string DeployedCondition = null;
[Desc("The terrain types that this actor can deploy on to receive these upgrades. " +
"Leave empty to allow any.")]
[Desc("The terrain types that this actor can deploy on. Leave empty to allow any.")]
public readonly HashSet<string> AllowedTerrainTypes = new HashSet<string>();
[Desc("Can this actor deploy on slopes?")]
@@ -72,9 +71,9 @@ namespace OpenRA.Mods.Common.Traits
readonly Lazy<WithSpriteBody> body;
DeployState deployState;
UpgradeManager manager;
int deployedToken = UpgradeManager.InvalidConditionToken;
int undeployedToken = UpgradeManager.InvalidConditionToken;
ConditionManager conditionManager;
int deployedToken = ConditionManager.InvalidConditionToken;
int undeployedToken = ConditionManager.InvalidConditionToken;
public GrantConditionOnDeploy(ActorInitializer init, GrantConditionOnDeployInfo info)
{
@@ -89,7 +88,7 @@ namespace OpenRA.Mods.Common.Traits
public void Created(Actor self)
{
manager = self.TraitOrDefault<UpgradeManager>();
conditionManager = self.TraitOrDefault<ConditionManager>();
switch (deployState)
{
@@ -119,13 +118,13 @@ namespace OpenRA.Mods.Common.Traits
public IEnumerable<IOrderTargeter> Orders
{
get { yield return new DeployOrderTargeter("DeployToUpgrade", 5,
get { yield return new DeployOrderTargeter("GrantConditionOnDeploy", 5,
() => IsCursorBlocked() ? info.DeployBlockedCursor : info.DeployCursor); }
}
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 null;
@@ -133,7 +132,7 @@ namespace OpenRA.Mods.Common.Traits
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;
if (!order.Queued)
@@ -207,19 +206,19 @@ namespace OpenRA.Mods.Common.Traits
if (!string.IsNullOrEmpty(info.DeploySound))
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)
OnDeployStarted();
// If there is no animation to play just grant the upgrades that are used while deployed.
// Alternatively, play the deploy animation and then grant the upgrades.
// 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 condition.
if (string.IsNullOrEmpty(info.DeployAnimation) || body.Value == null)
OnDeployCompleted();
else
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(bool init)
{
@@ -233,8 +232,8 @@ namespace OpenRA.Mods.Common.Traits
if (!init)
OnUndeployStarted();
// If there is no animation to play just grant the upgrades that are used while undeployed.
// Alternatively, play the undeploy animation and then grant the upgrades.
// 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 condition.
if (string.IsNullOrEmpty(info.DeployAnimation) || body.Value == null)
OnUndeployCompleted();
else
@@ -243,32 +242,32 @@ namespace OpenRA.Mods.Common.Traits
void OnDeployStarted()
{
if (undeployedToken != UpgradeManager.InvalidConditionToken)
undeployedToken = manager.RevokeCondition(self, undeployedToken);
if (undeployedToken != ConditionManager.InvalidConditionToken)
undeployedToken = conditionManager.RevokeCondition(self, undeployedToken);
deployState = DeployState.Deploying;
}
void OnDeployCompleted()
{
if (manager != null && !string.IsNullOrEmpty(info.DeployedCondition) && deployedToken == UpgradeManager.InvalidConditionToken)
deployedToken = manager.GrantCondition(self, info.DeployedCondition);
if (conditionManager != null && !string.IsNullOrEmpty(info.DeployedCondition) && deployedToken == ConditionManager.InvalidConditionToken)
deployedToken = conditionManager.GrantCondition(self, info.DeployedCondition);
deployState = DeployState.Deployed;
}
void OnUndeployStarted()
{
if (deployedToken != UpgradeManager.InvalidConditionToken)
deployedToken = manager.RevokeCondition(self, deployedToken);
if (deployedToken != ConditionManager.InvalidConditionToken)
deployedToken = conditionManager.RevokeCondition(self, deployedToken);
deployState = DeployState.Deploying;
}
void OnUndeployCompleted()
{
if (manager != null && !string.IsNullOrEmpty(info.UndeployedCondition) && undeployedToken == UpgradeManager.InvalidConditionToken)
undeployedToken = manager.GrantCondition(self, info.UndeployedCondition);
if (conditionManager != null && !string.IsNullOrEmpty(info.UndeployedCondition) && undeployedToken == ConditionManager.InvalidConditionToken)
undeployedToken = conditionManager.GrantCondition(self, info.UndeployedCondition);
deployState = DeployState.Undeployed;
}

View File

@@ -14,25 +14,25 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
public class GrantConditionOnMovementInfo : UpgradableTraitInfo, Requires<IMoveInfo>
public class GrantConditionOnMovementInfo : ConditionalTraitInfo, Requires<IMoveInfo>
{
[FieldLoader.Require]
[GrantedConditionReference]
[Desc("Condition to grant.")]
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 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;
UpgradeManager manager;
int conditionToken = UpgradeManager.InvalidConditionToken;
ConditionManager conditionManager;
int conditionToken = ConditionManager.InvalidConditionToken;
public GrantConditionOnMovement(Actor self, GrantConditionOnMovementInfo info)
: base(info)
@@ -42,21 +42,21 @@ namespace OpenRA.Mods.Common.Traits
protected override void Created(Actor self)
{
manager = self.TraitOrDefault<UpgradeManager>();
conditionManager = self.TraitOrDefault<ConditionManager>();
base.Created(self);
}
void ITick.Tick(Actor self)
{
if (manager == null)
if (conditionManager == null)
return;
var isMovingVertically = Info.ConsiderVerticalMovement ? movement.IsMovingVertically : false;
var isMoving = !IsTraitDisabled && !self.IsDead && (movement.IsMoving || isMovingVertically);
if (isMoving && conditionToken == UpgradeManager.InvalidConditionToken)
conditionToken = manager.GrantCondition(self, Info.Condition);
else if (!isMoving && conditionToken != UpgradeManager.InvalidConditionToken)
conditionToken = manager.RevokeCondition(self, conditionToken);
if (isMoving && conditionToken == ConditionManager.InvalidConditionToken)
conditionToken = conditionManager.GrantCondition(self, Info.Condition);
else if (!isMoving && conditionToken != ConditionManager.InvalidConditionToken)
conditionToken = conditionManager.RevokeCondition(self, conditionToken);
}
}
}

View File

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

View File

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

View File

@@ -14,14 +14,14 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Grants an upgrade to the collector.")]
[Desc("Grants a condition on the collector.")]
public class GrantExternalConditionCrateActionInfo : CrateActionInfo
{
[FieldLoader.Require]
[Desc("The condition to apply. Must be included in the target actor's ExternalConditions list.")]
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;
[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)
{
var um = a.TraitOrDefault<UpgradeManager>();
return um != null && um.AcceptsExternalCondition(a, info.Condition);
var cm = a.TraitOrDefault<ConditionManager>();
return cm != null && cm.AcceptsExternalCondition(a, info.Condition);
}
public override int GetSelectionShares(Actor collector)
@@ -71,11 +71,11 @@ namespace OpenRA.Mods.Common.Traits
if (!a.IsInWorld || a.IsDead)
continue;
var um = a.TraitOrDefault<UpgradeManager>();
var cm = a.TraitOrDefault<ConditionManager>();
// Condition token is ignored because we never revoke this condition.
if (um != null)
um.GrantCondition(a, info.Condition, true, info.Duration);
if (cm != null)
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 =>
{
// Don't upgrade the same unit twice
// Don't touch the same unit twice
if (a == collector)
return false;
// Only upgrade the collecting player's units
// Only affect the collecting player's units
// TODO: Also apply to allied units?
if (a.Owner != collector.Owner)
return false;

View File

@@ -17,7 +17,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[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.")]
[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); }
}
class DamagedByTerrain : UpgradableTrait<DamagedByTerrainInfo>, ITick, ISync, INotifyAddedToWorld
class DamagedByTerrain : ConditionalTrait<DamagedByTerrainInfo>, ITick, ISync, INotifyAddedToWorld
{
readonly Health health;

View File

@@ -14,7 +14,7 @@ using System.Collections.Generic;
namespace OpenRA.Mods.Common.Traits
{
[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.")]
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 class DetectCloaked : UpgradableTrait<DetectCloakedInfo>
public class DetectCloaked : ConditionalTrait<DetectCloakedInfo>
{
public DetectCloaked(DetectCloakedInfo info) : base(info) { }
}

View File

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

View File

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

View File

@@ -13,7 +13,7 @@ using OpenRA.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.")]
public readonly bool RemoveInstead = false;
@@ -21,7 +21,7 @@ namespace OpenRA.Mods.Common.Traits
public override object Create(ActorInitializer init) { return new KillsSelf(this); }
}
class KillsSelf : UpgradableTrait<KillsSelfInfo>, INotifyAddedToWorld
class KillsSelf : ConditionalTrait<KillsSelfInfo>, INotifyAddedToWorld
{
public KillsSelf(KillsSelfInfo info)
: base(info) { }

View File

@@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Traits
}
[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>
{
[FieldLoader.LoadUsing("LoadSpeeds", true)]
@@ -317,7 +317,7 @@ namespace OpenRA.Mods.Common.Traits
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
{
const int AverageTicksBeforePathing = 5;

View File

@@ -16,7 +16,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[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")]
[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 class UpgradeOverlay : UpgradableTrait<UpgradeOverlayInfo>, IRenderModifier
public class UpgradeOverlay : ConditionalTrait<UpgradeOverlayInfo>, IRenderModifier
{
public UpgradeOverlay(UpgradeOverlayInfo info)
: base(info) { }

View File

@@ -15,7 +15,7 @@ namespace OpenRA.Mods.Common.Traits
{
[Desc("Modifies the damage applied to this actor.",
"Use 0 to make actor invulnerable.")]
public class DamageMultiplierInfo : UpgradableTraitInfo
public class DamageMultiplierInfo : ConditionalTraitInfo
{
[FieldLoader.Require]
[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 class DamageMultiplier : UpgradableTrait<DamageMultiplierInfo>, IDamageModifier
public class DamageMultiplier : ConditionalTrait<DamageMultiplierInfo>, IDamageModifier
{
public DamageMultiplier(DamageMultiplierInfo info)
: base(info) { }

View File

@@ -12,7 +12,7 @@
namespace OpenRA.Mods.Common.Traits
{
[Desc("Modifies the damage applied by this actor.")]
public class FirepowerMultiplierInfo : UpgradableTraitInfo
public class FirepowerMultiplierInfo : ConditionalTraitInfo
{
[FieldLoader.Require]
[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 class FirepowerMultiplier : UpgradableTrait<FirepowerMultiplierInfo>, IFirepowerModifier
public class FirepowerMultiplier : ConditionalTrait<FirepowerMultiplierInfo>, IFirepowerModifier
{
public FirepowerMultiplier(FirepowerMultiplierInfo info)
: base(info) { }

View File

@@ -12,7 +12,7 @@
namespace OpenRA.Mods.Common.Traits
{
[Desc("Modifies the inaccuracy of weapons fired by this actor.")]
public class InaccuracyMultiplierInfo : UpgradableTraitInfo
public class InaccuracyMultiplierInfo : ConditionalTraitInfo
{
[FieldLoader.Require]
[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 class InaccuracyMultiplier : UpgradableTrait<InaccuracyMultiplierInfo>, IInaccuracyModifier
public class InaccuracyMultiplier : ConditionalTrait<InaccuracyMultiplierInfo>, IInaccuracyModifier
{
public InaccuracyMultiplier(InaccuracyMultiplierInfo info)
: base(info) { }

View File

@@ -14,7 +14,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Modifies the power usage/output of this actor.")]
public class PowerMultiplierInfo : UpgradableTraitInfo
public class PowerMultiplierInfo : ConditionalTraitInfo
{
[FieldLoader.Require]
[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 class PowerMultiplier : UpgradableTrait<PowerMultiplierInfo>, IPowerModifier, INotifyOwnerChanged
public class PowerMultiplier : ConditionalTrait<PowerMultiplierInfo>, IPowerModifier, INotifyOwnerChanged
{
PowerManager power;

View File

@@ -12,7 +12,7 @@
namespace OpenRA.Mods.Common.Traits
{
[Desc("Modifies the range of weapons fired by this actor.")]
public class RangeMultiplierInfo : UpgradableTraitInfo
public class RangeMultiplierInfo : ConditionalTraitInfo
{
[FieldLoader.Require]
[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 class RangeMultiplier : UpgradableTrait<RangeMultiplierInfo>, IRangeModifierInfo
public class RangeMultiplier : ConditionalTrait<RangeMultiplierInfo>, IRangeModifierInfo
{
public RangeMultiplier(RangeMultiplierInfo info)
: base(info) { }

View File

@@ -12,7 +12,7 @@
namespace OpenRA.Mods.Common.Traits
{
[Desc("Modifies the reload time of weapons fired by this actor.")]
public class ReloadDelayMultiplierInfo : UpgradableTraitInfo
public class ReloadDelayMultiplierInfo : ConditionalTraitInfo
{
[FieldLoader.Require]
[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 class ReloadDelayMultiplier : UpgradableTrait<ReloadDelayMultiplierInfo>, IReloadModifier
public class ReloadDelayMultiplier : ConditionalTrait<ReloadDelayMultiplierInfo>, IReloadModifier
{
public ReloadDelayMultiplier(ReloadDelayMultiplierInfo info)
: base(info) { }

View File

@@ -12,7 +12,7 @@
namespace OpenRA.Mods.Common.Traits
{
[Desc("Modifies the movement speed of this actor.")]
public class SpeedMultiplierInfo : UpgradableTraitInfo
public class SpeedMultiplierInfo : ConditionalTraitInfo
{
[FieldLoader.Require]
[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 class SpeedMultiplier : UpgradableTrait<SpeedMultiplierInfo>, ISpeedModifier
public class SpeedMultiplier : ConditionalTrait<SpeedMultiplierInfo>, ISpeedModifier
{
public SpeedMultiplier(SpeedMultiplierInfo info)
: base(info) { }

View File

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

View File

@@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Traits
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)

View File

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

View File

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

View File

@@ -15,7 +15,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[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.")]
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 class CanPowerDown : UpgradableTrait<CanPowerDownInfo>, IPowerModifier, IResolveOrder, IDisable, INotifyOwnerChanged
public class CanPowerDown : ConditionalTrait<CanPowerDownInfo>, IPowerModifier, IResolveOrder, IDisable, INotifyOwnerChanged
{
[Sync] bool disabled = false;
PowerManager power;

View File

@@ -15,7 +15,7 @@ using OpenRA.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.")]
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 class Power : UpgradableTrait<PowerInfo>, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyOwnerChanged
public class Power : ConditionalTrait<PowerInfo>, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyOwnerChanged
{
readonly Lazy<IPowerModifier[]> powerModifiers;

View File

@@ -14,12 +14,12 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[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); }
}
class RequiresPower : UpgradableTrait<RequiresPowerInfo>, IDisable, INotifyOwnerChanged
class RequiresPower : ConditionalTrait<RequiresPowerInfo>, IDisable, INotifyOwnerChanged
{
PowerManager playerPower;

View File

@@ -17,7 +17,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[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]
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 class QuantizeFacingsFromSequence : UpgradableTrait<QuantizeFacingsFromSequenceInfo>
public class QuantizeFacingsFromSequence : ConditionalTrait<QuantizeFacingsFromSequenceInfo>
{
public QuantizeFacingsFromSequence(QuantizeFacingsFromSequenceInfo info)
: base(info) { }

View File

@@ -15,7 +15,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[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.")]
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 class RejectsOrders : UpgradableTrait<RejectsOrdersInfo>
public class RejectsOrders : ConditionalTrait<RejectsOrdersInfo>
{
public HashSet<string> Except { get { return Info.Except; } }

View File

@@ -18,7 +18,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render
{
[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.")]
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 class Hovers : UpgradableTrait<HoversInfo>, IRenderModifier
public class Hovers : ConditionalTrait<HoversInfo>, IRenderModifier
{
readonly HoversInfo info;

View File

@@ -18,7 +18,7 @@ namespace OpenRA.Mods.Common.Traits.Render
public enum TrailType { Cell, CenterPosition }
[Desc("Renders a sprite effect when leaving a cell.")]
public class LeavesTrailsInfo : UpgradableTraitInfo
public class LeavesTrailsInfo : ConditionalTraitInfo
{
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 class LeavesTrails : UpgradableTrait<LeavesTrailsInfo>, ITick
public class LeavesTrails : ConditionalTrait<LeavesTrailsInfo>, ITick
{
BodyOrientation body;
IFacing facing;

View File

@@ -14,8 +14,8 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render
{
[Desc("Visualizes the remaining time for an upgrade.")]
class TimedConditionBarInfo : ITraitInfo, Requires<UpgradeManagerInfo>
[Desc("Visualizes the remaining time for a condition.")]
class TimedConditionBarInfo : ITraitInfo, Requires<ConditionManagerInfo>
{
[FieldLoader.Require]
[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.")]
public class WithDecorationInfo : UpgradableTraitInfo
public class WithDecorationInfo : ConditionalTraitInfo
{
[Desc("Image used for this decoration. Defaults to the actor's type.")]
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 class WithDecoration : UpgradableTrait<WithDecorationInfo>, ITick, IRenderAboveShroud, IRenderAboveShroudWhenSelected
public class WithDecoration : ConditionalTrait<WithDecorationInfo>, ITick, IRenderAboveShroud, IRenderAboveShroudWhenSelected
{
protected readonly Animation Anim;

View File

@@ -14,20 +14,20 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render
{
[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.")]
public readonly string[] Sequences = { "active" };
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 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;
bool buildComplete;

View File

@@ -18,7 +18,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render
{
[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.")]
[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;
bool buildComplete;

View File

@@ -18,7 +18,7 @@ using OpenRA.Traits;
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 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;
protected readonly Animation DefaultAnimation;

View File

@@ -18,7 +18,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render
{
[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")]
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); }
}
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, AnimationWithOffset> anims = new Dictionary<Barrel, AnimationWithOffset>();

View File

@@ -19,7 +19,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render
{
[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.")]
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 AnimationWithOffset anim;

View File

@@ -17,7 +17,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render
{
[Desc("Clones the actor sprite with another palette below it.")]
public class WithShadowInfo : UpgradableTraitInfo
public class WithShadowInfo : ConditionalTraitInfo
{
[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 class WithShadow : UpgradableTrait<WithShadowInfo>, IRenderModifier
public class WithShadow : ConditionalTrait<WithShadowInfo>, IRenderModifier
{
readonly WithShadowInfo info;

View File

@@ -19,7 +19,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render
{
[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>
{
[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;
readonly RenderSprites rs;

View File

@@ -18,7 +18,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render
{
[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]
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;
@@ -80,7 +80,7 @@ namespace OpenRA.Mods.Common.Traits.Render
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)
{
OnBuildComplete(self);

View File

@@ -19,7 +19,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render
{
[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>
{
[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;
protected readonly AttackBase Attack;

View File

@@ -20,7 +20,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render
{
[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;
@@ -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;
Color color;

View File

@@ -18,7 +18,7 @@ using OpenRA.Traits;
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")]
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 Armament armament;

View File

@@ -19,7 +19,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render
{
[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";
@@ -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;

View File

@@ -18,7 +18,7 @@ using OpenRA.Traits;
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")]
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 Turreted turreted;

View File

@@ -16,7 +16,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Lets the actor spread resources around it in a circle.")]
class SeedsResourceInfo : UpgradableTraitInfo
class SeedsResourceInfo : ConditionalTraitInfo
{
public readonly int Interval = 75;
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); }
}
class SeedsResource : UpgradableTrait<SeedsResourceInfo>, ITick, ISeedableResource
class SeedsResource : ConditionalTrait<SeedsResourceInfo>, ITick, ISeedableResource
{
readonly SeedsResourceInfo info;

View File

@@ -15,7 +15,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[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.")]
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); }
}
class SelfHealing : UpgradableTrait<SelfHealingInfo>, ITick, INotifyDamage
class SelfHealing : ConditionalTrait<SelfHealingInfo>, ITick, INotifyDamage
{
readonly Health health;

View File

@@ -18,7 +18,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Actor can be sold")]
public class SellableInfo : UpgradableTraitInfo
public class SellableInfo : ConditionalTraitInfo
{
public readonly int RefundPercent = 50;
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 class Sellable : UpgradableTrait<SellableInfo>, IResolveOrder, IProvideTooltipInfo
public class Sellable : ConditionalTrait<SellableInfo>, IResolveOrder, IProvideTooltipInfo
{
readonly Actor self;
readonly Lazy<Health> health;

View File

@@ -14,7 +14,7 @@ using OpenRA.Traits;
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.")]
class AmbientSoundInfo : UpgradableTraitInfo
class AmbientSoundInfo : ConditionalTraitInfo
{
[FieldLoader.Require]
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); }
}
class AmbientSound : UpgradableTrait<AmbientSoundInfo>, ITick
class AmbientSound : ConditionalTrait<AmbientSoundInfo>, ITick
{
ISound currentSound;
bool wasDisabled = true;

View File

@@ -15,7 +15,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Sound
{
[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.")]
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 class AttackSounds : UpgradableTrait<AttackSoundsInfo>, INotifyAttack, ITick
public class AttackSounds : ConditionalTrait<AttackSoundsInfo>, INotifyAttack, ITick
{
readonly AttackSoundsInfo info;
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.")]
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;
[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)
{
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)
@@ -69,11 +69,11 @@ namespace OpenRA.Mods.Common.Traits
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.
if (um != null)
um.GrantCondition(a, info.Condition, true, info.Duration);
if (cm != null)
cm.GrantCondition(a, info.Condition, true, info.Duration);
}
}
@@ -90,12 +90,12 @@ namespace OpenRA.Mods.Common.Traits
if (!a.Owner.IsAlliedWith(Self.Owner))
return false;
var um = a.TraitOrDefault<UpgradeManager>();
return um != null && um.AcceptsExternalCondition(a, info.Condition);
var cm = a.TraitOrDefault<ConditionManager>();
return cm != null && cm.AcceptsExternalCondition(a, info.Condition);
});
}
class SelectUpgradeTarget : IOrderGenerator
class SelectConditionTarget : IOrderGenerator
{
readonly GrantExternalConditionPower power;
readonly int range;
@@ -103,7 +103,7 @@ namespace OpenRA.Mods.Common.Traits
readonly SupportPowerManager manager;
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
if (Game.Settings.Game.UseClassicMouseStyle)

View File

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

View File

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

View File

@@ -16,7 +16,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Actor can be targeted.")]
public class TargetableInfo : UpgradableTraitInfo, ITargetableInfo
public class TargetableInfo : ConditionalTraitInfo, ITargetableInfo
{
[Desc("Target type. Used for filtering (in)valid targets.")]
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 class Targetable : UpgradableTrait<TargetableInfo>, ITargetable
public class Targetable : ConditionalTrait<TargetableInfo>, ITargetable
{
protected static readonly string[] None = new string[] { };
protected Cloak[] cloaks;

View File

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

View File

@@ -15,7 +15,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Wanders around aimlessly while idle.")]
public class WandersInfo : UpgradableTraitInfo, Requires<IMoveInfo>
public class WandersInfo : ConditionalTraitInfo, Requires<IMoveInfo>
{
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 class Wanders : UpgradableTrait<WandersInfo>, INotifyIdle, INotifyBecomingIdle
public class Wanders : ConditionalTrait<WandersInfo>, INotifyIdle, INotifyBecomingIdle
{
readonly Actor self;
readonly WandersInfo info;

View File

@@ -695,6 +695,15 @@ namespace OpenRA.Mods.Common.UtilityCommands
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);
}

View File

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

View File

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

View File

@@ -14,7 +14,7 @@ using OpenRA.Mods.Common.Traits;
namespace OpenRA.Mods.D2k.Traits
{
[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.")]
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 class AttractsWorms : UpgradableTrait<AttractsWormsInfo>
public class AttractsWorms : ConditionalTrait<AttractsWormsInfo>
{
readonly Actor self;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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