Trial a new resource model in cnc
This commit is contained in:
@@ -200,7 +200,6 @@
|
|||||||
<Compile Include="Traits\RallyPoint.cs" />
|
<Compile Include="Traits\RallyPoint.cs" />
|
||||||
<Compile Include="Traits\Render\RenderSimple.cs" />
|
<Compile Include="Traits\Render\RenderSimple.cs" />
|
||||||
<Compile Include="Traits\Render\RenderUnit.cs" />
|
<Compile Include="Traits\Render\RenderUnit.cs" />
|
||||||
<Compile Include="Traits\StoresOre.cs" />
|
|
||||||
<Compile Include="Traits\Cloak.cs" />
|
<Compile Include="Traits\Cloak.cs" />
|
||||||
<Compile Include="Traits\TraitsInterfaces.cs" />
|
<Compile Include="Traits\TraitsInterfaces.cs" />
|
||||||
<Compile Include="Traits\Turreted.cs" />
|
<Compile Include="Traits\Turreted.cs" />
|
||||||
@@ -239,6 +238,7 @@
|
|||||||
<Compile Include="GameRules\MusicInfo.cs" />
|
<Compile Include="GameRules\MusicInfo.cs" />
|
||||||
<Compile Include="Widgets\PowerBinWidget.cs" />
|
<Compile Include="Widgets\PowerBinWidget.cs" />
|
||||||
<Compile Include="Widgets\ImageWidget.cs" />
|
<Compile Include="Widgets\ImageWidget.cs" />
|
||||||
|
<Compile Include="Traits\StoresCash.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@@ -8,29 +8,28 @@ namespace OpenRA.Traits
|
|||||||
class PlayerResourcesInfo : ITraitInfo
|
class PlayerResourcesInfo : ITraitInfo
|
||||||
{
|
{
|
||||||
public readonly int InitialCash = 10000;
|
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 object Create(Actor self) { return new PlayerResources(self); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PlayerResources : ITick
|
public class PlayerResources : ITick
|
||||||
{
|
{
|
||||||
Player Owner;
|
Player Owner;
|
||||||
|
int AdviceInterval;
|
||||||
|
int nextSiloAdviceTime = 0;
|
||||||
|
int nextPowerAdviceTime = 0;
|
||||||
public PlayerResources(Actor self)
|
public PlayerResources(Actor self)
|
||||||
{
|
{
|
||||||
var p = self.Owner;
|
var p = self.Owner;
|
||||||
Owner = p;
|
Owner = p;
|
||||||
Cash = self.Info.Traits.Get<PlayerResourcesInfo>().InitialCash;
|
Cash = self.Info.Traits.Get<PlayerResourcesInfo>().InitialCash;
|
||||||
Ore = self.Info.Traits.Get<PlayerResourcesInfo>().InitialOre;
|
AdviceInterval = self.Info.Traits.Get<PlayerResourcesInfo>().AdviceInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Sync]
|
[Sync]
|
||||||
public int Cash;
|
public int Cash;
|
||||||
[Sync]
|
[Sync]
|
||||||
public int Ore;
|
public int CashCapacity;
|
||||||
[Sync]
|
|
||||||
public int OreCapacity;
|
|
||||||
[Sync]
|
[Sync]
|
||||||
public int DisplayCash;
|
public int DisplayCash;
|
||||||
[Sync]
|
[Sync]
|
||||||
@@ -58,7 +57,7 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
if (PowerProvided - PowerDrained < 0)
|
if (PowerProvided - PowerDrained < 0)
|
||||||
if (PowerProvided - PowerDrained != oldBalance)
|
if (PowerProvided - PowerDrained != oldBalance)
|
||||||
Owner.GiveAdvice(Rules.Info["world"].Traits.Get<EvaAlertsInfo>().LowPower);
|
nextPowerAdviceTime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PowerState GetPowerState()
|
public PowerState GetPowerState()
|
||||||
@@ -68,32 +67,23 @@ namespace OpenRA.Traits
|
|||||||
return PowerState.Critical;
|
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 GiveCash(int num)
|
||||||
public void GiveOre(int num)
|
|
||||||
{
|
{
|
||||||
Ore += num;
|
Cash += num;
|
||||||
|
|
||||||
if (Ore > OreCapacity)
|
if (Cash > CashCapacity)
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
num -= Ore;
|
nextSiloAdviceTime = 0;
|
||||||
Ore = 0;
|
Cash = CashCapacity;
|
||||||
Cash -= num;
|
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
Ore -= num;
|
|
||||||
|
public bool TakeCash(int num)
|
||||||
|
{
|
||||||
|
if (Cash < num) return false;
|
||||||
|
Cash -= num;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,21 +94,36 @@ namespace OpenRA.Traits
|
|||||||
{
|
{
|
||||||
UpdatePower();
|
UpdatePower();
|
||||||
|
|
||||||
OreCapacity = self.World.Queries.OwnedBy[Owner].WithTrait<StoresOre>()
|
if (--nextPowerAdviceTime <= 0)
|
||||||
.Sum(a => a.Actor.Info.Traits.Get<StoresOreInfo>().Capacity);
|
{
|
||||||
|
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;
|
if (--nextSiloAdviceTime <= 0)
|
||||||
var diff = Math.Abs(totalMoney - DisplayCash);
|
{
|
||||||
|
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),
|
var move = Math.Min(Math.Max((int)(diff * displayCashFracPerFrame),
|
||||||
displayCashDeltaPerFrame), diff);
|
displayCashDeltaPerFrame), diff);
|
||||||
|
|
||||||
var eva = self.World.WorldActor.Info.Traits.Get<EvaAlertsInfo>();
|
var eva = self.World.WorldActor.Info.Traits.Get<EvaAlertsInfo>();
|
||||||
if (DisplayCash < totalMoney)
|
if (DisplayCash < Cash)
|
||||||
{
|
{
|
||||||
DisplayCash += move;
|
DisplayCash += move;
|
||||||
Sound.PlayToPlayer(self.Owner, eva.CashTickUp);
|
Sound.PlayToPlayer(self.Owner, eva.CashTickUp);
|
||||||
}
|
}
|
||||||
else if (DisplayCash > totalMoney)
|
else if (DisplayCash > Cash)
|
||||||
{
|
{
|
||||||
DisplayCash -= move;
|
DisplayCash -= move;
|
||||||
Sound.PlayToPlayer(self.Owner, eva.CashTickDown);
|
Sound.PlayToPlayer(self.Owner, eva.CashTickDown);
|
||||||
|
|||||||
@@ -22,18 +22,18 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
namespace OpenRA.Traits
|
namespace OpenRA.Traits
|
||||||
{
|
{
|
||||||
class StoresOreInfo : TraitInfo<StoresOre>
|
class StoresCashInfo : TraitInfo<StoresCash>
|
||||||
{
|
{
|
||||||
public readonly int Pips = 0;
|
public readonly int Pips = 0;
|
||||||
public readonly int Capacity = 0;
|
public readonly int Capacity = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
class StoresOre : IPips, IAcceptThief
|
class StoresCash : IPips, IAcceptThief
|
||||||
{
|
{
|
||||||
public void OnSteal(Actor self, Actor thief)
|
public void OnSteal(Actor self, Actor thief)
|
||||||
{
|
{
|
||||||
// Steal half the ore the building holds
|
// Steal half the cash the building holds
|
||||||
var toSteal = self.Info.Traits.Get<StoresOreInfo>().Capacity / 2;
|
var toSteal = self.Info.Traits.Get<StoresCashInfo>().Capacity / 2;
|
||||||
self.Owner.PlayerActor.traits.Get<PlayerResources>().TakeCash(toSteal);
|
self.Owner.PlayerActor.traits.Get<PlayerResources>().TakeCash(toSteal);
|
||||||
thief.Owner.PlayerActor.traits.Get<PlayerResources>().GiveCash(toSteal);
|
thief.Owner.PlayerActor.traits.Get<PlayerResources>().GiveCash(toSteal);
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
public IEnumerable<PipType> GetPips(Actor self)
|
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,
|
return Graphics.Util.MakeArray( numPips,
|
||||||
i => (self.World.LocalPlayer.PlayerActor.traits.Get<PlayerResources>().GetSiloFullness() > i * 1.0f / numPips)
|
i => (self.World.LocalPlayer.PlayerActor.traits.Get<PlayerResources>().GetSiloFullness() > i * 1.0f / numPips)
|
||||||
@@ -18,6 +18,9 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Collections.Generic;
|
||||||
using OpenRA.Mods.RA;
|
using OpenRA.Mods.RA;
|
||||||
using OpenRA.Mods.RA.Activities;
|
using OpenRA.Mods.RA.Activities;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
@@ -27,17 +30,53 @@ namespace OpenRA.Mods.Cnc
|
|||||||
{
|
{
|
||||||
class TiberiumRefineryInfo : ITraitInfo
|
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); }
|
public object Create(Actor self) { return new TiberiumRefinery(self); }
|
||||||
}
|
}
|
||||||
|
|
||||||
class TiberiumRefinery : IAcceptOre
|
class TiberiumRefinery : ITick, IAcceptOre, IPips
|
||||||
{
|
{
|
||||||
Actor self;
|
Actor self;
|
||||||
|
TiberiumRefineryInfo Info;
|
||||||
|
|
||||||
|
[Sync]
|
||||||
|
int nextProcessTime = 0;
|
||||||
|
[Sync]
|
||||||
|
public int Tiberium = 0;
|
||||||
|
|
||||||
public TiberiumRefinery(Actor self)
|
public TiberiumRefinery(Actor self)
|
||||||
{
|
{
|
||||||
this.self = 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 int2 DeliverOffset { get { return new int2(0, 2); } }
|
||||||
public void OnDock(Actor harv, DeliverResources dockOrder)
|
public void OnDock(Actor harv, DeliverResources dockOrder)
|
||||||
{
|
{
|
||||||
@@ -51,5 +90,12 @@ namespace OpenRA.Mods.Cnc
|
|||||||
harv.QueueActivity(new Harvest());
|
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)
|
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();
|
contents.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,11 @@ namespace OpenRA.Mods.RA
|
|||||||
{
|
{
|
||||||
this.self = self;
|
this.self = self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void GiveOre(int amount)
|
||||||
|
{
|
||||||
|
// TODO: Unbreak this
|
||||||
|
}
|
||||||
public int2 DeliverOffset { get { return new int2(1, 2); } }
|
public int2 DeliverOffset { get { return new int2(1, 2); } }
|
||||||
public void OnDock(Actor harv, DeliverResources dockOrder)
|
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.
|
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
||||||
* This file is part of OpenRA.
|
* This file is part of OpenRA.
|
||||||
@@ -25,6 +25,7 @@ namespace OpenRA.Mods.RA
|
|||||||
public interface IAcceptOre
|
public interface IAcceptOre
|
||||||
{
|
{
|
||||||
void OnDock(Actor harv, DeliverResources dockOrder);
|
void OnDock(Actor harv, DeliverResources dockOrder);
|
||||||
|
void GiveOre(int amount);
|
||||||
int2 DeliverOffset { get; }
|
int2 DeliverOffset { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ PROC:
|
|||||||
Buildable:
|
Buildable:
|
||||||
Icon: procicnh
|
Icon: procicnh
|
||||||
BuildPaletteOrder: 30
|
BuildPaletteOrder: 30
|
||||||
Prerequisites: nuke
|
Prerequisites: silo
|
||||||
Owner: gdi,nod
|
Owner: gdi,nod
|
||||||
Cost: 2000
|
Cost: 2000
|
||||||
Description: Tiberium Refinery
|
Description: Tiberium Refinery
|
||||||
@@ -58,9 +58,10 @@ PROC:
|
|||||||
Sight: 6
|
Sight: 6
|
||||||
Bib:
|
Bib:
|
||||||
TiberiumRefinery:
|
TiberiumRefinery:
|
||||||
StoresOre:
|
Pips: 10
|
||||||
Pips: 17
|
|
||||||
Capacity: 1000
|
Capacity: 1000
|
||||||
|
ProcessTick: 25
|
||||||
|
ProcessAmount: 50
|
||||||
CustomSellValue:
|
CustomSellValue:
|
||||||
Value: 600
|
Value: 600
|
||||||
HasUnitOnBuild:
|
HasUnitOnBuild:
|
||||||
@@ -74,11 +75,11 @@ SILO:
|
|||||||
Buildable:
|
Buildable:
|
||||||
Icon: siloicnh
|
Icon: siloicnh
|
||||||
BuildPaletteOrder: 20
|
BuildPaletteOrder: 20
|
||||||
Prerequisites: proc
|
Prerequisites: nuke
|
||||||
Owner: gdi,nod
|
Owner: gdi,nod
|
||||||
Cost: 150
|
Cost: 150
|
||||||
Description: Tiberium Silo
|
Description: Tiberium Silo
|
||||||
LongDesc: Stores excess Tiberium until it can be processed
|
LongDesc: Stores processed Tiberium
|
||||||
Building:
|
Building:
|
||||||
Power: -10
|
Power: -10
|
||||||
Footprint: xx
|
Footprint: xx
|
||||||
@@ -88,9 +89,9 @@ SILO:
|
|||||||
Armor: wood
|
Armor: wood
|
||||||
Sight: 4
|
Sight: 4
|
||||||
RenderBuildingOre:
|
RenderBuildingOre:
|
||||||
StoresOre:
|
StoresCash:
|
||||||
Pips: 5
|
Pips: 5
|
||||||
Capacity: 1500
|
Capacity: 5000
|
||||||
-RenderBuilding:
|
-RenderBuilding:
|
||||||
|
|
||||||
PYLE:
|
PYLE:
|
||||||
|
|||||||
Reference in New Issue
Block a user