diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj
index 5f95edb4db..b8cc2484bc 100755
--- a/OpenRA.Game/OpenRA.Game.csproj
+++ b/OpenRA.Game/OpenRA.Game.csproj
@@ -200,7 +200,6 @@
-
@@ -239,6 +238,7 @@
+
diff --git a/OpenRA.Game/Traits/Player/PlayerResources.cs b/OpenRA.Game/Traits/Player/PlayerResources.cs
index 480ffbfd04..04f9cfda3d 100644
--- a/OpenRA.Game/Traits/Player/PlayerResources.cs
+++ b/OpenRA.Game/Traits/Player/PlayerResources.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -8,29 +8,28 @@ namespace OpenRA.Traits
class PlayerResourcesInfo : ITraitInfo
{
public readonly int InitialCash = 10000;
- public readonly int InitialOre = 0;
-
+ public readonly int AdviceInterval = 250;
public object Create(Actor self) { return new PlayerResources(self); }
}
public class PlayerResources : ITick
{
Player Owner;
-
+ int AdviceInterval;
+ int nextSiloAdviceTime = 0;
+ int nextPowerAdviceTime = 0;
public PlayerResources(Actor self)
{
var p = self.Owner;
Owner = p;
Cash = self.Info.Traits.Get().InitialCash;
- Ore = self.Info.Traits.Get().InitialOre;
+ AdviceInterval = self.Info.Traits.Get().AdviceInterval;
}
[Sync]
public int Cash;
[Sync]
- public int Ore;
- [Sync]
- public int OreCapacity;
+ public int CashCapacity;
[Sync]
public int DisplayCash;
[Sync]
@@ -58,7 +57,7 @@ namespace OpenRA.Traits
if (PowerProvided - PowerDrained < 0)
if (PowerProvided - PowerDrained != oldBalance)
- Owner.GiveAdvice(Rules.Info["world"].Traits.Get().LowPower);
+ nextPowerAdviceTime = 0;
}
public PowerState GetPowerState()
@@ -68,32 +67,23 @@ namespace OpenRA.Traits
return PowerState.Critical;
}
- public float GetSiloFullness() { return (float)Ore / OreCapacity; }
+ public float GetSiloFullness() { return (float)Cash / CashCapacity; }
- public void GiveCash(int num) { Cash += num; }
- public void GiveOre(int num)
+ public void GiveCash(int num)
{
- Ore += num;
-
- if (Ore > OreCapacity)
- Ore = OreCapacity; // trim off the overflow.
-
- if (Ore > .8 * OreCapacity)
- Owner.GiveAdvice(Owner.World.WorldActor.Info.Traits.Get().SilosNeeded);
- }
-
- public bool TakeCash(int num)
- {
- if (Cash + Ore < num) return false;
- if (Ore <= num)
+ Cash += num;
+
+ if (Cash > CashCapacity)
{
- num -= Ore;
- Ore = 0;
- Cash -= num;
+ nextSiloAdviceTime = 0;
+ Cash = CashCapacity;
}
- else
- Ore -= num;
-
+ }
+
+ public bool TakeCash(int num)
+ {
+ if (Cash < num) return false;
+ Cash -= num;
return true;
}
@@ -104,21 +94,36 @@ namespace OpenRA.Traits
{
UpdatePower();
- OreCapacity = self.World.Queries.OwnedBy[Owner].WithTrait()
- .Sum(a => a.Actor.Info.Traits.Get().Capacity);
+ if (--nextPowerAdviceTime <= 0)
+ {
+ if (PowerProvided - PowerDrained < 0)
+ Owner.GiveAdvice(Rules.Info["world"].Traits.Get().LowPower);
+
+ nextPowerAdviceTime = AdviceInterval;
+ }
+
+ CashCapacity = self.World.Queries.OwnedBy[Owner].WithTrait()
+ .Sum(a => a.Actor.Info.Traits.Get().Capacity);
- var totalMoney = Cash + Ore;
- var diff = Math.Abs(totalMoney - DisplayCash);
+ if (--nextSiloAdviceTime <= 0)
+ {
+ if (Cash > 0.8*CashCapacity)
+ Owner.GiveAdvice(Owner.World.WorldActor.Info.Traits.Get().SilosNeeded);
+
+ nextSiloAdviceTime = AdviceInterval;
+ }
+
+ var diff = Math.Abs(Cash - DisplayCash);
var move = Math.Min(Math.Max((int)(diff * displayCashFracPerFrame),
displayCashDeltaPerFrame), diff);
var eva = self.World.WorldActor.Info.Traits.Get();
- if (DisplayCash < totalMoney)
+ if (DisplayCash < Cash)
{
DisplayCash += move;
Sound.PlayToPlayer(self.Owner, eva.CashTickUp);
}
- else if (DisplayCash > totalMoney)
+ else if (DisplayCash > Cash)
{
DisplayCash -= move;
Sound.PlayToPlayer(self.Owner, eva.CashTickDown);
diff --git a/OpenRA.Game/Traits/StoresOre.cs b/OpenRA.Game/Traits/StoresCash.cs
similarity index 83%
rename from OpenRA.Game/Traits/StoresOre.cs
rename to OpenRA.Game/Traits/StoresCash.cs
index b92b5437f3..a234eb1069 100644
--- a/OpenRA.Game/Traits/StoresOre.cs
+++ b/OpenRA.Game/Traits/StoresCash.cs
@@ -22,18 +22,18 @@ using System.Collections.Generic;
namespace OpenRA.Traits
{
- class StoresOreInfo : TraitInfo
+ class StoresCashInfo : TraitInfo
{
public readonly int Pips = 0;
public readonly int Capacity = 0;
}
- class StoresOre : IPips, IAcceptThief
+ class StoresCash : IPips, IAcceptThief
{
public void OnSteal(Actor self, Actor thief)
{
- // Steal half the ore the building holds
- var toSteal = self.Info.Traits.Get().Capacity / 2;
+ // Steal half the cash the building holds
+ var toSteal = self.Info.Traits.Get().Capacity / 2;
self.Owner.PlayerActor.traits.Get().TakeCash(toSteal);
thief.Owner.PlayerActor.traits.Get().GiveCash(toSteal);
@@ -43,7 +43,7 @@ namespace OpenRA.Traits
public IEnumerable GetPips(Actor self)
{
- var numPips = self.Info.Traits.Get().Pips;
+ var numPips = self.Info.Traits.Get().Pips;
return Graphics.Util.MakeArray( numPips,
i => (self.World.LocalPlayer.PlayerActor.traits.Get().GetSiloFullness() > i * 1.0f / numPips)
diff --git a/OpenRA.Mods.Cnc/TiberiumRefinery.cs b/OpenRA.Mods.Cnc/TiberiumRefinery.cs
index dd2c12e02f..8fddb35c4d 100644
--- a/OpenRA.Mods.Cnc/TiberiumRefinery.cs
+++ b/OpenRA.Mods.Cnc/TiberiumRefinery.cs
@@ -18,6 +18,9 @@
*/
#endregion
+using System;
+using System.Linq;
+using System.Collections.Generic;
using OpenRA.Mods.RA;
using OpenRA.Mods.RA.Activities;
using OpenRA.Traits;
@@ -27,17 +30,53 @@ namespace OpenRA.Mods.Cnc
{
class TiberiumRefineryInfo : ITraitInfo
{
+ public readonly int Pips = 0;
+ public readonly int Capacity = 0;
+ public readonly int ProcessTick = 25;
+ public readonly int ProcessAmount = 50;
public object Create(Actor self) { return new TiberiumRefinery(self); }
}
- class TiberiumRefinery : IAcceptOre
+ class TiberiumRefinery : ITick, IAcceptOre, IPips
{
Actor self;
+ TiberiumRefineryInfo Info;
+
+ [Sync]
+ int nextProcessTime = 0;
+ [Sync]
+ public int Tiberium = 0;
+
public TiberiumRefinery(Actor self)
{
this.self = self;
+ Info = self.Info.Traits.Get();
}
-
+
+ public void GiveOre(int amount)
+ {
+ Tiberium += amount;
+ if (Tiberium > Info.Capacity)
+ Tiberium = Info.Capacity;
+ }
+
+ public void Tick(Actor self)
+ {
+ if (--nextProcessTime <= 0)
+ {
+ // Convert resources to cash
+ var pr = self.Owner.PlayerActor.traits.Get();
+ int amount = Math.Min(Tiberium, Info.ProcessAmount);
+ amount = Math.Min(amount, pr.CashCapacity - pr.Cash);
+ if (amount > 0)
+ {
+ Tiberium -=amount;
+ pr.GiveCash(amount);
+ }
+ nextProcessTime = Info.ProcessTick;
+ }
+ }
+
public int2 DeliverOffset { get { return new int2(0, 2); } }
public void OnDock(Actor harv, DeliverResources dockOrder)
{
@@ -51,5 +90,12 @@ namespace OpenRA.Mods.Cnc
harv.QueueActivity(new Harvest());
})));
}
+
+ public IEnumerable GetPips(Actor self)
+ {
+ return Graphics.Util.MakeArray( Info.Pips,
+ i => (Tiberium * 1.0f / Info.Capacity > i * 1.0f / Info.Pips)
+ ? PipType.Green : PipType.Transparent );
+ }
}
}
diff --git a/OpenRA.Mods.RA/Harvester.cs b/OpenRA.Mods.RA/Harvester.cs
index d9d5c46dcc..4656f4fb8f 100755
--- a/OpenRA.Mods.RA/Harvester.cs
+++ b/OpenRA.Mods.RA/Harvester.cs
@@ -56,7 +56,7 @@ namespace OpenRA.Mods.RA
public void Deliver(Actor self, Actor proc)
{
- proc.Owner.PlayerActor.traits.Get().GiveOre(contents.Sum(kv => kv.Key.ValuePerUnit * kv.Value));
+ proc.traits.Get().GiveOre(contents.Sum(kv => kv.Key.ValuePerUnit * kv.Value));
contents.Clear();
}
diff --git a/OpenRA.Mods.RA/OreRefinery.cs b/OpenRA.Mods.RA/OreRefinery.cs
index 206f512847..89fbf2651c 100755
--- a/OpenRA.Mods.RA/OreRefinery.cs
+++ b/OpenRA.Mods.RA/OreRefinery.cs
@@ -36,6 +36,11 @@ namespace OpenRA.Mods.RA
{
this.self = self;
}
+
+ public void GiveOre(int amount)
+ {
+ // TODO: Unbreak this
+ }
public int2 DeliverOffset { get { return new int2(1, 2); } }
public void OnDock(Actor harv, DeliverResources dockOrder)
{
diff --git a/OpenRA.Mods.RA/TraitsInterfaces.cs b/OpenRA.Mods.RA/TraitsInterfaces.cs
index e4b4b63c07..75dfa465ca 100755
--- a/OpenRA.Mods.RA/TraitsInterfaces.cs
+++ b/OpenRA.Mods.RA/TraitsInterfaces.cs
@@ -1,4 +1,4 @@
-#region Copyright & License Information
+#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
@@ -25,6 +25,7 @@ namespace OpenRA.Mods.RA
public interface IAcceptOre
{
void OnDock(Actor harv, DeliverResources dockOrder);
+ void GiveOre(int amount);
int2 DeliverOffset { get; }
}
}
diff --git a/mods/cnc/structures.yaml b/mods/cnc/structures.yaml
index bdb5a013aa..ce671be095 100644
--- a/mods/cnc/structures.yaml
+++ b/mods/cnc/structures.yaml
@@ -42,7 +42,7 @@ PROC:
Buildable:
Icon: procicnh
BuildPaletteOrder: 30
- Prerequisites: nuke
+ Prerequisites: silo
Owner: gdi,nod
Cost: 2000
Description: Tiberium Refinery
@@ -58,9 +58,10 @@ PROC:
Sight: 6
Bib:
TiberiumRefinery:
- StoresOre:
- Pips: 17
+ Pips: 10
Capacity: 1000
+ ProcessTick: 25
+ ProcessAmount: 50
CustomSellValue:
Value: 600
HasUnitOnBuild:
@@ -74,11 +75,11 @@ SILO:
Buildable:
Icon: siloicnh
BuildPaletteOrder: 20
- Prerequisites: proc
+ Prerequisites: nuke
Owner: gdi,nod
Cost: 150
Description: Tiberium Silo
- LongDesc: Stores excess Tiberium until it can be processed
+ LongDesc: Stores processed Tiberium
Building:
Power: -10
Footprint: xx
@@ -88,9 +89,9 @@ SILO:
Armor: wood
Sight: 4
RenderBuildingOre:
- StoresOre:
+ StoresCash:
Pips: 5
- Capacity: 1500
+ Capacity: 5000
-RenderBuilding:
PYLE: