Rename UpgradeManager to ConditionManager.

This commit is contained in:
Paul Chote
2016-12-23 14:42:08 +00:00
parent 189c25431b
commit dcad5c3f7c
32 changed files with 121 additions and 112 deletions

View File

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

View File

@@ -498,7 +498,7 @@
<Compile Include="Traits\Upgrades\GrantConditionOnDamageState.cs" /> <Compile Include="Traits\Upgrades\GrantConditionOnDamageState.cs" />
<Compile Include="Traits\Upgrades\GrantConditionOnTerrain.cs" /> <Compile Include="Traits\Upgrades\GrantConditionOnTerrain.cs" />
<Compile Include="Traits\Upgrades\GrantConditionOnMovement.cs" /> <Compile Include="Traits\Upgrades\GrantConditionOnMovement.cs" />
<Compile Include="Traits\Upgrades\UpgradeManager.cs" /> <Compile Include="Traits\Upgrades\ConditionManager.cs" />
<Compile Include="Traits\Valued.cs" /> <Compile Include="Traits\Valued.cs" />
<Compile Include="Traits\Voiced.cs" /> <Compile Include="Traits\Voiced.cs" />
<Compile Include="Traits\Wanders.cs" /> <Compile Include="Traits\Wanders.cs" />

View File

@@ -20,15 +20,15 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Scripting namespace OpenRA.Mods.Common.Scripting
{ {
[ScriptPropertyGroup("General")] [ScriptPropertyGroup("General")]
public class ConditionProperties : ScriptActorProperties, Requires<UpgradeManagerInfo> public class ConditionProperties : ScriptActorProperties, Requires<ConditionManagerInfo>
{ {
readonly UpgradeManager um; readonly ConditionManager um;
readonly Dictionary<string, Stack<int>> legacyShim = new Dictionary<string, Stack<int>>(); readonly Dictionary<string, Stack<int>> legacyShim = new Dictionary<string, Stack<int>>();
public ConditionProperties(ScriptContext context, Actor self) public ConditionProperties(ScriptContext context, Actor self)
: base(context, self) : base(context, self)
{ {
um = self.Trait<UpgradeManager>(); um = self.Trait<ConditionManager>();
} }
[Desc("Grant an external condition on this actor and return the revocation token.", [Desc("Grant an external condition on this actor and return the revocation token.",

View File

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

View File

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

View File

@@ -88,8 +88,8 @@ namespace OpenRA.Mods.Common.Traits
int totalWeight = 0; int totalWeight = 0;
int reservedWeight = 0; int reservedWeight = 0;
Aircraft aircraft; Aircraft aircraft;
UpgradeManager upgradeManager; ConditionManager upgradeManager;
int loadingToken = UpgradeManager.InvalidConditionToken; int loadingToken = ConditionManager.InvalidConditionToken;
Stack<int> loadedTokens = new Stack<int>(); Stack<int> loadedTokens = new Stack<int>();
CPos currentCell; CPos currentCell;
@@ -141,7 +141,7 @@ namespace OpenRA.Mods.Common.Traits
void INotifyCreated.Created(Actor self) void INotifyCreated.Created(Actor self)
{ {
aircraft = self.TraitOrDefault<Aircraft>(); aircraft = self.TraitOrDefault<Aircraft>();
upgradeManager = self.Trait<UpgradeManager>(); upgradeManager = self.Trait<ConditionManager>();
} }
static int GetWeight(Actor a) { return a.Info.TraitInfo<PassengerInfo>().Weight; } static int GetWeight(Actor a) { return a.Info.TraitInfo<PassengerInfo>().Weight; }
@@ -208,7 +208,7 @@ namespace OpenRA.Mods.Common.Traits
if (!HasSpace(w)) if (!HasSpace(w))
return false; return false;
if (upgradeManager != null && loadingToken == UpgradeManager.InvalidConditionToken && !string.IsNullOrEmpty(Info.LoadingCondition)) if (upgradeManager != null && loadingToken == ConditionManager.InvalidConditionToken && !string.IsNullOrEmpty(Info.LoadingCondition))
loadingToken = upgradeManager.GrantCondition(self, Info.LoadingCondition); loadingToken = upgradeManager.GrantCondition(self, Info.LoadingCondition);
reserves.Add(a); reserves.Add(a);
@@ -225,7 +225,7 @@ namespace OpenRA.Mods.Common.Traits
reservedWeight -= GetWeight(a); reservedWeight -= GetWeight(a);
reserves.Remove(a); reserves.Remove(a);
if (loadingToken != UpgradeManager.InvalidConditionToken) if (loadingToken != ConditionManager.InvalidConditionToken)
loadingToken = upgradeManager.RevokeCondition(self, loadingToken); loadingToken = upgradeManager.RevokeCondition(self, loadingToken);
} }
@@ -321,7 +321,7 @@ namespace OpenRA.Mods.Common.Traits
reservedWeight -= w; reservedWeight -= w;
reserves.Remove(a); reserves.Remove(a);
if (loadingToken != UpgradeManager.InvalidConditionToken) if (loadingToken != ConditionManager.InvalidConditionToken)
loadingToken = upgradeManager.RevokeCondition(self, loadingToken); loadingToken = upgradeManager.RevokeCondition(self, loadingToken);
} }

View File

@@ -33,9 +33,9 @@ namespace OpenRA.Mods.Common.Traits
public class Carryable : UpgradableTrait<CarryableInfo> public class Carryable : UpgradableTrait<CarryableInfo>
{ {
UpgradeManager upgradeManager; ConditionManager upgradeManager;
int reservedToken = UpgradeManager.InvalidConditionToken; int reservedToken = ConditionManager.InvalidConditionToken;
int carriedToken = UpgradeManager.InvalidConditionToken; int carriedToken = ConditionManager.InvalidConditionToken;
public Actor Carrier { get; private set; } public Actor Carrier { get; private set; }
public bool Reserved { get { return state != State.Free; } } public bool Reserved { get { return state != State.Free; } }
@@ -51,7 +51,7 @@ namespace OpenRA.Mods.Common.Traits
protected override void Created(Actor self) protected override void Created(Actor self)
{ {
upgradeManager = self.Trait<UpgradeManager>(); upgradeManager = self.Trait<ConditionManager>();
base.Created(self); base.Created(self);
} }
@@ -63,7 +63,7 @@ namespace OpenRA.Mods.Common.Traits
attached = true; attached = true;
if (carriedToken == UpgradeManager.InvalidConditionToken && !string.IsNullOrEmpty(Info.CarriedCondition)) if (carriedToken == ConditionManager.InvalidConditionToken && !string.IsNullOrEmpty(Info.CarriedCondition))
carriedToken = upgradeManager.GrantCondition(self, Info.CarriedCondition); carriedToken = upgradeManager.GrantCondition(self, Info.CarriedCondition);
} }
@@ -75,7 +75,7 @@ namespace OpenRA.Mods.Common.Traits
attached = false; attached = false;
if (carriedToken != UpgradeManager.InvalidConditionToken) if (carriedToken != ConditionManager.InvalidConditionToken)
carriedToken = upgradeManager.RevokeCondition(self, carriedToken); carriedToken = upgradeManager.RevokeCondition(self, carriedToken);
} }
@@ -87,7 +87,7 @@ namespace OpenRA.Mods.Common.Traits
state = State.Reserved; state = State.Reserved;
Carrier = carrier; Carrier = carrier;
if (reservedToken == UpgradeManager.InvalidConditionToken && !string.IsNullOrEmpty(Info.ReservedCondition)) if (reservedToken == ConditionManager.InvalidConditionToken && !string.IsNullOrEmpty(Info.ReservedCondition))
reservedToken = upgradeManager.GrantCondition(self, Info.ReservedCondition); reservedToken = upgradeManager.GrantCondition(self, Info.ReservedCondition);
return true; return true;
@@ -98,7 +98,7 @@ namespace OpenRA.Mods.Common.Traits
state = State.Free; state = State.Free;
Carrier = null; Carrier = null;
if (reservedToken != UpgradeManager.InvalidConditionToken) if (reservedToken != ConditionManager.InvalidConditionToken)
reservedToken = upgradeManager.RevokeCondition(self, reservedToken); reservedToken = upgradeManager.RevokeCondition(self, reservedToken);
} }

