From 06a78cd73da0b19343597a4a52ca36a4070d9641 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Mon, 14 Jun 2010 22:15:43 +1200 Subject: [PATCH] Deathweapon capability, refactoring, and Pip polishing on Silo, Proc, Harv. Lose ore on silo death. --- OpenRA.Game/Traits/StoresOre.cs | 49 +++++++++++++++++++++-------- OpenRA.Mods.Cnc/TiberiumRefinery.cs | 37 ++++++++++++++++------ OpenRA.Mods.RA/Harvester.cs | 35 ++++++++++++++------- OpenRA.Mods.RA/OreRefinery.cs | 9 +++--- mods/cnc/structures.yaml | 6 ++-- mods/cnc/vehicles.yaml | 2 ++ mods/ra/structures.yaml | 6 ++-- 7 files changed, 101 insertions(+), 43 deletions(-) diff --git a/OpenRA.Game/Traits/StoresOre.cs b/OpenRA.Game/Traits/StoresOre.cs index d0a6b0893d..c2b7c3cb49 100644 --- a/OpenRA.Game/Traits/StoresOre.cs +++ b/OpenRA.Game/Traits/StoresOre.cs @@ -22,35 +22,58 @@ using System.Collections.Generic; namespace OpenRA.Traits { - class StoresOreInfo : TraitInfo + 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(); + Info = info; + } + public void OnCapture(Actor self, Actor captor) { var ore = Stored(self); - self.Owner.PlayerActor.traits.Get().TakeOre(ore); - captor.Owner.PlayerActor.traits.Get().GiveOre(ore); + Player.TakeOre(ore); + Player.GiveOre(ore); } int Stored(Actor self) { - var use = self.Owner.PlayerActor.traits.Get().GetSiloFullness(); - var capacity = self.Info.Traits.Get().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 GetPips(Actor self) { - var numPips = self.Info.Traits.Get().Pips; - - return Graphics.Util.MakeArray( numPips, - i => (self.Owner.PlayerActor.traits.Get().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 ); } } } diff --git a/OpenRA.Mods.Cnc/TiberiumRefinery.cs b/OpenRA.Mods.Cnc/TiberiumRefinery.cs index 3be56b7850..fa11e85d5b 100644 --- a/OpenRA.Mods.Cnc/TiberiumRefinery.cs +++ b/OpenRA.Mods.Cnc/TiberiumRefinery.cs @@ -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(); + } 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(); 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 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 ); } } } diff --git a/OpenRA.Mods.RA/Harvester.cs b/OpenRA.Mods.RA/Harvester.cs index 4656f4fb8f..ad651d1251 100755 --- a/OpenRA.Mods.RA/Harvester.cs +++ b/OpenRA.Mods.RA/Harvester.cs @@ -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 contents = new Dictionary(); - 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().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 GetPips(Actor self) { - int numPips = self.Info.Traits.Get().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().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; } diff --git a/OpenRA.Mods.RA/OreRefinery.cs b/OpenRA.Mods.RA/OreRefinery.cs index f9d2f6266a..d7bc6a8362 100755 --- a/OpenRA.Mods.RA/OreRefinery.cs +++ b/OpenRA.Mods.RA/OreRefinery.cs @@ -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 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); } } diff --git a/mods/cnc/structures.yaml b/mods/cnc/structures.yaml index f61c5819e5..15a4ec250d 100644 --- a/mods/cnc/structures.yaml +++ b/mods/cnc/structures.yaml @@ -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: diff --git a/mods/cnc/vehicles.yaml b/mods/cnc/vehicles.yaml index d7d9b2beaa..634ac0812a 100644 --- a/mods/cnc/vehicles.yaml +++ b/mods/cnc/vehicles.yaml @@ -39,6 +39,8 @@ HARV: Priority: 7 Harvester: Resources: Tiberium + PipCount: 5 + PipColor: Green Capacity: 28 Unit: HP: 600 diff --git a/mods/ra/structures.yaml b/mods/ra/structures.yaml index cb04aa4de2..e3ff334221 100644 --- a/mods/ra/structures.yaml +++ b/mods/ra/structures.yaml @@ -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: