From ac039ce7cd3b503a4e9dad02624d68cf2b5c97e6 Mon Sep 17 00:00:00 2001 From: Anuken Date: Tue, 17 Jul 2018 19:12:44 -0400 Subject: [PATCH] Fixed sector world gen / Added sector goal unlocks --- core/assets/bundles/bundle.properties | 4 +- core/src/io/anuke/mindustry/core/Control.java | 9 ++++ .../io/anuke/mindustry/core/NetClient.java | 52 +++++-------------- core/src/io/anuke/mindustry/maps/Sector.java | 16 ++++-- core/src/io/anuke/mindustry/maps/Sectors.java | 11 ++-- .../maps/generation/WorldGenerator.java | 2 +- .../io/anuke/mindustry/maps/goals/Goal.java | 5 ++ .../anuke/mindustry/maps/goals/WaveGoal.java | 16 ++++++ .../mindustry/ui/dialogs/SectorsDialog.java | 9 ++-- core/src/io/anuke/mindustry/world/Build.java | 18 ++----- 10 files changed, 74 insertions(+), 68 deletions(-) create mode 100644 core/src/io/anuke/mindustry/maps/goals/Goal.java create mode 100644 core/src/io/anuke/mindustry/maps/goals/WaveGoal.java diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index 7ed0e94c48..da4762e3b2 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -51,9 +51,11 @@ text.customgame=Custom Game text.campaign=Campaign text.sectors=Sectors text.sector=Selected Sector: [LIGHT_GRAY]{0} +text.sector.time=Time: [LIGHT_GRAY]{0} text.sector.deploy=Deploy text.sector.resume=Resume -text.sector.locked=[scarlet][[LOCKED] +text.sector.unlocked=Sector completed! +text.sector.locked=[scarlet][[Incomplete] text.sector.unexplored=[accent][[Unexplored] text.quit=Quit text.maps=Maps diff --git a/core/src/io/anuke/mindustry/core/Control.java b/core/src/io/anuke/mindustry/core/Control.java index 38816ced32..5b3d15af3b 100644 --- a/core/src/io/anuke/mindustry/core/Control.java +++ b/core/src/io/anuke/mindustry/core/Control.java @@ -368,6 +368,15 @@ public class Control extends Module{ input.update(); } + //check unlocked sectors + if(world.getSector() != null && world.getSector().goal.isComplete() && !world.getSector().complete){ + world.sectors().completeSector(world.getSector().x, world.getSector().y); + world.sectors().save(); + if(!headless){ + ui.showInfoFade("$text.sector.unlocked"); + } + } + //check unlocks every 2 seconds if(!state.mode.infiniteResources && Timers.get("timerCheckUnlock", 120)){ checkUnlockableBlocks(); diff --git a/core/src/io/anuke/mindustry/core/NetClient.java b/core/src/io/anuke/mindustry/core/NetClient.java index 4ba984c6d3..c3ed9bd45d 100644 --- a/core/src/io/anuke/mindustry/core/NetClient.java +++ b/core/src/io/anuke/mindustry/core/NetClient.java @@ -41,59 +41,33 @@ public class NetClient extends Module{ private final static float playerSyncTime = 2; private Timer timer = new Timer(5); - /** - * Whether the client is currently connecting. - */ + /**Whether the client is currently connecting.*/ private boolean connecting = false; - /** - * If true, no message will be shown on disconnect. - */ + /**If true, no message will be shown on disconnect.*/ private boolean quiet = false; - /** - * Counter for data timeout. - */ + /**Counter for data timeout.*/ private float timeoutTime = 0f; - /** - * Last sent client snapshot ID. - */ + /**Last sent client snapshot ID.*/ private int lastSent; - /** - * Last snapshot ID recieved. - */ + /**Last snapshot ID recieved.*/ private int lastSnapshotBaseID = -1; - /** - * Last snapshot recieved. - */ + /**Last snapshot recieved.*/ private byte[] lastSnapshotBase; - /** - * Current snapshot that is being built from chinks. - */ + /**Current snapshot that is being built from chinks.*/ private byte[] currentSnapshot; - /** - * Array of recieved chunk statuses. - */ + /**Array of recieved chunk statuses.*/ private boolean[] recievedChunks; - /** - * Counter of how many chunks have been recieved. - */ + /**Counter of how many chunks have been recieved.*/ private int recievedChunkCounter; - /** - * ID of snapshot that is currently being constructed. - */ + /**ID of snapshot that is currently being constructed.*/ private int currentSnapshotID = -1; - /** - * Decoder for uncompressing snapshots. - */ + /**Decoder for uncompressing snapshots.*/ private DEZDecoder decoder = new DEZDecoder(); - /** - * List of entities that were removed, and need not be added while syncing. - */ + /**List of entities that were removed, and need not be added while syncing.*/ private IntSet removed = new IntSet(); - /** - * Byte stream for reading in snapshots. - */ + /**Byte stream for reading in snapshots.*/ private ReusableByteArrayInputStream byteStream = new ReusableByteArrayInputStream(); private DataInputStream dataStream = new DataInputStream(byteStream); diff --git a/core/src/io/anuke/mindustry/maps/Sector.java b/core/src/io/anuke/mindustry/maps/Sector.java index 37dad39fb3..4fda353884 100644 --- a/core/src/io/anuke/mindustry/maps/Sector.java +++ b/core/src/io/anuke/mindustry/maps/Sector.java @@ -1,7 +1,9 @@ package io.anuke.mindustry.maps; import com.badlogic.gdx.graphics.Texture; -import io.anuke.mindustry.io.SaveIO; +import io.anuke.mindustry.game.Saves.SaveSlot; +import io.anuke.mindustry.maps.goals.Goal; +import io.anuke.mindustry.maps.goals.WaveGoal; import io.anuke.ucore.util.Bits; import static io.anuke.mindustry.Vars.control; @@ -9,15 +11,21 @@ import static io.anuke.mindustry.Vars.control; public class Sector{ /**Position on the map, can be positive or negative.*/ public short x, y; - /**Whether this sector has already been captured. TODO statistics?*/ - public boolean unlocked; + /**Whether this sector has already been completed.*/ + public boolean complete; /**Slot ID of this sector's save. -1 means no save has been created.*/ public int saveID = -1; /**Display texture. Needs to be disposed.*/ public transient Texture texture; + /**Goal of this sector-- what needs to be accomplished to unlock it.*/ + public transient Goal goal = new WaveGoal(30); + + public SaveSlot getSave(){ + return control.getSaves().getByID(saveID); + } public boolean hasSave(){ - return saveID != -1 && SaveIO.isSaveValid(saveID) && control.getSaves().getByID(saveID) != null; + return control.getSaves().getByID(saveID) != null; } public int packedPosition(){ diff --git a/core/src/io/anuke/mindustry/maps/Sectors.java b/core/src/io/anuke/mindustry/maps/Sectors.java index aa4273a9b0..39bf308e07 100644 --- a/core/src/io/anuke/mindustry/maps/Sectors.java +++ b/core/src/io/anuke/mindustry/maps/Sectors.java @@ -29,11 +29,10 @@ public class Sectors{ } /**Unlocks a sector. This shows nearby sectors.*/ - public void unlockSector(int x, int y){ + public void completeSector(int x, int y){ createSector(x, y); Sector sector = get(x, y); - sector.unlocked = true; - if(sector.texture == null) createTexture(sector); + sector.complete = true; for(GridPoint2 point : Geometry.d4){ createSector(sector.x + point.x, sector.y + point.y); @@ -47,8 +46,10 @@ public class Sectors{ Sector sector = new Sector(); sector.x = (short)x; sector.y = (short)y; - sector.unlocked = false; + sector.complete = false; grid.put(x, y, sector); + + if(sector.texture == null) createTexture(sector); } public void load(){ @@ -60,7 +61,7 @@ public class Sectors{ } if(out.size == 0){ - unlockSector(0, 0); + createSector(0, 0); } } diff --git a/core/src/io/anuke/mindustry/maps/generation/WorldGenerator.java b/core/src/io/anuke/mindustry/maps/generation/WorldGenerator.java index ec208c6e62..6236d34152 100644 --- a/core/src/io/anuke/mindustry/maps/generation/WorldGenerator.java +++ b/core/src/io/anuke/mindustry/maps/generation/WorldGenerator.java @@ -223,7 +223,7 @@ public class WorldGenerator{ double border = 14; if(edgeDist < border){ - elevation += (border - edgeDist) / 6.0; + // elevation += (border - edgeDist) / 6.0; } if(temp < 0.35){ diff --git a/core/src/io/anuke/mindustry/maps/goals/Goal.java b/core/src/io/anuke/mindustry/maps/goals/Goal.java new file mode 100644 index 0000000000..c0ad1bd509 --- /dev/null +++ b/core/src/io/anuke/mindustry/maps/goals/Goal.java @@ -0,0 +1,5 @@ +package io.anuke.mindustry.maps.goals; + +public interface Goal{ + boolean isComplete(); +} diff --git a/core/src/io/anuke/mindustry/maps/goals/WaveGoal.java b/core/src/io/anuke/mindustry/maps/goals/WaveGoal.java new file mode 100644 index 0000000000..e87ded082e --- /dev/null +++ b/core/src/io/anuke/mindustry/maps/goals/WaveGoal.java @@ -0,0 +1,16 @@ +package io.anuke.mindustry.maps.goals; + +import static io.anuke.mindustry.Vars.*; + +public class WaveGoal implements Goal{ + private final int target; + + public WaveGoal(int target){ + this.target = target; + } + + @Override + public boolean isComplete(){ + return state.wave >= target; + } +} diff --git a/core/src/io/anuke/mindustry/ui/dialogs/SectorsDialog.java b/core/src/io/anuke/mindustry/ui/dialogs/SectorsDialog.java index 8b91cdb22d..14126249f4 100644 --- a/core/src/io/anuke/mindustry/ui/dialogs/SectorsDialog.java +++ b/core/src/io/anuke/mindustry/ui/dialogs/SectorsDialog.java @@ -37,8 +37,9 @@ public class SectorsDialog extends FloatingDialog{ addCloseButton(); content().label(() -> Bundles.format("text.sector", selected == null ? "" : - (selected.x + ", " + selected.y + (!selected.unlocked ? " " + Bundles.get("text.sector.locked") : "")) - + (selected.saveID == -1 && selected.unlocked ? " " + Bundles.get("text.sector.unexplored") : ""))); + (selected.x + ", " + selected.y + (!selected.complete && selected.saveID != -1 ? " " + Bundles.get("text.sector.locked") : "")) + + (selected.saveID == -1 ? " " + Bundles.get("text.sector.unexplored") : + (selected.hasSave() ? " [accent]/[white] " + Bundles.format("text.sector.time", selected.getSave().getPlayTime()) : "")))); content().row(); content().add(new SectorView()).grow(); content().row(); @@ -56,7 +57,7 @@ public class SectorsDialog extends FloatingDialog{ logic.play(); } }); - }).size(230f, 64f).name("deploy-button").disabled(b -> selected == null || !selected.unlocked); + }).size(230f, 64f).name("deploy-button").disabled(b -> selected == null); } void selectSector(Sector sector){ @@ -148,7 +149,7 @@ public class SectorsDialog extends FloatingDialog{ selectSector(sector); } Draw.color(Palette.remove); - }else if (sector.unlocked){ + }else if (sector.complete){ Draw.color(Palette.accent); }else{ Draw.color(Color.LIGHT_GRAY); diff --git a/core/src/io/anuke/mindustry/world/Build.java b/core/src/io/anuke/mindustry/world/Build.java index d0fab8e84e..34726fec7f 100644 --- a/core/src/io/anuke/mindustry/world/Build.java +++ b/core/src/io/anuke/mindustry/world/Build.java @@ -16,10 +16,7 @@ public class Build{ private static final Rectangle rect = new Rectangle(); private static final Rectangle hitrect = new Rectangle(); - /** - * Returns block type that was broken, or null if unsuccesful. - */ - //@Remote(targets = Loc.both, forward = true, called = Loc.server, in = In.blocks) + /**Returns block type that was broken, or null if unsuccesful.*/ public static void beginBreak(Team team, int x, int y){ if(!validBreak(team, x, y)){ return; @@ -61,10 +58,7 @@ public class Build{ } - /** - * Places a BuildBlock at this location. - */ - //@Remote(targets = Loc.both, forward = true, called = Loc.server, in = In.blocks) + /**Places a BuildBlock at this location.*/ public static void beginPlace(Team team, int x, int y, Recipe recipe, int rotation){ if(!validPlace(team, x, y, recipe.result, rotation)){ return; @@ -107,9 +101,7 @@ public class Build{ threads.runDelay(() -> Events.fire(BlockBuildEvent.class, team, tile)); } - /** - * Returns whether a tile can be placed at this location by this team. - */ + /**Returns whether a tile can be placed at this location by this team.*/ public static boolean validPlace(Team team, int x, int y, Block type, int rotation){ Recipe recipe = Recipe.getByResult(type); @@ -179,9 +171,7 @@ public class Build{ } } - /** - * Returns whether the tile at this position is breakable by this team - */ + /**Returns whether the tile at this position is breakable by this team*/ public static boolean validBreak(Team team, int x, int y){ Tile tile = world.tile(x, y);