Generator cleanup
This commit is contained in:
@@ -22,7 +22,7 @@ public class Zones implements ContentList{
|
||||
@Override
|
||||
public void load(){
|
||||
|
||||
groundZero = new Zone("groundZero", starter, new MapGenerator("groundZero")){{
|
||||
groundZero = new Zone("groundZero", starter, new FileMapGenerator("groundZero")){{
|
||||
baseLaunchCost = list(copper, -60);
|
||||
startingItems = list(copper, 60);
|
||||
alwaysUnlocked = true;
|
||||
@@ -31,7 +31,7 @@ public class Zones implements ContentList{
|
||||
resources = with(copper, scrap, lead);
|
||||
}};
|
||||
|
||||
desertWastes = new Zone("desertWastes", starter, new DesertWastesGenerator(260, 260)){{
|
||||
desertWastes = new Zone("desertWastes", starter, new DesertWastesGenerator()){{
|
||||
startingItems = list(copper, 120);
|
||||
conditionWave = 20;
|
||||
launchPeriod = 10;
|
||||
@@ -82,7 +82,7 @@ public class Zones implements ContentList{
|
||||
);
|
||||
}};
|
||||
|
||||
saltFlats = new Zone("saltFlats", starter, new MapGenerator("saltFlats")){{
|
||||
saltFlats = new Zone("saltFlats", starter, new FileMapGenerator("saltFlats")){{
|
||||
startingItems = list(copper, 200, Items.silicon, 200, lead, 200);
|
||||
loadout = Loadouts.basicFoundation;
|
||||
conditionWave = 10;
|
||||
@@ -98,7 +98,7 @@ public class Zones implements ContentList{
|
||||
);
|
||||
}};
|
||||
|
||||
frozenForest = new Zone("frozenForest", starter, new MapGenerator("frozenForest")){{
|
||||
frozenForest = new Zone("frozenForest", starter, new FileMapGenerator("frozenForest")){{
|
||||
loadout = Loadouts.basicFoundation;
|
||||
startingItems = list(copper, 250);
|
||||
conditionWave = 10;
|
||||
@@ -110,7 +110,7 @@ public class Zones implements ContentList{
|
||||
);
|
||||
}};
|
||||
|
||||
craters = new Zone("craters", starter, new MapGenerator("craters")){{
|
||||
craters = new Zone("craters", starter, new FileMapGenerator("craters")){{
|
||||
startingItems = list(copper, 100);
|
||||
conditionWave = 10;
|
||||
resources = with(copper, lead, coal, sand, scrap);
|
||||
@@ -121,7 +121,7 @@ public class Zones implements ContentList{
|
||||
);
|
||||
}};
|
||||
|
||||
ruinousShores = new Zone("ruinousShores", starter, new MapGenerator("ruinousShores")){{
|
||||
ruinousShores = new Zone("ruinousShores", starter, new FileMapGenerator("ruinousShores")){{
|
||||
loadout = Loadouts.basicFoundation;
|
||||
startingItems = list(copper, 140, lead, 50);
|
||||
conditionWave = 20;
|
||||
@@ -137,7 +137,7 @@ public class Zones implements ContentList{
|
||||
);
|
||||
}};
|
||||
|
||||
stainedMountains = new Zone("stainedMountains", starter, new MapGenerator("stainedMountains")){{
|
||||
stainedMountains = new Zone("stainedMountains", starter, new FileMapGenerator("stainedMountains")){{
|
||||
loadout = Loadouts.basicFoundation;
|
||||
startingItems = list(copper, 200, lead, 50);
|
||||
conditionWave = 10;
|
||||
@@ -151,7 +151,7 @@ public class Zones implements ContentList{
|
||||
);
|
||||
}};
|
||||
|
||||
fungalPass = new Zone("fungalPass", starter, new MapGenerator("fungalPass")){{
|
||||
fungalPass = new Zone("fungalPass", starter, new FileMapGenerator("fungalPass")){{
|
||||
startingItems = list(copper, 250, lead, 250, Items.metaglass, 100, Items.graphite, 100);
|
||||
resources = with(copper, lead, coal, titanium, sand);
|
||||
configureObjective = new Launched(this);
|
||||
@@ -164,7 +164,7 @@ public class Zones implements ContentList{
|
||||
);
|
||||
}};
|
||||
|
||||
overgrowth = new Zone("overgrowth", starter, new MapGenerator("overgrowth")){{
|
||||
overgrowth = new Zone("overgrowth", starter, new FileMapGenerator("overgrowth")){{
|
||||
startingItems = list(copper, 1500, lead, 1000, Items.silicon, 500, Items.metaglass, 250);
|
||||
conditionWave = 12;
|
||||
launchPeriod = 4;
|
||||
@@ -181,7 +181,7 @@ public class Zones implements ContentList{
|
||||
);
|
||||
}};
|
||||
|
||||
tarFields = new Zone("tarFields", starter, new MapGenerator("tarFields")){{
|
||||
tarFields = new Zone("tarFields", starter, new FileMapGenerator("tarFields")){{
|
||||
loadout = Loadouts.basicFoundation;
|
||||
startingItems = list(copper, 250, lead, 100);
|
||||
conditionWave = 15;
|
||||
@@ -195,7 +195,7 @@ public class Zones implements ContentList{
|
||||
);
|
||||
}};
|
||||
|
||||
desolateRift = new Zone("desolateRift", starter, new MapGenerator("desolateRift")){{
|
||||
desolateRift = new Zone("desolateRift", starter, new FileMapGenerator("desolateRift")){{
|
||||
loadout = Loadouts.basicNucleus;
|
||||
startingItems = list(copper, 1000, lead, 1000, Items.graphite, 250, titanium, 250, Items.silicon, 250);
|
||||
conditionWave = 3;
|
||||
@@ -220,7 +220,7 @@ public class Zones implements ContentList{
|
||||
resources = Array.with(Items.copper, Items.scrap, Items.lead, Items.coal, Items.sand};
|
||||
}};*/
|
||||
|
||||
nuclearComplex = new Zone("nuclearComplex", starter, new MapGenerator("nuclearProductionComplex")){{
|
||||
nuclearComplex = new Zone("nuclearComplex", starter, new FileMapGenerator("nuclearProductionComplex")){{
|
||||
loadout = Loadouts.basicNucleus;
|
||||
startingItems = list(copper, 1250, lead, 1500, Items.silicon, 400, Items.metaglass, 250);
|
||||
conditionWave = 30;
|
||||
|
||||
@@ -6,7 +6,6 @@ import arc.audio.*;
|
||||
import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.input.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.scene.ui.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
@@ -23,7 +22,6 @@ import mindustry.maps.Map;
|
||||
import mindustry.type.*;
|
||||
import mindustry.ui.dialogs.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.storage.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.text.*;
|
||||
@@ -281,6 +279,9 @@ public class Control implements ApplicationListener, Loadable{
|
||||
}
|
||||
|
||||
public void playTutorial(){
|
||||
//TODO implement
|
||||
ui.showInfo("death");
|
||||
/*
|
||||
Zone zone = Zones.groundZero;
|
||||
ui.loadAnd(() -> {
|
||||
logic.reset();
|
||||
@@ -331,7 +332,7 @@ public class Control implements ApplicationListener, Loadable{
|
||||
state.rules.buildCostMultiplier = 0.3f;
|
||||
state.rules.tutorial = true;
|
||||
Events.fire(Trigger.newGame);
|
||||
});
|
||||
});*/
|
||||
}
|
||||
|
||||
public boolean isHighScore(){
|
||||
|
||||
@@ -357,7 +357,7 @@ public class World{
|
||||
int edgeBlend = 2;
|
||||
|
||||
float dark = 0;
|
||||
int edgeDst = Math.min(x, Math.min(y, Math.min(Math.abs(x - (world.width() - 1)), Math.abs(y - (world.height() - 1)))));
|
||||
int edgeDst = Math.min(x, Math.min(y, Math.min(Math.abs(x - (tiles.width - 1)), Math.abs(y - (tiles.height - 1)))));
|
||||
if(edgeDst <= edgeBlend){
|
||||
dark = Math.max((edgeBlend - edgeDst) * (4f / edgeBlend), dark);
|
||||
}
|
||||
@@ -367,7 +367,7 @@ public class World{
|
||||
int circleBlend = 14;
|
||||
//quantized angle
|
||||
float offset = getSector().rect.rotation + 90;
|
||||
float angle = Angles.angle(x, y, world.width()/2, world.height()/2) + offset;
|
||||
float angle = Angles.angle(x, y, tiles.width/2, tiles.height/2) + offset;
|
||||
//polygon sides, depends on sector
|
||||
int sides = getSector().tile.corners.length;
|
||||
float step = 360f / sides;
|
||||
@@ -375,15 +375,15 @@ public class World{
|
||||
float prev = Mathf.round(angle, step);
|
||||
float next = prev + step;
|
||||
//raw line length to be translated
|
||||
float length = world.width()/2f;
|
||||
float rawDst = Intersector.distanceLinePoint(Tmp.v1.trns(prev, length), Tmp.v2.trns(next, length), Tmp.v3.set(x - world.width()/2, y - world.height()/2).rotate(offset)) / Mathf.sqrt3 - 1;
|
||||
float length = tiles.width/2f;
|
||||
float rawDst = Intersector.distanceLinePoint(Tmp.v1.trns(prev, length), Tmp.v2.trns(next, length), Tmp.v3.set(x - tiles.width/2, y - tiles.height/2).rotate(offset)) / Mathf.sqrt3 - 1;
|
||||
|
||||
//noise
|
||||
rawDst += Noise.noise(x, y, 11f, 7f) + Noise.noise(x, y, 22f, 15f);
|
||||
|
||||
int circleDst = (int)(rawDst - (world.width() / 2 - circleBlend));
|
||||
int circleDst = (int)(rawDst - (tiles.width / 2 - circleBlend));
|
||||
if(circleDst > 0){
|
||||
dark = Math.max(circleDst / 0.8f, dark);
|
||||
dark = Math.max(circleDst / 1f, dark);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
package mindustry.maps.generators;
|
||||
|
||||
public class BaseGenerator{
|
||||
}
|
||||
@@ -1,56 +1,65 @@
|
||||
package mindustry.maps.generators;
|
||||
|
||||
import arc.func.*;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.struct.*;
|
||||
import arc.func.Intc2;
|
||||
import arc.math.Mathf;
|
||||
import arc.math.geom.Geometry;
|
||||
import arc.math.geom.Point2;
|
||||
import arc.util.Structs;
|
||||
import arc.util.noise.Simplex;
|
||||
import mindustry.content.Blocks;
|
||||
import arc.util.*;
|
||||
import arc.util.noise.*;
|
||||
import mindustry.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.Floor;
|
||||
|
||||
import java.util.PriorityQueue;
|
||||
import java.util.*;
|
||||
|
||||
public abstract class BasicGenerator extends RandomGenerator{
|
||||
import static mindustry.Vars.world;
|
||||
|
||||
public abstract class BasicGenerator implements WorldGenerator{
|
||||
protected static final DistanceHeuristic manhattan = (x1, y1, x2, y2) -> Math.abs(x1 - x2) + Math.abs(y1 - y2);
|
||||
|
||||
protected Array<Block> ores;
|
||||
protected Simplex sim = new Simplex();
|
||||
protected Simplex sim2 = new Simplex();
|
||||
|
||||
protected int width, height;
|
||||
protected Tiles tiles;
|
||||
|
||||
public BasicGenerator(int width, int height, Block... ores){
|
||||
super(width, height);
|
||||
this.ores = Array.with(ores);
|
||||
}
|
||||
//for drawing
|
||||
protected Block floor;
|
||||
protected Block block;
|
||||
protected Block ore;
|
||||
|
||||
@Override
|
||||
public void generate(Tiles tiles){
|
||||
this.tiles = tiles;
|
||||
this.width = tiles.width;
|
||||
this.height = tiles.height;
|
||||
int seed = Mathf.random(99999999);
|
||||
sim.setSeed(seed);
|
||||
sim2.setSeed(seed + 1);
|
||||
super.generate(tiles);
|
||||
|
||||
generate();
|
||||
}
|
||||
|
||||
public void ores(Tiles tiles){
|
||||
pass(tiles, (x, y) -> {
|
||||
if(ores != null){
|
||||
int offsetX = x - 4, offsetY = y + 23;
|
||||
for(int i = ores.size - 1; i >= 0; i--){
|
||||
Block entry = ores.get(i);
|
||||
if(Math.abs(0.5f - sim.octaveNoise2D(2, 0.7, 1f / (40 + i * 2), offsetX, offsetY + i*999)) > 0.26f &&
|
||||
Math.abs(0.5f - sim2.octaveNoise2D(1, 1, 1f / (30 + i * 4), offsetX, offsetY - i*999)) > 0.37f){
|
||||
ore = entry;
|
||||
break;
|
||||
}
|
||||
protected void generate(){
|
||||
|
||||
}
|
||||
|
||||
public void ores(Array<Block> ores){
|
||||
pass((x, y) -> {
|
||||
int offsetX = x - 4, offsetY = y + 23;
|
||||
for(int i = ores.size - 1; i >= 0; i--){
|
||||
Block entry = ores.get(i);
|
||||
if(Math.abs(0.5f - sim.octaveNoise2D(2, 0.7, 1f / (40 + i * 2), offsetX, offsetY + i*999)) > 0.26f &&
|
||||
Math.abs(0.5f - sim2.octaveNoise2D(1, 1, 1f / (30 + i * 4), offsetX, offsetY - i*999)) > 0.37f){
|
||||
ore = entry;
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void terrain(Tiles tiles, Block dst, float scl, float mag, float cmag){
|
||||
pass(tiles, (x, y) -> {
|
||||
public void terrain(Block dst, float scl, float mag, float cmag){
|
||||
pass((x, y) -> {
|
||||
double rocks = sim.octaveNoise2D(5, 0.5, 1f / scl, x, y) * mag
|
||||
+ Mathf.dst((float)x / width, (float)y / height, 0.5f, 0.5f) * cmag;
|
||||
|
||||
@@ -61,14 +70,14 @@ public abstract class BasicGenerator extends RandomGenerator{
|
||||
}
|
||||
|
||||
if(rocks > 0.9){
|
||||
block =dst;
|
||||
block = dst;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void noise(Tiles tiles, Block floor, Block block, int octaves, float falloff, float scl, float threshold){
|
||||
public void noise(Block floor, Block block, int octaves, float falloff, float scl, float threshold){
|
||||
sim.setSeed(Mathf.random(99999));
|
||||
pass(tiles, (x, y) -> {
|
||||
pass((x, y) -> {
|
||||
if(sim.octaveNoise2D(octaves, falloff, 1f / scl, x, y) > threshold){
|
||||
Tile tile = tiles.getn(x, y);
|
||||
this.floor = floor;
|
||||
@@ -79,19 +88,19 @@ public abstract class BasicGenerator extends RandomGenerator{
|
||||
});
|
||||
}
|
||||
|
||||
public void overlay(Tiles tiles, Block floor, Block block, float chance, int octaves, float falloff, float scl, float threshold){
|
||||
public void overlay(Block floor, Block block, float chance, int octaves, float falloff, float scl, float threshold){
|
||||
sim.setSeed(Mathf.random(99999));
|
||||
pass(tiles, (x, y) -> {
|
||||
pass((x, y) -> {
|
||||
if(sim.octaveNoise2D(octaves, falloff, 1f / scl, x, y) > threshold && Mathf.chance(chance) && tiles.getn(x, y).floor() == floor){
|
||||
ore = block;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void tech(Tiles tiles){
|
||||
public void tech(){
|
||||
Block[] blocks = {Blocks.darkPanel3};
|
||||
int secSize = 20;
|
||||
pass(tiles, (x, y) -> {
|
||||
pass((x, y) -> {
|
||||
int mx = x % secSize, my = y % secSize;
|
||||
int sclx = x / secSize, scly = y / secSize;
|
||||
if(noise(sclx, scly, 10f, 1f) > 0.63f && (mx == 0 || my == 0 || mx == secSize - 1 || my == secSize - 1)){
|
||||
@@ -109,25 +118,27 @@ public abstract class BasicGenerator extends RandomGenerator{
|
||||
});
|
||||
}
|
||||
|
||||
public void distort(Tiles tiles, float scl, float mag){
|
||||
Block[][] blocks = new Block[width][height];
|
||||
Floor[][] floors = new Floor[width][height];
|
||||
public void distort(float scl, float mag){
|
||||
short[] blocks = new short[tiles.width * tiles.height];
|
||||
short[] floors = new short[blocks.length];
|
||||
|
||||
each((x, y) -> {
|
||||
float cx = x + noise(x, y, scl, mag) - mag / 2f, cy = y + noise(x, y + 1525215f, scl, mag) - mag / 2f;
|
||||
Tile other = tiles.getn(Mathf.clamp((int)cx, 0, width-1), Mathf.clamp((int)cy, 0, height-1));
|
||||
blocks[x][y] = other.block();
|
||||
floors[x][y] = other.floor();
|
||||
tiles.each((x, y) -> {
|
||||
int idx = y*tiles.width + x;
|
||||
float cx = x + noise(x, y, scl, mag) - mag / 2f, cy = y + noise(x, y + 152f, scl, mag) - mag / 2f;
|
||||
Tile other = tiles.getn(Mathf.clamp((int)cx, 0, tiles.width-1), Mathf.clamp((int)cy, 0, tiles.height-1));
|
||||
blocks[idx] = other.block().id;
|
||||
floors[idx] = other.floor().id;
|
||||
});
|
||||
|
||||
pass(tiles, (x, y) -> {
|
||||
floor = floors[x][y];
|
||||
block = blocks[x][y];
|
||||
});
|
||||
for(int i = 0; i < blocks.length; i++){
|
||||
Tile tile = tiles.geti(i);
|
||||
tile.setFloor(Vars.content.block(floors[i]).asFloor());
|
||||
tile.setBlock(Vars.content.block(blocks[i]));
|
||||
}
|
||||
}
|
||||
|
||||
public void scatter(Tiles tiles, Block target, Block dst, float chance){
|
||||
pass(tiles, (x, y) -> {
|
||||
public void scatter(Block target, Block dst, float chance){
|
||||
pass((x, y) -> {
|
||||
if(!Mathf.chance(chance)) return;
|
||||
if(floor == target){
|
||||
floor = dst;
|
||||
@@ -149,23 +160,23 @@ public abstract class BasicGenerator extends RandomGenerator{
|
||||
return (float)sim2.octaveNoise2D(1f, 0f, 1f / scl, x + 0x361266f, y + 0x251259f) * mag;
|
||||
}
|
||||
|
||||
public void pass(Tiles tiles, Intc2 r){
|
||||
for(int x = 0; x < width; x++){
|
||||
for(int y = 0; y < height; y++){
|
||||
floor = tiles.getn(x, y).floor();
|
||||
block = tiles.getn(x, y).block();
|
||||
ore = tiles.getn(x, y).overlay();
|
||||
r.get(x, y);
|
||||
tiles.set(x, y, new Tile(x, y, floor, ore, block));
|
||||
}
|
||||
public void pass(Intc2 r){
|
||||
for(Tile tile : tiles){
|
||||
floor = tile.floor();
|
||||
block = tile.block();
|
||||
ore = tile.overlay();
|
||||
r.get(tile.x, tile.y);
|
||||
tile.setFloor(floor.asFloor());
|
||||
tile.setBlock(block);
|
||||
tile.setOverlay(ore);
|
||||
}
|
||||
}
|
||||
|
||||
public void brush(Tiles tiles, Array<Tile> path, int rad){
|
||||
path.each(tile -> erase(tiles, tile.x, tile.y, rad));
|
||||
public void brush(Array<Tile> path, int rad){
|
||||
path.each(tile -> erase(tile.x, tile.y, rad));
|
||||
}
|
||||
|
||||
public void erase(Tiles tiles, int cx, int cy, int rad){
|
||||
public void erase(int cx, int cy, int rad){
|
||||
for(int x = -rad; x <= rad; x++){
|
||||
for(int y = -rad; y <= rad; y++){
|
||||
int wx = cx + x, wy = cy + y;
|
||||
@@ -177,7 +188,7 @@ public abstract class BasicGenerator extends RandomGenerator{
|
||||
}
|
||||
}
|
||||
|
||||
public Array<Tile> pathfind(Tiles tiles, int startX, int startY, int endX, int endY, TileHueristic th, DistanceHeuristic dh){
|
||||
public Array<Tile> pathfind(int startX, int startY, int endX, int endY, TileHueristic th, DistanceHeuristic dh){
|
||||
Tile start = tiles.getn(startX, startY);
|
||||
Tile end = tiles.getn(endX, endY);
|
||||
GridBits closed = new GridBits(width, height);
|
||||
@@ -195,7 +206,7 @@ public abstract class BasicGenerator extends RandomGenerator{
|
||||
closed.set(next.x, next.y);
|
||||
for(Point2 point : Geometry.d4){
|
||||
int newx = next.x + point.x, newy = next.y + point.y;
|
||||
if(Structs.inBounds(newx, newy, width, height)){
|
||||
if(Structs.inBounds(newx, newy, width, height) && world.getDarkness(newx, newy) == 0){
|
||||
Tile child = tiles.getn(newx, newy);
|
||||
if(!closed.get(child.x, child.y)){
|
||||
closed.set(child.x, child.y);
|
||||
@@ -223,7 +234,7 @@ public abstract class BasicGenerator extends RandomGenerator{
|
||||
return out;
|
||||
}
|
||||
|
||||
public void inverseFloodFill(Tiles tiles, Tile start, Block block){
|
||||
public void inverseFloodFill(Tile start){
|
||||
IntArray arr = new IntArray();
|
||||
arr.add(start.pos());
|
||||
while(!arr.isEmpty()){
|
||||
@@ -242,12 +253,9 @@ public abstract class BasicGenerator extends RandomGenerator{
|
||||
}
|
||||
}
|
||||
|
||||
for(int x = 0; x < width; x ++){
|
||||
for(int y = 0; y < height; y++){
|
||||
Tile tile = tiles.getn(x, y);
|
||||
if(tile.cost != 2 && tile.block() == Blocks.air){
|
||||
tile.setBlock(block);
|
||||
}
|
||||
for(Tile tile : tiles){
|
||||
if((tile.cost != 2 && tile.block() == Blocks.air) || world.getDarkness(tile.x, tile.y) != 0){
|
||||
tile.setBlock(tile.floor().wall);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.ctype.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.io.*;
|
||||
import mindustry.maps.*;
|
||||
import mindustry.type.*;
|
||||
@@ -13,32 +12,11 @@ import mindustry.world.blocks.storage.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
//TODO:
|
||||
//- limited # of enemy spawns as filter
|
||||
//- spawn loadout selection as filter
|
||||
//- configure map loadout, make 1 core the default
|
||||
public class MapGenerator extends Generator{
|
||||
private Map map;
|
||||
private String mapName;
|
||||
public class FileMapGenerator implements WorldGenerator{
|
||||
public final Map map;
|
||||
|
||||
public MapGenerator(String mapName){
|
||||
this.mapName = mapName;
|
||||
}
|
||||
|
||||
public void removePrefix(String name){
|
||||
this.mapName = this.mapName.substring(name.length() + 1);
|
||||
}
|
||||
|
||||
public Map getMap(){
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(Schematic loadout){
|
||||
this.loadout = loadout;
|
||||
map = maps.loadInternalMap(mapName);
|
||||
width = map.width;
|
||||
height = map.height;
|
||||
public FileMapGenerator(String mapName){
|
||||
this.map = maps.loadInternalMap(mapName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -70,7 +48,8 @@ public class MapGenerator extends Generator{
|
||||
}
|
||||
|
||||
if(tile.block() instanceof CoreBlock && tile.team() == state.rules.defaultTeam){
|
||||
schematics.placeLoadout(loadout, tile.x, tile.y);
|
||||
//TODO PLACE THE LOADOUT
|
||||
//schematics.placeLoadout(loadout, tile.x, tile.y);
|
||||
anyCores = true;
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package mindustry.maps.generators;
|
||||
|
||||
import mindustry.game.*;
|
||||
import mindustry.world.*;
|
||||
|
||||
public abstract class Generator{
|
||||
public int width, height;
|
||||
protected Schematic loadout;
|
||||
|
||||
public Generator(int width, int height){
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public Generator(){
|
||||
}
|
||||
|
||||
public void init(Schematic loadout){
|
||||
this.loadout = loadout;
|
||||
}
|
||||
|
||||
public abstract void generate(Tiles tiles);
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package mindustry.maps.generators;
|
||||
|
||||
import arc.struct.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.maps.*;
|
||||
import mindustry.world.*;
|
||||
|
||||
import static mindustry.Vars.world;
|
||||
|
||||
public abstract class RandomGenerator extends Generator{
|
||||
protected Block floor;
|
||||
protected Block block;
|
||||
protected Block ore;
|
||||
|
||||
public RandomGenerator(int width, int height){
|
||||
super(width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generate(Tiles tiles){
|
||||
for(int x = 0; x < width; x++){
|
||||
for(int y = 0; y < height; y++){
|
||||
Tile prev = tiles.getn(x, y);
|
||||
floor = prev.floor();
|
||||
block = prev.block();
|
||||
ore = prev.overlay();
|
||||
generate(x, y);
|
||||
prev.setFloor(floor.asFloor());
|
||||
prev.setBlock(block);
|
||||
prev.setOverlay(ore);
|
||||
}
|
||||
}
|
||||
|
||||
decorate(tiles);
|
||||
|
||||
world.setMap(new Map(new StringMap()));
|
||||
}
|
||||
|
||||
public abstract void decorate(Tiles tiles);
|
||||
|
||||
/**
|
||||
* Sets {@link #floor} and {@link #block} to the correct values as output.
|
||||
* Before this method is called, both are set to {@link Blocks#air} as defaults.
|
||||
*/
|
||||
public abstract void generate(int x, int y);
|
||||
}
|
||||
7
core/src/mindustry/maps/generators/WorldGenerator.java
Normal file
7
core/src/mindustry/maps/generators/WorldGenerator.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package mindustry.maps.generators;
|
||||
|
||||
import mindustry.world.*;
|
||||
|
||||
public interface WorldGenerator{
|
||||
void generate(Tiles tiles);
|
||||
}
|
||||
@@ -120,8 +120,8 @@ public class TestPlanetGenerator implements PlanetGenerator{
|
||||
tiles.each((x, y) -> tiles.get(x, y).setBlock(!read.get(x, y) ? Blocks.air : tiles.get(x, y).floor().wall));
|
||||
distort(0.009f, 12f);
|
||||
|
||||
OvergrowthGenerator gen = new OvergrowthGenerator(tiles.width, tiles.height);
|
||||
gen.decorate(tiles);
|
||||
OvergrowthGenerator gen = new OvergrowthGenerator();
|
||||
gen.generate(tiles);
|
||||
|
||||
//tiles.get(tiles.width /2, tiles.height /2).setBlock(Blocks.coreShard, Team.sharded);
|
||||
}
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
package mindustry.maps.zonegen;
|
||||
|
||||
import arc.math.Mathf;
|
||||
import mindustry.content.Blocks;
|
||||
import mindustry.maps.generators.BasicGenerator;
|
||||
import mindustry.world.*;
|
||||
|
||||
import static mindustry.Vars.schematics;
|
||||
import mindustry.maps.generators.*;
|
||||
|
||||
//TODO remove
|
||||
public class DesertWastesGenerator extends BasicGenerator{
|
||||
|
||||
/*
|
||||
public DesertWastesGenerator(int width, int height){
|
||||
super(width, height, Blocks.oreCopper, Blocks.oreLead, Blocks.oreCoal, Blocks.oreCopper);
|
||||
}
|
||||
@@ -35,7 +31,7 @@ public class DesertWastesGenerator extends BasicGenerator{
|
||||
erase(tiles, endX, endY, 10);
|
||||
erase(tiles, spawnX, spawnY, 20);
|
||||
distort(tiles, 20f, 4f);
|
||||
inverseFloodFill(tiles, tiles.getn(spawnX, spawnY), Blocks.sandRocks);
|
||||
inverseFloodFill(tiles, tiles.getn(spawnX, spawnY));
|
||||
|
||||
noise(tiles, Blocks.salt, Blocks.saltRocks, 5, 0.6f, 200f, 0.55f);
|
||||
noise(tiles, Blocks.darksand, Blocks.duneRocks, 5, 0.7f, 120f, 0.5f);
|
||||
@@ -46,5 +42,5 @@ public class DesertWastesGenerator extends BasicGenerator{
|
||||
|
||||
tiles.getn(endX, endY).setOverlay(Blocks.spawn);
|
||||
schematics.placeLoadout(loadout, spawnX, spawnY);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package mindustry.maps.zonegen;
|
||||
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.maps.generators.*;
|
||||
import mindustry.world.*;
|
||||
@@ -9,18 +12,10 @@ import static mindustry.Vars.schematics;
|
||||
|
||||
//TODO remove
|
||||
public class OvergrowthGenerator extends BasicGenerator{
|
||||
|
||||
public OvergrowthGenerator(int width, int height){
|
||||
super(width, height, Blocks.oreCopper, Blocks.oreLead, Blocks.oreCoal, Blocks.oreCopper);
|
||||
}
|
||||
Array<Block> ores = Array.with(Blocks.oreCopper, Blocks.oreLead, Blocks.oreCoal, Blocks.oreCopper);
|
||||
|
||||
@Override
|
||||
public void generate(int x, int y){
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decorate(Tiles tiles){
|
||||
ores(tiles);
|
||||
protected void generate(){
|
||||
//terrain(tiles, Blocks.sporePine, 70f, 1.4f, 1f);
|
||||
|
||||
//int rand = 40;
|
||||
@@ -28,21 +23,58 @@ public class OvergrowthGenerator extends BasicGenerator{
|
||||
//int spawnX = Mathf.clamp(30 + Mathf.range(rand), border, width - border), spawnY = Mathf.clamp(30 + Mathf.range(rand), border, height - border);
|
||||
//int endX = Mathf.clamp(width - 30 + Mathf.range(rand), border, width - border), endY = Mathf.clamp(height - 30 + Mathf.range(rand), border, height - border);
|
||||
|
||||
int radius = (int)(width / 2 / Mathf.sqrt3);
|
||||
float constraint = 1.3f;
|
||||
float radius = width / 2f / Mathf.sqrt3;
|
||||
int rooms = Mathf.random(2, 5);
|
||||
Array<Point3> array = new Array<>();
|
||||
|
||||
brush(tiles, pathfind(tiles, spawnX, spawnY, endX, endY, tile -> (tile.solid() ? 5f : 0f) + (float)sim.octaveNoise2D(1, 1, 1f / 50f, tile.x, tile.y) * 50, manhattan), 6);
|
||||
brush(tiles, pathfind(tiles, spawnX, spawnY, endX, endY, tile -> (tile.solid() ? 4f : 0f) + (float)sim.octaveNoise2D(1, 1, 1f / 90f, tile.x+999, tile.y) * 70, manhattan), 5);
|
||||
//TODO replace random calls with seed
|
||||
|
||||
erase(tiles, endX, endY, 10);
|
||||
erase(tiles, spawnX, spawnY, 20);
|
||||
distort(tiles, 20f, 4f);
|
||||
inverseFloodFill(tiles, tiles.getn(spawnX, spawnY), Blocks.sporerocks);
|
||||
for(int i = 0; i < rooms; i++){
|
||||
Tmp.v1.trns(Mathf.random(360f), Mathf.random(radius / constraint));
|
||||
float rx = (width/2f + Tmp.v1.x);
|
||||
float ry = (height/2f + Tmp.v1.y);
|
||||
float maxrad = radius - Tmp.v1.len();
|
||||
float rrad = Math.min(Mathf.random(9f, maxrad), 40f);
|
||||
array.add(new Point3((int)rx, (int)ry, (int)rrad));
|
||||
}
|
||||
|
||||
for(Point3 room : array){
|
||||
erase(room.x, room.y, room.z);
|
||||
}
|
||||
|
||||
int connections = Mathf.random(Math.max(rooms - 1, 1), rooms + 3);
|
||||
for(int i = 0; i < connections; i++){
|
||||
Point3 from = array.random();
|
||||
Point3 to = array.random();
|
||||
|
||||
float nscl = Mathf.random(20f, 60f);
|
||||
int stroke = Mathf.random(4, 12);
|
||||
brush(pathfind(from.x, from.y, to.x, to.y, tile -> (tile.solid() ? 5f : 0f) + (float)sim.octaveNoise2D(1, 1, 1f / nscl, tile.x, tile.y) * 50, manhattan), stroke);
|
||||
}
|
||||
|
||||
//
|
||||
//brush(tiles, pathfind(tiles, spawnX, spawnY, endX, endY, tile -> (tile.solid() ? 4f : 0f) + (float)sim.octaveNoise2D(1, 1, 1f / 90f, tile.x+999, tile.y) * 70, manhattan), 5);
|
||||
|
||||
//
|
||||
//erase(tiles, spawnX, spawnY, 20);
|
||||
distort(20f, 6f);
|
||||
|
||||
Point3 spawn = array.random();
|
||||
inverseFloodFill(tiles.getn(spawn.x, spawn.y));
|
||||
|
||||
ores(ores);
|
||||
|
||||
for(Point3 other : array){
|
||||
if(other != spawn){
|
||||
// tiles.getn(other.x, other.y).setOverlay(Blocks.spawn);
|
||||
}
|
||||
}
|
||||
|
||||
//noise(tiles, Blocks.darksandTaintedWater, Blocks.duneRocks, 4, 0.7f, 120f, 0.64f);
|
||||
//scatter(tiles, Blocks.sporePine, Blocks.whiteTreeDead, 1f);
|
||||
|
||||
tiles.getn(endX, endY).setOverlay(Blocks.spawn);
|
||||
loadout = Loadouts.advancedShard;
|
||||
schematics.placeLoadout(loadout, spawnX, spawnY);
|
||||
//tiles.getn(endX, endY).setOverlay(Blocks.spawn);
|
||||
schematics.placeLoadout(Loadouts.advancedShard, spawn.x, spawn.y);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,8 +14,9 @@ import mindustry.maps.generators.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
//TODO ? remove ?
|
||||
public class Zone extends UnlockableContent{
|
||||
public @NonNull Generator generator;
|
||||
public @NonNull WorldGenerator generator;
|
||||
public @NonNull Objective configureObjective = new ZoneWave(this, 15);
|
||||
public @NonNull Planet planet;
|
||||
public Array<Objective> requirements = new Array<>();
|
||||
@@ -34,19 +35,19 @@ public class Zone extends UnlockableContent{
|
||||
|
||||
private Array<ItemStack> defaultStartingItems = new Array<>();
|
||||
|
||||
public Zone(String name, Planet planet, Generator generator){
|
||||
public Zone(String name, Planet planet, WorldGenerator generator){
|
||||
super(name);
|
||||
this.generator = generator;
|
||||
this.planet = planet;
|
||||
}
|
||||
|
||||
public Zone(String name){
|
||||
this(name, Planets.starter, new MapGenerator(name));
|
||||
this(name, Planets.starter, new FileMapGenerator(name));
|
||||
}
|
||||
|
||||
public Rules getRules(){
|
||||
if(generator instanceof MapGenerator){
|
||||
return ((MapGenerator)generator).getMap().rules();
|
||||
if(generator instanceof FileMapGenerator){
|
||||
return ((FileMapGenerator)generator).map.rules();
|
||||
}else{
|
||||
Rules rules = new Rules();
|
||||
this.rules.get(rules);
|
||||
@@ -167,11 +168,6 @@ public class Zone extends UnlockableContent{
|
||||
|
||||
@Override
|
||||
public void init(){
|
||||
if(generator instanceof MapGenerator && minfo.mod != null){
|
||||
((MapGenerator)generator).removePrefix(minfo.mod.name);
|
||||
}
|
||||
|
||||
generator.init(loadout);
|
||||
resources.sort();
|
||||
|
||||
for(ItemStack stack : startingItems){
|
||||
|
||||
Reference in New Issue
Block a user