Replace UpgradeMinEnabledLevel checks with an EnabledByDefault shim.
This commit is contained in:
@@ -47,7 +47,11 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
public readonly string OnFireSound = null;
|
public readonly string OnFireSound = null;
|
||||||
|
|
||||||
public override object Create(ActorInitializer init) { return new IonCannonPower(init.Self, this); }
|
public override object Create(ActorInitializer init) { return new IonCannonPower(init.Self, this); }
|
||||||
public void RulesetLoaded(Ruleset rules, ActorInfo ai) { WeaponInfo = rules.Weapons[Weapon.ToLowerInvariant()]; }
|
public override void RulesetLoaded(Ruleset rules, ActorInfo ai)
|
||||||
|
{
|
||||||
|
WeaponInfo = rules.Weapons[Weapon.ToLowerInvariant()];
|
||||||
|
base.RulesetLoaded(rules, ai);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class IonCannonPower : SupportPower
|
class IonCannonPower : SupportPower
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Mods.Common.Traits;
|
using OpenRA.Mods.Common.Traits;
|
||||||
|
using OpenRA.Support;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.AI
|
namespace OpenRA.Mods.Common.AI
|
||||||
@@ -193,7 +194,7 @@ namespace OpenRA.Mods.Common.AI
|
|||||||
|
|
||||||
bool HasSufficientPowerForActor(ActorInfo actorInfo)
|
bool HasSufficientPowerForActor(ActorInfo actorInfo)
|
||||||
{
|
{
|
||||||
return (actorInfo.TraitInfos<PowerInfo>().Where(i => i.UpgradeMinEnabledLevel < 1)
|
return (actorInfo.TraitInfos<PowerInfo>().Where(i => i.EnabledByDefault)
|
||||||
.Sum(p => p.Amount) + playerPower.ExcessPower) >= ai.Info.MinimumExcessPower;
|
.Sum(p => p.Amount) + playerPower.ExcessPower) >= ai.Info.MinimumExcessPower;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,12 +204,12 @@ namespace OpenRA.Mods.Common.AI
|
|||||||
|
|
||||||
// This gets used quite a bit, so let's cache it here
|
// This gets used quite a bit, so let's cache it here
|
||||||
var power = GetProducibleBuilding(ai.Info.BuildingCommonNames.Power, buildableThings,
|
var power = GetProducibleBuilding(ai.Info.BuildingCommonNames.Power, buildableThings,
|
||||||
a => a.TraitInfos<PowerInfo>().Where(i => i.UpgradeMinEnabledLevel < 1).Sum(p => p.Amount));
|
a => a.TraitInfos<PowerInfo>().Where(i => i.EnabledByDefault).Sum(p => p.Amount));
|
||||||
|
|
||||||
// First priority is to get out of a low power situation
|
// First priority is to get out of a low power situation
|
||||||
if (playerPower.ExcessPower < ai.Info.MinimumExcessPower)
|
if (playerPower.ExcessPower < ai.Info.MinimumExcessPower)
|
||||||
{
|
{
|
||||||
if (power != null && power.TraitInfos<PowerInfo>().Where(i => i.UpgradeMinEnabledLevel < 1).Sum(p => p.Amount) > 0)
|
if (power != null && power.TraitInfos<PowerInfo>().Where(i => i.EnabledByDefault).Sum(p => p.Amount) > 0)
|
||||||
{
|
{
|
||||||
HackyAI.BotDebug("AI: {0} decided to build {1}: Priority override (low power)", queue.Actor.Owner, power.Name);
|
HackyAI.BotDebug("AI: {0} decided to build {1}: Priority override (low power)", queue.Actor.Owner, power.Name);
|
||||||
return power;
|
return power;
|
||||||
@@ -314,7 +315,7 @@ namespace OpenRA.Mods.Common.AI
|
|||||||
if (playerPower.ExcessPower < ai.Info.MinimumExcessPower || !HasSufficientPowerForActor(actor))
|
if (playerPower.ExcessPower < ai.Info.MinimumExcessPower || !HasSufficientPowerForActor(actor))
|
||||||
{
|
{
|
||||||
// Try building a power plant instead
|
// Try building a power plant instead
|
||||||
if (power != null && power.TraitInfos<PowerInfo>().Where(i => i.UpgradeMinEnabledLevel < 1).Sum(pi => pi.Amount) > 0)
|
if (power != null && power.TraitInfos<PowerInfo>().Where(i => i.EnabledByDefault).Sum(pi => pi.Amount) > 0)
|
||||||
{
|
{
|
||||||
if (playerPower.PowerOutageRemainingTicks > 0)
|
if (playerPower.PowerOutageRemainingTicks > 0)
|
||||||
HackyAI.BotDebug("{0} decided to build {1}: Priority override (is low power)", queue.Actor.Owner, power.Name);
|
HackyAI.BotDebug("{0} decided to build {1}: Priority override (is low power)", queue.Actor.Owner, power.Name);
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Desc("Allows you to attach weapons to the unit (use @IdentifierSuffix for > 1)")]
|
[Desc("Allows you to attach weapons to the unit (use @IdentifierSuffix for > 1)")]
|
||||||
public class ArmamentInfo : UpgradableTraitInfo, IRulesetLoaded, Requires<AttackBaseInfo>
|
public class ArmamentInfo : UpgradableTraitInfo, Requires<AttackBaseInfo>
|
||||||
{
|
{
|
||||||
public readonly string Name = "primary";
|
public readonly string Name = "primary";
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public override object Create(ActorInitializer init) { return new Armament(init.Self, this); }
|
public override object Create(ActorInitializer init) { return new Armament(init.Self, this); }
|
||||||
|
|
||||||
public void RulesetLoaded(Ruleset rules, ActorInfo ai)
|
public override void RulesetLoaded(Ruleset rules, ActorInfo ai)
|
||||||
{
|
{
|
||||||
WeaponInfo weaponInfo;
|
WeaponInfo weaponInfo;
|
||||||
|
|
||||||
@@ -91,6 +91,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
ModifiedRange = new WDist(Util.ApplyPercentageModifiers(
|
ModifiedRange = new WDist(Util.ApplyPercentageModifiers(
|
||||||
WeaponInfo.Range.Length,
|
WeaponInfo.Range.Length,
|
||||||
ai.TraitInfos<IRangeModifierInfo>().Select(m => m.GetRangeModifierDefault())));
|
ai.TraitInfos<IRangeModifierInfo>().Select(m => m.GetRangeModifierDefault())));
|
||||||
|
|
||||||
|
base.RulesetLoaded(rules, ai);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
[PaletteReference] public readonly string MuzzlePalette = "effect";
|
[PaletteReference] public readonly string MuzzlePalette = "effect";
|
||||||
|
|
||||||
public override object Create(ActorInitializer init) { return new AttackGarrisoned(init.Self, this); }
|
public override object Create(ActorInitializer init) { return new AttackGarrisoned(init.Self, this); }
|
||||||
public void RulesetLoaded(Ruleset rules, ActorInfo ai)
|
public override void RulesetLoaded(Ruleset rules, ActorInfo ai)
|
||||||
{
|
{
|
||||||
if (PortOffsets.Length == 0)
|
if (PortOffsets.Length == 0)
|
||||||
throw new YamlException("PortOffsets must have at least one entry.");
|
throw new YamlException("PortOffsets must have at least one entry.");
|
||||||
@@ -67,6 +67,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
Cone = PortCones[i],
|
Cone = PortCones[i],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
base.RulesetLoaded(rules, ai);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
// Defer this lookup until we really need it to ensure we get the correct value.
|
// Defer this lookup until we really need it to ensure we get the correct value.
|
||||||
range = Exts.Lazy(() =>
|
range = Exts.Lazy(() =>
|
||||||
{
|
{
|
||||||
var armaments = ai.TraitInfos<ArmamentInfo>().Where(a => a.UpgradeMinEnabledLevel == 0);
|
var armaments = ai.TraitInfos<ArmamentInfo>().Where(a => a.EnabledByDefault);
|
||||||
if (!armaments.Any())
|
if (!armaments.Any())
|
||||||
return FallbackRange;
|
return FallbackRange;
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
|
|
||||||
public IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
|
public IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
|
||||||
{
|
{
|
||||||
if (UpgradeMinEnabledLevel > 0)
|
if (!EnabledByDefault)
|
||||||
yield break;
|
yield break;
|
||||||
|
|
||||||
if (Palette != null)
|
if (Palette != null)
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
|
|
||||||
public IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
|
public IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
|
||||||
{
|
{
|
||||||
if (UpgradeMinEnabledLevel > 0)
|
if (!EnabledByDefault)
|
||||||
yield break;
|
yield break;
|
||||||
|
|
||||||
if (image == null)
|
if (image == null)
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
|
|
||||||
public IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
|
public IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
|
||||||
{
|
{
|
||||||
if (UpgradeMinEnabledLevel > 0)
|
if (!EnabledByDefault)
|
||||||
yield break;
|
yield break;
|
||||||
|
|
||||||
var body = init.Actor.TraitInfo<BodyOrientationInfo>();
|
var body = init.Actor.TraitInfo<BodyOrientationInfo>();
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
|
|
||||||
public virtual IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
|
public virtual IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
|
||||||
{
|
{
|
||||||
if (UpgradeMinEnabledLevel > 0)
|
if (!EnabledByDefault)
|
||||||
yield break;
|
yield break;
|
||||||
|
|
||||||
var anim = new Animation(init.World, image);
|
var anim = new Animation(init.World, image);
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
|
|
||||||
public IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
|
public IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
|
||||||
{
|
{
|
||||||
if (UpgradeMinEnabledLevel > 0)
|
if (!EnabledByDefault)
|
||||||
yield break;
|
yield break;
|
||||||
|
|
||||||
var body = init.Actor.TraitInfo<BodyOrientationInfo>();
|
var body = init.Actor.TraitInfo<BodyOrientationInfo>();
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ using OpenRA.Traits;
|
|||||||
namespace OpenRA.Mods.Common.Traits.Render
|
namespace OpenRA.Mods.Common.Traits.Render
|
||||||
{
|
{
|
||||||
[Desc("Displays a text overlay relative to the selection box.")]
|
[Desc("Displays a text overlay relative to the selection box.")]
|
||||||
public class WithTextDecorationInfo : UpgradableTraitInfo, IRulesetLoaded
|
public class WithTextDecorationInfo : UpgradableTraitInfo
|
||||||
{
|
{
|
||||||
[FieldLoader.Require] [Translate] public readonly string Text = null;
|
[FieldLoader.Require] [Translate] public readonly string Text = null;
|
||||||
|
|
||||||
@@ -47,10 +47,12 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
|
|
||||||
public override object Create(ActorInitializer init) { return new WithTextDecoration(init.Self, this); }
|
public override object Create(ActorInitializer init) { return new WithTextDecoration(init.Self, this); }
|
||||||
|
|
||||||
void IRulesetLoaded<ActorInfo>.RulesetLoaded(Ruleset rules, ActorInfo info)
|
public override void RulesetLoaded(Ruleset rules, ActorInfo ai)
|
||||||
{
|
{
|
||||||
if (!Game.ModData.Manifest.Fonts.ContainsKey(Font))
|
if (!Game.ModData.Manifest.Fonts.ContainsKey(Font))
|
||||||
throw new YamlException("Font '{0}' is not listed in the mod.yaml's Fonts section".F(Font));
|
throw new YamlException("Font '{0}' is not listed in the mod.yaml's Fonts section".F(Font));
|
||||||
|
|
||||||
|
base.RulesetLoaded(rules, ai);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
public IEnumerable<VoxelAnimation> RenderPreviewVoxels(
|
public IEnumerable<VoxelAnimation> RenderPreviewVoxels(
|
||||||
ActorPreviewInitializer init, RenderVoxelsInfo rv, string image, Func<WRot> orientation, int facings, PaletteReference p)
|
ActorPreviewInitializer init, RenderVoxelsInfo rv, string image, Func<WRot> orientation, int facings, PaletteReference p)
|
||||||
{
|
{
|
||||||
if (UpgradeMinEnabledLevel > 0)
|
if (!EnabledByDefault)
|
||||||
yield break;
|
yield break;
|
||||||
|
|
||||||
var body = init.Actor.TraitInfo<BodyOrientationInfo>();
|
var body = init.Actor.TraitInfo<BodyOrientationInfo>();
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
public IEnumerable<VoxelAnimation> RenderPreviewVoxels(
|
public IEnumerable<VoxelAnimation> RenderPreviewVoxels(
|
||||||
ActorPreviewInitializer init, RenderVoxelsInfo rv, string image, Func<WRot> orientation, int facings, PaletteReference p)
|
ActorPreviewInitializer init, RenderVoxelsInfo rv, string image, Func<WRot> orientation, int facings, PaletteReference p)
|
||||||
{
|
{
|
||||||
if (UpgradeMinEnabledLevel > 0)
|
if (!EnabledByDefault)
|
||||||
yield break;
|
yield break;
|
||||||
|
|
||||||
var body = init.Actor.TraitInfo<BodyOrientationInfo>();
|
var body = init.Actor.TraitInfo<BodyOrientationInfo>();
|
||||||
|
|||||||
@@ -74,7 +74,11 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public WeaponInfo WeaponInfo { get; private set; }
|
public WeaponInfo WeaponInfo { get; private set; }
|
||||||
|
|
||||||
public override object Create(ActorInitializer init) { return new NukePower(init.Self, this); }
|
public override object Create(ActorInitializer init) { return new NukePower(init.Self, this); }
|
||||||
public void RulesetLoaded(Ruleset rules, ActorInfo ai) { WeaponInfo = rules.Weapons[MissileWeapon.ToLowerInvariant()]; }
|
public override void RulesetLoaded(Ruleset rules, ActorInfo ai)
|
||||||
|
{
|
||||||
|
WeaponInfo = rules.Weapons[MissileWeapon.ToLowerInvariant()];
|
||||||
|
base.RulesetLoaded(rules, ai);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class NukePower : SupportPower
|
class NukePower : SupportPower
|
||||||
|
|||||||
@@ -10,12 +10,14 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using OpenRA.Support;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
{
|
{
|
||||||
/// <summary>Use as base class for *Info to subclass of UpgradableTrait. (See UpgradableTrait.)</summary>
|
/// <summary>Use as base class for *Info to subclass of UpgradableTrait. (See UpgradableTrait.)</summary>
|
||||||
public abstract class UpgradableTraitInfo : IUpgradableInfo
|
public abstract class UpgradableTraitInfo : IUpgradableInfo, IRulesetLoaded
|
||||||
{
|
{
|
||||||
[UpgradeUsedReference]
|
[UpgradeUsedReference]
|
||||||
[Desc("The upgrade types which can enable or disable this trait.")]
|
[Desc("The upgrade types which can enable or disable this trait.")]
|
||||||
@@ -34,6 +36,16 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public readonly int UpgradeMaxAcceptedLevel = 1;
|
public readonly int UpgradeMaxAcceptedLevel = 1;
|
||||||
|
|
||||||
public abstract object Create(ActorInitializer init);
|
public abstract object Create(ActorInitializer init);
|
||||||
|
|
||||||
|
// HACK: A shim for all the ActorPreview code that used to query UpgradeMinEnabledLevel directly
|
||||||
|
// This can go away after we introduce an InitialUpgrades ActorInit and have the traits query the
|
||||||
|
// condition directly
|
||||||
|
public bool EnabledByDefault { get; private set; }
|
||||||
|
|
||||||
|
public virtual void RulesetLoaded(Ruleset rules, ActorInfo ai)
|
||||||
|
{
|
||||||
|
EnabledByDefault = UpgradeMinEnabledLevel < 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ using System;
|
|||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Mods.Common.Traits;
|
using OpenRA.Mods.Common.Traits;
|
||||||
|
using OpenRA.Support;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
using OpenRA.Widgets;
|
using OpenRA.Widgets;
|
||||||
|
|
||||||
@@ -74,7 +75,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
var requiresString = prereqs.Any() ? requiresLabel.Text.F(prereqs.JoinWith(", ")) : "";
|
var requiresString = prereqs.Any() ? requiresLabel.Text.F(prereqs.JoinWith(", ")) : "";
|
||||||
requiresLabel.GetText = () => requiresString;
|
requiresLabel.GetText = () => requiresString;
|
||||||
|
|
||||||
var power = actor.TraitInfos<PowerInfo>().Where(i => i.UpgradeMinEnabledLevel < 1).Sum(i => i.Amount);
|
var power = actor.TraitInfos<PowerInfo>().Where(i => i.EnabledByDefault).Sum(i => i.Amount);
|
||||||
var powerString = power.ToString();
|
var powerString = power.ToString();
|
||||||
powerLabel.GetText = () => powerString;
|
powerLabel.GetText = () => powerString;
|
||||||
powerLabel.GetColor = () => ((pm.PowerProvided - pm.PowerDrained) >= -power || power > 0)
|
powerLabel.GetColor = () => ((pm.PowerProvided - pm.PowerDrained) >= -power || power > 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user