Implemented smelting with flux

This commit is contained in:
Anuken
2018-06-18 17:20:23 -04:00
parent c31a710aa7
commit 354c6e17c0
10 changed files with 106 additions and 176 deletions

View File

@ -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()

View File

@ -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) {{

View File

@ -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;
}};

View File

@ -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") {{

View File

@ -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;

View File

@ -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;
}
};
}
}

View File

@ -55,7 +55,6 @@ public class ContentLoader {
new ArtilleryBullets(),
new FlakBullets(),
new MissileBullets(),
new ShellBullets(),
new StandardBullets(),
new TurretBullets(),

View File

@ -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);

View File

@ -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);

View File

@ -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