Merge pull request #9060 from abcdefg30/cratespawndelay

Add a InitialSpawnDelay to CrateSpawner
This commit is contained in:
Oliver Brakmann
2015-09-26 01:26:41 +02:00
11 changed files with 47 additions and 22 deletions

View File

@@ -19,14 +19,17 @@ namespace OpenRA.Mods.Common.Traits
{ {
public class CrateSpawnerInfo : ITraitInfo public class CrateSpawnerInfo : ITraitInfo
{ {
[Desc("Minimum number of crates")] [Desc("Minimum number of crates.")]
public readonly int Minimum = 1; public readonly int Minimum = 1;
[Desc("Maximum number of crates")] [Desc("Maximum number of crates.")]
public readonly int Maximum = 255; public readonly int Maximum = 255;
[Desc("Average time (seconds) between crate spawn")] [Desc("Average time (ticks) between crate spawn.")]
public readonly int SpawnInterval = 180; public readonly int SpawnInterval = 180 * 25;
[Desc("Delay (in ticks) before the first crate spawns.")]
public readonly int InitialSpawnDelay = 300 * 25;
[Desc("Which terrain types can we drop on?")] [Desc("Which terrain types can we drop on?")]
public readonly HashSet<string> ValidGround = new HashSet<string> { "Clear", "Rough", "Road", "Ore", "Beach" }; public readonly HashSet<string> ValidGround = new HashSet<string> { "Clear", "Rough", "Road", "Ore", "Beach" };
@@ -34,8 +37,8 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Which terrain types count as water?")] [Desc("Which terrain types count as water?")]
public readonly HashSet<string> ValidWater = new HashSet<string> { "Water" }; public readonly HashSet<string> ValidWater = new HashSet<string> { "Water" };
[Desc("Chance of generating a water crate instead of a land crate")] [Desc("Chance of generating a water crate instead of a land crate.")]
public readonly float WaterChance = .2f; public readonly int WaterChance = 20;
[ActorReference] [ActorReference]
[Desc("Crate actors to drop")] [Desc("Crate actors to drop")]
@@ -68,6 +71,8 @@ namespace OpenRA.Mods.Common.Traits
{ {
this.info = info; this.info = info;
this.self = self; this.self = self;
ticks = info.InitialSpawnDelay;
} }
public void Tick(Actor self) public void Tick(Actor self)
@@ -77,7 +82,7 @@ namespace OpenRA.Mods.Common.Traits
if (--ticks <= 0) if (--ticks <= 0)
{ {
ticks = info.SpawnInterval * 25; ticks = info.SpawnInterval;
var toSpawn = Math.Max(0, info.Minimum - crates) var toSpawn = Math.Max(0, info.Minimum - crates)
+ (crates < info.Maximum ? 1 : 0); + (crates < info.Maximum ? 1 : 0);
@@ -89,9 +94,8 @@ namespace OpenRA.Mods.Common.Traits
void SpawnCrate(Actor self) void SpawnCrate(Actor self)
{ {
var threshold = 100; var inWater = self.World.SharedRandom.Next(100) < info.WaterChance;
var inWater = self.World.SharedRandom.NextFloat() < info.WaterChance; var pp = ChooseDropCell(self, inWater, 100);
var pp = ChooseDropCell(self, inWater, threshold);
if (pp == null) if (pp == null)
return; return;

View File

@@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
{ {
var value = float.Parse(input, CultureInfo.InvariantCulture); var value = float.Parse(input, CultureInfo.InvariantCulture);
if (value < 1) if (value <= 1)
value = (int)Math.Round(value * 100, 0); value = (int)Math.Round(value * 100, 0);
else else
value = (int)Math.Round(value, 0); value = (int)Math.Round(value, 0);
@@ -2158,6 +2158,23 @@ namespace OpenRA.Mods.Common.UtilityCommands
} }
} }
if (engineVersion < 20150926)
{
if (node.Key == "CrateSpawner")
{
var interval = node.Value.Nodes.FirstOrDefault(n => n.Key == "SpawnInterval");
if (interval != null)
{
var value = Exts.ParseIntegerInvariant(interval.Value.Value);
interval.Value.Value = (value * 25).ToString();
}
var chance = node.Value.Nodes.FirstOrDefault(n => n.Key == "WaterChance");
if (chance != null)
ConvertFloatToIntPercentage(ref chance.Value.Value);
}
}
UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1); UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1);
} }
} }

