split ore/cash

This commit is contained in:
Chris Forbes
2009-12-05 21:35:17 +13:00
parent 08727f5196
commit 764da53fd4
2 changed files with 23 additions and 13 deletions

View File

@@ -11,6 +11,7 @@ namespace OpenRa.Game
public Race Race; public Race Race;
public readonly int Index; public readonly int Index;
public int Cash; public int Cash;
public int Ore;
public int DisplayCash; public int DisplayCash;
int powerProvided; int powerProvided;
int powerDrained; int powerDrained;
@@ -24,6 +25,7 @@ namespace OpenRa.Game
this.PlayerName = playerName; this.PlayerName = playerName;
this.Race = race; this.Race = race;
this.Cash = 10000; this.Cash = 10000;
this.Ore = 0;
this.DisplayCash = 0; this.DisplayCash = 0;
this.powerProvided = this.powerDrained = 0; this.powerProvided = this.powerDrained = 0;
@@ -49,15 +51,21 @@ namespace OpenRa.Game
return 0.5f; /* todo: work this out the same way as RA */ return 0.5f; /* todo: work this out the same way as RA */
} }
public void GiveCash( int num ) public void GiveCash( int num ) { Cash += num; }
{ public void GiveOre(int num) { Ore += num; }
Cash += num;
}
public bool TakeCash( int num ) public bool TakeCash( int num )
{ {
if (Cash < num) return false; if (Cash + Ore < num) return false;
Cash -= num; if (Ore <= num)
{
num -= Ore;
Ore = 0;
Cash -= num;
}
else
Ore -= num;
return true; return true;
} }
@@ -71,16 +79,18 @@ namespace OpenRa.Game
if (this == Game.LocalPlayer) if (this == Game.LocalPlayer)
{ {
if (DisplayCash < Cash) var totalMoney = Cash + Ore;
if (DisplayCash < totalMoney)
{ {
DisplayCash += Math.Min(displayCashDeltaPerFrame, DisplayCash += Math.Min(displayCashDeltaPerFrame,
Cash - DisplayCash); totalMoney - DisplayCash);
Sound.Play("cashup1.aud"); Sound.Play("cashup1.aud");
} }
else if (DisplayCash > Cash) else if (DisplayCash > totalMoney)
{ {
DisplayCash -= Math.Min(displayCashDeltaPerFrame, DisplayCash -= Math.Min(displayCashDeltaPerFrame,
DisplayCash - Cash); DisplayCash - totalMoney);
Sound.Play("cashdn1.aud"); Sound.Play("cashdn1.aud");
} }
} }

View File

@@ -19,8 +19,8 @@ namespace OpenRa.Game.Traits
public void Deliver(Actor self, Actor proc) public void Deliver(Actor self, Actor proc)
{ {
proc.Owner.GiveCash(oreCarried * Rules.General.GoldValue); proc.Owner.GiveOre(oreCarried * Rules.General.GoldValue);
proc.Owner.GiveCash(gemsCarried * Rules.General.GemValue); proc.Owner.GiveOre(gemsCarried * Rules.General.GemValue);
oreCarried = 0; oreCarried = 0;
gemsCarried = 0; gemsCarried = 0;
} }