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:
@@ -2315,6 +2315,8 @@ lst.getblock = Get tile data at any location.
|
|||||||
lst.setblock = Set tile data at any location.
|
lst.setblock = Set tile data at any location.
|
||||||
lst.spawnunit = Spawn unit at a location.
|
lst.spawnunit = Spawn unit at a location.
|
||||||
lst.applystatus = Apply or clear a status effect from a unit.
|
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.spawnwave = Spawn a wave.
|
||||||
lst.explosion = Create an explosion at a location.
|
lst.explosion = Create an explosion at a location.
|
||||||
lst.setrate = Set processor execution speed in instructions/tick.
|
lst.setrate = Set processor execution speed in instructions/tick.
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ public class Weathers{
|
|||||||
suspendParticles;
|
suspendParticles;
|
||||||
|
|
||||||
public static void load(){
|
public static void load(){
|
||||||
snow = new ParticleWeather("snow"){{
|
snow = new ParticleWeather("snowing"){{
|
||||||
particleRegion = "particle";
|
particleRegion = "particle";
|
||||||
sizeMax = 13f;
|
sizeMax = 13f;
|
||||||
sizeMin = 2.6f;
|
sizeMin = 2.6f;
|
||||||
|
|||||||
@@ -314,6 +314,14 @@ public class ContentLoader{
|
|||||||
return getByName(ContentType.planet, name);
|
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(){
|
public Seq<UnitStance> unitStances(){
|
||||||
return getBy(ContentType.unitStance);
|
return getBy(ContentType.unitStance);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -125,6 +125,10 @@ public class GlobalVars{
|
|||||||
put("@" + type.name, type);
|
put("@" + type.name, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(Weather weather : Vars.content.weathers()){
|
||||||
|
put("@" + weather.name, weather);
|
||||||
|
}
|
||||||
|
|
||||||
//store sensor constants
|
//store sensor constants
|
||||||
for(LAccess sensor : LAccess.all){
|
for(LAccess sensor : LAccess.all){
|
||||||
put("@" + sensor.name(), sensor);
|
put("@" + sensor.name(), sensor);
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ import mindustry.content.*;
|
|||||||
import mindustry.core.*;
|
import mindustry.core.*;
|
||||||
import mindustry.ctype.*;
|
import mindustry.ctype.*;
|
||||||
import mindustry.entities.*;
|
import mindustry.entities.*;
|
||||||
import mindustry.game.*;
|
|
||||||
import mindustry.game.EventType.*;
|
import mindustry.game.EventType.*;
|
||||||
|
import mindustry.game.*;
|
||||||
import mindustry.game.MapObjectives.*;
|
import mindustry.game.MapObjectives.*;
|
||||||
import mindustry.game.Teams.*;
|
import mindustry.game.Teams.*;
|
||||||
import mindustry.gen.*;
|
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 static class ApplyEffectI implements LInstruction{
|
||||||
public boolean clear;
|
public boolean clear;
|
||||||
public String effect;
|
public String effect;
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import mindustry.logic.LCanvas.*;
|
|||||||
import mindustry.logic.LExecutor.*;
|
import mindustry.logic.LExecutor.*;
|
||||||
import mindustry.ui.*;
|
import mindustry.ui.*;
|
||||||
|
|
||||||
import static mindustry.Vars.ui;
|
import static mindustry.Vars.*;
|
||||||
import static mindustry.logic.LCanvas.*;
|
import static mindustry.logic.LCanvas.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -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")
|
@RegisterStatement("spawnwave")
|
||||||
public static class SpawnWaveStatement extends LStatement{
|
public static class SpawnWaveStatement extends LStatement{
|
||||||
public String x = "10", y = "10", natural = "false";
|
public String x = "10", y = "10", natural = "false";
|
||||||
|
|||||||
@@ -314,7 +314,7 @@ public class Weather extends UnlockableContent{
|
|||||||
@EntityDef(value = {WeatherStatec.class}, pooled = true, isFinal = false)
|
@EntityDef(value = {WeatherStatec.class}, pooled = true, isFinal = false)
|
||||||
@Component(base = true)
|
@Component(base = true)
|
||||||
abstract static class WeatherStateComp implements Drawc, Syncc{
|
abstract static class WeatherStateComp implements Drawc, Syncc{
|
||||||
private static final float fadeTime = 60 * 4;
|
public static final float fadeTime = 60 * 4;
|
||||||
|
|
||||||
Weather weather;
|
Weather weather;
|
||||||
float intensity = 1f, opacity = 0f, life, effectTimer;
|
float intensity = 1f, opacity = 0f, life, effectTimer;
|
||||||
|
|||||||
Reference in New Issue
Block a user