Sector lock state

This commit is contained in:
Anuken
2020-03-19 11:29:18 -04:00
parent 6bf031d0f5
commit e9994794aa
7 changed files with 115 additions and 21 deletions
Binary file not shown.
+4
View File
@@ -77,12 +77,16 @@ public class Planet extends UnlockableContent{
//read data for sectors //read data for sectors
Fi data = Vars.tree.get("planets/" + name + ".dat"); Fi data = Vars.tree.get("planets/" + name + ".dat");
if(data.exists()){ if(data.exists()){
try{
try(Reads read = data.reads()){ try(Reads read = data.reads()){
short dsize = read.s(); short dsize = read.s();
for(int i = 0; i < dsize; i++){ for(int i = 0; i < dsize; i++){
sectors.get(i).data.read(read); sectors.get(i).data.read(read);
} }
} }
}catch(Throwable t){
t.printStackTrace();
}
} }
}else{ }else{
sectors = new Array<>(); sectors = new Array<>();
+18 -1
View File
@@ -1,8 +1,8 @@
package mindustry.type; package mindustry.type;
import arc.math.geom.*; import arc.math.geom.*;
import arc.util.*;
import arc.util.ArcAnnotate.*; import arc.util.ArcAnnotate.*;
import arc.util.*;
import arc.util.io.*; import arc.util.io.*;
import mindustry.*; import mindustry.*;
import mindustry.ctype.*; import mindustry.ctype.*;
@@ -34,6 +34,10 @@ public class Sector{
this.data = data; this.data = data;
} }
public boolean locked(){
return true;
}
/** @return light dot product in the range [0, 1]. */ /** @return light dot product in the range [0, 1]. */
public float getLight(){ public float getLight(){
Vec3 normal = Tmp.v31.set(tile.v).rotate(Vec3.Y, -planet.getRotation()).nor(); 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); 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 static class SectorRect{
public final Vec3 center, top, right; public final Vec3 center, top, right;
public final Vec3 result = new Vec3(); public final Vec3 result = new Vec3();
@@ -115,6 +123,7 @@ public class Sector{
public Block[] floors = {}; public Block[] floors = {};
public int[] floorCounts = {}; public int[] floorCounts = {};
public int attributes;
public void write(Writes write){ public void write(Writes write){
write.s(resources.length); write.s(resources.length);
@@ -129,6 +138,8 @@ public class Sector{
write.s(floors[i].id); write.s(floors[i].id);
write.i(floorCounts[i]); write.i(floorCounts[i]);
} }
write.i(attributes);
} }
public void read(Reads read){ public void read(Reads read){
@@ -144,6 +155,12 @@ public class Sector{
floors[i] = Vars.content.block(read.s()); floors[i] = Vars.content.block(read.s());
floorCounts[i] = read.i(); floorCounts[i] = read.i();
} }
attributes = read.i();
} }
} }
public enum SectorAttribute{
/** Requires naval technology to land on, e.g. mostly water */
naval
}
} }
@@ -19,6 +19,7 @@ import mindustry.graphics.*;
import mindustry.graphics.g3d.*; import mindustry.graphics.g3d.*;
import mindustry.graphics.g3d.PlanetGrid.*; import mindustry.graphics.g3d.PlanetGrid.*;
import mindustry.type.*; import mindustry.type.*;
import mindustry.type.Sector.*;
import mindustry.ui.*; import mindustry.ui.*;
import static mindustry.Vars.*; import static mindustry.Vars.*;
@@ -30,7 +31,7 @@ public class PlanetDialog extends FloatingDialog{
borderColor = Pal.accent.cpy().a(0.3f), borderColor = Pal.accent.cpy().a(0.3f),
shadowColor = new Color(0, 0, 0, 0.7f); shadowColor = new Color(0, 0, 0, 0.7f);
private static final float camLength = 4f; private static final float camLength = 4f;
float outlineRad = 1.15f; float outlineRad = 1.16f;
//the base planet that's being rendered //the base planet that's being rendered
private final Planet solarSystem = Planets.sun; 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); buttons.addImageTextButton("$techtree", Icon.tree, () -> ui.tech.show()).size(230f, 64f);
camRelative.set(0, 0f, camLength); camRelative.set(0, 0f, camLength);
projector.setScaling(1f / 300f); projector.setScaling(1f / 150f);
update(() -> { update(() -> {
Vec3 v = Tmp.v33.set(Core.input.mouseX(), Core.input.mouseY(), 0); Vec3 v = Tmp.v33.set(Core.input.mouseX(), Core.input.mouseY(), 0);
@@ -95,7 +96,7 @@ public class PlanetDialog extends FloatingDialog{
addListener(new ElementGestureListener(){ addListener(new ElementGestureListener(){
@Override @Override
public void tap(InputEvent event, float x, float y, int count, KeyCode button){ 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){ if(selected != null){
updateSelected(); updateSelected();
} }
@@ -158,10 +159,15 @@ public class PlanetDialog extends FloatingDialog{
if(hovered != null){ if(hovered != null){
Draw.batch(projector, () -> { Draw.batch(projector, () -> {
setPlane(hovered); setPlane(hovered);
Draw.color(Color.white, Pal.accent, Mathf.absin(5f, 1f));
if(false){ //TODO locked check TextureRegion icon = hovered.locked() ? Icon.lock.getRegion() : hovered.hasAttribute(SectorAttribute.naval) ? Liquids.water.icon(Cicon.large) : null;
Draw.rect(Icon.lock.getRegion(), 0, 0);
if(icon != null){
Draw.rect(icon, 0, 0);
} }
Draw.reset();
}); });
} }
@@ -1,6 +1,7 @@
package mindustry.world.blocks.logic; package mindustry.world.blocks.logic;
import arc.math.*; import arc.math.*;
import mindustry.gen.*;
public class LogicExecutor{ public class LogicExecutor{
Instruction[] instructions; Instruction[] instructions;
@@ -17,26 +18,69 @@ public class LogicExecutor{
if(counter >= instructions.length) counter = 0; if(counter >= instructions.length) counter = 0;
} }
Tilec device(short id){
return null; //TODO
}
interface Instruction{ interface Instruction{
void exec(); void exec();
} }
class RegisterI{ class RegisterI implements Instruction{
/** operation to perform */
Op op; Op op;
short from, to; /** destination register */
int immediate; 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(){ 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{ enum Op{
@@ -52,16 +96,18 @@ public class LogicExecutor{
and("and", (a, b) -> a & b), and("and", (a, b) -> a & b),
xor("xor", (a, b) -> a ^ b); xor("xor", (a, b) -> a ^ b);
final BinaryOp function; final OpLambda function;
final String symbol; final String symbol;
Op(String symbol, BinaryOp function){ Op(String symbol, OpLambda function){
this.symbol = symbol; this.symbol = symbol;
this.function = function; this.function = function;
} }
}
interface BinaryOp{ interface OpLambda{
int get(int a, int b); int get(int a, int b);
} }
} }
}
@@ -92,6 +92,10 @@ public class ItemModule extends BlockModule{
return null; return null;
} }
public int get(int id){
return items[id];
}
public int get(Item item){ public int get(Item item){
return items[item.id]; return items[item.id];
} }
@@ -50,14 +50,24 @@ public class SectorDataGenerator{
ObjectSet<Content> content = new ObjectSet<>(); ObjectSet<Content> content = new ObjectSet<>();
world.loadSector(sector); world.loadSector(sector);
int waterFloors = 0, totalFloors = 0;
state.rules.sector = sector;
for(Tile tile : world.tiles){ for(Tile tile : world.tiles){
if(world.getDarkness(tile.x, tile.y) >= 3){
continue;
}
Item item = tile.floor().itemDrop; Item item = tile.floor().itemDrop;
Liquid liquid = tile.floor().liquidDrop; Liquid liquid = tile.floor().liquidDrop;
if(item != null) content.add(item); if(item != null) content.add(item);
if(liquid != null) content.add(liquid); if(liquid != null) content.add(liquid);
if(!tile.block().isStatic()){ if(!tile.block().isStatic()){
totalFloors ++;
if(liquid == Liquids.water){
waterFloors ++;
}
floors.increment(tile.floor()); floors.increment(tile.floor());
if(tile.overlay() != Blocks.air){ if(tile.overlay() != Blocks.air){
floors.increment(tile.overlay()); 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); 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){ if(count[0]++ % 10 == 0){
Log.info("&lyDone with sector &lm{0}/{1}", count[0], planet.sectors.size); Log.info("&lyDone with sector &lm{0}/{1}", count[0], planet.sectors.size);
} }