Cache ore capacity
This commit is contained in:
@@ -18,6 +18,7 @@ namespace OpenRa.Game
|
|||||||
public readonly int Index;
|
public readonly int Index;
|
||||||
public int Cash;
|
public int Cash;
|
||||||
public int Ore;
|
public int Ore;
|
||||||
|
public int OreCapacity;
|
||||||
public int DisplayCash;
|
public int DisplayCash;
|
||||||
public int PowerProvided;
|
public int PowerProvided;
|
||||||
public int PowerDrained;
|
public int PowerDrained;
|
||||||
@@ -60,10 +61,10 @@ namespace OpenRa.Game
|
|||||||
if (PowerProvided - PowerDrained != oldBalance)
|
if (PowerProvided - PowerDrained != oldBalance)
|
||||||
GiveAdvice("lopower1.aud");
|
GiveAdvice("lopower1.aud");
|
||||||
}
|
}
|
||||||
|
|
||||||
public float GetSiloFullness()
|
public float GetSiloFullness()
|
||||||
{
|
{
|
||||||
return (float)Ore / GetOreCapacity();
|
return (float)Ore / OreCapacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PowerState GetPowerState()
|
public PowerState GetPowerState()
|
||||||
@@ -73,9 +74,9 @@ namespace OpenRa.Game
|
|||||||
return PowerState.Critical;
|
return PowerState.Critical;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GetOreCapacity()
|
void UpdateOreCapacity()
|
||||||
{
|
{
|
||||||
return Game.world.Actors
|
OreCapacity = Game.world.Actors
|
||||||
.Where(a => a.Owner == this && a.traits.Contains<StoresOre>())
|
.Where(a => a.Owner == this && a.traits.Contains<StoresOre>())
|
||||||
.Select(a => a.Info as BuildingInfo)
|
.Select(a => a.Info as BuildingInfo)
|
||||||
.Where(b => b != null)
|
.Where(b => b != null)
|
||||||
@@ -95,11 +96,10 @@ namespace OpenRa.Game
|
|||||||
{
|
{
|
||||||
Ore += num;
|
Ore += num;
|
||||||
|
|
||||||
var capacity = GetOreCapacity();
|
if (Ore > OreCapacity)
|
||||||
if (Ore > capacity)
|
Ore = OreCapacity; // trim off the overflow.
|
||||||
Ore = capacity; // trim off the overflow.
|
|
||||||
|
|
||||||
if (Ore > .8 * capacity)
|
if (Ore > .8 * OreCapacity)
|
||||||
GiveAdvice("silond1.aud"); // silos needed
|
GiveAdvice("silond1.aud"); // silos needed
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,6 +123,7 @@ namespace OpenRa.Game
|
|||||||
public void Tick()
|
public void Tick()
|
||||||
{
|
{
|
||||||
UpdatePower();
|
UpdatePower();
|
||||||
|
UpdateOreCapacity();
|
||||||
|
|
||||||
if (this == Game.LocalPlayer)
|
if (this == Game.LocalPlayer)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,8 +13,6 @@ namespace OpenRa.Game.Traits
|
|||||||
|
|
||||||
public IEnumerable<PipType> GetPips()
|
public IEnumerable<PipType> GetPips()
|
||||||
{
|
{
|
||||||
if (self.Info.OrePips == 0) yield break;
|
|
||||||
|
|
||||||
for (int i = 0; i < self.Info.OrePips; i++)
|
for (int i = 0; i < self.Info.OrePips; i++)
|
||||||
{
|
{
|
||||||
if (Game.LocalPlayer.GetSiloFullness() > i * 1.0f / self.Info.OrePips)
|
if (Game.LocalPlayer.GetSiloFullness() > i * 1.0f / self.Info.OrePips)
|
||||||
|
|||||||
Reference in New Issue
Block a user