repairing buildings mostly complete

This commit is contained in:
Alli
2010-01-02 17:20:08 +13:00
parent a54909cdaf
commit 3b53f692df
4 changed files with 60 additions and 4 deletions

View File

@@ -84,6 +84,17 @@ namespace OpenRa.Game.Graphics
DrawBandBox(); DrawBandBox();
foreach(var a in Game.world.Actors.Where(b => b.Owner == Game.LocalPlayer && b.traits.Contains<Building>() && b.traits.Get<Building>().IsRepairing()))
{
var bounds = a.GetBounds(true);
var repairImages = new Animation("select");
repairImages.PlayRepeating("repair");
spriteRenderer.DrawSprite(repairImages.Image, new float2(.5f * (bounds.Left + bounds.Right)-12, .5f * (bounds.Top + bounds.Bottom)-11), PaletteType.Chrome);
}
if (Game.controller.orderGenerator != null) if (Game.controller.orderGenerator != null)
Game.controller.orderGenerator.Render(); Game.controller.orderGenerator.Render();

View File

@@ -25,7 +25,7 @@ namespace OpenRa.Game.Orders
var building = underCursor != null ? underCursor.Info as BuildingInfo : null; var building = underCursor != null ? underCursor.Info as BuildingInfo : null;
if (building == null || !building.Repairable) if (building == null || !building.Repairable || underCursor.Health == building.Strength)
{ {
yield return new Order("NoRepair", Game.LocalPlayer.PlayerActor, null, int2.Zero, null); yield return new Order("NoRepair", Game.LocalPlayer.PlayerActor, null, int2.Zero, null);
yield break; yield break;

View File

@@ -1,11 +1,16 @@
using OpenRa.Game.GameRules; using OpenRa.Game.GameRules;
using OpenRa.Game.Traits.Activities; using OpenRa.Game.Traits.Activities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OpenRa.Game.Traits namespace OpenRa.Game.Traits
{ {
class Building : INotifyDamage, IOrder class Building : INotifyDamage, IOrder, ITick
{ {
public readonly BuildingInfo unitInfo; public readonly BuildingInfo unitInfo;
bool isRepairing = false;
public Building(Actor self) public Building(Actor self)
{ {
@@ -32,6 +37,43 @@ namespace OpenRa.Game.Traits
self.CancelActivity(); self.CancelActivity();
self.QueueActivity(new Sell()); self.QueueActivity(new Sell());
} }
if (order.OrderString == "Repair")
{
isRepairing = !isRepairing;
}
}
public bool IsRepairing(){
return isRepairing;
}
int remainingTicks;
public void Tick(Actor self)
{
if (!isRepairing) return;
if (remainingTicks == 0)
{
var costPerHp = (Rules.General.URepairPercent * self.Info.Cost) / self.Info.Strength;
var hpToRepair = Math.Min(Rules.General.URepairStep, self.Info.Strength - self.Health);
var cost = (int)Math.Ceiling(costPerHp * hpToRepair);
if (!self.Owner.TakeCash(cost))
{
remainingTicks = 1;
}
self.InflictDamage(self, -hpToRepair, Rules.WarheadInfo["Super"]);
if (self.Health == self.Info.Strength)
{
isRepairing = false;
return;
}
remainingTicks = (int)(Rules.General.RepairRate * 60 * 25);
}
else
--remainingTicks;
} }
} }
} }

View File

@@ -991,4 +991,7 @@
<unit name="minv"> <unit name="minv">
<sequence name="idle" start="0" length="1" /> <sequence name="idle" start="0" length="1" />
</unit> </unit>
<unit name="select">
<sequence name="repair" start="2" length="1" />
</unit>
</sequences> </sequences>