Selectively power-up/down buildings via chrome

This commit is contained in:
Paul Chote
2010-01-04 21:04:57 +13:00
parent 3b0fd0e22c
commit 88c3e21ed0
10 changed files with 115 additions and 13 deletions

View File

@@ -26,12 +26,9 @@ namespace OpenRa.Game.Traits
protected override void QueueAttack( Actor self, Order order )
{
var bi = self.Info as BuildingInfo;
if (bi != null && bi.Powered && self.Owner.GetPowerState() != PowerState.Normal)
{
if (self.Owner == Game.LocalPlayer) Sound.Play("nopowr1.aud");
var bi = self.traits.Get<Building>();
if (bi != null && !bi.IsActive())
return;
}
const int RangeTolerance = 1; /* how far inside our maximum range we should try to sit */
/* todo: choose the appropriate weapon, when only one works against this target */

View File

@@ -10,15 +10,34 @@ namespace OpenRa.Game.Traits
{
class Building : INotifyDamage, IOrder, ITick
{
readonly Actor self;
public readonly BuildingInfo unitInfo;
bool isRepairing = false;
bool isPoweredDown = false;
public Building(Actor self)
{
this.self = self;
unitInfo = (BuildingInfo)self.Info;
self.CenterLocation = Game.CellSize
* ((float2)self.Location + .5f * (float2)unitInfo.Dimensions);
}
public bool IsActive()
{
return !(isPoweredDown || (unitInfo.Powered && self.Owner.GetPowerState() != PowerState.Normal));
}
public int GetPowerUsage()
{
if (isPoweredDown)
return 0;
if (unitInfo.Power > 0) /* todo: is this how real-ra scales it? */
return (self.Health * unitInfo.Power) / unitInfo.Strength;
else
return unitInfo.Power;
}
public void Damaged(Actor self, AttackInfo e)
{
@@ -43,6 +62,11 @@ namespace OpenRa.Game.Traits
{
isRepairing = !isRepairing;
}
if (order.OrderString == "PowerDown")
{
isPoweredDown = !isPoweredDown;
}
}
int remainingTicks;