Classes moved / Fixed autotile bugs / Added sector display

This commit is contained in:
Anuken 2018-07-16 18:42:29 -04:00
parent 9b505106e3
commit dd45b43d7f
14 changed files with 221 additions and 81 deletions

View File

@ -49,6 +49,7 @@ text.joingame=Join Game
text.addplayers=Add/Remove Players
text.customgame=Custom Game
text.campaign=Campaign
text.sectors=Sectors
text.quit=Quit
text.maps=Maps
text.maps.none=[LIGHT_GRAY]No maps found!

View File

@ -17,6 +17,6 @@
<extend-configuration-property name="gdx.reflect.include" value="io.anuke.mindustry.game.Team"/>
<extend-configuration-property name="gdx.reflect.include" value="io.anuke.mindustry.net.Streamable"/>
<extend-configuration-property name="gdx.reflect.include" value="io.anuke.mindustry.world.meta.BlockBar"/>
<extend-configuration-property name="gdx.reflect.include" value="io.anuke.mindustry.world.mapgen.WorldGenerator"/>
<extend-configuration-property name="gdx.reflect.include" value="io.anuke.mindustry.maps.generation.WorldGenerator"/>
<extend-configuration-property name="gdx.reflect.include" value="io.anuke.mindustry.entities.StatusController"/>
</module>

View File

