diff --git a/core/src/io/anuke/mindustry/ai/BlockIndexer.java b/core/src/io/anuke/mindustry/ai/BlockIndexer.java index b9c513489e..9ba7ada244 100644 --- a/core/src/io/anuke/mindustry/ai/BlockIndexer.java +++ b/core/src/io/anuke/mindustry/ai/BlockIndexer.java @@ -13,7 +13,6 @@ import io.anuke.mindustry.type.Item; import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.meta.BlockFlag; import io.anuke.ucore.core.Events; -import io.anuke.ucore.entities.trait.Entity; import io.anuke.ucore.function.Predicate; import io.anuke.ucore.util.EnumSet; import io.anuke.ucore.util.Geometry; @@ -26,6 +25,7 @@ import static io.anuke.mindustry.Vars.*; //TODO maybe use Arrays instead of ObjectSets? /**Class used for indexing special target blocks for AI.*/ +@SuppressWarnings("unchecked") public class BlockIndexer{ /**Size of one ore quadrant.*/ private final static int oreQuadrantSize = 20; @@ -116,7 +116,7 @@ public class BlockIndexer{ } public TileEntity findTile(Team team, float x, float y, float range, Predicate pred){ - Entity closest = null; + TileEntity closest = null; float dst = 0; for(int rx = Math.max((int) ((x - range) / tilesize / structQuadrantSize), 0); rx <= (int) ((x + range) / tilesize / structQuadrantSize) && rx < quadWidth(); rx++){ @@ -142,7 +142,7 @@ public class BlockIndexer{ } } - return (TileEntity) closest; + return closest; } /** diff --git a/core/src/io/anuke/mindustry/core/Renderer.java b/core/src/io/anuke/mindustry/core/Renderer.java index 2eebee5b56..4ab7d6ff4c 100644 --- a/core/src/io/anuke/mindustry/core/Renderer.java +++ b/core/src/io/anuke/mindustry/core/Renderer.java @@ -5,7 +5,6 @@ import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Vector2; -import com.badlogic.gdx.utils.ObjectIntMap; import io.anuke.mindustry.content.fx.Fx; import io.anuke.mindustry.core.GameState.State; import io.anuke.mindustry.entities.Player; @@ -16,9 +15,7 @@ import io.anuke.mindustry.entities.traits.BelowLiquidTrait; import io.anuke.mindustry.entities.units.BaseUnit; import io.anuke.mindustry.game.Team; import io.anuke.mindustry.graphics.*; -import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.blocks.defense.ForceProjector.ShieldEntity; -import io.anuke.mindustry.world.meta.BlockFlag; import io.anuke.ucore.core.Core; import io.anuke.ucore.core.Effects; import io.anuke.ucore.core.Graphics; @@ -350,42 +347,6 @@ public class Renderer extends RendererModule{ return avgPosition; } - void drawDebug(){ - int rangex = (int) (Core.camera.viewportWidth / tilesize / 2), rangey = (int) (Core.camera.viewportHeight / tilesize / 2); - - for(int x = -rangex; x <= rangex; x++){ - for(int y = -rangey; y <= rangey; y++){ - int worldx = Mathf.scl(camera.position.x, tilesize) + x; - int worldy = Mathf.scl(camera.position.y, tilesize) + y; - - if(world.tile(worldx, worldy) == null) continue; - - float value = world.pathfinder().getDebugValue(worldx, worldy); - Draw.color(Color.PURPLE); - Draw.alpha((value % 10f) / 10f); - Lines.square(worldx * tilesize, worldy * tilesize, 4f); - } - } - - Draw.color(Color.ORANGE); - Draw.tcolor(Color.ORANGE); - - ObjectIntMap seen = new ObjectIntMap<>(); - - for(BlockFlag flag : BlockFlag.values()){ - for(Tile tile : world.indexer().getEnemy(Team.blue, flag)){ - int index = seen.getAndIncrement(tile, 0, 1); - Draw.tscl(0.125f); - Draw.text(flag.name(), tile.drawx(), tile.drawy() + tile.block().size * tilesize / 2f + 4 + index * 3); - Lines.square(tile.drawx(), tile.drawy(), tile.block().size * tilesize / 2f); - } - } - Draw.tscl(fontScale); - Draw.tcolor(); - - Draw.color(); - } - public void setCameraScale(int amount){ targetscale = amount; clampScale(); diff --git a/core/src/io/anuke/mindustry/core/UI.java b/core/src/io/anuke/mindustry/core/UI.java index c9d66465d2..e880e6d609 100644 --- a/core/src/io/anuke/mindustry/core/UI.java +++ b/core/src/io/anuke/mindustry/core/UI.java @@ -27,8 +27,6 @@ import io.anuke.ucore.scene.ui.layout.Table; import io.anuke.ucore.scene.ui.layout.Unit; import io.anuke.ucore.util.Structs; -import java.util.Locale; - import static io.anuke.mindustry.Vars.*; import static io.anuke.ucore.scene.actions.Actions.*; @@ -63,13 +61,11 @@ public class UI extends SceneModule{ public SectorsDialog sectors; public MissionDialog missions; - private Locale lastLocale; - public UI(){ Dialog.setShowAction(() -> sequence( alpha(0f), originCenter(), - moveToAligned(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2, Align.center), + moveToAligned(Gdx.graphics.getWidth() / 2f, Gdx.graphics.getHeight() / 2f, Align.center), scaleTo(0.0f, 1f), parallel( scaleTo(1f, 1f, 0.1f, Interpolation.fade), @@ -187,24 +183,6 @@ public class UI extends SceneModule{ Events.fire(new ResizeEvent()); } - public Locale getLocale(){ - String loc = Settings.getString("locale"); - if(loc.equals("default")){ - return Locale.getDefault(); - }else{ - if(lastLocale == null || !lastLocale.toString().equals(loc)){ - if(loc.contains("_")){ - String[] split = loc.split("_"); - lastLocale = new Locale(split[0], split[1]); - }else{ - lastLocale = new Locale(loc); - } - } - - return lastLocale; - } - } - public void loadGraphics(Runnable call){ loadGraphics("$text.loading", call); } @@ -223,12 +201,11 @@ public class UI extends SceneModule{ public void loadLogic(String text, Runnable call){ loadfrag.show(text); - Timers.runTask(7f, () -> { + Timers.runTask(7f, () -> threads.run(() -> { call.run(); threads.runGraphics(loadfrag::hide); - }); - }); + })); } public void showTextInput(String title, String text, String def, TextFieldFilter filter, Consumer confirmed){ diff --git a/core/src/io/anuke/mindustry/entities/Damage.java b/core/src/io/anuke/mindustry/entities/Damage.java index 740d443b88..199b3379d1 100644 --- a/core/src/io/anuke/mindustry/entities/Damage.java +++ b/core/src/io/anuke/mindustry/entities/Damage.java @@ -24,17 +24,13 @@ import io.anuke.ucore.util.Translator; import static io.anuke.mindustry.Vars.*; -/** - * Utility class for damaging in an area. - */ +/**Utility class for damaging in an area.*/ public class Damage{ private static Rectangle rect = new Rectangle(); private static Rectangle hitrect = new Rectangle(); private static Translator tr = new Translator(); - /** - * Creates a dynamic explosion based on specified parameters. - */ + /**Creates a dynamic explosion based on specified parameters.*/ public static void dynamicExplosion(float x, float y, float flammability, float explosiveness, float power, float radius, Color color){ for(int i = 0; i < Mathf.clamp(power / 20, 0, 6); i++){ int branches = 5 + Mathf.clamp((int) (power / 30), 1, 20); @@ -43,7 +39,7 @@ public class Damage{ } for(int i = 0; i < Mathf.clamp(flammability / 4, 0, 30); i++){ - Timers.run(i / 2, () -> Call.createBullet(TurretBullets.fireball, x, y, Mathf.random(360f))); + Timers.run(i / 2f, () -> Call.createBullet(TurretBullets.fireball, x, y, Mathf.random(360f))); } int waves = Mathf.clamp((int) (explosiveness / 4), 0, 30); @@ -135,9 +131,7 @@ public class Damage{ Units.getNearbyEnemies(team, rect, cons); } - /** - * Damages all entities and blocks in a radius that are enemies of the team. - */ + /**Damages all entities and blocks in a radius that are enemies of the team.*/ public static void damageUnits(Team team, float x, float y, float size, float damage, Predicate predicate, Consumer acceptor){ Consumer cons = entity -> { if(!predicate.test(entity)) return; @@ -158,16 +152,12 @@ public class Damage{ } } - /** - * Damages everything in a radius. - */ + /**Damages everything in a radius.*/ public static void damage(float x, float y, float radius, float damage){ damage(null, x, y, radius, damage); } - /** - * Damages all entities and blocks in a radius that are enemies of the team. - */ + /**Damages all entities and blocks in a radius that are enemies of the team.*/ public static void damage(Team team, float x, float y, float radius, float damage){ Consumer cons = entity -> { if(entity.team == team || entity.distanceTo(x, y) > radius){ diff --git a/core/src/io/anuke/mindustry/entities/Player.java b/core/src/io/anuke/mindustry/entities/Player.java index b8ca770540..32b99070ba 100644 --- a/core/src/io/anuke/mindustry/entities/Player.java +++ b/core/src/io/anuke/mindustry/entities/Player.java @@ -103,7 +103,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra @Override public void getHitboxTile(Rectangle rectangle){ - rectangle.setSize(4).setCenter(x, y); + rectangle.setSize(mech.hitsize * 2f / 3f).setCenter(x, y); } @Override @@ -412,9 +412,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra Draw.tscl(fontScale); } - /** - * Draw all current build requests. Does not draw the beam effect, only the positions. - */ + /**Draw all current build requests. Does not draw the beam effect, only the positions.*/ public void drawBuildRequests(){ synchronized(getPlaceQueue()){ for(BuildRequest request : getPlaceQueue()){ @@ -455,7 +453,6 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra hitTime -= Timers.delta(); if(Float.isNaN(x) || Float.isNaN(y)){ - //throw new RuntimeException("NaN found!"); velocity.set(0f, 0f); x = 0; y = 0; diff --git a/core/src/io/anuke/mindustry/maps/SectorPresets.java b/core/src/io/anuke/mindustry/maps/SectorPresets.java index 3776af2243..125462feb4 100644 --- a/core/src/io/anuke/mindustry/maps/SectorPresets.java +++ b/core/src/io/anuke/mindustry/maps/SectorPresets.java @@ -4,7 +4,11 @@ import com.badlogic.gdx.utils.Array; import io.anuke.mindustry.content.Items; import io.anuke.mindustry.content.Liquids; import io.anuke.mindustry.content.Mechs; -import io.anuke.mindustry.content.blocks.*; +import io.anuke.mindustry.content.UnitTypes; +import io.anuke.mindustry.content.blocks.CraftingBlocks; +import io.anuke.mindustry.content.blocks.ProductionBlocks; +import io.anuke.mindustry.content.blocks.UnitBlocks; +import io.anuke.mindustry.content.blocks.UpgradeBlocks; import io.anuke.mindustry.entities.units.UnitCommand; import io.anuke.mindustry.maps.missions.*; import io.anuke.mindustry.type.Item; @@ -26,9 +30,10 @@ public class SectorPresets{ 1)); //command center mission - add(new SectorPreset(2, 0, + add(new SectorPreset(0, 1, Structs.array( - new BlockMission(UnitBlocks.daggerFactory), + Missions.blockRecipe(UnitBlocks.daggerFactory), + new UnitMission(UnitTypes.dagger), Missions.blockRecipe(UnitBlocks.commandCenter), new CommandMission(UnitCommand.retreat), new CommandMission(UnitCommand.attack), diff --git a/core/src/io/anuke/mindustry/maps/Sectors.java b/core/src/io/anuke/mindustry/maps/Sectors.java index d64f6cbbdd..d98061bb08 100644 --- a/core/src/io/anuke/mindustry/maps/Sectors.java +++ b/core/src/io/anuke/mindustry/maps/Sectors.java @@ -3,8 +3,8 @@ package io.anuke.mindustry.maps; 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 com.badlogic.gdx.utils.Json; import io.anuke.mindustry.content.Items; import io.anuke.mindustry.core.GameState.State; import io.anuke.mindustry.entities.units.BaseUnit; @@ -13,29 +13,28 @@ import io.anuke.mindustry.game.Team; import io.anuke.mindustry.io.SaveIO; import io.anuke.mindustry.maps.SectorPresets.SectorPreset; import io.anuke.mindustry.maps.generation.WorldGenerator.GenResult; +import io.anuke.mindustry.maps.missions.BlockMission; import io.anuke.mindustry.maps.missions.Mission; -import io.anuke.mindustry.maps.missions.WaveMission; import io.anuke.mindustry.type.Item; import io.anuke.mindustry.type.ItemStack; +import io.anuke.mindustry.type.Recipe; import io.anuke.mindustry.world.ColorMapper; import io.anuke.mindustry.world.Tile; import io.anuke.ucore.core.Settings; import io.anuke.ucore.entities.Entities; import io.anuke.ucore.entities.EntityGroup; import io.anuke.ucore.entities.trait.Entity; -import io.anuke.ucore.util.Bits; -import io.anuke.ucore.util.GridMap; -import io.anuke.ucore.util.Log; -import io.anuke.ucore.util.Mathf; +import io.anuke.ucore.util.*; import static io.anuke.mindustry.Vars.*; public class Sectors{ private static final int sectorImageSize = 32; - private static final boolean checkExpansion = false; + private static final boolean checkExpansion = true; private final GridMap grid = new GridMap<>(); private final SectorPresets presets = new SectorPresets(); + private final Array allOres = Array.with(Items.copper, Items.lead, Items.coal, Items.titanium, Items.thorium); public void playSector(Sector sector){ if(sector.hasSave() && SaveIO.breakingVersions.contains(sector.getSave().getBuild())){ @@ -94,13 +93,6 @@ public class Sectors{ throw new IllegalArgumentException("Sector is not being played in!"); } - //remove old sector data to clear things up - for(int x = sector.x; x < sector.x+sector.width; x++){ - for(int y = sector.y; y < sector.y+sector.height; y++){ - grid.put(x, y, null); - } - } - if(expandX < 0) sector.x += expandX; if(expandY < 0) sector.y += expandY; @@ -110,8 +102,9 @@ public class Sectors{ if(checkExpansion) { for (int x = sector.x; x < sector.x + sector.width; x++) { for (int y = sector.y; y < sector.y + sector.height; y++) { - if (grid.get(x, y) != null && grid.get(x, y).complete) { + if (grid.get(x, y) != null && (grid.get(x, y).hasSave() /*|| !canMerge(sector, grid.get(x, y))*/)) { //if a completed sector is hit, expansion failed + //put back the values of the sector if (expandX < 0) sector.x -= expandX; if (expandY < 0) sector.y -= expandY; sector.width -= Math.abs(expandX); @@ -191,6 +184,28 @@ public class Sectors{ return true; } + /* + private boolean canMerge(Sector s1, Sector s2){ + int minx = Math.min(s1.x, s2.x); + int miny = Math.min(s1.y, s2.y); + + int maxx = Math.max(s1.x + s1.width, s2.x + s2.width); + int maxy = Math.max(s1.y + s1.height, s2.y + s2.height); + + + }*/ + + /**Returns whether a sector of this size and position can be fit here.*/ + public boolean canFit(int x, int y, int width, int height){ + for(int cx = x; cx < x + width; cx++){ + for(int cy = y; cy < y + height; cy++){ + if(grid.get(cx, cy) != null){ + return false; + } + } + } + return true; + } public Difficulty getDifficulty(Sector sector){ if(sector.difficulty == 0){ @@ -207,7 +222,7 @@ public class Sectors{ } public Array getOres(int x, int y){ - return presets.getOres(x, y) == null ? Array.with(Items.copper) : presets.getOres(x, y); + return presets.getOres(x, y) == null ? allOres : presets.getOres(x, y); } /**Unlocks a sector. This shows nearby sectors.*/ @@ -296,7 +311,7 @@ public class Sectors{ sector.x = (short)p.x; sector.y = (short)p.y; }else{ - genMissions(sector); + generate(sector); } sector.spawns = new Array<>(); @@ -314,15 +329,65 @@ public class Sectors{ sector.startingItems = Array.with(new ItemStack(Items.copper, 950), new ItemStack(Items.lead, 300), new ItemStack(Items.densealloy, 190), new ItemStack(Items.silicon, 140)); }else if(sector.difficulty > 3){ //now with carbide sector.startingItems = Array.with(new ItemStack(Items.copper, 700), new ItemStack(Items.lead, 200), new ItemStack(Items.densealloy, 130)); - }else if(sector.difficulty > 1){ //more starter items for faster start + }else if(sector.difficulty > 2){ //more starter items for faster start sector.startingItems = Array.with(new ItemStack(Items.copper, 400), new ItemStack(Items.lead, 100)); }else{ //empty default sector.startingItems = Array.with(); } } - private void genMissions(Sector sector){ - sector.missions.add(new WaveMission(sector.difficulty*5 + Mathf.randomSeed(sector.getSeed(), 0, 3)*5)); + private void generate(Sector sector){ + int width = Mathf.randomSeed(sector.getSeed()+1, 1, 3); + int height = Mathf.randomSeed(sector.getSeed()+2, 1, 3); + int finalWidth = 1, finalHeight = 1; + int finalX = sector.x, finalY = sector.y; + + for(int x = 1; x <= width; x++){ + for(int y = 1; y <= height; y++){ + for(GridPoint2 point : Geometry.d8edge){ + int shiftx = (int)(-width/2f + (point.x * (width - 1))/2f), shifty = (int)(-height/2f + (point.y * (height - 1))/2f); + if(canFit(sector.x + shiftx, sector.y + shifty, x, y)){ + finalWidth = x; + finalHeight = y; + finalX = sector.x + shiftx; + finalY = sector.y + shifty; + } + } + } + } + + sector.width = finalWidth; + sector.height = finalHeight; + sector.x = (short)finalX; + sector.y = (short)finalY; + + //int missions = Math.max((int)(Math.log10(sector.difficulty/3.0) * 5), 1); + + //for(int i = 0; i < missions; i++){ + + //} + + if(!headless/* && Mathf.randomSeed(sector.getSeed() + 3) < 0.5*/){ + //build list of locked recipes to add mission for obtaining it + Array recipes = new Array<>(); + for(Recipe r : content.recipes()){ + if(!control.unlocks.isUnlocked(r)){ + recipes.add(r); + } + } + + if(recipes.size > 0){ + Recipe recipe = recipes.random(); + sector.missions.add(new BlockMission(recipe.result)); + } + } + + if(Mathf.randomSeed(sector.getSeed() + 4) < 0.5){ + + } + + //sector.missions.add(new ExpandMission()); + //sector.missions.add(new WaveMission(sector.difficulty*5 + Mathf.randomSeed(sector.getSeed(), 0, 3)*5)); } private void createTexture(Sector sector){ diff --git a/core/src/io/anuke/mindustry/maps/missions/ExpandMission.java b/core/src/io/anuke/mindustry/maps/missions/ExpandMission.java index 660064ff4c..331325122e 100644 --- a/core/src/io/anuke/mindustry/maps/missions/ExpandMission.java +++ b/core/src/io/anuke/mindustry/maps/missions/ExpandMission.java @@ -5,8 +5,12 @@ import static io.anuke.mindustry.Vars.*; /**An action mission which simply expands the sector.*/ public class ExpandMission extends ActionMission{ private boolean done = false; + private final int expandX, expandY; public ExpandMission(int expandX, int expandY){ + this.expandX = expandX; + this.expandY = expandY; + runner = () -> { if(headless){ world.sectors().expandSector(world.getSector(), expandX, expandY); @@ -34,4 +38,12 @@ public class ExpandMission extends ActionMission{ public void onComplete(){ done = false; } + + public int getExpandX(){ + return expandX; + } + + public int getExpandY(){ + return expandY; + } } diff --git a/core/src/io/anuke/mindustry/ui/dialogs/LanguageDialog.java b/core/src/io/anuke/mindustry/ui/dialogs/LanguageDialog.java index 1c50fcc6a9..6a9f247522 100644 --- a/core/src/io/anuke/mindustry/ui/dialogs/LanguageDialog.java +++ b/core/src/io/anuke/mindustry/ui/dialogs/LanguageDialog.java @@ -14,6 +14,7 @@ import static io.anuke.mindustry.Vars.locales; import static io.anuke.mindustry.Vars.ui; public class LanguageDialog extends FloatingDialog{ + private Locale lastLocale; public LanguageDialog(){ super("$text.settings.language"); @@ -31,19 +32,37 @@ public class LanguageDialog extends FloatingDialog{ for(Locale loc : locales){ TextButton button = new TextButton(Platform.instance.getLocaleName(loc), "toggle"); - button.setChecked(ui.getLocale().equals(loc)); + button.setChecked(getLocale().equals(loc)); button.clicked(() -> { - if(ui.getLocale().equals(loc)) return; + if(getLocale().equals(loc)) return; Settings.putString("locale", loc.toString()); Settings.save(); Log.info("Setting locale: {0}", loc.toString()); ui.showInfo("$text.language.restart"); }); langs.add(button).group(group).update(t -> { - t.setChecked(loc.equals(ui.getLocale())); + t.setChecked(loc.equals(getLocale())); }).size(400f, 60f).row(); } content().add(pane); } + + public Locale getLocale(){ + String loc = Settings.getString("locale"); + if(loc.equals("default")){ + return Locale.getDefault(); + }else{ + if(lastLocale == null || !lastLocale.toString().equals(loc)){ + if(loc.contains("_")){ + String[] split = loc.split("_"); + lastLocale = new Locale(split[0], split[1]); + }else{ + lastLocale = new Locale(loc); + } + } + + return lastLocale; + } + } }