power tracks damaged/destroyed correctly
This commit is contained in:
@@ -2,6 +2,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRa.Game.GameRules;
|
using OpenRa.Game.GameRules;
|
||||||
|
using OpenRa.Game.Traits;
|
||||||
|
|
||||||
namespace OpenRa.Game
|
namespace OpenRa.Game
|
||||||
{
|
{
|
||||||
@@ -35,15 +36,28 @@ namespace OpenRa.Game
|
|||||||
ProductionInit( cat );
|
ProductionInit( cat );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ChangePower(int dPower)
|
void UpdatePower()
|
||||||
{
|
{
|
||||||
if (dPower > 0)
|
var oldBalance = powerProvided - powerDrained;
|
||||||
powerProvided += dPower;
|
|
||||||
if (dPower < 0)
|
|
||||||
powerDrained -= dPower;
|
|
||||||
|
|
||||||
if (powerDrained > powerProvided)
|
powerProvided = 0;
|
||||||
GiveAdvice("lopower1.aud");
|
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");
|
||||||
}
|
}
|
||||||
|
|
||||||
public float GetSiloFullness()
|
public float GetSiloFullness()
|
||||||
@@ -99,6 +113,8 @@ namespace OpenRa.Game
|
|||||||
|
|
||||||
public void Tick()
|
public void Tick()
|
||||||
{
|
{
|
||||||
|
UpdatePower();
|
||||||
|
|
||||||
foreach( var p in production )
|
foreach( var p in production )
|
||||||
if( p.Value != null )
|
if( p.Value != null )
|
||||||
p.Value.Tick( this );
|
p.Value.Tick( this );
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace OpenRa.Game.Traits
|
namespace OpenRa.Game.Traits
|
||||||
{
|
{
|
||||||
class Building : ITick, INotifyBuildComplete
|
class Building : ITick
|
||||||
{
|
{
|
||||||
public readonly BuildingInfo unitInfo;
|
public readonly BuildingInfo unitInfo;
|
||||||
|
|
||||||
@@ -19,11 +19,5 @@ namespace OpenRa.Game.Traits
|
|||||||
|
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void BuildingComplete(Actor self)
|
|
||||||
{
|
|
||||||
if (self.Owner != null)
|
|
||||||
self.Owner.ChangePower(unitInfo.Power);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user