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();
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)
Game.controller.orderGenerator.Render();

View File

@@ -25,7 +25,7 @@ namespace OpenRa.Game.Orders
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 break;

View File

@@ -1,11 +1,16 @@
using OpenRa.Game.GameRules;
using OpenRa.Game.Traits.Activities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OpenRa.Game.Traits
{
class Building : INotifyDamage, IOrder
class Building : INotifyDamage, IOrder, ITick
{
public readonly BuildingInfo unitInfo;
bool isRepairing = false;
public Building(Actor self)
{
@@ -32,6 +37,43 @@ namespace OpenRa.Game.Traits
self.CancelActivity();
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

@@ -372,7 +372,7 @@
<sequence name="move-minimap" start="29" length="6" />
<sequence name="repair" start="35" length="24" />
<sequence name="deploy" start="59" length="9" x="12" y="12" />
<sequence name="sell" start="68" length="12" x="12" y="12"/>
<sequence name="sell" start="68" length="12" x="12" y="12" />
<sequence name="default-minimap" start="80" length="1" />
<sequence name="ability" start="82" length="8" />
<sequence name="nuke" start="90" length="7" x="12" y="12" />
@@ -388,7 +388,7 @@
<sequence name="guard-minimap" start="146" length="1" />
<sequence name="guard" start="147" length="1" x="12" y="12" />
<sequence name="sell-vehicle" start="148" length="12" />
<sequence name="heal" start="160" length="4" x="12" y="12"/>
<sequence name="heal" start="160" length="4" x="12" y="12" />
<sequence name="capture" start="164" length="3" />
<sequence name="capture-minimap" start="167" length="3" />
<sequence name="repair2" start="170" length="24" />
@@ -991,4 +991,7 @@
<unit name="minv">
<sequence name="idle" start="0" length="1" />
</unit>
<unit name="select">
<sequence name="repair" start="2" length="1" />
</unit>
</sequences>