diff --git a/core/src/mindustry/core/Control.java b/core/src/mindustry/core/Control.java index 206248d0f4..bdaa09c1d7 100644 --- a/core/src/mindustry/core/Control.java +++ b/core/src/mindustry/core/Control.java @@ -176,7 +176,7 @@ public class Control implements ApplicationListener, Loadable{ }); Events.on(UnitDestroyEvent.class, e -> { - if(world.isCampaign()){ + if(state.isCampaign()){ data.unlockContent(e.unit.type()); } }); @@ -448,7 +448,7 @@ public class Control implements ApplicationListener, Loadable{ if(!state.is(State.menu)){ input.update(); - if(world.isCampaign()){ + if(state.isCampaign()){ for(Tilec tile : state.teams.cores(player.team())){ for(Item item : content.items()){ if(tile.items().has(item)){ diff --git a/core/src/mindustry/core/GameState.java b/core/src/mindustry/core/GameState.java index f546a933f1..e801e86f59 100644 --- a/core/src/mindustry/core/GameState.java +++ b/core/src/mindustry/core/GameState.java @@ -1,11 +1,13 @@ package mindustry.core; import arc.*; +import arc.util.ArcAnnotate.*; import mindustry.game.EventType.*; import mindustry.game.*; import mindustry.gen.*; +import mindustry.type.*; -import static mindustry.Vars.*; +import static mindustry.Vars.net; public class GameState{ /** Current wave number, can be anything in non-wave modes. */ @@ -34,6 +36,20 @@ public class GameState{ state = astate; } + /**Note that being in a campaign does not necessarily mean having a sector. */ + public boolean isCampaign(){ + return rules.sector != null; + } + + public boolean hasSector(){ + return rules.sector != null; + } + + @Nullable + public Sector getSector(){ + return rules.sector; + } + public boolean isEditor(){ return rules.editor; } diff --git a/core/src/mindustry/core/Logic.java b/core/src/mindustry/core/Logic.java index 812f9f6d6e..d6c038b860 100644 --- a/core/src/mindustry/core/Logic.java +++ b/core/src/mindustry/core/Logic.java @@ -31,9 +31,9 @@ public class Logic implements ApplicationListener{ public Logic(){ Events.on(WaveEvent.class, event -> { - if(world.isCampaign()){ + if(state.isCampaign()){ //TODO implement - //world.getSector().updateWave(state.wave); + //state.getSector().updateWave(state.wave); } }); @@ -101,7 +101,7 @@ public class Logic implements ApplicationListener{ Events.fire(new PlayEvent()); //add starting items - if(!world.isCampaign()){ + if(!state.isCampaign()){ for(TeamData team : state.teams.getActive()){ if(team.hasCore()){ Tilec entity = team.core(); @@ -130,7 +130,7 @@ public class Logic implements ApplicationListener{ public void runWave(){ spawner.spawnEnemies(); state.wave++; - state.wavetime = world.isCampaign() && world.getSector().isLaunchWave(state.wave) ? state.rules.waveSpacing * state.rules.launchWaveMultiplier : state.rules.waveSpacing; + state.wavetime = state.isCampaign() && state.getSector().isLaunchWave(state.wave) ? state.rules.waveSpacing * state.rules.launchWaveMultiplier : state.rules.waveSpacing; Events.fire(new WaveEvent()); } @@ -152,7 +152,7 @@ public class Logic implements ApplicationListener{ } if(alive != null && !state.gameOver){ - if(world.isCampaign() && alive == state.rules.defaultTeam){ + if(state.isCampaign() && alive == state.rules.defaultTeam){ //in attack maps, a victorious game over is equivalent to a launch Call.launchZone(); }else{ @@ -173,9 +173,9 @@ public class Logic implements ApplicationListener{ Fx.launch.at(tile); } - if(world.isCampaign()){ + if(state.isCampaign()){ //TODO implement - //world.getSector().setLaunched(); + //state.getSector().setLaunched(); } Time.runTask(30f, () -> { @@ -212,7 +212,7 @@ public class Logic implements ApplicationListener{ } if(!state.isPaused()){ - if(world.isCampaign()){ + if(state.isCampaign()){ universe.update(); } Time.update(); diff --git a/core/src/mindustry/core/World.java b/core/src/mindustry/core/World.java index 9a963b3391..f52fafd4b7 100644 --- a/core/src/mindustry/core/World.java +++ b/core/src/mindustry/core/World.java @@ -178,14 +178,6 @@ public class World{ return generating; } - public boolean isCampaign(){ - return getSector() != null; - } - - public Sector getSector(){ - return state.rules.sector; - } - public void loadGenerator(int width, int height, Cons generator){ beginMapLoad(); @@ -352,13 +344,13 @@ public class World{ } //TODO tweak noise and radius - if(world.isCampaign()){ + if(state.isCampaign()){ int circleBlend = 14; //quantized angle - float offset = getSector().rect.rotation + 90; + float offset = state.getSector().rect.rotation + 90; float angle = Angles.angle(x, y, tiles.width/2, tiles.height/2) + offset; //polygon sides, depends on sector - int sides = getSector().tile.corners.length; + int sides = state.getSector().tile.corners.length; float step = 360f / sides; //prev and next angles of poly float prev = Mathf.round(angle, step); diff --git a/core/src/mindustry/ctype/UnlockableContent.java b/core/src/mindustry/ctype/UnlockableContent.java index a6fabd3796..4e1043eb9f 100644 --- a/core/src/mindustry/ctype/UnlockableContent.java +++ b/core/src/mindustry/ctype/UnlockableContent.java @@ -70,7 +70,7 @@ public abstract class UnlockableContent extends MappableContent{ /** @return whether this content is unlocked, or the player is in a custom game. */ public final boolean unlockedCur(){ - return Vars.data.isUnlocked(this) || !Vars.world.isCampaign(); + return Vars.data.isUnlocked(this) || !Vars.state.isCampaign(); } public final boolean locked(){ diff --git a/core/src/mindustry/game/Universe.java b/core/src/mindustry/game/Universe.java index e14c75c757..c7912018f1 100644 --- a/core/src/mindustry/game/Universe.java +++ b/core/src/mindustry/game/Universe.java @@ -45,7 +45,7 @@ public class Universe{ } //update sector light - float light = world.getSector().getLight(); + 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; diff --git a/core/src/mindustry/maps/generators/FileMapGenerator.java b/core/src/mindustry/maps/generators/FileMapGenerator.java index 9be6d4ec5d..c1c13af4a9 100644 --- a/core/src/mindustry/maps/generators/FileMapGenerator.java +++ b/core/src/mindustry/maps/generators/FileMapGenerator.java @@ -27,8 +27,8 @@ public class FileMapGenerator implements WorldGenerator{ SaveIO.load(map.file); for(Tile tile : tiles){ - if(tile.block() instanceof StorageBlock && !(tile.block() instanceof CoreBlock) && world.getSector() != null){ - for(Content content : world.getSector().data.resources){ + if(tile.block() instanceof StorageBlock && !(tile.block() instanceof CoreBlock) && state.getSector() != null){ + 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/DatabaseDialog.java b/core/src/mindustry/ui/dialogs/DatabaseDialog.java index 3ebeddb3f3..b1551349e5 100644 --- a/core/src/mindustry/ui/dialogs/DatabaseDialog.java +++ b/core/src/mindustry/ui/dialogs/DatabaseDialog.java @@ -91,6 +91,6 @@ public class DatabaseDialog extends FloatingDialog{ } boolean unlocked(UnlockableContent content){ - return (!Vars.world.isCampaign() && !Vars.state.is(State.menu)) || content.unlocked(); + return (!Vars.state.isCampaign() && !Vars.state.is(State.menu)) || content.unlocked(); } } diff --git a/core/src/mindustry/ui/dialogs/GameOverDialog.java b/core/src/mindustry/ui/dialogs/GameOverDialog.java index 90ca773a19..e805923b17 100644 --- a/core/src/mindustry/ui/dialogs/GameOverDialog.java +++ b/core/src/mindustry/ui/dialogs/GameOverDialog.java @@ -66,7 +66,7 @@ public class GameOverDialog extends FloatingDialog{ t.add(Core.bundle.format("stat.playtime", control.saves.getCurrent().getPlayTime())); t.row(); } - if(world.isCampaign() && !state.stats.itemsDelivered.isEmpty()){ + if(state.isCampaign() && !state.stats.itemsDelivered.isEmpty()){ t.add("$stat.delivered"); t.row(); for(Item item : content.items()){ @@ -80,14 +80,14 @@ public class GameOverDialog extends FloatingDialog{ } } - if(world.isCampaign()){ - RankResult result = state.stats.calculateRank(world.getSector(), state.launched); + if(state.isCampaign()){ + RankResult result = state.stats.calculateRank(state.getSector(), state.launched); t.add(Core.bundle.format("stat.rank", result.rank + result.modifier)); t.row(); } }).pad(12); - if(world.isCampaign()){ + if(state.isCampaign()){ buttons.addButton("$continue", () -> { hide(); state.set(State.menu); diff --git a/core/src/mindustry/ui/dialogs/PausedDialog.java b/core/src/mindustry/ui/dialogs/PausedDialog.java index 02ff86455f..17f26ac688 100644 --- a/core/src/mindustry/ui/dialogs/PausedDialog.java +++ b/core/src/mindustry/ui/dialogs/PausedDialog.java @@ -41,7 +41,7 @@ public class PausedDialog extends FloatingDialog{ cont.addImageTextButton("$back", Icon.left, this::hide).colspan(2).width(dw * 2 + 20f); cont.row(); - if(world.isCampaign()){ + if(state.isCampaign()){ cont.addImageTextButton("$techtree", Icon.tree, ui.tech::show); }else{ cont.addImageTextButton("$database", Icon.book, ui.database::show); @@ -49,7 +49,7 @@ public class PausedDialog extends FloatingDialog{ cont.addImageTextButton("$settings", Icon.settings, ui.settings::show); if(!state.rules.tutorial){ - if(!world.isCampaign() && !state.isEditor()){ + if(!state.isCampaign() && !state.isEditor()){ cont.row(); cont.addImageTextButton("$savegame", Icon.save, save::show); cont.addImageTextButton("$loadgame", Icon.upload, load::show).disabled(b -> net.active()); @@ -79,7 +79,7 @@ public class PausedDialog extends FloatingDialog{ cont.addRowImageTextButton("$back", Icon.play, this::hide); cont.addRowImageTextButton("$settings", Icon.settings, ui.settings::show); - if(!world.isCampaign() && !state.isEditor()){ + if(!state.isCampaign() && !state.isEditor()){ cont.addRowImageTextButton("$save", Icon.save, save::show); cont.row(); diff --git a/core/src/mindustry/ui/fragments/HudFragment.java b/core/src/mindustry/ui/fragments/HudFragment.java index faf5674491..7cfd2def50 100644 --- a/core/src/mindustry/ui/fragments/HudFragment.java +++ b/core/src/mindustry/ui/fragments/HudFragment.java @@ -84,7 +84,7 @@ public class HudFragment extends Fragment{ }else{ ui.chatfrag.toggle(); } - }else if(world.isCampaign()){ + }else if(state.isCampaign()){ ui.tech.show(); }else{ ui.database.show(); @@ -497,10 +497,10 @@ public class HudFragment extends Fragment{ } private boolean inLaunchWave(){ - return world.isCampaign() && - world.getSector().metCondition() && + return state.isCampaign() && + state.getSector().metCondition() && !net.client() && - state.wave % world.getSector().launchPeriod == 0 && !spawner.isSpawning(); + state.wave % state.getSector().launchPeriod == 0 && !spawner.isSpawning(); } private boolean canLaunch(){ @@ -559,7 +559,7 @@ public class HudFragment extends Fragment{ }else{ builder.append(Core.bundle.get("launch")); builder.append("\n"); - builder.append(Core.bundle.format("launch.next", state.wave + world.getSector().launchPeriod)); + builder.append(Core.bundle.format("launch.next", state.wave + state.getSector().launchPeriod)); builder.append("\n"); } builder.append("[]\n"); diff --git a/core/src/mindustry/ui/fragments/PlacementFragment.java b/core/src/mindustry/ui/fragments/PlacementFragment.java index 29015854c2..c0e4f95a6b 100644 --- a/core/src/mindustry/ui/fragments/PlacementFragment.java +++ b/core/src/mindustry/ui/fragments/PlacementFragment.java @@ -440,7 +440,7 @@ public class PlacementFragment extends Fragment{ } boolean unlocked(Block block){ - return !world.isCampaign() || data.isUnlocked(block); + return !state.isCampaign() || data.isUnlocked(block); } /** Returns the currently displayed block in the top box. */ diff --git a/core/src/mindustry/world/Block.java b/core/src/mindustry/world/Block.java index 0bc210b03d..97fb8d185e 100644 --- a/core/src/mindustry/world/Block.java +++ b/core/src/mindustry/world/Block.java @@ -376,7 +376,7 @@ public class Block extends BlockStorage{ /** Call when some content is produced. This unlocks the content if it is applicable. */ public void useContent(Tile tile, UnlockableContent content){ //only unlocks content in zones - if(!headless && tile.team() == player.team() && world.isCampaign()){ + if(!headless && tile.team() == player.team() && state.isCampaign()){ logic.handleContent(content); } } diff --git a/core/src/mindustry/world/blocks/ItemSelection.java b/core/src/mindustry/world/blocks/ItemSelection.java index fecf5622ea..31929e7ad7 100644 --- a/core/src/mindustry/world/blocks/ItemSelection.java +++ b/core/src/mindustry/world/blocks/ItemSelection.java @@ -24,7 +24,7 @@ public class ItemSelection{ int i = 0; for(T item : items){ - if(!data.isUnlocked(item) && world.isCampaign()) continue; + if(!data.isUnlocked(item) && state.isCampaign()) continue; ImageButton button = cont.addImageButton(Tex.whiteui, Styles.clearToggleTransi, 24, () -> control.input.frag.config.hideConfig()).group(group).get(); button.changed(() -> consumer.get(button.isChecked() ? item : null)); diff --git a/core/src/mindustry/world/blocks/defense/turrets/ItemTurret.java b/core/src/mindustry/world/blocks/defense/turrets/ItemTurret.java index a7e046bc12..4293c2fd1a 100644 --- a/core/src/mindustry/world/blocks/defense/turrets/ItemTurret.java +++ b/core/src/mindustry/world/blocks/defense/turrets/ItemTurret.java @@ -47,7 +47,7 @@ public class ItemTurret extends CooledTurret{ @Override public void build(Tile tile, Table table){ MultiReqImage image = new MultiReqImage(); - content.items().each(i -> filter.get(i) && (!world.isCampaign() || data.isUnlocked(i)), item -> image.add(new ReqImage(new ItemImage(item.icon(Cicon.medium)), + content.items().each(i -> filter.get(i) && (!state.isCampaign() || data.isUnlocked(i)), item -> image.add(new ReqImage(new ItemImage(item.icon(Cicon.medium)), () -> tile.entity != null && !((ItemTurretEntity)tile.entity).ammo.isEmpty() && ((ItemEntry)tile.ent().ammo.peek()).item == item))); table.add(image).size(8 * 4); diff --git a/core/src/mindustry/world/blocks/storage/LaunchPad.java b/core/src/mindustry/world/blocks/storage/LaunchPad.java index 2f9604afa3..d33e5f0041 100644 --- a/core/src/mindustry/world/blocks/storage/LaunchPad.java +++ b/core/src/mindustry/world/blocks/storage/LaunchPad.java @@ -16,8 +16,7 @@ import mindustry.world.Tile; import mindustry.world.meta.BlockStat; import mindustry.world.meta.StatUnit; -import static mindustry.Vars.data; -import static mindustry.Vars.world; +import static mindustry.Vars.*; public class LaunchPad extends StorageBlock{ public final int timerLaunch = timers++; @@ -73,7 +72,7 @@ public class LaunchPad extends StorageBlock{ public void update(Tile tile){ Tilec entity = tile.entity; - if(world.isCampaign() && entity.consValid() && entity.items().total() >= itemCapacity && entity.timer(timerLaunch, launchTime / entity.timeScale())){ + if(state.isCampaign() && entity.consValid() && entity.items().total() >= itemCapacity && entity.timer(timerLaunch, launchTime / entity.timeScale())){ for(Item item : Vars.content.items()){ Events.fire(Trigger.itemLaunch); Fx.padlaunch.at(tile); diff --git a/core/src/mindustry/world/consumers/ConsumeItemFilter.java b/core/src/mindustry/world/consumers/ConsumeItemFilter.java index c8daa86803..9a3a011882 100644 --- a/core/src/mindustry/world/consumers/ConsumeItemFilter.java +++ b/core/src/mindustry/world/consumers/ConsumeItemFilter.java @@ -35,7 +35,7 @@ public class ConsumeItemFilter extends Consume{ @Override public void build(Tile tile, Table table){ MultiReqImage image = new MultiReqImage(); - content.items().each(i -> filter.get(i) && (!world.isCampaign() || data.isUnlocked(i)), item -> image.add(new ReqImage(new ItemImage(item.icon(Cicon.medium), 1), () -> tile.entity != null && tile.entity.items() != null && tile.entity.items().has(item)))); + content.items().each(i -> filter.get(i) && (!state.isCampaign() || data.isUnlocked(i)), item -> image.add(new ReqImage(new ItemImage(item.icon(Cicon.medium), 1), () -> tile.entity != null && tile.entity.items() != null && tile.entity.items().has(item)))); table.add(image).size(8 * 4); } diff --git a/core/src/mindustry/world/meta/BuildVisibility.java b/core/src/mindustry/world/meta/BuildVisibility.java index 62b3e6ce60..ccf9ccaa72 100644 --- a/core/src/mindustry/world/meta/BuildVisibility.java +++ b/core/src/mindustry/world/meta/BuildVisibility.java @@ -8,7 +8,7 @@ public enum BuildVisibility{ shown(() -> true), debugOnly(() -> false), sandboxOnly(() -> Vars.state.rules.infiniteResources), - campaignOnly(() -> Vars.world.isCampaign()), + campaignOnly(() -> Vars.state.isCampaign()), lightingOnly(() -> Vars.state.rules.lighting); private final Boolp visible; diff --git a/desktop/src/mindustry/desktop/steam/SStats.java b/desktop/src/mindustry/desktop/steam/SStats.java index 0efa181776..39c3dca136 100644 --- a/desktop/src/mindustry/desktop/steam/SStats.java +++ b/desktop/src/mindustry/desktop/steam/SStats.java @@ -188,7 +188,7 @@ public class SStats implements SteamUserStatsCallback{ Events.on(LoseEvent.class, e -> { if(campaign()){ //TODO implement - //if(world.getSector().metCondition() && (state.wave - world.getSector().conditionWave) / world.getSector().launchPeriod >= 1){ + //if(state.getSector().metCondition() && (state.wave - state.getSector().conditionWave) / state.getSector().launchPeriod >= 1){ // skipLaunching2Death.complete(); //} } @@ -240,7 +240,7 @@ public class SStats implements SteamUserStatsCallback{ SStat.attacksWon.add(); } - RankResult result = state.stats.calculateRank(world.getSector(), state.launched); + RankResult result = state.stats.calculateRank(state.getSector(), state.launched); if(result.rank == Rank.S) earnSRank.complete(); if(result.rank == Rank.SS) earnSSRank.complete(); } @@ -274,7 +274,7 @@ public class SStats implements SteamUserStatsCallback{ } private boolean campaign(){ - return Vars.world.isCampaign(); + return Vars.state.isCampaign(); } @Override