Merge pull request #6750 from atlimit8/ITraitDisabled

Added IDisabledTrait & UpgradableTrait with upgrade levels support
This commit is contained in:
obrakmann
2014-11-26 20:21:15 +01:00
38 changed files with 545 additions and 415 deletions

View File

@@ -15,6 +15,7 @@ using System.Globalization;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using OpenRA.Support; using OpenRA.Support;
using OpenRA.Traits;
namespace OpenRA namespace OpenRA
{ {
@@ -408,6 +409,16 @@ namespace OpenRA
{ {
return int.TryParse(s, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out i); return int.TryParse(s, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out i);
} }
public static bool IsTraitEnabled(this object trait)
{
return trait as IDisabledTrait == null || !(trait as IDisabledTrait).IsTraitDisabled;
}
public static bool IsTraitEnabled<T>(T t)
{
return IsTraitEnabled(t as object);
}
} }
public static class Enum<T> public static class Enum<T>

View File

@@ -104,12 +104,6 @@ namespace OpenRA.Traits
public interface INotifyInfiltrated { void Infiltrated(Actor self, Actor infiltrator); } public interface INotifyInfiltrated { void Infiltrated(Actor self, Actor infiltrator); }
public interface IDisableMove { bool MoveDisabled(Actor self); } public interface IDisableMove { bool MoveDisabled(Actor self); }
public interface IUpgradable
{
bool AcceptsUpgrade(string type);
void UpgradeAvailable(Actor self, string type, bool available);
}
public interface ISeedableResource { void Seed(Actor self); } public interface ISeedableResource { void Seed(Actor self); }
public interface IDemolishableInfo { bool IsValidTarget(ActorInfo actorInfo, Actor saboteur); } public interface IDemolishableInfo { bool IsValidTarget(ActorInfo actorInfo, Actor saboteur); }
@@ -140,6 +134,7 @@ namespace OpenRA.Traits
bool IsOwnerRowVisible { get; } bool IsOwnerRowVisible { get; }
} }
public interface IDisabledTrait { bool IsTraitDisabled { get; } }
public interface IDisable { bool Disabled { get; } } public interface IDisable { bool Disabled { get; } }
public interface IExplodeModifier { bool ShouldExplode(Actor self); } public interface IExplodeModifier { bool ShouldExplode(Actor self); }
public interface IHuskModifier { string HuskActor(Actor self); } public interface IHuskModifier { string HuskActor(Actor self); }

View File

@@ -21,4 +21,11 @@ namespace OpenRA.Mods.Common
public interface INotifyChat { bool OnChat(string from, string message); } public interface INotifyChat { bool OnChat(string from, string message); }
public interface IRenderActorPreviewInfo { IEnumerable<IActorPreview> RenderPreview (ActorPreviewInitializer init); } public interface IRenderActorPreviewInfo { IEnumerable<IActorPreview> RenderPreview (ActorPreviewInitializer init); }
public interface IUpgradable
{
IEnumerable<string> UpgradeTypes { get; }
bool AcceptsUpgradeLevel(Actor self, string type, int level);
void UpgradeLevelChanged(Actor self, string type, int oldLevel, int newLevel);
}
} }

View File

@@ -13,7 +13,7 @@ using System.Drawing;
using System.Linq; using System.Linq;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.Common
{ {
[Desc("Visualizes the remaining time for an upgrade.")] [Desc("Visualizes the remaining time for an upgrade.")]
class TimedUpgradeBarInfo : ITraitInfo, Requires<UpgradeManagerInfo> class TimedUpgradeBarInfo : ITraitInfo, Requires<UpgradeManagerInfo>

View File

@@ -80,6 +80,7 @@
<Compile Include="LoadWidgetAtGameStart.cs" /> <Compile Include="LoadWidgetAtGameStart.cs" />
<Compile Include="ModChooserLoadScreen.cs" /> <Compile Include="ModChooserLoadScreen.cs" />
<Compile Include="NullLoadScreen.cs" /> <Compile Include="NullLoadScreen.cs" />
<Compile Include="Modifiers\TimedUpgradeBar.cs" />
<Compile Include="Orders\DeployOrderTargeter.cs" /> <Compile Include="Orders\DeployOrderTargeter.cs" />
<Compile Include="Orders\EnterAlliedActorTargeter.cs" /> <Compile Include="Orders\EnterAlliedActorTargeter.cs" />
<Compile Include="Orders\UnitOrderTargeter.cs" /> <Compile Include="Orders\UnitOrderTargeter.cs" />
@@ -136,6 +137,8 @@
<Compile Include="Traits\World\SpawnMapActors.cs" /> <Compile Include="Traits\World\SpawnMapActors.cs" />
<Compile Include="Traits\World\StartGameNotification.cs" /> <Compile Include="Traits\World\StartGameNotification.cs" />
<Compile Include="Traits\World\TerrainGeometryOverlay.cs" /> <Compile Include="Traits\World\TerrainGeometryOverlay.cs" />
<Compile Include="Upgrades\UpgradableTrait.cs" />
<Compile Include="Upgrades\UpgradeManager.cs" />
<Compile Include="UtilityCommands\ConvertPngToShpCommand.cs" /> <Compile Include="UtilityCommands\ConvertPngToShpCommand.cs" />
<Compile Include="UtilityCommands\ConvertSpriteToPngCommand.cs" /> <Compile Include="UtilityCommands\ConvertSpriteToPngCommand.cs" />
<Compile Include="UtilityCommands\ExtractFilesCommand.cs" /> <Compile Include="UtilityCommands\ExtractFilesCommand.cs" />

View File

@@ -15,26 +15,18 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
[Desc("Display a colored overlay when a timed upgrade is active.")] [Desc("Display a colored overlay when a timed upgrade is active.")]
public class UpgradeOverlayInfo : ITraitInfo public class UpgradeOverlayInfo : UpgradableTraitInfo, ITraitInfo
{ {
[Desc("Upgrade that is required before this overlay is rendered")]
public readonly string RequiresUpgrade = null;
[Desc("Palette to use when rendering the overlay")] [Desc("Palette to use when rendering the overlay")]
public readonly string Palette = "invuln"; public readonly string Palette = "invuln";
public object Create(ActorInitializer init) { return new UpgradeOverlay(this); } public object Create(ActorInitializer init) { return new UpgradeOverlay(this); }
} }
public class UpgradeOverlay : IRenderModifier, IUpgradable public class UpgradeOverlay : UpgradableTrait<UpgradeOverlayInfo>, IRenderModifier
{ {
readonly UpgradeOverlayInfo info;
bool enabled;
public UpgradeOverlay(UpgradeOverlayInfo info) public UpgradeOverlay(UpgradeOverlayInfo info)
{ : base (info) { }
this.info = info;
}
public IEnumerable<IRenderable> ModifyRender(Actor self, WorldRenderer wr, IEnumerable<IRenderable> r) public IEnumerable<IRenderable> ModifyRender(Actor self, WorldRenderer wr, IEnumerable<IRenderable> r)
{ {
@@ -42,22 +34,11 @@ namespace OpenRA.Mods.Common.Traits
{ {
yield return a; yield return a;
if (enabled && !a.IsDecoration) if (!IsTraitDisabled && !a.IsDecoration)
yield return a.WithPalette(wr.Palette(info.Palette)) yield return a.WithPalette(wr.Palette(Info.Palette))
.WithZOffset(a.ZOffset + 1) .WithZOffset(a.ZOffset + 1)
.AsDecoration(); .AsDecoration();
} }
} }
public bool AcceptsUpgrade(string type)
{
return type == info.RequiresUpgrade;
}
public void UpgradeAvailable(Actor self, string type, bool available)
{
if (type == info.RequiresUpgrade)
enabled = available;
}
} }
} }

View File

