Refactor building power-down and Invulnerable effect. Introduces render bugs on state change (effects appearing/dissapearing a frame too late)
This commit is contained in:
30
OpenRa.Game/Effects/InvulnEffect.cs
Normal file
30
OpenRa.Game/Effects/InvulnEffect.cs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using OpenRa.Game.Graphics;
|
||||||
|
using OpenRa.Game.Traits;
|
||||||
|
|
||||||
|
namespace OpenRa.Game.Effects
|
||||||
|
{
|
||||||
|
class InvulnEffect : IEffect
|
||||||
|
{
|
||||||
|
Actor a;
|
||||||
|
IronCurtainable b;
|
||||||
|
|
||||||
|
public InvulnEffect(Actor a)
|
||||||
|
{
|
||||||
|
this.a = a;
|
||||||
|
this.b = a.traits.Get<IronCurtainable>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Tick()
|
||||||
|
{
|
||||||
|
if (a.IsDead || b.GetDamageModifier() > 0)
|
||||||
|
Game.world.AddFrameEndTask(w => w.Remove(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<Renderable> Render()
|
||||||
|
{
|
||||||
|
foreach (var r in a.Render())
|
||||||
|
yield return r.WithPalette(PaletteType.Invuln);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
36
OpenRa.Game/Effects/PowerDownIndicator.cs
Normal file
36
OpenRa.Game/Effects/PowerDownIndicator.cs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using OpenRa.Game.Graphics;
|
||||||
|
using OpenRa.Game.Traits;
|
||||||
|
|
||||||
|
namespace OpenRa.Game.Effects
|
||||||
|
{
|
||||||
|
class PowerDownIndicator : IEffect
|
||||||
|
{
|
||||||
|
Actor a;
|
||||||
|
Building b;
|
||||||
|
Animation anim = new Animation("powerdown");
|
||||||
|
|
||||||
|
public PowerDownIndicator(Actor a)
|
||||||
|
{
|
||||||
|
this.a = a;
|
||||||
|
this.b = a.traits.Get<Building>();
|
||||||
|
anim.PlayRepeating("disabled");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Tick()
|
||||||
|
{
|
||||||
|
if (!b.Disabled || a.IsDead)
|
||||||
|
Game.world.AddFrameEndTask(w => w.Remove(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<Renderable> Render()
|
||||||
|
{
|
||||||
|
foreach (var r in a.Render())
|
||||||
|
yield return r.WithPalette(PaletteType.Disabled);
|
||||||
|
|
||||||
|
if (b.ManuallyDisabled)
|
||||||
|
yield return new Renderable(anim.Image,
|
||||||
|
a.CenterLocation - .5f * anim.Image.size, PaletteType.Chrome);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -83,6 +83,7 @@
|
|||||||
<Compile Include="Effects\Corpse.cs" />
|
<Compile Include="Effects\Corpse.cs" />
|
||||||
<Compile Include="Effects\DelayedAction.cs" />
|
<Compile Include="Effects\DelayedAction.cs" />
|
||||||
<Compile Include="Effects\FlashTarget.cs" />
|
<Compile Include="Effects\FlashTarget.cs" />
|
||||||
|
<Compile Include="Effects\InvulnEffect.cs" />
|
||||||
<Compile Include="Effects\MoveFlash.cs" />
|
<Compile Include="Effects\MoveFlash.cs" />
|
||||||
<Compile Include="Effects\PowerDownIndicator.cs" />
|
<Compile Include="Effects\PowerDownIndicator.cs" />
|
||||||
<Compile Include="Effects\RepairIndicator.cs" />
|
<Compile Include="Effects\RepairIndicator.cs" />
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ namespace OpenRa.Game.Traits
|
|||||||
|
|
||||||
protected override void QueueAttack( Actor self, Order order )
|
protected override void QueueAttack( Actor self, Order order )
|
||||||
{
|
{
|
||||||
if (self.traits.Contains<Building>() && self.traits.Get<Building>().InsuffientPower())
|
if (self.traits.Contains<Building>() && self.traits.Get<Building>().Disabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const int RangeTolerance = 1; /* how far inside our maximum range we should try to sit */
|
const int RangeTolerance = 1; /* how far inside our maximum range we should try to sit */
|
||||||
|
|||||||
@@ -9,13 +9,15 @@ using OpenRa.Game.Graphics;
|
|||||||
|
|
||||||
namespace OpenRa.Game.Traits
|
namespace OpenRa.Game.Traits
|
||||||
{
|
{
|
||||||
class Building : INotifyDamage, IOrder, ITick, IRenderModifier
|
class Building : INotifyDamage, IOrder, ITick
|
||||||
{
|
{
|
||||||
readonly Actor self;
|
readonly Actor self;
|
||||||
public readonly BuildingInfo unitInfo;
|
public readonly BuildingInfo unitInfo;
|
||||||
bool isRepairing = false;
|
bool isRepairing = false;
|
||||||
bool isPoweredDown = false;
|
bool isManuallyDisabled = false;
|
||||||
public bool IsPoweredDown { get { return isPoweredDown; } }
|
bool wasManuallyDisabled = false;
|
||||||
|
public bool ManuallyDisabled { get { return isManuallyDisabled; } }
|
||||||
|
public bool Disabled { get { return (isManuallyDisabled || (unitInfo.Powered && self.Owner.GetPowerState() != PowerState.Normal)); } }
|
||||||
|
|
||||||
public Building(Actor self)
|
public Building(Actor self)
|
||||||
{
|
{
|
||||||
@@ -25,14 +27,9 @@ namespace OpenRa.Game.Traits
|
|||||||
* ((float2)self.Location + .5f * (float2)unitInfo.Dimensions);
|
* ((float2)self.Location + .5f * (float2)unitInfo.Dimensions);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool InsuffientPower()
|
|
||||||
{
|
|
||||||
return (isPoweredDown || (unitInfo.Powered && self.Owner.GetPowerState() != PowerState.Normal));
|
|
||||||
}
|
|
||||||
|
|
||||||
public int GetPowerUsage()
|
public int GetPowerUsage()
|
||||||
{
|
{
|
||||||
if (isPoweredDown)
|
if (isManuallyDisabled)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (unitInfo.Power > 0) /* todo: is this how real-ra scales it? */
|
if (unitInfo.Power > 0) /* todo: is this how real-ra scales it? */
|
||||||
@@ -41,21 +38,6 @@ namespace OpenRa.Game.Traits
|
|||||||
return unitInfo.Power;
|
return unitInfo.Power;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Animation iconAnim;
|
|
||||||
public IEnumerable<Renderable>
|
|
||||||
ModifyRender(Actor self, IEnumerable<Renderable> rs)
|
|
||||||
{
|
|
||||||
if (!InsuffientPower())
|
|
||||||
return rs;
|
|
||||||
|
|
||||||
List<Renderable> nrs = new List<Renderable>(rs);
|
|
||||||
foreach(var r in rs)
|
|
||||||
{
|
|
||||||
nrs.Add(r.WithPalette(PaletteType.Disabled));
|
|
||||||
}
|
|
||||||
return nrs;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Damaged(Actor self, AttackInfo e)
|
public void Damaged(Actor self, AttackInfo e)
|
||||||
{
|
{
|
||||||
if (e.DamageState == DamageState.Dead)
|
if (e.DamageState == DamageState.Dead)
|
||||||
@@ -82,9 +64,8 @@ namespace OpenRa.Game.Traits
|
|||||||
|
|
||||||
if (order.OrderString == "PowerDown")
|
if (order.OrderString == "PowerDown")
|
||||||
{
|
{
|
||||||
isPoweredDown = !isPoweredDown;
|
isManuallyDisabled = !isManuallyDisabled;
|
||||||
if (isPoweredDown) Game.world.AddFrameEndTask(w => w.Add(new PowerDownIndicator(self)));
|
Sound.Play((isManuallyDisabled) ? "bleep12.aud" : "bleep11.aud");
|
||||||
Sound.Play((isPoweredDown) ? "bleep12.aud" : "bleep11.aud");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,6 +73,11 @@ namespace OpenRa.Game.Traits
|
|||||||
|
|
||||||
public void Tick(Actor self)
|
public void Tick(Actor self)
|
||||||
{
|
{
|
||||||
|
// If the disabled state has changed since the last frame
|
||||||
|
if (Disabled ^ wasManuallyDisabled
|
||||||
|
&& (wasManuallyDisabled = Disabled)) // Yes, I mean assignment
|
||||||
|
Game.world.AddFrameEndTask(w => w.Add(new PowerDownIndicator(self)));
|
||||||
|
|
||||||
if (!isRepairing) return;
|
if (!isRepairing) return;
|
||||||
|
|
||||||
if (remainingTicks == 0)
|
if (remainingTicks == 0)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ using OpenRa.Game.Graphics;
|
|||||||
|
|
||||||
namespace OpenRa.Game.Traits
|
namespace OpenRa.Game.Traits
|
||||||
{
|
{
|
||||||
class IronCurtainable: IOrder, IDamageModifier, ITick, IRenderModifier
|
class IronCurtainable: IOrder, IDamageModifier, ITick
|
||||||
{
|
{
|
||||||
int RemainingTicks = 0;
|
int RemainingTicks = 0;
|
||||||
|
|
||||||
@@ -23,6 +23,7 @@ namespace OpenRa.Game.Traits
|
|||||||
{
|
{
|
||||||
return (RemainingTicks > 0) ? 0.0f : 1.0f;
|
return (RemainingTicks > 0) ? 0.0f : 1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor)
|
public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor)
|
||||||
{
|
{
|
||||||
return null; // Chronoshift order is issued through Chrome.
|
return null; // Chronoshift order is issued through Chrome.
|
||||||
@@ -33,6 +34,7 @@ namespace OpenRa.Game.Traits
|
|||||||
if (order.OrderString == "IronCurtain")
|
if (order.OrderString == "IronCurtain")
|
||||||
{
|
{
|
||||||
Game.controller.CancelInputMode();
|
Game.controller.CancelInputMode();
|
||||||
|
Game.world.AddFrameEndTask(w => w.Add(new InvulnEffect(self)));
|
||||||
RemainingTicks = (int)(Rules.General.IronCurtain * 60 * 25);
|
RemainingTicks = (int)(Rules.General.IronCurtain * 60 * 25);
|
||||||
Sound.Play("ironcur9.aud");
|
Sound.Play("ironcur9.aud");
|
||||||
// Play active anim
|
// Play active anim
|
||||||
@@ -41,18 +43,5 @@ namespace OpenRa.Game.Traits
|
|||||||
ironCurtain.traits.Get<RenderBuilding>().PlayCustomAnim(ironCurtain, "active");
|
ironCurtain.traits.Get<RenderBuilding>().PlayCustomAnim(ironCurtain, "active");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> rs)
|
|
||||||
{
|
|
||||||
if (RemainingTicks <= 0)
|
|
||||||
return rs;
|
|
||||||
|
|
||||||
List<Renderable> nrs = new List<Renderable>(rs);
|
|
||||||
foreach(var r in rs)
|
|
||||||
{
|
|
||||||
nrs.Add(r.WithPalette(PaletteType.Invuln));
|
|
||||||
}
|
|
||||||
return nrs;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ namespace OpenRa.Game.Traits
|
|||||||
foreach (var p in primaryProducers)
|
foreach (var p in primaryProducers)
|
||||||
{
|
{
|
||||||
// Ignore buildings that are disabled
|
// Ignore buildings that are disabled
|
||||||
if (p.traits.Contains<Building>() && p.traits.Get<Building>().InsuffientPower())
|
if (p.traits.Contains<Building>() && p.traits.Get<Building>().Disabled)
|
||||||
continue;
|
continue;
|
||||||
producer = p;
|
producer = p;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace OpenRa.Game.Traits
|
|||||||
|
|
||||||
// Check if powered
|
// Check if powered
|
||||||
var b = self.traits.Get<Building>();
|
var b = self.traits.Get<Building>();
|
||||||
if (b != null && b.InsuffientPower())
|
if (b != null && b.Disabled)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user