@ -45,9 +45,10 @@ public class Vars{
public static final int saveSlots = 64;
public static final float itemSize = 5f;
public static final int tilesize = 8;
public static final int sectorSize = 256;
public static final Locale[] locales = {new Locale("en"), new Locale("fr"), new Locale("ru"), new Locale("uk", "UA"), new Locale("pl"),
new Locale("de"), new Locale("pt", "BR"), new Locale("ko"), new Locale("in", "ID"),
new Locale("ita"), new Locale("es"), new Locale("zh","TW")};
new Locale("ita"), new Locale("es"), new Locale("zh","TW")};
public static final Color[] playerColors = {
Color.valueOf("82759a"),
Color.valueOf("c0c1c5"),

View File

@ -61,6 +61,7 @@ public class UI extends SceneModule{
public LocalPlayerDialog localplayers;
public UnlocksDialog unlocks;
public ContentInfoDialog content;
public SectorsDialog sectors;
private Locale lastLocale;
@ -167,6 +168,7 @@ public class UI extends SceneModule{
localplayers = new LocalPlayerDialog();
unlocks = new UnlocksDialog();
content = new ContentInfoDialog();
sectors = new SectorsDialog();
Group group = Core.scene.getRoot();

View File

@ -17,7 +17,7 @@ import io.anuke.mindustry.maps.Maps;
import io.anuke.mindustry.maps.Sectors;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.mapgen.WorldGenerator;
import io.anuke.mindustry.maps.generation.WorldGenerator;
import io.anuke.ucore.core.Events;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.entities.EntityPhysics;
@ -51,6 +51,10 @@ public class World extends Module{
maps.dispose();
}
public WorldGenerator generator(){
return generator;
}
public Sectors sectors(){
return sectors;
}

View File

@ -5,15 +5,18 @@ import com.badlogic.gdx.graphics.Pixmap.Format;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.math.GridPoint2;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.content.blocks.Blocks;
import io.anuke.mindustry.maps.generation.WorldGenerator.GenResult;
import io.anuke.mindustry.world.ColorMapper;
import io.anuke.ucore.core.Settings;
import io.anuke.ucore.util.Geometry;
import io.anuke.ucore.util.GridMap;
import static io.anuke.mindustry.Vars.headless;
import static io.anuke.mindustry.Vars.*;
public class Sectors{
private static final int sectorSize = 256;
private static final int sectorImageSize = 8;
private static final int sectorImageSize = 16;
private GridMap<Sector> grid = new GridMap<>();
public Sectors(){
@ -32,8 +35,9 @@ public class Sectors{
sector.unlocked = true;
if(sector.texture == null) createTexture(sector);
//TODO fix
for(GridPoint2 point : Geometry.d4){
createSector(sector.x + point.x, sector.y + point.y);
// createSector(sector.x + point.x, sector.y + point.y);
}
}
@ -45,6 +49,7 @@ public class Sectors{
sector.x = (short)x;
sector.y = (short)y;
sector.unlocked = false;
grid.put(x, y, sector);
}
public void load(){
@ -74,9 +79,15 @@ public class Sectors{
int worldX = sector.x * sectorSize;
int worldY = sector.y * sectorSize;
for(int x = worldX; x < (worldX + sectorSize); x++){
for(int y = worldY; y < (worldY + sectorSize); y++){
for(int x = 0; x < sectorImageSize; x++){
for(int y = 0; y < sectorImageSize; y++){
int toX = x * sectorSize / sectorImageSize;
int toY = y * sectorSize / sectorImageSize;
GenResult result = world.generator().generateTile(sector.x, sector.y, toX, toY);
int color = ColorMapper.getBlockColor(result.wall == Blocks.air ? result.floor : result.wall);
pixmap.drawPixel(x, sectorImageSize - 1 - y, color);
}
}

View File

@ -1,4 +1,4 @@
package io.anuke.mindustry.world.mapgen;
package io.anuke.mindustry.maps.generation;
public class GenProperties{
public long seed;

View File

@ -1,7 +1,6 @@
package io.anuke.mindustry.world.mapgen;
package io.anuke.mindustry.maps.generation;
import com.badlogic.gdx.math.GridPoint2;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.IntArray;
@ -19,17 +18,38 @@ import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.Floor;
import io.anuke.ucore.noise.RidgedPerlin;
import io.anuke.ucore.noise.Simplex;
import io.anuke.ucore.util.Bits;
import io.anuke.ucore.util.Geometry;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.SeedRandom;
import static io.anuke.mindustry.Vars.sectorSize;
import static io.anuke.mindustry.Vars.state;
import static io.anuke.mindustry.Vars.world;
public class WorldGenerator{
private int seed;
int oreIndex = 0;
private final int seed = 0;
private int oreIndex = 0;
private Simplex sim = new Simplex(seed);
private Simplex sim2 = new Simplex(seed + 1);
private Simplex sim3 = new Simplex(seed + 2);
private SeedRandom random = new SeedRandom(seed + 3);
private GenResult result = new GenResult();
private ObjectMap<Block, Block> decoration;
public WorldGenerator(){
decoration = Mathf.map(
Blocks.grass, Blocks.shrub,
Blocks.stone, Blocks.rock,
Blocks.ice, Blocks.icerock,
Blocks.snow, Blocks.icerock,
Blocks.blackstone, Blocks.blackrock
);
}
/**Loads raw map tile data into a Tile[][] array, setting up multiblocks, cliffs and ores. */
public void loadTileData(Tile[][] tiles, MapTileData data, boolean genOres, int seed){
@ -146,74 +166,12 @@ public class WorldGenerator{
}
public void generateMap(Tile[][] tiles, int seed){
MathUtils.random.setSeed((long) (Math.random() * 99999999));
Simplex sim = new Simplex(Mathf.random(99999));
Simplex sim2 = new Simplex(Mathf.random(99999));
Simplex sim3 = new Simplex(Mathf.random(99999));
SeedRandom random = new SeedRandom(Mathf.random(99999));
int width = tiles.length, height = tiles[0].length;
ObjectMap<Block, Block> decoration = new ObjectMap<>();
decoration.put(Blocks.grass, Blocks.shrub);
decoration.put(Blocks.stone, Blocks.rock);
decoration.put(Blocks.ice, Blocks.icerock);
decoration.put(Blocks.snow, Blocks.icerock);
decoration.put(Blocks.blackstone, Blocks.blackrock);
for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){
Block floor = Blocks.stone;
Block wall = Blocks.air;
double elevation = sim.octaveNoise2D(3, 0.5, 1f / 100, x, y) * 4.1 - 1;
double temp = sim3.octaveNoise2D(7, 0.54, 1f / 320f, x, y);
double r = sim2.octaveNoise2D(1, 0.6, 1f / 70, x, y);
double edgeDist = Math.max(width / 2, height / 2) - Math.max(Math.abs(x - width / 2), Math.abs(y - height / 2));
double dst = Vector2.dst(width / 2, height / 2, x, y);
double elevDip = 30;
double border = 14;
if(edgeDist < border){
elevation += (border - edgeDist) / 6.0;
}
if(temp < 0.35){
floor = Blocks.snow;
}else if(temp < 0.45){
floor = Blocks.stone;
}else if(temp < 0.65){
floor = Blocks.grass;
}else if(temp < 0.8){
floor = Blocks.sand;
}else if(temp < 0.9){
floor = Blocks.blackstone;
elevation = 0f;
}else{
floor = Blocks.lava;
}
if(dst < elevDip){
elevation -= (elevDip - dst) / elevDip * 3.0;
}else if(r > 0.9){
floor = Blocks.water;
elevation = 0;
if(r > 0.94){
floor = Blocks.deepwater;
}
}
if(wall == Blocks.air && decoration.containsKey(floor) && random.chance(0.03)){
wall = decoration.get(floor);
}
Tile tile = new Tile(x, y, (byte) floor.id, (byte) wall.id);
tile.elevation = (byte) Math.max(elevation, 0);
GenResult result = generateTile(0, 0, x, y);
Tile tile = new Tile(x, y, (byte)result.floor.id, (byte)result.wall.id, (byte)0, (byte)0, result.elevation);
tiles[x][y] = tile;
}
}
@ -243,6 +201,72 @@ public class WorldGenerator{
prepareTiles(tiles, seed, true);
}
public void setSector(int sectorX, int sectorY){
random.setSeed(Bits.packLong(sectorX, sectorY));
}
public GenResult generateTile(int sectorX, int sectorY, int localX, int localY){
int x = sectorX * sectorSize + localX;
int y = sectorY * sectorSize + localY;
Block floor = Blocks.stone;
Block wall = Blocks.air;
double elevation = sim.octaveNoise2D(3, 0.5, 1f / 100, x, y) * 4.1 - 1;
double temp = sim3.octaveNoise2D(7, 0.54, 1f / 320f, x, y);
double r = sim2.octaveNoise2D(1, 0.6, 1f / 70, x, y);
double edgeDist = Math.max(sectorSize / 2, sectorSize / 2) - Math.max(Math.abs(x - sectorSize / 2), Math.abs(y - sectorSize / 2));
double dst = Vector2.dst(sectorSize / 2, sectorSize / 2, x, y);
double elevDip = 30;
double border = 14;
if(edgeDist < border){
elevation += (border - edgeDist) / 6.0;
}
if(temp < 0.35){
floor = Blocks.snow;
}else if(temp < 0.45){
floor = Blocks.stone;
}else if(temp < 0.65){
floor = Blocks.grass;
}else if(temp < 0.8){
floor = Blocks.sand;
}else if(temp < 0.9){
floor = Blocks.blackstone;
elevation = 0f;
}else{
floor = Blocks.lava;
}
if(dst < elevDip){
elevation -= (elevDip - dst) / elevDip * 3.0;
}else if(r > 0.9){
floor = Blocks.water;
elevation = 0;
if(r > 0.94){
floor = Blocks.deepwater;
}
}
if(wall == Blocks.air && decoration.containsKey(floor) && random.chance(0.03)){
wall = decoration.get(floor);
}
result.wall = wall;
result.floor = floor;
result.elevation = (byte) Math.max(elevation, 0);
return result;
}
public class GenResult{
public Block floor, wall;
public byte elevation;
}
public class OreEntry{
final float frequency;
final Item item;

View File

@ -1,8 +1,101 @@
package io.anuke.mindustry.ui.dialogs;
import com.badlogic.gdx.math.Rectangle;
import io.anuke.mindustry.maps.Sector;
import io.anuke.ucore.core.Graphics;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.graphics.Lines;
import io.anuke.ucore.scene.Element;
import io.anuke.ucore.scene.event.InputEvent;
import io.anuke.ucore.scene.event.InputListener;
import io.anuke.ucore.scene.utils.Cursors;
import io.anuke.ucore.scene.utils.ScissorStack;
import static io.anuke.mindustry.Vars.world;
public class SectorsDialog extends FloatingDialog{
private Rectangle clip = new Rectangle();
public SectorsDialog(){
super("");
super("$text.sectors");
addCloseButton();
setup();
}
void setup(){
content().clear();
content().add(new SectorView()).grow();
}
class SectorView extends Element{
float panX, panY;
float lastX, lastY;
float sectorSize = 100f;
SectorView(){
addListener(new InputListener(){
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button){
Cursors.setHand();
lastX = x;
lastY = y;
return true;
}
@Override
public void touchDragged(InputEvent event, float x, float y, int pointer){
panX -= x - lastX;
panY -= y - lastY;
lastX = x;
lastY = y;
}
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button){
Cursors.restoreCursor();
}
});
}
@Override
public void draw(){
Draw.alpha(alpha);
float clipSize = Math.min(width, height);
int shownSectors = Math.round(clipSize/sectorSize/2f + 1f);
clip.setSize(clipSize).setCenter(x + width/2f, y + height/2f);
Graphics.flush();
boolean clipped = ScissorStack.pushScissors(clip);
int offsetX = (int)(panX / sectorSize);
int offsetY = (int)(panY / sectorSize);
for(int x = -shownSectors; x <= shownSectors; x++){
for(int y = -shownSectors; y <= shownSectors; y++){
int sectorX = offsetX + x;
int sectorY = offsetY + y;
float drawX = x + width/2f+ sectorX * sectorSize - offsetX * sectorSize - panX % sectorSize;
float drawY = y + height/2f + sectorY * sectorSize - offsetY * sectorSize - panY % sectorSize;
if(world.sectors().get(sectorX, sectorY) == null){
world.sectors().unlockSector(sectorX, sectorY);
}
Sector sector = world.sectors().get(sectorX, sectorY);
Draw.rect(sector.texture, drawX, drawY, sectorSize, sectorSize);
Lines.stroke(2f);
Lines.crect(drawX, drawY, sectorSize, sectorSize);
}
}
Draw.reset();
Graphics.flush();
if(clipped) ScissorStack.popScissors();
}
}
}

View File

@ -148,7 +148,7 @@ public class MenuFragment extends Fragment{
dialog.content().add(new MenuButton("icon-play-2", "$text.campaign", () -> {
dialog.hide();
ui.levels.show();
ui.sectors.show();
})).width(bw).colspan(2);
dialog.content().row();

View File

@ -23,6 +23,8 @@ public abstract class BaseBlock{
public boolean outputsLiquid = false;
public boolean singleLiquid = true;
public boolean outputsItems = false;
public int itemCapacity;
public float liquidCapacity = 10f;
public float liquidFlowFactor = 4.9f;

View File

@ -126,7 +126,7 @@ public class Conveyor extends Block{
Tile other = tile.getNearby(Mathf.mod(tile.getRotation() - direction, 4));
if(other != null) other = other.target();
if(other == null || !(other.block().hasItems) /*|| !(other.block().outputsLiquid)*/) return false;
if(other == null || (!other.block().outputsItems && !other.block().hasItems)) return false;
return (tile.getNearby(tile.getRotation()) == other)
|| (!other.block().rotate || other.getNearby(other.getRotation()) == tile);
}

View File

@ -20,6 +20,7 @@ public class Junction extends Block{
update = true;
solid = true;
instantTransfer = true;
outputsItems = true;
group = BlockGroup.transportation;
}

View File

@ -27,6 +27,7 @@ public class Sorter extends Block implements SelectionTrait{
update = true;
solid = true;
instantTransfer = true;
outputsItems = true;
group = BlockGroup.transportation;
configurable = true;
}