View File

@@ -213,8 +213,9 @@ Rules:
World: World:
CrateSpawner: CrateSpawner:
Maximum: 4 Maximum: 4
SpawnInterval: 5 SpawnInterval: 125
CrateActors: unitcrate CrateActors: unitcrate
InitialSpawnDelay: 0
-SpawnMPUnits: -SpawnMPUnits:
-MPStartLocations: -MPStartLocations:
UNITCRATE: UNITCRATE:

View File

@@ -139,7 +139,7 @@ World:
CrateSpawner: CrateSpawner:
Minimum: 1 Minimum: 1
Maximum: 6 Maximum: 6
SpawnInterval: 120 SpawnInterval: 3000
WaterChance: 0 WaterChance: 0
PathFinder: PathFinder:
ValidateOrder: ValidateOrder:

View File

@@ -62,7 +62,7 @@ World:
CrateSpawner: CrateSpawner:
Minimum: 0 Minimum: 0
Maximum: 2 Maximum: 2
SpawnInterval: 60 SpawnInterval: 1500
WaterChance: 0 WaterChance: 0
ValidGround: Sand, Dune, Rock ValidGround: Sand, Dune, Rock
DomainIndex: DomainIndex:

View File

@@ -294,8 +294,9 @@ Rules:
World: World:
CrateSpawner: CrateSpawner:
Maximum: 3 Maximum: 3
SpawnInterval: 5 SpawnInterval: 125
CrateActors: unitcrate CrateActors: unitcrate
InitialSpawnDelay: 0
-SpawnMPUnits: -SpawnMPUnits:
-MPStartLocations: -MPStartLocations:
UNITCRATE: UNITCRATE:

View File

@@ -199,9 +199,10 @@ Rules:
World: World:
CrateSpawner: CrateSpawner:
Maximum: 3 Maximum: 3
SpawnInterval: 5 SpawnInterval: 125
WaterChance: 1 WaterChance: 100
CrateActors: unitcrate CrateActors: unitcrate
InitialSpawnDelay: 0
-SpawnMPUnits: -SpawnMPUnits:
-MPStartLocations: -MPStartLocations:
UNITCRATE: UNITCRATE:

View File

@@ -189,8 +189,9 @@ Rules:
World: World:
CrateSpawner: CrateSpawner:
Maximum: 3 Maximum: 3
SpawnInterval: 5 SpawnInterval: 125
CrateActors: unitcrate CrateActors: unitcrate
InitialSpawnDelay: 0
-SpawnMPUnits: -SpawnMPUnits:
-MPStartLocations: -MPStartLocations:
UNITCRATE: UNITCRATE:

View File

@@ -497,7 +497,7 @@ Rules:
World: World:
CrateSpawner: CrateSpawner:
Maximum: 1 Maximum: 1
SpawnInterval: 100 SpawnInterval: 2500
CrateActors: fortcrate CrateActors: fortcrate
-SpawnMPUnits: -SpawnMPUnits:
-MPStartLocations: -MPStartLocations:

View File

@@ -105,8 +105,8 @@ World:
QuantizedFacings: 16 QuantizedFacings: 16
Minimum: 1 Minimum: 1
Maximum: 3 Maximum: 3
SpawnInterval: 120 SpawnInterval: 3000
WaterChance: .2 WaterChance: 20
DomainIndex: DomainIndex:
SmudgeLayer@SCORCH: SmudgeLayer@SCORCH:
Type: Scorch Type: Scorch

View File

@@ -157,7 +157,7 @@ World:
CrateSpawner: CrateSpawner:
Minimum: 1 Minimum: 1
Maximum: 6 Maximum: 6
SpawnInterval: 120 SpawnInterval: 3000
WaterChance: 0 WaterChance: 0
ValidGround: Clear, Rough, Road, DirtRoad, Tiberium, BlueTiberium ValidGround: Clear, Rough, Road, DirtRoad, Tiberium, BlueTiberium
PathFinder: PathFinder: