Use the same model for ra (but let proc hold ore as before)

This commit is contained in:
Paul Chote
2010-06-13 17:34:58 +12:00
parent dc8178f984
commit de6434c0f1
4 changed files with 56 additions and 12 deletions

View File

@@ -301,16 +301,15 @@ namespace OpenRA.Graphics
{ {
foreach (var pip in pips.GetPips(selectedUnit)) foreach (var pip in pips.GetPips(selectedUnit))
{ {
var pipImages = new Animation("pips");
pipImages.PlayRepeating(pipStrings[(int)pip]);
spriteRenderer.DrawSprite(pipImages.Image, pipxyBase + pipxyOffset, "chrome");
pipxyOffset += new float2(4, 0);
if (pipxyOffset.X+5 > selectedUnit.GetBounds(false).Width) if (pipxyOffset.X+5 > selectedUnit.GetBounds(false).Width)
{ {
pipxyOffset.X = 0; pipxyOffset.X = 0;
pipxyOffset.Y -= 4; pipxyOffset.Y -= 4;
} }
var pipImages = new Animation("pips");
pipImages.PlayRepeating(pipStrings[(int)pip]);
spriteRenderer.DrawSprite(pipImages.Image, pipxyBase + pipxyOffset, "chrome");
pipxyOffset += new float2(4, 0);
} }
// Increment row // Increment row
pipxyOffset.X = 0; pipxyOffset.X = 0;

View File

@@ -34,7 +34,7 @@ namespace OpenRA.Mods.Cnc
public readonly int Capacity = 0; public readonly int Capacity = 0;
public readonly int ProcessTick = 25; public readonly int ProcessTick = 25;
public readonly int ProcessAmount = 50; public readonly int ProcessAmount = 50;
public object Create(Actor self) { return new TiberiumRefinery(self); } public object Create(Actor self) { return new TiberiumRefinery(self, this); }
} }
class TiberiumRefinery : ITick, IAcceptOre, IPips class TiberiumRefinery : ITick, IAcceptOre, IPips
@@ -47,10 +47,10 @@ namespace OpenRA.Mods.Cnc
[Sync] [Sync]
public int Tiberium = 0; public int Tiberium = 0;
public TiberiumRefinery(Actor self) public TiberiumRefinery(Actor self, TiberiumRefineryInfo info)
{ {
this.self = self; this.self = self;
Info = self.Info.Traits.Get<TiberiumRefineryInfo>(); Info = info;
} }
public void GiveOre(int amount) public void GiveOre(int amount)

View File

@@ -18,6 +18,9 @@
*/ */
#endregion #endregion
using System;
using System.Linq;
using System.Collections.Generic;
using OpenRA.Mods.RA.Activities; using OpenRA.Mods.RA.Activities;
using OpenRA.Traits; using OpenRA.Traits;
using OpenRA.Traits.Activities; using OpenRA.Traits.Activities;
@@ -26,21 +29,59 @@ namespace OpenRA.Mods.RA
{ {
class OreRefineryInfo : ITraitInfo class OreRefineryInfo : ITraitInfo
{ {
public object Create(Actor self) { return new OreRefinery(self); } 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 OreRefinery(self, this); }
} }
class OreRefinery : IAcceptOre class OreRefinery : ITick, IAcceptOre, IPips
{ {
Actor self; Actor self;
public OreRefinery(Actor self) OreRefineryInfo Info;
[Sync]
int nextProcessTime = 0;
[Sync]
public int Ore = 0;
public OreRefinery(Actor self, OreRefineryInfo info)
{ {
this.self = self; this.self = self;
Info = info;
} }
public void GiveOre(int amount) public void GiveOre(int amount)
{ {
// TODO: Unbreak this Ore += amount;
if (Ore > Info.Capacity)
Ore = 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(Ore, Info.ProcessAmount);
amount = Math.Min(amount, pr.OreCapacity - pr.Ore);
if (amount > 0)
{
Ore -=amount;
pr.GiveOre(amount);
}
nextProcessTime = Info.ProcessTick;
}
}
public IEnumerable<PipType> GetPips(Actor self)
{
return Graphics.Util.MakeArray( Info.Pips,
i => (Ore * 1.0f / Info.Capacity > i * 1.0f / Info.Pips)
? PipType.Red : PipType.Transparent );
}
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)
{ {

View File

@@ -468,6 +468,10 @@ PROC:
Sight: 6 Sight: 6
Bib: Bib:
OreRefinery: OreRefinery:
Pips: 17
Capacity: 1000
ProcessTick: 25
ProcessAmount: 50
StoresOre: StoresOre:
Pips: 17 Pips: 17
Capacity: 2000 Capacity: 2000