diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index 84511dacf1..643656803b 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -655,6 +655,7 @@ block.arc.name=Arc block.rtg-generator.name=RTG Generator block.spectre.name=Spectre block.meltdown.name=Meltdown +block.container.name=Container team.blue.name=blue team.red.name=red diff --git a/core/src/io/anuke/mindustry/core/Control.java b/core/src/io/anuke/mindustry/core/Control.java index 19f5b7a889..bc30c48359 100644 --- a/core/src/io/anuke/mindustry/core/Control.java +++ b/core/src/io/anuke/mindustry/core/Control.java @@ -251,16 +251,11 @@ public class Control extends Module{ } public void playMap(Map map){ - ui.loadfrag.show(); - - Timers.run(5f, () -> - threads.run(() -> { - logic.reset(); - world.loadMap(map); - logic.play(); - - Gdx.app.postRunnable(ui.loadfrag::hide); - })); + ui.loadLogic(() -> { + logic.reset(); + world.loadMap(map); + logic.play(); + }); } public boolean isHighScore(){ diff --git a/core/src/io/anuke/mindustry/maps/Sectors.java b/core/src/io/anuke/mindustry/maps/Sectors.java index 7ff39f5bbe..adc7ca0a90 100644 --- a/core/src/io/anuke/mindustry/maps/Sectors.java +++ b/core/src/io/anuke/mindustry/maps/Sectors.java @@ -34,7 +34,7 @@ public class Sectors{ private final GridMap grid = new GridMap<>(); private final SectorPresets presets = new SectorPresets(); - private final Array allOres = Array.with(Items.copper, Items.lead, Items.coal, Items.titanium, Items.thorium); + private final Array allOres = Item.getAllOres(); public void playSector(Sector sector){ if(sector.hasSave() && SaveIO.breakingVersions.contains(sector.getSave().getBuild())){ diff --git a/core/src/io/anuke/mindustry/maps/generation/WorldGenerator.java b/core/src/io/anuke/mindustry/maps/generation/WorldGenerator.java index 6f4c6d4f12..d7d1301b04 100644 --- a/core/src/io/anuke/mindustry/maps/generation/WorldGenerator.java +++ b/core/src/io/anuke/mindustry/maps/generation/WorldGenerator.java @@ -8,7 +8,9 @@ import com.badlogic.gdx.utils.ObjectMap; import io.anuke.mindustry.content.Items; import io.anuke.mindustry.content.blocks.Blocks; import io.anuke.mindustry.content.blocks.OreBlocks; +import io.anuke.mindustry.content.blocks.StorageBlocks; import io.anuke.mindustry.game.Team; +import io.anuke.mindustry.maps.Map; import io.anuke.mindustry.maps.MapTileData; import io.anuke.mindustry.maps.MapTileData.TileDataMarker; import io.anuke.mindustry.maps.Sector; @@ -25,8 +27,7 @@ import io.anuke.ucore.util.Mathf; import io.anuke.ucore.util.SeedRandom; import io.anuke.ucore.util.Structs; -import static io.anuke.mindustry.Vars.sectorSize; -import static io.anuke.mindustry.Vars.world; +import static io.anuke.mindustry.Vars.*; public class WorldGenerator{ @@ -138,6 +139,49 @@ public class WorldGenerator{ } } + public void playRandomMap(){ + ui.loadLogic(() -> { + logic.reset(); + + int sx = (short)Mathf.range(Short.MAX_VALUE/2); + int sy = (short)Mathf.range(Short.MAX_VALUE/2); + int width = 380; + int height = 380; + Array spawns = new Array<>(); + Array ores = Item.getAllOres(); + + if(state.mode.isPvp){ + int scaling = 10; + spawns.add(new GridPoint2(width/scaling, height/scaling)); + spawns.add(new GridPoint2(width - 1 - width/scaling, height - 1 - height/scaling)); + }else{ + spawns.add(new GridPoint2(width/2, height/2)); + } + + Tile[][] tiles = world.createTiles(width, height); + world.setMap(new Map("Generated Map", width, height)); + world.beginMapLoad(); + + for(int x = 0; x < width; x++){ + for(int y = 0; y < height; y++){ + generateTile(result, sx, sy, x, y, true, spawns, ores); + tiles[x][y] = new Tile(x, y, result.floor.id, result.wall.id, (byte)0, (byte)0, result.elevation); + } + } + + prepareTiles(tiles); + + world.setBlock(tiles[spawns.get(0).x][spawns.get(0).y], StorageBlocks.core, Team.blue); + + if(state.mode.isPvp){ + world.setBlock(tiles[spawns.get(1).x][spawns.get(1).y], StorageBlocks.core, Team.red); + } + + world.endMapLoad(); + logic.play(); + }); + } + public void generateOres(Tile[][] tiles, long seed, boolean genOres, Array usedOres){ oreIndex = 0; diff --git a/core/src/io/anuke/mindustry/type/Item.java b/core/src/io/anuke/mindustry/type/Item.java index 2860056a20..62e91451ed 100644 --- a/core/src/io/anuke/mindustry/type/Item.java +++ b/core/src/io/anuke/mindustry/type/Item.java @@ -2,6 +2,8 @@ package io.anuke.mindustry.type; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.g2d.TextureRegion; +import com.badlogic.gdx.utils.Array; +import io.anuke.mindustry.Vars; import io.anuke.mindustry.game.UnlockableContent; import io.anuke.mindustry.graphics.Palette; import io.anuke.mindustry.ui.ContentDisplay; @@ -95,4 +97,12 @@ public class Item extends UnlockableContent implements Comparable{ public ContentType getContentType(){ return ContentType.item; } + + public static Array getAllOres(){ + Array arr = new Array<>(); + for(Item item : Vars.content.items()){ + if(item.genOre) arr.add(item); + } + return arr; + } } diff --git a/core/src/io/anuke/mindustry/ui/dialogs/CustomGameDialog.java b/core/src/io/anuke/mindustry/ui/dialogs/CustomGameDialog.java index 021d87fd04..329eead0d2 100644 --- a/core/src/io/anuke/mindustry/ui/dialogs/CustomGameDialog.java +++ b/core/src/io/anuke/mindustry/ui/dialogs/CustomGameDialog.java @@ -89,6 +89,7 @@ public class CustomGameDialog extends FloatingDialog{ float images = 146f; i = 0; + maps.defaults().width(170).fillY().top().pad(4f); for(Map map : world.maps.all()){ if(i % maxwidth == 0){ @@ -112,11 +113,18 @@ public class CustomGameDialog extends FloatingDialog{ control.playMap(map); }); - maps.add(image).width(170).fillY().top().pad(4f); + maps.add(image); i++; } + ImageButton gen = maps.addImageButton("icon-editor", "clear", 16*4, () -> { + hide(); + world.generator.playRandomMap(); + }).growY().get(); + gen.row(); + gen.add("$text.map.random"); + if(world.maps.all().size == 0){ maps.add("$text.maps.none").pad(50); }