mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-07 00:38:26 +07:00
Added random PvP/Waves map generation
This commit is contained in:
@ -655,6 +655,7 @@ block.arc.name=Arc
|
|||||||
block.rtg-generator.name=RTG Generator
|
block.rtg-generator.name=RTG Generator
|
||||||
block.spectre.name=Spectre
|
block.spectre.name=Spectre
|
||||||
block.meltdown.name=Meltdown
|
block.meltdown.name=Meltdown
|
||||||
|
block.container.name=Container
|
||||||
|
|
||||||
team.blue.name=blue
|
team.blue.name=blue
|
||||||
team.red.name=red
|
team.red.name=red
|
||||||
|
@ -251,16 +251,11 @@ public class Control extends Module{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void playMap(Map map){
|
public void playMap(Map map){
|
||||||
ui.loadfrag.show();
|
ui.loadLogic(() -> {
|
||||||
|
|
||||||
Timers.run(5f, () ->
|
|
||||||
threads.run(() -> {
|
|
||||||
logic.reset();
|
logic.reset();
|
||||||
world.loadMap(map);
|
world.loadMap(map);
|
||||||
logic.play();
|
logic.play();
|
||||||
|
});
|
||||||
Gdx.app.postRunnable(ui.loadfrag::hide);
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isHighScore(){
|
public boolean isHighScore(){
|
||||||
|
@ -34,7 +34,7 @@ public class Sectors{
|
|||||||
|
|
||||||
private final GridMap<Sector> grid = new GridMap<>();
|
private final GridMap<Sector> grid = new GridMap<>();
|
||||||
private final SectorPresets presets = new SectorPresets();
|
private final SectorPresets presets = new SectorPresets();
|
||||||
private final Array<Item> allOres = Array.with(Items.copper, Items.lead, Items.coal, Items.titanium, Items.thorium);
|
private final Array<Item> allOres = Item.getAllOres();
|
||||||
|
|
||||||
public void playSector(Sector sector){
|
public void playSector(Sector sector){
|
||||||
if(sector.hasSave() && SaveIO.breakingVersions.contains(sector.getSave().getBuild())){
|
if(sector.hasSave() && SaveIO.breakingVersions.contains(sector.getSave().getBuild())){
|
||||||
|
@ -8,7 +8,9 @@ import com.badlogic.gdx.utils.ObjectMap;
|
|||||||
import io.anuke.mindustry.content.Items;
|
import io.anuke.mindustry.content.Items;
|
||||||
import io.anuke.mindustry.content.blocks.Blocks;
|
import io.anuke.mindustry.content.blocks.Blocks;
|
||||||
import io.anuke.mindustry.content.blocks.OreBlocks;
|
import io.anuke.mindustry.content.blocks.OreBlocks;
|
||||||
|
import io.anuke.mindustry.content.blocks.StorageBlocks;
|
||||||
import io.anuke.mindustry.game.Team;
|
import io.anuke.mindustry.game.Team;
|
||||||
|
import io.anuke.mindustry.maps.Map;
|
||||||
import io.anuke.mindustry.maps.MapTileData;
|
import io.anuke.mindustry.maps.MapTileData;
|
||||||
import io.anuke.mindustry.maps.MapTileData.TileDataMarker;
|
import io.anuke.mindustry.maps.MapTileData.TileDataMarker;
|
||||||
import io.anuke.mindustry.maps.Sector;
|
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.SeedRandom;
|
||||||
import io.anuke.ucore.util.Structs;
|
import io.anuke.ucore.util.Structs;
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.sectorSize;
|
import static io.anuke.mindustry.Vars.*;
|
||||||
import static io.anuke.mindustry.Vars.world;
|
|
||||||
|
|
||||||
|
|
||||||
public class WorldGenerator{
|
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<GridPoint2> spawns = new Array<>();
|
||||||
|
Array<Item> 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<Item> usedOres){
|
public void generateOres(Tile[][] tiles, long seed, boolean genOres, Array<Item> usedOres){
|
||||||
oreIndex = 0;
|
oreIndex = 0;
|
||||||
|
|
||||||
|
@ -2,6 +2,8 @@ package io.anuke.mindustry.type;
|
|||||||
|
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
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.game.UnlockableContent;
|
||||||
import io.anuke.mindustry.graphics.Palette;
|
import io.anuke.mindustry.graphics.Palette;
|
||||||
import io.anuke.mindustry.ui.ContentDisplay;
|
import io.anuke.mindustry.ui.ContentDisplay;
|
||||||
@ -95,4 +97,12 @@ public class Item extends UnlockableContent implements Comparable<Item>{
|
|||||||
public ContentType getContentType(){
|
public ContentType getContentType(){
|
||||||
return ContentType.item;
|
return ContentType.item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Array<Item> getAllOres(){
|
||||||
|
Array<Item> arr = new Array<>();
|
||||||
|
for(Item item : Vars.content.items()){
|
||||||
|
if(item.genOre) arr.add(item);
|
||||||
|
}
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,6 +89,7 @@ public class CustomGameDialog extends FloatingDialog{
|
|||||||
float images = 146f;
|
float images = 146f;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
|
maps.defaults().width(170).fillY().top().pad(4f);
|
||||||
for(Map map : world.maps.all()){
|
for(Map map : world.maps.all()){
|
||||||
|
|
||||||
if(i % maxwidth == 0){
|
if(i % maxwidth == 0){
|
||||||
@ -112,11 +113,18 @@ public class CustomGameDialog extends FloatingDialog{
|
|||||||
control.playMap(map);
|
control.playMap(map);
|
||||||
});
|
});
|
||||||
|
|
||||||
maps.add(image).width(170).fillY().top().pad(4f);
|
maps.add(image);
|
||||||
|
|
||||||
i++;
|
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){
|
if(world.maps.all().size == 0){
|
||||||
maps.add("$text.maps.none").pad(50);
|
maps.add("$text.maps.none").pad(50);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user