diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index 543934f2df..3a7e413d36 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -114,7 +114,7 @@ mod.disable = Disable mod.content = Content: mod.delete.error = Unable to delete mod. File may be in use. mod.requiresversion = [scarlet]Requires min game version: [accent]{0} -mod.outdated = [scarlet]Not compatible with V6 (no min-game-version: 105) +mod.outdated = [scarlet]Not compatible with V6 (no minGameVersion: 105) mod.missingdependencies = [scarlet]Missing dependencies: {0} mod.erroredcontent = [scarlet]Content Errors mod.errors = Errors have occurred loading content. diff --git a/core/src/mindustry/Vars.java b/core/src/mindustry/Vars.java index 54f58da967..34ad2f6daa 100644 --- a/core/src/mindustry/Vars.java +++ b/core/src/mindustry/Vars.java @@ -78,6 +78,8 @@ public class Vars implements Loadable{ public static final float miningRange = 70f; /** range for building */ public static final float buildingRange = 220f; + /** range for moving items */ + public static final float itemTransferRange = 220f; /** duration of time between turns in ticks */ public static final float turnDuration = 20 * Time.toMinutes; /** turns needed to destroy a sector completely */ diff --git a/core/src/mindustry/entities/comp/BuildingComp.java b/core/src/mindustry/entities/comp/BuildingComp.java index 898cf355b9..499573a6d2 100644 --- a/core/src/mindustry/entities/comp/BuildingComp.java +++ b/core/src/mindustry/entities/comp/BuildingComp.java @@ -1226,6 +1226,13 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc, return 0; } + @Override + public Object senseObject(LAccess sensor){ + if(sensor == LAccess.type) return block; + + return noSensed; + } + @Override public double sense(Content content){ if(content instanceof Item && items != null) return items.get((Item)content); diff --git a/core/src/mindustry/entities/comp/UnitComp.java b/core/src/mindustry/entities/comp/UnitComp.java index b20d37d36a..8e8f575f98 100644 --- a/core/src/mindustry/entities/comp/UnitComp.java +++ b/core/src/mindustry/entities/comp/UnitComp.java @@ -85,6 +85,13 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I return 0; } + @Override + public Object senseObject(LAccess sensor){ + if(sensor == LAccess.type) return type; + + return noSensed; + } + @Override public double sense(Content content){ if(content == stack().item) return stack().amount; diff --git a/core/src/mindustry/graphics/OverlayRenderer.java b/core/src/mindustry/graphics/OverlayRenderer.java index f3724d39dc..f5936125d2 100644 --- a/core/src/mindustry/graphics/OverlayRenderer.java +++ b/core/src/mindustry/graphics/OverlayRenderer.java @@ -161,7 +161,7 @@ public class OverlayRenderer{ Draw.reset(); Building tile = world.buildWorld(v.x, v.y); - if(tile != null && tile.interactable(player.team()) && tile.acceptStack(player.unit().item(), player.unit().stack.amount, player.unit()) > 0){ + if(tile != null && tile.interactable(player.team()) && tile.acceptStack(player.unit().item(), player.unit().stack.amount, player.unit()) > 0 && player.within(tile, itemTransferRange)){ Lines.stroke(3f, Pal.gray); Lines.square(tile.x, tile.y, tile.block().size * tilesize / 2f + 3 + Mathf.absin(Time.time(), 5f, 1f)); Lines.stroke(1f, Pal.place); diff --git a/core/src/mindustry/input/DesktopInput.java b/core/src/mindustry/input/DesktopInput.java index f28902819c..cf90e40827 100644 --- a/core/src/mindustry/input/DesktopInput.java +++ b/core/src/mindustry/input/DesktopInput.java @@ -75,13 +75,13 @@ public class DesktopInput extends InputHandler{ }); group.fill(t -> { - t.visible(() -> Core.settings.getBool("hints") && lastSchematic != null && !selectRequests.isEmpty()); + t.visible(() -> lastSchematic != null && !selectRequests.isEmpty()); t.bottom(); t.table(Styles.black6, b -> { b.defaults().left(); - b.label( () -> Core.bundle.format("schematic.flip", - Core.keybinds.get(Binding.schematic_flip_x).key.toString(), - Core.keybinds.get(Binding.schematic_flip_y).key.toString())).style(Styles.outlineLabel); + b.label(() -> Core.bundle.format("schematic.flip", + Core.keybinds.get(Binding.schematic_flip_x).key.toString(), + Core.keybinds.get(Binding.schematic_flip_y).key.toString())).style(Styles.outlineLabel).visible(() -> Core.settings.getBool("hints")); b.row(); b.table(a -> { a.button("@schematic.add", Icon.save, this::showSchematicSave).colspan(2).size(250f, 50f).disabled(f -> lastSchematic == null || lastSchematic.file != null); diff --git a/core/src/mindustry/input/InputHandler.java b/core/src/mindustry/input/InputHandler.java index 34e4552958..601e8e6caf 100644 --- a/core/src/mindustry/input/InputHandler.java +++ b/core/src/mindustry/input/InputHandler.java @@ -186,7 +186,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{ @Remote(targets = Loc.both, forward = true, called = Loc.server) public static void transferInventory(Player player, Building tile){ - if(player == null || tile == null) return; + if(player == null || tile == null || !player.within(tile, buildingRange)) return; if(net.server() && (player.unit().stack.amount <= 0 || !Units.canInteract(player, tile) || !netServer.admins.allowAction(player, ActionType.depositItem, tile.tile(), action -> { diff --git a/core/src/mindustry/logic/ConditionOp.java b/core/src/mindustry/logic/ConditionOp.java index c85bc6f37a..2661509c7e 100644 --- a/core/src/mindustry/logic/ConditionOp.java +++ b/core/src/mindustry/logic/ConditionOp.java @@ -1,8 +1,8 @@ package mindustry.logic; public enum ConditionOp{ - equal("==", (a, b) -> Math.abs(a - b) < 0.000001), - notEqual("not", (a, b) -> Math.abs(a - b) >= 0.000001), + equal("==", (a, b) -> Math.abs(a - b) < 0.000001, (a, b) -> a == b), + notEqual("not", (a, b) -> Math.abs(a - b) >= 0.000001, (a, b) -> a != b), lessThan("<", (a, b) -> a < b), lessThanEq("<=", (a, b) -> a <= b), greaterThan(">", (a, b) -> a > b), @@ -10,12 +10,18 @@ public enum ConditionOp{ public static final ConditionOp[] all = values(); + public final CondObjOpLambda objFunction; public final CondOpLambda function; public final String symbol; ConditionOp(String symbol, CondOpLambda function){ + this(symbol, function, null); + } + + ConditionOp(String symbol, CondOpLambda function, CondObjOpLambda objFunction){ this.symbol = symbol; this.function = function; + this.objFunction = objFunction; } @Override @@ -23,6 +29,10 @@ public enum ConditionOp{ return symbol; } + interface CondObjOpLambda{ + boolean get(Object a, Object b); + } + interface CondOpLambda{ boolean get(double a, double b); } diff --git a/core/src/mindustry/logic/LAccess.java b/core/src/mindustry/logic/LAccess.java index 95217ddd71..30eacf2402 100644 --- a/core/src/mindustry/logic/LAccess.java +++ b/core/src/mindustry/logic/LAccess.java @@ -25,6 +25,7 @@ public enum LAccess{ shootY, shooting, team, + type, //values with parameters are considered controllable enabled("to"), //"to" is standard for single parameter access diff --git a/core/src/mindustry/logic/LAssembler.java b/core/src/mindustry/logic/LAssembler.java index 47fb032c83..7ca74ca83c 100644 --- a/core/src/mindustry/logic/LAssembler.java +++ b/core/src/mindustry/logic/LAssembler.java @@ -8,6 +8,7 @@ import mindustry.gen.*; import mindustry.logic.LExecutor.*; import mindustry.logic.LStatements.*; import mindustry.type.*; +import mindustry.world.*; /** "Compiles" a sequence of statements into instructions. */ public class LAssembler{ @@ -38,6 +39,12 @@ public class LAssembler{ putConst("@" + liquid.name, liquid); } + for(Block block : Vars.content.blocks()){ + if(block.synthetic()){ + putConst("@" + block.name, block); + } + } + //store sensor constants for(LAccess sensor : LAccess.all){ diff --git a/core/src/mindustry/logic/LExecutor.java b/core/src/mindustry/logic/LExecutor.java index 1b7793165b..e2399363a2 100644 --- a/core/src/mindustry/logic/LExecutor.java +++ b/core/src/mindustry/logic/LExecutor.java @@ -255,18 +255,22 @@ public class LExecutor{ Object target = exec.obj(from); Object sense = exec.obj(type); - double output = 0; - if(target instanceof Senseable){ + Senseable se = (Senseable)target; if(sense instanceof Content){ - output = ((Senseable)target).sense(((Content)sense)); + exec.setnum(to, se.sense(((Content)sense))); }else if(sense instanceof LAccess){ - output = ((Senseable)target).sense(((LAccess)sense)); + Object objOut = se.senseObject((LAccess)sense); + + if(objOut == Senseable.noSensed){ + //numeric output + exec.setnum(to, se.sense((LAccess)sense)); + }else{ + //object output + exec.setobj(to, objOut); + } } } - - exec.setnum(to, output); - } } @@ -399,7 +403,17 @@ public class LExecutor{ if(op.unary){ exec.setnum(dest, op.function1.get(exec.num(a))); }else{ - exec.setnum(dest, op.function2.get(exec.num(a), exec.num(b))); + Var va = exec.vars[a]; + Var vb = exec.vars[b]; + + if(op.objFunction2 != null && (va.isobj || vb.isobj)){ + //use object function if provided, and one of the variables is an object + exec.setnum(dest, op.objFunction2.get(exec.obj(a), exec.obj(b))); + }else{ + //otherwise use the numeric function + exec.setnum(dest, op.function2.get(exec.num(a), exec.num(b))); + } + } } } @@ -554,8 +568,21 @@ public class LExecutor{ @Override public void run(LExecutor exec){ - if(address != -1 && op.function.get(exec.num(value), exec.num(compare))){ - exec.vars[varCounter].numval = address; + if(address != -1){ + Var va = exec.vars[value]; + Var vb = exec.vars[compare]; + boolean cmp = false; + + if(op.objFunction != null && (va.isobj || vb.isobj)){ + //use object function if provided, and one of the variables is an object + cmp = op.objFunction.get(exec.obj(value), exec.obj(compare)); + }else{ + cmp = op.function.get(exec.num(value), exec.num(compare)); + } + + if(cmp){ + exec.vars[varCounter].numval = address; + } } } } diff --git a/core/src/mindustry/logic/LogicOp.java b/core/src/mindustry/logic/LogicOp.java index 616ae5a464..3f0c0d7ca9 100644 --- a/core/src/mindustry/logic/LogicOp.java +++ b/core/src/mindustry/logic/LogicOp.java @@ -8,8 +8,8 @@ public enum LogicOp{ mul("*", (a, b) -> a * b), div("/", (a, b) -> a / b), mod("%", (a, b) -> a % b), - equal("==", (a, b) -> Math.abs(a - b) < 0.000001 ? 1 : 0), - notEqual("not", (a, b) -> Math.abs(a - b) < 0.000001 ? 0 : 1), + equal("==", (a, b) -> Math.abs(a - b) < 0.000001 ? 1 : 0, (a, b) -> a == b ? 1 : 0), + notEqual("not", (a, b) -> Math.abs(a - b) < 0.000001 ? 0 : 1, (a, b) -> a != b ? 1 : 0), lessThan("<", (a, b) -> a < b ? 1 : 0), lessThanEq("<=", (a, b) -> a <= b ? 1 : 0), greaterThan(">", (a, b) -> a > b ? 1 : 0), @@ -41,16 +41,22 @@ public enum LogicOp{ public static final LogicOp[] all = values(); + public final OpObjLambda2 objFunction2; public final OpLambda2 function2; public final OpLambda1 function1; public final boolean unary; public final String symbol; LogicOp(String symbol, OpLambda2 function){ + this(symbol, function, null); + } + + LogicOp(String symbol, OpLambda2 function, OpObjLambda2 objFunction){ this.symbol = symbol; this.function2 = function; this.function1 = null; this.unary = false; + this.objFunction2 = objFunction; } LogicOp(String symbol, OpLambda1 function){ @@ -58,6 +64,7 @@ public enum LogicOp{ this.function1 = function; this.function2 = null; this.unary = true; + this.objFunction2 = null; } @Override @@ -65,6 +72,10 @@ public enum LogicOp{ return symbol; } + interface OpObjLambda2{ + double get(Object a, Object b); + } + interface OpLambda2{ double get(double a, double b); } diff --git a/core/src/mindustry/logic/Senseable.java b/core/src/mindustry/logic/Senseable.java index 3f9e3798a4..6ae99afbfa 100644 --- a/core/src/mindustry/logic/Senseable.java +++ b/core/src/mindustry/logic/Senseable.java @@ -3,6 +3,12 @@ package mindustry.logic; import mindustry.ctype.*; public interface Senseable{ + Object noSensed = new Object(); + double sense(LAccess sensor); double sense(Content content); + + default Object senseObject(LAccess sensor){ + return noSensed; + } } diff --git a/core/src/mindustry/ui/fragments/BlockInventoryFragment.java b/core/src/mindustry/ui/fragments/BlockInventoryFragment.java index 08079ba7a7..76ab36cd25 100644 --- a/core/src/mindustry/ui/fragments/BlockInventoryFragment.java +++ b/core/src/mindustry/ui/fragments/BlockInventoryFragment.java @@ -44,7 +44,7 @@ public class BlockInventoryFragment extends Fragment{ @Remote(called = Loc.server, targets = Loc.both, forward = true) public static void requestItem(Player player, Building tile, Item item, int amount){ - if(player == null || tile == null || !tile.interactable(player.team())) return; + if(player == null || tile == null || !tile.interactable(player.team()) || !player.within(tile, buildingRange)) return; amount = Math.min(player.unit().maxAccepted(item), amount); int fa = amount; @@ -165,7 +165,7 @@ public class BlockInventoryFragment extends Fragment{ container.add(i); - Boolp canPick = () -> player.unit().acceptsItem(item) && !state.isPaused(); + Boolp canPick = () -> player.unit().acceptsItem(item) && !state.isPaused() && player.within(tile, itemTransferRange); HandCursorListener l = new HandCursorListener(); l.setEnabled(canPick);