Made save format support removed blocks
|
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1000 B |
|
Before Width: | Height: | Size: 779 B After Width: | Height: | Size: 779 B |
|
Before Width: | Height: | Size: 760 B After Width: | Height: | Size: 759 B |
@@ -1516,14 +1516,14 @@ thorium-reactor
|
|||||||
orig: 96, 96
|
orig: 96, 96
|
||||||
offset: 0, 0
|
offset: 0, 0
|
||||||
index: -1
|
index: -1
|
||||||
thorium-reactor-center
|
thorium-reactor-lights
|
||||||
rotate: false
|
rotate: false
|
||||||
xy: 1901, 1301
|
xy: 1901, 1301
|
||||||
size: 96, 96
|
size: 96, 96
|
||||||
orig: 96, 96
|
orig: 96, 96
|
||||||
offset: 0, 0
|
offset: 0, 0
|
||||||
index: -1
|
index: -1
|
||||||
thorium-reactor-lights
|
thorium-reactor-top
|
||||||
rotate: false
|
rotate: false
|
||||||
xy: 900, 1203
|
xy: 900, 1203
|
||||||
size: 96, 96
|
size: 96, 96
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 845 KiB After Width: | Height: | Size: 845 KiB |
|
Before Width: | Height: | Size: 126 KiB After Width: | Height: | Size: 125 KiB |
|
Before Width: | Height: | Size: 279 KiB After Width: | Height: | Size: 279 KiB |
|
Before Width: | Height: | Size: 916 KiB After Width: | Height: | Size: 914 KiB |
@@ -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
|
//region IO methods
|
||||||
|
|
||||||
/** Loads a schematic from base64. May throw an exception. */
|
/** Loads a schematic from base64. May throw an exception. */
|
||||||
|
|||||||
@@ -88,8 +88,8 @@ public abstract class SaveFileReader{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Reads a chunk of some length. Use the runner for reading to catch more descriptive errors. */
|
/** Reads a chunk of some length. Use the runner for reading to catch more descriptive errors. */
|
||||||
public int readChunk(DataInput input, boolean isByte, IORunner<DataInput> runner) throws IOException{
|
public int readChunk(DataInput input, boolean isShort, IORunner<DataInput> runner) throws IOException{
|
||||||
int length = isByte ? input.readUnsignedShort() : input.readInt();
|
int length = isShort ? input.readUnsignedShort() : input.readInt();
|
||||||
runner.accept(input);
|
runner.accept(input);
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -152,6 +152,9 @@ public abstract class SaveVersion extends SaveFileReader{
|
|||||||
Tile tile = world.rawTile(i % world.width(), i / world.width());
|
Tile tile = world.rawTile(i % world.width(), i / world.width());
|
||||||
stream.writeShort(tile.blockID());
|
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
|
//only write the entity for multiblocks once - in the center
|
||||||
if(tile.entity != null){
|
if(tile.entity != null){
|
||||||
if(tile.isCenter()){
|
if(tile.isCenter()){
|
||||||
@@ -218,8 +221,9 @@ public abstract class SaveVersion extends SaveFileReader{
|
|||||||
Tile tile = context.tile(i);
|
Tile tile = context.tile(i);
|
||||||
if(block == null) block = Blocks.air;
|
if(block == null) block = Blocks.air;
|
||||||
boolean isCenter = true;
|
boolean isCenter = true;
|
||||||
|
boolean hadEntity = stream.readBoolean();
|
||||||
|
|
||||||
if(block.hasEntity()){
|
if(hadEntity){
|
||||||
isCenter = stream.readBoolean();
|
isCenter = stream.readBoolean();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,15 +232,20 @@ public abstract class SaveVersion extends SaveFileReader{
|
|||||||
tile.setBlock(block);
|
tile.setBlock(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(block.hasEntity()){
|
if(hadEntity){
|
||||||
if(isCenter){ //only read entity for center blocks
|
if(isCenter){ //only read entity for center blocks
|
||||||
try{
|
if(block.hasEntity()){
|
||||||
readChunk(stream, true, in -> {
|
try{
|
||||||
byte revision = in.readByte();
|
readChunk(stream, true, in -> {
|
||||||
tile.entity.readAll(Reads.get(in), revision);
|
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);
|
}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{
|
}else{
|
||||||
|
|||||||
@@ -1,13 +1,78 @@
|
|||||||
package mindustry.maps.generators;
|
package mindustry.maps.generators;
|
||||||
|
|
||||||
|
import arc.*;
|
||||||
|
import arc.math.*;
|
||||||
import arc.struct.*;
|
import arc.struct.*;
|
||||||
|
import arc.util.*;
|
||||||
|
import mindustry.*;
|
||||||
|
import mindustry.content.*;
|
||||||
import mindustry.game.*;
|
import mindustry.game.*;
|
||||||
import mindustry.type.*;
|
import mindustry.type.*;
|
||||||
import mindustry.world.*;
|
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{
|
public class BaseGenerator{
|
||||||
|
static Array<Schematic> schematics = new Array<>();
|
||||||
|
|
||||||
public void generate(Tiles tiles, Array<Tile> cores, Tile spawn, Team team, Sector sector){
|
public void generate(Tiles tiles, Array<Tile> 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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||