Sector -2 0 fix (#322)
* Added a battle mission to Sector (-2,0) as otherwise no core would be spawned * Fixed a crash which occurred during test execution... ... and could maybe occur during any startup with bad timing * Added a new class for sector tests ... ... and added a test which makes sure that any predefined sector defines a spawn point * Added fix after applying test driven bugfixing
This commit is contained in:
@@ -247,7 +247,7 @@ public class BlockIndexer{
|
|||||||
for(int x = quadrantX * structQuadrantSize; x < world.width() && x < (quadrantX + 1) * structQuadrantSize; x++){
|
for(int x = quadrantX * structQuadrantSize; x < world.width() && x < (quadrantX + 1) * structQuadrantSize; x++){
|
||||||
for(int y = quadrantY * structQuadrantSize; y < world.height() && y < (quadrantY + 1) * structQuadrantSize; y++){
|
for(int y = quadrantY * structQuadrantSize; y < world.height() && y < (quadrantY + 1) * structQuadrantSize; y++){
|
||||||
Tile result = world.tile(x, y);
|
Tile result = world.tile(x, y);
|
||||||
if(result.block().drops == null || !scanOres.contains(result.block().drops.item)) continue;
|
if( result == null || result.block().drops == null || !scanOres.contains(result.block().drops.item)) continue;
|
||||||
|
|
||||||
itemSet.add(result.block().drops.item);
|
itemSet.add(result.block().drops.item);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,7 +56,8 @@ public class SectorPresets{
|
|||||||
Missions.blockRecipe(ProductionBlocks.waterExtractor),
|
Missions.blockRecipe(ProductionBlocks.waterExtractor),
|
||||||
new ContentMission(Items.biomatter),
|
new ContentMission(Items.biomatter),
|
||||||
Missions.blockRecipe(CraftingBlocks.biomatterCompressor),
|
Missions.blockRecipe(CraftingBlocks.biomatterCompressor),
|
||||||
new ContentMission(Liquids.oil)
|
new ContentMission(Liquids.oil),
|
||||||
|
new BattleMission()
|
||||||
),
|
),
|
||||||
Array.with(Items.copper, Items.lead, Items.coal, Items.titanium)));
|
Array.with(Items.copper, Items.lead, Items.coal, Items.titanium)));
|
||||||
}
|
}
|
||||||
@@ -69,6 +70,8 @@ public class SectorPresets{
|
|||||||
return presets.get(x, y);
|
return presets.get(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GridMap<SectorPreset> getPresets() { return presets; }
|
||||||
|
|
||||||
private void add(SectorPreset preset){
|
private void add(SectorPreset preset){
|
||||||
presets.put(preset.x, preset.y, preset);
|
presets.put(preset.x, preset.y, preset);
|
||||||
orePresets.put(preset.x, preset.y, preset.ores);
|
orePresets.put(preset.x, preset.y, preset.ores);
|
||||||
|
|||||||
54
tests/src/test/java/SectorTests.java
Normal file
54
tests/src/test/java/SectorTests.java
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
import com.badlogic.gdx.utils.Array;
|
||||||
|
import io.anuke.mindustry.Vars;
|
||||||
|
import io.anuke.mindustry.core.ContentLoader;
|
||||||
|
import io.anuke.mindustry.maps.SectorPresets;
|
||||||
|
import io.anuke.mindustry.maps.generation.Generation;
|
||||||
|
import io.anuke.mindustry.maps.missions.Mission;
|
||||||
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
/** This class is responsible for testing predefined sectors. */
|
||||||
|
public class SectorTests{
|
||||||
|
|
||||||
|
private SectorPresets presets;
|
||||||
|
private Generation fakeGen;
|
||||||
|
|
||||||
|
@BeforeAll
|
||||||
|
static void initializeDependencies(){
|
||||||
|
Vars.content = new ContentLoader();
|
||||||
|
Vars.content.load();
|
||||||
|
}
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void initTest(){
|
||||||
|
this.presets = new SectorPresets();
|
||||||
|
|
||||||
|
// Fake away the Generation dependency
|
||||||
|
this.fakeGen = new Generation(null, null, 250, 250, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns true if at least one mission provides a spawn point. */
|
||||||
|
private boolean spawnPointIsDefined(Array<Mission> missions){
|
||||||
|
for(Mission mission : missions){
|
||||||
|
if(mission.getSpawnPoints(this.fakeGen).size > 0){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// No spawn point provided
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Makes sure that every predefined sector has a position for the player core defined.
|
||||||
|
* This is achieved by adding at least one mission which defines a spawn point.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
void test_sectorHasACore(){
|
||||||
|
for(SectorPresets.SectorPreset preset : this.presets.getPresets().values()){
|
||||||
|
assertTrue(spawnPointIsDefined(preset.missions), "Sector at (" + preset.x + "|" + preset.y + ") contains no missions which define a spawn point. Add a battle or wave mission.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user