From b33b3a79195526de59d9a88c75e4a0a2f21d8eeb Mon Sep 17 00:00:00 2001 From: Anuken Date: Fri, 18 Dec 2020 13:36:18 -0500 Subject: [PATCH] Always-on weather rule support --- core/assets/bundles/bundle.properties | 1 + core/src/mindustry/core/Logic.java | 5 ++--- core/src/mindustry/type/Weather.java | 11 +++++++++-- core/src/mindustry/ui/dialogs/CustomRulesDialog.java | 12 ++++++++---- gradle.properties | 2 +- 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index cb194c37cc..247fc13932 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -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 diff --git a/core/src/mindustry/core/Logic.java b/core/src/mindustry/core/Logic.java index bb91fc824e..5b7349e78e 100644 --- a/core/src/mindustry/core/Logic.java +++ b/core/src/mindustry/core/Logic.java @@ -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); diff --git a/core/src/mindustry/type/Weather.java b/core/src/mindustry/type/Weather.java index 48a05219f5..c6ae657bc9 100644 --- a/core/src/mindustry/type/Weather.java +++ b/core/src/mindustry/type/Weather.java @@ -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){ diff --git a/core/src/mindustry/ui/dialogs/CustomRulesDialog.java b/core/src/mindustry/ui/dialogs/CustomRulesDialog.java index 4d6a4483f9..234068bfd5 100644 --- a/core/src/mindustry/ui/dialogs/CustomRulesDialog.java +++ b/core/src/mindustry/ui/dialogs/CustomRulesDialog.java @@ -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(); diff --git a/gradle.properties b/gradle.properties index e304188492..5271fb2c42 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ org.gradle.daemon=true org.gradle.jvmargs=-Xms256m -Xmx1024m -archash=9b130afd1b8b6899c8c39843622842930c8ddcbf +archash=b647f8dd4e96daf1ed869f1fd1fb38bb3f37135c