diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index b8d3d5eb41..d91a85630f 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -357,7 +357,6 @@ - @@ -443,7 +442,6 @@ - diff --git a/OpenRA.Mods.Common/Traits/Multipliers/DamageMultiplier.cs b/OpenRA.Mods.Common/Traits/Multipliers/DamageMultiplier.cs index 6ba58d0921..8d133ea0da 100644 --- a/OpenRA.Mods.Common/Traits/Multipliers/DamageMultiplier.cs +++ b/OpenRA.Mods.Common/Traits/Multipliers/DamageMultiplier.cs @@ -13,19 +13,25 @@ using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits { - [Desc("Damage taken by this actor is multiplied based on upgrade level.", - "Decrease to increase actor's apparent strength.", + [Desc("Modifies the damage applied to this actor.", "Use 0 to make actor invulnerable.")] - public class DamageMultiplierInfo : UpgradeMultiplierTraitInfo + public class DamageMultiplierInfo : UpgradableTraitInfo { - public override object Create(ActorInitializer init) { return new DamageMultiplier(this, init.Self.Info.Name); } + [FieldLoader.Require] + [Desc("Percentage modifier to apply.")] + public readonly int Modifier = 100; + + public override object Create(ActorInitializer init) { return new DamageMultiplier(this); } } - public class DamageMultiplier : UpgradeMultiplierTrait, IDamageModifier + public class DamageMultiplier : UpgradableTrait, IDamageModifier { - public DamageMultiplier(DamageMultiplierInfo info, string actorType) - : base(info, "DamageMultiplier", actorType) { } + public DamageMultiplier(DamageMultiplierInfo info) + : base(info) { } - int IDamageModifier.GetDamageModifier(Actor attacker, Damage damage) { return GetModifier(); } + int IDamageModifier.GetDamageModifier(Actor attacker, Damage damage) + { + return IsTraitDisabled ? 100 : Info.Modifier; + } } } diff --git a/OpenRA.Mods.Common/Traits/Multipliers/FirepowerMultiplier.cs b/OpenRA.Mods.Common/Traits/Multipliers/FirepowerMultiplier.cs index cead62c54b..8248089e0c 100644 --- a/OpenRA.Mods.Common/Traits/Multipliers/FirepowerMultiplier.cs +++ b/OpenRA.Mods.Common/Traits/Multipliers/FirepowerMultiplier.cs @@ -11,17 +11,21 @@ namespace OpenRA.Mods.Common.Traits { - [Desc("The firepower of this actor is multiplied based on upgrade level if specified.")] - public class FirepowerMultiplierInfo : UpgradeMultiplierTraitInfo + [Desc("Modifies the damage applied by this actor.")] + public class FirepowerMultiplierInfo : UpgradableTraitInfo { - public override object Create(ActorInitializer init) { return new FirepowerMultiplier(this, init.Self.Info.Name); } + [FieldLoader.Require] + [Desc("Percentage modifier to apply.")] + public readonly int Modifier = 100; + + public override object Create(ActorInitializer init) { return new FirepowerMultiplier(this); } } - public class FirepowerMultiplier : UpgradeMultiplierTrait, IFirepowerModifier + public class FirepowerMultiplier : UpgradableTrait, IFirepowerModifier { - public FirepowerMultiplier(FirepowerMultiplierInfo info, string actorType) - : base(info, "FirepowerMultiplier", actorType) { } + public FirepowerMultiplier(FirepowerMultiplierInfo info) + : base(info) { } - int IFirepowerModifier.GetFirepowerModifier() { return GetModifier(); } + int IFirepowerModifier.GetFirepowerModifier() { return IsTraitDisabled ? 100 : Info.Modifier; } } } diff --git a/OpenRA.Mods.Common/Traits/Multipliers/InaccuracyMultiplier.cs b/OpenRA.Mods.Common/Traits/Multipliers/InaccuracyMultiplier.cs index c65d7e1f38..c3dc05bd13 100644 --- a/OpenRA.Mods.Common/Traits/Multipliers/InaccuracyMultiplier.cs +++ b/OpenRA.Mods.Common/Traits/Multipliers/InaccuracyMultiplier.cs @@ -11,17 +11,21 @@ namespace OpenRA.Mods.Common.Traits { - [Desc("The inaccuracy of this actor is multiplied based on upgrade level if specified.")] - public class InaccuracyMultiplierInfo : UpgradeMultiplierTraitInfo + [Desc("Modifies the inaccuracy of weapons fired by this actor.")] + public class InaccuracyMultiplierInfo : UpgradableTraitInfo { - public override object Create(ActorInitializer init) { return new InaccuracyMultiplier(this, init.Self.Info.Name); } + [FieldLoader.Require] + [Desc("Percentage modifier to apply.")] + public readonly int Modifier = 100; + + public override object Create(ActorInitializer init) { return new InaccuracyMultiplier(this); } } - public class InaccuracyMultiplier : UpgradeMultiplierTrait, IInaccuracyModifier + public class InaccuracyMultiplier : UpgradableTrait, IInaccuracyModifier { - public InaccuracyMultiplier(InaccuracyMultiplierInfo info, string actorType) - : base(info, "InaccuracyMultiplier", actorType) { } + public InaccuracyMultiplier(InaccuracyMultiplierInfo info) + : base(info) { } - int IInaccuracyModifier.GetInaccuracyModifier() { return GetModifier(); } + int IInaccuracyModifier.GetInaccuracyModifier() { return IsTraitDisabled ? 100 : Info.Modifier; } } } diff --git a/OpenRA.Mods.Common/Traits/Multipliers/PowerMultiplier.cs b/OpenRA.Mods.Common/Traits/Multipliers/PowerMultiplier.cs index 04ac350055..dee64dba15 100644 --- a/OpenRA.Mods.Common/Traits/Multipliers/PowerMultiplier.cs +++ b/OpenRA.Mods.Common/Traits/Multipliers/PowerMultiplier.cs @@ -13,22 +13,30 @@ using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits { - [Desc("The power usage/output of this actor is multiplied based on upgrade level if specified.")] - public class PowerMultiplierInfo : UpgradeMultiplierTraitInfo + [Desc("Modifies the power usage/output of this actor.")] + public class PowerMultiplierInfo : UpgradableTraitInfo { + [FieldLoader.Require] + [Desc("Percentage modifier to apply.")] + public readonly int Modifier = 100; + public override object Create(ActorInitializer init) { return new PowerMultiplier(init.Self, this); } } - public class PowerMultiplier : UpgradeMultiplierTrait, IPowerModifier, INotifyOwnerChanged + public class PowerMultiplier : UpgradableTrait, IPowerModifier, INotifyOwnerChanged { PowerManager power; public PowerMultiplier(Actor self, PowerMultiplierInfo info) - : base(info, "PowerMultiplier", self.Info.Name) { power = self.Owner.PlayerActor.Trait(); } + : base(info) + { + power = self.Owner.PlayerActor.Trait(); + } - int IPowerModifier.GetPowerModifier() { return GetModifier(); } + protected override void UpgradeEnabled(Actor self) { power.UpdateActor(self); } + protected override void UpgradeDisabled(Actor self) { power.UpdateActor(self); } - protected override void Update(Actor self) { power.UpdateActor(self); } + int IPowerModifier.GetPowerModifier() { return IsTraitDisabled ? 100 : Info.Modifier; } void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner) { diff --git a/OpenRA.Mods.Common/Traits/Multipliers/RangeMultiplier.cs b/OpenRA.Mods.Common/Traits/Multipliers/RangeMultiplier.cs index df857f759b..11979e3ad6 100644 --- a/OpenRA.Mods.Common/Traits/Multipliers/RangeMultiplier.cs +++ b/OpenRA.Mods.Common/Traits/Multipliers/RangeMultiplier.cs @@ -11,22 +11,21 @@ namespace OpenRA.Mods.Common.Traits { - [Desc("Range of this actor is multiplied based on upgrade level.")] - public class RangeMultiplierInfo : UpgradeMultiplierTraitInfo, IRangeModifierInfo + [Desc("Modifies the range of weapons fired by this actor.")] + public class RangeMultiplierInfo : UpgradableTraitInfo { - public override object Create(ActorInitializer init) { return new RangeMultiplier(this, init.Self.Info.Name); } + [FieldLoader.Require] + [Desc("Percentage modifier to apply.")] + public readonly int Modifier = 100; - int IRangeModifierInfo.GetRangeModifierDefault() - { - return BaseLevel > 0 || UpgradeTypes.Length == 0 ? 100 : Modifier[0]; - } + public override object Create(ActorInitializer init) { return new RangeMultiplier(this); } } - public class RangeMultiplier : UpgradeMultiplierTrait, IRangeModifier + public class RangeMultiplier : UpgradableTrait, IRangeModifierInfo { - public RangeMultiplier(RangeMultiplierInfo info, string actorType) - : base(info, "RangeMultiplier", actorType) { } + public RangeMultiplier(RangeMultiplierInfo info) + : base(info) { } - int IRangeModifier.GetRangeModifier() { return GetModifier(); } + int IRangeModifierInfo.GetRangeModifierDefault() { return IsTraitDisabled ? 100 : Info.Modifier; } } } diff --git a/OpenRA.Mods.Common/Traits/Multipliers/ReloadDelayMultiplier.cs b/OpenRA.Mods.Common/Traits/Multipliers/ReloadDelayMultiplier.cs index 2a3806ab93..793367d7d3 100644 --- a/OpenRA.Mods.Common/Traits/Multipliers/ReloadDelayMultiplier.cs +++ b/OpenRA.Mods.Common/Traits/Multipliers/ReloadDelayMultiplier.cs @@ -11,17 +11,21 @@ namespace OpenRA.Mods.Common.Traits { - [Desc("The reloading time of this actor is multiplied based on upgrade level if specified.")] - public class ReloadDelayMultiplierInfo : UpgradeMultiplierTraitInfo + [Desc("Modifies the reload time of weapons fired by this actor.")] + public class ReloadDelayMultiplierInfo : UpgradableTraitInfo { - public override object Create(ActorInitializer init) { return new ReloadDelayMultiplier(this, init.Self.Info.Name); } + [FieldLoader.Require] + [Desc("Percentage modifier to apply.")] + public readonly int Modifier = 100; + + public override object Create(ActorInitializer init) { return new ReloadDelayMultiplier(this); } } - public class ReloadDelayMultiplier : UpgradeMultiplierTrait, IReloadModifier + public class ReloadDelayMultiplier : UpgradableTrait, IReloadModifier { - public ReloadDelayMultiplier(ReloadDelayMultiplierInfo info, string actorType) - : base(info, "ReloadDelayMultiplier", actorType) { } + public ReloadDelayMultiplier(ReloadDelayMultiplierInfo info) + : base(info) { } - int IReloadModifier.GetReloadModifier() { return GetModifier(); } + int IReloadModifier.GetReloadModifier() { return IsTraitDisabled ? 100 : Info.Modifier; } } } diff --git a/OpenRA.Mods.Common/Traits/Multipliers/SpeedMultiplier.cs b/OpenRA.Mods.Common/Traits/Multipliers/SpeedMultiplier.cs index 7528e8707a..2b885d4b25 100644 --- a/OpenRA.Mods.Common/Traits/Multipliers/SpeedMultiplier.cs +++ b/OpenRA.Mods.Common/Traits/Multipliers/SpeedMultiplier.cs @@ -11,17 +11,21 @@ namespace OpenRA.Mods.Common.Traits { - [Desc("The speed of this actor is multiplied based on upgrade level if specified.")] - public class SpeedMultiplierInfo : UpgradeMultiplierTraitInfo + [Desc("Modifies the movement speed of this actor.")] + public class SpeedMultiplierInfo : UpgradableTraitInfo { - public override object Create(ActorInitializer init) { return new SpeedMultiplier(this, init.Self.Info.Name); } + [FieldLoader.Require] + [Desc("Percentage modifier to apply.")] + public readonly int Modifier = 100; + + public override object Create(ActorInitializer init) { return new SpeedMultiplier(this); } } - public class SpeedMultiplier : UpgradeMultiplierTrait, ISpeedModifier + public class SpeedMultiplier : UpgradableTrait, ISpeedModifier { - public SpeedMultiplier(SpeedMultiplierInfo info, string actorType) - : base(info, "SpeedMultiplier", actorType) { } + public SpeedMultiplier(SpeedMultiplierInfo info) + : base(info) { } - int ISpeedModifier.GetSpeedModifier() { return GetModifier(); } + int ISpeedModifier.GetSpeedModifier() { return IsTraitDisabled ? 100 : Info.Modifier; } } } diff --git a/OpenRA.Mods.Common/Traits/Multipliers/UpgradableMultiplierTrait.cs b/OpenRA.Mods.Common/Traits/Multipliers/UpgradableMultiplierTrait.cs deleted file mode 100644 index 18170ba72b..0000000000 --- a/OpenRA.Mods.Common/Traits/Multipliers/UpgradableMultiplierTrait.cs +++ /dev/null @@ -1,117 +0,0 @@ -#region Copyright & License Information -/* - * Copyright 2007-2016 The OpenRA Developers (see AUTHORS) - * This file is part of OpenRA, which is free software. It is made - * available to you under the terms of the GNU General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. For more - * information, see COPYING. - */ -#endregion - -using System; -using System.Collections.Generic; -using System.Linq; -using OpenRA.Support; -using OpenRA.Traits; - -namespace OpenRA.Mods.Common.Traits -{ - public abstract class UpgradeMultiplierTraitInfo : ITraitInfo - { - [Desc("Boolean expression defining the condition to enable this trait.", - "Overrides UpgradeTypes/BaseLevel if set.", - "Only the first Modifier will be used when the condition is enabled.")] - [UpgradeUsedReference] - public readonly BooleanExpression RequiresCondition = null; - - [UpgradeUsedReference] - [Desc("Accepted upgrade types.")] - public readonly string[] UpgradeTypes = { }; - - [Desc("The lowest upgrade level using the scale.")] - public readonly int BaseLevel = 1; - - [FieldLoader.Require] - [Desc("Percentages to apply with the first being applied at the base level.", - "Repeat last entry to accept time extensions.", - "If no upgrade types are specified, then the first/only modifier is always applied.")] - public readonly int[] Modifier = { }; - - public abstract object Create(ActorInitializer init); - } - - public abstract class UpgradeMultiplierTrait : IUpgradable, IDisabledTrait, ISync - { - readonly UpgradeMultiplierTraitInfo info; - readonly Dictionary conditions = new Dictionary(); - - [Sync] int level = 0; - [Sync] public bool IsTraitDisabled { get; private set; } - - IEnumerable IUpgradable.UpgradeTypes - { - get - { - if (info.RequiresCondition != null) - return info.RequiresCondition.Variables; - - return info.UpgradeTypes; - } - } - - protected UpgradeMultiplierTrait(UpgradeMultiplierTraitInfo info, string modifierType, string actorType) - { - this.info = info; - if (info.Modifier.Length == 0) - throw new ArgumentException("No modifiers in " + modifierType + " for " + actorType); - - // TODO: Set initial state from a future ConditionsInit - if (info.RequiresCondition != null) - IsTraitDisabled = !info.RequiresCondition.Evaluate(conditions); - else - { - IsTraitDisabled = info.UpgradeTypes != null && info.UpgradeTypes.Length > 0 && info.BaseLevel > 0; - level = IsTraitDisabled ? 0 : info.BaseLevel; - } - } - - public bool AcceptsUpgradeLevel(Actor self, string type, int level) - { - if (info.RequiresCondition != null) - return level == 1; - - return level < info.Modifier.Length + info.BaseLevel; - } - - // Override to receive notice of level change. - protected virtual void Update(Actor self) { } - - public void UpgradeLevelChanged(Actor self, string type, int oldLevel, int newLevel) - { - if (info.RequiresCondition != null) - { - conditions[type] = newLevel > 0; - IsTraitDisabled = !info.RequiresCondition.Evaluate(conditions); - } - else - { - if (!info.UpgradeTypes.Contains(type)) - return; - - level = newLevel.Clamp(0, Math.Max(info.Modifier.Length + info.BaseLevel - 1, 0)); - IsTraitDisabled = level < info.BaseLevel; - } - - Update(self); - } - - public int GetModifier() - { - if (info.RequiresCondition != null) - return IsTraitDisabled ? 100 : info.Modifier[0]; - - return IsTraitDisabled ? 100 : info.Modifier[level - info.BaseLevel]; - } - } -} diff --git a/OpenRA.Mods.Common/Traits/Render/WithRankDecoration.cs b/OpenRA.Mods.Common/Traits/Render/WithRankDecoration.cs deleted file mode 100644 index 4a23787c42..0000000000 --- a/OpenRA.Mods.Common/Traits/Render/WithRankDecoration.cs +++ /dev/null @@ -1,28 +0,0 @@ -#region Copyright & License Information -/* - * Copyright 2007-2016 The OpenRA Developers (see AUTHORS) - * This file is part of OpenRA, which is free software. It is made - * available to you under the terms of the GNU General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. For more - * information, see COPYING. - */ -#endregion - -namespace OpenRA.Mods.Common.Traits.Render -{ - public class WithRankDecorationInfo : WithDecorationInfo - { - public override object Create(ActorInitializer init) { return new WithRankDecoration(init.Self, this); } - } - - public class WithRankDecoration : WithDecoration - { - public WithRankDecoration(Actor self, WithRankDecorationInfo info) : base(self, info) { } - - protected override void UpgradeLevelChanged(Actor self, int oldLevel, int newLevel) - { - Anim.PlayFetchIndex(Info.Sequence, () => newLevel - 1); - } - } -} diff --git a/OpenRA.Mods.Common/Traits/Upgrades/UpgradableTrait.cs b/OpenRA.Mods.Common/Traits/Upgrades/UpgradableTrait.cs index 086c960daf..843d3d98ef 100644 --- a/OpenRA.Mods.Common/Traits/Upgrades/UpgradableTrait.cs +++ b/OpenRA.Mods.Common/Traits/Upgrades/UpgradableTrait.cs @@ -22,26 +22,9 @@ namespace OpenRA.Mods.Common.Traits static readonly Dictionary NoConditions = new Dictionary(); [UpgradeUsedReference] - [Desc("Boolean expression defining the condition to enable this trait.", - "Overrides UpgradeTypes/UpgradeMinEnabledLevel/UpgradeMaxEnabledLevel/UpgradeMaxAcceptedLevel if set.")] + [Desc("Boolean expression defining the condition to enable this trait.")] public readonly BooleanExpression RequiresCondition = null; - [UpgradeUsedReference] - [Desc("The upgrade types which can enable or disable this trait.")] - public readonly HashSet UpgradeTypes = new HashSet(); - - [Desc("The minimum upgrade level at which this trait is enabled.", "Defaults to 0 (enabled by default).")] - public readonly int UpgradeMinEnabledLevel = 0; - - [Desc("The maximum upgrade level at which the trait is enabled.", - "Defaults to UpgradeMaxAcceptedLevel (enabled for all levels greater than UpgradeMinEnabledLevel).", - "Set this to a value smaller than UpgradeMaxAcceptedLevel to disable the trait at higher levels.", - "Use UpgradeMaxAcceptedLevel: 2 (1 more) to be able to extend upgrade time.")] - public readonly int UpgradeMaxEnabledLevel = int.MaxValue; - - [Desc("The maximum upgrade level that this trait will accept.")] - public readonly int UpgradeMaxAcceptedLevel = 1; - public abstract object Create(ActorInitializer init); // HACK: A shim for all the ActorPreview code that used to query UpgradeMinEnabledLevel directly @@ -51,8 +34,7 @@ namespace OpenRA.Mods.Common.Traits public virtual void RulesetLoaded(Ruleset rules, ActorInfo ai) { - EnabledByDefault = RequiresCondition != null ? - RequiresCondition.Evaluate(NoConditions) : UpgradeMinEnabledLevel < 1; + EnabledByDefault = RequiresCondition != null ? RequiresCondition.Evaluate(NoConditions) : true; } } @@ -73,7 +55,7 @@ namespace OpenRA.Mods.Common.Traits if (Info.RequiresCondition != null) return Info.RequiresCondition.Variables; - return Info.UpgradeTypes; + return Enumerable.Empty(); } } @@ -84,42 +66,20 @@ namespace OpenRA.Mods.Common.Traits Info = info; // TODO: Set initial state from a ConditionsInit once that exists - if (info.RequiresCondition != null) - IsTraitDisabled = !info.RequiresCondition.Evaluate(conditions); - else - IsTraitDisabled = info.UpgradeTypes != null && info.UpgradeTypes.Count > 0 && info.UpgradeMinEnabledLevel > 0; + IsTraitDisabled = info.RequiresCondition != null ? + !info.RequiresCondition.Evaluate(conditions) : false; } bool IUpgradable.AcceptsUpgradeLevel(Actor self, string type, int level) { - if (Info.RequiresCondition != null) - return level == 1; - - return level > 0 && level <= Info.UpgradeMaxAcceptedLevel; + return level == 1; } void IUpgradable.UpgradeLevelChanged(Actor self, string type, int oldLevel, int newLevel) { var wasDisabled = IsTraitDisabled; - - if (Info.RequiresCondition != null) - { - conditions[type] = newLevel > 0; - IsTraitDisabled = !Info.RequiresCondition.Evaluate(conditions); - } - else - { - if (!Info.UpgradeTypes.Contains(type)) - return; - - // Restrict the levels to the allowed range - oldLevel = oldLevel.Clamp(0, Info.UpgradeMaxAcceptedLevel); - newLevel = newLevel.Clamp(0, Info.UpgradeMaxAcceptedLevel); - if (oldLevel == newLevel) - return; - - IsTraitDisabled = newLevel < Info.UpgradeMinEnabledLevel || newLevel > Info.UpgradeMaxEnabledLevel; - } + conditions[type] = newLevel > 0; + IsTraitDisabled = !Info.RequiresCondition.Evaluate(conditions); UpgradeLevelChanged(self, oldLevel, newLevel);