Always-on weather rule support

This commit is contained in:
Anuken
2020-12-18 13:36:18 -05:00
parent b0bf80d8b7
commit b33b3a7919
5 changed files with 21 additions and 10 deletions

View File

@ -957,6 +957,7 @@ rules.explosions = Block/Unit Explosion Damage
rules.ambientlight = Ambient Light
rules.weather = Weather
rules.weather.frequency = Frequency:
rules.weather.always = Always
rules.weather.duration = Duration:
content.item.name = Items

View File

@ -258,13 +258,12 @@ public class Logic implements ApplicationListener{
state.rules.weather.removeAll(w -> w.weather == null);
for(WeatherEntry entry : state.rules.weather){
if(entry.weather == null) continue;
//update cooldown
entry.cooldown -= Time.delta;
//create new event when not active
if(entry.cooldown < 0 && !entry.weather.isActive()){
float duration = Mathf.random(entry.minDuration, entry.maxDuration);
if((entry.cooldown < 0 || entry.always) && !entry.weather.isActive()){
float duration = entry.always ? Float.POSITIVE_INFINITY : Mathf.random(entry.minDuration, entry.maxDuration);
entry.cooldown = duration + Mathf.random(entry.minFrequency, entry.maxFrequency);
Tmp.v1.setToRandomDirection();
Call.createWeather(entry.weather, entry.intensity, duration, Tmp.v1.x, Tmp.v1.y);

View File

@ -61,12 +61,17 @@ public class Weather extends UnlockableContent{
return entity;
}
@Nullable
public WeatherState instance(){
return Groups.weather.find(w -> w.weather() == this);
}
public boolean isActive(){
return Groups.weather.find(w -> w.weather() == this) != null;
return instance() != null;
}
public void remove(){
Entityc e = Groups.weather.find(w -> w.weather() == this);
var e = instance();
if(e != null) e.remove();
}
@ -259,6 +264,8 @@ public class Weather extends UnlockableContent{
public float cooldown;
/** Intensity of the weather produced. */
public float intensity = 1f;
/** If true, this weather is always active. */
public boolean always = false;
/** Creates a weather entry with some approximate weather values. */
public WeatherEntry(Weather weather){

View File

@ -284,19 +284,23 @@ public class CustomRulesDialog extends BaseDialog{
f.defaults().padRight(4).left();
f.add("@rules.weather.duration");
field(f, entry.minDuration / toMinutes, v -> entry.minDuration = v * toMinutes);
field(f, entry.minDuration / toMinutes, v -> entry.minDuration = v * toMinutes).disabled(v -> entry.always);
f.add("@waves.to");
field(f, entry.maxDuration / toMinutes, v -> entry.maxDuration = v * toMinutes);
field(f, entry.maxDuration / toMinutes, v -> entry.maxDuration = v * toMinutes).disabled(v -> entry.always);
f.add("@unit.minutes");
f.row();
f.add("@rules.weather.frequency");
field(f, entry.minFrequency / toMinutes, v -> entry.minFrequency = v * toMinutes);
field(f, entry.minFrequency / toMinutes, v -> entry.minFrequency = v * toMinutes).disabled(v -> entry.always);
f.add("@waves.to");
field(f, entry.maxFrequency / toMinutes, v -> entry.maxFrequency = v * toMinutes);
field(f, entry.maxFrequency / toMinutes, v -> entry.maxFrequency = v * toMinutes).disabled(v -> entry.always);
f.add("@unit.minutes");
f.row();
f.check("@rules.weather.always", val -> entry.always = val).checked(cc -> entry.always).padBottom(4);
//intensity can't currently be customized
}).grow().left().pad(6).top();

View File

@ -1,3 +1,3 @@
org.gradle.daemon=true
org.gradle.jvmargs=-Xms256m -Xmx1024m
archash=9b130afd1b8b6899c8c39843622842930c8ddcbf
archash=b647f8dd4e96daf1ed869f1fd1fb38bb3f37135c