diff --git a/core/src/mindustry/logic/LExecutor.java b/core/src/mindustry/logic/LExecutor.java index d2d074ae56..1ba96cc93a 100644 --- a/core/src/mindustry/logic/LExecutor.java +++ b/core/src/mindustry/logic/LExecutor.java @@ -61,6 +61,8 @@ public class LExecutor{ //yes, this is a minor memory leak, but it's probably not significant enough to matter protected static IntFloatMap unitTimeouts = new IntFloatMap(); + //lookup variable by name, lazy init. + protected @Nullable ObjectIntMap nameMap; static{ Events.on(ResetEvent.class, e -> unitTimeouts.clear()); @@ -92,6 +94,7 @@ public class LExecutor{ /** Loads with a specified assembler. Resets all variables. */ public void load(LAssembler builder){ + nameMap = null; vars = builder.vars.values().toSeq().retainAll(var -> !var.constant).toArray(LVar.class); for(int i = 0; i < vars.length; i++){ vars[i].id = i; @@ -106,6 +109,17 @@ public class LExecutor{ //region utility + + public @Nullable LVar optionalVar(String name){ + if(nameMap == null){ + nameMap = new ObjectIntMap<>(); + for(int i = 0; i < vars.length; i++){ + nameMap.put(vars[i].name, i); + } + } + return optionalVar(nameMap.get(name, -1)); + } + /** @return a Var from this processor. May be null if out of bounds. */ public @Nullable LVar optionalVar(int index){ return index < 0 || index >= vars.length ? null : vars[index]; @@ -227,7 +241,7 @@ public class LExecutor{ outFound.setnum(0); } - if(res != null && res.build != null && + if(res != null && res.build != null && (unit.within(res.build.x, res.build.y, Math.max(unit.range(), buildingRange)) || res.build.team == exec.team)){ cache.build = res.build; outBuild.setobj(res.build); @@ -557,6 +571,13 @@ public class LExecutor{ if(from instanceof MemoryBuild mem && (exec.privileged || (from.team == exec.team && !mem.block.privileged))){ output.setnum(address < 0 || address >= mem.memory.length ? 0 : mem.memory[address]); + }else if(from instanceof LogicBuild logic && (exec.privileged || (from.team == exec.team && !from.block.privileged)) && position.isobj && position.objval instanceof String name){ + LVar fromVar = logic.executor.optionalVar(name); + if(fromVar != null && !output.constant){ + output.objval = fromVar.objval; + output.numval = fromVar.numval; + output.isobj = fromVar.isobj; + } } } } @@ -580,6 +601,13 @@ public class LExecutor{ if(from instanceof MemoryBuild mem && (exec.privileged || (from.team == exec.team && !mem.block.privileged)) && address >= 0 && address < mem.memory.length){ mem.memory[address] = value.num(); + }else if(from instanceof LogicBuild logic && (exec.privileged || (from.team == exec.team && !from.block.privileged)) && position.isobj && position.objval instanceof String name){ + LVar toVar = logic.executor.optionalVar(name); + if(toVar != null && !toVar.constant){ + toVar.objval = value.objval; + toVar.numval = value.numval; + toVar.isobj = value.isobj; + } } } } diff --git a/core/src/mindustry/type/UnitType.java b/core/src/mindustry/type/UnitType.java index a8d7ddc846..83fb19f6f5 100644 --- a/core/src/mindustry/type/UnitType.java +++ b/core/src/mindustry/type/UnitType.java @@ -1754,29 +1754,30 @@ public class UnitType extends UnlockableContent implements Senseable{ Tmp.v1.set(x, y).rotate(rot); float ex = Tmp.v1.x, ey = Tmp.v1.y; + float rad = (radius + Mathf.absin(Time.time, 2f, radius / 4f)) * scale; //engine outlines (cursed?) /*float z = Draw.z(); Draw.z(z - 0.0001f); Draw.color(type.outlineColor); Fill.circle( - unit.x + ex, - unit.y + ey, - (type.outlineRadius * Draw.scl + radius + Mathf.absin(Time.time, 2f, radius / 4f)) * scale + unit.x + ex, + unit.y + ey, + (type.outlineRadius * Draw.scl + radius + Mathf.absin(Time.time, 2f, radius / 4f)) * scale ); Draw.z(z);*/ Draw.color(color); Fill.circle( - unit.x + ex, - unit.y + ey, - (radius + Mathf.absin(Time.time, 2f, radius / 4f)) * scale + unit.x + ex, + unit.y + ey, + rad ); Draw.color(type.engineColorInner); Fill.circle( - unit.x + ex - Angles.trnsx(rot + rotation, 1f), - unit.y + ey - Angles.trnsy(rot + rotation, 1f), - (radius + Mathf.absin(Time.time, 2f, radius / 4f)) / 2f * scale + unit.x + ex - Angles.trnsx(rot + rotation, rad / 4f), + unit.y + ey - Angles.trnsy(rot + rotation, rad / 4f), + rad / 2f ); }