From a4ddf90ef5c136752077ff20180a17b74b61e04a Mon Sep 17 00:00:00 2001 From: Anuken Date: Thu, 30 Jul 2020 23:13:06 -0400 Subject: [PATCH] Added sectors to tech tree / Bugfixes --- core/assets/bundles/bundle.properties | 1 + core/src/mindustry/content/SectorPresets.java | 66 +------------- core/src/mindustry/content/TechTree.java | 90 +++++++++++++++++-- core/src/mindustry/game/Objectives.java | 19 ++++ core/src/mindustry/io/TypeIO.java | 4 + core/src/mindustry/mod/ContentParser.java | 2 +- core/src/mindustry/type/SectorPreset.java | 21 ----- .../mindustry/ui/dialogs/PlanetDialog.java | 3 +- 8 files changed, 113 insertions(+), 93 deletions(-) diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index b0c58156d9..344101e0e6 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -466,6 +466,7 @@ complete = [lightgray]Complete: requirement.wave = Reach Wave {0} in {1} requirement.core = Destroy Enemy Core in {0} requirement.research = Research {0} +requirement.capture = Capture {0} resume = Resume Zone:\n[lightgray]{0} bestwave = [lightgray]Best Wave: {0} #TODO fix/remove this diff --git a/core/src/mindustry/content/SectorPresets.java b/core/src/mindustry/content/SectorPresets.java index 18f2248dec..1cc50426ce 100644 --- a/core/src/mindustry/content/SectorPresets.java +++ b/core/src/mindustry/content/SectorPresets.java @@ -1,10 +1,8 @@ package mindustry.content; import mindustry.ctype.*; -import mindustry.game.Objectives.*; import mindustry.type.*; -import static arc.struct.Seq.*; import static mindustry.content.Planets.*; public class SectorPresets implements ContentList{ @@ -29,112 +27,52 @@ public class SectorPresets implements ContentList{ saltFlats = new SectorPreset("saltFlats", serpulo, 101){{ conditionWave = 10; launchPeriod = 5; - requirements = with( - new SectorWave(groundZero, 60), - //new Unlock(Blocks.daggerFactory), - //new Unlock(Blocks.draugFactory), - new Research(Blocks.door), - new Research(Blocks.waterExtractor) - ); }}; frozenForest = new SectorPreset("frozenForest", serpulo, 86){{ conditionWave = 10; - requirements = with( - new SectorWave(groundZero, 10), - new Research(Blocks.junction), - new Research(Blocks.router) - ); }}; craters = new SectorPreset("craters", serpulo, 18){{ conditionWave = 10; - requirements = with( - new SectorWave(frozenForest, 10), - new Research(Blocks.mender), - new Research(Blocks.combustionGenerator) - ); }}; ruinousShores = new SectorPreset("ruinousShores", serpulo, 19){{ conditionWave = 20; launchPeriod = 20; - requirements = with( - new SectorWave(groundZero, 20), - new SectorWave(craters, 15), - new Research(Blocks.graphitePress), - new Research(Blocks.combustionGenerator), - new Research(Blocks.kiln), - new Research(Blocks.mechanicalPump) - ); }}; stainedMountains = new SectorPreset("stainedMountains", serpulo, 20){{ conditionWave = 10; launchPeriod = 10; - requirements = with( - new SectorWave(frozenForest, 15), - new Research(Blocks.pneumaticDrill), - new Research(Blocks.powerNode), - new Research(Blocks.turbineGenerator) - ); }}; fungalPass = new SectorPreset("fungalPass", serpulo, 21){{ - requirements = with( - new SectorWave(stainedMountains, 15), - //new Unlock(Blocks.daggerFactory), - //new Unlock(Blocks.crawlerFactory), - new Research(Blocks.door), - new Research(Blocks.siliconSmelter) - ); + }}; overgrowth = new SectorPreset("overgrowth", serpulo, 22){{ conditionWave = 12; launchPeriod = 4; - requirements = with( - new SectorWave(craters, 40), - new Launched(fungalPass), - new Research(Blocks.cultivator), - new Research(Blocks.sporePress) - //new Unlock(Blocks.titanFactory), - //new Unlock(Blocks.wraithFactory) - ); }}; tarFields = new SectorPreset("tarFields", serpulo, 23){{ conditionWave = 15; launchPeriod = 10; - requirements = with( - new SectorWave(ruinousShores, 20), - new Research(Blocks.coalCentrifuge), - new Research(Blocks.conduit), - new Research(Blocks.wave) - ); }}; desolateRift = new SectorPreset("desolateRift", serpulo, 123){{ conditionWave = 3; launchPeriod = 2; - requirements = with( - new SectorWave(tarFields, 20), - new Research(Blocks.thermalGenerator), - new Research(Blocks.thoriumReactor) - ); }}; nuclearComplex = new SectorPreset("nuclearComplex", serpulo, 130){{ conditionWave = 30; launchPeriod = 15; - requirements = with( - new Launched(fungalPass), - new Research(Blocks.thermalGenerator), - new Research(Blocks.laserDrill) - ); }}; + /* crags = new Zone("crags", new MapGenerator("crags").dist(2f)){{ loadout = Loadouts.basicFoundation; diff --git a/core/src/mindustry/content/TechTree.java b/core/src/mindustry/content/TechTree.java index 53fa052574..2c52645f44 100644 --- a/core/src/mindustry/content/TechTree.java +++ b/core/src/mindustry/content/TechTree.java @@ -11,6 +11,8 @@ import mindustry.type.*; import mindustry.world.*; import static mindustry.content.Blocks.*; +import static mindustry.content.SectorPresets.*; +import static mindustry.content.SectorPresets.craters; import static mindustry.content.UnitTypes.*; import static mindustry.type.ItemStack.*; @@ -405,17 +407,87 @@ public class TechTree implements ContentList{ }); //TODO research sectors - /* - node(SectorPresets.groundZero, () -> { - node(SectorPresets.nuclearComplex, () -> { - node(SectorPresets.craters, () -> { - node(SectorPresets.saltFlats, () -> { + node(groundZero, () -> { + node(frozenForest, Seq.with( + new SectorComplete(groundZero), + new Research(junction), + new Research(router) + ), () -> { + node(craters, Seq.with( + new SectorComplete(frozenForest), + new Research(mender), + new Research(combustionGenerator) + ), () -> { + node(ruinousShores, Seq.with( + new SectorComplete(craters), + new Research(graphitePress), + new Research(combustionGenerator), + new Research(kiln), + new Research(mechanicalPump) + ), () -> { + + node(tarFields, Seq.with( + new SectorComplete(ruinousShores), + new Research(coalCentrifuge), + new Research(conduit), + new Research(wave) + ), () -> { + node(desolateRift, Seq.with( + new SectorComplete(tarFields), + new Research(thermalGenerator), + new Research(thoriumReactor) + ), () -> { + + }); + }); + + node(saltFlats, Seq.with( + new SectorComplete(ruinousShores), + new Research(groundFactory), + new Research(airFactory), + new Research(door), + new Research(waterExtractor) + ), () -> { + + }); + }); + + node(overgrowth, Seq.with( + new SectorComplete(craters), + new SectorComplete(fungalPass), + new Research(cultivator), + new Research(sporePress), + new Research(UnitTypes.mace), + new Research(UnitTypes.flare) + ), () -> { + + }); + }); + + node(stainedMountains, Seq.with( + new SectorComplete(frozenForest), + new Research(pneumaticDrill), + new Research(powerNode), + new Research(turbineGenerator) + ), () -> { + node(fungalPass, Seq.with( + new SectorComplete(stainedMountains), + new Research(groundFactory), + new Research(door), + new Research(siliconSmelter) + ), () -> { + node(nuclearComplex, Seq.with( + new SectorComplete(fungalPass), + new Research(thermalGenerator), + new Research(laserDrill) + ), () -> { + + }); }); }); }); }); - */ }); } @@ -448,6 +520,12 @@ public class TechTree implements ContentList{ return new TechNode(content, requirements, children); } + private static TechNode node(UnlockableContent content, Seq objectives, Runnable children){ + TechNode node = new TechNode(content, empty, children); + node.objectives = objectives; + return node; + } + private static TechNode node(UnlockableContent block){ return node(block, () -> {}); } diff --git a/core/src/mindustry/game/Objectives.java b/core/src/mindustry/game/Objectives.java index 27f5bcf5c3..aaa2b7c1d5 100644 --- a/core/src/mindustry/game/Objectives.java +++ b/core/src/mindustry/game/Objectives.java @@ -50,6 +50,25 @@ public class Objectives{ } } + public static class SectorComplete extends SectorObjective{ + + public SectorComplete(SectorPreset zone){ + this.preset = zone; + } + + protected SectorComplete(){} + + @Override + public boolean complete(){ + return preset.sector.isCaptured(); + } + + @Override + public String display(){ + return Core.bundle.format("requirement.capture",preset.localizedName); + } + } + public static class Launched extends SectorObjective{ public Launched(SectorPreset zone){ diff --git a/core/src/mindustry/io/TypeIO.java b/core/src/mindustry/io/TypeIO.java index 5330f89af2..ade16c63cf 100644 --- a/core/src/mindustry/io/TypeIO.java +++ b/core/src/mindustry/io/TypeIO.java @@ -74,6 +74,9 @@ public class TypeIO{ write.b(9); write.b((byte)map.content.getContentType().ordinal()); write.s(map.content.id); + }else if(object instanceof Boolean){ + write.b((byte)10); + write.bool((Boolean)object); }else{ throw new IllegalArgumentException("Unknown object type: " + object.getClass()); } @@ -92,6 +95,7 @@ public class TypeIO{ case 7: return new Point2(read.i(), read.i()); case 8: byte len = read.b(); Point2[] out = new Point2[len]; for(int i = 0; i < len; i ++) out[i] = Point2.unpack(read.i()); return out; case 9: return TechTree.getNotNull(content.getByID(ContentType.all[read.b()], read.s())); + case 10: return read.bool(); default: throw new IllegalArgumentException("Unknown object type: " + type); } } diff --git a/core/src/mindustry/mod/ContentParser.java b/core/src/mindustry/mod/ContentParser.java index d093918062..cf343cce8f 100644 --- a/core/src/mindustry/mod/ContentParser.java +++ b/core/src/mindustry/mod/ContentParser.java @@ -87,7 +87,7 @@ public class ContentParser{ return sound; }); put(Objectives.Objective.class, (type, data) -> { - Class oc = data.has("type") ? resolve(data.getString("type"), "mindustry.game.Objectives") : SectorWave.class; + Class oc = data.has("type") ? resolve(data.getString("type"), "mindustry.game.Objectives") : SectorComplete.class; data.remove("type"); Objectives.Objective obj = make(oc); readFields(obj, data); diff --git a/core/src/mindustry/type/SectorPreset.java b/core/src/mindustry/type/SectorPreset.java index d7a5508f20..7e3fc1b286 100644 --- a/core/src/mindustry/type/SectorPreset.java +++ b/core/src/mindustry/type/SectorPreset.java @@ -4,11 +4,8 @@ import arc.*; import arc.func.*; import arc.graphics.g2d.*; import arc.scene.ui.layout.*; -import arc.struct.*; import arc.util.ArcAnnotate.*; import mindustry.ctype.*; -import mindustry.game.EventType.*; -import mindustry.game.Objectives.*; import mindustry.game.*; import mindustry.gen.*; import mindustry.maps.generators.*; @@ -20,7 +17,6 @@ public class SectorPreset extends UnlockableContent{ public @NonNull FileMapGenerator generator; public @NonNull Planet planet; public @NonNull Sector sector; - public Seq requirements = new Seq<>(); public Cons rules = rules -> {}; public int conditionWave = Integer.MAX_VALUE; @@ -43,28 +39,11 @@ public class SectorPreset extends UnlockableContent{ return metCondition() && wave % launchPeriod == 0; } - public boolean canUnlock(){ - return unlocked() || !requirements.contains(r -> !r.complete()); - } - public boolean hasLaunched(){ //TODO implement return Core.settings.getBool(name + "-launched", false); } - public void updateObjectives(Runnable closure){ - Seq incomplete = content.sectors() - .flatMap(z -> z.requirements) - .filter(o -> o.zone() == this && !o.complete()).as(); - - closure.run(); - for(SectorObjective objective : incomplete){ - if(objective.complete()){ - Events.fire(new ZoneRequireCompleteEvent(objective.preset, content.sectors().find(z -> z.requirements.contains(objective)), objective)); - } - } - } - public int bestWave(){ //TODO implement return Core.settings.getInt(name + "-wave", 0); diff --git a/core/src/mindustry/ui/dialogs/PlanetDialog.java b/core/src/mindustry/ui/dialogs/PlanetDialog.java index 66933a81b2..6e0cdc43e4 100644 --- a/core/src/mindustry/ui/dialogs/PlanetDialog.java +++ b/core/src/mindustry/ui/dialogs/PlanetDialog.java @@ -13,6 +13,7 @@ import arc.scene.ui.*; import arc.scene.ui.layout.*; import arc.util.*; import arc.util.ArcAnnotate.*; +import mindustry.content.*; import mindustry.core.*; import mindustry.ctype.*; import mindustry.game.*; @@ -120,7 +121,7 @@ public class PlanetDialog extends BaseDialog implements PlanetInterfaceRenderer{ return mode == launch && (sector.tile.v.within(launchSector.tile.v, (launchRange + 0.5f) * planets.planet.sectorApproxRadius*2) //within range //TODO completely untested - || (sector.preset != null && sector.preset.unlocked() && sector.preset.requirements.contains(r -> r.zone() != null && r.zone() == sector.preset))); //is an unlocked preset + || (sector.preset != null && sector.preset.unlocked() && TechTree.get(sector.preset) != null && TechTree.get(sector.preset).objectives.contains(r -> r.zone() != null && r.zone() == sector.preset))); //is an unlocked preset } @Override