From a175f53ba73d802b27ab91c724becabe0b6a5870 Mon Sep 17 00:00:00 2001 From: reaperrr Date: Sun, 8 Nov 2015 13:59:38 +0100 Subject: [PATCH] Improve spice bloom seeding mechanism Improve seeding target cell determination. Draw out spice seedable cells before loop. Default to null for SpiceBloom.Weapon. Pull spice seeding into its own method. Skip it completely if no seed weapon is defined. --- OpenRA.Mods.D2k/Traits/SpiceBloom.cs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/OpenRA.Mods.D2k/Traits/SpiceBloom.cs b/OpenRA.Mods.D2k/Traits/SpiceBloom.cs index 1f06fb200d..bc258aacc3 100644 --- a/OpenRA.Mods.D2k/Traits/SpiceBloom.cs +++ b/OpenRA.Mods.D2k/Traits/SpiceBloom.cs @@ -39,7 +39,7 @@ namespace OpenRA.Mods.D2k.Traits [Desc("The weapon to use for spice creation.")] [WeaponReference] - public readonly string Weapon = "SpiceExplosion"; + public readonly string Weapon = null; [Desc("The amount of spice to expel.")] public readonly int[] Pieces = { 2, 12 }; @@ -98,18 +98,19 @@ namespace OpenRA.Mods.D2k.Traits } } - public void Killed(Actor self, AttackInfo e) + void SeedResources(Actor self) { var pieces = self.World.SharedRandom.Next(info.Pieces[0], info.Pieces[1]) * ticks / growTicks; if (pieces < info.Pieces[0]) pieces = info.Pieces[0]; - for (var i = 0; pieces > i; i++) + var cells = self.World.Map.FindTilesInAnnulus(self.Location, 1, info.Range); + + for (var i = 0; i < pieces; i++) { - var cells = OpenRA.Traits.Util.RandomWalk(self.Location, self.World.SharedRandom); - var cell = cells.Take(info.Range).SkipWhile(p => resLayer.GetResource(p) == resType && resLayer.IsFull(p)).Cast().RandomOrDefault(self.World.SharedRandom); + var cell = cells.SkipWhile(p => resLayer.GetResource(p) == resType && resLayer.IsFull(p)).Cast().RandomOrDefault(self.World.SharedRandom); if (cell == null) - cell = cells.Take(info.Range).Random(self.World.SharedRandom); + cell = cells.Random(self.World.SharedRandom); var args = new ProjectileArgs { @@ -140,6 +141,12 @@ namespace OpenRA.Mods.D2k.Traits } }); } + } + + public void Killed(Actor self, AttackInfo e) + { + if (!string.IsNullOrEmpty(info.Weapon)) + SeedResources(self); self.World.AddFrameEndTask(t => t.Add(new DelayedAction(respawnTicks, () => {