From 04c2bbc24d7c69855df19b46a4938b2ad93f0de0 Mon Sep 17 00:00:00 2001 From: Anuken Date: Thu, 10 Feb 2022 09:36:31 -0500 Subject: [PATCH] Logic rule instruction / Lock erekir proc sectors --- core/src/mindustry/content/Blocks.java | 6 ++-- core/src/mindustry/content/UnitTypes.java | 10 +++--- .../mindustry/entities/comp/BuildingComp.java | 1 + .../src/mindustry/entities/comp/UnitComp.java | 2 ++ .../src/mindustry/entities/part/DrawPart.java | 15 ++++++++ .../mindustry/entities/part/RegionPart.java | 24 +++++++++---- core/src/mindustry/input/MobileInput.java | 5 +++ core/src/mindustry/logic/LAssembler.java | 11 ++++++ core/src/mindustry/logic/LExecutor.java | 28 +++++++++++++++ core/src/mindustry/logic/LStatements.java | 34 +++++++++++++++++++ core/src/mindustry/logic/LogicRule.java | 15 ++++++++ .../maps/generators/PlanetGenerator.java | 5 +++ .../maps/planet/ErekirPlanetGenerator.java | 6 ++++ .../mindustry/ui/dialogs/PlanetDialog.java | 5 ++- core/src/mindustry/world/Block.java | 27 ++++++++++++++- gradle.properties | 2 +- 16 files changed, 179 insertions(+), 17 deletions(-) create mode 100644 core/src/mindustry/logic/LogicRule.java diff --git a/core/src/mindustry/content/Blocks.java b/core/src/mindustry/content/Blocks.java index 6f944bff4f..34d46e749c 100644 --- a/core/src/mindustry/content/Blocks.java +++ b/core/src/mindustry/content/Blocks.java @@ -3177,7 +3177,7 @@ public class Blocks{ new RegionPart("-back"){{ progress = PartProgress.warmup; mirror = true; - rotMove = 40f; + moveRot = 40f; x = 22 / 4f; y = -1f / 4f; moveY = 6f / 4f; @@ -3187,7 +3187,7 @@ public class Blocks{ new RegionPart("-front"){{ progress = PartProgress.warmup; mirror = true; - rotMove = 40f; + moveRot = 40f; x = 20 / 4f; y = 17f / 4f; moveX = 1f; @@ -3296,7 +3296,7 @@ public class Blocks{ mirror = true; moveX = 2f * 4f / 3f; moveY = -0.5f; - rotMove = -40f; + moveRot = -40f; under = true; heatColor = Color.red.cpy(); }}); diff --git a/core/src/mindustry/content/UnitTypes.java b/core/src/mindustry/content/UnitTypes.java index c9c09cf819..861c4f530e 100644 --- a/core/src/mindustry/content/UnitTypes.java +++ b/core/src/mindustry/content/UnitTypes.java @@ -2542,7 +2542,7 @@ public class UnitTypes{ under = true; moveX = 0.75f; moveY = 0.75f; - rotMove = 82f; + moveRot = 82f; x = 37 / 4f; y = 8 / 4f; }}, @@ -2578,7 +2578,7 @@ public class UnitTypes{ heatColor = new Color(1f, 0.1f, 0.1f); mirror = true; under = true; - rotMove = -40f * fi; + moveRot = -40f * fi; moveX = 3f; layerOffset = -0.002f; @@ -2845,7 +2845,7 @@ public class UnitTypes{ y = 10f / 4f; moveY = 1f - fi * 3f; moveX = fi * 0.5f; - rotMove = -30f - fi * 15f; + moveRot = -30f - fi * 15f; }}); } @@ -3020,7 +3020,7 @@ public class UnitTypes{ heatColor = Color.valueOf("9c50ff"); x = 5 / 4f; y = 0f; - rotMove = -33f; + moveRot = -33f; moveY = -1f; moveX = -1f; under = true; @@ -3059,7 +3059,7 @@ public class UnitTypes{ parts.add(new RegionPart("-fin"){{ mirror = true; progress = PartProgress.life.mul(3f).curve(Interp.pow5In); - rotMove = 32f; + moveRot = 32f; rotation = -6f; moveY = 1.5f; x = 3f / 4f; diff --git a/core/src/mindustry/entities/comp/BuildingComp.java b/core/src/mindustry/entities/comp/BuildingComp.java index 41a399fd4b..52e3969ed1 100644 --- a/core/src/mindustry/entities/comp/BuildingComp.java +++ b/core/src/mindustry/entities/comp/BuildingComp.java @@ -1617,6 +1617,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc, return switch(sensor){ case x -> World.conv(x); case y -> World.conv(y); + case color -> Color.toDoubleBits(team.color.r, team.color.g, team.color.b, 1f); case dead -> !isValid() ? 1 : 0; case team -> team.id; case health -> health; diff --git a/core/src/mindustry/entities/comp/UnitComp.java b/core/src/mindustry/entities/comp/UnitComp.java index 4a34fe5e34..5d4c0c9988 100644 --- a/core/src/mindustry/entities/comp/UnitComp.java +++ b/core/src/mindustry/entities/comp/UnitComp.java @@ -2,6 +2,7 @@ package mindustry.entities.comp; import arc.*; import arc.func.*; +import arc.graphics.*; import arc.graphics.g2d.*; import arc.math.*; import arc.math.geom.*; @@ -195,6 +196,7 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I case commanded -> controller instanceof FormationAI && isValid() ? 1 : 0; case payloadCount -> ((Object)this) instanceof Payloadc pay ? pay.payloads().size : 0; case size -> hitSize / tilesize; + case color -> Color.toDoubleBits(team.color.r, team.color.g, team.color.b, 1f); default -> Float.NaN; }; } diff --git a/core/src/mindustry/entities/part/DrawPart.java b/core/src/mindustry/entities/part/DrawPart.java index b19df4cebb..d6e6e13041 100644 --- a/core/src/mindustry/entities/part/DrawPart.java +++ b/core/src/mindustry/entities/part/DrawPart.java @@ -38,6 +38,21 @@ public abstract class DrawPart{ } } + public static class PartMove{ + public PartProgress progress = PartProgress.warmup; + public float x, y, rot; + + public PartMove(PartProgress progress, float x, float y, float rot){ + this.progress = progress; + this.x = x; + this.y = y; + this.rot = rot; + } + + public PartMove(){ + } + } + public interface PartProgress{ /** Reload of the weapon - 1 right after shooting, 0 when ready to fire*/ PartProgress diff --git a/core/src/mindustry/entities/part/RegionPart.java b/core/src/mindustry/entities/part/RegionPart.java index a8a99559ba..191144a97e 100644 --- a/core/src/mindustry/entities/part/RegionPart.java +++ b/core/src/mindustry/entities/part/RegionPart.java @@ -31,11 +31,12 @@ public class RegionPart extends DrawPart{ public Blending blending = Blending.normal; public float layer = -1, layerOffset = 0f; public float outlineLayerOffset = -0.001f; - public float rotation, rotMove; - public float x, y, moveX, moveY; + public float x, y, rotation; + public float moveX, moveY, moveRot; public @Nullable Color color, colorTo; public Color heatColor = Pal.turretHeat.cpy(); public Seq children = new Seq<>(); + public Seq moves = new Seq<>(); public RegionPart(String region){ this.suffix = region; @@ -61,6 +62,17 @@ public class RegionPart extends DrawPart{ float prevZ = Draw.z(); float prog = progress.getClamp(params); + float mx = moveX * prog, my = moveY * prog, mr = moveRot * prog; + + if(moves.size > 0){ + for(int i = 0; i < moves.size; i++){ + var move = moves.get(i); + float p = move.progress.getClamp(params); + mx += move.x * p; + my += move.y * p; + mr += move.rot * p; + } + } int len = mirror && params.sideOverride == -1 ? 2 : 1; @@ -71,12 +83,12 @@ public class RegionPart extends DrawPart{ //can be null var region = drawRegion ? regions[Math.min(i, regions.length - 1)] : null; float sign = (i == 0 ? 1 : -1) * params.sideMultiplier; - Tmp.v1.set((x + moveX * prog) * sign, y + moveY * prog).rotate(params.rotation - 90); + Tmp.v1.set((x + mx) * sign, y + my).rotate(params.rotation - 90); float rx = params.x + Tmp.v1.x, ry = params.y + Tmp.v1.y, - rot = rotMove * prog * sign + params.rotation - 90; + rot = mr * sign + params.rotation - 90; Draw.xscl = sign; @@ -113,9 +125,9 @@ public class RegionPart extends DrawPart{ for(int s = 0; s < len; s++){ int i = (params.sideOverride == -1 ? s : params.sideOverride); float sign = (i == 1 ? -1 : 1) * params.sideMultiplier; - Tmp.v1.set((x + moveX * prog) * sign, y + moveY * prog).rotate(params.rotation - 90); + Tmp.v1.set((x + mx) * sign, y + my).rotate(params.rotation - 90); - childParam.set(params.warmup, params.reload, params.smoothReload, params.heat, params.x + Tmp.v1.x, params.y + Tmp.v1.y, i * sign + rotMove * prog * sign + params.rotation); + childParam.set(params.warmup, params.reload, params.smoothReload, params.heat, params.x + Tmp.v1.x, params.y + Tmp.v1.y, i * sign + mr * sign + params.rotation); childParam.sideMultiplier = params.sideMultiplier; childParam.life = params.life; childParam.sideOverride = i; diff --git a/core/src/mindustry/input/MobileInput.java b/core/src/mindustry/input/MobileInput.java index 528829457d..dae619f04c 100644 --- a/core/src/mindustry/input/MobileInput.java +++ b/core/src/mindustry/input/MobileInput.java @@ -894,6 +894,11 @@ public class MobileInput extends InputHandler implements GestureListener{ unit.lookAt(unit.prefRotation()); } + //validate payload, if it's a destroyed unit/building, remove it + if(payloadTarget instanceof Healthc h && !h.isValid()){ + payloadTarget = null; + } + if(payloadTarget != null && unit instanceof Payloadc pay){ targetPos.set(payloadTarget); attractDst = 0f; diff --git a/core/src/mindustry/logic/LAssembler.java b/core/src/mindustry/logic/LAssembler.java index 4323f27402..e907a10eeb 100644 --- a/core/src/mindustry/logic/LAssembler.java +++ b/core/src/mindustry/logic/LAssembler.java @@ -1,6 +1,7 @@ package mindustry.logic; import arc.func.*; +import arc.graphics.*; import arc.struct.*; import arc.util.*; import mindustry.*; @@ -99,10 +100,20 @@ public class LAssembler{ //parse hex/binary syntax if(symbol.startsWith("0b")) return Strings.parseLong(symbol, 2, 2, symbol.length(), invalidNum); if(symbol.startsWith("0x")) return Strings.parseLong(symbol, 16, 2, symbol.length(), invalidNum); + if(symbol.startsWith("%") && (symbol.length() == 7 || symbol.length() == 9)) return parseColor(symbol); return Strings.parseDouble(symbol, invalidNum); } + double parseColor(String symbol){ + int + r = Strings.parseInt(symbol, 16, 0, 1, 3), + g = Strings.parseInt(symbol, 16, 0, 3, 5), + b = Strings.parseInt(symbol, 16, 0, 5, 7), + a = symbol.length() == 9 ? Strings.parseInt(symbol, 16, 0, 7, 9) : 255; + return Color.toDoubleBits(r, g, b, a); + } + /** Adds a constant value by name. */ public BVar putConst(String name, Object value){ BVar var = putVar(name); diff --git a/core/src/mindustry/logic/LExecutor.java b/core/src/mindustry/logic/LExecutor.java index b58aff8d54..81e56ff055 100644 --- a/core/src/mindustry/logic/LExecutor.java +++ b/core/src/mindustry/logic/LExecutor.java @@ -1187,5 +1187,33 @@ public class LExecutor{ } } + public static class SetRuleI implements LInstruction{ + public LogicRule rule = LogicRule.waveSpacing; + public int value; + + public SetRuleI(LogicRule rule, int value){ + this.rule = rule; + this.value = value; + } + + public SetRuleI(){ + } + + @Override + public void run(LExecutor exec){ + switch(rule){ + case waveTimer -> state.rules.waveTimer = exec.bool(value); + case waves -> state.rules.waves = exec.bool(value); + case attackMode -> state.rules.attackMode = exec.bool(value); + case waveSpacing -> state.rules.waveSpacing = exec.numf(value) * 60f; + case enemyCoreBuildRadius -> state.rules.enemyCoreBuildRadius = exec.numf(value) * 8f; + case dropZoneRadius -> state.rules.dropZoneRadius = exec.numf(value) * 8f; + case unitCap -> state.rules.unitCap = exec.numi(value); + case lighting -> state.rules.lighting = exec.bool(value); + case ambientLight -> state.rules.ambientLight.fromDouble(exec.num(value)); + } + } + } + //endregion } diff --git a/core/src/mindustry/logic/LStatements.java b/core/src/mindustry/logic/LStatements.java index dd9c55a839..0b1d85cd25 100644 --- a/core/src/mindustry/logic/LStatements.java +++ b/core/src/mindustry/logic/LStatements.java @@ -6,6 +6,7 @@ import arc.graphics.*; import arc.scene.style.*; import arc.scene.ui.*; import arc.scene.ui.layout.*; +import arc.util.*; import mindustry.*; import mindustry.annotations.Annotations.*; import mindustry.ctype.*; @@ -1205,4 +1206,37 @@ public class LStatements{ return new SpawnUnitI(builder.var(type), builder.var(x), builder.var(y), builder.var(rotation), builder.var(team), effect, builder.var(result)); } } + + @RegisterStatement("setrule") + public static class SetRuleStatement extends LStatement{ + public LogicRule rule = LogicRule.waveSpacing; + public String value = "100"; + + @Override + public void build(Table table){ + table.button(b -> { + b.label(() -> rule.name()).growX().wrap().labelAlign(Align.center); + b.clicked(() -> showSelect(b, LogicRule.all, rule, o -> rule = o, 2, c -> c.width(150f))); + }, Styles.logict, () -> {}).size(150f, 40f).pad(4f).color(table.color); + + table.add(" = "); + + field(table, value, s -> value = s); + } + + @Override + public boolean privileged(){ + return true; + } + + @Override + public Color color(){ + return Pal.logicWorld; + } + + @Override + public LInstruction build(LAssembler builder){ + return new SetRuleI(rule, builder.var(value)); + } + } } diff --git a/core/src/mindustry/logic/LogicRule.java b/core/src/mindustry/logic/LogicRule.java new file mode 100644 index 0000000000..f89e801ca5 --- /dev/null +++ b/core/src/mindustry/logic/LogicRule.java @@ -0,0 +1,15 @@ +package mindustry.logic; + +public enum LogicRule{ + waveTimer, + waves, + waveSpacing, + attackMode, + enemyCoreBuildRadius, + dropZoneRadius, + unitCap, + lighting, + ambientLight; + + public static final LogicRule[] all = values(); +} diff --git a/core/src/mindustry/maps/generators/PlanetGenerator.java b/core/src/mindustry/maps/generators/PlanetGenerator.java index 3b67cd13c1..cbf2ee44ff 100644 --- a/core/src/mindustry/maps/generators/PlanetGenerator.java +++ b/core/src/mindustry/maps/generators/PlanetGenerator.java @@ -53,6 +53,11 @@ public abstract class PlanetGenerator extends BasicGenerator implements HexMeshe } } + /** @return whether to allow landing on the specified procedural sector */ + public boolean allowLanding(Sector sector){ + return sector.hasBase() || sector.near().contains(Sector::hasBase); + } + public void addWeather(Sector sector, Rules rules){ //apply weather based on terrain diff --git a/core/src/mindustry/maps/planet/ErekirPlanetGenerator.java b/core/src/mindustry/maps/planet/ErekirPlanetGenerator.java index 9f774e942b..6f8f09ca3f 100644 --- a/core/src/mindustry/maps/planet/ErekirPlanetGenerator.java +++ b/core/src/mindustry/maps/planet/ErekirPlanetGenerator.java @@ -64,6 +64,12 @@ public class ErekirPlanetGenerator extends PlanetGenerator{ return Loadouts.basicBastion; } + @Override + public boolean allowLanding(Sector sector){ + //TODO disallowed for now + return false; + } + float rawHeight(Vec3 position){ return Simplex.noise3d(seed, octaves, persistence, 1f/heightScl, 10f + position.x, 10f + position.y, 10f + position.z); } diff --git a/core/src/mindustry/ui/dialogs/PlanetDialog.java b/core/src/mindustry/ui/dialogs/PlanetDialog.java index 0673db5990..3d09b34f3f 100644 --- a/core/src/mindustry/ui/dialogs/PlanetDialog.java +++ b/core/src/mindustry/ui/dialogs/PlanetDialog.java @@ -331,7 +331,10 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{ return node == null || node.parent == null || node.parent.content.unlocked(); } - return sector.hasBase() || sector.near().contains(Sector::hasBase); //near an occupied sector + return sector.planet.generator != null ? + //use planet impl when possible + sector.planet.generator.allowLanding(sector) : + sector.hasBase() || sector.near().contains(Sector::hasBase); //near an occupied sector } Sector findLauncher(Sector to){ diff --git a/core/src/mindustry/world/Block.java b/core/src/mindustry/world/Block.java index fdb4e961f5..1195767a33 100644 --- a/core/src/mindustry/world/Block.java +++ b/core/src/mindustry/world/Block.java @@ -23,6 +23,7 @@ import mindustry.game.*; import mindustry.gen.*; import mindustry.graphics.*; import mindustry.graphics.MultiPacker.*; +import mindustry.logic.*; import mindustry.type.*; import mindustry.ui.*; import mindustry.world.blocks.*; @@ -37,7 +38,7 @@ import java.util.*; import static mindustry.Vars.*; -public class Block extends UnlockableContent{ +public class Block extends UnlockableContent implements Senseable{ /** If true, buildings have an ItemModule. */ public boolean hasItems; /** If true, buildings have a LiquidModule. */ @@ -1148,4 +1149,28 @@ public class Block extends UnlockableContent{ req.rotation = Mathf.mod(req.rotation + 2, 4); } } + + @Override + public double sense(LAccess sensor){ + return switch(sensor){ + case color -> Color.toDoubleBits(mapColor.r, mapColor.g, mapColor.b, mapColor.a); + case health, maxHealth -> health; + case size -> size * tilesize; + case itemCapacity -> itemCapacity; + case liquidCapacity -> liquidCapacity; + case powerCapacity -> consumes.hasPower() && consumes.getPower().buffered ? consumes.getPower().capacity : 0f; + default -> Double.NaN; + }; + } + + @Override + public double sense(Content content){ + return Double.NaN; + } + + @Override + public Object senseObject(LAccess sensor){ + if(sensor == LAccess.name) return name; + return noSensed; + } } diff --git a/gradle.properties b/gradle.properties index 595e0e34dd..7e9e4ce0a8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -24,4 +24,4 @@ android.useAndroidX=true #used for slow jitpack builds; TODO see if this actually works org.gradle.internal.http.socketTimeout=100000 org.gradle.internal.http.connectionTimeout=100000 -archash=5babd5fc94 +archash=a1e1841832