diff --git a/core/assets-raw/sprites/blocks/distribution/payload-router-icon.png b/core/assets-raw/sprites/blocks/distribution/payload-router-icon.png index e83d1b521a..9d40f86518 100644 Binary files a/core/assets-raw/sprites/blocks/distribution/payload-router-icon.png and b/core/assets-raw/sprites/blocks/distribution/payload-router-icon.png differ diff --git a/core/assets-raw/sprites/blocks/power/thorium-reactor-center.png b/core/assets-raw/sprites/blocks/power/thorium-reactor-top.png similarity index 100% rename from core/assets-raw/sprites/blocks/power/thorium-reactor-center.png rename to core/assets-raw/sprites/blocks/power/thorium-reactor-top.png diff --git a/core/assets/sprites/block_colors.png b/core/assets/sprites/block_colors.png index bc6c7d05b5..ab5acb7eef 100644 Binary files a/core/assets/sprites/block_colors.png and b/core/assets/sprites/block_colors.png differ diff --git a/core/assets/sprites/sprites.atlas b/core/assets/sprites/sprites.atlas index f6eb6fe60b..1d74c85805 100644 --- a/core/assets/sprites/sprites.atlas +++ b/core/assets/sprites/sprites.atlas @@ -1516,14 +1516,14 @@ thorium-reactor orig: 96, 96 offset: 0, 0 index: -1 -thorium-reactor-center +thorium-reactor-lights rotate: false xy: 1901, 1301 size: 96, 96 orig: 96, 96 offset: 0, 0 index: -1 -thorium-reactor-lights +thorium-reactor-top rotate: false xy: 900, 1203 size: 96, 96 diff --git a/core/assets/sprites/sprites.png b/core/assets/sprites/sprites.png index 3037ff3098..1c082ec126 100644 Binary files a/core/assets/sprites/sprites.png and b/core/assets/sprites/sprites.png differ diff --git a/core/assets/sprites/sprites2.png b/core/assets/sprites/sprites2.png index a278097a29..a0722a5194 100644 Binary files a/core/assets/sprites/sprites2.png and b/core/assets/sprites/sprites2.png differ diff --git a/core/assets/sprites/sprites4.png b/core/assets/sprites/sprites4.png index 35a96cd79e..4155fc847d 100644 Binary files a/core/assets/sprites/sprites4.png and b/core/assets/sprites/sprites4.png differ diff --git a/core/assets/sprites/sprites5.png b/core/assets/sprites/sprites5.png index 72d8f55eb1..da7426dfc2 100644 Binary files a/core/assets/sprites/sprites5.png and b/core/assets/sprites/sprites5.png differ diff --git a/core/src/mindustry/game/Schematics.java b/core/src/mindustry/game/Schematics.java index 7c1374dad0..0ecb7ab20e 100644 --- a/core/src/mindustry/game/Schematics.java +++ b/core/src/mindustry/game/Schematics.java @@ -393,6 +393,22 @@ public class Schematics implements Loadable{ }); } + public static void place(Schematic schem, int x, int y, Team team){ + int ox = x - schem.width/2, oy = y - schem.height/2; + schem.tiles.each(st -> { + Tile tile = world.tile(st.x + ox, st.y + oy); + if(tile == null) return; + + tile.setBlock(st.block, team, 0); + tile.rotation(st.rotation); + + Object config = st.config; + if(tile.entity != null){ + tile.entity.configureAny(config); + } + }); + } + //region IO methods /** Loads a schematic from base64. May throw an exception. */ diff --git a/core/src/mindustry/io/SaveFileReader.java b/core/src/mindustry/io/SaveFileReader.java index 9478d54bd9..16938dc869 100644 --- a/core/src/mindustry/io/SaveFileReader.java +++ b/core/src/mindustry/io/SaveFileReader.java @@ -88,8 +88,8 @@ public abstract class SaveFileReader{ } /** Reads a chunk of some length. Use the runner for reading to catch more descriptive errors. */ - public int readChunk(DataInput input, boolean isByte, IORunner runner) throws IOException{ - int length = isByte ? input.readUnsignedShort() : input.readInt(); + public int readChunk(DataInput input, boolean isShort, IORunner runner) throws IOException{ + int length = isShort ? input.readUnsignedShort() : input.readInt(); runner.accept(input); return length; } diff --git a/core/src/mindustry/io/SaveVersion.java b/core/src/mindustry/io/SaveVersion.java index 05c5425df1..4f81cd903c 100644 --- a/core/src/mindustry/io/SaveVersion.java +++ b/core/src/mindustry/io/SaveVersion.java @@ -152,6 +152,9 @@ public abstract class SaveVersion extends SaveFileReader{ Tile tile = world.rawTile(i % world.width(), i / world.width()); stream.writeShort(tile.blockID()); + //make note of whether there was an entity here + stream.writeBoolean(tile.entity != null); + //only write the entity for multiblocks once - in the center if(tile.entity != null){ if(tile.isCenter()){ @@ -218,8 +221,9 @@ public abstract class SaveVersion extends SaveFileReader{ Tile tile = context.tile(i); if(block == null) block = Blocks.air; boolean isCenter = true; + boolean hadEntity = stream.readBoolean(); - if(block.hasEntity()){ + if(hadEntity){ isCenter = stream.readBoolean(); } @@ -228,15 +232,20 @@ public abstract class SaveVersion extends SaveFileReader{ tile.setBlock(block); } - if(block.hasEntity()){ + if(hadEntity){ if(isCenter){ //only read entity for center blocks - try{ - readChunk(stream, true, in -> { - byte revision = in.readByte(); - tile.entity.readAll(Reads.get(in), revision); - }); - }catch(Throwable e){ - throw new IOException("Failed to read tile entity of block: " + block, e); + if(block.hasEntity()){ + try{ + readChunk(stream, true, in -> { + byte revision = in.readByte(); + tile.entity.readAll(Reads.get(in), revision); + }); + }catch(Throwable e){ + throw new IOException("Failed to read tile entity of block: " + block, e); + } + }else{ + //skip the entity region, as the entity and its IO code are now gone + skipRegion(stream, true); } } }else{ diff --git a/core/src/mindustry/maps/generators/BaseGenerator.java b/core/src/mindustry/maps/generators/BaseGenerator.java index bc03f9d50e..da56c3117d 100644 --- a/core/src/mindustry/maps/generators/BaseGenerator.java +++ b/core/src/mindustry/maps/generators/BaseGenerator.java @@ -1,13 +1,78 @@ package mindustry.maps.generators; +import arc.*; +import arc.math.*; import arc.struct.*; +import arc.util.*; +import mindustry.*; +import mindustry.content.*; import mindustry.game.*; import mindustry.type.*; import mindustry.world.*; +import mindustry.world.blocks.defense.turrets.*; +import mindustry.world.blocks.defense.turrets.ItemTurret.*; +import mindustry.world.blocks.environment.*; + +import java.io.*; public class BaseGenerator{ + static Array schematics = new Array<>(); public void generate(Tiles tiles, Array cores, Tile spawn, Team team, Sector sector){ + for(Tile tile : cores){ + tile.clearOverlay(); + tile.setBlock(Blocks.coreShard, team); + } + + //TODO remove this, it's just a test + if(!Core.files.external("SCHEMATICOUTPUT").exists()){ + Log.err("no schematics"); + return; + } + + if(schematics.isEmpty()){ + schematics.addAll(Array.with(Core.files.external("SCHEMATICOUTPUT").list()).map(s -> { + try{ + return Schematics.read(s); + }catch(IOException e){ + throw new RuntimeException(); + } + })); + } + + Vars.state.rules.enemyCheat = true; + + int range = 180; + int attempts = 3000; + int cx = cores.first().x, cy = cores.first().y; + + outer: + for(int i = 0; i < attempts; i++){ + Tmp.v1.rnd(Mathf.random(range)); + int x = (int)(cx + Tmp.v1.x), y = (int)(cy + Tmp.v1.y); + + Schematic res = schematics.random(); + int ex = x - res.width/2, ey = y - res.height/2; + + for(int rx = ex; rx <= ex + res.width; rx++){ + for(int ry = ey; ry <= ey + res.height; ry++){ + Tile tile = tiles.get(rx, ry); + if(tile == null || Vars.world.getDarkness(rx, ry) > 0 || tile.floor().isDeep() || (!tile.block().isAir() && !(tile.block() instanceof Rock && tile.block().destructible))) continue outer; + } + } + + Schematics.place(res, x, y, team); + + //add ammo + for(int rx = ex; rx <= ex + res.width; rx++){ + for(int ry = ey; ry <= ey + res.height; ry++){ + Tile tile = tiles.get(rx, ry); + if(tile != null && tile.entity instanceof ItemTurretEntity){ + tile.entity.handleItem(tile.entity, ((ItemTurret)tile.block()).ammoTypes.keys().toArray().first()); + } + } + } + } } }