diff --git a/build.gradle b/build.gradle index a0012d6e39..e176dc0d5b 100644 --- a/build.gradle +++ b/build.gradle @@ -27,7 +27,7 @@ allprojects { gdxVersion = '1.9.8' roboVMVersion = '2.3.0' aiVersion = '1.8.1' - uCoreVersion = 'e4eec58b02' + uCoreVersion = '3e5e261181' getVersionString = { String buildVersion = getBuildVersion() diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index 4888825c1f..7ed0e94c48 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -50,9 +50,11 @@ text.addplayers=Add/Remove Players text.customgame=Custom Game text.campaign=Campaign text.sectors=Sectors -text.sector=Selected Sector: {0} +text.sector=Selected Sector: [LIGHT_GRAY]{0} text.sector.deploy=Deploy +text.sector.resume=Resume text.sector.locked=[scarlet][[LOCKED] +text.sector.unexplored=[accent][[Unexplored] text.quit=Quit text.maps=Maps text.maps.none=[LIGHT_GRAY]No maps found! diff --git a/core/src/io/anuke/mindustry/Vars.java b/core/src/io/anuke/mindustry/Vars.java index d8c0afdca0..01df4f07fa 100644 --- a/core/src/io/anuke/mindustry/Vars.java +++ b/core/src/io/anuke/mindustry/Vars.java @@ -46,6 +46,7 @@ public class Vars{ public static final float itemSize = 5f; public static final int tilesize = 8; public static final int sectorSize = 256; + public static final int invalidSector = Integer.MAX_VALUE; 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")}; diff --git a/core/src/io/anuke/mindustry/core/World.java b/core/src/io/anuke/mindustry/core/World.java index 95e424f1e0..3e33254ea7 100644 --- a/core/src/io/anuke/mindustry/core/World.java +++ b/core/src/io/anuke/mindustry/core/World.java @@ -11,10 +11,7 @@ import io.anuke.mindustry.game.EventType.TileChangeEvent; import io.anuke.mindustry.game.EventType.WorldLoadEvent; import io.anuke.mindustry.game.Team; import io.anuke.mindustry.io.MapIO; -import io.anuke.mindustry.maps.Map; -import io.anuke.mindustry.maps.MapMeta; -import io.anuke.mindustry.maps.Maps; -import io.anuke.mindustry.maps.Sectors; +import io.anuke.mindustry.maps.*; import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.maps.generation.WorldGenerator; @@ -31,6 +28,7 @@ import static io.anuke.mindustry.Vars.*; public class World extends Module{ private Map currentMap; + private Sector currentSector; private Tile[][] tiles; private Pathfinder pathfinder = new Pathfinder(); private BlockIndexer indexer = new BlockIndexer(); @@ -43,6 +41,10 @@ public class World extends Module{ public World(){ maps.load(); + } + + @Override + public void init(){ sectors.load(); } @@ -105,6 +107,10 @@ public class World extends Module{ return currentMap; } + public Sector getSector(){ + return currentSector; + } + public void setMap(Map map){ this.currentMap = map; } @@ -206,8 +212,9 @@ public class World extends Module{ Events.fire(WorldLoadEvent.class); } - /**Loads up a procedural map. This does not call play(), but calls reset().*/ - public void loadProceduralMap(int sectorX, int sectorY){ + /**Loads up a sector map. This does not call play(), but calls reset().*/ + public void loadSector(Sector sector){ + currentSector = sector; Timers.mark(); Timers.mark(); @@ -219,13 +226,13 @@ public class World extends Module{ Tile[][] tiles = createTiles(width, height); - Map map = new Map("Sector [" + sectorX + ", " + sectorY + "]", new MapMeta(0, new ObjectMap<>(), width, height, null), true, () -> null); + Map map = new Map("Sector [" + sector.x + ", " + sector.y + "]", new MapMeta(0, new ObjectMap<>(), width, height, null), true, () -> null); setMap(map); EntityPhysics.resizeTree(0, 0, width * tilesize, height * tilesize); Timers.mark(); - generator.generateMap(tiles, sectorX, sectorY); + generator.generateMap(tiles, sector.x, sector.y); Log.info("Time to generate base map: {0}", Timers.elapsed()); Log.info("Time to generate fully without additional events: {0}", Timers.elapsed()); @@ -236,6 +243,7 @@ public class World extends Module{ } public void loadMap(Map map){ + currentSector = null; beginMapLoad(); this.currentMap = map; diff --git a/core/src/io/anuke/mindustry/entities/Unit.java b/core/src/io/anuke/mindustry/entities/Unit.java index 0053b63bfa..02c56c633c 100644 --- a/core/src/io/anuke/mindustry/entities/Unit.java +++ b/core/src/io/anuke/mindustry/entities/Unit.java @@ -244,7 +244,7 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ } //on slope - if(tile.elevation == -1){ + if(tile.getElevation() == -1){ velocity.scl(0.7f); } } diff --git a/core/src/io/anuke/mindustry/game/Saves.java b/core/src/io/anuke/mindustry/game/Saves.java index f9ef61abad..0330037911 100644 --- a/core/src/io/anuke/mindustry/game/Saves.java +++ b/core/src/io/anuke/mindustry/game/Saves.java @@ -2,6 +2,7 @@ package io.anuke.mindustry.game; import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.utils.Array; +import com.badlogic.gdx.utils.IntMap; import com.badlogic.gdx.utils.TimeUtils; import io.anuke.mindustry.core.GameState.State; import io.anuke.mindustry.game.EventType.StateChangeEvent; @@ -21,6 +22,7 @@ import static io.anuke.mindustry.Vars.*; public class Saves{ private int nextSlot; private Array saves = new ThreadArray<>(); + private IntMap saveMap = new IntMap<>(); private SaveSlot current; private boolean saving; private float time; @@ -44,6 +46,7 @@ public class Saves{ if(SaveIO.isSaveValid(index)){ SaveSlot slot = new SaveSlot(index); saves.add(slot); + saveMap.put(slot.index, slot); slot.meta = SaveIO.getData(index); nextSlot = Math.max(index + 1, nextSlot); } @@ -99,16 +102,18 @@ public class Saves{ return saving; } - public void addSave(String name){ + public SaveSlot addSave(String name){ SaveSlot slot = new SaveSlot(nextSlot); nextSlot++; slot.setName(name); saves.add(slot); + saveMap.put(slot.index, slot); SaveIO.saveToSlot(slot.index); slot.meta = SaveIO.getData(slot.index); current = slot; saveSlots(); + return slot; } public SaveSlot importSave(FileHandle file) throws IOException{ @@ -117,12 +122,17 @@ public class Saves{ nextSlot++; slot.setName(file.nameWithoutExtension()); saves.add(slot); + saveMap.put(slot.index, slot); slot.meta = SaveIO.getData(slot.index); current = slot; saveSlots(); return slot; } + public SaveSlot getByID(int id){ + return saveMap.get(id); + } + public Array getSaveSlots(){ return saves; } @@ -157,6 +167,10 @@ public class Saves{ current = this; } + public boolean isHidden(){ + return meta.sector != invalidSector; + } + public String getPlayTime(){ return Strings.formatMillis(current == this ? totalPlaytime : meta.timePlayed); } @@ -223,11 +237,16 @@ public class Saves{ } public void delete(){ - SaveIO.fileFor(index).delete(); + if(!gwt){ //can't delete files + SaveIO.fileFor(index).delete(); + } saves.removeValue(this, true); + saveMap.remove(index); if(this == current){ current = null; } + + saveSlots(); } } } diff --git a/core/src/io/anuke/mindustry/graphics/MinimapRenderer.java b/core/src/io/anuke/mindustry/graphics/MinimapRenderer.java index 2760dbdc78..1f5cc7938a 100644 --- a/core/src/io/anuke/mindustry/graphics/MinimapRenderer.java +++ b/core/src/io/anuke/mindustry/graphics/MinimapRenderer.java @@ -139,15 +139,8 @@ public class MinimapRenderer implements Disposable{ } private int colorFor(Tile tile){ - int color = tile.breakable() ? tile.target().getTeam().intColor : ColorMapper.getBlockColor(tile.block()); - if(color == 0) color = ColorMapper.getBlockColor(tile.floor()); - if(tile.elevation > 0){ - float mul = 1.1f + tile.elevation / 4f; - tmpColor.set(color); - tmpColor.mul(mul, mul, mul, 1f); - color = Color.rgba8888(tmpColor); - } - return color; + tile = tile.target(); + return ColorMapper.colorFor(tile.floor(), tile.block(), tile.getTeam(), tile.getElevation()); } @Override diff --git a/core/src/io/anuke/mindustry/io/SaveFileVersion.java b/core/src/io/anuke/mindustry/io/SaveFileVersion.java index 010ae561f5..c9e0ee89d8 100644 --- a/core/src/io/anuke/mindustry/io/SaveFileVersion.java +++ b/core/src/io/anuke/mindustry/io/SaveFileVersion.java @@ -14,14 +14,15 @@ public abstract class SaveFileVersion{ } public SaveMeta getData(DataInputStream stream) throws IOException{ - long time = stream.readLong(); //read last saved time + long time = stream.readLong(); long playtime = stream.readLong(); int build = stream.readInt(); - byte mode = stream.readByte(); //read the gamemode - String map = stream.readUTF(); //read the map - int wave = stream.readInt(); //read the wave - byte difficulty = stream.readByte(); //read the difficulty - return new SaveMeta(version, time, playtime, build, mode, map, wave, Difficulty.values()[difficulty]); + int sector = stream.readInt(); + byte mode = stream.readByte(); + String map = stream.readUTF(); + int wave = stream.readInt(); + byte difficulty = stream.readByte(); + return new SaveMeta(version, time, playtime, build, sector, mode, map, wave, Difficulty.values()[difficulty]); } public abstract void read(DataInputStream stream) throws IOException; diff --git a/core/src/io/anuke/mindustry/io/SaveMeta.java b/core/src/io/anuke/mindustry/io/SaveMeta.java index a0c5a83915..22cfbed537 100644 --- a/core/src/io/anuke/mindustry/io/SaveMeta.java +++ b/core/src/io/anuke/mindustry/io/SaveMeta.java @@ -14,16 +14,18 @@ public class SaveMeta{ public int build; public String date; public long timePlayed; + public int sector; public GameMode mode; public Map map; public int wave; public Difficulty difficulty; - public SaveMeta(int version, long date, long timePlayed, int build, int mode, String map, int wave, Difficulty difficulty){ + public SaveMeta(int version, long date, long timePlayed, int build, int sector, int mode, String map, int wave, Difficulty difficulty){ this.version = version; this.build = build; this.date = Platform.instance.format(new Date(date)); this.timePlayed = timePlayed; + this.sector = sector; this.mode = GameMode.values()[mode]; this.map = world.maps().getByName(map); this.wave = wave; diff --git a/core/src/io/anuke/mindustry/io/versions/Save16.java b/core/src/io/anuke/mindustry/io/versions/Save16.java index 42aaea8cf4..901213df7d 100644 --- a/core/src/io/anuke/mindustry/io/versions/Save16.java +++ b/core/src/io/anuke/mindustry/io/versions/Save16.java @@ -38,6 +38,7 @@ public class Save16 extends SaveFileVersion{ stream.readLong(); //time stream.readLong(); //total playtime stream.readInt(); //build + stream.readInt(); //sector ID //general state byte mode = stream.readByte(); @@ -102,7 +103,7 @@ public class Save16 extends SaveFileVersion{ byte elevation = stream.readByte(); Tile tile = new Tile(x, y, floorid, wallid); - tile.elevation = elevation; + tile.setElevation(elevation); if(wallid == Blocks.blockpart.id){ tile.link = stream.readByte(); @@ -136,7 +137,7 @@ public class Save16 extends SaveFileVersion{ for(int j = i + 1; j < i + 1 + consecutives; j++){ int newx = j % width, newy = j / width; Tile newTile = new Tile(newx, newy, floorid, wallid); - newTile.elevation = elevation; + newTile.setElevation(elevation); tiles[newx][newy] = newTile; } @@ -156,6 +157,7 @@ public class Save16 extends SaveFileVersion{ stream.writeLong(TimeUtils.millis()); //last saved stream.writeLong(headless ? 0 : control.getSaves().getTotalPlaytime()); //playtime stream.writeInt(Version.build); //build + stream.writeInt(world.getSector() == null ? invalidSector : world.getSector().packedPosition()); //sector ID //--GENERAL STATE-- stream.writeByte(state.mode.ordinal()); //gamemode @@ -212,7 +214,7 @@ public class Save16 extends SaveFileVersion{ stream.writeByte(tile.getFloorID()); stream.writeByte(tile.getWallID()); - stream.writeByte(tile.elevation); + stream.writeByte(tile.getElevation()); if(tile.block() instanceof BlockPart){ stream.writeByte(tile.link); @@ -232,7 +234,7 @@ public class Save16 extends SaveFileVersion{ for(int j = i + 1; j < world.width() * world.height() && consecutives < 255; j++){ Tile nextTile = world.tile(j); - if(nextTile.getFloorID() != tile.getFloorID() || nextTile.getWallID() != 0 || nextTile.elevation != tile.elevation){ + if(nextTile.getFloorID() != tile.getFloorID() || nextTile.getWallID() != 0 || nextTile.getElevation() != tile.getElevation()){ break; } diff --git a/core/src/io/anuke/mindustry/maps/Sector.java b/core/src/io/anuke/mindustry/maps/Sector.java index 3671deff27..37dad39fb3 100644 --- a/core/src/io/anuke/mindustry/maps/Sector.java +++ b/core/src/io/anuke/mindustry/maps/Sector.java @@ -1,12 +1,26 @@ package io.anuke.mindustry.maps; import com.badlogic.gdx.graphics.Texture; +import io.anuke.mindustry.io.SaveIO; +import io.anuke.ucore.util.Bits; + +import static io.anuke.mindustry.Vars.control; public class Sector{ /**Position on the map, can be positive or negative.*/ public short x, y; /**Whether this sector has already been captured. TODO statistics?*/ public boolean unlocked; + /**Slot ID of this sector's save. -1 means no save has been created.*/ + public int saveID = -1; /**Display texture. Needs to be disposed.*/ public transient Texture texture; + + public boolean hasSave(){ + return saveID != -1 && SaveIO.isSaveValid(saveID) && control.getSaves().getByID(saveID) != null; + } + + public int packedPosition(){ + return Bits.packInt(x, y); + } } diff --git a/core/src/io/anuke/mindustry/maps/Sectors.java b/core/src/io/anuke/mindustry/maps/Sectors.java index be7f26c87e..aa4273a9b0 100644 --- a/core/src/io/anuke/mindustry/maps/Sectors.java +++ b/core/src/io/anuke/mindustry/maps/Sectors.java @@ -1,12 +1,13 @@ package io.anuke.mindustry.maps; -import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Pixmap; 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.game.Team; 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; @@ -19,7 +20,7 @@ public class Sectors{ private GridMap grid = new GridMap<>(); public Sectors(){ - + Settings.json().addClassTag("Sector", Sector.class); } /**If a sector is not yet unlocked, returns null.*/ @@ -34,9 +35,8 @@ 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); } } @@ -58,6 +58,10 @@ public class Sectors{ createTexture(sector); grid.put(sector.x, sector.y, sector); } + + if(out.size == 0){ + unlockSector(0, 0); + } } public void save(){ @@ -83,7 +87,7 @@ public class Sectors{ GenResult result = world.generator().generateTile(sector.x, sector.y, toX, toY); - int color = Color.rgba8888(result.floor.minimapColor); + int color = ColorMapper.colorFor(result.floor, result.wall, Team.none, result.elevation); pixmap.drawPixel(x, sectorImageSize - 1 - y, color); } } diff --git a/core/src/io/anuke/mindustry/maps/generation/WorldGenerator.java b/core/src/io/anuke/mindustry/maps/generation/WorldGenerator.java index c49fa5add8..ec208c6e62 100644 --- a/core/src/io/anuke/mindustry/maps/generation/WorldGenerator.java +++ b/core/src/io/anuke/mindustry/maps/generation/WorldGenerator.java @@ -180,14 +180,14 @@ public class WorldGenerator{ for(int y = 0; y < height; y++){ Tile tile = tiles[x][y]; - byte elevation = tile.elevation; + byte elevation = tile.getElevation(); for(GridPoint2 point : Geometry.d4){ if(!Mathf.inBounds(x + point.x, y + point.y, width, height)) continue; - if(tiles[x + point.x][y + point.y].elevation < elevation){ + if(tiles[x + point.x][y + point.y].getElevation() < elevation){ if(Mathf.chance(0.05)){ - tile.elevation = -1; + tile.setElevation(-1); } break; } diff --git a/core/src/io/anuke/mindustry/net/NetworkIO.java b/core/src/io/anuke/mindustry/net/NetworkIO.java index 9e893e8efe..8db698a89e 100644 --- a/core/src/io/anuke/mindustry/net/NetworkIO.java +++ b/core/src/io/anuke/mindustry/net/NetworkIO.java @@ -64,7 +64,7 @@ public class NetworkIO{ stream.writeByte(tile.getFloorID()); stream.writeByte(tile.getWallID()); - stream.writeByte(tile.elevation); + stream.writeByte(tile.getElevation()); if(tile.block() instanceof BlockPart){ stream.writeByte(tile.link); @@ -84,7 +84,7 @@ public class NetworkIO{ for(int j = i + 1; j < world.width() * world.height() && consecutives < 255; j++){ Tile nextTile = world.tile(j); - if(nextTile.getFloorID() != tile.getFloorID() || nextTile.getWallID() != 0 || nextTile.elevation != tile.elevation){ + if(nextTile.getFloorID() != tile.getFloorID() || nextTile.getWallID() != 0 || nextTile.getElevation() != tile.getElevation()){ break; } @@ -178,7 +178,7 @@ public class NetworkIO{ byte elevation = stream.readByte(); Tile tile = new Tile(x, y, floorid, wallid); - tile.elevation = elevation; + tile.setElevation(elevation); if(wallid == Blocks.blockpart.id){ tile.link = stream.readByte(); @@ -205,7 +205,7 @@ public class NetworkIO{ for(int j = i + 1; j < i + 1 + consecutives; j++){ int newx = j % width, newy = j / width; Tile newTile = new Tile(newx, newy, floorid, wallid); - newTile.elevation = elevation; + newTile.setElevation(elevation); tiles[newx][newy] = newTile; } diff --git a/core/src/io/anuke/mindustry/ui/dialogs/LevelDialog.java b/core/src/io/anuke/mindustry/ui/dialogs/LevelDialog.java index 82cd9cdb72..e8bbfdd562 100644 --- a/core/src/io/anuke/mindustry/ui/dialogs/LevelDialog.java +++ b/core/src/io/anuke/mindustry/ui/dialogs/LevelDialog.java @@ -125,7 +125,7 @@ public class LevelDialog extends FloatingDialog{ Timers.run(5f, () -> { Cursors.restoreCursor(); threads.run(() -> { - world.loadProceduralMap(0, 0); + world.loadSector(0, 0); logic.play(); Gdx.app.postRunnable(ui.loadfrag::hide); }); diff --git a/core/src/io/anuke/mindustry/ui/dialogs/LoadDialog.java b/core/src/io/anuke/mindustry/ui/dialogs/LoadDialog.java index 1f145363c0..5081282dca 100644 --- a/core/src/io/anuke/mindustry/ui/dialogs/LoadDialog.java +++ b/core/src/io/anuke/mindustry/ui/dialogs/LoadDialog.java @@ -56,6 +56,7 @@ public class LoadDialog extends FloatingDialog{ Array array = control.getSaves().getSaveSlots(); for(SaveSlot slot : array){ + if(slot.isHidden()) continue; TextButton button = new TextButton("[accent]" + slot.getName(), "clear"); button.getLabelCell().growX().left(); @@ -140,7 +141,10 @@ public class LoadDialog extends FloatingDialog{ } public void addSetup(){ - if(control.getSaves().getSaveSlots().size == 0){ + boolean valids = false; + for(SaveSlot slot : control.getSaves().getSaveSlots()) if(!slot.isHidden()) valids = true; + + if(!valids){ slots.row(); slots.addButton("$text.save.none", "clear", () -> { diff --git a/core/src/io/anuke/mindustry/ui/dialogs/SectorsDialog.java b/core/src/io/anuke/mindustry/ui/dialogs/SectorsDialog.java index 10cba415cd..226d1b40e5 100644 --- a/core/src/io/anuke/mindustry/ui/dialogs/SectorsDialog.java +++ b/core/src/io/anuke/mindustry/ui/dialogs/SectorsDialog.java @@ -12,6 +12,7 @@ import io.anuke.ucore.scene.Element; import io.anuke.ucore.scene.event.ClickListener; import io.anuke.ucore.scene.event.InputEvent; import io.anuke.ucore.scene.event.InputListener; +import io.anuke.ucore.scene.ui.TextButton; import io.anuke.ucore.scene.utils.Cursors; import io.anuke.ucore.scene.utils.ScissorStack; import io.anuke.ucore.util.Bundles; @@ -26,15 +27,18 @@ public class SectorsDialog extends FloatingDialog{ public SectorsDialog(){ super("$text.sectors"); - addCloseButton(); - setup(); + shown(this::setup); } void setup(){ content().clear(); + buttons().clear(); + + addCloseButton(); content().label(() -> Bundles.format("text.sector", selected == null ? "" : - selected.x + ", " + selected.y + (!selected.unlocked ? Bundles.get("text.sector.locked") : ""))); + (selected.x + ", " + selected.y + (!selected.unlocked ? " " + Bundles.get("text.sector.locked") : "")) + + (selected.saveID == -1 && selected.unlocked ? " " + Bundles.get("text.sector.unexplored") : ""))); content().row(); content().add(new SectorView()).grow(); content().row(); @@ -42,10 +46,22 @@ public class SectorsDialog extends FloatingDialog{ hide(); ui.loadLogic(() -> { - world.loadProceduralMap(selected.x, selected.y); - logic.play(); + if(!selected.hasSave()){ + world.loadSector(selected); + logic.play(); + selected.saveID = control.getSaves().addSave("sector-" + selected.packedPosition()).index; + world.sectors().save(); + }else{ + control.getSaves().getByID(selected.saveID).load(); + logic.play(); + } }); - }).size(230f, 64f).disabled(b -> selected == null); + }).size(230f, 64f).name("deploy-button").disabled(b -> selected == null || !selected.unlocked); + } + + void selectSector(Sector sector){ + buttons().find("deploy-button").setText(sector.hasSave() ? "$text.sector.resume" : "$text.sector.deploy"); + selected = sector; } class SectorView extends Element{ @@ -110,22 +126,20 @@ public class SectorsDialog extends FloatingDialog{ 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); - if(sector == null) continue; + if(sector != null && sector.texture != null){ + Draw.color(Color.WHITE); + Draw.rect(sector.texture, drawX, drawY, sectorSize, sectorSize); + } - Draw.color(Color.WHITE); - Draw.rect(sector.texture, drawX, drawY, sectorSize, sectorSize); - - if(sector == selected){ + if(sector == null){ + Draw.color(Color.DARK_GRAY); + }else if(sector == selected){ Draw.color(Palette.place); }else if(Mathf.inRect(mouse.x, mouse.y, drawX - sectorSize/2f, drawY - sectorSize/2f, drawX + sectorSize/2f, drawY + sectorSize/2f)){ if(clicked){ - selected = sector; + selectSector(sector); } Draw.color(Palette.remove); }else if (sector.unlocked){ @@ -134,7 +148,7 @@ public class SectorsDialog extends FloatingDialog{ Draw.color(Color.LIGHT_GRAY); } - Lines.stroke(selected == sector ? 5f : 3f); + Lines.stroke(sector != null && selected == sector ? 5f : 3f); Lines.crect(drawX, drawY, sectorSize, sectorSize); } } diff --git a/core/src/io/anuke/mindustry/world/ColorMapper.java b/core/src/io/anuke/mindustry/world/ColorMapper.java index 012caefe05..9941bd3b5a 100644 --- a/core/src/io/anuke/mindustry/world/ColorMapper.java +++ b/core/src/io/anuke/mindustry/world/ColorMapper.java @@ -5,11 +5,13 @@ import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.IntMap; import com.badlogic.gdx.utils.ObjectIntMap; import io.anuke.mindustry.game.Content; +import io.anuke.mindustry.game.Team; import io.anuke.mindustry.type.ContentList; public class ColorMapper implements ContentList{ private static IntMap blockMap = new IntMap<>(); private static ObjectIntMap colorMap = new ObjectIntMap<>(); + private static Color tmpColor = new Color(); public static Block getByColor(int color){ return blockMap.get(color); @@ -19,6 +21,18 @@ public class ColorMapper implements ContentList{ return colorMap.get(block, 0); } + public static int colorFor(Block floor, Block wall, Team team, int elevation){ + int color = wall.breakable ? team.intColor : getBlockColor(wall); + if(color == 0) color = ColorMapper.getBlockColor(floor); + if(elevation > 0){ + float mul = 1.1f + elevation / 4f; + tmpColor.set(color); + tmpColor.mul(mul, mul, mul, 1f); + color = Color.rgba8888(tmpColor); + } + return color; + } + @Override public void load(){ for(Block block : Block.all()){ diff --git a/core/src/io/anuke/mindustry/world/Tile.java b/core/src/io/anuke/mindustry/world/Tile.java index 57fa14fc27..707114d8ca 100644 --- a/core/src/io/anuke/mindustry/world/Tile.java +++ b/core/src/io/anuke/mindustry/world/Tile.java @@ -34,8 +34,6 @@ public class Tile implements PosTrait, TargetTrait{ public short x, y; /** Tile traversal cost. */ public byte cost = 1; - /** Elevation of tile. */ - public byte elevation; /** Position of cliffs around the tile, packed into bits 0-8. */ public byte cliffs; /** Tile entity, usually null. */ @@ -47,6 +45,8 @@ public class Tile implements PosTrait, TargetTrait{ private byte rotation; /** Team ordinal. */ private byte team; + /** Tile elevation. -1 means slope.*/ + private byte elevation; public Tile(int x, int y){ this.x = (short) x; @@ -65,7 +65,7 @@ public class Tile implements PosTrait, TargetTrait{ this.floor = (Floor) Block.getByID(floor); this.wall = Block.getByID(wall); this.rotation = rotation; - this.elevation = elevation; + this.setElevation(elevation); changed(); this.team = team; } @@ -201,6 +201,14 @@ public class Tile implements PosTrait, TargetTrait{ this.rotation = dump; } + public byte getElevation(){ + return elevation; + } + + public void setElevation(int elevation){ + this.elevation = (byte)elevation; + } + public boolean passable(){ Block block = block(); Block floor = floor(); @@ -217,7 +225,7 @@ public class Tile implements PosTrait, TargetTrait{ Block block = block(); Block floor = floor(); return block.solid || cliffs != 0 || (floor.solid && (block == Blocks.air || block.solidifes)) || block.isSolidFor(this) - || (isLinked() && getLinked().block().isSolidFor(getLinked())); + || (isLinked() && getLinked().block().isSolidFor(getLinked())); } public boolean breakable(){ @@ -453,6 +461,6 @@ public class Tile implements PosTrait, TargetTrait{ Block floor = floor(); return floor.name() + ":" + block.name() + "[" + x + "," + y + "] " + "entity=" + (entity == null ? "null" : ClassReflection.getSimpleName(entity.getClass())) + - (link != 0 ? " link=[" + (Bits.getLeftByte(link) - 8) + ", " + (Bits.getRightByte(link) - 8) + "]" : ""); + (link != 0 ? " link=[" + (Bits.getLeftByte(link) - 8) + ", " + (Bits.getRightByte(link) - 8) + "]" : ""); } } \ No newline at end of file diff --git a/core/src/io/anuke/mindustry/world/blocks/distribution/Splitter.java b/core/src/io/anuke/mindustry/world/blocks/distribution/Splitter.java index 8814415013..4b405c7f78 100644 --- a/core/src/io/anuke/mindustry/world/blocks/distribution/Splitter.java +++ b/core/src/io/anuke/mindustry/world/blocks/distribution/Splitter.java @@ -11,7 +11,7 @@ import io.anuke.mindustry.world.meta.BlockGroup; import io.anuke.ucore.core.Timers; public class Splitter extends Block{ - protected float speed = 8f; + protected float speed = 7f; public Splitter(String name){ super(name); diff --git a/server/src/io/anuke/mindustry/server/ServerControl.java b/server/src/io/anuke/mindustry/server/ServerControl.java index 8ac080d746..633ed4b0ec 100644 --- a/server/src/io/anuke/mindustry/server/ServerControl.java +++ b/server/src/io/anuke/mindustry/server/ServerControl.java @@ -104,13 +104,11 @@ public class ServerControl extends Module{ world.loadMap(map); }else{ info("Selected a procedural map."); - world.loadProceduralMap(); - logic.play(); + playSectorMap(); } }else{ info("Selected a procedural map."); - world.loadProceduralMap(); - logic.play(); + playSectorMap(); } }else{ state.set(State.menu); @@ -181,17 +179,17 @@ public class ServerControl extends Module{ logic.reset(); world.loadMap(result); + logic.play(); }else{ Log.info("&ly&fiNo map specified, so a procedural one was generated."); - world.loadProceduralMap(); + playSectorMap(); } }else{ Log.info("&ly&fiNo map specified, so a procedural one was generated."); - world.loadProceduralMap(); + playSectorMap(); } - logic.play(); info("Map loaded."); host(); @@ -807,6 +805,11 @@ public class ServerControl extends Module{ } } + private void playSectorMap(){ + world.loadSector(world.sectors().get(0, 0)); + logic.play(); + } + private void host(){ try{ Net.host(port);