From ad45bebbdc66d1ad66a600475c42cb7ba64b2c47 Mon Sep 17 00:00:00 2001 From: Anuken Date: Sun, 22 Mar 2020 09:28:55 -0400 Subject: [PATCH] Better spawn selection --- core/src/mindustry/ai/WaveSpawner.java | 2 +- core/src/mindustry/content/Blocks.java | 3 +- core/src/mindustry/content/Fx.java | 7 ++-- core/src/mindustry/core/Control.java | 2 +- core/src/mindustry/input/InputHandler.java | 30 ++++++-------- .../maps/planet/TestPlanetGenerator.java | 40 +++++++++++++++---- core/src/mindustry/type/Planet.java | 3 +- 7 files changed, 56 insertions(+), 31 deletions(-) diff --git a/core/src/mindustry/ai/WaveSpawner.java b/core/src/mindustry/ai/WaveSpawner.java index 927f00f126..f30fbadefb 100644 --- a/core/src/mindustry/ai/WaveSpawner.java +++ b/core/src/mindustry/ai/WaveSpawner.java @@ -97,7 +97,7 @@ public class WaveSpawner{ for(Tile tile : spawns){ float angle = Angles.angle(tile.x, tile.y, world.width()/2, world.height()/2); - float trns = (world.width() + world.height()) * tilesize; + float trns = Math.max(world.width(), world.height()) * Mathf.sqrt2 * tilesize; float spawnX = Mathf.clamp(world.width() * tilesize / 2f + Angles.trnsx(angle, trns), -margin, world.width() * tilesize + margin); float spawnY = Mathf.clamp(world.height() * tilesize / 2f + Angles.trnsy(angle, trns), -margin, world.height() * tilesize + margin); cons.get(spawnX, spawnY); diff --git a/core/src/mindustry/content/Blocks.java b/core/src/mindustry/content/Blocks.java index 4c5359cda6..0554a22f7e 100644 --- a/core/src/mindustry/content/Blocks.java +++ b/core/src/mindustry/content/Blocks.java @@ -112,7 +112,8 @@ public class Blocks implements ContentList{ { variants = 0; } - public void draw(){} + @Override + public void drawBase(Tile tile){} }; cliff = new Cliff("cliff"); diff --git a/core/src/mindustry/content/Fx.java b/core/src/mindustry/content/Fx.java index 22436c5154..ae0577907f 100644 --- a/core/src/mindustry/content/Fx.java +++ b/core/src/mindustry/content/Fx.java @@ -42,12 +42,13 @@ public class Fx{ Tmp.v1.set(e.x, e.y).interpolate(Tmp.v2.set(to), e.fin(), Interpolation.pow3) .add(Tmp.v2.sub(e.x, e.y).nor().rotate90(1).scl(Mathf.randomSeedRange(e.id, 1f) * e.fslope() * 10f)); float x = Tmp.v1.x, y = Tmp.v1.y; + float size = Math.min(0.8f + e.rotation / 5f, 2); - stroke(e.fslope() * 2f, Pal.accent); - Lines.circle(x, y, e.fslope() * 2f); + stroke(e.fslope() * 2f * size, Pal.accent); + Lines.circle(x, y, e.fslope() * 2f * size); color(e.color); - Fill.circle(x, y, e.fslope() * 1.5f); + Fill.circle(x, y, e.fslope() * 1.5f * size); }), lightning = new Effect(10f, 500f, e -> { diff --git a/core/src/mindustry/core/Control.java b/core/src/mindustry/core/Control.java index d9ab6bb7e7..1cf4562ac0 100644 --- a/core/src/mindustry/core/Control.java +++ b/core/src/mindustry/core/Control.java @@ -251,7 +251,7 @@ public class Control implements ApplicationListener, Loadable{ ui.planet.hide(); SaveSlot slot = sector.save; //TODO comment for new sector states - //slot = null; + slot = null; if(slot != null){ try{ net.reset(); diff --git a/core/src/mindustry/input/InputHandler.java b/core/src/mindustry/input/InputHandler.java index 204f81b257..d3f5170e89 100644 --- a/core/src/mindustry/input/InputHandler.java +++ b/core/src/mindustry/input/InputHandler.java @@ -69,26 +69,26 @@ public abstract class InputHandler implements InputProcessor, GestureListener{ @Remote(called = Loc.server, unreliable = true) public static void transferItemEffect(Item item, float x, float y, Itemsc to){ if(to == null) return; - createItemTransfer(item, x, y, to, null); + createItemTransfer(item, 1, x, y, to, null); } @Remote(called = Loc.server, unreliable = true) public static void transferItemToUnit(Item item, float x, float y, Itemsc to){ if(to == null) return; - createItemTransfer(item, x, y, to, () -> to.addItem(item)); + createItemTransfer(item, 1, x, y, to, () -> to.addItem(item)); } @Remote(called = Loc.server, unreliable = true) public static void transferItemTo(Item item, int amount, float x, float y, Tile tile){ if(tile == null || tile.entity == null || tile.entity.items() == null) return; for(int i = 0; i < Mathf.clamp(amount / 3, 1, 8); i++){ - Time.run(i * 3, () -> createItemTransfer(item, x, y, tile, () -> {})); + Time.run(i * 3, () -> createItemTransfer(item, amount, x, y, tile, () -> {})); } tile.entity.items().add(item, amount); } - public static void createItemTransfer(Item item, float x, float y, Position to, Runnable done){ - Fx.itemTransfer.at(x, y, 0, item.color, to); + public static void createItemTransfer(Item item, int amount, float x, float y, Position to, Runnable done){ + Fx.itemTransfer.at(x, y, amount, item.color, to); if(done != null){ Time.run(Fx.itemTransfer.lifetime, done); } @@ -137,21 +137,17 @@ public abstract class InputHandler implements InputProcessor, GestureListener{ int accepted = tile.acceptStack(item, amount, player.unit()); player.unit().stack().amount -= accepted; - int sent = Mathf.clamp(accepted / 4, 1, 8); - Block block = tile.block(); - Core.app.post(() -> Events.fire(new DepositEvent(tile, player, item, accepted))); - for(int i = 0; i < sent; i++){ - tile.getStackOffset(item, stackTrns); + tile.getStackOffset(item, stackTrns); - createItemTransfer(item, player.x() + Angles.trnsx(player.unit().rotation() + 180f, backTrns), player.y() + Angles.trnsy(player.unit().rotation() + 180f, backTrns), - new Vec2(tile.x() + stackTrns.x, tile.y() + stackTrns.y), () -> { - if(tile.block() != block || !tile.isValid() || tile.items() == null) return; - - tile.handleStack(item, accepted, player.unit()); - }); - } + createItemTransfer( + item, + amount, + player.x() + Angles.trnsx(player.unit().rotation() + 180f, backTrns), player.y() + Angles.trnsy(player.unit().rotation() + 180f, backTrns), + new Vec2(tile.x() + stackTrns.x, tile.y() + stackTrns.y), + () -> tile.handleStack(item, accepted, player.unit()) + ); } @Remote(targets = Loc.both, called = Loc.server, forward = true) diff --git a/core/src/mindustry/maps/planet/TestPlanetGenerator.java b/core/src/mindustry/maps/planet/TestPlanetGenerator.java index c7be060cc7..f8bff4ba0b 100644 --- a/core/src/mindustry/maps/planet/TestPlanetGenerator.java +++ b/core/src/mindustry/maps/planet/TestPlanetGenerator.java @@ -125,7 +125,7 @@ public class TestPlanetGenerator extends PlanetGenerator{ float constraint = 1.3f; float radius = width / 2f / Mathf.sqrt3; - int rooms = rand.random(2, 5); + int rooms = rand.random(2, 5)/* - 1*/; Array array = new Array<>(); for(int i = 0; i < rooms; i++){ @@ -137,12 +137,40 @@ public class TestPlanetGenerator extends PlanetGenerator{ array.add(new Room((int)rx, (int)ry, (int)rrad)); } + //check positions on the map to place the player spawn. this needs to be in the corner of the map + Room spawn = null; + int offset = rand.nextInt(360); + float length = width/2.55f - rand.random(13, 23); + int angleStep = 5; + int waterCheckRad = 5; + for(int i = 0; i < 360; i+= angleStep){ + int angle = offset + i; + int cx = (int)(width/2 + Angles.trnsx(angle, length)); + int cy = (int)(height/2 + Angles.trnsy(angle, length)); + + int waterTiles = 0; + + //check for water presence + for(int rx = -waterCheckRad; rx <= waterCheckRad; rx++){ + for(int ry = -waterCheckRad; ry <= waterCheckRad; ry++){ + Tile tile = tiles.get(cx + rx, cy + ry); + if(tile == null || tile.floor().liquidDrop != null){ + waterTiles ++; + } + } + } + + if(waterTiles <= 4 || (i + angleStep >= 360)){ + array.add(spawn = new Room(cx, cy, rand.random(8, 15))); + break; + } + } + for(Room room : array){ erase(room.x, room.y, room.radius); } int connections = rand.random(Math.max(rooms - 1, 1), rooms + 3); - Room spawn = array.random(rand); for(int i = 0; i < connections; i++){ array.random(rand).connect(array.random(rand)); } @@ -158,11 +186,9 @@ public class TestPlanetGenerator extends PlanetGenerator{ ores(ores); - for(Room other : array){ - if(other != spawn){ - // tiles.getn(other.x, other.y).setOverlay(Blocks.spawn); - } - } + Room target = spawn; + Room furthest = array.max(r -> Mathf.dst(r.x, r.y, target.x, target.y)); + tiles.getn(furthest.x, furthest.y).setOverlay(Blocks.spawn); trimDark(); diff --git a/core/src/mindustry/type/Planet.java b/core/src/mindustry/type/Planet.java index e058ede455..42c4abc293 100644 --- a/core/src/mindustry/type/Planet.java +++ b/core/src/mindustry/type/Planet.java @@ -89,7 +89,8 @@ public class Planet extends UnlockableContent{ } } - sectors.get(sectors.size/2).unlocked = true; + //for now + sectors.each(s -> s.unlocked = true); }else{ sectors = new Array<>(); }