From d9751dbc6d188e57c7bb8dd9c0b3d30151c080e6 Mon Sep 17 00:00:00 2001 From: Anuken Date: Sun, 17 May 2020 11:12:22 -0400 Subject: [PATCH] Sector preset support / Per-player votekick cooldown --- ...uctionComplex.msav => nuclearComplex.msav} | Bin core/src/mindustry/content/Zones.java | 49 ++++++------------ core/src/mindustry/core/Control.java | 6 --- core/src/mindustry/core/NetServer.java | 12 +++-- core/src/mindustry/core/World.java | 8 ++- .../maps/generators/FileMapGenerator.java | 11 ++-- core/src/mindustry/type/Planet.java | 4 ++ core/src/mindustry/type/Sector.java | 1 + core/src/mindustry/type/SectorPreset.java | 31 +++-------- .../mindustry/ui/dialogs/ZoneInfoDialog.java | 6 ++- 10 files changed, 52 insertions(+), 76 deletions(-) rename core/assets/maps/{nuclearProductionComplex.msav => nuclearComplex.msav} (100%) diff --git a/core/assets/maps/nuclearProductionComplex.msav b/core/assets/maps/nuclearComplex.msav similarity index 100% rename from core/assets/maps/nuclearProductionComplex.msav rename to core/assets/maps/nuclearComplex.msav diff --git a/core/src/mindustry/content/Zones.java b/core/src/mindustry/content/Zones.java index c770ecc669..decfb74554 100644 --- a/core/src/mindustry/content/Zones.java +++ b/core/src/mindustry/content/Zones.java @@ -2,7 +2,6 @@ package mindustry.content; import mindustry.ctype.*; import mindustry.game.Objectives.*; -import mindustry.maps.generators.*; import mindustry.type.*; import static arc.struct.Array.with; @@ -20,18 +19,17 @@ public class Zones implements ContentList{ @Override public void load(){ - groundZero = new SectorPreset("groundZero", starter, new FileMapGenerator("groundZero")){{ + groundZero = new SectorPreset("groundZero", starter){{ baseLaunchCost = list(copper, -60); startingItems = list(copper, 60); alwaysUnlocked = true; conditionWave = 5; launchPeriod = 5; - resources = with(copper, scrap, lead); }}; //TODO remove /* - desertWastes = new Zone("desertWastes", starter, new FileMapGenerator("groundZero")){{ + desertWastes = new Zone("desertWastes", starter){{ startingItems = list(copper, 120); conditionWave = 20; launchPeriod = 10; @@ -82,13 +80,11 @@ public class Zones implements ContentList{ ); }};*/ - saltFlats = new SectorPreset("saltFlats", starter, new FileMapGenerator("saltFlats")){{ + saltFlats = new SectorPreset("saltFlats", starter){{ startingItems = list(copper, 200, Items.silicon, 200, lead, 200); loadout = Loadouts.basicFoundation; conditionWave = 10; launchPeriod = 5; - configureObjective = new Launched(this); - resources = with(copper, scrap, lead, coal, sand, titanium); requirements = with( new ZoneWave(desertWastes, 60), //new Unlock(Blocks.daggerFactory), @@ -98,11 +94,10 @@ public class Zones implements ContentList{ ); }}; - frozenForest = new SectorPreset("frozenForest", starter, new FileMapGenerator("frozenForest")){{ + frozenForest = new SectorPreset("frozenForest", starter){{ loadout = Loadouts.basicFoundation; startingItems = list(copper, 250); conditionWave = 10; - resources = with(copper, lead, coal); requirements = with( new ZoneWave(groundZero, 10), new Unlock(Blocks.junction), @@ -110,10 +105,9 @@ public class Zones implements ContentList{ ); }}; - craters = new SectorPreset("craters", starter, new FileMapGenerator("craters")){{ + craters = new SectorPreset("craters", starter){{ startingItems = list(copper, 100); conditionWave = 10; - resources = with(copper, lead, coal, sand, scrap); requirements = with( new ZoneWave(frozenForest, 10), new Unlock(Blocks.mender), @@ -121,12 +115,11 @@ public class Zones implements ContentList{ ); }}; - ruinousShores = new SectorPreset("ruinousShores", starter, new FileMapGenerator("ruinousShores")){{ + ruinousShores = new SectorPreset("ruinousShores", starter){{ loadout = Loadouts.basicFoundation; startingItems = list(copper, 140, lead, 50); conditionWave = 20; launchPeriod = 20; - resources = with(copper, scrap, lead, coal, sand); requirements = with( new ZoneWave(desertWastes, 20), new ZoneWave(craters, 15), @@ -137,12 +130,11 @@ public class Zones implements ContentList{ ); }}; - stainedMountains = new SectorPreset("stainedMountains", starter, new FileMapGenerator("stainedMountains")){{ + stainedMountains = new SectorPreset("stainedMountains", starter){{ loadout = Loadouts.basicFoundation; startingItems = list(copper, 200, lead, 50); conditionWave = 10; launchPeriod = 10; - resources = with(copper, scrap, lead, coal, titanium, sand); requirements = with( new ZoneWave(frozenForest, 15), new Unlock(Blocks.pneumaticDrill), @@ -151,10 +143,8 @@ public class Zones implements ContentList{ ); }}; - fungalPass = new SectorPreset("fungalPass", starter, new FileMapGenerator("fungalPass")){{ + fungalPass = new SectorPreset("fungalPass", starter){{ startingItems = list(copper, 250, lead, 250, Items.metaglass, 100, Items.graphite, 100); - resources = with(copper, lead, coal, titanium, sand); - configureObjective = new Launched(this); requirements = with( new ZoneWave(stainedMountains, 15), //new Unlock(Blocks.daggerFactory), @@ -164,13 +154,11 @@ public class Zones implements ContentList{ ); }}; - overgrowth = new SectorPreset("overgrowth", starter, new FileMapGenerator("overgrowth")){{ + overgrowth = new SectorPreset("overgrowth", starter){{ startingItems = list(copper, 1500, lead, 1000, Items.silicon, 500, Items.metaglass, 250); conditionWave = 12; launchPeriod = 4; loadout = Loadouts.basicNucleus; - configureObjective = new Launched(this); - resources = with(copper, lead, coal, titanium, sand, thorium, scrap); requirements = with( new ZoneWave(craters, 40), new Launched(fungalPass), @@ -181,12 +169,11 @@ public class Zones implements ContentList{ ); }}; - tarFields = new SectorPreset("tarFields", starter, new FileMapGenerator("tarFields")){{ + tarFields = new SectorPreset("tarFields", starter){{ loadout = Loadouts.basicFoundation; startingItems = list(copper, 250, lead, 100); conditionWave = 15; launchPeriod = 10; - resources = with(copper, scrap, lead, coal, titanium, thorium, sand); requirements = with( new ZoneWave(ruinousShores, 20), new Unlock(Blocks.coalCentrifuge), @@ -195,12 +182,11 @@ public class Zones implements ContentList{ ); }}; - desolateRift = new SectorPreset("desolateRift", starter, new FileMapGenerator("desolateRift")){{ + desolateRift = new SectorPreset("desolateRift", starter){{ loadout = Loadouts.basicNucleus; startingItems = list(copper, 1000, lead, 1000, Items.graphite, 250, titanium, 250, Items.silicon, 250); conditionWave = 3; launchPeriod = 2; - resources = with(copper, scrap, lead, coal, titanium, sand, thorium); requirements = with( new ZoneWave(tarFields, 20), new Unlock(Blocks.thermalGenerator), @@ -220,12 +206,11 @@ public class Zones implements ContentList{ resources = Array.with(Items.copper, Items.scrap, Items.lead, Items.coal, Items.sand}; }};*/ - nuclearComplex = new SectorPreset("nuclearComplex", starter, new FileMapGenerator("nuclearProductionComplex")){{ + nuclearComplex = new SectorPreset("nuclearComplex", starter){{ loadout = Loadouts.basicNucleus; startingItems = list(copper, 1250, lead, 1500, Items.silicon, 400, Items.metaglass, 250); conditionWave = 30; launchPeriod = 15; - resources = with(copper, scrap, lead, coal, titanium, thorium, sand); requirements = with( new Launched(fungalPass), new Unlock(Blocks.thermalGenerator), @@ -234,15 +219,15 @@ public class Zones implements ContentList{ }}; /* - impact0078 = new Zone("impact0078", new MapGenerator("impact0078").dist(2f)){{ + impact0078 = new SectorPreset("impact0078"){{ loadout = Loadouts.basicNucleus; - baseLaunchCost = ItemStack.with(); + baseLaunchCost = ItemStack.list(); startingItems = ItemStack.list(Items.copper, 2000, Items.lead, 2000, Items.graphite, 500, Items.titanium, 500, Items.silicon, 500); conditionWave = 3; launchPeriod = 2; - requirements = with(nuclearComplex, 40); - blockRequirements = new Block[]{Blocks.thermalGenerator}; - resources = Array.with(Items.copper, Items.scrap, Items.lead, Items.coal, Items.titanium, Items.thorium}; + //requirements = with(nuclearComplex, 40); + //blockRequirements = new Block[]{Blocks.thermalGenerator}; + //resources = Array.with(Items.copper, Items.scrap, Items.lead, Items.coal, Items.titanium, Items.thorium}; }};*/ } } diff --git a/core/src/mindustry/core/Control.java b/core/src/mindustry/core/Control.java index b0a14daeba..1d4353b33f 100644 --- a/core/src/mindustry/core/Control.java +++ b/core/src/mindustry/core/Control.java @@ -155,12 +155,6 @@ public class Control implements ApplicationListener, Loadable{ } }); - Events.on(ZoneConfigureCompleteEvent.class, e -> { - if(e.zone.configureObjective.display() != null){ - ui.hudfrag.showToast(Core.bundle.format("zone.config.unlocked", e.zone.configureObjective.display())); - } - }); - Events.on(Trigger.newGame, () -> { Tilec core = player.closestCore(); diff --git a/core/src/mindustry/core/NetServer.java b/core/src/mindustry/core/NetServer.java index 7783dcfa2f..7461016a49 100644 --- a/core/src/mindustry/core/NetServer.java +++ b/core/src/mindustry/core/NetServer.java @@ -303,8 +303,8 @@ public class NetServer implements ApplicationListener{ int kickDuration = 60 * 60; //voting round duration in seconds float voteDuration = 0.5f * 60; - //cooldown between votes - int voteCooldown = 60 * 1; + //cooldown between votes in seconds + int voteCooldown = 60 * 5; class VoteSession{ Playerc target; @@ -346,11 +346,12 @@ public class NetServer implements ApplicationListener{ } } - Timekeeper vtime = new Timekeeper(voteCooldown); + //cooldowns per player + ObjectMap cooldowns = new ObjectMap<>(); //current kick sessions VoteSession[] currentlyKicking = {null}; - clientCommands.register("votekick", "[player...]", "Vote to kick a player, with a cooldown.", (args, player) -> { + clientCommands.register("votekick", "[player...]", "Vote to kick a player.", (args, player) -> { if(!Config.enableVotekick.bool()){ player.sendMessage("[scarlet]Vote-kick is disabled on this server."); return; @@ -391,6 +392,8 @@ public class NetServer implements ApplicationListener{ }else if(found.team() != player.team()){ player.sendMessage("[scarlet]Only players on your team can be kicked."); }else{ + Timekeeper vtime = cooldowns.getOr(player.uuid(), () -> new Timekeeper(voteCooldown)); + if(!vtime.get()){ player.sendMessage("[scarlet]You must wait " + voteCooldown/60 + " minutes between votekicks."); return; @@ -437,7 +440,6 @@ public class NetServer implements ApplicationListener{ } }); - clientCommands.register("sync", "Re-synchronize world state.", (args, player) -> { if(player.isLocal()){ player.sendMessage("[scarlet]Re-synchronizing as the host is pointless."); diff --git a/core/src/mindustry/core/World.java b/core/src/mindustry/core/World.java index 1e9ba226ad..8103418fd9 100644 --- a/core/src/mindustry/core/World.java +++ b/core/src/mindustry/core/World.java @@ -214,7 +214,13 @@ public class World{ setSectorRules(sector); int size = sector.getSize(); - loadGenerator(size, size, tiles -> sector.planet.generator.generate(tiles, sector)); + loadGenerator(size, size, tiles -> { + if(sector.preset != null){ + sector.preset.generator.generate(tiles); + }else{ + sector.planet.generator.generate(tiles, sector); + } + }); if(state.rules.defaultTeam.core() != null){ sector.setSpawnPosition(state.rules.defaultTeam.core().pos()); diff --git a/core/src/mindustry/maps/generators/FileMapGenerator.java b/core/src/mindustry/maps/generators/FileMapGenerator.java index 8b3ae29c2f..78592073ce 100644 --- a/core/src/mindustry/maps/generators/FileMapGenerator.java +++ b/core/src/mindustry/maps/generators/FileMapGenerator.java @@ -4,6 +4,7 @@ import arc.math.*; import arc.math.geom.*; import mindustry.content.*; import mindustry.ctype.*; +import mindustry.game.*; import mindustry.io.*; import mindustry.maps.*; import mindustry.type.*; @@ -13,16 +14,14 @@ import mindustry.world.blocks.storage.*; import static mindustry.Vars.*; public class FileMapGenerator implements WorldGenerator{ - public final Map map = null; + public final Map map; public FileMapGenerator(String mapName){ - //TODO doesn't work - //this.map = maps.loadInternalMap(mapName); + this.map = maps.loadInternalMap(mapName); } @Override public void generate(Tiles tiles){ - if(true) throw new IllegalArgumentException("no!"); tiles.fill(); SaveIO.load(map.file); @@ -50,8 +49,8 @@ public class FileMapGenerator implements WorldGenerator{ } if(tile.block() instanceof CoreBlock && tile.team() == state.rules.defaultTeam){ - //TODO PLACE THE LOADOUT - //schematics.placeLoadout(loadout, tile.x, tile.y); + //TODO PLACE THE (CORRECT) LOADOUT + Schematics.placeLoadout(Loadouts.basicFoundation, tile.x, tile.y); anyCores = true; } } diff --git a/core/src/mindustry/type/Planet.java b/core/src/mindustry/type/Planet.java index 8ac17109ef..e2f9cab47c 100644 --- a/core/src/mindustry/type/Planet.java +++ b/core/src/mindustry/type/Planet.java @@ -122,6 +122,10 @@ public class Planet extends UnlockableContent{ for(solarSystem = this; solarSystem.parent != null; solarSystem = solarSystem.parent); } + public void preset(int index, SectorPreset preset){ + sectors.get(index).preset = preset; + } + public boolean isLandable(){ return grid != null && generator != null && sectors.size > 0; } diff --git a/core/src/mindustry/type/Sector.java b/core/src/mindustry/type/Sector.java index 5459a2cf8b..bcc031bf4e 100644 --- a/core/src/mindustry/type/Sector.java +++ b/core/src/mindustry/type/Sector.java @@ -25,6 +25,7 @@ public class Sector{ public final SectorData data; public @Nullable SaveSlot save; + public @Nullable SectorPreset preset; public boolean unlocked; /** Sector enemy hostility from 0 to 1 */ diff --git a/core/src/mindustry/type/SectorPreset.java b/core/src/mindustry/type/SectorPreset.java index 80675a4aaa..33bca1f802 100644 --- a/core/src/mindustry/type/SectorPreset.java +++ b/core/src/mindustry/type/SectorPreset.java @@ -16,12 +16,9 @@ import static mindustry.Vars.*; //TODO ? remove ? public class SectorPreset extends UnlockableContent{ - public @NonNull WorldGenerator generator; - public @NonNull Objectives.Objective configureObjective = new ZoneWave(this, 15); + public @NonNull FileMapGenerator generator; public @NonNull Planet planet; public Array requirements = new Array<>(); - //TODO autogenerate - public Array resources = new Array<>(); public Cons rules = rules -> {}; public boolean alwaysUnlocked; @@ -32,27 +29,20 @@ public class SectorPreset extends UnlockableContent{ protected Array baseLaunchCost = new Array<>(); protected Array startingItems = new Array<>(); protected Array launchCost; + protected Array defaultStartingItems = new Array<>(); - private Array defaultStartingItems = new Array<>(); - - public SectorPreset(String name, Planet planet, WorldGenerator generator){ + public SectorPreset(String name, Planet planet){ super(name); - this.generator = generator; + this.generator = new FileMapGenerator(name); this.planet = planet; } public SectorPreset(String name){ - this(name, Planets.starter, new FileMapGenerator(name)); + this(name, Planets.starter); } public Rules getRules(){ - if(generator instanceof FileMapGenerator){ - return ((FileMapGenerator)generator).map.rules(); - }else{ - Rules rules = new Rules(); - this.rules.get(rules); - return rules; - } + return generator.map.rules(); } public boolean isLaunchWave(int wave){ @@ -107,18 +97,12 @@ public class SectorPreset extends UnlockableContent{ .select(o -> o.zone() == this && !o.complete()) .as(ZoneObjective.class); - boolean wasConfig = configureObjective.complete(); - closure.run(); for(ZoneObjective objective : incomplete){ if(objective.complete()){ Events.fire(new ZoneRequireCompleteEvent(objective.zone, content.zones().find(z -> z.requirements.contains(objective)), objective)); } } - - if(!wasConfig && configureObjective.complete()){ - Events.fire(new ZoneConfigureCompleteEvent(this)); - } } public int bestWave(){ @@ -163,12 +147,11 @@ public class SectorPreset extends UnlockableContent{ } public boolean canConfigure(){ - return configureObjective.complete(); + return true; } @Override public void init(){ - resources.sort(); for(ItemStack stack : startingItems){ defaultStartingItems.add(new ItemStack(stack.item, stack.amount)); diff --git a/core/src/mindustry/ui/dialogs/ZoneInfoDialog.java b/core/src/mindustry/ui/dialogs/ZoneInfoDialog.java index 5483db1d67..2e6a11765b 100644 --- a/core/src/mindustry/ui/dialogs/ZoneInfoDialog.java +++ b/core/src/mindustry/ui/dialogs/ZoneInfoDialog.java @@ -110,6 +110,7 @@ public class ZoneInfoDialog extends FloatingDialog{ t.left(); t.add("$zone.resources").padRight(6); + /* if(zone.resources.size > 0){ t.table(r -> { t.left(); @@ -123,7 +124,7 @@ public class ZoneInfoDialog extends FloatingDialog{ }); }else{ t.add("$none"); - } + }*/ }); Rules rules = zone.getRules(); @@ -143,9 +144,10 @@ public class ZoneInfoDialog extends FloatingDialog{ }); cont.row(); + /* cont.button(zone.canConfigure() ? "$configure" : Core.bundle.format("configure.locked", zone.configureObjective.display()), () -> loadout.show(zone.loadout.findCore().itemCapacity, zone.getStartingItems(), zone::resetStartingItems, zone::updateLaunchCost, rebuildItems) - ).fillX().pad(3).disabled(b -> !zone.canConfigure()); + ).fillX().pad(3).disabled(b -> !zone.canConfigure());*/ cont.row();