Remove RepairIndicator dependence on target RenderSimple.

This also fixes the case where the building palette doesn't
match the indicator, and saves 2 trait lookups per tick.
This commit is contained in:
Paul Chote
2013-02-24 14:30:44 +13:00
parent 3380817865
commit 43159a0e05
2 changed files with 11 additions and 9 deletions

View File

@@ -19,6 +19,7 @@ namespace OpenRA.Mods.RA.Buildings
public readonly int RepairPercent = 20; public readonly int RepairPercent = 20;
public readonly int RepairInterval = 24; public readonly int RepairInterval = 24;
public readonly int RepairStep = 7; public readonly int RepairStep = 7;
public readonly string IndicatorPalettePrefix = "player";
public object Create(ActorInitializer init) { return new RepairableBuilding(init.self, this); } public object Create(ActorInitializer init) { return new RepairableBuilding(init.self, this); }
} }
@@ -51,7 +52,7 @@ namespace OpenRA.Mods.RA.Buildings
Sound.PlayNotification(Repairer, "Speech", "Repairing", self.Owner.Country.Race); Sound.PlayNotification(Repairer, "Speech", "Repairing", self.Owner.Country.Race);
self.World.AddFrameEndTask( self.World.AddFrameEndTask(
w => w.Add(new RepairIndicator(self, p))); w => w.Add(new RepairIndicator(self, Info.IndicatorPalettePrefix, p)));
} }
} }
} }

View File

@@ -20,23 +20,23 @@ namespace OpenRA.Mods.RA.Effects
{ {
Actor building; Actor building;
Player player; Player player;
RenderSimple rs; string palettePrefix;
Animation anim = new Animation("allyrepair"); Animation anim = new Animation("allyrepair");
RepairableBuilding rb;
public RepairIndicator(Actor building, Player player) public RepairIndicator(Actor building, string palettePrefix, Player player)
{ {
this.building = building; this.building = building;
this.player = player; this.player = player;
this.palettePrefix = palettePrefix;
rb = building.Trait<RepairableBuilding>();
anim.PlayRepeating("repair"); anim.PlayRepeating("repair");
rs = building.Trait<RenderSimple>();
} }
public void Tick(World world) public void Tick(World world)
{ {
if (!building.IsInWorld || if (!building.IsInWorld || building.IsDead() ||
building.IsDead() || rb.Repairer == null || rb.Repairer != player)
building.Trait<RepairableBuilding>().Repairer == null ||
building.Trait<RepairableBuilding>().Repairer != player)
world.AddFrameEndTask(w => w.Remove(this)); world.AddFrameEndTask(w => w.Remove(this));
anim.Tick(); anim.Tick();
@@ -47,7 +47,8 @@ namespace OpenRA.Mods.RA.Effects
if (!building.Destroyed) if (!building.Destroyed)
{ {
yield return new Renderable(anim.Image, yield return new Renderable(anim.Image,
building.CenterLocation.ToFloat2() - .5f * anim.Image.size, rs.Palette(player, wr), (int)building.CenterLocation.Y); building.CenterLocation.ToFloat2() - .5f * anim.Image.size,
wr.Palette(palettePrefix+player.InternalName), (int)building.CenterLocation.Y);
} }
} }
} }