View File

@@ -66,11 +66,11 @@ namespace OpenRA.Mods.Common.Traits
[Sync] int remainingTime; [Sync] int remainingTime;
[Sync] bool damageDisabled; [Sync] bool damageDisabled;
bool isDocking; bool isDocking;
UpgradeManager upgradeManager; ConditionManager upgradeManager;
CPos? lastPos; CPos? lastPos;
bool wasCloaked = false; bool wasCloaked = false;
int cloakedToken = UpgradeManager.InvalidConditionToken; int cloakedToken = ConditionManager.InvalidConditionToken;
public Cloak(CloakInfo info) public Cloak(CloakInfo info)
: base(info) : base(info)
@@ -80,12 +80,12 @@ namespace OpenRA.Mods.Common.Traits
void INotifyCreated.Created(Actor self) void INotifyCreated.Created(Actor self)
{ {
upgradeManager = self.TraitOrDefault<UpgradeManager>(); upgradeManager = self.TraitOrDefault<ConditionManager>();
if (Cloaked) if (Cloaked)
{ {
wasCloaked = true; wasCloaked = true;
if (upgradeManager != null && cloakedToken == UpgradeManager.InvalidConditionToken && !string.IsNullOrEmpty(Info.CloakedCondition)) if (upgradeManager != null && cloakedToken == ConditionManager.InvalidConditionToken && !string.IsNullOrEmpty(Info.CloakedCondition))
cloakedToken = upgradeManager.GrantCondition(self, Info.CloakedCondition); cloakedToken = upgradeManager.GrantCondition(self, Info.CloakedCondition);
} }
} }
@@ -144,7 +144,7 @@ namespace OpenRA.Mods.Common.Traits
var isCloaked = Cloaked; var isCloaked = Cloaked;
if (isCloaked && !wasCloaked) if (isCloaked && !wasCloaked)
{ {
if (upgradeManager != null && cloakedToken == UpgradeManager.InvalidConditionToken && !string.IsNullOrEmpty(Info.CloakedCondition)) if (upgradeManager != null && cloakedToken == ConditionManager.InvalidConditionToken && !string.IsNullOrEmpty(Info.CloakedCondition))
cloakedToken = upgradeManager.GrantCondition(self, Info.CloakedCondition); cloakedToken = upgradeManager.GrantCondition(self, Info.CloakedCondition);
if (!self.TraitsImplementing<Cloak>().Any(a => a != this && a.Cloaked)) if (!self.TraitsImplementing<Cloak>().Any(a => a != this && a.Cloaked))
@@ -152,7 +152,7 @@ namespace OpenRA.Mods.Common.Traits
} }
else if (!isCloaked && wasCloaked) else if (!isCloaked && wasCloaked)
{ {
if (cloakedToken != UpgradeManager.InvalidConditionToken) if (cloakedToken != ConditionManager.InvalidConditionToken)
cloakedToken = upgradeManager.RevokeCondition(self, cloakedToken); cloakedToken = upgradeManager.RevokeCondition(self, cloakedToken);
if (!self.TraitsImplementing<Cloak>().Any(a => a != this && a.Cloaked)) if (!self.TraitsImplementing<Cloak>().Any(a => a != this && a.Cloaked))

View File

@@ -47,7 +47,7 @@ namespace OpenRA.Mods.Common.Traits
bool AcceptsCondition(Actor a) bool AcceptsCondition(Actor a)
{ {
var um = a.TraitOrDefault<UpgradeManager>(); var um = a.TraitOrDefault<ConditionManager>();
return um != null && um.AcceptsExternalCondition(a, info.Condition); return um != null && um.AcceptsExternalCondition(a, info.Condition);
} }
@@ -71,7 +71,7 @@ namespace OpenRA.Mods.Common.Traits
if (!a.IsInWorld || a.IsDead) if (!a.IsInWorld || a.IsDead)
continue; continue;
var um = a.TraitOrDefault<UpgradeManager>(); var um = a.TraitOrDefault<ConditionManager>();
// Condition token is ignored because we never revoke this condition. // Condition token is ignored because we never revoke this condition.
if (um != null) if (um != null)

View File

@@ -46,7 +46,7 @@ namespace OpenRA.Mods.Common.Traits
readonly int initialExperience; readonly int initialExperience;
readonly List<Pair<int, string>> nextLevel = new List<Pair<int, string>>(); readonly List<Pair<int, string>> nextLevel = new List<Pair<int, string>>();
UpgradeManager um; ConditionManager um;
// Stored as a percentage of our value // Stored as a percentage of our value
[Sync] int experience = 0; [Sync] int experience = 0;
@@ -70,7 +70,7 @@ namespace OpenRA.Mods.Common.Traits
void INotifyCreated.Created(Actor self) void INotifyCreated.Created(Actor self)
{ {
um = self.TraitOrDefault<UpgradeManager>(); um = self.TraitOrDefault<ConditionManager>();
if (initialExperience > 0) if (initialExperience > 0)
GiveExperience(initialExperience, info.SuppressLevelupAnimation); GiveExperience(initialExperience, info.SuppressLevelupAnimation);
} }

View File

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

View File

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

View File

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

View File

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

View File

@@ -69,7 +69,7 @@ namespace OpenRA.Mods.Common.Traits
foreach (var a in UnitsInRange(order.TargetLocation)) foreach (var a in UnitsInRange(order.TargetLocation))
{ {
var um = a.TraitOrDefault<UpgradeManager>(); var um = a.TraitOrDefault<ConditionManager>();
// Condition token is ignored because we never revoke this condition. // Condition token is ignored because we never revoke this condition.
if (um != null) if (um != null)
@@ -90,7 +90,7 @@ namespace OpenRA.Mods.Common.Traits
if (!a.Owner.IsAlliedWith(Self.Owner)) if (!a.Owner.IsAlliedWith(Self.Owner))
return false; return false;
var um = a.TraitOrDefault<UpgradeManager>(); var um = a.TraitOrDefault<ConditionManager>();
return um != null && um.AcceptsExternalCondition(a, info.Condition); return um != null && um.AcceptsExternalCondition(a, info.Condition);
}); });
} }

