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:
Paul Chote
2010-01-08 01:26:30 +13:00
parent 42cfa7ec59
commit f3fd108a23
8 changed files with 87 additions and 45 deletions

View File

@@ -9,14 +9,16 @@ using OpenRa.Game.Graphics;
namespace OpenRa.Game.Traits
{
class Building : INotifyDamage, IOrder, ITick, IRenderModifier
class Building : INotifyDamage, IOrder, ITick
{
readonly Actor self;
public readonly BuildingInfo unitInfo;
bool isRepairing = false;
bool isPoweredDown = false;
public bool IsPoweredDown { get { return isPoweredDown; } }
bool isManuallyDisabled = false;
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)
{
this.self = self;
@@ -25,14 +27,9 @@ namespace OpenRa.Game.Traits
* ((float2)self.Location + .5f * (float2)unitInfo.Dimensions);
}
public bool InsuffientPower()
{
return (isPoweredDown || (unitInfo.Powered && self.Owner.GetPowerState() != PowerState.Normal));
}
public int GetPowerUsage()
{
if (isPoweredDown)
if (isManuallyDisabled)
return 0;
if (unitInfo.Power > 0) /* todo: is this how real-ra scales it? */
@@ -41,21 +38,6 @@ namespace OpenRa.Game.Traits
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)
{
if (e.DamageState == DamageState.Dead)
@@ -82,9 +64,8 @@ namespace OpenRa.Game.Traits
if (order.OrderString == "PowerDown")
{
isPoweredDown = !isPoweredDown;
if (isPoweredDown) Game.world.AddFrameEndTask(w => w.Add(new PowerDownIndicator(self)));
Sound.Play((isPoweredDown) ? "bleep12.aud" : "bleep11.aud");
isManuallyDisabled = !isManuallyDisabled;
Sound.Play((isManuallyDisabled) ? "bleep12.aud" : "bleep11.aud");
}
}
@@ -92,6 +73,11 @@ namespace OpenRa.Game.Traits
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 (remainingTicks == 0)