From 86a6ec6bd2c031f32c04bc9c9d99b422b9cb8ac4 Mon Sep 17 00:00:00 2001 From: Anuken Date: Sat, 11 Dec 2021 16:23:42 -0500 Subject: [PATCH] Editor crash fix --- core/src/mindustry/editor/EditorTile.java | 9 +++ core/src/mindustry/graphics/Drawf.java | 7 ++ .../maps/planet/ErekirPlanetGenerator.java | 2 +- core/src/mindustry/world/Tile.java | 6 +- .../world/blocks/units/UnitAssembler.java | 80 +++++++++++++++++++ 5 files changed, 100 insertions(+), 4 deletions(-) create mode 100644 core/src/mindustry/world/blocks/units/UnitAssembler.java diff --git a/core/src/mindustry/editor/EditorTile.java b/core/src/mindustry/editor/EditorTile.java index 69b00f3495..146f1427f5 100644 --- a/core/src/mindustry/editor/EditorTile.java +++ b/core/src/mindustry/editor/EditorTile.java @@ -102,6 +102,15 @@ public class EditorTile extends Tile{ } } + @Override + protected void firePreChanged(){ + if(skip()){ + super.firePreChanged(); + }else{ + update(); + } + } + @Override public void recache(){ if(skip()){ diff --git a/core/src/mindustry/graphics/Drawf.java b/core/src/mindustry/graphics/Drawf.java index ff909a329f..2d926685fc 100644 --- a/core/src/mindustry/graphics/Drawf.java +++ b/core/src/mindustry/graphics/Drawf.java @@ -82,6 +82,13 @@ public class Drawf{ Draw.reset(); } + public static void dashRect(Color color, Rect rect){ + dashLine(color, rect.x, rect.y, rect.x + rect.width, rect.y); + dashLine(color, rect.x, rect.y, rect.x, rect.y + rect.height); + dashLine(color, rect.x + rect.width, rect.y, rect.x + rect.width, rect.y + rect.height); + dashLine(color, rect.x, rect.y + rect.height, rect.x + rect.width, rect.y + rect.height); + } + public static void target(float x, float y, float rad, Color color){ target(x, y, rad, 1, color); } diff --git a/core/src/mindustry/maps/planet/ErekirPlanetGenerator.java b/core/src/mindustry/maps/planet/ErekirPlanetGenerator.java index 4f3a229ead..9077e86cac 100644 --- a/core/src/mindustry/maps/planet/ErekirPlanetGenerator.java +++ b/core/src/mindustry/maps/planet/ErekirPlanetGenerator.java @@ -92,7 +92,7 @@ public class ErekirPlanetGenerator extends PlanetGenerator{ tile.block = tile.floor.asFloor().wall; - if(Ridged.noise3d(1, position.x, position.y, position.z, 2, 14) > 0.15){ + if(Ridged.noise3d(1, position.x, position.y, position.z, 2, 14) > 0.14){ tile.block = Blocks.air; } diff --git a/core/src/mindustry/world/Tile.java b/core/src/mindustry/world/Tile.java index 4d6652635d..267a0290cd 100644 --- a/core/src/mindustry/world/Tile.java +++ b/core/src/mindustry/world/Tile.java @@ -532,7 +532,7 @@ public class Tile implements Position, QuadTreeObject, Displayable{ } protected void preChanged(){ - firePreChange(); + firePreChanged(); if(build != null){ //only call removed() for the center block - this only gets called once. @@ -552,7 +552,7 @@ public class Tile implements Position, QuadTreeObject, Displayable{ //reset entity and block *manually* - thus, preChanged() will not be called anywhere else, for multiblocks if(other != this){ //do not remove own entity so it can be processed in changed() //manually call pre-change event for other tile - other.firePreChange(); + other.firePreChanged(); other.build = null; other.block = Blocks.air; @@ -634,7 +634,7 @@ public class Tile implements Position, QuadTreeObject, Displayable{ } } - protected void firePreChange(){ + protected void firePreChanged(){ if(!world.isGenerating()){ //same as above diff --git a/core/src/mindustry/world/blocks/units/UnitAssembler.java b/core/src/mindustry/world/blocks/units/UnitAssembler.java new file mode 100644 index 0000000000..4b5b915ac2 --- /dev/null +++ b/core/src/mindustry/world/blocks/units/UnitAssembler.java @@ -0,0 +1,80 @@ +package mindustry.world.blocks.units; + +import arc.math.geom.*; +import arc.struct.*; +import arc.util.*; +import mindustry.content.*; +import mindustry.gen.*; +import mindustry.graphics.*; +import mindustry.type.*; +import mindustry.world.blocks.payloads.*; + +import static mindustry.Vars.*; + +/** + * Steps: + * 0. place the assembler with the rectangle indicating build area + * 1. wait for power/consValid + * 2. print / create the 3-5 drones for free, make sure they're tethered - build speed depends on drone active fraction + * 3. + * */ +public class UnitAssembler extends PayloadBlock{ + public int areaSize = 10; + public UnitType unitType; + public int unitsCreated = 4; + + public UnitAssembler(String name){ + super(name); + update = solid = true; + rotate = true; + rotateDraw = false; + } + + @Override + public void drawPlace(int x, int y, int rotation, boolean valid){ + super.drawPlace(x, y, rotation, valid); + + x *= tilesize; + y *= tilesize; + + Tmp.r1.setCentered(x, y, areaSize * tilesize); + float len = tilesize * (areaSize + size)/2f; + + Tmp.r1.x += Geometry.d4x(rotation) * len; + Tmp.r1.y += Geometry.d4y(rotation) * len; + + //TODO better visuals here? + Drawf.dashRect(valid ? Pal.accent : Pal.remove, Tmp.r1); + } + + public class UnitAssemblerBuild extends PayloadBlockBuild{ + public Seq units = new Seq<>(); + public Seq payloads = new Seq<>(); + + @Override + public void updateTile(){ + units.removeAll(u -> !u.isAdded() || u.dead); + + if(consValid() && units.size < unitsCreated){ + //TODO build animation? distribute spawning? + var unit = unitType.create(team); + if(unit instanceof BuildingTetherc bt){ + bt.building(this); + } + unit.set(x, y); + unit.rotation = 90f; + unit.add(); + + Fx.spawn.at(unit); + units.add(unit); + } + + //TODO drones need to indicate that they are in position + } + + @Override + public boolean acceptPayload(Building source, Payload payload){ + return super.acceptPayload(source, payload); + } + } +}