From 2671e40c1d6bc296561db23c8ceb282ce2679ec7 Mon Sep 17 00:00:00 2001 From: Taryn Hill Date: Sat, 31 Oct 2020 07:21:43 -0500 Subject: [PATCH] feat: ActorSpawnManager.SpawnInterval supports 1 or 2 values Providing 2 values creates a range from which a value is randomly selected. --- .../Traits/World/ActorSpawnManager.cs | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/World/ActorSpawnManager.cs b/OpenRA.Mods.Common/Traits/World/ActorSpawnManager.cs index 476bfdaee0..17a00d5908 100644 --- a/OpenRA.Mods.Common/Traits/World/ActorSpawnManager.cs +++ b/OpenRA.Mods.Common/Traits/World/ActorSpawnManager.cs @@ -11,6 +11,7 @@ using System.Collections.Generic; using System.Linq; +using OpenRA.Mods.Common; using OpenRA.Primitives; using OpenRA.Traits; @@ -25,8 +26,8 @@ namespace OpenRA.Mods.Common.Traits [Desc("Maximum number of actors.")] public readonly int Maximum = 4; - [Desc("Time (in ticks) between actor spawn.")] - public readonly int SpawnInterval = 6000; + [Desc("Time (in ticks) between actor spawn. Supports 1 or 2 values.\nIf 2 values are provided they are used as a range from which a value is randomly selected.")] + public readonly int[] SpawnInterval = { 6000 }; [FieldLoader.Require] [ActorReference] @@ -38,6 +39,20 @@ namespace OpenRA.Mods.Common.Traits [Desc("Type of ActorSpawner with which it connects.")] public readonly HashSet Types = new HashSet() { }; + public override void RulesetLoaded(Ruleset rules, ActorInfo ai) + { + base.RulesetLoaded(rules, ai); + + if (SpawnInterval.Length == 0 || SpawnInterval.Length > 2) + throw new YamlException("{0}.{1} must be either 1 or 2 values".F(nameof(ActorSpawnManager), nameof(SpawnInterval))); + + if (SpawnInterval.Length == 2 && SpawnInterval[0] >= SpawnInterval[1]) + throw new YamlException("{0}.{1}'s first value must be less than the second value".F(nameof(ActorSpawnManager), nameof(SpawnInterval))); + + if (SpawnInterval.Any(it => it < 0)) + throw new YamlException("{0}.{1}'s value(s) must not be less than 0".F(nameof(ActorSpawnManager), nameof(SpawnInterval))); + } + public override object Create(ActorInitializer init) { return new ActorSpawnManager(init.Self, this); } } @@ -77,7 +92,7 @@ namespace OpenRA.Mods.Common.Traits if (spawnPoint == null) return; - spawnCountdown = info.SpawnInterval; + spawnCountdown = Util.RandomDelay(self.World, info.SpawnInterval); do {