Deathweapon capability, refactoring, and Pip polishing on Silo, Proc, Harv. Lose ore on silo death.

This commit is contained in:
Paul Chote
2010-06-14 22:15:43 +12:00
parent d36c8deb97
commit 06a78cd73d
7 changed files with 101 additions and 43 deletions

View File

@@ -22,35 +22,58 @@ using System.Collections.Generic;
namespace OpenRA.Traits
{
class StoresOreInfo : TraitInfo<StoresOre>
class StoresOreInfo : ITraitInfo
{
public readonly int Pips = 0;
public readonly int PipCount = 0;
public readonly PipType PipColor = PipType.Yellow;
public readonly int Capacity = 0;
public readonly string DeathWeapon = null;
public object Create(Actor self) { return new StoresOre(self, this); }
}
class StoresOre : IPips, INotifyCapture
class StoresOre : IPips, INotifyCapture, INotifyDamage
{
readonly PlayerResources Player;
readonly StoresOreInfo Info;
public StoresOre(Actor self, StoresOreInfo info)
{
Player = self.Owner.PlayerActor.traits.Get<PlayerResources>();
Info = info;
}
public void OnCapture(Actor self, Actor captor)
{
var ore = Stored(self);
self.Owner.PlayerActor.traits.Get<PlayerResources>().TakeOre(ore);
captor.Owner.PlayerActor.traits.Get<PlayerResources>().GiveOre(ore);
Player.TakeOre(ore);
Player.GiveOre(ore);
}
int Stored(Actor self)
{
var use = self.Owner.PlayerActor.traits.Get<PlayerResources>().GetSiloFullness();
var capacity = self.Info.Traits.Get<StoresOreInfo>().Capacity;
return (int)use*capacity;
return (int)(Player.GetSiloFullness() * Info.Capacity);
}
public void Damaged(Actor self, AttackInfo e)
{
if (self.IsDead && Player.GetSiloFullness() > 0)
{
if (Info.DeathWeapon != null)
{
Combat.DoExplosion(e.Attacker, Info.DeathWeapon,
self.CenterLocation.ToInt2(), 0);
}
// Lose the stored ore
Player.TakeOre(Stored(self));
}
}
public IEnumerable<PipType> GetPips(Actor self)
{
var numPips = self.Info.Traits.Get<StoresOreInfo>().Pips;
return Graphics.Util.MakeArray( numPips,
i => (self.Owner.PlayerActor.traits.Get<PlayerResources>().GetSiloFullness() > i * 1.0f / numPips)
? PipType.Yellow : PipType.Transparent );
return Graphics.Util.MakeArray( Info.PipCount,
i => (Player.GetSiloFullness() > i * 1.0f / Info.PipCount)
? Info.PipColor : PipType.Transparent );
}
}
}

View File

@@ -30,17 +30,20 @@ namespace OpenRA.Mods.Cnc
{
class TiberiumRefineryInfo : ITraitInfo
{
public readonly int Pips = 0;
public readonly int PipCount = 0;
public readonly PipType PipColor = PipType.Red;
public readonly int Capacity = 0;
public readonly int ProcessTick = 25;
public readonly int ProcessAmount = 50;
public readonly string DeathWeapon = null;
public object Create(Actor self) { return new TiberiumRefinery(self, this); }
}
class TiberiumRefinery : ITick, IAcceptOre, IPips
class TiberiumRefinery : ITick, IAcceptOre, INotifyDamage, IPips
{
Actor self;
TiberiumRefineryInfo Info;
readonly Actor self;
readonly TiberiumRefineryInfo Info;
readonly PlayerResources Player;
[Sync]
int nextProcessTime = 0;
@@ -51,6 +54,8 @@ namespace OpenRA.Mods.Cnc
{
this.self = self;
Info = info;
Player = self.Owner.PlayerActor.traits.Get<PlayerResources>();
}
public void GiveOre(int amount)
@@ -65,18 +70,30 @@ namespace OpenRA.Mods.Cnc
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.OreCapacity - pr.Ore);
amount = Math.Min(amount, Player.OreCapacity - Player.Ore);
if (amount > 0)
{
Tiberium -=amount;
pr.GiveOre(amount);
Player.GiveOre(amount);
}
nextProcessTime = Info.ProcessTick;
}
}
public void Damaged(Actor self, AttackInfo e)
{
if (self.IsDead && Tiberium > 0)
{
if (Info.DeathWeapon != null)
{
Combat.DoExplosion(e.Attacker, Info.DeathWeapon,
self.CenterLocation.ToInt2(), 0);
}
}
}
public int2 DeliverOffset { get { return new int2(0, 2); } }
public void OnDock(Actor harv, DeliverResources dockOrder)
{
@@ -93,9 +110,9 @@ namespace OpenRA.Mods.Cnc
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 );
return Graphics.Util.MakeArray( Info.PipCount,
i => (Tiberium * 1.0f / Info.Capacity > i * 1.0f / Info.PipCount)
? Info.PipColor : PipType.Transparent );
}
}
}

