diff --git a/core/assets/planets/TODO.dat b/core/assets/planets/TODO.dat index ecc370bc49..db308eedc8 100644 Binary files a/core/assets/planets/TODO.dat and b/core/assets/planets/TODO.dat differ diff --git a/core/src/mindustry/type/Planet.java b/core/src/mindustry/type/Planet.java index d12937a278..87732d411b 100644 --- a/core/src/mindustry/type/Planet.java +++ b/core/src/mindustry/type/Planet.java @@ -77,11 +77,15 @@ public class Planet extends UnlockableContent{ //read data for sectors Fi data = Vars.tree.get("planets/" + name + ".dat"); if(data.exists()){ - try(Reads read = data.reads()){ - short dsize = read.s(); - for(int i = 0; i < dsize; i++){ - sectors.get(i).data.read(read); + try{ + try(Reads read = data.reads()){ + short dsize = read.s(); + for(int i = 0; i < dsize; i++){ + sectors.get(i).data.read(read); + } } + }catch(Throwable t){ + t.printStackTrace(); } } }else{ diff --git a/core/src/mindustry/type/Sector.java b/core/src/mindustry/type/Sector.java index d8834228df..6affe16f97 100644 --- a/core/src/mindustry/type/Sector.java +++ b/core/src/mindustry/type/Sector.java @@ -1,8 +1,8 @@ package mindustry.type; import arc.math.geom.*; -import arc.util.*; import arc.util.ArcAnnotate.*; +import arc.util.*; import arc.util.io.*; import mindustry.*; import mindustry.ctype.*; @@ -34,6 +34,10 @@ public class Sector{ this.data = data; } + public boolean locked(){ + return true; + } + /** @return light dot product in the range [0, 1]. */ public float getLight(){ Vec3 normal = Tmp.v31.set(tile.v).rotate(Vec3.Y, -planet.getRotation()).nor(); @@ -87,6 +91,10 @@ public class Sector{ return new SectorRect(radius, center, planeTop, planeRight, angle); } + public boolean hasAttribute(SectorAttribute attribute){ + return (data.attributes & (1 << attribute.ordinal())) != 0; + } + public static class SectorRect{ public final Vec3 center, top, right; public final Vec3 result = new Vec3(); @@ -115,6 +123,7 @@ public class Sector{ public Block[] floors = {}; public int[] floorCounts = {}; + public int attributes; public void write(Writes write){ write.s(resources.length); @@ -129,6 +138,8 @@ public class Sector{ write.s(floors[i].id); write.i(floorCounts[i]); } + + write.i(attributes); } public void read(Reads read){ @@ -144,6 +155,12 @@ public class Sector{ floors[i] = Vars.content.block(read.s()); floorCounts[i] = read.i(); } + attributes = read.i(); } } + + public enum SectorAttribute{ + /** Requires naval technology to land on, e.g. mostly water */ + naval + } } diff --git a/core/src/mindustry/ui/dialogs/PlanetDialog.java b/core/src/mindustry/ui/dialogs/PlanetDialog.java index 945938cdd4..ed1fe67710 100644 --- a/core/src/mindustry/ui/dialogs/PlanetDialog.java +++ b/core/src/mindustry/ui/dialogs/PlanetDialog.java @@ -19,6 +19,7 @@ import mindustry.graphics.*; import mindustry.graphics.g3d.*; import mindustry.graphics.g3d.PlanetGrid.*; import mindustry.type.*; +import mindustry.type.Sector.*; import mindustry.ui.*; import static mindustry.Vars.*; @@ -30,7 +31,7 @@ public class PlanetDialog extends FloatingDialog{ borderColor = Pal.accent.cpy().a(0.3f), shadowColor = new Color(0, 0, 0, 0.7f); private static final float camLength = 4f; - float outlineRad = 1.15f; + float outlineRad = 1.16f; //the base planet that's being rendered private final Planet solarSystem = Planets.sun; @@ -59,7 +60,7 @@ public class PlanetDialog extends FloatingDialog{ buttons.addImageTextButton("$techtree", Icon.tree, () -> ui.tech.show()).size(230f, 64f); camRelative.set(0, 0f, camLength); - projector.setScaling(1f / 300f); + projector.setScaling(1f / 150f); update(() -> { Vec3 v = Tmp.v33.set(Core.input.mouseX(), Core.input.mouseY(), 0); @@ -95,7 +96,7 @@ public class PlanetDialog extends FloatingDialog{ addListener(new ElementGestureListener(){ @Override public void tap(InputEvent event, float x, float y, int count, KeyCode button){ - selected = hovered; + selected = hovered != null && hovered.locked() ? null : hovered; if(selected != null){ updateSelected(); } @@ -158,10 +159,15 @@ public class PlanetDialog extends FloatingDialog{ if(hovered != null){ Draw.batch(projector, () -> { setPlane(hovered); + Draw.color(Color.white, Pal.accent, Mathf.absin(5f, 1f)); - if(false){ //TODO locked check - Draw.rect(Icon.lock.getRegion(), 0, 0); + TextureRegion icon = hovered.locked() ? Icon.lock.getRegion() : hovered.hasAttribute(SectorAttribute.naval) ? Liquids.water.icon(Cicon.large) : null; + + if(icon != null){ + Draw.rect(icon, 0, 0); } + + Draw.reset(); }); } diff --git a/core/src/mindustry/world/blocks/logic/LogicExecutor.java b/core/src/mindustry/world/blocks/logic/LogicExecutor.java index ef7eac06ea..65b8b9599a 100644 --- a/core/src/mindustry/world/blocks/logic/LogicExecutor.java +++ b/core/src/mindustry/world/blocks/logic/LogicExecutor.java @@ -1,6 +1,7 @@ package mindustry.world.blocks.logic; import arc.math.*; +import mindustry.gen.*; public class LogicExecutor{ Instruction[] instructions; @@ -17,26 +18,69 @@ public class LogicExecutor{ if(counter >= instructions.length) counter = 0; } + Tilec device(short id){ + return null; //TODO + } + interface Instruction{ void exec(); } - class RegisterI{ + class RegisterI implements Instruction{ + /** operation to perform */ Op op; - short from, to; - int immediate; + /** destination register */ + short dest; + /** registers to take data from. -1 for no register. */ + short left, right; + /** left/right immediate values, only used if no registers are present. */ + int ileft, iright; + @Override public void exec(){ - registers[to] = op.function.get(registers[from], immediate); + registers[dest] = op.function.get(left == -1 ? ileft : registers[left], right == -1 ? iright : registers[right]); } } - static class ReadI{ + class ReadI implements Instruction{ + /** register to write result to */ + short dest; + /** device to read from */ + short device; + /** the type of data to be read */ + ReadOp op; + /** any additional read parameters */ + int parameter; + @Override + public void exec(){ + registers[dest] = op.function.get(device(device), parameter); + } } - static class WriteI{ + class WriteI implements Instruction{ + @Override + public void exec(){ + + } + } + + enum ReadOp{ + item((tile, id) -> tile.items() == null ? 0 : tile.items().get(id)), + itemTotal((tile, param) -> tile.items() == null ? 0 : tile.items().total()); + + final ReadOpLambda function; + final String symbol; + + ReadOp(ReadOpLambda function){ + this.symbol = name(); + this.function = function; + } + + interface ReadOpLambda{ + int get(Tilec tile, int parameter); + } } enum Op{ @@ -52,16 +96,18 @@ public class LogicExecutor{ and("and", (a, b) -> a & b), xor("xor", (a, b) -> a ^ b); - final BinaryOp function; + final OpLambda function; final String symbol; - Op(String symbol, BinaryOp function){ + Op(String symbol, OpLambda function){ this.symbol = symbol; this.function = function; } + + interface OpLambda{ + int get(int a, int b); + } } - interface BinaryOp{ - int get(int a, int b); - } + } diff --git a/core/src/mindustry/world/modules/ItemModule.java b/core/src/mindustry/world/modules/ItemModule.java index ef91960e87..d96a0f89c5 100644 --- a/core/src/mindustry/world/modules/ItemModule.java +++ b/core/src/mindustry/world/modules/ItemModule.java @@ -92,6 +92,10 @@ public class ItemModule extends BlockModule{ return null; } + public int get(int id){ + return items[id]; + } + public int get(Item item){ return items[item.id]; } diff --git a/tools/src/mindustry/tools/SectorDataGenerator.java b/tools/src/mindustry/tools/SectorDataGenerator.java index 77c0134e3e..337cf05027 100644 --- a/tools/src/mindustry/tools/SectorDataGenerator.java +++ b/tools/src/mindustry/tools/SectorDataGenerator.java @@ -50,14 +50,24 @@ public class SectorDataGenerator{ ObjectSet content = new ObjectSet<>(); world.loadSector(sector); + int waterFloors = 0, totalFloors = 0; + state.rules.sector = sector; for(Tile tile : world.tiles){ + if(world.getDarkness(tile.x, tile.y) >= 3){ + continue; + } + Item item = tile.floor().itemDrop; Liquid liquid = tile.floor().liquidDrop; if(item != null) content.add(item); if(liquid != null) content.add(liquid); if(!tile.block().isStatic()){ + totalFloors ++; + if(liquid == Liquids.water){ + waterFloors ++; + } floors.increment(tile.floor()); if(tile.overlay() != Blocks.air){ floors.increment(tile.overlay()); @@ -80,6 +90,13 @@ public class SectorDataGenerator{ data.resources = content.asArray().sort(Structs.comps(Structs.comparing(Content::getContentType), Structs.comparingInt(c -> c.id))).toArray(UnlockableContent.class); + //50% water -> naval attribute + //TODO also select sectors with water spawns + if((float)waterFloors / totalFloors >= 0.5f){ + Log.info("Floor percentage for sector {0} : {1}", sector.id, (int)((float)waterFloors / totalFloors * 100)); + data.attributes |= (1 << SectorAttribute.naval.ordinal()); + } + if(count[0]++ % 10 == 0){ Log.info("&lyDone with sector &lm{0}/{1}", count[0], planet.sectors.size); }