power tracks damaged/destroyed correctly

This commit is contained in:
Chris Forbes
2009-12-08 20:33:54 +13:00
parent 073cdc202d
commit bcea1f01b0
2 changed files with 24 additions and 14 deletions

View File

@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using OpenRa.Game.GameRules;
using OpenRa.Game.Traits;
namespace OpenRa.Game
{
@@ -35,14 +36,27 @@ namespace OpenRa.Game
ProductionInit( cat );
}
public void ChangePower(int dPower)
void UpdatePower()
{
if (dPower > 0)
powerProvided += dPower;
if (dPower < 0)
powerDrained -= dPower;
var oldBalance = powerProvided - powerDrained;
if (powerDrained > powerProvided)
powerProvided = 0;
powerDrained = 0;
var myBuildings = Game.world.Actors
.Where(a => a.Owner == this && a.traits.Contains<Building>());
foreach (var a in myBuildings)
{
var bi = a.Info as BuildingInfo;
if (bi.Power > 0) /* todo: is this how real-ra scales it? */
powerProvided += (a.Health * bi.Power) / bi.Strength;
else
powerDrained -= bi.Power;
}
if (powerProvided - powerDrained < 0)
if (powerProvided - powerDrained != oldBalance)
GiveAdvice("lopower1.aud");
}
@@ -99,6 +113,8 @@ namespace OpenRa.Game
public void Tick()
{
UpdatePower();
foreach( var p in production )
if( p.Value != null )
p.Value.Tick( this );

View File

@@ -2,7 +2,7 @@
namespace OpenRa.Game.Traits
{
class Building : ITick, INotifyBuildComplete
class Building : ITick
{
public readonly BuildingInfo unitInfo;
@@ -19,11 +19,5 @@ namespace OpenRa.Game.Traits
first = false;
}
public void BuildingComplete(Actor self)
{
if (self.Owner != null)
self.Owner.ChangePower(unitInfo.Power);
}
}
}