From 81e954c258b0dee6c605eae78a55126a4365d07f Mon Sep 17 00:00:00 2001 From: Anuken Date: Sun, 29 Jul 2018 11:57:46 -0400 Subject: [PATCH] Implemented multi-mission sectors / Various bugfixes --- .../src/io/anuke/mindustry/content/Items.java | 13 ++++++++++--- core/src/io/anuke/mindustry/core/Control.java | 17 ++++++++++++----- .../anuke/mindustry/entities/TileEntity.java | 19 +------------------ core/src/io/anuke/mindustry/maps/Sector.java | 7 ++++--- core/src/io/anuke/mindustry/maps/Sectors.java | 6 +++--- .../maps/generation/WorldGenerator.java | 6 ++++-- .../mindustry/ui/dialogs/SectorsDialog.java | 2 +- .../io/anuke/mindustry/world/BaseBlock.java | 4 ++-- .../world/blocks/distribution/Conduit.java | 2 +- .../world/blocks/distribution/Conveyor.java | 14 ++++---------- 10 files changed, 42 insertions(+), 48 deletions(-) diff --git a/core/src/io/anuke/mindustry/content/Items.java b/core/src/io/anuke/mindustry/content/Items.java index d9de2c5513..85f8e07024 100644 --- a/core/src/io/anuke/mindustry/content/Items.java +++ b/core/src/io/anuke/mindustry/content/Items.java @@ -71,9 +71,16 @@ public class Items implements ContentList{ cost = 1.5f; }}; - surgealloy = new Item("surge-alloy", Color.valueOf("b4d5c7")){{ - type = ItemType.material; - }}; + surgealloy = new Item("surge-alloy", Color.valueOf("b4d5c7")){ + { + type = ItemType.material; + } + + @Override + public boolean isHidden(){ + return true; + } + }; biomatter = new Item("biomatter", Color.valueOf("648b55")){{ flammability = 0.4f; diff --git a/core/src/io/anuke/mindustry/core/Control.java b/core/src/io/anuke/mindustry/core/Control.java index d69045d058..4e2d6c6142 100644 --- a/core/src/io/anuke/mindustry/core/Control.java +++ b/core/src/io/anuke/mindustry/core/Control.java @@ -363,11 +363,18 @@ public class Control extends Module{ } //check unlocked sectors - if(world.getSector() != null && world.getSector().mission.isComplete() && !world.getSector().complete){ - world.sectors().completeSector(world.getSector().x, world.getSector().y); - world.sectors().save(); - if(!headless){ - ui.showInfoFade("$text.sector.unlocked"); + if(world.getSector() != null && !world.getSector().complete){ + //all assigned missions are complete + if(world.getSector().completedMissions >= world.getSector().missions.size){ + + world.sectors().completeSector(world.getSector().x, world.getSector().y); + world.sectors().save(); + if(!headless){ + ui.showInfoFade("$text.sector.unlocked"); + } + }else if(world.getSector().missions.get(world.getSector().completedMissions).isComplete()){ + //increment completed missions, check next index next frame + world.getSector().completedMissions ++; } } diff --git a/core/src/io/anuke/mindustry/entities/TileEntity.java b/core/src/io/anuke/mindustry/entities/TileEntity.java index 651b968760..51787ba060 100644 --- a/core/src/io/anuke/mindustry/entities/TileEntity.java +++ b/core/src/io/anuke/mindustry/entities/TileEntity.java @@ -84,10 +84,7 @@ public class TileEntity extends BaseEntity implements TargetTrait{ return this; } - /** - * Call when nothing is happening to the entity. - * This increments the internal sleep timer. - */ + /**Call when nothing is happening to the entity. This increments the internal sleep timer.*/ public void sleep(){ sleepTime += Timers.delta(); if(!sleeping && sleepTime >= timeToSleep){ @@ -97,20 +94,6 @@ public class TileEntity extends BaseEntity implements TargetTrait{ } } - /** - * Call when something just happened to the entity. - * If the entity was sleeping, this enables it. This also resets the sleep timer. - */ - public void wakeUp(){ - noSleep(); - - for(Tile tile : proximity){ - if(tile.entity.isSleeping()){ - tile.entity.wakeUp(); - } - } - } - /**Call when this entity is updating. This wakes it up.*/ public void noSleep(){ sleepTime = 0f; diff --git a/core/src/io/anuke/mindustry/maps/Sector.java b/core/src/io/anuke/mindustry/maps/Sector.java index 8678309a3d..107b7e1aec 100644 --- a/core/src/io/anuke/mindustry/maps/Sector.java +++ b/core/src/io/anuke/mindustry/maps/Sector.java @@ -5,7 +5,6 @@ import com.badlogic.gdx.utils.Array; import io.anuke.mindustry.game.Saves.SaveSlot; import io.anuke.mindustry.game.SpawnGroup; import io.anuke.mindustry.maps.missions.Mission; -import io.anuke.mindustry.maps.missions.WaveMission; import io.anuke.mindustry.type.Item; import io.anuke.ucore.util.Bits; @@ -20,10 +19,12 @@ public class Sector{ public int saveID = -1; /**Sector size; if more than 1, the coordinates are the bottom left corner.*/ public int size = 1; + /**Num of missions in this sector that have been completed so far.*/ + public int completedMissions; /**Display texture. Needs to be disposed.*/ public transient Texture texture; - /**Mission of this sector-- what needs to be accomplished to unlock it.*/ - public transient Mission mission = new WaveMission(30); + /**Missions of this sector-- what needs to be accomplished to unlock it.*/ + public transient Array missions = new Array<>(); /**Enemies spawned at this sector.*/ public transient Array spawns = new Array<>(); /**Ores that appear in this sector.*/ diff --git a/core/src/io/anuke/mindustry/maps/Sectors.java b/core/src/io/anuke/mindustry/maps/Sectors.java index 0169d08c94..08e262fc2f 100644 --- a/core/src/io/anuke/mindustry/maps/Sectors.java +++ b/core/src/io/anuke/mindustry/maps/Sectors.java @@ -134,12 +134,12 @@ public class Sectors{ sector.difficulty = (int)(Mathf.dst(sector.x, sector.y)/2); if(sector.difficulty < 1){ - sector.mission = new WaveMission(30); + sector.missions.add(new WaveMission(30)); }else{ - sector.mission = Mathf.choose( + sector.missions.add(Mathf.choose( new BattleMission(sector.difficulty), new WaveMission(30 + sector.difficulty*5 + Mathf.randomSeed(sector.getSeed(), 0, 5)*5) - ); + )); } //add all ores for now since material differences aren't well handled yet diff --git a/core/src/io/anuke/mindustry/maps/generation/WorldGenerator.java b/core/src/io/anuke/mindustry/maps/generation/WorldGenerator.java index c68df21f11..81a71fef7a 100644 --- a/core/src/io/anuke/mindustry/maps/generation/WorldGenerator.java +++ b/core/src/io/anuke/mindustry/maps/generation/WorldGenerator.java @@ -12,6 +12,7 @@ import io.anuke.mindustry.game.Team; import io.anuke.mindustry.maps.MapTileData; import io.anuke.mindustry.maps.MapTileData.TileDataMarker; import io.anuke.mindustry.maps.Sector; +import io.anuke.mindustry.maps.missions.Mission; import io.anuke.mindustry.type.Item; import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Tile; @@ -35,7 +36,6 @@ public class WorldGenerator{ private Simplex sim3 = new Simplex(baseSeed + 2); private RidgedPerlin rid = new RidgedPerlin(baseSeed + 4, 1); private VoronoiNoise vn = new VoronoiNoise(baseSeed + 2, (short)0); - private SeedRandom random = new SeedRandom(baseSeed + 3); private GenResult result = new GenResult(); @@ -212,7 +212,9 @@ public class WorldGenerator{ tiles[coreX][coreY].setBlock(StorageBlocks.core); tiles[coreX][coreY].setTeam(Team.blue); - sector.mission.generate(tiles, sector); + for(Mission mission : sector.missions){ + mission.generate(tiles, sector); + } prepareTiles(tiles, sector.getSeed(), true, sector.ores); } diff --git a/core/src/io/anuke/mindustry/ui/dialogs/SectorsDialog.java b/core/src/io/anuke/mindustry/ui/dialogs/SectorsDialog.java index 9226c65dd9..c33cdf4ab6 100644 --- a/core/src/io/anuke/mindustry/ui/dialogs/SectorsDialog.java +++ b/core/src/io/anuke/mindustry/ui/dialogs/SectorsDialog.java @@ -41,7 +41,7 @@ public class SectorsDialog extends FloatingDialog{ + (selected.saveID == -1 ? " " + Bundles.get("text.sector.unexplored") : (selected.hasSave() ? " [accent]/[white] " + Bundles.format("text.sector.time", selected.getSave().getPlayTime()) : "")))); content().row(); - content().label(() -> Bundles.format("text.mission", selected == null ? Bundles.get("text.none") : selected.mission.displayString())); + content().label(() -> Bundles.format("text.mission", selected == null || selected.completedMissions >= selected.missions.size ? Bundles.get("text.none") : selected.missions.get(selected.completedMissions).displayString())); content().row(); content().add(new SectorView()).grow(); content().row(); diff --git a/core/src/io/anuke/mindustry/world/BaseBlock.java b/core/src/io/anuke/mindustry/world/BaseBlock.java index e1558d4513..2c99241dfb 100644 --- a/core/src/io/anuke/mindustry/world/BaseBlock.java +++ b/core/src/io/anuke/mindustry/world/BaseBlock.java @@ -55,14 +55,14 @@ public abstract class BaseBlock{ * Remove a stack from this inventory, and return the amount removed. */ public int removeStack(Tile tile, Item item, int amount){ - tile.entity.wakeUp(); + tile.entity.noSleep(); tile.entity.items.remove(item, amount); return amount; } /**Handle a stack input.*/ public void handleStack(Item item, int amount, Tile tile, Unit source){ - tile.entity.wakeUp(); + tile.entity.noSleep(); tile.entity.items.add(item, amount); } diff --git a/core/src/io/anuke/mindustry/world/blocks/distribution/Conduit.java b/core/src/io/anuke/mindustry/world/blocks/distribution/Conduit.java index 01513da6b8..2061950eb1 100644 --- a/core/src/io/anuke/mindustry/world/blocks/distribution/Conduit.java +++ b/core/src/io/anuke/mindustry/world/blocks/distribution/Conduit.java @@ -121,7 +121,7 @@ public class Conduit extends LiquidBlock{ @Override public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){ - tile.entity.wakeUp(); + tile.entity.noSleep(); return super.acceptLiquid(tile, source, liquid, amount) && ((2 + source.relativeTo(tile.x, tile.y)) % 4 != tile.getRotation()); } diff --git a/core/src/io/anuke/mindustry/world/blocks/distribution/Conveyor.java b/core/src/io/anuke/mindustry/world/blocks/distribution/Conveyor.java index 34726f1962..a84db53acf 100644 --- a/core/src/io/anuke/mindustry/world/blocks/distribution/Conveyor.java +++ b/core/src/io/anuke/mindustry/world/blocks/distribution/Conveyor.java @@ -209,7 +209,6 @@ public class Conveyor extends Block{ int minremove = Integer.MAX_VALUE; float speed = Math.max(this.speed - (1f - (carryCapacity - entity.carrying) / carryCapacity), 0f); - float totalMoved = 0f; for(int i = entity.convey.size - 1; i >= 0; i--){ long value = entity.convey.get(i); @@ -221,7 +220,6 @@ public class Conveyor extends Block{ break; } - float prev = pos.y; float nextpos = (i == entity.convey.size - 1 ? 100f : pos2.set(entity.convey.get(i + 1), ItemPos.updateShorts).y) - itemSpace; if(entity.minCarry >= pos.y && entity.minCarry <= nextpos){ nextpos = entity.minCarry; @@ -236,11 +234,9 @@ public class Conveyor extends Block{ } pos.y = Mathf.clamp(pos.y); - totalMoved += (pos.y - prev); if(pos.y >= 0.9999f && offloadDir(tile, pos.item)){ minremove = Math.min(i, minremove); - totalMoved = 1f; tile.entity.items.remove(pos.item, 1); }else{ value = pos.pack(); @@ -260,9 +256,7 @@ public class Conveyor extends Block{ entity.carrying = 0f; entity.minCarry = 2f; - Tile next = tile.getNearby(tile.getRotation()); - - if((next != null && next.block() instanceof Conveyor) && totalMoved/Timers.delta() <= 0.0001f){ + if(entity.items.total() == 0){ entity.sleep(); }else{ entity.noSleep(); @@ -279,7 +273,7 @@ public class Conveyor extends Block{ @Override public synchronized int removeStack(Tile tile, Item item, int amount){ ConveyorEntity entity = tile.entity(); - entity.wakeUp(); + entity.noSleep(); int removed = 0; for(int j = 0; j < amount; j++){ @@ -315,7 +309,7 @@ public class Conveyor extends Block{ long result = ItemPos.packItem(item, 0f, 0f, (byte) Mathf.random(255)); entity.convey.insert(0, result); entity.items.add(item, 1); - entity.wakeUp(); + entity.noSleep(); } @Override @@ -337,7 +331,7 @@ public class Conveyor extends Block{ float y = (ang == -1 || ang == 3) ? 1 : (ang == 1 || ang == -3) ? -1 : 0; ConveyorEntity entity = tile.entity(); - entity.wakeUp(); + entity.noSleep(); long result = ItemPos.packItem(item, y * 0.9f, pos, (byte) Mathf.random(255)); boolean inserted = false;