Remove legacy UpgradeTypes consumer code.

This commit is contained in:
Paul Chote
2016-11-17 14:20:08 +00:00
parent 9ceb3813e6
commit 05187f5828
11 changed files with 90 additions and 248 deletions

View File

@@ -357,7 +357,6 @@
<Compile Include="Traits\Parachutable.cs" />
<Compile Include="Traits\ParaDrop.cs" />
<Compile Include="Traits\Passenger.cs" />
<Compile Include="Traits\Multipliers\UpgradableMultiplierTrait.cs" />
<Compile Include="Traits\Multipliers\DamageMultiplier.cs" />
<Compile Include="Traits\Multipliers\FirepowerMultiplier.cs" />
<Compile Include="Traits\Multipliers\InaccuracyMultiplier.cs" />
@@ -443,7 +442,6 @@
<Compile Include="Traits\Render\WithMuzzleOverlay.cs" />
<Compile Include="Traits\Render\WithParachute.cs" />
<Compile Include="Traits\Render\WithRangeCircle.cs" />
<Compile Include="Traits\Render\WithRankDecoration.cs" />
<Compile Include="Traits\Render\WithRearmAnimation.cs" />
<Compile Include="Traits\Render\WithRepairAnimation.cs" />
<Compile Include="Traits\Render\WithRepairOverlay.cs" />

View File

@@ -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<DamageMultiplierInfo>, 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;
}
}
}

View File

@@ -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<FirepowerMultiplierInfo>, 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; }
}
}

View File

@@ -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<InaccuracyMultiplierInfo>, 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; }
}
}

View File

@@ -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<PowerMultiplierInfo>, IPowerModifier, INotifyOwnerChanged
{
PowerManager power;
public PowerMultiplier(Actor self, PowerMultiplierInfo info)
: base(info, "PowerMultiplier", self.Info.Name) { power = self.Owner.PlayerActor.Trait<PowerManager>(); }
: base(info)
{
power = self.Owner.PlayerActor.Trait<PowerManager>();
}
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)
{

View File

@@ -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<RangeMultiplierInfo>, 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; }
}
}

View File

@@ -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<ReloadDelayMultiplierInfo>, 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; }
}
}

View File

@@ -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<SpeedMultiplierInfo>, 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; }
}
}

View File

@@ -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<string, bool> conditions = new Dictionary<string, bool>();
[Sync] int level = 0;
[Sync] public bool IsTraitDisabled { get; private set; }
IEnumerable<string> 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];
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -22,26 +22,9 @@ namespace OpenRA.Mods.Common.Traits
static readonly Dictionary<string, bool> NoConditions = new Dictionary<string, bool>();
[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<string> UpgradeTypes = new HashSet<string>();
[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<string>();
}
}
@@ -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;
}
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;
}
UpgradeLevelChanged(self, oldLevel, newLevel);