diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index 11e6d4f3f8..322a34c2c4 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -75,6 +75,7 @@ text.mission.command=Send Command {0} To Units text.mission.linknode=Link Power Node text.mission.display=[accent]Mission:\n[LIGHT_GRAY]{0} text.mission.mech=Switch to mech[accent] {0}[] +text.mission.create=Create[accent] {0}[] text.none= text.close=Close diff --git a/core/src/io/anuke/mindustry/content/Recipes.java b/core/src/io/anuke/mindustry/content/Recipes.java index 5f07f5deec..3628b1f300 100644 --- a/core/src/io/anuke/mindustry/content/Recipes.java +++ b/core/src/io/anuke/mindustry/content/Recipes.java @@ -141,12 +141,12 @@ public class Recipes implements ContentList{ //DRILLS, PRODUCERS new Recipe(production, ProductionBlocks.mechanicalDrill, new ItemStack(Items.copper, 45)).setAlwaysUnlocked(true); new Recipe(production, ProductionBlocks.pneumaticDrill, new ItemStack(Items.copper, 60), new ItemStack(Items.densealloy, 50)); - new Recipe(production, ProductionBlocks.laserdrill, new ItemStack(Items.copper, 70), new ItemStack(Items.densealloy, 90), new ItemStack(Items.silicon, 60), new ItemStack(Items.titanium, 50)); - new Recipe(production, ProductionBlocks.blastdrill, new ItemStack(Items.copper, 130), new ItemStack(Items.densealloy, 180), new ItemStack(Items.silicon, 120), new ItemStack(Items.titanium, 100), new ItemStack(Items.thorium, 60)); + new Recipe(production, ProductionBlocks.laserDrill, new ItemStack(Items.copper, 70), new ItemStack(Items.densealloy, 90), new ItemStack(Items.silicon, 60), new ItemStack(Items.titanium, 50)); + new Recipe(production, ProductionBlocks.blastDrill, new ItemStack(Items.copper, 130), new ItemStack(Items.densealloy, 180), new ItemStack(Items.silicon, 120), new ItemStack(Items.titanium, 100), new ItemStack(Items.thorium, 60)); - new Recipe(production, ProductionBlocks.waterextractor, new ItemStack(Items.copper, 50), new ItemStack(Items.densealloy, 50), new ItemStack(Items.lead, 40)); + new Recipe(production, ProductionBlocks.waterExtractor, new ItemStack(Items.copper, 50), new ItemStack(Items.densealloy, 50), new ItemStack(Items.lead, 40)); new Recipe(production, ProductionBlocks.cultivator, new ItemStack(Items.copper, 20), new ItemStack(Items.lead, 50), new ItemStack(Items.silicon, 20)); - new Recipe(production, ProductionBlocks.oilextractor, new ItemStack(Items.copper, 300), new ItemStack(Items.densealloy, 350), new ItemStack(Items.lead, 230), new ItemStack(Items.thorium, 230), new ItemStack(Items.silicon, 150)); + new Recipe(production, ProductionBlocks.oilExtractor, new ItemStack(Items.copper, 300), new ItemStack(Items.densealloy, 350), new ItemStack(Items.lead, 230), new ItemStack(Items.thorium, 230), new ItemStack(Items.silicon, 150)); //UNITS diff --git a/core/src/io/anuke/mindustry/content/blocks/ProductionBlocks.java b/core/src/io/anuke/mindustry/content/blocks/ProductionBlocks.java index 9cb2ff315e..f25d7b3ddb 100644 --- a/core/src/io/anuke/mindustry/content/blocks/ProductionBlocks.java +++ b/core/src/io/anuke/mindustry/content/blocks/ProductionBlocks.java @@ -12,7 +12,7 @@ import io.anuke.mindustry.world.blocks.production.Fracker; import io.anuke.mindustry.world.blocks.production.SolidPump; public class ProductionBlocks extends BlockList implements ContentList{ - public static Block mechanicalDrill, pneumaticDrill, laserdrill, blastdrill, plasmadrill, waterextractor, oilextractor, cultivator; + public static Block mechanicalDrill, pneumaticDrill, laserDrill, blastDrill, plasmaDrill, waterExtractor, oilExtractor, cultivator; @Override public void load(){ @@ -30,7 +30,7 @@ public class ProductionBlocks extends BlockList implements ContentList{ drawMineItem = true; }}; - laserdrill = new Drill("laser-drill"){{ + laserDrill = new Drill("laser-drill"){{ drillTime = 140; size = 2; hasPower = true; @@ -41,7 +41,7 @@ public class ProductionBlocks extends BlockList implements ContentList{ consumes.power(0.16f); }}; - blastdrill = new Drill("blast-drill"){{ + blastDrill = new Drill("blast-drill"){{ drillTime = 60; size = 3; drawRim = true; @@ -56,7 +56,7 @@ public class ProductionBlocks extends BlockList implements ContentList{ consumes.power(0.3f); }}; - plasmadrill = new Drill("plasma-drill"){{ + plasmaDrill = new Drill("plasma-drill"){{ heatColor = Color.valueOf("ff461b"); drillTime = 50; size = 4; @@ -73,7 +73,7 @@ public class ProductionBlocks extends BlockList implements ContentList{ consumes.power(0.7f); }}; - waterextractor = new SolidPump("water-extractor"){{ + waterExtractor = new SolidPump("water-extractor"){{ result = Liquids.water; pumpAmount = 0.065f; size = 2; @@ -83,7 +83,7 @@ public class ProductionBlocks extends BlockList implements ContentList{ consumes.power(0.13f); }}; - oilextractor = new Fracker("oil-extractor"){{ + oilExtractor = new Fracker("oil-extractor"){{ result = Liquids.oil; updateEffect = BlockFx.pulverize; liquidCapacity = 50f; diff --git a/core/src/io/anuke/mindustry/core/Control.java b/core/src/io/anuke/mindustry/core/Control.java index 7fc27445d0..80059b2379 100644 --- a/core/src/io/anuke/mindustry/core/Control.java +++ b/core/src/io/anuke/mindustry/core/Control.java @@ -73,7 +73,7 @@ public class Control extends Module{ long value = soundMap.get(sound, 0L); if(TimeUtils.timeSinceMillis(value) >= minSoundPeriod){ - threads.run(() -> sound.play(volume)); + threads.runGraphics(() -> sound.play(volume)); soundMap.put(sound, time); } }); @@ -159,6 +159,12 @@ public class Control extends Module{ }); Events.on(WorldLoadEvent.class, event -> threads.runGraphics(() -> Events.fire(new WorldLoadGraphicsEvent()))); + + Events.on(BlockBuildEvent.class, event -> { + if(event.team == players[0].getTeam() && Recipe.getByResult(event.tile.block()) != null){ + unlocks.handleContentUsed(Recipe.getByResult(event.tile.block())); + } + }); } public void addPlayer(int index){ diff --git a/core/src/io/anuke/mindustry/game/Unlocks.java b/core/src/io/anuke/mindustry/game/Unlocks.java index 63b258615a..7e61d1314a 100644 --- a/core/src/io/anuke/mindustry/game/Unlocks.java +++ b/core/src/io/anuke/mindustry/game/Unlocks.java @@ -17,6 +17,14 @@ public class Unlocks{ static{ Settings.setSerializer(ContentType.class, (stream, t) -> stream.writeInt(t.ordinal()), stream -> ContentType.values()[stream.readInt()]); } + + /**Handles the event of content being used by either the player or some block.*/ + public void handleContentUsed(UnlockableContent content){ + if(world.getSector() != null){ + world.getSector().currentMission().onContentUsed(content); + } + unlockContent(content); + } /** Returns whether or not this piece of content is unlocked yet.*/ public boolean isUnlocked(UnlockableContent content){ diff --git a/core/src/io/anuke/mindustry/maps/SectorPresets.java b/core/src/io/anuke/mindustry/maps/SectorPresets.java index ed2f150616..7baaeeb76a 100644 --- a/core/src/io/anuke/mindustry/maps/SectorPresets.java +++ b/core/src/io/anuke/mindustry/maps/SectorPresets.java @@ -2,6 +2,7 @@ package io.anuke.mindustry.maps; import com.badlogic.gdx.utils.Array; import io.anuke.mindustry.content.Items; +import io.anuke.mindustry.content.Liquids; import io.anuke.mindustry.content.Mechs; import io.anuke.mindustry.content.blocks.*; import io.anuke.mindustry.entities.units.UnitCommand; @@ -24,15 +25,6 @@ public class SectorPresets{ Array.with(), 1)); - //water mission - add(new SectorPreset(-2, 0, - Structs.array( - Missions.blockRecipe(LiquidBlocks.mechanicalPump), - Missions.blockRecipe(ProductionBlocks.cultivator) - ), - Array.with(Items.copper, Items.lead, Items.copper), - 2)); - //command center mission add(new SectorPreset(2, 0, Structs.array( @@ -45,7 +37,7 @@ public class SectorPresets{ Array.with(Items.copper, Items.lead, Items.copper), 2)); - //reconstructor mission + //pad mission add(new SectorPreset(0, -2, Structs.array( Missions.blockRecipe(mobile ? UpgradeBlocks.tridentPad : UpgradeBlocks.deltaPad), @@ -56,10 +48,13 @@ public class SectorPresets{ 2)); //oil mission - add(new SectorPreset(0, 1, + add(new SectorPreset(-2, 0, Structs.array( Missions.blockRecipe(ProductionBlocks.cultivator), - Missions.blockRecipe(CraftingBlocks.biomatterCompressor) + Missions.blockRecipe(ProductionBlocks.waterExtractor), + new ContentMission(Items.biomatter), + Missions.blockRecipe(CraftingBlocks.biomatterCompressor), + new ContentMission(Liquids.oil) ), Array.with(Items.copper, Items.lead, Items.copper, Items.titanium), 2)); diff --git a/core/src/io/anuke/mindustry/maps/Sectors.java b/core/src/io/anuke/mindustry/maps/Sectors.java index 5513b46b2a..6f83abdff7 100644 --- a/core/src/io/anuke/mindustry/maps/Sectors.java +++ b/core/src/io/anuke/mindustry/maps/Sectors.java @@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.Pixmap; import com.badlogic.gdx.graphics.Pixmap.Format; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.utils.Array; +import com.badlogic.gdx.utils.Json; import io.anuke.mindustry.content.Items; import io.anuke.mindustry.core.GameState.State; import io.anuke.mindustry.entities.units.BaseUnit; @@ -71,7 +72,6 @@ public class Sectors{ threads.runGraphics(() -> ui.showError("$text.sector.corrupted")); } } - } /**If a sector is not yet unlocked, returns null.*/ @@ -243,7 +243,7 @@ public class Sectors{ for(int cx = 0; cx < sector.width; cx++){ for(int cy = 0; cy < sector.height; cy++){ - grid.put(x + cx, y + cy, sector); + grid.put(sector.x + cx, sector.y + cy, sector); } } diff --git a/core/src/io/anuke/mindustry/maps/generation/FortressGenerator.java b/core/src/io/anuke/mindustry/maps/generation/FortressGenerator.java index 1176e781e3..f06447a3db 100644 --- a/core/src/io/anuke/mindustry/maps/generation/FortressGenerator.java +++ b/core/src/io/anuke/mindustry/maps/generation/FortressGenerator.java @@ -163,7 +163,7 @@ public class FortressGenerator{ seeder.get(PowerBlocks.thoriumReactor, tile -> tile.block() instanceof Drill && gen.random.chance(0.2) && gen.drillItem(tile.x, tile.y, (Drill)tile.block()) == Items.thorium && gen.random.chance(0.3)), //water extractors - seeder.get(ProductionBlocks.waterextractor, tile -> tile.block() instanceof NuclearReactor && gen.random.chance(0.5)), + seeder.get(ProductionBlocks.waterExtractor, tile -> tile.block() instanceof NuclearReactor && gen.random.chance(0.5)), //mend cores seeder.get(DefenseBlocks.mendProjector, tile -> tile.block() instanceof PowerGenerator && gen.random.chance(0.03)), diff --git a/core/src/io/anuke/mindustry/maps/missions/BlockMission.java b/core/src/io/anuke/mindustry/maps/missions/BlockMission.java index 6e79b12b9f..4ddf80efe1 100644 --- a/core/src/io/anuke/mindustry/maps/missions/BlockMission.java +++ b/core/src/io/anuke/mindustry/maps/missions/BlockMission.java @@ -1,54 +1,12 @@ package io.anuke.mindustry.maps.missions; -import io.anuke.mindustry.game.EventType.BlockBuildEvent; -import io.anuke.mindustry.game.GameMode; +import io.anuke.mindustry.type.Recipe; import io.anuke.mindustry.world.Block; -import io.anuke.ucore.core.Events; -import io.anuke.ucore.util.Bundles; - -import static io.anuke.mindustry.Vars.defaultTeam; -import static io.anuke.mindustry.Vars.world; /**A mission in which the player must place a block somewhere.*/ -public class BlockMission extends Mission{ - private final Block block; - private boolean complete; +public class BlockMission extends ContentMission{ - static{ - Events.on(BlockBuildEvent.class, event -> { - if(world.getSector() != null && event.team == defaultTeam){ - Mission mission = world.getSector().currentMission(); - if(mission instanceof BlockMission){ - BlockMission block = (BlockMission)world.getSector().currentMission(); - if(block.block == event.tile.block()){ - block.complete = true; - } - } - } - }); - } - - public BlockMission(Block block){ - this.block = block; - } - - @Override - public void reset(){ - complete = false; - } - - @Override - public boolean isComplete(){ - return complete; - } - - @Override - public String displayString(){ - return Bundles.format("text.mission.block", block.formalName); - } - - @Override - public GameMode getMode(){ - return GameMode.noWaves; + public BlockMission(Block block) { + super(Recipe.getByResult(block)); } } diff --git a/core/src/io/anuke/mindustry/maps/missions/ContentMission.java b/core/src/io/anuke/mindustry/maps/missions/ContentMission.java new file mode 100644 index 0000000000..c4a85afd26 --- /dev/null +++ b/core/src/io/anuke/mindustry/maps/missions/ContentMission.java @@ -0,0 +1,35 @@ +package io.anuke.mindustry.maps.missions; + +import io.anuke.mindustry.game.UnlockableContent; +import io.anuke.ucore.util.Bundles; + +public class ContentMission extends Mission { + private final UnlockableContent content; + private boolean done; + + public ContentMission(UnlockableContent content) { + this.content = content; + } + + @Override + public void onContentUsed(UnlockableContent content) { + if(content == this.content){ + done = true; + } + } + + @Override + public boolean isComplete() { + return done; + } + + @Override + public void reset() { + done = false; + } + + @Override + public String displayString() { + return Bundles.format("text.mission.create", content.localizedName()); + } +} diff --git a/core/src/io/anuke/mindustry/maps/missions/Mission.java b/core/src/io/anuke/mindustry/maps/missions/Mission.java index cc5a38f412..6f9de67d1d 100644 --- a/core/src/io/anuke/mindustry/maps/missions/Mission.java +++ b/core/src/io/anuke/mindustry/maps/missions/Mission.java @@ -6,6 +6,7 @@ import io.anuke.mindustry.content.blocks.StorageBlocks; import io.anuke.mindustry.game.GameMode; import io.anuke.mindustry.game.SpawnGroup; import io.anuke.mindustry.game.Team; +import io.anuke.mindustry.game.UnlockableContent; import io.anuke.mindustry.maps.Sector; import io.anuke.mindustry.maps.generation.Generation; import io.anuke.ucore.core.Timers; @@ -43,6 +44,11 @@ public abstract class Mission{ return this; } + /**Called when a specified piece of content is 'used' by a block.*/ + public void onContentUsed(UnlockableContent content){ + + } + /**Draw mission overlay.*/ public void drawOverlay(){ diff --git a/core/src/io/anuke/mindustry/world/Block.java b/core/src/io/anuke/mindustry/world/Block.java index 3d6994257f..8b664e83e4 100644 --- a/core/src/io/anuke/mindustry/world/Block.java +++ b/core/src/io/anuke/mindustry/world/Block.java @@ -217,9 +217,9 @@ public class Block extends BaseBlock { } /**Call when some content is produced. This unlocks the content if it is applicable.*/ - public void useContent(UnlockableContent content){ - if(!headless){ - control.unlocks().unlockContent(content); + public void useContent(Tile tile, UnlockableContent content){ + if(!headless && tile.getTeam() == players[0].getTeam()){ + control.unlocks().handleContentUsed(content); } } diff --git a/core/src/io/anuke/mindustry/world/blocks/production/Drill.java b/core/src/io/anuke/mindustry/world/blocks/production/Drill.java index 7248b3172b..23be92f1f1 100644 --- a/core/src/io/anuke/mindustry/world/blocks/production/Drill.java +++ b/core/src/io/anuke/mindustry/world/blocks/production/Drill.java @@ -203,7 +203,7 @@ public class Drill extends Block{ offloadNear(tile, entity.dominantItem); - useContent(entity.dominantItem); + useContent(tile, entity.dominantItem); entity.index++; entity.progress = 0f; diff --git a/core/src/io/anuke/mindustry/world/blocks/production/GenericCrafter.java b/core/src/io/anuke/mindustry/world/blocks/production/GenericCrafter.java index c2e5f79e12..3de1799dd3 100644 --- a/core/src/io/anuke/mindustry/world/blocks/production/GenericCrafter.java +++ b/core/src/io/anuke/mindustry/world/blocks/production/GenericCrafter.java @@ -97,7 +97,7 @@ public class GenericCrafter extends Block{ if(consumes.has(ConsumeItem.class)) tile.entity.items.remove(consumes.item(), consumes.itemAmount()); - useContent(output); + useContent(tile, output); offloadNear(tile, output); Effects.effect(craftEffect, tile.drawx(), tile.drawy()); diff --git a/core/src/io/anuke/mindustry/world/blocks/production/Pump.java b/core/src/io/anuke/mindustry/world/blocks/production/Pump.java index f4437ab163..942dcce5db 100644 --- a/core/src/io/anuke/mindustry/world/blocks/production/Pump.java +++ b/core/src/io/anuke/mindustry/world/blocks/production/Pump.java @@ -15,6 +15,8 @@ public class Pump extends LiquidBlock{ protected final Array drawTiles = new Array<>(); protected final Array updateTiles = new Array<>(); + protected int timerContentCheck = timers++; + /**Pump amount per tile this block is on.*/ protected float pumpAmount = 1f; /**Maximum liquid tier this pump can use.*/ @@ -98,6 +100,10 @@ public class Pump extends LiquidBlock{ tile.entity.liquids.add(liquidDrop, maxPump); } + if(tile.entity.liquids.currentAmount() > 0f && tile.entity.timer.get(timerContentCheck, 10)){ + useContent(tile, tile.entity.liquids.current()); + } + tryDumpLiquid(tile, tile.entity.liquids.current()); } diff --git a/core/src/io/anuke/mindustry/world/blocks/storage/CoreBlock.java b/core/src/io/anuke/mindustry/world/blocks/storage/CoreBlock.java index 0ea78c8ef0..3e760677fc 100644 --- a/core/src/io/anuke/mindustry/world/blocks/storage/CoreBlock.java +++ b/core/src/io/anuke/mindustry/world/blocks/storage/CoreBlock.java @@ -224,7 +224,7 @@ public class CoreBlock extends StorageBlock{ unit.setDead(true); unit.add(); - useContent(droneType); + useContent(tile, droneType); entity.droneID = unit.id; } diff --git a/core/src/io/anuke/mindustry/world/blocks/units/UnitFactory.java b/core/src/io/anuke/mindustry/world/blocks/units/UnitFactory.java index e0a3dc3699..5a6091d27a 100644 --- a/core/src/io/anuke/mindustry/world/blocks/units/UnitFactory.java +++ b/core/src/io/anuke/mindustry/world/blocks/units/UnitFactory.java @@ -178,7 +178,7 @@ public class UnitFactory extends Block{ entity.buildTime = 0f; Call.onUnitFactorySpawn(tile); - useContent(type); + useContent(tile, type); for(ItemStack stack : consumes.items()){ entity.items.remove(stack.item, stack.amount);