From 354c6e17c0959b3e8f117647b48bb2202092cd48 Mon Sep 17 00:00:00 2001 From: Anuken Date: Mon, 18 Jun 2018 17:20:23 -0400 Subject: [PATCH] Implemented smelting with flux --- build.gradle | 2 +- .../io/anuke/mindustry/content/AmmoTypes.java | 24 +--- .../src/io/anuke/mindustry/content/Items.java | 1 - .../content/blocks/CraftingBlocks.java | 10 ++ .../content/blocks/WeaponBlocks.java | 2 +- .../content/bullets/ShellBullets.java | 127 ------------------ .../anuke/mindustry/core/ContentLoader.java | 1 - .../io/anuke/mindustry/world/BaseBlock.java | 6 +- .../world/blocks/production/PowerSmelter.java | 48 +++++-- .../world/blocks/production/Smelter.java | 61 +++++++-- 10 files changed, 106 insertions(+), 176 deletions(-) delete mode 100644 core/src/io/anuke/mindustry/content/bullets/ShellBullets.java diff --git a/build.gradle b/build.gradle index 9c980cd4a7..e41badb06a 100644 --- a/build.gradle +++ b/build.gradle @@ -27,7 +27,7 @@ allprojects { gdxVersion = '1.9.8' roboVMVersion = '2.3.0' aiVersion = '1.8.1' - uCoreVersion = ' d1af4c8' + uCoreVersion = 'd1af4c8' getVersionString = { String buildVersion = getBuildVersion() diff --git a/core/src/io/anuke/mindustry/content/AmmoTypes.java b/core/src/io/anuke/mindustry/content/AmmoTypes.java index 5da3b6660b..9e2b84b4f1 100644 --- a/core/src/io/anuke/mindustry/content/AmmoTypes.java +++ b/core/src/io/anuke/mindustry/content/AmmoTypes.java @@ -8,7 +8,7 @@ import io.anuke.mindustry.type.AmmoType; import io.anuke.mindustry.type.ContentList; public class AmmoTypes implements ContentList { - public static AmmoType bulletIron, bulletLead, bulletSteel, bulletThorium, bulletSilicon, bulletThermite, flakLead, flakExplosive, flakPlastic, flakSurge, shellLead, shellExplosive, shellPlastic, shellThorium, missileExplosive, missileIncindiary, missileSurge, artilleryLead, artilleryThorium, artilleryPlastic, artilleryHoming, artilleryIncindiary, basicFlame, lancerLaser, lightning, spectreLaser, meltdownLaser, fuseShotgun, oil, water, lava, cryofluid; + public static AmmoType bulletIron, bulletLead, bulletSteel, bulletThorium, bulletSilicon, bulletThermite, flakLead, flakExplosive, flakPlastic, flakSurge, missileExplosive, missileIncindiary, missileSurge, artilleryLead, artilleryThorium, artilleryPlastic, artilleryHoming, artilleryIncindiary, basicFlame, lancerLaser, lightning, spectreLaser, meltdownLaser, fuseShotgun, oil, water, lava, cryofluid; @Override public void load() { @@ -67,28 +67,6 @@ public class AmmoTypes implements ContentList { smokeEffect = ShootFx.shootSmallSmoke; }}; - //shells - - shellLead = new AmmoType(Items.lead, ShellBullets.lead, 1) {{ - shootEffect = ShootFx.shootBig2; - smokeEffect = ShootFx.shootBigSmoke2; - }}; - - shellExplosive = new AmmoType(Items.blastCompound, ShellBullets.explosive, 1) {{ - shootEffect = ShootFx.shootBig2; - smokeEffect = ShootFx.shootBigSmoke2; - }}; - - shellPlastic = new AmmoType(Items.plasteel, ShellBullets.plastic, 1) {{ - shootEffect = ShootFx.shootBig2; - smokeEffect = ShootFx.shootBigSmoke2; - }}; - - shellThorium = new AmmoType(Items.thorium, ShellBullets.thorium, 1) {{ - shootEffect = ShootFx.shootBig2; - smokeEffect = ShootFx.shootBigSmoke2; - }}; - //missiles missileExplosive = new AmmoType(Items.blastCompound, MissileBullets.explosive, 1) {{ diff --git a/core/src/io/anuke/mindustry/content/Items.java b/core/src/io/anuke/mindustry/content/Items.java index 085b521c64..4b94c5b308 100644 --- a/core/src/io/anuke/mindustry/content/Items.java +++ b/core/src/io/anuke/mindustry/content/Items.java @@ -30,7 +30,6 @@ public class Items implements ContentList{ coal = new Item("coal", Color.valueOf("272727")) {{ explosiveness = 0.2f; flammability = 0.5f; - fluxiness = 0.3f; hardness = 2; }}; diff --git a/core/src/io/anuke/mindustry/content/blocks/CraftingBlocks.java b/core/src/io/anuke/mindustry/content/blocks/CraftingBlocks.java index fbdd6f307b..cc7431136a 100644 --- a/core/src/io/anuke/mindustry/content/blocks/CraftingBlocks.java +++ b/core/src/io/anuke/mindustry/content/blocks/CraftingBlocks.java @@ -21,6 +21,7 @@ public class CraftingBlocks extends BlockList implements ContentList { fuel = Items.coal; result = Items.steel; craftTime = 35f; + useFlux = true; }}; arcsmelter = new PowerSmelter("arc-smelter") {{ @@ -31,6 +32,9 @@ public class CraftingBlocks extends BlockList implements ContentList { powerUse = 0.1f; craftTime = 25f; size = 2; + + useFlux = true; + fluxNeeded = 2; }}; siliconsmelter = new PowerSmelter("silicon-smelter") {{ @@ -79,6 +83,9 @@ public class CraftingBlocks extends BlockList implements ContentList { powerUse = 0.3f; craftTime = 50f; size = 2; + + useFlux = true; + fluxNeeded = 4; }}; alloyfuser = new PowerSmelter("alloy-fuser") {{ @@ -89,6 +96,9 @@ public class CraftingBlocks extends BlockList implements ContentList { powerUse = 0.4f; craftTime = 30f; size = 3; + + useFlux = true; + fluxNeeded = 4; }}; cryofluidmixer = new LiquidMixer("cryofluidmixer") {{ diff --git a/core/src/io/anuke/mindustry/content/blocks/WeaponBlocks.java b/core/src/io/anuke/mindustry/content/blocks/WeaponBlocks.java index 892c9a7442..99f93b4828 100644 --- a/core/src/io/anuke/mindustry/content/blocks/WeaponBlocks.java +++ b/core/src/io/anuke/mindustry/content/blocks/WeaponBlocks.java @@ -109,7 +109,7 @@ public class WeaponBlocks extends BlockList implements ContentList { salvo = new ItemTurret("salvo") {{ size = 2; range = 100f; - ammoTypes = new AmmoType[]{AmmoTypes.shellExplosive, AmmoTypes.shellLead, AmmoTypes.shellPlastic, AmmoTypes.shellThorium}; + ammoTypes = new AmmoType[]{AmmoTypes.bulletIron, AmmoTypes.bulletLead, AmmoTypes.bulletSteel, AmmoTypes.bulletThermite, AmmoTypes.bulletThorium, AmmoTypes.bulletSilicon}; reload = 70f; restitution = 0.03f; ammoEjectBack = 3f; diff --git a/core/src/io/anuke/mindustry/content/bullets/ShellBullets.java b/core/src/io/anuke/mindustry/content/bullets/ShellBullets.java deleted file mode 100644 index d94817abc2..0000000000 --- a/core/src/io/anuke/mindustry/content/bullets/ShellBullets.java +++ /dev/null @@ -1,127 +0,0 @@ -package io.anuke.mindustry.content.bullets; - -import io.anuke.mindustry.content.fx.BulletFx; -import io.anuke.mindustry.content.fx.Fx; -import io.anuke.mindustry.entities.bullet.BasicBulletType; -import io.anuke.mindustry.entities.bullet.BulletType; -import io.anuke.mindustry.type.ContentList; - -public class ShellBullets extends BulletList implements ContentList { - public static BulletType lead, leadShard, thorium, thoriumShard, plastic, plasticShard, explosive, explosiveShard, incindiary; - - @Override - public void load() { - - lead = new BasicBulletType(3f, 0, "shell") { - { - hiteffect = BulletFx.flakExplosion; - knockback = 0.8f; - lifetime = 90f; - drag = 0.01f; - bulletWidth = bulletHeight = 9f; - fragBullet = leadShard; - bulletShrink = 0.1f; - } - }; - - leadShard = new BasicBulletType(3f, 0, "shell") { - { - drag = 0.1f; - hiteffect = Fx.none; - despawneffect = Fx.none; - hitsize = 4; - lifetime = 20f; - bulletWidth = 9f; - bulletHeight = 11f; - bulletShrink = 1f; - } - }; - - thorium = new BasicBulletType(3f, 0, "shell") { - { - hiteffect = BulletFx.flakExplosion; - knockback = 0.8f; - lifetime = 90f; - drag = 0.01f; - bulletWidth = bulletHeight = 9f; - fragBullet = leadShard; - bulletShrink = 0.1f; - } - }; - - thoriumShard = new BasicBulletType(3f, 0, "shell") { - { - drag = 0.1f; - hiteffect = Fx.none; - despawneffect = Fx.none; - hitsize = 4; - lifetime = 20f; - bulletWidth = 9f; - bulletHeight = 11f; - bulletShrink = 1f; - } - }; - - plastic = new BasicBulletType(3f, 0, "shell") { - { - hiteffect = BulletFx.flakExplosion; - knockback = 0.8f; - lifetime = 90f; - drag = 0.01f; - bulletWidth = bulletHeight = 9f; - fragBullet = leadShard; - bulletShrink = 0.1f; - } - }; - - plasticShard = new BasicBulletType(3f, 0, "shell") { - { - drag = 0.1f; - hiteffect = Fx.none; - despawneffect = Fx.none; - hitsize = 4; - lifetime = 20f; - bulletWidth = 9f; - bulletHeight = 11f; - bulletShrink = 1f; - } - }; - - explosive = new BasicBulletType(3f, 0, "shell") { - { - hiteffect = BulletFx.flakExplosion; - knockback = 0.8f; - lifetime = 90f; - drag = 0.01f; - bulletWidth = bulletHeight = 9f; - fragBullet = leadShard; - bulletShrink = 0.1f; - } - }; - - explosiveShard = new BasicBulletType(3f, 0, "shell") { - { - drag = 0.1f; - hiteffect = Fx.none; - despawneffect = Fx.none; - hitsize = 4; - lifetime = 20f; - bulletWidth = 9f; - bulletHeight = 11f; - bulletShrink = 1f; - } - }; - - incindiary = new BasicBulletType(3f, 0, "shell") { - { - hiteffect = BulletFx.flakExplosion; - knockback = 0.8f; - lifetime = 90f; - drag = 0.01f; - bulletWidth = bulletHeight = 9f; - fragBullet = leadShard; - bulletShrink = 0.1f; - } - }; - } -} diff --git a/core/src/io/anuke/mindustry/core/ContentLoader.java b/core/src/io/anuke/mindustry/core/ContentLoader.java index 4bb7810333..3e56b802c9 100644 --- a/core/src/io/anuke/mindustry/core/ContentLoader.java +++ b/core/src/io/anuke/mindustry/core/ContentLoader.java @@ -55,7 +55,6 @@ public class ContentLoader { new ArtilleryBullets(), new FlakBullets(), new MissileBullets(), - new ShellBullets(), new StandardBullets(), new TurretBullets(), diff --git a/core/src/io/anuke/mindustry/world/BaseBlock.java b/core/src/io/anuke/mindustry/world/BaseBlock.java index 32cd293903..9916cf39af 100644 --- a/core/src/io/anuke/mindustry/world/BaseBlock.java +++ b/core/src/io/anuke/mindustry/world/BaseBlock.java @@ -24,12 +24,16 @@ public abstract class BaseBlock { /**Returns the amount of items this block can accept.*/ public int acceptStack(Item item, int amount, Tile tile, Unit source){ if(acceptItem(item, tile, tile) && hasItems && source.getTeam() == tile.getTeam()){ - return Math.min(itemCapacity - tile.entity.items.totalItems(), amount); + return Math.min(getMaximumAccepted(tile, item), amount); }else{ return 0; } } + public int getMaximumAccepted(Tile tile, Item item){ + return itemCapacity - tile.entity.items.totalItems(); + } + /**Remove a stack from this inventory, and return the amount removed.*/ public int removeStack(Tile tile, Item item, int amount){ tile.entity.items.removeItem(item, amount); diff --git a/core/src/io/anuke/mindustry/world/blocks/production/PowerSmelter.java b/core/src/io/anuke/mindustry/world/blocks/production/PowerSmelter.java index daa8e0d877..5764f60641 100644 --- a/core/src/io/anuke/mindustry/world/blocks/production/PowerSmelter.java +++ b/core/src/io/anuke/mindustry/world/blocks/production/PowerSmelter.java @@ -33,6 +33,11 @@ public class PowerSmelter extends PowerBlock { protected Item result; protected float powerUse; + protected float minFlux = 0.2f; + protected int fluxNeeded = 1; + protected float baseFluxChance = 0.15f; + protected boolean useFlux = false; + protected float heatUpTime = 80f; protected float minHeat = 0.5f; @@ -42,13 +47,12 @@ public class PowerSmelter extends PowerBlock { burnEffect = BlockFx.fuelburn; protected Color flameColor = Color.valueOf("ffc999"); - protected int capacity = 20; - public PowerSmelter(String name) { super(name); hasItems = true; update = true; solid = true; + itemCapacity = 20; } @Override @@ -57,7 +61,7 @@ public class PowerSmelter extends PowerBlock { bars.remove(BarType.inventory); for(ItemStack item : inputs){ - bars.add(new BlockBar(BarType.inventory, true, tile -> (float) tile.entity.items.getItem(item.item) / capacity)); + bars.add(new BlockBar(BarType.inventory, true, tile -> (float) tile.entity.items.getItem(item.item) / itemCapacity)); } } @@ -70,8 +74,8 @@ public class PowerSmelter extends PowerBlock { stats.add(BlockStat.powerUse, powerUse * 60f); stats.add(BlockStat.outputItem, result.toString()); stats.add(BlockStat.craftSpeed, 60f/craftTime); - stats.add(BlockStat.inputItemCapacity, capacity); - stats.add(BlockStat.outputItemCapacity, capacity); + stats.add(BlockStat.inputItemCapacity, itemCapacity); + stats.add(BlockStat.outputItemCapacity, itemCapacity); } @Override @@ -104,14 +108,31 @@ public class PowerSmelter extends PowerBlock { } } - if(entity.items.getItem(result) >= capacity //output full + if(entity.items.getItem(result) >= itemCapacity //output full || entity.heat <= minHeat //not burning || !entity.timer.get(timerCraft, craftTime)){ //not yet time return; } - for(ItemStack item : inputs){ - entity.items.removeItem(item.item, item.amount); + boolean consumeInputs = false; + + if(useFlux){ + //remove flux materials if present + for(Item item : Item.all()){ + if(item.fluxiness >= minFlux && tile.entity.items.getItem(item) >= fluxNeeded){ + tile.entity.items.removeItem(item, fluxNeeded); + + //chance of not consuming inputs if flux material present + consumeInputs = !Mathf.chance(item.fluxiness * baseFluxChance); + break; + } + } + } + + if(consumeInputs) { + for (ItemStack item : inputs) { + entity.items.removeItem(item.item, item.amount); + } } offloadNear(tile, result); @@ -123,13 +144,22 @@ public class PowerSmelter extends PowerBlock { for(ItemStack stack : inputs){ if(stack.item == item){ - return tile.entity.items.getItem(item) < capacity; + return tile.entity.items.getItem(item) < itemCapacity; } } + if(useFlux && item.fluxiness >= minFlux){ + return tile.entity.items.getItem(item) < itemCapacity; + } + return false; } + @Override + public int getMaximumAccepted(Tile tile, Item item) { + return itemCapacity - tile.entity.items.getItem(item); + } + @Override public void draw(Tile tile){ super.draw(tile); diff --git a/core/src/io/anuke/mindustry/world/blocks/production/Smelter.java b/core/src/io/anuke/mindustry/world/blocks/production/Smelter.java index 85eecc87a7..35b0c93a5e 100644 --- a/core/src/io/anuke/mindustry/world/blocks/production/Smelter.java +++ b/core/src/io/anuke/mindustry/world/blocks/production/Smelter.java @@ -26,24 +26,27 @@ public class Smelter extends Block{ protected Item fuel; protected Item result; - protected float craftTime = 20f; //time to craft one item, so max 3 items per second by default - protected float burnDuration = 50f; //by default, the fuel will burn 45 frames, so that's 2.5 items/fuel at most + protected float minFlux = 0.2f; + protected float baseFluxChance = 0.15f; + protected boolean useFlux = false; + + protected float craftTime = 20f; + protected float burnDuration = 50f; protected Effect craftEffect = BlockFx.smelt, burnEffect = BlockFx.fuelburn; protected Color flameColor = Color.valueOf("ffb879"); - protected int capacity = 20; - public Smelter(String name) { super(name); update = true; hasItems = true; solid = true; + itemCapacity = 20; } @Override public void setBars(){ for(Item item : inputs){ - bars.add(new BlockBar(BarType.inventory, true, tile -> (float)tile.entity.items.getItem(item)/capacity)); + bars.add(new BlockBar(BarType.inventory, true, tile -> (float)tile.entity.items.getItem(item)/itemCapacity)); } } @@ -56,10 +59,21 @@ public class Smelter extends Block{ stats.add(BlockStat.inputItems, Arrays.toString(inputs)); stats.add(BlockStat.outputItem, result.toString()); stats.add(BlockStat.craftSpeed, 60f/craftTime); - stats.add(BlockStat.inputItemCapacity, capacity); - stats.add(BlockStat.outputItemCapacity, capacity); + stats.add(BlockStat.inputItemCapacity, itemCapacity); + stats.add(BlockStat.outputItemCapacity, itemCapacity); } - + + @Override + public void init() { + super.init(); + + for(Item item : inputs){ + if(item.fluxiness >= minFlux && useFlux){ + throw new IllegalArgumentException("'" + name + "' has input item '" + item.name + "', which is a flux, when useFlux is enabled. To prevent ambiguous item use, either remove this flux item from the inputs, or set useFlux to false."); + } + } + } + @Override public void update(Tile tile){ SmelterEntity entity = tile.entity(); @@ -90,20 +104,42 @@ public class Smelter extends Block{ } } - if(entity.items.getItem(result) >= capacity //output full + if(entity.items.getItem(result) >= itemCapacity //output full || entity.burnTime <= 0 //not burning || !entity.timer.get(timerCraft, craftTime)){ //not yet time return; } - for(Item item : inputs){ - entity.items.removeItem(item, 1); + boolean consumeInputs = false; + + if(useFlux){ + //remove flux materials if present + for(Item item : Item.all()){ + if(item.fluxiness >= minFlux && tile.entity.items.getItem(item) > 0){ + tile.entity.items.removeItem(item, 1); + + //chance of not consuming inputs if flux material present + consumeInputs = !Mathf.chance(item.fluxiness * baseFluxChance); + break; + } + } + } + + if(consumeInputs) { + for (Item item : inputs) { + entity.items.removeItem(item, 1); + } } offloadNear(tile, result); Effects.effect(craftEffect, flameColor, tile.drawx(), tile.drawy()); } + @Override + public int getMaximumAccepted(Tile tile, Item item) { + return itemCapacity - tile.entity.items.getItem(item); + } + @Override public boolean acceptItem(Item item, Tile tile, Tile source){ boolean isInput = false; @@ -115,7 +151,8 @@ public class Smelter extends Block{ } } - return (isInput && tile.entity.items.getItem(item) < capacity) || (item == fuel && tile.entity.items.getItem(fuel) < capacity); + return (isInput && tile.entity.items.getItem(item) < itemCapacity) || (item == fuel && tile.entity.items.getItem(fuel) < itemCapacity) || + (useFlux && item.fluxiness >= minFlux && tile.entity.items.getItem(item) < itemCapacity); } @Override