Trial a new resource model in cnc
This commit is contained in:
@@ -200,7 +200,6 @@
|
||||
<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" />
|
||||
@@ -239,6 +238,7 @@
|
||||
<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">
|
||||
|
||||
@@ -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<PlayerResourcesInfo>().InitialCash;
|
||||
Ore = self.Info.Traits.Get<PlayerResourcesInfo>().InitialOre;
|
||||
AdviceInterval = self.Info.Traits.Get<PlayerResourcesInfo>().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<EvaAlertsInfo>().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<EvaAlertsInfo>().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<StoresOre>()
|
||||
.Sum(a => a.Actor.Info.Traits.Get<StoresOreInfo>().Capacity);
|
||||
if (--nextPowerAdviceTime <= 0)
|
||||
{
|
||||
if (PowerProvided - PowerDrained < 0)
|
||||
Owner.GiveAdvice(Rules.Info["world"].Traits.Get<EvaAlertsInfo>().LowPower);
|
||||
|
||||
nextPowerAdviceTime = AdviceInterval;
|
||||
}
|
||||
|
||||
CashCapacity = self.World.Queries.OwnedBy[Owner].WithTrait<StoresCash>()
|
||||
.Sum(a => a.Actor.Info.Traits.Get<StoresCashInfo>().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<EvaAlertsInfo>().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<EvaAlertsInfo>();
|
||||
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);
|
||||
|
||||
@@ -22,18 +22,18 @@ using System.Collections.Generic;
|
||||
|
||||
namespace OpenRA.Traits
|
||||
{
|
||||
class StoresOreInfo : TraitInfo<StoresOre>
|
||||
class StoresCashInfo : TraitInfo<StoresCash>
|
||||
{
|
||||
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<StoresOreInfo>().Capacity / 2;
|
||||
// Steal half the cash the building holds
|
||||
var toSteal = self.Info.Traits.Get<StoresCashInfo>().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<StoresOreInfo>().Pips;
|
||||
var numPips = self.Info.Traits.Get<StoresCashInfo>().Pips;
|
||||
|
||||
return Graphics.Util.MakeArray( numPips,
|
||||
i => (self.World.LocalPlayer.PlayerActor.traits.Get<PlayerResources>().GetSiloFullness() > i * 1.0f / numPips)
|
||||
@@ -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<TiberiumRefineryInfo>();
|
||||
}
|
||||
|
||||
|
||||
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<PlayerResources>();
|
||||
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<PipType> GetPips(Actor self)
|
||||
{
|
||||
return Graphics.Util.MakeArray( Info.Pips,
|
||||
i => (Tiberium * 1.0f / Info.Capacity > i * 1.0f / Info.Pips)
|
||||
? PipType.Green : PipType.Transparent );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
public void Deliver(Actor self, Actor proc)
|
||||
{
|
||||
proc.Owner.PlayerActor.traits.Get<PlayerResources>().GiveOre(contents.Sum(kv => kv.Key.ValuePerUnit * kv.Value));
|
||||
proc.traits.Get<IAcceptOre>().GiveOre(contents.Sum(kv => kv.Key.ValuePerUnit * kv.Value));
|
||||
contents.Clear();
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user