From 1bc70a6a2148902d23d7443d142317c0295a1407 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 6 Jul 2021 10:57:29 +0200 Subject: [PATCH 1/9] Changed iron density in cave to match small/big chunk ratios of Meso --- simulation_parameters/microbe_stage/biomes.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simulation_parameters/microbe_stage/biomes.json b/simulation_parameters/microbe_stage/biomes.json index 68e9059514b..3b091e4ce12 100644 --- a/simulation_parameters/microbe_stage/biomes.json +++ b/simulation_parameters/microbe_stage/biomes.json @@ -1290,7 +1290,7 @@ "convexShapePath": "res://assets/models/Iron4.shape" } ], - "density": 0.0001, + "density": 0.001, "dissolves": true, "radius": 1, "chunkScale": 1, From 6d225df9b034c65336d14666f8e7826724575c9f Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 6 Jul 2021 14:12:52 +0200 Subject: [PATCH 2/9] Does one attempt per spawner up to max instead of max per spawner to diversify generation - esp. in cave --- src/microbe_stage/SpawnSystem.cs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/microbe_stage/SpawnSystem.cs b/src/microbe_stage/SpawnSystem.cs index d6899fabc2d..ca3362c8543 100644 --- a/src/microbe_stage/SpawnSystem.cs +++ b/src/microbe_stage/SpawnSystem.cs @@ -232,7 +232,19 @@ private void SpawnEntities(Vector3 playerPosition, Vector3 playerRotation, int e int spawned = 0; + // TODO ugly + Dictionary attemptsPerSpawnType = new Dictionary(); + int maxAttempts = -1; foreach (var spawnType in spawnTypes) + { + int numAttempts = Math.Min(Math.Max(spawnType.SpawnFrequency * 2, 1), + maxTriesPerSpawner); + attemptsPerSpawnType[spawnType] = numAttempts; + if (numAttempts > maxAttempts) + maxAttempts = numAttempts; + } + + for (int i = 0; i < maxAttempts; i++) { /* To actually spawn a given entity for a given attempt, two @@ -249,11 +261,13 @@ entity multiple times depending on the spawnFrequency. numAttempts stores how many times the SpawnSystem attempts to spawn the given entity. */ - int numAttempts = Math.Min(Math.Max(spawnType.SpawnFrequency * 2, 1), - maxTriesPerSpawner); - for (int i = 0; i < numAttempts; i++) + foreach (var spawnType in spawnTypes) { + int numAttempts = attemptsPerSpawnType[spawnType]; + if (i > numAttempts) + continue; + if (random.Next(0, numAttempts + 1) < spawnType.SpawnFrequency) { /* From 6bb73ab6c8b88802e63307f9d025343e6055b4dd Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 6 Jul 2021 14:17:31 +0200 Subject: [PATCH 3/9] Code optimisation, comments, cleaning --- src/microbe_stage/SpawnSystem.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/microbe_stage/SpawnSystem.cs b/src/microbe_stage/SpawnSystem.cs index ca3362c8543..620644faa55 100644 --- a/src/microbe_stage/SpawnSystem.cs +++ b/src/microbe_stage/SpawnSystem.cs @@ -68,6 +68,8 @@ public class SpawnSystem /// private int estimateEntityCount; + private Dictionary attemptsPerSpawnType; + public SpawnSystem(Node root) { worldRoot = root; @@ -232,8 +234,7 @@ private void SpawnEntities(Vector3 playerPosition, Vector3 playerRotation, int e int spawned = 0; - // TODO ugly - Dictionary attemptsPerSpawnType = new Dictionary(); + attemptsPerSpawnType.Clear(); int maxAttempts = -1; foreach (var spawnType in spawnTypes) { @@ -265,6 +266,8 @@ to spawn the given entity. foreach (var spawnType in spawnTypes) { int numAttempts = attemptsPerSpawnType[spawnType]; + + // Already did max attempts for this type if (i > numAttempts) continue; From 244e92b50bf7e2a9eecf6a0845d7531aa6173f9e Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 6 Jul 2021 14:27:53 +0200 Subject: [PATCH 4/9] Initialized attemptsPerSpawnType --- src/microbe_stage/SpawnSystem.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/microbe_stage/SpawnSystem.cs b/src/microbe_stage/SpawnSystem.cs index 620644faa55..0ec82b33c54 100644 --- a/src/microbe_stage/SpawnSystem.cs +++ b/src/microbe_stage/SpawnSystem.cs @@ -73,6 +73,7 @@ public class SpawnSystem public SpawnSystem(Node root) { worldRoot = root; + attemptsPerSpawnType = new Dictionary(); } // Needs no params constructor for loading saves? From 32e67e74750486da34d10d77171d7daa8ec5625a Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 6 Jul 2021 15:13:08 +0200 Subject: [PATCH 5/9] Added code explanation --- src/microbe_stage/SpawnSystem.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/microbe_stage/SpawnSystem.cs b/src/microbe_stage/SpawnSystem.cs index 0ec82b33c54..bf61ae093c0 100644 --- a/src/microbe_stage/SpawnSystem.cs +++ b/src/microbe_stage/SpawnSystem.cs @@ -261,7 +261,9 @@ To allow more than one entity of each type to spawn per spawn cycle, the SpawnSystem attempts to spawn each given entity multiple times depending on the spawnFrequency. numAttempts stores how many times the SpawnSystem attempts - to spawn the given entity. + to spawn the given entity. Furthermore, each attempt gives a spawn chance + for each spawner (up to their type limit) to still favor diversity, + instead of one spawner taking up all the free spawning slots. */ foreach (var spawnType in spawnTypes) From 59848d465bd3c6d4fe291747925adfa7a1af20c7 Mon Sep 17 00:00:00 2001 From: Maxonovien Date: Wed, 7 Jul 2021 11:36:40 +0200 Subject: [PATCH 6/9] Styling Co-authored-by: adQuid <28126232+adQuid@users.noreply.github.com> --- src/microbe_stage/SpawnSystem.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/microbe_stage/SpawnSystem.cs b/src/microbe_stage/SpawnSystem.cs index bf61ae093c0..abc7974d6dd 100644 --- a/src/microbe_stage/SpawnSystem.cs +++ b/src/microbe_stage/SpawnSystem.cs @@ -242,6 +242,7 @@ private void SpawnEntities(Vector3 playerPosition, Vector3 playerRotation, int e int numAttempts = Math.Min(Math.Max(spawnType.SpawnFrequency * 2, 1), maxTriesPerSpawner); attemptsPerSpawnType[spawnType] = numAttempts; + if (numAttempts > maxAttempts) maxAttempts = numAttempts; } From e8c0c56cac8acd86f54a62586b9a2a4511fd9c11 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 7 Jul 2021 11:44:11 +0200 Subject: [PATCH 7/9] Fix Styling --- src/microbe_stage/SpawnSystem.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/microbe_stage/SpawnSystem.cs b/src/microbe_stage/SpawnSystem.cs index abc7974d6dd..20f868a0777 100644 --- a/src/microbe_stage/SpawnSystem.cs +++ b/src/microbe_stage/SpawnSystem.cs @@ -242,7 +242,7 @@ private void SpawnEntities(Vector3 playerPosition, Vector3 playerRotation, int e int numAttempts = Math.Min(Math.Max(spawnType.SpawnFrequency * 2, 1), maxTriesPerSpawner); attemptsPerSpawnType[spawnType] = numAttempts; - + if (numAttempts > maxAttempts) maxAttempts = numAttempts; } From 18925d686b3723301995b912a7f04f4f6d50f83e Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 7 Jul 2021 18:45:06 +0200 Subject: [PATCH 8/9] Fixed styling --- src/microbe_stage/SpawnSystem.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/microbe_stage/SpawnSystem.cs b/src/microbe_stage/SpawnSystem.cs index 20f868a0777..97a2df3ae94 100644 --- a/src/microbe_stage/SpawnSystem.cs +++ b/src/microbe_stage/SpawnSystem.cs @@ -239,12 +239,12 @@ private void SpawnEntities(Vector3 playerPosition, Vector3 playerRotation, int e int maxAttempts = -1; foreach (var spawnType in spawnTypes) { - int numAttempts = Math.Min(Math.Max(spawnType.SpawnFrequency * 2, 1), + int attempts = Math.Min(Math.Max(spawnType.SpawnFrequency * 2, 1), maxTriesPerSpawner); - attemptsPerSpawnType[spawnType] = numAttempts; + attemptsPerSpawnType[spawnType] = attempts; - if (numAttempts > maxAttempts) - maxAttempts = numAttempts; + if (attempts > maxAttempts) + maxAttempts = attempts; } for (int i = 0; i < maxAttempts; i++) @@ -269,13 +269,13 @@ instead of one spawner taking up all the free spawning slots. foreach (var spawnType in spawnTypes) { - int numAttempts = attemptsPerSpawnType[spawnType]; + int attempts = attemptsPerSpawnType[spawnType]; // Already did max attempts for this type - if (i > numAttempts) + if (i > attempts) continue; - if (random.Next(0, numAttempts + 1) < spawnType.SpawnFrequency) + if (random.Next(0, attempts + 1) < spawnType.SpawnFrequency) { /* First condition passed. Choose a location for the entity. From 9df68639f5c21f557f72a0f5437d926c31caa51c Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 10 Jul 2021 00:14:09 +0200 Subject: [PATCH 9/9] Replaced min and max by mathf.clamp --- src/microbe_stage/SpawnSystem.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/microbe_stage/SpawnSystem.cs b/src/microbe_stage/SpawnSystem.cs index 97a2df3ae94..ffc6683f44b 100644 --- a/src/microbe_stage/SpawnSystem.cs +++ b/src/microbe_stage/SpawnSystem.cs @@ -239,8 +239,7 @@ private void SpawnEntities(Vector3 playerPosition, Vector3 playerRotation, int e int maxAttempts = -1; foreach (var spawnType in spawnTypes) { - int attempts = Math.Min(Math.Max(spawnType.SpawnFrequency * 2, 1), - maxTriesPerSpawner); + int attempts = Mathf.Clamp(spawnType.SpawnFrequency * 2, 1, maxTriesPerSpawner); attemptsPerSpawnType[spawnType] = attempts; if (attempts > maxAttempts)