From 3ed5282e14839114e30a89638c4d7a45af3a8d81 Mon Sep 17 00:00:00 2001 From: Anuken Date: Sun, 1 Mar 2020 12:15:38 -0500 Subject: [PATCH] Better sector null checks --- core/src/mindustry/core/Logic.java | 2 +- core/src/mindustry/core/World.java | 2 +- core/src/mindustry/game/Universe.java | 14 ++++++++------ .../maps/generators/FileMapGenerator.java | 2 +- core/src/mindustry/ui/dialogs/GameOverDialog.java | 2 +- core/src/mindustry/ui/fragments/HudFragment.java | 2 +- desktop/src/mindustry/desktop/steam/SStats.java | 2 +- 7 files changed, 14 insertions(+), 12 deletions(-) diff --git a/core/src/mindustry/core/Logic.java b/core/src/mindustry/core/Logic.java index d6c038b860..bb76368817 100644 --- a/core/src/mindustry/core/Logic.java +++ b/core/src/mindustry/core/Logic.java @@ -130,7 +130,7 @@ public class Logic implements ApplicationListener{ public void runWave(){ spawner.spawnEnemies(); state.wave++; - state.wavetime = state.isCampaign() && state.getSector().isLaunchWave(state.wave) ? state.rules.waveSpacing * state.rules.launchWaveMultiplier : state.rules.waveSpacing; + state.wavetime = state.hasSector() && state.getSector().isLaunchWave(state.wave) ? state.rules.waveSpacing * state.rules.launchWaveMultiplier : state.rules.waveSpacing; Events.fire(new WaveEvent()); } diff --git a/core/src/mindustry/core/World.java b/core/src/mindustry/core/World.java index f52fafd4b7..e1e3d64196 100644 --- a/core/src/mindustry/core/World.java +++ b/core/src/mindustry/core/World.java @@ -344,7 +344,7 @@ public class World{ } //TODO tweak noise and radius - if(state.isCampaign()){ + if(state.hasSector()){ int circleBlend = 14; //quantized angle float offset = state.getSector().rect.rotation + 90; diff --git a/core/src/mindustry/game/Universe.java b/core/src/mindustry/game/Universe.java index c7912018f1..94b0d2d99d 100644 --- a/core/src/mindustry/game/Universe.java +++ b/core/src/mindustry/game/Universe.java @@ -44,12 +44,14 @@ public class Universe{ } } - //update sector light - float light = state.getSector().getLight(); - float alpha = Mathf.clamp(Mathf.map(light, 0f, 0.8f, 0.1f, 1f)); - //assign and map so darkness is not 100% dark - state.rules.ambientLight.a = 1f - alpha; - state.rules.lighting = !Mathf.equal(alpha, 1f); + if(state.hasSector()){ + //update sector light + float light = state.getSector().getLight(); + float alpha = Mathf.clamp(Mathf.map(light, 0f, 0.8f, 0.1f, 1f)); + //assign and map so darkness is not 100% dark + state.rules.ambientLight.a = 1f - alpha; + state.rules.lighting = !Mathf.equal(alpha, 1f); + } } public float secondsMod(float mod, float scale){ diff --git a/core/src/mindustry/maps/generators/FileMapGenerator.java b/core/src/mindustry/maps/generators/FileMapGenerator.java index c1c13af4a9..653c8a64a9 100644 --- a/core/src/mindustry/maps/generators/FileMapGenerator.java +++ b/core/src/mindustry/maps/generators/FileMapGenerator.java @@ -27,7 +27,7 @@ public class FileMapGenerator implements WorldGenerator{ SaveIO.load(map.file); for(Tile tile : tiles){ - if(tile.block() instanceof StorageBlock && !(tile.block() instanceof CoreBlock) && state.getSector() != null){ + if(tile.block() instanceof StorageBlock && !(tile.block() instanceof CoreBlock) && state.hasSector()){ for(Content content : state.getSector().data.resources){ if(content instanceof Item && Mathf.chance(0.3)){ tile.entity.items().add((Item)content, Math.min(Mathf.random(500), tile.block().itemCapacity)); diff --git a/core/src/mindustry/ui/dialogs/GameOverDialog.java b/core/src/mindustry/ui/dialogs/GameOverDialog.java index e805923b17..a012b6c7a0 100644 --- a/core/src/mindustry/ui/dialogs/GameOverDialog.java +++ b/core/src/mindustry/ui/dialogs/GameOverDialog.java @@ -80,7 +80,7 @@ public class GameOverDialog extends FloatingDialog{ } } - if(state.isCampaign()){ + if(state.hasSector()){ RankResult result = state.stats.calculateRank(state.getSector(), state.launched); t.add(Core.bundle.format("stat.rank", result.rank + result.modifier)); t.row(); diff --git a/core/src/mindustry/ui/fragments/HudFragment.java b/core/src/mindustry/ui/fragments/HudFragment.java index 7cfd2def50..5963fe50bd 100644 --- a/core/src/mindustry/ui/fragments/HudFragment.java +++ b/core/src/mindustry/ui/fragments/HudFragment.java @@ -497,7 +497,7 @@ public class HudFragment extends Fragment{ } private boolean inLaunchWave(){ - return state.isCampaign() && + return state.hasSector() && state.getSector().metCondition() && !net.client() && state.wave % state.getSector().launchPeriod == 0 && !spawner.isSpawning(); diff --git a/desktop/src/mindustry/desktop/steam/SStats.java b/desktop/src/mindustry/desktop/steam/SStats.java index 39c3dca136..a2ddfa675a 100644 --- a/desktop/src/mindustry/desktop/steam/SStats.java +++ b/desktop/src/mindustry/desktop/steam/SStats.java @@ -231,7 +231,7 @@ public class SStats implements SteamUserStatsCallback{ }); Events.on(WinEvent.class, e -> { - if(campaign()){ + if(state.hasSector()){ if(Vars.state.wave <= 5 && state.rules.attackMode){ defeatAttack5Waves.complete(); }