From f9f12843d2752480babec3d7b30e257e25c44131 Mon Sep 17 00:00:00 2001 From: Anuken Date: Sun, 13 Feb 2022 19:59:57 -0500 Subject: [PATCH] Logic explosion statement --- .../mindustry/entities/comp/BuildingComp.java | 14 +++---- .../mindustry/graphics/OverlayRenderer.java | 2 +- core/src/mindustry/logic/LExecutor.java | 3 +- core/src/mindustry/logic/LStatements.java | 42 ++++++++++++++++--- 4 files changed, 45 insertions(+), 16 deletions(-) diff --git a/core/src/mindustry/entities/comp/BuildingComp.java b/core/src/mindustry/entities/comp/BuildingComp.java index 96115c6711..881178fa86 100644 --- a/core/src/mindustry/entities/comp/BuildingComp.java +++ b/core/src/mindustry/entities/comp/BuildingComp.java @@ -109,7 +109,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc, set(tile.drawx(), tile.drawy()); - if(shouldAdd && shouldUpdate()){ + if(shouldAdd){ add(); } @@ -491,7 +491,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc, } /** @return whether this block is allowed to update based on team/environment */ - public boolean shouldUpdate(){ + public boolean allowUpdate(){ return team != Team.derelict && block.supportsEnv(state.rules.environment); } @@ -524,7 +524,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc, /** Call when this entity is updating. This wakes it up. */ public void noSleep(){ sleepTime = 0f; - if(sleeping && shouldUpdate()){ + if(sleeping){ add(); sleeping = false; sleepingEntities--; @@ -1508,10 +1508,6 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc, this.team = next; indexer.addIndex(tile); Events.fire(teamChangeEvent.set(last, self())); - - if(!shouldUpdate()){ - remove(); - } } public boolean canPickup(){ @@ -1783,6 +1779,10 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc, timeScale = 1f; } + if(!allowUpdate()){ + enabled = false; + } + //TODO unacceptable overhead? if(!enabled && block.autoResetEnabled){ noSleep(); diff --git a/core/src/mindustry/graphics/OverlayRenderer.java b/core/src/mindustry/graphics/OverlayRenderer.java index ff6c35da30..6589f8d6e9 100644 --- a/core/src/mindustry/graphics/OverlayRenderer.java +++ b/core/src/mindustry/graphics/OverlayRenderer.java @@ -206,7 +206,7 @@ public class OverlayRenderer{ if(build != null && build.team == player.team()){ build.drawSelect(); - if((!build.enabled && build.block.drawDisabled) || !build.shouldUpdate()){ + if(!build.enabled && build.block.drawDisabled){ build.drawDisabled(); } diff --git a/core/src/mindustry/logic/LExecutor.java b/core/src/mindustry/logic/LExecutor.java index a4f60fca92..365d49573c 100644 --- a/core/src/mindustry/logic/LExecutor.java +++ b/core/src/mindustry/logic/LExecutor.java @@ -1234,7 +1234,7 @@ public class LExecutor{ public static class SpawnUnitI implements LInstruction{ public int type, x, y, rotation, team, result; - public SpawnUnitI(int type, int x, int y, int rotation, int team, boolean effect, int result){ + public SpawnUnitI(int type, int x, int y, int rotation, int team, int result){ this.type = type; this.x = x; this.y = y; @@ -1356,7 +1356,6 @@ public class LExecutor{ @Remote(called = Loc.server, unreliable = true) public static void logicExplosion(Team team, float x, float y, float radius, float damage, boolean air, boolean ground, boolean pierce){ - Damage.damage(team, x, y, radius, damage, pierce, air, ground); if(pierce){ Fx.spawnShockwave.at(x, y, World.conv(radius)); diff --git a/core/src/mindustry/logic/LStatements.java b/core/src/mindustry/logic/LStatements.java index 53e6805d72..446872777f 100644 --- a/core/src/mindustry/logic/LStatements.java +++ b/core/src/mindustry/logic/LStatements.java @@ -1191,7 +1191,6 @@ public class LStatements{ @RegisterStatement("spawn") public static class SpawnUnitStatement extends LStatement{ public String type = "@dagger", x = "10", y = "10", rotation = "90", team = "@sharded", result = "result"; - public boolean effect = true; @Override public void build(Table table){ @@ -1217,10 +1216,6 @@ public class LStatements{ table.add(" rot "); fields(table, rotation, str -> rotation = str).left(); - - //effect mostly unnecessary and looks bad - //row(table); - //table.check("effect", effect, val -> effect = val); } @Override @@ -1235,7 +1230,7 @@ public class LStatements{ @Override public LInstruction build(LAssembler builder){ - return new SpawnUnitI(builder.var(type), builder.var(x), builder.var(y), builder.var(rotation), builder.var(team), effect, builder.var(result)); + return new SpawnUnitI(builder.var(type), builder.var(x), builder.var(y), builder.var(rotation), builder.var(team), builder.var(result)); } } @@ -1373,4 +1368,39 @@ public class LStatements{ return new CutsceneI(action, builder.var(p1), builder.var(p2), builder.var(p3), builder.var(p4)); } } + + @RegisterStatement("explosion") + public static class ExplosionStatement extends LStatement{ + public String team = "@crux", x = "0", y = "0", radius = "5", damage = "50", air = "true", ground = "true", pierce = "false"; + + @Override + public void build(Table table){ + fields(table, "team", team, str -> team = str); + fields(table, "x", x, str -> x = str); + row(table); + fields(table, "y", y, str -> y = str); + fields(table, "radius", radius, str -> radius = str); + table.row(); + fields(table, "damage", damage, str -> damage = str); + fields(table, "air", air, str -> air = str); + row(table); + fields(table, "ground", ground, str -> ground = str); + fields(table, "pierce", pierce, str -> pierce = str); + } + + @Override + public boolean privileged(){ + return true; + } + + @Override + public Color color(){ + return Pal.logicWorld; + } + + @Override + public LInstruction build(LAssembler b){ + return new ExplosionI(b.var(team), b.var(x), b.var(y), b.var(radius), b.var(damage), b.var(air), b.var(ground), b.var(pierce)); + } + } }