View File

@@ -26,26 +26,28 @@ using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA
{
class HarvesterInfo : ITraitInfo
public class HarvesterInfo : ITraitInfo
{
public readonly int Capacity = 28;
public readonly int PipCount = 7;
public readonly PipType PipColor = PipType.Yellow;
public readonly string[] Resources = { };
public readonly string DeathWeapon = null;
public object Create(Actor self) { return new Harvester(self); }
public object Create(Actor self) { return new Harvester(self, this); }
}
public class Harvester : IIssueOrder, IResolveOrder, IPips
public class Harvester : IIssueOrder, IResolveOrder, INotifyDamage, IPips
{
Dictionary<ResourceTypeInfo, int> contents = new Dictionary<ResourceTypeInfo, int>();
Actor self;
public Harvester(Actor self)
readonly HarvesterInfo Info;
public Harvester(Actor self, HarvesterInfo info)
{
this.self = self;
Info = info;
}
public bool IsFull { get { return contents.Values.Sum() == self.Info.Traits.Get<HarvesterInfo>().Capacity; } }
public bool IsFull { get { return contents.Values.Sum() == Info.Capacity; } }
public bool IsEmpty { get { return contents.Values.Sum() == 0; } }
public void AcceptResource(ResourceType type)
@@ -93,16 +95,27 @@ namespace OpenRA.Mods.RA
}
}
public void Damaged(Actor self, AttackInfo e)
{
if (self.IsDead && contents.Count > 0)
{
if (Info.DeathWeapon != null)
{
Combat.DoExplosion(e.Attacker, Info.DeathWeapon,
self.CenterLocation.ToInt2(), 0);
}
}
}
public IEnumerable<PipType> GetPips(Actor self)
{
int numPips = self.Info.Traits.Get<HarvesterInfo>().PipCount;
int numPips = Info.PipCount;
int n = contents.Values.Sum();
for (int i = 0; i < numPips; i++)
{
// todo: pip colors based on ResourceTypeInfo
if (n * 1.0f / self.Info.Traits.Get<HarvesterInfo>().Capacity > i * 1.0f / numPips)
yield return PipType.Yellow;
if (n * 1.0f / Info.Capacity > i * 1.0f / numPips)
yield return Info.PipColor;
else
yield return PipType.Transparent;
}

View File

@@ -29,7 +29,8 @@ namespace OpenRA.Mods.RA
{
class OreRefineryInfo : ITraitInfo
{
public readonly int Pips = 0;
public readonly int PipCount = 0;
public readonly PipType PipColor = PipType.Red;
public readonly int Capacity = 0;
public readonly int ProcessTick = 25;
public readonly int ProcessAmount = 50;
@@ -77,9 +78,9 @@ namespace OpenRA.Mods.RA
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 );
return Graphics.Util.MakeArray( Info.PipCount,
i => (Ore * 1.0f / Info.Capacity > i * 1.0f / Info.PipCount)
? Info.PipColor : PipType.Transparent );
}
public int2 DeliverOffset { get { return new int2(1, 2); } }

View File

@@ -58,7 +58,8 @@ PROC:
Sight: 6
Bib:
TiberiumRefinery:
Pips: 15
PipCount: 15
PipColor: Red
Capacity: 1000
ProcessTick: 25
ProcessAmount: 50
@@ -90,7 +91,8 @@ SILO:
Sight: 4
RenderBuildingOre:
StoresOre:
Pips: 5
PipCount: 5
PipColor: Green
Capacity: 1000
-RenderBuilding:

View File

@@ -39,6 +39,8 @@ HARV:
Priority: 7
Harvester:
Resources: Tiberium
PipCount: 5
PipColor: Green
Capacity: 28
Unit:
HP: 600

View File

@@ -468,12 +468,12 @@ PROC:
Sight: 6
Bib:
OreRefinery:
Pips: 17
PipCount: 17
Capacity: 1000
ProcessTick: 25
ProcessAmount: 50
StoresOre:
Pips: 17
PipCount: 17
Capacity: 2000
IronCurtainable:
CustomSellValue:
@@ -502,7 +502,7 @@ SILO:
Sight: 4
RenderBuildingOre:
StoresOre:
Pips: 5
PipCount: 5
Capacity: 1500
IronCurtainable:
-RenderBuilding: