Reimplement iron curtain as a generic stat upgrade.
This commit is contained in:
@@ -1,44 +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.Collections.Generic;
|
||||
using OpenRA.Effects;
|
||||
using OpenRA.Graphics;
|
||||
|
||||
namespace OpenRA.Mods.RA.Effects
|
||||
{
|
||||
class InvulnEffect : IEffect
|
||||
{
|
||||
Actor a;
|
||||
IronCurtainable b;
|
||||
|
||||
public InvulnEffect(Actor a)
|
||||
{
|
||||
this.a = a;
|
||||
this.b = a.Trait<IronCurtainable>();
|
||||
}
|
||||
|
||||
public void Tick( World world )
|
||||
{
|
||||
if (a.IsDead() || b.GetDamageModifier(null, null) > 0)
|
||||
world.AddFrameEndTask(w => w.Remove(this));
|
||||
}
|
||||
|
||||
public IEnumerable<IRenderable> Render(WorldRenderer wr)
|
||||
{
|
||||
if (a.Destroyed) // Tick will clean up
|
||||
yield break;
|
||||
|
||||
foreach (var r in a.Render(wr))
|
||||
if (!r.IsDecoration)
|
||||
yield return r.WithPalette(wr.Palette("invuln"));
|
||||
}
|
||||
}
|
||||
}
|
||||
51
OpenRA.Mods.RA/InvulnerabilityUpgrade.cs
Normal file
51
OpenRA.Mods.RA/InvulnerabilityUpgrade.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
#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 OpenRA.GameRules;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
public class InvulnerabilityUpgradeInfo : ITraitInfo
|
||||
{
|
||||
public readonly string RequiresUpgrade = "invulnerability";
|
||||
|
||||
public object Create(ActorInitializer init) { return new InvulnerabilityUpgrade(this); }
|
||||
}
|
||||
|
||||
public class InvulnerabilityUpgrade : IUpgradable, IDamageModifier
|
||||
{
|
||||
readonly InvulnerabilityUpgradeInfo info;
|
||||
bool enabled;
|
||||
|
||||
public InvulnerabilityUpgrade(InvulnerabilityUpgradeInfo 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)
|
||||
{
|
||||
return enabled ? 0 : 100;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,55 +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.Drawing;
|
||||
using OpenRA.GameRules;
|
||||
using OpenRA.Mods.RA.Effects;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
class IronCurtainableInfo : TraitInfo<IronCurtainable> { }
|
||||
|
||||
class IronCurtainable : IDamageModifier, ITick, ISync, ISelectionBar
|
||||
{
|
||||
[Sync] int RemainingTicks = 0;
|
||||
int TotalTicks;
|
||||
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
if (RemainingTicks > 0)
|
||||
RemainingTicks--;
|
||||
}
|
||||
|
||||
public int GetDamageModifier(Actor attacker, DamageWarhead warhead)
|
||||
{
|
||||
return RemainingTicks > 0 ? 0 : 100;
|
||||
}
|
||||
|
||||
public void Activate(Actor self, int duration)
|
||||
{
|
||||
if (RemainingTicks == 0)
|
||||
self.World.AddFrameEndTask(w => w.Add(new InvulnEffect(self))); // do not stack the invuln effect
|
||||
|
||||
RemainingTicks = duration;
|
||||
TotalTicks = duration;
|
||||
}
|
||||
|
||||
// Show the remaining time as a bar
|
||||
public float GetValue()
|
||||
{
|
||||
if (RemainingTicks == 0) // otherwise an empty bar is rendered all the time
|
||||
return 0f;
|
||||
|
||||
return (float)RemainingTicks / TotalTicks;
|
||||
}
|
||||
public Color GetColor() { return Color.Red; }
|
||||
}
|
||||
}
|
||||
63
OpenRA.Mods.RA/Modifiers/UpgradeOverlay.cs
Normal file
63
OpenRA.Mods.RA/Modifiers/UpgradeOverlay.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
#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 OpenRA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
[Desc("Display a colored overlay when a timed upgrade is active.")]
|
||||
public class UpgradeOverlayInfo : ITraitInfo
|
||||
{
|
||||
[Desc("Upgrade that is required before this overlay is rendered")]
|
||||
public readonly string RequiresUpgrade = null;
|
||||
|
||||
[Desc("Palette to use when rendering the overlay")]
|
||||
public readonly string Palette = "invuln";
|
||||
|
||||
public object Create(ActorInitializer init) { return new UpgradeOverlay(this); }
|
||||
}
|
||||
|
||||
public class UpgradeOverlay : IRenderModifier, IUpgradable
|
||||
{
|
||||
readonly UpgradeOverlayInfo info;
|
||||
bool enabled;
|
||||
|
||||
public UpgradeOverlay(UpgradeOverlayInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public IEnumerable<IRenderable> ModifyRender(Actor self, WorldRenderer wr, IEnumerable<IRenderable> r)
|
||||
{
|
||||
foreach (var a in r)
|
||||
{
|
||||
yield return a;
|
||||
|
||||
if (enabled && !a.IsDecoration)
|
||||
yield return a.WithPalette(wr.Palette(info.Palette))
|
||||
.WithZOffset(a.ZOffset + 1)
|
||||
.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -220,7 +220,6 @@
|
||||
<Compile Include="Effects\GpsDot.cs" />
|
||||
<Compile Include="Effects\GpsSatellite.cs" />
|
||||
<Compile Include="Effects\GravityBomb.cs" />
|
||||
<Compile Include="Effects\InvulnEffect.cs" />
|
||||
<Compile Include="Effects\LaserZap.cs" />
|
||||
<Compile Include="Effects\Missile.cs" />
|
||||
<Compile Include="Effects\NukeLaunch.cs" />
|
||||
@@ -245,7 +244,6 @@
|
||||
<Compile Include="Husk.cs" />
|
||||
<Compile Include="Infiltration\InfiltrateForSupportPower.cs" />
|
||||
<Compile Include="Invulnerable.cs" />
|
||||
<Compile Include="IronCurtainable.cs" />
|
||||
<Compile Include="JamsMissiles.cs" />
|
||||
<Compile Include="LeavesHusk.cs" />
|
||||
<Compile Include="Captures.cs" />
|
||||
@@ -359,7 +357,6 @@
|
||||
<Compile Include="SupportPowers\AirstrikePower.cs" />
|
||||
<Compile Include="SupportPowers\ChronoshiftPower.cs" />
|
||||
<Compile Include="SupportPowers\GpsPower.cs" />
|
||||
<Compile Include="SupportPowers\IronCurtainPower.cs" />
|
||||
<Compile Include="SupportPowers\NukePower.cs" />
|
||||
<Compile Include="SupportPowers\ParatroopersPower.cs" />
|
||||
<Compile Include="SupportPowers\SupportPower.cs" />
|
||||
|
||||
@@ -17,22 +17,27 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
class IronCurtainPowerInfo : SupportPowerInfo
|
||||
class GrantUpgradePowerInfo : SupportPowerInfo
|
||||
{
|
||||
[Desc("Seconds")]
|
||||
public readonly int Duration = 10;
|
||||
[Desc("The upgrades to apply.")]
|
||||
public readonly string[] Upgrades = { };
|
||||
|
||||
[Desc("Duration of the upgrade (in ticks). Set to 0 for a permanent upgrade.")]
|
||||
public readonly int Duration = 0;
|
||||
|
||||
[Desc("Cells")]
|
||||
public readonly int Range = 1;
|
||||
public readonly string IronCurtainSound = "ironcur9.aud";
|
||||
public readonly string GrantUpgradeSound = "ironcur9.aud";
|
||||
|
||||
public override object Create(ActorInitializer init) { return new IronCurtainPower(init.self, this); }
|
||||
public override object Create(ActorInitializer init) { return new GrantUpgradePower(init.self, this); }
|
||||
}
|
||||
|
||||
class IronCurtainPower : SupportPower
|
||||
class GrantUpgradePower : SupportPower
|
||||
{
|
||||
IronCurtainPowerInfo info;
|
||||
GrantUpgradePowerInfo info;
|
||||
|
||||
public IronCurtainPower(Actor self, IronCurtainPowerInfo info) : base(self, info)
|
||||
public GrantUpgradePower(Actor self, GrantUpgradePowerInfo info)
|
||||
: base(self, info)
|
||||
{
|
||||
this.info = info;
|
||||
}
|
||||
@@ -49,38 +54,59 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
self.Trait<RenderBuilding>().PlayCustomAnim(self, "active");
|
||||
|
||||
Sound.Play(info.IronCurtainSound, self.World.Map.CenterOfCell(order.TargetLocation));
|
||||
Sound.Play(info.GrantUpgradeSound, self.World.Map.CenterOfCell(order.TargetLocation));
|
||||
|
||||
foreach (var target in UnitsInRange(order.TargetLocation)
|
||||
.Where(a => a.Owner.Stances[self.Owner] == Stance.Ally))
|
||||
target.Trait<IronCurtainable>().Activate(target, ((IronCurtainPowerInfo)Info).Duration * 25);
|
||||
foreach (var a in UnitsInRange(order.TargetLocation))
|
||||
{
|
||||
var um = a.TraitOrDefault<UpgradeManager>();
|
||||
if (um == null)
|
||||
continue;
|
||||
|
||||
foreach (var u in info.Upgrades)
|
||||
{
|
||||
if (!um.AcceptsUpgrade(a, u))
|
||||
continue;
|
||||
|
||||
if (info.Duration > 0)
|
||||
um.GrantTimedUpgrade(a, u, info.Duration);
|
||||
else
|
||||
um.GrantUpgrade(a, u, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Actor> UnitsInRange(CPos xy)
|
||||
{
|
||||
var range = ((IronCurtainPowerInfo)Info).Range;
|
||||
var range = info.Range;
|
||||
var tiles = self.World.Map.FindTilesInCircle(xy, range);
|
||||
var units = new List<Actor>();
|
||||
foreach (var t in tiles)
|
||||
units.AddRange(self.World.ActorMap.GetUnitsAt(t));
|
||||
|
||||
return units.Distinct().Where(a => a.HasTrait<IronCurtainable>());
|
||||
return units.Distinct().Where(a =>
|
||||
{
|
||||
if (!a.Owner.IsAlliedWith(self.Owner))
|
||||
return false;
|
||||
|
||||
var um = a.TraitOrDefault<UpgradeManager>();
|
||||
return um != null && info.Upgrades.Any(u => um.AcceptsUpgrade(a, u));
|
||||
});
|
||||
}
|
||||
|
||||
class SelectTarget : IOrderGenerator
|
||||
{
|
||||
readonly IronCurtainPower power;
|
||||
readonly GrantUpgradePower power;
|
||||
readonly int range;
|
||||
readonly Sprite tile;
|
||||
readonly SupportPowerManager manager;
|
||||
readonly string order;
|
||||
|
||||
public SelectTarget(World world, string order, SupportPowerManager manager, IronCurtainPower power)
|
||||
public SelectTarget(World world, string order, SupportPowerManager manager, GrantUpgradePower power)
|
||||
{
|
||||
this.manager = manager;
|
||||
this.order = order;
|
||||
this.power = power;
|
||||
this.range = ((IronCurtainPowerInfo)power.Info).Range;
|
||||
this.range = power.info.Range;
|
||||
tile = world.Map.SequenceProvider.GetSequence("overlay", "target-select").GetSprite(0);
|
||||
}
|
||||
|
||||
@@ -101,8 +127,7 @@ namespace OpenRA.Mods.RA
|
||||
public IEnumerable<IRenderable> RenderAfterWorld(WorldRenderer wr, World world)
|
||||
{
|
||||
var xy = wr.Viewport.ViewToWorld(Viewport.LastMousePos);
|
||||
var targetUnits = power.UnitsInRange(xy).Where(a => a.Owner.Stances[power.self.Owner] == Stance.Ally);
|
||||
foreach (var unit in targetUnits)
|
||||
foreach (var unit in power.UnitsInRange(xy))
|
||||
yield return new SelectionBoxRenderable(unit, Color.Red);
|
||||
}
|
||||
|
||||
@@ -117,7 +142,7 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
public string GetCursor(World world, CPos xy, MouseInput mi)
|
||||
{
|
||||
return power.UnitsInRange(xy).Any(a => a.Owner.Stances[power.self.Owner] == Stance.Ally) ? "ability" : "move-blocked";
|
||||
return power.UnitsInRange(xy).Any() ? "ability" : "move-blocked";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user