View File

@@ -25,9 +25,9 @@ namespace OpenRA.Mods.Common.Traits
} }
[Desc("Attach this to a unit to enable dynamic upgrades by warheads, experience, crates, support powers, etc.")] [Desc("Attach this to a unit to enable dynamic upgrades by warheads, experience, crates, support powers, etc.")]
public class UpgradeManagerInfo : TraitInfo<UpgradeManager>, Requires<IConditionConsumerInfo> { } public class ConditionManagerInfo : TraitInfo<ConditionManager>, Requires<IConditionConsumerInfo> { }
public class UpgradeManager : INotifyCreated, ITick public class ConditionManager : INotifyCreated, ITick
{ {
/// <summary>Value used to represent an invalid token.</summary> /// <summary>Value used to represent an invalid token.</summary>
public static readonly int InvalidConditionToken = -1; public static readonly int InvalidConditionToken = -1;

View File

@@ -26,28 +26,28 @@ namespace OpenRA.Mods.Common.Traits
class GrantCondition : UpgradableTrait<GrantConditionInfo> class GrantCondition : UpgradableTrait<GrantConditionInfo>
{ {
UpgradeManager manager; ConditionManager manager;
int conditionToken = UpgradeManager.InvalidConditionToken; int conditionToken = ConditionManager.InvalidConditionToken;
public GrantCondition(GrantConditionInfo info) public GrantCondition(GrantConditionInfo info)
: base(info) { } : base(info) { }
protected override void Created(Actor self) protected override void Created(Actor self)
{ {
manager = self.Trait<UpgradeManager>(); manager = self.Trait<ConditionManager>();
base.Created(self); base.Created(self);
} }
protected override void TraitEnabled(Actor self) protected override void TraitEnabled(Actor self)
{ {
if (conditionToken == UpgradeManager.InvalidConditionToken) if (conditionToken == ConditionManager.InvalidConditionToken)
conditionToken = manager.GrantCondition(self, Info.Condition); conditionToken = manager.GrantCondition(self, Info.Condition);
} }
protected override void TraitDisabled(Actor self) protected override void TraitDisabled(Actor self)
{ {
if (conditionToken == UpgradeManager.InvalidConditionToken) if (conditionToken == ConditionManager.InvalidConditionToken)
return; return;
conditionToken = manager.RevokeCondition(self, conditionToken); conditionToken = manager.RevokeCondition(self, conditionToken);

View File

@@ -41,8 +41,8 @@ namespace OpenRA.Mods.Common.Traits
readonly GrantConditionOnDamageStateInfo info; readonly GrantConditionOnDamageStateInfo info;
readonly Health health; readonly Health health;
UpgradeManager manager; ConditionManager manager;
int conditionToken = UpgradeManager.InvalidConditionToken; int conditionToken = ConditionManager.InvalidConditionToken;
public GrantConditionOnDamageState(Actor self, GrantConditionOnDamageStateInfo info) public GrantConditionOnDamageState(Actor self, GrantConditionOnDamageStateInfo info)
{ {
@@ -52,13 +52,13 @@ namespace OpenRA.Mods.Common.Traits
void INotifyCreated.Created(Actor self) void INotifyCreated.Created(Actor self)
{ {
manager = self.TraitOrDefault<UpgradeManager>(); manager = self.TraitOrDefault<ConditionManager>();
GrantUpgradeOnValidDamageState(self, health.DamageState); GrantUpgradeOnValidDamageState(self, health.DamageState);
} }
void GrantUpgradeOnValidDamageState(Actor self, DamageState state) void GrantUpgradeOnValidDamageState(Actor self, DamageState state)
{ {
if (!info.ValidDamageStates.HasFlag(state) || conditionToken != UpgradeManager.InvalidConditionToken) if (!info.ValidDamageStates.HasFlag(state) || conditionToken != ConditionManager.InvalidConditionToken)
return; return;
conditionToken = manager.GrantCondition(self, info.Condition); conditionToken = manager.GrantCondition(self, info.Condition);
@@ -69,7 +69,7 @@ namespace OpenRA.Mods.Common.Traits
void INotifyDamageStateChanged.DamageStateChanged(Actor self, AttackInfo e) void INotifyDamageStateChanged.DamageStateChanged(Actor self, AttackInfo e)
{ {
var granted = conditionToken != UpgradeManager.InvalidConditionToken; var granted = conditionToken != ConditionManager.InvalidConditionToken;
if ((granted && info.GrantPermanently) || manager == null) if ((granted && info.GrantPermanently) || manager == null)
return; return;

View File

@@ -72,9 +72,9 @@ namespace OpenRA.Mods.Common.Traits
readonly Lazy<WithSpriteBody> body; readonly Lazy<WithSpriteBody> body;
DeployState deployState; DeployState deployState;
UpgradeManager manager; ConditionManager manager;
int deployedToken = UpgradeManager.InvalidConditionToken; int deployedToken = ConditionManager.InvalidConditionToken;
int undeployedToken = UpgradeManager.InvalidConditionToken; int undeployedToken = ConditionManager.InvalidConditionToken;
public GrantConditionOnDeploy(ActorInitializer init, GrantConditionOnDeployInfo info) public GrantConditionOnDeploy(ActorInitializer init, GrantConditionOnDeployInfo info)
{ {
@@ -89,7 +89,7 @@ namespace OpenRA.Mods.Common.Traits
public void Created(Actor self) public void Created(Actor self)
{ {
manager = self.TraitOrDefault<UpgradeManager>(); manager = self.TraitOrDefault<ConditionManager>();
switch (deployState) switch (deployState)
{ {
@@ -243,7 +243,7 @@ namespace OpenRA.Mods.Common.Traits
void OnDeployStarted() void OnDeployStarted()
{ {
if (undeployedToken != UpgradeManager.InvalidConditionToken) if (undeployedToken != ConditionManager.InvalidConditionToken)
undeployedToken = manager.RevokeCondition(self, undeployedToken); undeployedToken = manager.RevokeCondition(self, undeployedToken);
deployState = DeployState.Deploying; deployState = DeployState.Deploying;
@@ -251,7 +251,7 @@ namespace OpenRA.Mods.Common.Traits
void OnDeployCompleted() void OnDeployCompleted()
{ {
if (manager != null && !string.IsNullOrEmpty(info.DeployedCondition) && deployedToken == UpgradeManager.InvalidConditionToken) if (manager != null && !string.IsNullOrEmpty(info.DeployedCondition) && deployedToken == ConditionManager.InvalidConditionToken)
deployedToken = manager.GrantCondition(self, info.DeployedCondition); deployedToken = manager.GrantCondition(self, info.DeployedCondition);
deployState = DeployState.Deployed; deployState = DeployState.Deployed;
@@ -259,7 +259,7 @@ namespace OpenRA.Mods.Common.Traits
void OnUndeployStarted() void OnUndeployStarted()
{ {
if (deployedToken != UpgradeManager.InvalidConditionToken) if (deployedToken != ConditionManager.InvalidConditionToken)
deployedToken = manager.RevokeCondition(self, deployedToken); deployedToken = manager.RevokeCondition(self, deployedToken);
deployState = DeployState.Deploying; deployState = DeployState.Deploying;
@@ -267,7 +267,7 @@ namespace OpenRA.Mods.Common.Traits
void OnUndeployCompleted() void OnUndeployCompleted()
{ {
if (manager != null && !string.IsNullOrEmpty(info.UndeployedCondition) && undeployedToken == UpgradeManager.InvalidConditionToken) if (manager != null && !string.IsNullOrEmpty(info.UndeployedCondition) && undeployedToken == ConditionManager.InvalidConditionToken)
undeployedToken = manager.GrantCondition(self, info.UndeployedCondition); undeployedToken = manager.GrantCondition(self, info.UndeployedCondition);
deployState = DeployState.Undeployed; deployState = DeployState.Undeployed;

View File

@@ -31,8 +31,8 @@ namespace OpenRA.Mods.Common.Traits
{ {
readonly IMove movement; readonly IMove movement;
UpgradeManager manager; ConditionManager manager;
int conditionToken = UpgradeManager.InvalidConditionToken; int conditionToken = ConditionManager.InvalidConditionToken;
public GrantConditionOnMovement(Actor self, GrantConditionOnMovementInfo info) public GrantConditionOnMovement(Actor self, GrantConditionOnMovementInfo info)
: base(info) : base(info)
@@ -42,7 +42,7 @@ namespace OpenRA.Mods.Common.Traits
protected override void Created(Actor self) protected override void Created(Actor self)
{ {
manager = self.TraitOrDefault<UpgradeManager>(); manager = self.TraitOrDefault<ConditionManager>();
base.Created(self); base.Created(self);
} }
@@ -53,9 +53,9 @@ namespace OpenRA.Mods.Common.Traits
var isMovingVertically = Info.ConsiderVerticalMovement ? movement.IsMovingVertically : false; var isMovingVertically = Info.ConsiderVerticalMovement ? movement.IsMovingVertically : false;
var isMoving = !IsTraitDisabled && !self.IsDead && (movement.IsMoving || isMovingVertically); var isMoving = !IsTraitDisabled && !self.IsDead && (movement.IsMoving || isMovingVertically);
if (isMoving && conditionToken == UpgradeManager.InvalidConditionToken) if (isMoving && conditionToken == ConditionManager.InvalidConditionToken)
conditionToken = manager.GrantCondition(self, Info.Condition); conditionToken = manager.GrantCondition(self, Info.Condition);
else if (!isMoving && conditionToken != UpgradeManager.InvalidConditionToken) else if (!isMoving && conditionToken != ConditionManager.InvalidConditionToken)
conditionToken = manager.RevokeCondition(self, conditionToken); conditionToken = manager.RevokeCondition(self, conditionToken);
} }
} }

View File

@@ -32,8 +32,8 @@ namespace OpenRA.Mods.Common.Traits
{ {
readonly GrantConditionOnTerrainInfo info; readonly GrantConditionOnTerrainInfo info;
UpgradeManager manager; ConditionManager manager;
int conditionToken = UpgradeManager.InvalidConditionToken; int conditionToken = ConditionManager.InvalidConditionToken;
string previousTerrain; string previousTerrain;
public GrantConditionOnTerrain(ActorInitializer init, GrantConditionOnTerrainInfo info) public GrantConditionOnTerrain(ActorInitializer init, GrantConditionOnTerrainInfo info)
@@ -43,7 +43,7 @@ namespace OpenRA.Mods.Common.Traits
void INotifyCreated.Created(Actor self) void INotifyCreated.Created(Actor self)
{ {
manager = self.TraitOrDefault<UpgradeManager>(); manager = self.TraitOrDefault<ConditionManager>();
} }
public void Tick(Actor self) public void Tick(Actor self)
@@ -55,9 +55,9 @@ namespace OpenRA.Mods.Common.Traits
var wantsGranted = info.TerrainTypes.Contains(currentTerrain); var wantsGranted = info.TerrainTypes.Contains(currentTerrain);
if (currentTerrain != previousTerrain) if (currentTerrain != previousTerrain)
{ {
if (wantsGranted && conditionToken == UpgradeManager.InvalidConditionToken) if (wantsGranted && conditionToken == ConditionManager.InvalidConditionToken)
conditionToken = manager.GrantCondition(self, info.Condition); conditionToken = manager.GrantCondition(self, info.Condition);
else if (!wantsGranted && conditionToken != UpgradeManager.InvalidConditionToken) else if (!wantsGranted && conditionToken != ConditionManager.InvalidConditionToken)
conditionToken = manager.RevokeCondition(self, conditionToken); conditionToken = manager.RevokeCondition(self, conditionToken);
} }

View File

@@ -108,7 +108,7 @@ namespace OpenRA.Mods.Common.Traits
if (!info.ValidStances.HasStance(stance)) if (!info.ValidStances.HasStance(stance))
return; return;
var um = a.TraitOrDefault<UpgradeManager>(); var um = a.TraitOrDefault<ConditionManager>();
if (um != null && !tokens.ContainsKey(a) && um.AcceptsExternalCondition(a, info.Condition)) if (um != null && !tokens.ContainsKey(a) && um.AcceptsExternalCondition(a, info.Condition))
tokens[a] = um.GrantCondition(a, info.Condition, true); tokens[a] = um.GrantCondition(a, info.Condition, true);
} }
@@ -130,7 +130,7 @@ namespace OpenRA.Mods.Common.Traits
if (!info.ValidStances.HasStance(stance)) if (!info.ValidStances.HasStance(stance))
return; return;
var um = produced.TraitOrDefault<UpgradeManager>(); var um = produced.TraitOrDefault<ConditionManager>();
if (um != null && um.AcceptsExternalCondition(produced, info.Condition)) if (um != null && um.AcceptsExternalCondition(produced, info.Condition))
tokens[produced] = um.GrantCondition(produced, info.Condition, true); tokens[produced] = um.GrantCondition(produced, info.Condition, true);
} }
@@ -146,7 +146,7 @@ namespace OpenRA.Mods.Common.Traits
return; return;
tokens.Remove(a); tokens.Remove(a);
var um = a.TraitOrDefault<UpgradeManager>(); var um = a.TraitOrDefault<ConditionManager>();
if (um != null) if (um != null)
um.RevokeCondition(a, token); um.RevokeCondition(a, token);
} }

View File

@@ -64,7 +64,7 @@ namespace OpenRA.Mods.Common.Traits
{ {
Info = info; Info = info;
// Conditional traits will be enabled (if appropriate) by the UpgradeManager // Conditional traits will be enabled (if appropriate) by the ConditionManager
// calling IConditionConsumer.ConditionsChanged at the end of INotifyCreated. // calling IConditionConsumer.ConditionsChanged at the end of INotifyCreated.
IsTraitDisabled = Info.RequiresCondition != null; IsTraitDisabled = Info.RequiresCondition != null;
} }

View File

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

View File

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

View File

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

View File

@@ -83,8 +83,8 @@ namespace OpenRA.Mods.RA.Traits
readonly Actor self; readonly Actor self;
readonly DisguiseInfo info; readonly DisguiseInfo info;
UpgradeManager um; ConditionManager um;
int disguisedToken = UpgradeManager.InvalidConditionToken; int disguisedToken = ConditionManager.InvalidConditionToken;
public Disguise(Actor self, DisguiseInfo info) public Disguise(Actor self, DisguiseInfo info)
{ {
@@ -94,7 +94,7 @@ namespace OpenRA.Mods.RA.Traits
void INotifyCreated.Created(Actor self) void INotifyCreated.Created(Actor self)
{ {
um = self.TraitOrDefault<UpgradeManager>(); um = self.TraitOrDefault<ConditionManager>();
} }
public IEnumerable<IOrderTargeter> Orders public IEnumerable<IOrderTargeter> Orders
@@ -189,9 +189,9 @@ namespace OpenRA.Mods.RA.Traits
if (Disguised != oldDisguiseSetting && um != null) if (Disguised != oldDisguiseSetting && um != null)
{ {
if (Disguised && disguisedToken == UpgradeManager.InvalidConditionToken && !string.IsNullOrEmpty(info.DisguisedCondition)) if (Disguised && disguisedToken == ConditionManager.InvalidConditionToken && !string.IsNullOrEmpty(info.DisguisedCondition))
disguisedToken = um.GrantCondition(self, info.DisguisedCondition); disguisedToken = um.GrantCondition(self, info.DisguisedCondition);
else if (!Disguised && disguisedToken != UpgradeManager.InvalidConditionToken) else if (!Disguised && disguisedToken != ConditionManager.InvalidConditionToken)
disguisedToken = um.RevokeCondition(self, disguisedToken); disguisedToken = um.RevokeCondition(self, disguisedToken);
} }
} }

View File

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

View File

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

View File

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

View File

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

View File

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