The original method worked better; take the best of both worlds
This commit is contained in:
@@ -200,6 +200,7 @@
|
||||
<Compile Include="Traits\RallyPoint.cs" />
|
||||
<Compile Include="Traits\Render\RenderSimple.cs" />
|
||||
<Compile Include="Traits\Render\RenderUnit.cs" />
|
||||
<Compile Include="Traits\StoresOre.cs" />
|
||||
<Compile Include="Traits\Cloak.cs" />
|
||||
<Compile Include="Traits\TraitsInterfaces.cs" />
|
||||
<Compile Include="Traits\Turreted.cs" />
|
||||
@@ -238,7 +239,6 @@
|
||||
<Compile Include="GameRules\MusicInfo.cs" />
|
||||
<Compile Include="Widgets\PowerBinWidget.cs" />
|
||||
<Compile Include="Widgets\ImageWidget.cs" />
|
||||
<Compile Include="Traits\StoresCash.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||
|
||||
@@ -8,6 +8,7 @@ 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); }
|
||||
}
|
||||
@@ -23,15 +24,22 @@ namespace OpenRA.Traits
|
||||
var p = self.Owner;
|
||||
Owner = p;
|
||||
Cash = self.Info.Traits.Get<PlayerResourcesInfo>().InitialCash;
|
||||
Ore = self.Info.Traits.Get<PlayerResourcesInfo>().InitialOre;
|
||||
AdviceInterval = self.Info.Traits.Get<PlayerResourcesInfo>().AdviceInterval;
|
||||
}
|
||||
|
||||
[Sync]
|
||||
public int Cash;
|
||||
[Sync]
|
||||
public int CashCapacity;
|
||||
[Sync]
|
||||
public int DisplayCash;
|
||||
|
||||
[Sync]
|
||||
public int Ore;
|
||||
[Sync]
|
||||
public int OreCapacity;
|
||||
[Sync]
|
||||
public int DisplayOre;
|
||||
|
||||
[Sync]
|
||||
public int PowerProvided;
|
||||
[Sync]
|
||||
@@ -67,23 +75,36 @@ namespace OpenRA.Traits
|
||||
return PowerState.Critical;
|
||||
}
|
||||
|
||||
public float GetSiloFullness() { return (float)Cash / CashCapacity; }
|
||||
public float GetSiloFullness() { return (float)Ore / OreCapacity; }
|
||||
|
||||
public void GiveOre(int num)
|
||||
{
|
||||
Ore += num;
|
||||
|
||||
if (Ore > OreCapacity)
|
||||
{
|
||||
nextSiloAdviceTime = 0;
|
||||
Ore = OreCapacity;
|
||||
}
|
||||
}
|
||||
|
||||
public void GiveCash(int num)
|
||||
{
|
||||
Cash += num;
|
||||
|
||||
if (Cash > CashCapacity)
|
||||
{
|
||||
nextSiloAdviceTime = 0;
|
||||
Cash = CashCapacity;
|
||||
}
|
||||
}
|
||||
|
||||
public bool TakeCash(int num)
|
||||
{
|
||||
if (Cash < num) return false;
|
||||
if (Cash + Ore < num) return false;
|
||||
|
||||
// Spend cash before spending ore
|
||||
Cash -= num;
|
||||
if (Cash < 0)
|
||||
{
|
||||
Ore += Cash;
|
||||
Cash = 0;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -102,12 +123,12 @@ namespace OpenRA.Traits
|
||||
nextPowerAdviceTime = AdviceInterval;
|
||||
}
|
||||
|
||||
CashCapacity = self.World.Queries.OwnedBy[Owner].WithTrait<StoresCash>()
|
||||
.Sum(a => a.Actor.Info.Traits.Get<StoresCashInfo>().Capacity);
|
||||
OreCapacity = self.World.Queries.OwnedBy[Owner].WithTrait<StoresOre>()
|
||||
.Sum(a => a.Actor.Info.Traits.Get<StoresOreInfo>().Capacity);
|
||||
|
||||
if (--nextSiloAdviceTime <= 0)
|
||||
{
|
||||
if (Cash > 0.8*CashCapacity)
|
||||
if (Ore > 0.8*OreCapacity)
|
||||
Owner.GiveAdvice(Owner.World.WorldActor.Info.Traits.Get<EvaAlertsInfo>().SilosNeeded);
|
||||
|
||||
nextSiloAdviceTime = AdviceInterval;
|
||||
@@ -121,12 +142,27 @@ namespace OpenRA.Traits
|
||||
if (DisplayCash < Cash)
|
||||
{
|
||||
DisplayCash += move;
|
||||
Sound.PlayToPlayer(self.Owner, eva.CashTickUp);
|
||||
//Sound.PlayToPlayer(self.Owner, eva.CashTickUp);
|
||||
}
|
||||
else if (DisplayCash > Cash)
|
||||
{
|
||||
DisplayCash -= move;
|
||||
Sound.PlayToPlayer(self.Owner, eva.CashTickDown);
|
||||
//Sound.PlayToPlayer(self.Owner, eva.CashTickDown);
|
||||
}
|
||||
|
||||
diff = Math.Abs(Ore - DisplayOre);
|
||||
move = Math.Min(Math.Max((int)(diff * displayCashFracPerFrame),
|
||||
displayCashDeltaPerFrame), diff);
|
||||
|
||||
if (DisplayOre < Ore)
|
||||
{
|
||||
DisplayOre += move;
|
||||
//Sound.PlayToPlayer(self.Owner, eva.CashTickUp);
|
||||
}
|
||||
else if (DisplayOre > Ore)
|
||||
{
|
||||
DisplayOre -= move;
|
||||
//Sound.PlayToPlayer(self.Owner, eva.CashTickDown);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,18 +22,18 @@ using System.Collections.Generic;
|
||||
|
||||
namespace OpenRA.Traits
|
||||
{
|
||||
class StoresCashInfo : TraitInfo<StoresCash>
|
||||
class StoresOreInfo : TraitInfo<StoresOre>
|
||||
{
|
||||
public readonly int Pips = 0;
|
||||
public readonly int Capacity = 0;
|
||||
}
|
||||
|
||||
class StoresCash : IPips, IAcceptThief
|
||||
class StoresOre : IPips, IAcceptThief
|
||||
{
|
||||
public void OnSteal(Actor self, Actor thief)
|
||||
{
|
||||
// Steal half the cash the building holds
|
||||
var toSteal = self.Info.Traits.Get<StoresCashInfo>().Capacity / 2;
|
||||
var toSteal = self.Info.Traits.Get<StoresOreInfo>().Capacity / 2;
|
||||
self.Owner.PlayerActor.traits.Get<PlayerResources>().TakeCash(toSteal);
|
||||
thief.Owner.PlayerActor.traits.Get<PlayerResources>().GiveCash(toSteal);
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace OpenRA.Traits
|
||||
|
||||
public IEnumerable<PipType> GetPips(Actor self)
|
||||
{
|
||||
var numPips = self.Info.Traits.Get<StoresCashInfo>().Pips;
|
||||
var numPips = self.Info.Traits.Get<StoresOreInfo>().Pips;
|
||||
|
||||
return Graphics.Util.MakeArray( numPips,
|
||||
i => (self.World.LocalPlayer.PlayerActor.traits.Get<PlayerResources>().GetSiloFullness() > i * 1.0f / numPips)
|
||||
@@ -52,10 +52,22 @@ namespace OpenRA.Widgets
|
||||
ChromeProvider.GetImage(Game.chrome.renderer, chromeCollection, "moneybin"),
|
||||
new float2(Bounds.Left, 0), "chrome");
|
||||
|
||||
var moneyDigits = playerResources.DisplayCash.ToString();
|
||||
// Cash
|
||||
var cashDigits = playerResources.DisplayCash.ToString();
|
||||
var x = Bounds.Right - 65;
|
||||
|
||||
foreach (var d in moneyDigits.Reverse())
|
||||
foreach (var d in cashDigits.Reverse())
|
||||
{
|
||||
Game.chrome.renderer.RgbaSpriteRenderer.DrawSprite(
|
||||
ChromeProvider.GetImage(Game.chrome.renderer, digitCollection, (d - '0').ToString()),
|
||||
new float2(x, 6), "chrome");
|
||||
x -= 14;
|
||||
}
|
||||
x -= 14;
|
||||
// Ore
|
||||
var oreDigits = playerResources.DisplayOre.ToString();
|
||||
|
||||
foreach (var d in oreDigits.Reverse())
|
||||
{
|
||||
Game.chrome.renderer.RgbaSpriteRenderer.DrawSprite(
|
||||
ChromeProvider.GetImage(Game.chrome.renderer, digitCollection, (d - '0').ToString()),
|
||||
|
||||
@@ -67,11 +67,11 @@ namespace OpenRA.Mods.Cnc
|
||||
// Convert resources to cash
|
||||
var pr = self.Owner.PlayerActor.traits.Get<PlayerResources>();
|
||||
int amount = Math.Min(Tiberium, Info.ProcessAmount);
|
||||
amount = Math.Min(amount, pr.CashCapacity - pr.Cash);
|
||||
amount = Math.Min(amount, pr.OreCapacity - pr.Ore);
|
||||
if (amount > 0)
|
||||
{
|
||||
Tiberium -=amount;
|
||||
pr.GiveCash(amount);
|
||||
pr.GiveOre(amount);
|
||||
}
|
||||
nextProcessTime = Info.ProcessTick;
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ SILO:
|
||||
Armor: wood
|
||||
Sight: 4
|
||||
RenderBuildingOre:
|
||||
StoresCash:
|
||||
StoresOre:
|
||||
Pips: 5
|
||||
Capacity: 5000
|
||||
-RenderBuilding:
|
||||
|
||||
Reference in New Issue
Block a user