Merge remote-tracking branch 'origin/master'

# Conflicts:
#	core/src/io/anuke/mindustry/core/Renderer.java
This commit is contained in:
Anuken
2018-10-08 19:55:51 -04:00
31 changed files with 730 additions and 102 deletions

View File

@@ -159,7 +159,7 @@ public class BlockIndexer{
* Find the closest ore block relative to a position.
*/
public Tile findClosestOre(float xp, float yp, Item item){
Tile tile = Geometry.findClosest(xp, yp, world.indexer().getOrePositions(item));
Tile tile = Geometry.findClosest(xp, yp, world.indexer.getOrePositions(item));
if(tile == null) return null;

View File

@@ -111,7 +111,7 @@ public class Pathfinder{
path.lastSearchTime = TimeUtils.millis();
Array<Tile> set = world.indexer().getEnemy(team, BlockFlag.target);
Array<Tile> set = world.indexer.getEnemy(team, BlockFlag.target);
for(Tile other : set){
path.weights[other.x][other.y] = 0;
path.searches[other.x][other.y] = path.search;

View File

@@ -156,7 +156,7 @@ public class WaveSpawner{
for(int y = quady * quadsize; y < world.height() && y < (quady + 1) * quadsize; y++){
Tile tile = world.tile(x, y);
if(tile == null || tile.solid() || world.pathfinder().getValueforTeam(Team.red, x, y) == Float.MAX_VALUE){
if(tile == null || tile.solid() || world.pathfinder.getValueforTeam(Team.red, x, y) == Float.MAX_VALUE){
setQuad(quadx, quady, false);
break outer;
}

View File

@@ -100,15 +100,15 @@ public class Logic extends Module{
state.mode = world.getSector().currentMission().getMode();
world.getSector().currentMission().onBegin();
world.sectors().save();
world.sectors.save();
}
//check if all assigned missions are complete
if(!world.getSector().complete && world.getSector().completedMissions >= world.getSector().missions.size){
state.mode = GameMode.victory;
world.sectors().completeSector(world.getSector().x, world.getSector().y);
world.sectors().save();
world.sectors.completeSector(world.getSector().x, world.getSector().y);
world.sectors.save();
if(!headless){
ui.missions.show(world.getSector());
}
@@ -180,7 +180,7 @@ public class Logic extends Module{
EntityQuery.collideGroups(bulletGroup, playerGroup);
EntityQuery.collideGroups(playerGroup, playerGroup);
world.pathfinder().update();
world.pathfinder.update();
}
}

View File

@@ -12,9 +12,9 @@ import io.anuke.mindustry.game.EventType.WorldLoadEvent;
import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.io.MapIO;
import io.anuke.mindustry.maps.*;
import io.anuke.mindustry.maps.generation.WorldGenerator;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.maps.generation.WorldGenerator;
import io.anuke.mindustry.world.blocks.OreBlock;
import io.anuke.ucore.core.Events;
import io.anuke.ucore.core.Timers;
@@ -28,12 +28,12 @@ public class World extends Module{
public final Maps maps = new Maps();
public final Sectors sectors = new Sectors();
public final WorldGenerator generator = new WorldGenerator();
public final BlockIndexer indexer = new BlockIndexer();
public final Pathfinder pathfinder = new Pathfinder();
private Map currentMap;
private Sector currentSector;
private Tile[][] tiles;
private Pathfinder pathfinder = new Pathfinder();
private BlockIndexer indexer = new BlockIndexer();
private Array<Tile> tempTiles = new ThreadArray<>();
private boolean generating, invalidMap;
@@ -52,26 +52,6 @@ public class World extends Module{
maps.dispose();
}
public WorldGenerator generator(){
return generator;
}
public Sectors sectors(){
return sectors;
}
public Maps maps(){
return maps;
}
public BlockIndexer indexer(){
return indexer;
}
public Pathfinder pathfinder(){
return pathfinder;
}
public boolean isInvalidMap(){
return invalidMap;
}

View File

@@ -266,11 +266,11 @@ public class MapEditorDialog extends Dialog implements Disposable{
if(name.isEmpty()){
ui.showError("$text.editor.save.noname");
}else{
Map map = world.maps().getByName(name);
Map map = world.maps.getByName(name);
if(map != null && !map.custom){
ui.showError("$text.editor.save.overwrite");
}else{
world.maps().saveMap(name, editor.getMap(), editor.getTags());
world.maps.saveMap(name, editor.getMap(), editor.getTags());
ui.showInfoFade("$text.editor.saved");
}
}

View File

@@ -38,8 +38,8 @@ public class MapLoadDialog extends FloatingDialog{
public void rebuild(){
content().clear();
if(world.maps().all().size > 0){
selected = world.maps().all().first();
if(world.maps.all().size > 0){
selected = world.maps.all().first();
}
ButtonGroup<TextButton> group = new ButtonGroup<>();
@@ -55,7 +55,7 @@ public class MapLoadDialog extends FloatingDialog{
ScrollPane pane = new ScrollPane(table, "horizontal");
pane.setFadeScrollBars(false);
for(Map map : world.maps().all()){
for(Map map : world.maps.all()){
TextButton button = new TextButton(map.getDisplayName(), "toggle");
button.add(new BorderImage(map.texture, 2f)).size(16 * 4f);
@@ -67,7 +67,7 @@ public class MapLoadDialog extends FloatingDialog{
if(++i % maxcol == 0) table.row();
}
if(world.maps().all().size == 0){
if(world.maps.all().size == 0){
pane.setStyle(Core.skin.get("clear", ScrollPaneStyle.class));
table.add("$text.maps.none").center();
}else{

View File

@@ -24,7 +24,7 @@ public class MapSaveDialog extends FloatingDialog{
shown(() -> {
content().clear();
content().label(() -> {
Map map = world.maps().getByName(field.getText());
Map map = world.maps.getByName(field.getText());
if(map != null){
if(map.custom){
return "$text.editor.overwrite";
@@ -69,7 +69,7 @@ public class MapSaveDialog extends FloatingDialog{
if(field.getText().isEmpty()){
return true;
}
Map map = world.maps().getByName(field.getText());
Map map = world.maps.getByName(field.getText());
return map != null && !map.custom;
}
}

View File

@@ -106,7 +106,7 @@ public class Units{
* Returns the neareset ally tile in a range.
*/
public static TileEntity findAllyTile(Team team, float x, float y, float range, Predicate<Tile> pred){
return world.indexer().findTile(team, x, y, range, pred);
return world.indexer.findTile(team, x, y, range, pred);
}
/**
@@ -114,7 +114,7 @@ public class Units{
*/
public static TileEntity findEnemyTile(Team team, float x, float y, float range, Predicate<Tile> pred){
for(Team enemy : state.teams.enemiesOf(team)){
TileEntity entity = world.indexer().findTile(enemy, x, y, range, pred);
TileEntity entity = world.indexer.findTile(enemy, x, y, range, pred);
if(entity != null){
return entity;
}

View File

@@ -99,12 +99,12 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
}
public boolean isCommanded(){
return !isWave && world.indexer().getAllied(team, BlockFlag.comandCenter).size != 0;
return !isWave && world.indexer.getAllied(team, BlockFlag.comandCenter).size != 0;
}
public UnitCommand getCommand(){
if(isCommanded()){
return world.indexer().getAllied(team, BlockFlag.comandCenter).first().<CommandCenterEntity>entity().command;
return world.indexer.getAllied(team, BlockFlag.comandCenter).first().<CommandCenterEntity>entity().command;
}
return null;
}
@@ -180,12 +180,12 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
}
public void targetClosestAllyFlag(BlockFlag flag){
Tile target = Geometry.findClosest(x, y, world.indexer().getAllied(team, flag));
Tile target = Geometry.findClosest(x, y, world.indexer.getAllied(team, flag));
if(target != null) this.target = target.entity;
}
public void targetClosestEnemyFlag(BlockFlag flag){
Tile target = Geometry.findClosest(x, y, world.indexer().getEnemy(team, flag));
Tile target = Geometry.findClosest(x, y, world.indexer.getEnemy(team, flag));
if(target != null) this.target = target.entity;
}

View File

@@ -113,7 +113,7 @@ public abstract class FlyingUnit extends BaseUnit implements CarryTrait{
state.set(attack);
}else if(!targetHasFlag(BlockFlag.repair)){
retarget(() -> {
Tile target = Geometry.findClosest(x, y, world.indexer().getAllied(team, BlockFlag.repair));
Tile target = Geometry.findClosest(x, y, world.indexer.getAllied(team, BlockFlag.repair));
if(target != null) FlyingUnit.this.target = target.entity;
});
}else{
@@ -177,7 +177,7 @@ public abstract class FlyingUnit extends BaseUnit implements CarryTrait{
@Override
public void behavior(){
if(health <= health * type.retreatPercent && !isCommanded() &&
Geometry.findClosest(x, y, world.indexer().getAllied(team, BlockFlag.repair)) != null){
Geometry.findClosest(x, y, world.indexer.getAllied(team, BlockFlag.repair)) != null){
setState(retreat);
}

View File

@@ -268,7 +268,7 @@ public abstract class GroundUnit extends BaseUnit{
protected void moveToCore(){
Tile tile = world.tileWorld(x, y);
if(tile == null) return;
Tile targetTile = world.pathfinder().getTargetTile(team, tile);
Tile targetTile = world.pathfinder.getTargetTile(team, tile);
if(tile == targetTile) return;
@@ -288,7 +288,7 @@ public abstract class GroundUnit extends BaseUnit{
Tile tile = world.tileWorld(x, y);
if(tile == null) return;
Tile targetTile = world.pathfinder().getTargetTile(enemy, tile);
Tile targetTile = world.pathfinder.getTargetTile(enemy, tile);
TileEntity core = getClosestCore();
if(tile == targetTile || core == null || distanceTo(core) < 90f) return;

View File

@@ -158,7 +158,7 @@ public class Drone extends FlyingUnit implements BuilderTrait{
if(targetItem == null) return;
target = world.indexer().findClosestOre(x, y, targetItem);
target = world.indexer.findClosestOre(x, y, targetItem);
});
if(target instanceof Tile){
@@ -224,7 +224,7 @@ public class Drone extends FlyingUnit implements BuilderTrait{
state.set(attack);
}else if(!targetHasFlag(BlockFlag.repair)){
if(timer.get(timerTarget, 20)){
Tile target = Geometry.findClosest(x, y, world.indexer().getAllied(team, BlockFlag.repair));
Tile target = Geometry.findClosest(x, y, world.indexer.getAllied(team, BlockFlag.repair));
if(target != null) Drone.this.target = target.entity;
}
}else{
@@ -318,7 +318,7 @@ public class Drone extends FlyingUnit implements BuilderTrait{
@Override
public void behavior(){
if(health <= health * type.retreatPercent &&
Geometry.findClosest(x, y, world.indexer().getAllied(team, BlockFlag.repair)) != null){
Geometry.findClosest(x, y, world.indexer.getAllied(team, BlockFlag.repair)) != null){
setState(retreat);
}
}

View File

@@ -49,7 +49,7 @@ public class FloorRenderer{
@Override
public Tile getNearby(int dx, int dy){
Sector sec = world.getSector();
GenResult result = world.generator().generateTile(sec.x, sec.y, x + dx, y + dy);
GenResult result = world.generator.generateTile(sec.x, sec.y, x + dx, y + dy);
gutterNearTile.x = (short)(x + dx);
gutterNearTile.y = (short)(y + dy);
gutterNearTile.setElevation(result.elevation);
@@ -192,7 +192,7 @@ public class FloorRenderer{
Floor floor = null;
if(tile == null && sector != null && tilex < world.width() + gutter*2 && tiley < world.height() + gutter*2){
GenResult result = world.generator().generateTile(sector.x, sector.y, tilex - gutter, tiley - gutter);
GenResult result = world.generator.generateTile(sector.x, sector.y, tilex - gutter, tiley - gutter);
floor = (Floor) result.floor;
}else if(tile != null){
floor = tile.floor();
@@ -223,7 +223,7 @@ public class FloorRenderer{
if(tile == null){
if(sector != null && tilex < world.width() + gutter*2 && tiley < world.height() + gutter*2){
GenResult result = world.generator().generateTile(sector.x, sector.y, tilex - gutter, tiley - gutter);
GenResult result = world.generator.generateTile(sector.x, sector.y, tilex - gutter, tiley - gutter);
floor = (Floor)result.floor;
gutterTile.setFloor(floor);
gutterTile.x = (short)(tilex - gutter);

View File

@@ -27,7 +27,7 @@ public class SaveMeta{
this.timePlayed = timePlayed;
this.sector = sector;
this.mode = GameMode.values()[mode];
this.map = world.maps().getByName(map);
this.map = world.maps.getByName(map);
this.wave = wave;
this.difficulty = difficulty;
}

View File

@@ -42,10 +42,10 @@ public class Save16 extends SaveFileVersion{
byte mode = stream.readByte();
String mapname = stream.readUTF();
Map map = world.maps().getByName(mapname);
Map map = world.maps.getByName(mapname);
world.setMap(map);
world.setSector(world.sectors().get(sector));
world.setSector(world.sectors.get(sector));
int wave = stream.readInt();
byte difficulty = stream.readByte();

View File

@@ -51,7 +51,7 @@ public class Sectors{
if(!headless){
sector.saveID = control.saves.addSave("sector-" + sector.packedPosition()).index;
}
world.sectors().save();
world.sectors.save();
world.setSector(sector);
sector.currentMission().onBegin();
}else if(SaveIO.breakingVersions.contains(sector.getSave().getBuild())){
@@ -169,7 +169,7 @@ public class Sectors{
//gen tiles in sector
for (int x = 0; x < sectorSize; x++) {
for (int y = 0; y < sectorSize; y++) {
world.generator().generateTile(result, sx + sector.x, sy + sector.y, x, y, true, null, ores);
world.generator.generateTile(result, sx + sector.x, sy + sector.y, x, y, true, null, ores);
newTiles[sx * sectorSize + x][sy * sectorSize + y] = new Tile(x + sx * sectorSize, y + sy*sectorSize, result.floor.id, result.wall.id, (byte)0, (byte)0, result.elevation);
}
}
@@ -405,8 +405,8 @@ public class Sectors{
int toX = x * sectorSize / sectorImageSize;
int toY = y * sectorSize / sectorImageSize;
GenResult result = world.generator().generateTile(sector.x, sector.y, toX, toY, false);
world.generator().generateTile(secResult, sector.x, sector.y, toX, ((y+1) * sectorSize / sectorImageSize), false, null, null);
GenResult result = world.generator.generateTile(sector.x, sector.y, toX, toY, false);
world.generator.generateTile(secResult, sector.x, sector.y, toX, ((y+1) * sectorSize / sectorImageSize), false, null, null);
int color = ColorMapper.colorFor(result.floor, result.wall, Team.none, result.elevation, secResult.elevation > result.elevation ? (byte)(1 << 6) : (byte)0);
pixmap.drawPixel(x, pixmap.getHeight() - 1 - y, color);

View File

@@ -49,7 +49,7 @@ public class TutorialSector{
for(int x = 0; x < world.width(); x++){
for(int y = 0; y < world.height(); y++){
Tile tile = world.tile(x, y);
world.generator().generateTile(res, 0, 0, x, y, true, null, ores);
world.generator.generateTile(res, 0, 0, x, y, true, null, ores);
if(!tile.hasCliffs()){
tile.setFloor((Floor) res.floor);
}

View File

@@ -187,7 +187,7 @@ public class WorldGenerator{
SeedRandom rnd = new SeedRandom(sector.getSeed());
Generation gena = new Generation(sector, tiles, tiles.length, tiles[0].length, rnd);
Array<GridPoint2> spawnpoints = sector.currentMission().getSpawnPoints(gena);
Array<Item> ores = world.sectors().getOres(sector.x, sector.y);
Array<Item> ores = world.sectors.getOres(sector.x, sector.y);
for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){

View File

@@ -13,11 +13,11 @@ public class ExpandMission extends ActionMission{
runner = () -> {
if(headless){
world.sectors().expandSector(world.getSector(), expandX, expandY);
world.sectors.expandSector(world.getSector(), expandX, expandY);
done = true;
}else{
ui.loadLogic(() -> {
world.sectors().expandSector(world.getSector(), expandX, expandY);
world.sectors.expandSector(world.getSector(), expandX, expandY);
done = true;
});
}

View File

@@ -37,7 +37,7 @@ public class WaveMission extends Mission{
public void onBegin(){
super.onBegin();
world.pathfinder().activateTeamPath(waveTeam);
world.pathfinder.activateTeamPath(waveTeam);
}
@Override

View File

@@ -84,7 +84,7 @@ public class CustomGameDialog extends FloatingDialog{
float images = 146f;
int i = 0;
for(Map map : world.maps().all()){
for(Map map : world.maps.all()){
if(i % maxwidth == 0){
maps.row();
@@ -112,7 +112,7 @@ public class CustomGameDialog extends FloatingDialog{
i++;
}
if(world.maps().all().size == 0){
if(world.maps.all().size == 0){
maps.add("$text.maps.none").pad(50);
}

View File

@@ -85,7 +85,7 @@ public class GenViewDialog extends FloatingDialog{
Pixmap pixmap = new Pixmap(sectorSize, sectorSize, Format.RGBA8888);
for(int i = 0; i < sectorSize; i++){
for(int j = 0; j < sectorSize; j++){
world.generator().generateTile(result, wx, wy, i, j, true, null, ores);
world.generator.generateTile(result, wx, wy, i, j, true, null, ores);
pixmap.drawPixel(i, sectorSize - 1 - j, ColorMapper.colorFor(result.floor, result.wall, Team.none, result.elevation, (byte)0));
}
}

View File

@@ -40,15 +40,15 @@ public class MapsDialog extends FloatingDialog{
String name = meta.tags.get("name", file.nameWithoutExtension());
if(world.maps().getByName(name) != null && !world.maps().getByName(name).custom){
if(world.maps.getByName(name) != null && !world.maps.getByName(name).custom){
ui.showError(Bundles.format("text.editor.import.exists", name));
}else if(world.maps().getByName(name) != null){
}else if(world.maps.getByName(name) != null){
ui.showConfirm("$text.confirm", "$text.editor.overwrite.confirm", () -> {
world.maps().saveMap(name, data, meta.tags);
world.maps.saveMap(name, data, meta.tags);
setup();
});
}else{
world.maps().saveMap(name, data, meta.tags);
world.maps.saveMap(name, data, meta.tags);
setup();
}
@@ -80,7 +80,7 @@ public class MapsDialog extends FloatingDialog{
float mapsize = 200f;
int i = 0;
for(Map map : world.maps().all()){
for(Map map : world.maps.all()){
if(i % maxwidth == 0){
maps.row();
@@ -100,7 +100,7 @@ public class MapsDialog extends FloatingDialog{
i++;
}
if(world.maps().all().size == 0){
if(world.maps.all().size == 0){
maps.add("$text.maps.none");
}
@@ -154,7 +154,7 @@ public class MapsDialog extends FloatingDialog{
table.addImageTextButton("$text.delete", "icon-trash-16", "clear", 16 * 2, () -> {
ui.showConfirm("$text.confirm", Bundles.format("text.map.delete", map.name), () -> {
world.maps().removeMap(map);
world.maps.removeMap(map);
dialog.hide();
setup();
});

View File

@@ -42,7 +42,7 @@ public class RestartDialog extends FloatingDialog{
buttons().addButton("$text.sector.retry", () -> {
Sector sector = world.getSector();
ui.loadLogic(() -> world.sectors().playSector(sector));
ui.loadLogic(() -> world.sectors.playSector(sector));
hide();
}).size(130f, 60f);
}

View File

@@ -51,7 +51,7 @@ public class SectorsDialog extends FloatingDialog{
buttons().addImageTextButton("$text.sector.deploy", "icon-play", 10*3, () -> {
hide();
ui.loadLogic(() -> world.sectors().playSector(selected));
ui.loadLogic(() -> world.sectors.playSector(selected));
}).size(230f, 64f).disabled(b -> selected == null)
.update(t -> t.setText(selected != null && selected.hasSave() ? "$text.sector.resume" : "$text.sector.deploy"));
}
@@ -132,7 +132,7 @@ public class SectorsDialog extends FloatingDialog{
float drawX = x + width/2f+ sectorX * padSectorSize - offsetX * padSectorSize - panX % padSectorSize;
float drawY = y + height/2f + sectorY * padSectorSize - offsetY * padSectorSize - panY % padSectorSize;
Sector sector = world.sectors().get(sectorX, sectorY);
Sector sector = world.sectors.get(sectorX, sectorY);
int width = (sector == null ? 1 : sector.width);
int height = (sector == null ? 1 : sector.height);
float paddingx = (width-1) * sectorPadding;

View File

@@ -153,7 +153,7 @@ public class SettingsMenuDialog extends SettingsDialog{
ui.showConfirm("$text.confirm", "$text.settings.clear.confirm", () -> {
Settings.clearBytes("sectors");
Settings.save();
world.sectors().load();
world.sectors.load();
dialog.hide();
});
});

View File

@@ -47,7 +47,7 @@ public class CommandCenter extends Block{
@Override
public void playerPlaced(Tile tile){
ObjectSet<Tile> set = world.indexer().getAllied(tile.getTeam(), BlockFlag.comandCenter);
ObjectSet<Tile> set = world.indexer.getAllied(tile.getTeam(), BlockFlag.comandCenter);
if(set.size > 0){
CommandCenterEntity entity = tile.entity();
@@ -92,7 +92,7 @@ public class CommandCenter extends Block{
public static void onCommandCenterSet(Player player, Tile tile, UnitCommand command){
Effects.effect(((CommandCenter)tile.block()).effect, tile);
for(Tile center : world.indexer().getAllied(tile.getTeam(), BlockFlag.comandCenter)){
for(Tile center : world.indexer.getAllied(tile.getTeam(), BlockFlag.comandCenter)){
if(center.block() instanceof CommandCenter){
CommandCenterEntity entity = center.entity();
entity.command = command;