@@ -0,0 +1,86 @@
#region Copyright & License Information
/*
* Copyright 2007-2014 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. For more information,
* see COPYING.
*/
#endregion
using System.Collections.Generic;
using System.Linq;
using OpenRA.Traits;
namespace OpenRA.Mods.Common
{
/// <summary>Use as base class for *Info to subclass of UpgradableTrait. (See UpgradableTrait.)</summary>
public abstract class UpgradableTraitInfo
{
[Desc("The upgrade types which can enable or disable this trait.")]
public readonly string[] UpgradeTypes = { };
[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;
}
/// <summary>
/// Abstract base for enabling and disabling trait using upgrades.
/// Requires basing *Info on UpgradableTraitInfo and using base(info) constructor.
/// Note that EnabledByUpgrade is not called at creation even if this starts as enabled.
/// </summary>,
public abstract class UpgradableTrait<InfoType> : IUpgradable, IDisabledTrait, ISync where InfoType : UpgradableTraitInfo
{
public readonly InfoType Info;
public IEnumerable<string> UpgradeTypes { get { return Info.UpgradeTypes; } }
[Sync] public bool IsTraitDisabled { get; private set; }
public UpgradableTrait(InfoType info)
{
Info = info;
IsTraitDisabled = info.UpgradeTypes != null && info.UpgradeTypes.Length > 0 && info.UpgradeMinEnabledLevel > 0;
}
public bool AcceptsUpgradeLevel(Actor self, string type, int level)
{
return level > 0 && level <= Info.UpgradeMaxAcceptedLevel;
}
public void UpgradeLevelChanged(Actor self, string type, int oldLevel, int newLevel)
{
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;
var wasDisabled = IsTraitDisabled;
IsTraitDisabled = newLevel < Info.UpgradeMinEnabledLevel || newLevel > Info.UpgradeMaxEnabledLevel;
UpgradeLevelChanged(self, oldLevel, newLevel);
if (IsTraitDisabled != wasDisabled)
{
if (wasDisabled)
UpgradeEnabled(self);
else
UpgradeDisabled(self);
}
}
// Subclasses can add upgrade support by querying IsTraitDisabled and/or overriding these methods.
protected virtual void UpgradeLevelChanged(Actor self, int oldLevel, int newLevel) { }
protected virtual void UpgradeEnabled(Actor self) { }
protected virtual void UpgradeDisabled(Actor self) { }
}
}

View File

@@ -0,0 +1,160 @@
#region Copyright & License Information
/*
* Copyright 2007-2014 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. For more information,
* see COPYING.
*/
#endregion
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Common
{
public class UpgradeManagerInfo : ITraitInfo
{
public object Create(ActorInitializer init) { return new UpgradeManager(init); }
}
public class UpgradeManager : ITick
{
class TimedUpgrade
{
public readonly string Upgrade;
public readonly int Duration;
public int Remaining;
public TimedUpgrade(string upgrade, int duration)
{
Upgrade = upgrade;
Duration = duration;
Remaining = duration;
}
public void Tick() { Remaining--; }
}
class UpgradeState
{
public readonly List<IUpgradable> Traits = new List<IUpgradable>();
public readonly List<object> Sources = new List<object>();
public readonly List<Action<int, int>> Watchers = new List<Action<int, int>>();
}
readonly List<TimedUpgrade> timedUpgrades = new List<TimedUpgrade>();
readonly Lazy<Dictionary<string, UpgradeState>> upgrades;
readonly Dictionary<IUpgradable, int> levels = new Dictionary<IUpgradable, int>();
public UpgradeManager(ActorInitializer init)
{
upgrades = Exts.Lazy(() =>
{
var ret = new Dictionary<string, UpgradeState>();
foreach (var up in init.self.TraitsImplementing<IUpgradable>())
foreach (var t in up.UpgradeTypes)
ret.GetOrAdd(t).Traits.Add(up);
return ret;
});
}
public void GrantTimedUpgrade(Actor self, string upgrade, int duration)
{
var timed = timedUpgrades.FirstOrDefault(u => u.Upgrade == upgrade);
if (timed == null)
{
timed = new TimedUpgrade(upgrade, duration);
timedUpgrades.Add(timed);
GrantUpgrade(self, upgrade, timed);
}
else
timed.Remaining = Math.Max(duration, timed.Remaining);
}
// Different upgradeable traits may define (a) different level ranges for the same upgrade type,
// and (b) multiple upgrade types for the same trait. The unrestricted level for each trait is
// tracked independently so that we can can correctly revoke levels without adding the burden of
// tracking both the overall (unclamped) and effective (clamped) levels on each individual trait.
void NotifyUpgradeLevelChanged(IEnumerable<IUpgradable> traits, Actor self, string upgrade, int levelAdjust)
{
foreach (var up in traits)
{
var oldLevel = levels.GetOrAdd(up);
var newLevel = levels[up] = oldLevel + levelAdjust;
// This will internally clamp the levels to its own restricted range
up.UpgradeLevelChanged(self, upgrade, oldLevel, newLevel);
}
}
int GetOverallLevel(IUpgradable upgradable)
{
int level;
return levels.TryGetValue(upgradable, out level) ? level : 0;
}
public void GrantUpgrade(Actor self, string upgrade, object source)
{
UpgradeState s;
if (!upgrades.Value.TryGetValue(upgrade, out s))
return;
// Track the upgrade source so that the upgrade can be removed without conflicts
s.Sources.Add(source);
NotifyUpgradeLevelChanged(s.Traits, self, upgrade, 1);
}
public void RevokeUpgrade(Actor self, string upgrade, object source)
{
UpgradeState s;
if (!upgrades.Value.TryGetValue(upgrade, out s))
return;
if (!s.Sources.Remove(source))
throw new InvalidOperationException("Object <{0}> revoked more levels of upgrade {1} than it granted for {2}.".F(source, upgrade, self));
NotifyUpgradeLevelChanged(s.Traits, self, upgrade, -1);
}
public bool AcceptsUpgrade(Actor self, string upgrade)
{
UpgradeState s;
if (!upgrades.Value.TryGetValue(upgrade, out s))
return false;
return s.Traits.Any(up => up.AcceptsUpgradeLevel(self, upgrade, GetOverallLevel(up) + 1));
}
public void RegisterWatcher(string upgrade, Action<int, int> action)
{
UpgradeState s;
if (!upgrades.Value.TryGetValue(upgrade, out s))
return;
s.Watchers.Add(action);
}
public void Tick(Actor self)
{
foreach (var u in timedUpgrades)
{
u.Tick();
if (u.Remaining <= 0)
RevokeUpgrade(self, u.Upgrade, u);
foreach (var a in upgrades.Value[u.Upgrade].Watchers)
a(u.Duration, u.Remaining);
}
timedUpgrades.RemoveAll(u => u.Remaining <= 0);
}
}
}

View File

@@ -664,6 +664,33 @@ namespace OpenRA.Mods.Common.UtilityCommands
} }
} }
if (engineVersion < 20141121)
{
if (depth == 1)
{
if (node.Value.Nodes.Exists(n => n.Key == "RestrictedByUpgrade"))
{
node.Value.Nodes.Add(new MiniYamlNode("UpgradeMaxEnabledLevel", "0"));
node.Value.Nodes.Add(new MiniYamlNode("UpgradeMaxAcceptedLevel", "1"));
}
else if (node.Value.Nodes.Exists(n => n.Key == "RequiresUpgrade"))
node.Value.Nodes.Add(new MiniYamlNode("UpgradeMinEnabledLevel", "1"));
if (node.Key.StartsWith("DisableUpgrade") && !node.Value.Nodes.Any(n => n.Key == "RequiresUpgrade" || n.Key == "UpgradeTypes"))
node.Value.Nodes.Add(new MiniYamlNode("UpgradeTypes", "disable"));
if (node.Key.StartsWith("InvulnerabilityUpgrade") && !node.Value.Nodes.Any(n => n.Key == "RequiresUpgrade" || n.Key == "UpgradeTypes"))
node.Value.Nodes.Add(new MiniYamlNode("UpgradeTypes", "invulnerability"));
}
else if (depth == 2)
{
if (node.Key == "RequiresUpgrade" || node.Key == "RestrictedByUpgrade")
node.Key = "UpgradeTypes";
else if (node.Key == "-RequiresUpgrade" || node.Key == "-RestrictedByUpgrade")
node.Key = "-UpgradeTypes";
}
}
UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1); UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1);
} }
} }

View File

