Merge pull request #12350 from reaperrr/rem-spicebloom-DelAct

Merge SpiceBloom RespawnDelay & GrowthDelay into Lifetime
This commit is contained in:
Paul Chote
2017-02-04 16:22:39 +00:00
committed by GitHub
6 changed files with 102 additions and 52 deletions

View File

@@ -18,13 +18,21 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Remove the actor from the world (and destroy it) instead of killing it.")]
public readonly bool RemoveInstead = false;
public override object Create(ActorInitializer init) { return new KillsSelf(this); }
[Desc("The amount of time (in ticks) before the actor dies. Two values indicate a range between which a random value is chosen.")]
public readonly int[] Delay = { 250 };
public override object Create(ActorInitializer init) { return new KillsSelf(init.Self, this); }
}
class KillsSelf : ConditionalTrait<KillsSelfInfo>, INotifyAddedToWorld
class KillsSelf : ConditionalTrait<KillsSelfInfo>, INotifyAddedToWorld, ITick
{
public KillsSelf(KillsSelfInfo info)
: base(info) { }
int lifetime;
public KillsSelf(Actor self, KillsSelfInfo info)
: base(info)
{
lifetime = Util.RandomDelay(self.World, info.Delay);
}
public void AddedToWorld(Actor self)
{
@@ -37,10 +45,30 @@ namespace OpenRA.Mods.Common.Traits
if (self.IsDead)
return;
if (lifetime > 0)
return;
if (Info.RemoveInstead || !self.Info.HasTraitInfo<HealthInfo>())
self.Dispose();
else
self.Kill(self);
}
void ITick.Tick(Actor self)
{
if (self.IsDead || IsTraitDisabled)
return;
if (!self.World.Map.Contains(self.Location))
return;
if (lifetime-- == 0)
{
if (Info.RemoveInstead || !self.Info.HasTraitInfo<HealthInfo>())
self.Dispose();
else
self.Kill(self);
}
}
}
}

View File

@@ -40,7 +40,7 @@ namespace OpenRA.Mods.Common.Traits.Sound
public AmbientSound(Actor self, AmbientSoundInfo info)
: base(info)
{
delay = RandomDelay(self.World, info.Delay);
delay = Util.RandomDelay(self.World, info.Delay);
loop = Info.Interval.Length == 0 || (Info.Interval.Length == 1 && Info.Interval[0] == 0);
}
@@ -63,7 +63,7 @@ namespace OpenRA.Mods.Common.Traits.Sound
{
StartSound(self);
if (!loop)
delay = RandomDelay(self.World, Info.Interval);
delay = Util.RandomDelay(self.World, Info.Interval);
}
}
@@ -89,18 +89,7 @@ namespace OpenRA.Mods.Common.Traits.Sound
currentSound = null;
}
static int RandomDelay(World world, int[] range)
{
if (range.Length == 0)
return 0;
if (range.Length == 1)
return range[0];
return world.SharedRandom.Next(range[0], range[1]);
}
protected override void TraitEnabled(Actor self) { delay = RandomDelay(self.World, Info.Delay); }
protected override void TraitEnabled(Actor self) { delay = Util.RandomDelay(self.World, Info.Delay); }
protected override void TraitDisabled(Actor self) { StopSound(); }
void INotifyRemovedFromWorld.RemovedFromWorld(Actor self) { StopSound(); }

View File

@@ -164,5 +164,16 @@ namespace OpenRA.Mods.Common
yield return p;
}
}
public static int RandomDelay(World world, int[] range)
{
if (range.Length == 0)
return 0;
if (range.Length == 1)
return range[0];
return world.SharedRandom.Next(range[0], range[1]);
}
}
}

View File

@@ -781,6 +781,26 @@ namespace OpenRA.Mods.Common.UtilityCommands
if (node.Key.StartsWith("UpgradeOverlay", StringComparison.Ordinal))
RenameNodeKey(node, "WithColoredOverlay" + node.Key.Substring(14));
// Remove SpiceBloom.RespawnDelay to get rid of DelayedAction, and rename GrowthDelay to Lifetime
if (engineVersion < 20170203)
{
var spiceBloom = node.Value.Nodes.FirstOrDefault(n => n.Key == "SpiceBloom");
if (spiceBloom != null)
{
var respawnDelay = spiceBloom.Value.Nodes.FirstOrDefault(n => n.Key == "RespawnDelay");
if (respawnDelay != null)
{
spiceBloom.Value.Nodes.Remove(respawnDelay);
Console.WriteLine("RespawnDelay has been removed from SpiceBloom for technical reasons.");
Console.WriteLine("Increase self-kill delay of the spice bloom spawnpoint actor instead.");
}
var growthDelay = spiceBloom.Value.Nodes.FirstOrDefault(n => n.Key == "GrowthDelay");
if (growthDelay != null)
growthDelay.Key = "Lifetime";
}
}
UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
}