diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index e9805b2eb0..260c5af651 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -2315,6 +2315,8 @@ lst.getblock = Get tile data at any location. lst.setblock = Set tile data at any location. lst.spawnunit = Spawn unit at a location. lst.applystatus = Apply or clear a status effect from a unit. +lst.weathersensor = Check if a type of weather is active. +lst.weatherset = Set the current state of a type of weather. lst.spawnwave = Spawn a wave. lst.explosion = Create an explosion at a location. lst.setrate = Set processor execution speed in instructions/tick. diff --git a/core/src/mindustry/content/Weathers.java b/core/src/mindustry/content/Weathers.java index f0ee71d4ea..d69a6b4b43 100644 --- a/core/src/mindustry/content/Weathers.java +++ b/core/src/mindustry/content/Weathers.java @@ -17,7 +17,7 @@ public class Weathers{ suspendParticles; public static void load(){ - snow = new ParticleWeather("snow"){{ + snow = new ParticleWeather("snowing"){{ particleRegion = "particle"; sizeMax = 13f; sizeMin = 2.6f; diff --git a/core/src/mindustry/core/ContentLoader.java b/core/src/mindustry/core/ContentLoader.java index 91e9c80824..7abaf35f29 100644 --- a/core/src/mindustry/core/ContentLoader.java +++ b/core/src/mindustry/core/ContentLoader.java @@ -314,6 +314,14 @@ public class ContentLoader{ return getByName(ContentType.planet, name); } + public Seq weathers(){ + return getBy(ContentType.weather); + } + + public Weather weather(String name){ + return getByName(ContentType.weather, name); + } + public Seq unitStances(){ return getBy(ContentType.unitStance); } diff --git a/core/src/mindustry/logic/GlobalVars.java b/core/src/mindustry/logic/GlobalVars.java index fa07475c7f..65df2c3821 100644 --- a/core/src/mindustry/logic/GlobalVars.java +++ b/core/src/mindustry/logic/GlobalVars.java @@ -125,6 +125,10 @@ public class GlobalVars{ put("@" + type.name, type); } + for(Weather weather : Vars.content.weathers()){ + put("@" + weather.name, weather); + } + //store sensor constants for(LAccess sensor : LAccess.all){ put("@" + sensor.name(), sensor); diff --git a/core/src/mindustry/logic/LExecutor.java b/core/src/mindustry/logic/LExecutor.java index 8d02218748..ba9b194364 100644 --- a/core/src/mindustry/logic/LExecutor.java +++ b/core/src/mindustry/logic/LExecutor.java @@ -13,8 +13,8 @@ import mindustry.content.*; import mindustry.core.*; import mindustry.ctype.*; import mindustry.entities.*; -import mindustry.game.*; import mindustry.game.EventType.*; +import mindustry.game.*; import mindustry.game.MapObjectives.*; import mindustry.game.Teams.*; import mindustry.gen.*; @@ -1511,6 +1511,47 @@ public class LExecutor{ } } + public static class SenseWeatherI implements LInstruction{ + public int type, to; + + public SenseWeatherI(int type, int to){ + this.type = type; + this.to = to; + } + + @Override + public void run(LExecutor exec){ + exec.setbool(to, exec.obj(type) instanceof Weather weather && weather.isActive()); + } + } + + public static class SetWeatherI implements LInstruction{ + public int type, state; + + public SetWeatherI(int type, int state){ + this.type = type; + this.state = state; + } + + @Override + public void run(LExecutor exec){ + if(exec.obj(type) instanceof Weather weather){ + if(exec.bool(state)){ + if(!weather.isActive()){ //Create is not already active + Tmp.v1.setToRandomDirection(); + Call.createWeather(weather, 1f, WeatherState.fadeTime, Tmp.v1.x, Tmp.v1.y); + }else{ + weather.instance().life(WeatherState.fadeTime); + } + }else{ + if(weather.isActive() && weather.instance().life > WeatherState.fadeTime){ + weather.instance().life(WeatherState.fadeTime); + } + } + } + } + } + public static class ApplyEffectI implements LInstruction{ public boolean clear; public String effect; diff --git a/core/src/mindustry/logic/LStatement.java b/core/src/mindustry/logic/LStatement.java index 939114cc89..42e0c2ee67 100644 --- a/core/src/mindustry/logic/LStatement.java +++ b/core/src/mindustry/logic/LStatement.java @@ -16,7 +16,7 @@ import mindustry.logic.LCanvas.*; import mindustry.logic.LExecutor.*; import mindustry.ui.*; -import static mindustry.Vars.ui; +import static mindustry.Vars.*; import static mindustry.logic.LCanvas.*; /** diff --git a/core/src/mindustry/logic/LStatements.java b/core/src/mindustry/logic/LStatements.java index ceae4740c6..e04293a8e7 100644 --- a/core/src/mindustry/logic/LStatements.java +++ b/core/src/mindustry/logic/LStatements.java @@ -1380,6 +1380,115 @@ public class LStatements{ } } + @RegisterStatement("weathersensor") + public static class WeatherSenseStatement extends LStatement{ + public String to = "result"; + public String weather = "@rain"; + + private transient TextField tfield; + + @Override + public void build(Table table){ + field(table, to, str -> to = str); + + table.add(" = weather "); + + row(table); + + tfield = field(table, weather, str -> weather = str).padRight(0f).get(); + + table.button(b -> { + b.image(Icon.pencilSmall); + + b.clicked(() -> showSelectTable(b, (t, hide) -> { + t.row(); + t.table(i -> { + i.left(); + int c = 0; + for(Weather w : Vars.content.weathers()){ + i.button(w.name, Styles.flatt, () -> { + weather = "@" + w.name; + tfield.setText(weather); + hide.run(); + }).height(40f).uniformX().wrapLabel(false).growX(); + + if(++c % 2 == 0) i.row(); + } + }).left(); + })); + }, Styles.logict, () -> {}).size(40f).padLeft(-1).color(table.color); + } + + @Override + public boolean privileged(){ + return true; + } + + @Override + public LInstruction build(LAssembler builder){ + return new SenseWeatherI(builder.var(weather), builder.var(to)); + } + + @Override + public LCategory category(){ + return LCategory.world; + } + } + + @RegisterStatement("weatherset") + public static class WeatherSetStatement extends LStatement{ + public String weather = "@rain", state = "true"; + + private transient TextField tfield; + + @Override + public void build(Table table){ + table.add(" set weather "); + + tfield = field(table, weather, str -> weather = str).padRight(0f).get(); + + table.button(b -> { + b.image(Icon.pencilSmall); + + b.clicked(() -> showSelectTable(b, (t, hide) -> { + t.row(); + t.table(i -> { + i.left(); + int c = 0; + for(Weather w : Vars.content.weathers()){ + i.button(w.name, Styles.flatt, () -> { + weather = "@" + w.name; + tfield.setText(weather); + hide.run(); + }).height(40f).uniformX().wrapLabel(false).growX(); + + if(++c % 2 == 0) i.row(); + } + }).left(); + })); + }, Styles.logict, () -> {}).size(40f).padLeft(-1).color(table.color); + + table.add(" state "); + + fields(table, state, str -> state = str); + } + + @Override + public boolean privileged(){ + return true; + } + + @Override + public LInstruction build(LAssembler builder){ + return new SetWeatherI(builder.var(weather), builder.var(state)); + } + + @Override + public LCategory category(){ + return LCategory.world; + } + } + @RegisterStatement("spawnwave") public static class SpawnWaveStatement extends LStatement{ public String x = "10", y = "10", natural = "false"; diff --git a/core/src/mindustry/type/Weather.java b/core/src/mindustry/type/Weather.java index 286b7880fa..d8b7618ccc 100644 --- a/core/src/mindustry/type/Weather.java +++ b/core/src/mindustry/type/Weather.java @@ -314,7 +314,7 @@ public class Weather extends UnlockableContent{ @EntityDef(value = {WeatherStatec.class}, pooled = true, isFinal = false) @Component(base = true) abstract static class WeatherStateComp implements Drawc, Syncc{ - private static final float fadeTime = 60 * 4; + public static final float fadeTime = 60 * 4; Weather weather; float intensity = 1f, opacity = 0f, life, effectTimer;