From 5cfab33adab79ece72b84edba078cf917f24e447 Mon Sep 17 00:00:00 2001 From: Anuken Date: Wed, 12 Jun 2019 18:42:12 -0400 Subject: [PATCH] Fixed unit tests / Fixed zones having incorrect waves --- .../src/io/anuke/mindustry/content/Zones.java | 125 +++++++++--------- core/src/io/anuke/mindustry/core/Control.java | 2 +- core/src/io/anuke/mindustry/type/Zone.java | 3 +- tests/src/test/java/ApplicationTests.java | 43 +----- tests/src/test/java/ZoneTests.java | 19 ++- 5 files changed, 87 insertions(+), 105 deletions(-) diff --git a/core/src/io/anuke/mindustry/content/Zones.java b/core/src/io/anuke/mindustry/content/Zones.java index 9b6a57223e..45d7107242 100644 --- a/core/src/io/anuke/mindustry/content/Zones.java +++ b/core/src/io/anuke/mindustry/content/Zones.java @@ -1,7 +1,8 @@ package io.anuke.mindustry.content; import io.anuke.arc.collection.Array; -import io.anuke.mindustry.game.*; +import io.anuke.mindustry.game.ContentList; +import io.anuke.mindustry.game.SpawnGroup; import io.anuke.mindustry.maps.generators.MapGenerator; import io.anuke.mindustry.maps.generators.MapGenerator.Decoration; import io.anuke.mindustry.maps.zonegen.DesertWastesGenerator; @@ -25,11 +26,11 @@ public class Zones implements ContentList{ conditionWave = 5; launchPeriod = 5; resources = new Item[]{Items.copper, Items.scrap, Items.lead, Items.sand}; - rules = () -> new Rules(){{ - waves = true; - waveTimer = true; - waveSpacing = 60 * 60 * 2; - }}; + rules = r -> { + r.waves = true; + r.waveTimer = true; + r.waveSpacing = 60 * 60 * 2; + }; }}; desertWastes = new Zone("desertWastes", new DesertWastesGenerator(260, 260)){{ @@ -39,12 +40,12 @@ public class Zones implements ContentList{ loadout = Loadouts.advancedShard; zoneRequirements = ZoneRequirement.with(groundZero, 20); resources = new Item[]{Items.copper, Items.lead, Items.coal, Items.sand}; - rules = () -> new Rules(){{ - waves = true; - waveTimer = true; - launchWaveMultiplier = 3f; - waveSpacing = 60 * 50f; - spawns = Array.with( + rules = r -> { + r.waves = true; + r.waveTimer = true; + r.launchWaveMultiplier = 3f; + r.waveSpacing = 60 * 50f; + r.spawns = Array.with( new SpawnGroup(UnitTypes.crawler){{ unitScaling = 3f; }}, @@ -77,7 +78,7 @@ public class Zones implements ContentList{ spacing = 20; }} ); - }}; + }; }}; saltFlats = new Zone("saltFlats", new MapGenerator("saltFlats")){{ @@ -88,15 +89,15 @@ public class Zones implements ContentList{ launchPeriod = 5; zoneRequirements = ZoneRequirement.with(desertWastes, 60); resources = new Item[]{Items.copper, Items.scrap, Items.lead, Items.coal, Items.sand}; - rules = () -> new Rules(){{ - waves = true; - waveTimer = true; - attackMode = true; - waveSpacing = 60 * 60; - buildCostMultiplier = 0.5f; - unitBuildSpeedMultiplier = 0.5f; - enemyCheat = true; - }}; + rules = r -> { + r.waves = true; + r.waveTimer = true; + r.attackMode = true; + r.waveSpacing = 60 * 60; + r.buildCostMultiplier = 0.5f; + r.unitBuildSpeedMultiplier = 0.5f; + r.enemyCheat = true; + }; }}; craters = new Zone("craters", new MapGenerator("craters", 1).dist(0).decor(new Decoration(Blocks.snow, Blocks.sporeCluster, 0.01))){{ @@ -105,11 +106,11 @@ public class Zones implements ContentList{ zoneRequirements = ZoneRequirement.with(groundZero, 10); blockRequirements = new Block[]{Blocks.router}; resources = new Item[]{Items.copper, Items.lead, Items.coal}; - rules = () -> new Rules(){{ - waves = true; - waveTimer = true; - waveSpacing = 60 * 60 * 1.5f; - }}; + rules = r -> { + r.waves = true; + r.waveTimer = true; + r.waveSpacing = 60 * 60 * 1.5f; + }; }}; frozenForest = new Zone("frozenForest", new MapGenerator("frozenForest", 1) @@ -120,11 +121,11 @@ public class Zones implements ContentList{ conditionWave = 10; zoneRequirements = ZoneRequirement.with(craters, 10); resources = new Item[]{Items.copper, Items.lead, Items.coal}; - rules = () -> new Rules(){{ - waves = true; - waveTimer = true; - waveSpacing = 60 * 60 * 1.5f; - }}; + rules = r -> { + r.waves = true; + r.waveTimer = true; + r.waveSpacing = 60 * 60 * 1.5f; + }; }}; overgrowth = new Zone("overgrowth", new MapGenerator("overgrowth")){{ @@ -135,11 +136,11 @@ public class Zones implements ContentList{ zoneRequirements = ZoneRequirement.with(frozenForest, 40); blockRequirements = new Block[]{Blocks.router}; resources = new Item[]{Items.copper, Items.lead, Items.coal, Items.titanium, Items.sand, Items.thorium, Items.scrap}; - rules = () -> new Rules(){{ - waves = true; - waveTimer = true; - waveSpacing = 60 * 100f; - }}; + rules = r -> { + r.waves = true; + r.waveTimer = true; + r.waveSpacing = 60 * 100f; + }; }}; ruinousShores = new Zone("ruinousShores", new MapGenerator("ruinousShores", 1).dist(3f, true)){{ @@ -151,11 +152,11 @@ public class Zones implements ContentList{ zoneRequirements = ZoneRequirement.with(desertWastes, 20, craters, 15); blockRequirements = new Block[]{Blocks.graphitePress, Blocks.combustionGenerator}; resources = new Item[]{Items.copper, Items.scrap, Items.lead, Items.coal, Items.sand}; - rules = () -> new Rules(){{ - waves = true; - waveTimer = true; - waveSpacing = 60 * 80; - }}; + rules = r -> { + r.waves = true; + r.waveTimer = true; + r.waveSpacing = 60 * 80; + }; }}; stainedMountains = new Zone("stainedMountains", new MapGenerator("stainedMountains", 2) @@ -168,11 +169,11 @@ public class Zones implements ContentList{ zoneRequirements = ZoneRequirement.with(frozenForest, 15); blockRequirements = new Block[]{Blocks.pneumaticDrill}; resources = new Item[]{Items.copper, Items.scrap, Items.lead, Items.coal, Items.titanium, Items.sand}; - rules = () -> new Rules(){{ - waves = true; - waveTimer = true; - waveSpacing = 60 * 60 * 2; - }}; + rules = r -> { + r.waves = true; + r.waveTimer = true; + r.waveSpacing = 60 * 60 * 2; + }; }}; tarFields = new Zone("tarFields", new MapGenerator("tarFields") @@ -185,11 +186,11 @@ public class Zones implements ContentList{ zoneRequirements = ZoneRequirement.with(ruinousShores, 20); blockRequirements = new Block[]{Blocks.coalCentrifuge}; resources = new Item[]{Items.copper, Items.scrap, Items.lead, Items.coal, Items.titanium, Items.sand}; - rules = () -> new Rules(){{ - waves = true; - waveTimer = true; - waveSpacing = 60 * 60 * 2; - }}; + rules = r -> { + r.waves = true; + r.waveTimer = true; + r.waveSpacing = 60 * 60 * 2; + }; }}; desolateRift = new Zone("desolateRift", new MapGenerator("desolateRift").dist(2f)){{ @@ -201,11 +202,11 @@ public class Zones implements ContentList{ zoneRequirements = ZoneRequirement.with(tarFields, 20); blockRequirements = new Block[]{Blocks.thermalGenerator}; resources = new Item[]{Items.copper, Items.scrap, Items.lead, Items.coal, Items.titanium, Items.sand, Items.thorium}; - rules = () -> new Rules(){{ - waves = true; - waveTimer = true; - waveSpacing = 60 * 60 * 2.5f; - }}; + rules = r -> { + r.waves = true; + r.waveTimer = true; + r.waveSpacing = 60 * 60 * 2.5f; + }; }}; nuclearComplex = new Zone("nuclearComplex", new MapGenerator("nuclearProductionComplex", 1) @@ -218,11 +219,11 @@ public class Zones implements ContentList{ zoneRequirements = ZoneRequirement.with(stainedMountains, 20); blockRequirements = new Block[]{Blocks.thermalGenerator}; resources = new Item[]{Items.copper, Items.scrap, Items.lead, Items.coal, Items.titanium, Items.thorium, Items.sand}; - rules = () -> new Rules(){{ - waves = true; - waveTimer = true; - waveSpacing = 60 * 60 * 2; - }}; + rules = r -> { + r.waves = true; + r.waveTimer = true; + r.waveSpacing = 60 * 60 * 2; + }; }}; } } diff --git a/core/src/io/anuke/mindustry/core/Control.java b/core/src/io/anuke/mindustry/core/Control.java index 6862fb1362..3b87d16091 100644 --- a/core/src/io/anuke/mindustry/core/Control.java +++ b/core/src/io/anuke/mindustry/core/Control.java @@ -213,7 +213,7 @@ public class Control implements ApplicationListener{ ui.loadAnd(() -> { logic.reset(); world.loadGenerator(zone.generator); - state.rules = zone.rules.get(); + zone.rules.accept(state.rules); state.rules.zone = zone; for(Tile core : state.teams.get(defaultTeam).cores){ for(ItemStack stack : zone.getStartingItems()){ diff --git a/core/src/io/anuke/mindustry/type/Zone.java b/core/src/io/anuke/mindustry/type/Zone.java index 74ec3d9183..f0e936ae72 100644 --- a/core/src/io/anuke/mindustry/type/Zone.java +++ b/core/src/io/anuke/mindustry/type/Zone.java @@ -4,7 +4,6 @@ import io.anuke.arc.Core; import io.anuke.arc.Events; import io.anuke.arc.collection.Array; import io.anuke.arc.function.Consumer; -import io.anuke.arc.function.Supplier; import io.anuke.arc.graphics.g2d.TextureRegion; import io.anuke.arc.scene.ui.layout.Table; import io.anuke.arc.util.Structs; @@ -25,7 +24,7 @@ public class Zone extends UnlockableContent{ public Block[] blockRequirements = {}; public ZoneRequirement[] zoneRequirements = {}; public Item[] resources = {}; - public Supplier rules = Rules::new; + public Consumer rules = rules -> {}; public boolean alwaysUnlocked; public int conditionWave = Integer.MAX_VALUE; public int configureWave = 15; diff --git a/tests/src/test/java/ApplicationTests.java b/tests/src/test/java/ApplicationTests.java index baef9cd8ab..2ed4fbd0ab 100644 --- a/tests/src/test/java/ApplicationTests.java +++ b/tests/src/test/java/ApplicationTests.java @@ -1,6 +1,6 @@ -import io.anuke.arc.*; +import io.anuke.arc.ApplicationCore; +import io.anuke.arc.Core; import io.anuke.arc.backends.headless.HeadlessApplication; -import io.anuke.arc.collection.Array; import io.anuke.arc.math.geom.Point2; import io.anuke.arc.util.Log; import io.anuke.arc.util.Time; @@ -11,11 +11,13 @@ import io.anuke.mindustry.core.*; import io.anuke.mindustry.entities.traits.BuilderTrait.BuildRequest; import io.anuke.mindustry.entities.type.BaseUnit; import io.anuke.mindustry.entities.type.base.Spirit; -import io.anuke.mindustry.game.*; +import io.anuke.mindustry.game.Content; +import io.anuke.mindustry.game.Team; import io.anuke.mindustry.io.BundleLoader; import io.anuke.mindustry.io.SaveIO; import io.anuke.mindustry.maps.Map; -import io.anuke.mindustry.type.*; +import io.anuke.mindustry.type.ContentType; +import io.anuke.mindustry.type.Item; import io.anuke.mindustry.world.*; import io.anuke.mindustry.world.blocks.BlockPart; import org.junit.jupiter.api.*; @@ -266,39 +268,6 @@ public class ApplicationTests{ assertTrue(world.tile(1, 1).block() instanceof BlockPart); } - @Test - void zoneEmptyWaves(){ - for(Zone zone : content.zones()){ - Array spawns = zone.rules.get().spawns; - for(int i = 1; i <= 100; i++){ - int total = 0; - for(SpawnGroup spawn : spawns){ - total += spawn.getUnitsSpawned(i); - } - - assertNotEquals(0, total, "Zone " + zone + " has no spawned enemies at wave " + i); - } - } - } - - @Test - void zoneOverflowWaves(){ - for(Zone zone : content.zones()){ - Array spawns = zone.rules.get().spawns; - - for(int i = 1; i <= 40; i++){ - int total = 0; - for(SpawnGroup spawn : spawns){ - total += spawn.getUnitsSpawned(i); - } - - if(total >= 140){ - fail("Zone '" + zone + "' has too many spawned enemies at wave " + i + " : " + total); - } - } - } - } - @Test void buildingDestruction(){ initBuilding(); diff --git a/tests/src/test/java/ZoneTests.java b/tests/src/test/java/ZoneTests.java index c46974116e..8ad2a2f6fe 100644 --- a/tests/src/test/java/ZoneTests.java +++ b/tests/src/test/java/ZoneTests.java @@ -3,6 +3,7 @@ import io.anuke.arc.collection.ObjectSet; import io.anuke.arc.util.Structs; import io.anuke.arc.util.Time; import io.anuke.mindustry.core.GameState.State; +import io.anuke.mindustry.game.SpawnGroup; import io.anuke.mindustry.type.Item; import io.anuke.mindustry.type.Zone; import io.anuke.mindustry.world.Tile; @@ -10,6 +11,7 @@ import io.anuke.mindustry.world.blocks.storage.CoreBlock; import org.junit.jupiter.api.*; import static io.anuke.mindustry.Vars.*; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.DynamicTest.dynamicTest; @@ -28,7 +30,7 @@ public class ZoneTests{ } @TestFactory - DynamicTest[] testZoneResources(){ + DynamicTest[] testZoneValidity(){ Array out = new Array<>(); for(Zone zone : content.zones()){ @@ -36,6 +38,7 @@ public class ZoneTests{ zone.generator.init(zone.loadout); logic.reset(); world.loadGenerator(zone.generator); + zone.rules.accept(state.rules); ObjectSet resources = new ObjectSet<>(); boolean hasSpawnPoint = false; @@ -51,15 +54,25 @@ public class ZoneTests{ } } + Array spawns = state.rules.spawns; + for(int i = 1; i <= 100; i++){ + int total = 0; + for(SpawnGroup spawn : spawns){ + total += spawn.getUnitsSpawned(i); + } + + assertNotEquals(0, total, "Zone " + zone + " has no spawned enemies at wave " + i); + } + assertTrue(hasSpawnPoint, "Zone \"" + zone.name + "\" has no spawn points."); - assertTrue(world.spawner.countSpawns() > 0 || (zone.rules.get().attackMode && !state.teams.get(waveTeam).cores.isEmpty()), "Zone \"" + zone.name + "\" has no enemy spawn points: " + world.spawner.countSpawns()); + assertTrue(world.spawner.countSpawns() > 0 || (state.rules.attackMode && !state.teams.get(waveTeam).cores.isEmpty()), "Zone \"" + zone.name + "\" has no enemy spawn points: " + world.spawner.countSpawns()); for(Item item : resources){ assertTrue(Structs.contains(zone.resources, item), "Zone \"" + zone.name + "\" is missing item in resource list: \"" + item.name + "\""); } for(Item item : zone.resources){ - assertTrue(resources.contains(item), "Zone \"" + zone.name + "\" has unnecessary item in resoruce list: \"" + item.name + "\""); + assertTrue(resources.contains(item), "Zone \"" + zone.name + "\" has unnecessary item in resource list: \"" + item.name + "\""); } })); }