money works

This commit is contained in:
Chris Forbes
2009-11-05 21:32:34 +13:00
parent d385a89283
commit 841292fdf0
4 changed files with 25 additions and 9 deletions

View File

@@ -99,11 +99,12 @@ namespace OpenRa.Game.Graphics
lineRenderer.Flush(); lineRenderer.Flush();
renderer.DrawText(string.Format("RenderFrame {0} ({2:F1} ms)\nTick {1} ({3:F1} ms)\nOre ({4:F1} ms)", renderer.DrawText(string.Format("RenderFrame {0} ({2:F1} ms)\nTick {1} ({3:F1} ms)\nOre ({4:F1} ms)\n$ {5}",
Game.RenderFrame, Game.orderManager.FrameNumber, Game.RenderFrame, Game.orderManager.FrameNumber,
Game.RenderTime * 1000, Game.RenderTime * 1000,
Game.TickTime * 1000, Game.TickTime * 1000,
Game.OreTime * 1000), new int2(5, 5), Color.White); Game.OreTime * 1000,
Game.LocalPlayer.Cash), new int2(5, 5), Color.White);
} }
void DrawSelectionBox(Actor selectedUnit, Color c, bool drawHealthBar) void DrawSelectionBox(Actor selectedUnit, Color c, bool drawHealthBar)

View File

@@ -10,6 +10,7 @@ namespace OpenRa.Game
public string PlayerName; public string PlayerName;
public Race Race; public Race Race;
public readonly int Index; public readonly int Index;
public int Cash;
public Player( int index, int palette, string playerName, Race race ) public Player( int index, int palette, string playerName, Race race )
{ {
@@ -17,6 +18,7 @@ namespace OpenRa.Game
this.Palette = palette; this.Palette = palette;
this.PlayerName = playerName; this.PlayerName = playerName;
this.Race = race; this.Race = race;
this.Cash = 10000;
} }
public float GetSiloFullness() public float GetSiloFullness()
@@ -27,13 +29,21 @@ namespace OpenRa.Game
public void GiveCash( int num ) public void GiveCash( int num )
{ {
// TODO: increase cash // TODO: increase cash
Cash += num; // TODO: slowly
} }
public bool TakeCash( int num ) public bool TakeCash( int num )
{ {
if (Cash >= num)
{
Cash -= num;
return true;
}
return false;
// TODO: decrease cash. // TODO: decrease cash.
// returns: if enough cash was available, true // returns: if enough cash was available, true
return true; //return true;
} }
public void Tick() public void Tick()
@@ -103,7 +113,7 @@ namespace OpenRa.Game
if( Paused || Done ) return; if( Paused || Done ) return;
var costThisFrame = RemainingCost / RemainingTime; var costThisFrame = RemainingCost / RemainingTime;
if( costThisFrame == 0 && !player.TakeCash( costThisFrame ) ) return; if( costThisFrame != 0 && !player.TakeCash( costThisFrame ) ) return;
RemainingCost -= costThisFrame; RemainingCost -= costThisFrame;
RemainingTime -= 1; RemainingTime -= 1;

View File

@@ -41,9 +41,7 @@ namespace OpenRa.Game.Traits.Activities
{ {
var harv = self.traits.Get<Harvester>(); var harv = self.traits.Get<Harvester>();
/* todo: give cash */ harv.Deliver(self);
harv.gemsCarried = 0;
harv.oreCarried = 0;
if( NextActivity == null ) if( NextActivity == null )
NextActivity = new Harvest(); NextActivity = new Harvest();

View File

@@ -7,11 +7,10 @@ namespace OpenRa.Game.Traits
{ {
class Harvester : IOrder class Harvester : IOrder
{ {
const int capacity = 28;
public int oreCarried = 0; /* sum of these must not exceed capacity */ public int oreCarried = 0; /* sum of these must not exceed capacity */
public int gemsCarried = 0; public int gemsCarried = 0;
public bool IsFull { get { return oreCarried + gemsCarried == capacity; } } public bool IsFull { get { return oreCarried + gemsCarried == Rules.General.BailCount; } }
public bool IsEmpty { get { return oreCarried == 0 && gemsCarried == 0; } } public bool IsEmpty { get { return oreCarried == 0 && gemsCarried == 0; } }
public void AcceptResource(bool isGem) public void AcceptResource(bool isGem)
@@ -20,6 +19,14 @@ namespace OpenRa.Game.Traits
else oreCarried++; else oreCarried++;
} }
public void Deliver(Actor self)
{
self.Owner.GiveCash(oreCarried * Rules.General.GoldValue);
self.Owner.GiveCash(gemsCarried * Rules.General.GemValue);
oreCarried = 0;
gemsCarried = 0;
}
public Order Order(Actor self, int2 xy, bool lmb, Actor underCursor) public Order Order(Actor self, int2 xy, bool lmb, Actor underCursor)
{ {
if (lmb) return null; if (lmb) return null;