@@ -12,6 +12,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using OpenRA.GameRules; using OpenRA.GameRules;
using OpenRA.Mods.Common;
using OpenRA.Primitives; using OpenRA.Primitives;
using OpenRA.Traits; using OpenRA.Traits;
@@ -24,7 +25,7 @@ namespace OpenRA.Mods.RA
} }
[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 : ITraitInfo, Requires<AttackBaseInfo> public class ArmamentInfo : UpgradableTraitInfo, ITraitInfo, Requires<AttackBaseInfo>
{ {
public readonly string Name = "primary"; public readonly string Name = "primary";
@@ -53,18 +54,11 @@ namespace OpenRA.Mods.RA
[Desc("Use multiple muzzle images if non-zero")] [Desc("Use multiple muzzle images if non-zero")]
public readonly int MuzzleSplitFacings = 0; public readonly int MuzzleSplitFacings = 0;
[Desc("Enable only if this upgrade is enabled.")]
public readonly string RequiresUpgrade = null;
[Desc("Disable if this upgrade is enabled.")]
public readonly string RestrictedByUpgrade = null;
public object Create(ActorInitializer init) { return new Armament(init.self, this); } public object Create(ActorInitializer init) { return new Armament(init.self, this); }
} }
public class Armament : ITick, IExplodeModifier, IUpgradable public class Armament : UpgradableTrait<ArmamentInfo>, ITick, IExplodeModifier
{ {
public readonly ArmamentInfo Info;
public readonly WeaponInfo Weapon; public readonly WeaponInfo Weapon;
public readonly Barrel[] Barrels; public readonly Barrel[] Barrels;
@@ -78,13 +72,10 @@ namespace OpenRA.Mods.RA
public int FireDelay { get; private set; } public int FireDelay { get; private set; }
public int Burst { get; private set; } public int Burst { get; private set; }
bool requiresUpgrade;
bool restrictedByUpgrade;
public Armament(Actor self, ArmamentInfo info) public Armament(Actor self, ArmamentInfo info)
: base(info)
{ {
this.self = self; this.self = self;
Info = info;
// We can't resolve these until runtime // We can't resolve these until runtime
Turret = Exts.Lazy(() => self.TraitsImplementing<Turreted>().FirstOrDefault(t => t.Name == info.Turret)); Turret = Exts.Lazy(() => self.TraitsImplementing<Turreted>().FirstOrDefault(t => t.Name == info.Turret));
@@ -108,27 +99,11 @@ namespace OpenRA.Mods.RA
barrels.Add(new Barrel { Offset = WVec.Zero, Yaw = WAngle.Zero }); barrels.Add(new Barrel { Offset = WVec.Zero, Yaw = WAngle.Zero });
Barrels = barrels.ToArray(); Barrels = barrels.ToArray();
// Disable if an upgrade is required
requiresUpgrade = info.RequiresUpgrade != null;
}
public bool AcceptsUpgrade(string type)
{
return type == Info.RequiresUpgrade || type == Info.RestrictedByUpgrade;
}
public void UpgradeAvailable(Actor self, string type, bool available)
{
if (type == Info.RequiresUpgrade)
requiresUpgrade = !available;
else if (type == Info.RestrictedByUpgrade)
restrictedByUpgrade = available;
} }
public void Tick(Actor self) public void Tick(Actor self)
{ {
if (requiresUpgrade || restrictedByUpgrade) if (IsTraitDisabled)
return; return;
if (FireDelay > 0) if (FireDelay > 0)
@@ -226,7 +201,7 @@ namespace OpenRA.Mods.RA
return barrel; return barrel;
} }
public bool IsReloading { get { return FireDelay > 0 || requiresUpgrade || restrictedByUpgrade; } } public bool IsReloading { get { return FireDelay > 0 || IsTraitDisabled; } }
public bool ShouldExplode(Actor self) { return !IsReloading; } public bool ShouldExplode(Actor self) { return !IsReloading; }
public WVec MuzzleOffset(Actor self, Barrel b) public WVec MuzzleOffset(Actor self, Barrel b)

View File

@@ -15,6 +15,7 @@ using OpenRA.Traits;
using OpenRA.Primitives; using OpenRA.Primitives;
using OpenRA.Mods.RA.Activities; using OpenRA.Mods.RA.Activities;
using OpenRA.Mods.RA.Traits; using OpenRA.Mods.RA.Traits;
using OpenRA.Mods.Common;
using OpenRA.Mods.Common.Orders; using OpenRA.Mods.Common.Orders;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA

View File

@@ -13,12 +13,13 @@ using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using OpenRA.Graphics; using OpenRA.Graphics;
using OpenRA.Mods.Common;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
{ {
[Desc("This unit can cloak and uncloak in specific situations.")] [Desc("This unit can cloak and uncloak in specific situations.")]
public class CloakInfo : ITraitInfo public class CloakInfo : UpgradableTraitInfo, ITraitInfo
{ {
[Desc("Measured in game ticks.")] [Desc("Measured in game ticks.")]
public readonly int InitialDelay = 10; public readonly int InitialDelay = 10;
@@ -30,9 +31,6 @@ namespace OpenRA.Mods.RA
public readonly bool UncloakOnMove = false; public readonly bool UncloakOnMove = false;
public readonly bool UncloakOnUnload = true; public readonly bool UncloakOnUnload = true;
[Desc("Enable only if this upgrade is enabled.")]
public readonly string RequiresUpgrade = null;
public readonly string CloakSound = null; public readonly string CloakSound = null;
public readonly string UncloakSound = null; public readonly string UncloakSound = null;
public readonly string Palette = "cloak"; public readonly string Palette = "cloak";
@@ -42,44 +40,26 @@ namespace OpenRA.Mods.RA
public object Create(ActorInitializer init) { return new Cloak(init.self, this); } public object Create(ActorInitializer init) { return new Cloak(init.self, this); }
} }
public class Cloak : IUpgradable, IRenderModifier, INotifyDamageStateChanged, INotifyAttack, ITick, IVisibilityModifier, IRadarColorModifier, ISync public class Cloak : UpgradableTrait<CloakInfo>, IRenderModifier, INotifyDamageStateChanged, INotifyAttack, ITick, IVisibilityModifier, IRadarColorModifier
{ {
[Sync] int remainingTime; [Sync] int remainingTime;
[Sync] bool damageDisabled; [Sync] bool damageDisabled;
[Sync] bool disabled;
Actor self; Actor self;
public readonly CloakInfo Info;
CPos? lastPos; CPos? lastPos;
public Cloak(Actor self, CloakInfo info) public Cloak(Actor self, CloakInfo info)
: base (info)
{ {
this.self = self; this.self = self;
Info = info;
remainingTime = info.InitialDelay; remainingTime = info.InitialDelay;
// Disable if an upgrade is required
disabled = info.RequiresUpgrade != null;
} }
public bool AcceptsUpgrade(string type) protected override void UpgradeDisabled(Actor self)
{ {
return type == Info.RequiresUpgrade; Uncloak();
} remainingTime = Info.InitialDelay;
public void UpgradeAvailable(Actor self, string type, bool available)
{
if (type == Info.RequiresUpgrade)
{
disabled = !available;
if (disabled)
{
Uncloak();
remainingTime = Info.InitialDelay;
}
}
} }
public void Uncloak() { Uncloak(Info.CloakDelay); } public void Uncloak() { Uncloak(Info.CloakDelay); }
@@ -94,7 +74,7 @@ namespace OpenRA.Mods.RA
public void Attacking(Actor self, Target target, Armament a, Barrel barrel) { if (Info.UncloakOnAttack) Uncloak(); } public void Attacking(Actor self, Target target, Armament a, Barrel barrel) { if (Info.UncloakOnAttack) Uncloak(); }
public bool Cloaked { get { return !disabled && remainingTime <= 0; } } public bool Cloaked { get { return !IsTraitDisabled && remainingTime <= 0; } }
public void DamageStateChanged(Actor self, AttackInfo e) public void DamageStateChanged(Actor self, AttackInfo e)
{ {
@@ -105,7 +85,7 @@ namespace OpenRA.Mods.RA
public IEnumerable<IRenderable> ModifyRender(Actor self, WorldRenderer wr, IEnumerable<IRenderable> r) public IEnumerable<IRenderable> ModifyRender(Actor self, WorldRenderer wr, IEnumerable<IRenderable> r)
{ {
if (remainingTime > 0 || disabled) if (remainingTime > 0 || IsTraitDisabled)
return r; return r;
if (Cloaked && IsVisible(self, self.World.RenderPlayer)) if (Cloaked && IsVisible(self, self.World.RenderPlayer))
@@ -121,10 +101,10 @@ namespace OpenRA.Mods.RA
public void Tick(Actor self) public void Tick(Actor self)
{ {
if (disabled) if (IsTraitDisabled)
return; return;
if (remainingTime > 0 && !disabled && !damageDisabled && --remainingTime <= 0) if (remainingTime > 0 && !IsTraitDisabled && !damageDisabled && --remainingTime <= 0)
Sound.Play(Info.CloakSound, self.CenterPosition); Sound.Play(Info.CloakSound, self.CenterPosition);
if (self.IsDisabled()) if (self.IsDisabled())

View File

@@ -9,6 +9,7 @@
#endregion #endregion
using System.Linq; using System.Linq;
using OpenRA.Mods.Common;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.RA.Crates namespace OpenRA.Mods.RA.Crates

View File

@@ -11,40 +11,23 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using OpenRA.GameRules; using OpenRA.GameRules;
using OpenRA.Mods.Common;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
{ {
public class DisableUpgradeInfo : ITraitInfo public class DisableUpgradeInfo : UpgradableTraitInfo, ITraitInfo
{ {
public readonly string RequiresUpgrade = "disable";
public object Create(ActorInitializer init) { return new DisableUpgrade(this); } public object Create(ActorInitializer init) { return new DisableUpgrade(this); }
} }
public class DisableUpgrade : IUpgradable, IDisable, IDisableMove public class DisableUpgrade : UpgradableTrait<DisableUpgradeInfo>, IDisable, IDisableMove
{ {
readonly DisableUpgradeInfo info;
bool enabled;
public DisableUpgrade(DisableUpgradeInfo info) public DisableUpgrade(DisableUpgradeInfo info)
{ : base(info) { }
this.info = info;
}
public bool AcceptsUpgrade(string type) // Disable the actor when this trait is enabled.
{ public bool Disabled { get { return !IsTraitDisabled; } }
return type == info.RequiresUpgrade; public bool MoveDisabled(Actor self) { return !IsTraitDisabled; }
}
public void UpgradeAvailable(Actor self, string type, bool available)
{
if (type == info.RequiresUpgrade)
enabled = available;
}
public bool Disabled { get { return enabled; } }
public bool MoveDisabled(Actor self) { return enabled; }
} }
} }

View File

@@ -47,7 +47,7 @@ namespace OpenRA.Mods.RA
{ 200, new[] { "firepower", "damage", "speed", "reload", "inaccuracy" } }, { 200, new[] { "firepower", "damage", "speed", "reload", "inaccuracy" } },
{ 400, new[] { "firepower", "damage", "speed", "reload", "inaccuracy" } }, { 400, new[] { "firepower", "damage", "speed", "reload", "inaccuracy" } },
{ 800, new[] { "firepower", "damage", "speed", "reload", "inaccuracy" } }, { 800, new[] { "firepower", "damage", "speed", "reload", "inaccuracy" } },
{ 1600, new[] { "firepower", "damage", "speed", "reload", "inaccuracy", "selfheal" } } { 1600, new[] { "firepower", "damage", "speed", "reload", "inaccuracy", "eliteweapon", "selfheal" } }
}; };
} }

View File

@@ -11,6 +11,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using OpenRA.GameRules; using OpenRA.GameRules;
using OpenRA.Mods.Common;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
@@ -36,7 +37,7 @@ namespace OpenRA.Mods.RA
public object Create(ActorInitializer init) { return new GainsStatUpgrades(this); } public object Create(ActorInitializer init) { return new GainsStatUpgrades(this); }
} }
public class GainsStatUpgrades : IUpgradable, IFirepowerModifier, IDamageModifier, ISpeedModifier, IReloadModifier, IInaccuracyModifier public class GainsStatUpgrades : IUpgradable, IFirepowerModifier, IDamageModifier, ISpeedModifier, IReloadModifier, IInaccuracyModifier, IDisabledTrait
{ {
readonly GainsStatUpgradesInfo info; readonly GainsStatUpgradesInfo info;
[Sync] int firepowerLevel = 0; [Sync] int firepowerLevel = 0;
@@ -44,34 +45,59 @@ namespace OpenRA.Mods.RA
[Sync] int damageLevel = 0; [Sync] int damageLevel = 0;
[Sync] int reloadLevel = 0; [Sync] int reloadLevel = 0;
[Sync] int inaccuracyLevel = 0; [Sync] int inaccuracyLevel = 0;
public bool IsTraitDisabled { get { return firepowerLevel == 0 && speedLevel == 0 && damageLevel == 0 && reloadLevel == 0 && inaccuracyLevel == 0; } }
public IEnumerable<string> UpgradeTypes
{
get
{
yield return info.FirepowerUpgrade;
yield return info.DamageUpgrade;
yield return info.SpeedUpgrade;
yield return info.ReloadUpgrade;
yield return info.InaccuracyUpgrade;
}
}
public GainsStatUpgrades(GainsStatUpgradesInfo info) public GainsStatUpgrades(GainsStatUpgradesInfo info)
{ {
this.info = info; this.info = info;
} }
public bool AcceptsUpgrade(string type) public bool AcceptsUpgradeLevel(Actor self, string type, int level)
{ {
return (type == info.FirepowerUpgrade && firepowerLevel < info.FirepowerModifier.Length) if (level < 0)
|| (type == info.DamageUpgrade && damageLevel < info.DamageModifier.Length) return false;
|| (type == info.SpeedUpgrade && speedLevel < info.SpeedModifier.Length)
|| (type == info.ReloadUpgrade && reloadLevel < info.ReloadModifier.Length) if (type == info.FirepowerUpgrade)
|| (type == info.InaccuracyUpgrade && inaccuracyLevel < info.InaccuracyModifier.Length); return level <= info.FirepowerModifier.Length;
if (type == info.DamageUpgrade)
return level <= info.DamageModifier.Length;
if (type == info.SpeedUpgrade)
return level <= info.SpeedModifier.Length;
if (type == info.ReloadUpgrade)
return level <= info.ReloadModifier.Length;
if (type == info.InaccuracyUpgrade)
return level <= info.InaccuracyModifier.Length;
return false;
} }
public void UpgradeAvailable(Actor self, string type, bool available) public void UpgradeLevelChanged(Actor self, string type, int oldLevel, int newLevel)
{ {
var mod = available ? 1 : -1;
if (type == info.FirepowerUpgrade) if (type == info.FirepowerUpgrade)
firepowerLevel = (firepowerLevel + mod).Clamp(0, info.FirepowerModifier.Length); firepowerLevel = newLevel.Clamp(0, info.FirepowerModifier.Length);
else if (type == info.DamageUpgrade) else if (type == info.DamageUpgrade)
damageLevel = (damageLevel + mod).Clamp(0, info.DamageModifier.Length); damageLevel = newLevel.Clamp(0, info.DamageModifier.Length);
else if (type == info.SpeedUpgrade) else if (type == info.SpeedUpgrade)
speedLevel = (speedLevel + mod).Clamp(0, info.SpeedModifier.Length); speedLevel = newLevel.Clamp(0, info.SpeedModifier.Length);
else if (type == info.ReloadUpgrade) else if (type == info.ReloadUpgrade)
reloadLevel = (reloadLevel + mod).Clamp(0, info.ReloadModifier.Length); reloadLevel = newLevel.Clamp(0, info.ReloadModifier.Length);
else if (type == info.InaccuracyUpgrade) else if (type == info.InaccuracyUpgrade)
inaccuracyLevel = (inaccuracyLevel + mod).Clamp(0, info.InaccuracyModifier.Length); inaccuracyLevel = newLevel.Clamp(0, info.InaccuracyModifier.Length);
} }
public int GetDamageModifier(Actor attacker, DamageWarhead warhead) public int GetDamageModifier(Actor attacker, DamageWarhead warhead)

View File

@@ -12,7 +12,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using OpenRA.Mods.RA; using OpenRA.Mods.Common;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
@@ -30,6 +30,7 @@ namespace OpenRA.Mods.RA
readonly GlobalUpgradableInfo info; readonly GlobalUpgradableInfo info;
readonly GlobalUpgradeManager globalManager; readonly GlobalUpgradeManager globalManager;
readonly UpgradeManager manager; readonly UpgradeManager manager;
bool wasAvailable;
public GlobalUpgradable(Actor self, GlobalUpgradableInfo info) public GlobalUpgradable(Actor self, GlobalUpgradableInfo info)
{ {
@@ -52,13 +53,17 @@ namespace OpenRA.Mods.RA
public void PrerequisitesUpdated(Actor self, bool available) public void PrerequisitesUpdated(Actor self, bool available)
{ {
foreach (var u in info.Upgrades) if (available == wasAvailable)
{ return;
if (available)
if (available)
foreach (var u in info.Upgrades)
manager.GrantUpgrade(self, u, this); manager.GrantUpgrade(self, u, this);
else else
foreach (var u in info.Upgrades)
manager.RevokeUpgrade(self, u, this); manager.RevokeUpgrade(self, u, this);
}
wasAvailable = available;
} }
} }
} }

View File

@@ -11,41 +11,24 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using OpenRA.GameRules; using OpenRA.GameRules;
using OpenRA.Mods.Common;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
{ {
public class InvulnerabilityUpgradeInfo : ITraitInfo public class InvulnerabilityUpgradeInfo : UpgradableTraitInfo, ITraitInfo
{ {
public readonly string RequiresUpgrade = "invulnerability";
public object Create(ActorInitializer init) { return new InvulnerabilityUpgrade(this); } public object Create(ActorInitializer init) { return new InvulnerabilityUpgrade(this); }
} }
public class InvulnerabilityUpgrade : IUpgradable, IDamageModifier public class InvulnerabilityUpgrade : UpgradableTrait<InvulnerabilityUpgradeInfo>, IDamageModifier
{ {
readonly InvulnerabilityUpgradeInfo info;
bool enabled;
public InvulnerabilityUpgrade(InvulnerabilityUpgradeInfo info) public InvulnerabilityUpgrade(InvulnerabilityUpgradeInfo info)
{ : base (info) { }
this.info = info;
}
public bool AcceptsUpgrade(string type)
{
return type == info.RequiresUpgrade;
}
public void UpgradeAvailable(Actor self, string type, bool available)
{
if (type == info.RequiresUpgrade)
enabled = available;
}
public int GetDamageModifier(Actor attacker, DamageWarhead warhead) public int GetDamageModifier(Actor attacker, DamageWarhead warhead)
{ {
return enabled ? 0 : 100; return IsTraitDisabled ? 100 : 0;
} }
} }
} }

View File

@@ -12,57 +12,38 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using OpenRA.Effects;
using OpenRA.Mods.Common;
using OpenRA.Primitives; using OpenRA.Primitives;
using OpenRA.Traits; using OpenRA.Traits;
using OpenRA.Effects;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
{ {
class KillsSelfInfo : ITraitInfo class KillsSelfInfo : UpgradableTraitInfo, ITraitInfo
{ {
[Desc("Enable only if this upgrade is enabled.")]
public readonly string RequiresUpgrade = null;
[Desc("Remove the actor from the world (and destroy it) instead of killing it.")] [Desc("Remove the actor from the world (and destroy it) instead of killing it.")]
public readonly bool RemoveInstead = false; public readonly bool RemoveInstead = false;
public object Create(ActorInitializer init) { return new KillsSelf(init.self, this); } public object Create(ActorInitializer init) { return new KillsSelf(this); }
} }
class KillsSelf : INotifyAddedToWorld, IUpgradable class KillsSelf : UpgradableTrait<KillsSelfInfo>, INotifyAddedToWorld
{ {
readonly KillsSelfInfo info; public KillsSelf(KillsSelfInfo info)
readonly Actor self; : base(info) { }
public KillsSelf(Actor self, KillsSelfInfo info)
{
this.info = info;
this.self = self;
}
public void AddedToWorld(Actor self) public void AddedToWorld(Actor self)
{ {
if (info.RequiresUpgrade == null) if (!IsTraitDisabled)
Kill(); UpgradeEnabled(self);
} }
public bool AcceptsUpgrade(string type) protected override void UpgradeEnabled(Actor self)
{
return type == info.RequiresUpgrade;
}
public void UpgradeAvailable(Actor self, string type, bool available)
{
if (type == info.RequiresUpgrade)
Kill();
}
void Kill()
{ {
if (self.IsDead) if (self.IsDead)
return; return;
if (info.RemoveInstead || !self.HasTrait<Health>()) if (Info.RemoveInstead || !self.HasTrait<Health>())
self.Destroy(); self.Destroy();
else else
self.Kill(self); self.Kill(self);

View File

@@ -463,10 +463,8 @@
<Compile Include="Scripting\Properties\HelicopterProperties.cs" /> <Compile Include="Scripting\Properties\HelicopterProperties.cs" />
<Compile Include="Scripting\Properties\PlaneProperties.cs" /> <Compile Include="Scripting\Properties\PlaneProperties.cs" />
<Compile Include="SupportPowers\GrantUpgradePower.cs" /> <Compile Include="SupportPowers\GrantUpgradePower.cs" />
<Compile Include="TimedUpgradeBar.cs" />
<Compile Include="InvulnerabilityUpgrade.cs" /> <Compile Include="InvulnerabilityUpgrade.cs" />
<Compile Include="DisableUpgrade.cs" /> <Compile Include="DisableUpgrade.cs" />
<Compile Include="UpgradeManager.cs" />
<Compile Include="KillsSelf.cs" /> <Compile Include="KillsSelf.cs" />
<Compile Include="Warheads\GrantUpgradeWarhead.cs" /> <Compile Include="Warheads\GrantUpgradeWarhead.cs" />
<Compile Include="Crates\GrantUpgradeCrateAction.cs" /> <Compile Include="Crates\GrantUpgradeCrateAction.cs" />

View File

@@ -12,6 +12,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using OpenRA.Graphics; using OpenRA.Graphics;
using OpenRA.Mods.Common.Power; using OpenRA.Mods.Common.Power;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Orders namespace OpenRA.Mods.RA.Orders
{ {
@@ -39,7 +40,8 @@ namespace OpenRA.Mods.RA.Orders
if (mi.Button == MouseButton.Left) if (mi.Button == MouseButton.Left)
{ {
var underCursor = world.ScreenMap.ActorsAt(mi) var underCursor = world.ScreenMap.ActorsAt(mi)
.FirstOrDefault(a => a.Owner == world.LocalPlayer && a.HasTrait<T>()); .FirstOrDefault(a => a.Owner == world.LocalPlayer && a.TraitsImplementing<T>()
.Any(Exts.IsTraitEnabled));
if (underCursor != null) if (underCursor != null)
yield return new Order(order, underCursor, false); yield return new Order(order, underCursor, false);

View File

@@ -8,6 +8,7 @@
*/ */
#endregion #endregion
using OpenRA.Mods.Common;
using OpenRA.Scripting; using OpenRA.Scripting;
using OpenRA.Traits; using OpenRA.Traits;

View File

@@ -8,62 +8,43 @@
*/ */
#endregion #endregion
using System;
using System.Linq; using System.Linq;
using OpenRA.Mods.Common;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
{ {
[Desc("Attach this to actors which should be able to regenerate their health points.")] [Desc("Attach this to actors which should be able to regenerate their health points.")]
class SelfHealingInfo : ITraitInfo, Requires<HealthInfo> class SelfHealingInfo : UpgradableTraitInfo, ITraitInfo, Requires<HealthInfo>
{ {
public readonly int Step = 5; public readonly int Step = 5;
public readonly int Ticks = 5; public readonly int Ticks = 5;
public readonly float HealIfBelow = .5f; public readonly float HealIfBelow = .5f;
public readonly int DamageCooldown = 0; public readonly int DamageCooldown = 0;
[Desc("Enable only if this upgrade is enabled.")]
public readonly string RequiresUpgrade = null;
public virtual object Create(ActorInitializer init) { return new SelfHealing(init.self, this); } public virtual object Create(ActorInitializer init) { return new SelfHealing(init.self, this); }
} }
class SelfHealing : ITick, ISync, INotifyDamage, IUpgradable class SelfHealing : UpgradableTrait<SelfHealingInfo>, ITick, INotifyDamage
{ {
readonly SelfHealingInfo info;
readonly Health health; readonly Health health;
[Sync] int ticks; [Sync] int ticks;
[Sync] int damageTicks; [Sync] int damageTicks;
[Sync] bool disabled;
public SelfHealing(Actor self, SelfHealingInfo info) public SelfHealing(Actor self, SelfHealingInfo info)
: base (info)
{ {
this.info = info;
health = self.Trait<Health>(); health = self.Trait<Health>();
// Disable if an upgrade is required
disabled = info.RequiresUpgrade != null;
}
public bool AcceptsUpgrade(string type)
{
return type == info.RequiresUpgrade;
}
public void UpgradeAvailable(Actor self, string type, bool available)
{
if (type == info.RequiresUpgrade)
disabled = !available;
} }
public void Tick(Actor self) public void Tick(Actor self)
{ {
if (self.IsDead || disabled) if (self.IsDead || IsTraitDisabled)
return; return;
if (health.HP >= info.HealIfBelow * health.MaxHP) if (health.HP >= Info.HealIfBelow * health.MaxHP)
return; return;
if (damageTicks > 0) if (damageTicks > 0)
@@ -74,15 +55,15 @@ namespace OpenRA.Mods.RA
if (--ticks <= 0) if (--ticks <= 0)
{ {
ticks = info.Ticks; ticks = Info.Ticks;
self.InflictDamage(self, -info.Step, null); self.InflictDamage(self, -Info.Step, null);
} }
} }
public void Damaged(Actor self, AttackInfo e) public void Damaged(Actor self, AttackInfo e)
{ {
if (e.Damage > 0) if (e.Damage > 0)
damageTicks = info.DamageCooldown; damageTicks = Info.DamageCooldown;
} }
} }
} }

View File

@@ -12,6 +12,7 @@ using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using OpenRA.Graphics; using OpenRA.Graphics;
using OpenRA.Mods.Common;
using OpenRA.Mods.RA.Render; using OpenRA.Mods.RA.Render;
using OpenRA.Traits; using OpenRA.Traits;

View File

@@ -11,6 +11,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using OpenRA.GameRules; using OpenRA.GameRules;
using OpenRA.Mods.Common;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA

View File

@@ -1,134 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007-2014 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. For more information,
* see COPYING.
*/
#endregion
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
public class UpgradeManagerInfo : ITraitInfo
{
public object Create(ActorInitializer init) { return new UpgradeManager(init); }
}
public class UpgradeManager : ITick
{
class TimedUpgrade
{
public readonly string Upgrade;
public readonly int Duration;
public int Remaining;
public TimedUpgrade(string upgrade, int duration)
{
Upgrade = upgrade;
Duration = duration;
Remaining = duration;
}
public void Tick() { Remaining--; }
}
readonly List<TimedUpgrade> timedUpgrades = new List<TimedUpgrade>();
readonly Dictionary<string, List<object>> sources = new Dictionary<string, List<object>>();
readonly Dictionary<string, List<Action<int, int>>> watchers = new Dictionary<string, List<Action<int, int>>>();
readonly Lazy<IEnumerable<IUpgradable>> upgradable;
public UpgradeManager(ActorInitializer init)
{
upgradable = Exts.Lazy(() => init.self.TraitsImplementing<IUpgradable>());
}
public void GrantTimedUpgrade(Actor self, string upgrade, int duration)
{
var timed = timedUpgrades.FirstOrDefault(u => u.Upgrade == upgrade);
if (timed == null)
{
timed = new TimedUpgrade(upgrade, duration);
timedUpgrades.Add(timed);
GrantUpgrade(self, upgrade, timed);
}
else
timed.Remaining = Math.Max(duration, timed.Remaining);
}
public void GrantUpgrade(Actor self, string upgrade, object source)
{
List<object> ss;
if (!sources.TryGetValue(upgrade, out ss))
{
ss = new List<object>();
sources.Add(upgrade, ss);
foreach (var up in upgradable.Value)
if (up.AcceptsUpgrade(upgrade))
up.UpgradeAvailable(self, upgrade, true);
}
// Track the upgrade source so that the upgrade can be removed without conflicts
ss.Add(source);
}
public void RevokeUpgrade(Actor self, string upgrade, object source)
{
// This upgrade may have been granted by multiple sources
// We must be careful to only remove the upgrade after all
// sources have been revoked
List<object> ss;
if (!sources.TryGetValue(upgrade, out ss))
return;
ss.Remove(source);
if (!ss.Any())
{
foreach (var up in upgradable.Value)
if (up.AcceptsUpgrade(upgrade))
up.UpgradeAvailable(self, upgrade, false);
sources.Remove(upgrade);
}
}
public bool AcceptsUpgrade(Actor self, string upgrade)
{
return upgradable.Value.Any(up => up.AcceptsUpgrade(upgrade));
}
public void RegisterWatcher(string upgrade, Action<int, int> action)
{
if (!watchers.ContainsKey(upgrade))
watchers.Add(upgrade, new List<Action<int, int>>());
watchers[upgrade].Add(action);
}
public void Tick(Actor self)
{
foreach (var u in timedUpgrades)
{
u.Tick();
if (u.Remaining <= 0)
RevokeUpgrade(self, u.Upgrade, u);
List<Action<int, int>> actions;
if (watchers.TryGetValue(u.Upgrade, out actions))
foreach (var a in actions)
a(u.Duration, u.Remaining);
}
timedUpgrades.RemoveAll(u => u.Remaining <= 0);
}
}
}

View File

@@ -13,6 +13,7 @@ using System.Linq;
using OpenRA.Effects; using OpenRA.Effects;
using OpenRA.GameRules; using OpenRA.GameRules;
using OpenRA.Traits; using OpenRA.Traits;
using OpenRA.Mods.Common;
using OpenRA.Mods.RA.Effects; using OpenRA.Mods.RA.Effects;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA

View File

@@ -34,7 +34,8 @@
GenericName: Vehicle GenericName: Vehicle
UpdatesPlayerStatistics: UpdatesPlayerStatistics:
Cloak: Cloak:
RequiresUpgrade: cloak UpgradeTypes: cloak
UpgradeMinEnabledLevel: 1
InitialDelay: 15 InitialDelay: 15
CloakDelay: 90 CloakDelay: 90
CloakSound: trans1.aud CloakSound: trans1.aud
@@ -47,7 +48,8 @@
Ticks: 100 Ticks: 100
HealIfBelow: 1 HealIfBelow: 1
DamageCooldown: 125 DamageCooldown: 125
RequiresUpgrade: selfheal UpgradeTypes: selfheal
UpgradeMinEnabledLevel: 1
UpgradeManager: UpgradeManager:
^Tank: ^Tank:
@@ -89,7 +91,8 @@
GenericName: Tank GenericName: Tank
UpdatesPlayerStatistics: UpdatesPlayerStatistics:
Cloak: Cloak:
RequiresUpgrade: cloak UpgradeTypes: cloak
UpgradeMinEnabledLevel: 1
InitialDelay: 15 InitialDelay: 15
CloakDelay: 90 CloakDelay: 90
CloakSound: trans1.aud CloakSound: trans1.aud
@@ -102,7 +105,8 @@
Ticks: 100 Ticks: 100
HealIfBelow: 1 HealIfBelow: 1
DamageCooldown: 125 DamageCooldown: 125
RequiresUpgrade: selfheal UpgradeTypes: selfheal
UpgradeMinEnabledLevel: 1
UpgradeManager: UpgradeManager:
^Helicopter: ^Helicopter:
@@ -142,7 +146,8 @@
Ticks: 100 Ticks: 100
HealIfBelow: 1 HealIfBelow: 1
DamageCooldown: 125 DamageCooldown: 125
RequiresUpgrade: selfheal UpgradeTypes: selfheal
UpgradeMinEnabledLevel: 1
UpgradeManager: UpgradeManager:
^Infantry: ^Infantry:
@@ -201,7 +206,8 @@
Ticks: 100 Ticks: 100
HealIfBelow: 1 HealIfBelow: 1
DamageCooldown: 125 DamageCooldown: 125
RequiresUpgrade: hospitalheal UpgradeTypes: hospitalheal
UpgradeMinEnabledLevel: 1
GlobalUpgradable: GlobalUpgradable:
Upgrades: hospitalheal Upgrades: hospitalheal
Prerequisites: hosp Prerequisites: hosp
@@ -224,7 +230,8 @@
Ticks: 100 Ticks: 100
HealIfBelow: 1 HealIfBelow: 1
DamageCooldown: 125 DamageCooldown: 125
RequiresUpgrade: selfheal UpgradeTypes: selfheal
UpgradeMinEnabledLevel: 1
UpgradeManager: UpgradeManager:
^CivInfantry: ^CivInfantry:
@@ -330,7 +337,8 @@
Ticks: 100 Ticks: 100
HealIfBelow: 1 HealIfBelow: 1
DamageCooldown: 125 DamageCooldown: 125
RequiresUpgrade: selfheal UpgradeTypes: selfheal
UpgradeMinEnabledLevel: 1
UpgradeManager: UpgradeManager:
^Ship: ^Ship:
@@ -363,7 +371,8 @@
Ticks: 100 Ticks: 100
HealIfBelow: 1 HealIfBelow: 1
DamageCooldown: 125 DamageCooldown: 125
RequiresUpgrade: selfheal UpgradeTypes: selfheal
UpgradeMinEnabledLevel: 1
UpgradeManager: UpgradeManager:
^Building: ^Building:

View File

@@ -533,7 +533,7 @@ STNK:
RevealsShroud: RevealsShroud:
Range: 7c0 Range: 7c0
Cloak: Cloak:
-RequiresUpgrade: -UpgradeTypes:
InitialDelay: 90 InitialDelay: 90
CloakDelay: 90 CloakDelay: 90
CloakSound: trans1.aud CloakSound: trans1.aud

View File

@@ -44,7 +44,8 @@
Ticks: 100 Ticks: 100
HealIfBelow: 1 HealIfBelow: 1
DamageCooldown: 125 DamageCooldown: 125
RequiresUpgrade: selfheal UpgradeTypes: selfheal
UpgradeMinEnabledLevel: 1
UpgradeManager: UpgradeManager:
^Tank: ^Tank:
@@ -93,7 +94,8 @@
Ticks: 100 Ticks: 100
HealIfBelow: 1 HealIfBelow: 1
DamageCooldown: 125 DamageCooldown: 125
RequiresUpgrade: selfheal UpgradeTypes: selfheal
UpgradeMinEnabledLevel: 1
UpgradeManager: UpgradeManager:
^Husk: ^Husk:
@@ -217,7 +219,8 @@
Ticks: 100 Ticks: 100
HealIfBelow: 1 HealIfBelow: 1
DamageCooldown: 125 DamageCooldown: 125
RequiresUpgrade: selfheal UpgradeTypes: selfheal
UpgradeMinEnabledLevel: 1
UpgradeManager: UpgradeManager:
^Plane: ^Plane:
@@ -249,7 +252,8 @@
Ticks: 100 Ticks: 100
HealIfBelow: 1 HealIfBelow: 1
DamageCooldown: 125 DamageCooldown: 125
RequiresUpgrade: selfheal UpgradeTypes: selfheal
UpgradeMinEnabledLevel: 1
UpgradeManager: UpgradeManager:
^Helicopter: ^Helicopter:

View File

@@ -1300,14 +1300,16 @@ Rules:
GainsExperience: GainsExperience:
Upgrades: Upgrades:
InvulnerabilityUpgrade@UNKILLABLE: InvulnerabilityUpgrade@UNKILLABLE:
RequiresUpgrade: unkillable UpgradeTypes: unkillable
UpgradeMinEnabledLevel: 1
^Tank: ^Tank:
GivesBounty: GivesBounty:
Percentage: 0 Percentage: 0
GainsExperience: GainsExperience:
Upgrades: Upgrades:
InvulnerabilityUpgrade@UNKILLABLE: InvulnerabilityUpgrade@UNKILLABLE:
RequiresUpgrade: unkillable UpgradeTypes: unkillable
UpgradeMinEnabledLevel: 1
^Infantry: ^Infantry:
GivesBounty: GivesBounty:
Percentage: 0 Percentage: 0
@@ -1320,24 +1322,28 @@ Rules:
DeathSounds@ZAPPED: DeathSounds@ZAPPED:
VolumeMultiplier: 0.1 VolumeMultiplier: 0.1
InvulnerabilityUpgrade@UNKILLABLE: InvulnerabilityUpgrade@UNKILLABLE:
RequiresUpgrade: unkillable UpgradeTypes: unkillable
UpgradeMinEnabledLevel: 1
^Ship: ^Ship:
GivesBounty: GivesBounty:
Percentage: 0 Percentage: 0
GainsExperience: GainsExperience:
Upgrades: Upgrades:
InvulnerabilityUpgrade@UNKILLABLE: InvulnerabilityUpgrade@UNKILLABLE:
RequiresUpgrade: unkillable UpgradeTypes: unkillable
UpgradeMinEnabledLevel: 1
^Plane: ^Plane:
GivesBounty: GivesBounty:
Percentage: 0 Percentage: 0
InvulnerabilityUpgrade@UNKILLABLE: InvulnerabilityUpgrade@UNKILLABLE:
RequiresUpgrade: unkillable UpgradeTypes: unkillable
UpgradeMinEnabledLevel: 1
^Building: ^Building:
GivesBounty: GivesBounty:
Percentage: 0 Percentage: 0
InvulnerabilityUpgrade@UNKILLABLE: InvulnerabilityUpgrade@UNKILLABLE:
RequiresUpgrade: unkillable UpgradeTypes: unkillable
UpgradeMinEnabledLevel: 1
E7: E7:
-Selectable: -Selectable:

View File

@@ -658,7 +658,8 @@ Rules:
AutoTarget: AutoTarget:
InitialStance: Defend InitialStance: Defend
InvulnerabilityUpgrade@UNKILLABLE: InvulnerabilityUpgrade@UNKILLABLE:
RequiresUpgrade: unkillable UpgradeTypes: unkillable
UpgradeMinEnabledLevel: 1
SPY: SPY:
Inherits: ^Infantry Inherits: ^Infantry
Buildable: Buildable:

View File

@@ -59,12 +59,16 @@
Ticks: 100 Ticks: 100
HealIfBelow: 1 HealIfBelow: 1
DamageCooldown: 125 DamageCooldown: 125
RequiresUpgrade: selfheal UpgradeTypes: selfheal
UpgradeMinEnabledLevel: 1
UpgradeManager: UpgradeManager:
UpgradeOverlay@IRONCURTAIN: UpgradeOverlay@IRONCURTAIN:
RequiresUpgrade: invulnerability UpgradeTypes: invulnerability
UpgradeMinEnabledLevel: 1
InvulnerabilityUpgrade@IRONCURTAIN: InvulnerabilityUpgrade@IRONCURTAIN:
RequiresUpgrade: invulnerability UpgradeTypes: invulnerability
UpgradeMinEnabledLevel: 1
UpgradeMaxAcceptedLevel: 2
TimedUpgradeBar: TimedUpgradeBar:
Upgrade: invulnerability Upgrade: invulnerability
@@ -129,12 +133,16 @@
Ticks: 100 Ticks: 100
HealIfBelow: 1 HealIfBelow: 1
DamageCooldown: 125 DamageCooldown: 125
RequiresUpgrade: selfheal UpgradeTypes: selfheal
UpgradeMinEnabledLevel: 1
UpgradeManager: UpgradeManager:
UpgradeOverlay@IRONCURTAIN: UpgradeOverlay@IRONCURTAIN:
RequiresUpgrade: invulnerability UpgradeTypes: invulnerability
UpgradeMinEnabledLevel: 1
InvulnerabilityUpgrade@IRONCURTAIN: InvulnerabilityUpgrade@IRONCURTAIN:
RequiresUpgrade: invulnerability UpgradeTypes: invulnerability
UpgradeMinEnabledLevel: 1
UpgradeMaxAcceptedLevel: 2
TimedUpgradeBar: TimedUpgradeBar:
Upgrade: invulnerability Upgrade: invulnerability
@@ -192,7 +200,8 @@
Ticks: 100 Ticks: 100
HealIfBelow: 1 HealIfBelow: 1
DamageCooldown: 125 DamageCooldown: 125
RequiresUpgrade: hospitalheal UpgradeTypes: hospitalheal
UpgradeMinEnabledLevel: 1
GlobalUpgradable: GlobalUpgradable:
Upgrades: hospitalheal Upgrades: hospitalheal
Prerequisites: hosp Prerequisites: hosp
@@ -221,7 +230,8 @@
Ticks: 100 Ticks: 100
HealIfBelow: 1 HealIfBelow: 1
DamageCooldown: 125 DamageCooldown: 125
RequiresUpgrade: selfheal UpgradeTypes: selfheal
UpgradeMinEnabledLevel: 1
UpgradeManager: UpgradeManager:
^Ship: ^Ship:
@@ -263,14 +273,19 @@
Ticks: 100 Ticks: 100
HealIfBelow: 1 HealIfBelow: 1
DamageCooldown: 125 DamageCooldown: 125
RequiresUpgrade: selfheal UpgradeTypes: selfheal
UpgradeMinEnabledLevel: 1
UpgradeManager: UpgradeManager:
UpgradeOverlay@IRONCURTAIN: UpgradeOverlay@IRONCURTAIN:
RequiresUpgrade: invulnerability UpgradeTypes: invulnerability
UpgradeMinEnabledLevel: 1
InvulnerabilityUpgrade@IRONCURTAIN: InvulnerabilityUpgrade@IRONCURTAIN:
RequiresUpgrade: invulnerability UpgradeTypes: invulnerability
UpgradeMinEnabledLevel: 1
UpgradeMaxAcceptedLevel: 2
TimedUpgradeBar: TimedUpgradeBar:
Upgrade: invulnerability Upgrade: invulnerability
UpgradeMinEnabledLevel: 1
^Plane: ^Plane:
AppearsOnRadar: AppearsOnRadar:
@@ -314,12 +329,16 @@
Ticks: 100 Ticks: 100
HealIfBelow: 1 HealIfBelow: 1
DamageCooldown: 125 DamageCooldown: 125
RequiresUpgrade: selfheal UpgradeTypes: selfheal
UpgradeMinEnabledLevel: 1
UpgradeManager: UpgradeManager:
UpgradeOverlay@IRONCURTAIN: UpgradeOverlay@IRONCURTAIN:
RequiresUpgrade: invulnerability UpgradeTypes: invulnerability
UpgradeMinEnabledLevel: 1
InvulnerabilityUpgrade@IRONCURTAIN: InvulnerabilityUpgrade@IRONCURTAIN:
RequiresUpgrade: invulnerability UpgradeTypes: invulnerability
UpgradeMinEnabledLevel: 1
UpgradeMaxAcceptedLevel: 2
TimedUpgradeBar: TimedUpgradeBar:
Upgrade: invulnerability Upgrade: invulnerability
@@ -382,9 +401,12 @@
ScriptTriggers: ScriptTriggers:
UpgradeManager: UpgradeManager:
UpgradeOverlay@IRONCURTAIN: UpgradeOverlay@IRONCURTAIN:
RequiresUpgrade: invulnerability UpgradeTypes: invulnerability
UpgradeMinEnabledLevel: 1
InvulnerabilityUpgrade@IRONCURTAIN: InvulnerabilityUpgrade@IRONCURTAIN:
RequiresUpgrade: invulnerability UpgradeTypes: invulnerability
UpgradeMinEnabledLevel: 1
UpgradeMaxAcceptedLevel: 2
TimedUpgradeBar: TimedUpgradeBar:
Upgrade: invulnerability Upgrade: invulnerability

View File

@@ -655,7 +655,8 @@ DTRK:
DemoTruck: DemoTruck:
-InvulnerabilityUpgrade@IRONCURTAIN: -InvulnerabilityUpgrade@IRONCURTAIN:
KillsSelf: KillsSelf:
RequiresUpgrade: invulnerability UpgradeTypes: invulnerability
UpgradeMinEnabledLevel: 1
Chronoshiftable: Chronoshiftable:
ExplodeInstead: yes ExplodeInstead: yes

View File

@@ -45,7 +45,8 @@
WithMakeAnimation: WithMakeAnimation:
UpgradeManager: UpgradeManager:
Cloak@CLOAKGENERATOR: Cloak@CLOAKGENERATOR:
RequiresUpgrade: cloakgenerator UpgradeTypes: cloakgenerator
UpgradeMinEnabledLevel: 1
InitialDelay: 0 InitialDelay: 0
CloakDelay: 90 CloakDelay: 90
@@ -87,7 +88,8 @@
ScriptTriggers: ScriptTriggers:
UpgradeManager: UpgradeManager:
Cloak@CLOAKGENERATOR: Cloak@CLOAKGENERATOR:
RequiresUpgrade: cloakgenerator UpgradeTypes: cloakgenerator
UpgradeMinEnabledLevel: 1
InitialDelay: 0 InitialDelay: 0
CloakDelay: 90 CloakDelay: 90
@@ -138,7 +140,8 @@
Ticks: 100 Ticks: 100
HealIfBelow: 1 HealIfBelow: 1
DamageCooldown: 125 DamageCooldown: 125
RequiresUpgrade: selfheal UpgradeTypes: selfheal
UpgradeMinEnabledLevel: 1
GivesExperience: GivesExperience:
DrawLineToTarget: DrawLineToTarget:
ActorLostNotification: ActorLostNotification:
@@ -167,7 +170,8 @@
DeathTypes: 6 DeathTypes: 6
UpgradeManager: UpgradeManager:
Cloak@CLOAKGENERATOR: Cloak@CLOAKGENERATOR:
RequiresUpgrade: cloakgenerator UpgradeTypes: cloakgenerator
UpgradeMinEnabledLevel: 1
InitialDelay: 0 InitialDelay: 0
CloakDelay: 90 CloakDelay: 90
@@ -238,7 +242,8 @@
Ticks: 100 Ticks: 100
HealIfBelow: 1 HealIfBelow: 1
DamageCooldown: 125 DamageCooldown: 125
RequiresUpgrade: selfheal UpgradeTypes: selfheal
UpgradeMinEnabledLevel: 1
GivesExperience: GivesExperience:
DrawLineToTarget: DrawLineToTarget:
ActorLostNotification: ActorLostNotification:
@@ -258,15 +263,21 @@
EmptyWeapon: UnitExplodeSmall EmptyWeapon: UnitExplodeSmall
UpgradeManager: UpgradeManager:
UpgradeOverlay@EMPDISABLE: UpgradeOverlay@EMPDISABLE:
RequiresUpgrade: empdisable UpgradeTypes: empdisable
UpgradeMinEnabledLevel: 1
UpgradeMaxAcceptedLevel: 2
Palette: disabled Palette: disabled
DisableUpgrade@EMPDISABLE: DisableUpgrade@EMPDISABLE:
RequiresUpgrade: empdisable UpgradeTypes: empdisable
UpgradeMinEnabledLevel: 1
UpgradeMaxAcceptedLevel: 2
TimedUpgradeBar@EMPDISABLE: TimedUpgradeBar@EMPDISABLE:
Upgrade: empdisable Upgrade: empdisable
Color: 255,255,255 Color: 255,255,255
Cloak@CLOAKGENERATOR: Cloak@CLOAKGENERATOR:
RequiresUpgrade: cloakgenerator UpgradeTypes: cloakgenerator
UpgradeMinEnabledLevel: 1
UpgradeMaxAcceptedLevel: 2
InitialDelay: 0 InitialDelay: 0
CloakDelay: 90 CloakDelay: 90
@@ -310,7 +321,8 @@
Ticks: 100 Ticks: 100
HealIfBelow: 1 HealIfBelow: 1
DamageCooldown: 125 DamageCooldown: 125
RequiresUpgrade: selfheal UpgradeTypes: selfheal
UpgradeMinEnabledLevel: 1
GivesExperience: GivesExperience:
DrawLineToTarget: DrawLineToTarget:
ActorLostNotification: ActorLostNotification:
@@ -330,15 +342,21 @@
EmptyWeapon: UnitExplodeSmall EmptyWeapon: UnitExplodeSmall
UpgradeManager: UpgradeManager:
UpgradeOverlay@EMPDISABLE: UpgradeOverlay@EMPDISABLE:
RequiresUpgrade: empdisable UpgradeTypes: empdisable
UpgradeMinEnabledLevel: 1
UpgradeMaxAcceptedLevel: 2
Palette: disabled Palette: disabled
DisableUpgrade@EMPDISABLE: DisableUpgrade@EMPDISABLE:
RequiresUpgrade: empdisable UpgradeTypes: empdisable
UpgradeMinEnabledLevel: 1
UpgradeMaxAcceptedLevel: 2
TimedUpgradeBar@EMPDISABLE: TimedUpgradeBar@EMPDISABLE:
Upgrade: empdisable Upgrade: empdisable
Color: 255,255,255 Color: 255,255,255
Cloak@CLOAKGENERATOR: Cloak@CLOAKGENERATOR:
RequiresUpgrade: cloakgenerator UpgradeTypes: cloakgenerator
UpgradeMinEnabledLevel: 1
UpgradeMaxAcceptedLevel: 2
InitialDelay: 0 InitialDelay: 0
CloakDelay: 90 CloakDelay: 90
@@ -375,7 +393,8 @@
Ticks: 100 Ticks: 100
HealIfBelow: 1 HealIfBelow: 1
DamageCooldown: 125 DamageCooldown: 125
RequiresUpgrade: selfheal UpgradeTypes: selfheal
UpgradeMinEnabledLevel: 1
GivesExperience: GivesExperience:
DrawLineToTarget: DrawLineToTarget:
ActorLostNotification: ActorLostNotification:

View File

@@ -17,10 +17,13 @@ E1:
Speed: 71 Speed: 71
Armament@PRIMARY: Armament@PRIMARY:
Weapon: Minigun Weapon: Minigun
RestrictedByUpgrade: eliteweapon UpgradeTypes: eliteweapon
UpgradeMaxEnabledLevel: 0
UpgradeMaxAcceptedLevel: 1
Armament@ELITE: Armament@ELITE:
Weapon: M1Carbine Weapon: M1Carbine
RequiresUpgrade: eliteweapon UpgradeTypes: eliteweapon
UpgradeMinEnabledLevel: 1
AttackFrontal: AttackFrontal:
TakeCover: TakeCover:
RenderInfantry: RenderInfantry:

View File

@@ -501,12 +501,15 @@ GATICK:
Armament@PRIMARY: Armament@PRIMARY:
Weapon: 90mm Weapon: 90mm
LocalOffset: 384,0,128 LocalOffset: 384,0,128
RestrictedByUpgrade: eliteweapon UpgradeTypes: eliteweapon
UpgradeMaxEnabledLevel: 0
UpgradeMaxAcceptedLevel: 1
MuzzleSequence: muzzle MuzzleSequence: muzzle
Armament@ELITE: Armament@ELITE:
Weapon: 120mmx Weapon: 120mmx
LocalOffset: 384,0,128 LocalOffset: 384,0,128
RequiresUpgrade: eliteweapon UpgradeTypes: eliteweapon
UpgradeMinEnabledLevel: 1
MuzzleSequence: muzzle MuzzleSequence: muzzle
AttackTurreted: AttackTurreted:
BodyOrientation: BodyOrientation:

View File

@@ -624,11 +624,14 @@ BIKE:
Range: 5c0 Range: 5c0
Armament@PRIMARY: Armament@PRIMARY:
Weapon: BikeMissile Weapon: BikeMissile
RestrictedByUpgrade: eliteweapon UpgradeTypes: eliteweapon
UpgradeMaxEnabledLevel: 0
UpgradeMaxAcceptedLevel: 1
LocalOffset: -128,-170,213, -128,170,213 LocalOffset: -128,-170,213, -128,170,213
Armament@ELITE: Armament@ELITE:
Weapon: HoverMissile Weapon: HoverMissile
RequiresUpgrade: eliteweapon UpgradeTypes: eliteweapon
UpgradeMinEnabledLevel: 1
LocalOffset: -128,-170,213, -128,170,213 LocalOffset: -128,-170,213, -128,170,213
AttackFrontal: AttackFrontal:
AutoTarget: AutoTarget:
@@ -785,12 +788,15 @@ TTNK:
Armament@PRIMARY: Armament@PRIMARY:
Weapon: 90mm Weapon: 90mm
LocalOffset: 256,0,256 LocalOffset: 256,0,256
RestrictedByUpgrade: eliteweapon UpgradeTypes: eliteweapon
UpgradeMaxEnabledLevel: 0
UpgradeMaxAcceptedLevel: 1
MuzzleSequence: muzzle MuzzleSequence: muzzle
Armament@ELITE: Armament@ELITE:
Weapon: 120mmx Weapon: 120mmx
LocalOffset: 256,0,256 LocalOffset: 256,0,256
RequiresUpgrade: eliteweapon UpgradeTypes: eliteweapon
UpgradeMinEnabledLevel: 1
MuzzleSequence: muzzle MuzzleSequence: muzzle
WithMuzzleFlash: WithMuzzleFlash:
RevealsShroud: RevealsShroud: