Weather with World Logic (#9621)

* Weather sense

Honestly, doesn't seem game changing enough to warrant privileged restriction.

* Weather set

* Rename "snow" to "snowing"

Fix conflict with the snow floor block, though I don't know if this'll have negative repercussions on saves.

* Don't last forever

* Cleanup and bundle

* add space
This commit is contained in:
MEEPofFaith
2024-03-14 11:25:03 -07:00
committed by GitHub
parent 3f46080f42
commit 60c6e03d32
8 changed files with 168 additions and 4 deletions

View File

@@ -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;

View File

@@ -314,6 +314,14 @@ public class ContentLoader{
return getByName(ContentType.planet, name);
}
public Seq<Weather> weathers(){
return getBy(ContentType.weather);
}
public Weather weather(String name){
return getByName(ContentType.weather, name);
}
public Seq<UnitStance> unitStances(){
return getBy(ContentType.unitStance);
}

View File

@@ -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);

View File

@@ -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;

View File

@@ -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.*;
/**

View File

@@ -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";

View File

@@ -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;