Merge
This commit is contained in:
@@ -3,11 +3,17 @@ package io.anuke.mindustry.content;
|
||||
import io.anuke.arc.Core;
|
||||
import io.anuke.arc.graphics.Color;
|
||||
import io.anuke.arc.graphics.g2d.Draw;
|
||||
import io.anuke.arc.graphics.g2d.Lines;
|
||||
import io.anuke.arc.graphics.g2d.TextureRegion;
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.game.ContentList;
|
||||
import io.anuke.mindustry.graphics.CacheLayer;
|
||||
import io.anuke.mindustry.graphics.Pal;
|
||||
import io.anuke.mindustry.graphics.Shaders;
|
||||
import io.anuke.mindustry.type.Category;
|
||||
import io.anuke.mindustry.type.ItemStack;
|
||||
import io.anuke.mindustry.type.LiquidStack;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.*;
|
||||
@@ -24,9 +30,9 @@ import io.anuke.mindustry.world.blocks.storage.Vault;
|
||||
import io.anuke.mindustry.world.blocks.units.MechPad;
|
||||
import io.anuke.mindustry.world.blocks.units.RepairPoint;
|
||||
import io.anuke.mindustry.world.blocks.units.UnitFactory;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeItemFilter;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeLiquidFilter;
|
||||
import io.anuke.mindustry.world.meta.Attribute;
|
||||
import io.anuke.mindustry.world.modules.LiquidModule;
|
||||
|
||||
import static io.anuke.mindustry.Vars.state;
|
||||
import static io.anuke.mindustry.Vars.world;
|
||||
@@ -371,7 +377,7 @@ public class Blocks implements ContentList{
|
||||
requirements(Category.crafting, ItemStack.with(Items.copper, 150, Items.lead, 60));
|
||||
|
||||
craftEffect = Fx.pulverizeMedium;
|
||||
output = Items.graphite;
|
||||
outputItem = new ItemStack(Items.graphite, 1);
|
||||
craftTime = 90f;
|
||||
size = 2;
|
||||
hasItems = true;
|
||||
@@ -383,7 +389,7 @@ public class Blocks implements ContentList{
|
||||
requirements(Category.crafting, ItemStack.with(Items.titanium, 200, Items.silicon, 50, Items.lead, 200, Items.graphite, 100));
|
||||
|
||||
craftEffect = Fx.pulverizeMedium;
|
||||
output = Items.graphite;
|
||||
outputItem = new ItemStack(Items.graphite, 2);
|
||||
craftTime = 30f;
|
||||
size = 3;
|
||||
hasItems = true;
|
||||
@@ -391,14 +397,14 @@ public class Blocks implements ContentList{
|
||||
hasPower = true;
|
||||
|
||||
consumes.power(2f);
|
||||
consumes.item(Items.coal, 2);
|
||||
consumes.item(Items.coal, 4);
|
||||
consumes.liquid(Liquids.water, 0.1f);
|
||||
}};
|
||||
|
||||
siliconSmelter = new PowerSmelter("silicon-smelter"){{
|
||||
siliconSmelter = new GenericSmelter("silicon-smelter"){{
|
||||
requirements(Category.crafting, ItemStack.with(Items.copper, 60, Items.lead, 50));
|
||||
craftEffect = Fx.smeltsmoke;
|
||||
output = Items.silicon;
|
||||
outputItem = new ItemStack(Items.silicon, 1);
|
||||
craftTime = 40f;
|
||||
size = 2;
|
||||
hasLiquids = false;
|
||||
@@ -408,10 +414,10 @@ public class Blocks implements ContentList{
|
||||
consumes.power(0.50f);
|
||||
}};
|
||||
|
||||
kiln = new PowerSmelter("kiln"){{
|
||||
kiln = new GenericSmelter("kiln"){{
|
||||
requirements(Category.crafting, ItemStack.with(Items.copper, 120, Items.graphite, 60, Items.lead, 60));
|
||||
craftEffect = Fx.smeltsmoke;
|
||||
output = Items.metaglass;
|
||||
outputItem = new ItemStack(Items.metaglass, 1);
|
||||
craftTime = 30f;
|
||||
size = 2;
|
||||
hasPower = hasItems = true;
|
||||
@@ -421,12 +427,12 @@ public class Blocks implements ContentList{
|
||||
consumes.power(0.60f);
|
||||
}};
|
||||
|
||||
plastaniumCompressor = new PlastaniumCompressor("plastanium-compressor"){{
|
||||
plastaniumCompressor = new GenericCrafter("plastanium-compressor"){{
|
||||
requirements(Category.crafting, ItemStack.with(Items.silicon, 160, Items.lead, 230, Items.graphite, 120, Items.titanium, 160));
|
||||
hasItems = true;
|
||||
liquidCapacity = 60f;
|
||||
craftTime = 60f;
|
||||
output = Items.plastanium;
|
||||
outputItem = new ItemStack(Items.plastanium, 1);
|
||||
size = 2;
|
||||
health = 320;
|
||||
hasPower = hasLiquids = true;
|
||||
@@ -436,23 +442,69 @@ public class Blocks implements ContentList{
|
||||
consumes.liquid(Liquids.oil, 0.25f);
|
||||
consumes.power(3f);
|
||||
consumes.item(Items.titanium, 2);
|
||||
|
||||
int topRegion = reg("-top");
|
||||
|
||||
drawer = tile -> {
|
||||
super.draw(tile);
|
||||
|
||||
GenericCrafterEntity entity = tile.entity();
|
||||
|
||||
Draw.alpha(Mathf.absin(entity.totalProgress, 3f, 0.9f) * entity.warmup);
|
||||
Draw.rect(reg(topRegion), tile.drawx(), tile.drawy());
|
||||
Draw.reset();
|
||||
};
|
||||
}};
|
||||
|
||||
phaseWeaver = new PhaseWeaver("phase-weaver"){{
|
||||
phaseWeaver = new GenericCrafter("phase-weaver"){{
|
||||
requirements(Category.crafting, ItemStack.with(Items.silicon, 260, Items.lead, 240, Items.thorium, 150));
|
||||
craftEffect = Fx.smeltsmoke;
|
||||
output = Items.phasefabric;
|
||||
outputItem = new ItemStack(Items.phasefabric, 1);
|
||||
craftTime = 120f;
|
||||
size = 2;
|
||||
|
||||
consumes.items(new ItemStack(Items.thorium, 4), new ItemStack(Items.sand, 10));
|
||||
consumes.power(5f);
|
||||
|
||||
int bottomRegion = reg("-bottom"), weaveRegion = reg("-weave");
|
||||
|
||||
drawer = tile -> {
|
||||
GenericCrafterEntity entity = tile.entity();
|
||||
|
||||
Draw.rect(reg(bottomRegion), tile.drawx(), tile.drawy());
|
||||
|
||||
float progress = 0.5f;
|
||||
|
||||
Shaders.build.region = reg(weaveRegion);
|
||||
Shaders.build.progress = progress;
|
||||
Shaders.build.color.set(Pal.accent);
|
||||
Shaders.build.color.a = entity.warmup;
|
||||
Shaders.build.time = -entity.totalProgress / 10f;
|
||||
|
||||
Draw.shader(Shaders.build, false);
|
||||
Shaders.build.apply();
|
||||
Draw.rect(reg(weaveRegion), tile.drawx(), tile.drawy(), entity.totalProgress);
|
||||
Draw.shader();
|
||||
|
||||
Draw.color(Pal.accent);
|
||||
Draw.alpha(entity.warmup);
|
||||
|
||||
Lines.lineAngleCenter(
|
||||
tile.drawx() + Mathf.sin(entity.totalProgress, 6f, Vars.tilesize / 3f * size),
|
||||
tile.drawy(),
|
||||
90,
|
||||
size * Vars.tilesize / 2f);
|
||||
|
||||
Draw.reset();
|
||||
|
||||
Draw.rect(region, tile.drawx(), tile.drawy());
|
||||
};
|
||||
}};
|
||||
|
||||
surgeSmelter = new PowerSmelter("alloy-smelter"){{
|
||||
surgeSmelter = new GenericSmelter("alloy-smelter"){{
|
||||
requirements(Category.crafting, ItemStack.with(Items.silicon, 160, Items.lead, 160, Items.thorium, 140));
|
||||
craftEffect = Fx.smeltsmoke;
|
||||
output = Items.surgealloy;
|
||||
outputItem = new ItemStack(Items.surgealloy, 1);
|
||||
craftTime = 75f;
|
||||
size = 3;
|
||||
|
||||
@@ -460,35 +512,60 @@ public class Blocks implements ContentList{
|
||||
consumes.items(new ItemStack(Items.titanium, 2), new ItemStack(Items.lead, 4), new ItemStack(Items.silicon, 3), new ItemStack(Items.copper, 3));
|
||||
}};
|
||||
|
||||
cryofluidMixer = new LiquidMixer("cryofluidmixer"){{
|
||||
cryofluidMixer = new GenericCrafter("cryofluidmixer"){{
|
||||
requirements(Category.crafting, ItemStack.with(Items.lead, 130, Items.silicon, 80, Items.thorium, 90));
|
||||
outputLiquid = Liquids.cryofluid;
|
||||
liquidPerItem = 50f;
|
||||
outputLiquid = new LiquidStack(Liquids.cryofluid, 0.3f);
|
||||
craftTime = 5f;
|
||||
size = 2;
|
||||
hasPower = true;
|
||||
hasItems = true;
|
||||
rotate = false;
|
||||
solid = true;
|
||||
outputsLiquid = true;
|
||||
|
||||
consumes.power(1f);
|
||||
consumes.item(Items.titanium);
|
||||
consumes.liquid(Liquids.water, 0.3f);
|
||||
|
||||
int liquidRegion = reg("-liquid"), topRegion = reg("-top"), bottomRegion = reg("-bottom");
|
||||
|
||||
drawIcons = () -> new TextureRegion[]{Core.atlas.find(name + "-bottom"), Core.atlas.find(name + "-top")};
|
||||
|
||||
drawer = tile -> {
|
||||
LiquidModule mod = tile.entity.liquids;
|
||||
|
||||
int rotation = rotate ? tile.getRotation() * 90 : 0;
|
||||
|
||||
Draw.rect(reg(bottomRegion), tile.drawx(), tile.drawy(), rotation);
|
||||
|
||||
if(mod.total() > 0.001f){
|
||||
Draw.color(outputLiquid.liquid.color);
|
||||
Draw.alpha(mod.get(outputLiquid.liquid) / liquidCapacity);
|
||||
Draw.rect(reg(liquidRegion), tile.drawx(), tile.drawy(), rotation);
|
||||
Draw.color();
|
||||
}
|
||||
|
||||
Draw.rect(reg(topRegion), tile.drawx(), tile.drawy(), rotation);
|
||||
};
|
||||
}};
|
||||
|
||||
blastMixer = new GenericCrafter("blast-mixer"){{
|
||||
requirements(Category.crafting, ItemStack.with(Items.lead, 60, Items.titanium, 40));
|
||||
hasItems = true;
|
||||
hasPower = true;
|
||||
output = Items.blastCompound;
|
||||
outputItem = new ItemStack(Items.blastCompound, 1);
|
||||
size = 2;
|
||||
|
||||
consumes.items(new ItemStack(Items.pyratite, 1), new ItemStack(Items.sporePod, 1));
|
||||
consumes.power(0.40f);
|
||||
}};
|
||||
|
||||
pyratiteMixer = new PowerSmelter("pyratite-mixer"){{
|
||||
pyratiteMixer = new GenericSmelter("pyratite-mixer"){{
|
||||
requirements(Category.crafting, ItemStack.with(Items.copper, 100, Items.lead, 50));
|
||||
flameColor = Color.CLEAR;
|
||||
hasItems = true;
|
||||
hasPower = true;
|
||||
output = Items.pyratite;
|
||||
outputItem = new ItemStack(Items.pyratite, 1);
|
||||
|
||||
size = 2;
|
||||
|
||||
@@ -496,11 +573,10 @@ public class Blocks implements ContentList{
|
||||
consumes.items(new ItemStack(Items.coal, 1), new ItemStack(Items.lead, 2), new ItemStack(Items.sand, 2));
|
||||
}};
|
||||
|
||||
melter = new PowerCrafter("melter"){{
|
||||
melter = new GenericCrafter("melter"){{
|
||||
requirements(Category.crafting, ItemStack.with(Items.copper, 60, Items.lead, 70, Items.graphite, 90));
|
||||
health = 200;
|
||||
outputLiquid = Liquids.slag;
|
||||
outputLiquidAmount = 2f;
|
||||
outputLiquid = new LiquidStack(Liquids.slag, 2f);
|
||||
craftTime = 10f;
|
||||
hasLiquids = hasPower = true;
|
||||
|
||||
@@ -517,7 +593,7 @@ public class Blocks implements ContentList{
|
||||
Items.titanium, 2
|
||||
);
|
||||
hasPower = true;
|
||||
filterTime = 35f;
|
||||
craftTime = 35f;
|
||||
spinnerLength = 1.5f;
|
||||
spinnerRadius = 3.5f;
|
||||
spinnerThickness = 1.5f;
|
||||
@@ -530,7 +606,7 @@ public class Blocks implements ContentList{
|
||||
|
||||
cultivator = new Cultivator("cultivator"){{
|
||||
requirements(Category.crafting, ItemStack.with(Items.copper, 20, Items.lead, 50, Items.silicon, 20));
|
||||
output = Items.sporePod;
|
||||
outputItem = new ItemStack(Items.sporePod, 1);
|
||||
craftTime = 160;
|
||||
size = 2;
|
||||
hasLiquids = true;
|
||||
@@ -541,23 +617,41 @@ public class Blocks implements ContentList{
|
||||
consumes.liquid(Liquids.water, 0.15f);
|
||||
}};
|
||||
|
||||
sporePress = new Compressor("spore-press"){{
|
||||
sporePress = new GenericCrafter("spore-press"){{
|
||||
requirements(Category.crafting, ItemStack.with(Items.lead, 70, Items.silicon, 60));
|
||||
liquidCapacity = 60f;
|
||||
craftTime = 20f;
|
||||
outputLiquid = Liquids.oil;
|
||||
outputLiquidAmount = 4f;
|
||||
outputLiquid = new LiquidStack(Liquids.oil, 4f);
|
||||
size = 2;
|
||||
health = 320;
|
||||
hasLiquids = true;
|
||||
|
||||
consumes.item(Items.sporePod, 1);
|
||||
consumes.power(0.60f);
|
||||
|
||||
int[] frameRegions = new int[3];
|
||||
for(int i = 0; i < 3; i++){
|
||||
frameRegions[i] = reg("-frame" + i);
|
||||
}
|
||||
|
||||
int liquidRegion = reg("-liquid");
|
||||
int topRegion =reg("-top");
|
||||
|
||||
drawer = tile -> {
|
||||
GenericCrafterEntity entity = tile.entity();
|
||||
|
||||
Draw.rect(region, tile.drawx(), tile.drawy());
|
||||
Draw.rect(reg(frameRegions[(int) Mathf.absin(entity.totalProgress, 5f, 2.999f)]), tile.drawx(), tile.drawy());
|
||||
Draw.color(Color.CLEAR, tile.entity.liquids.current().color, tile.entity.liquids.total() / liquidCapacity);
|
||||
Draw.rect(reg(liquidRegion), tile.drawx(), tile.drawy());
|
||||
Draw.color();
|
||||
Draw.rect(reg(topRegion), tile.drawx(), tile.drawy());
|
||||
};
|
||||
}};
|
||||
|
||||
pulverizer = new Pulverizer("pulverizer"){{
|
||||
pulverizer = new GenericCrafter("pulverizer"){{
|
||||
requirements(Category.crafting, ItemStack.with(Items.copper, 60, Items.lead, 50));
|
||||
output = Items.sand;
|
||||
outputItem = new ItemStack(Items.sand, 1);
|
||||
craftEffect = Fx.pulverize;
|
||||
craftTime = 40f;
|
||||
updateEffect = Fx.pulverizeSmall;
|
||||
@@ -565,6 +659,15 @@ public class Blocks implements ContentList{
|
||||
|
||||
consumes.item(Items.scrap, 1);
|
||||
consumes.power(0.50f);
|
||||
|
||||
int rotatorRegion = reg("-rotator");
|
||||
|
||||
drawer = tile -> {
|
||||
GenericCrafterEntity entity = tile.entity();
|
||||
|
||||
Draw.rect(region, tile.drawx(), tile.drawy());
|
||||
Draw.rect(reg(rotatorRegion), tile.drawx(), tile.drawy(), entity.totalProgress * 2f);
|
||||
};
|
||||
}};
|
||||
|
||||
incinerator = new Incinerator("incinerator"){{
|
||||
@@ -725,13 +828,13 @@ public class Blocks implements ContentList{
|
||||
requirements(Category.effect, ItemStack.with(Items.lead, 200, Items.titanium, 150, Items.silicon, 150, Items.plastanium, 60));
|
||||
consumes.power(3.50f);
|
||||
size = 2;
|
||||
consumes.item(Items.phasefabric).optional(true).boost(true);
|
||||
consumes.item(Items.phasefabric).optional(true);
|
||||
}};
|
||||
|
||||
forceProjector = new ForceProjector("force-projector"){{
|
||||
requirements(Category.effect, ItemStack.with(Items.lead, 200, Items.titanium, 150, Items.silicon, 250));
|
||||
size = 3;
|
||||
consumes.item(Items.phasefabric).optional(true).boost(true);
|
||||
consumes.item(Items.phasefabric).optional(true);
|
||||
}};
|
||||
|
||||
shockMine = new ShockMine("shock-mine"){{
|
||||
@@ -921,7 +1024,7 @@ public class Blocks implements ContentList{
|
||||
size = 2;
|
||||
}};
|
||||
|
||||
turbineGenerator = new TurbineGenerator("turbine-generator"){{
|
||||
turbineGenerator = new BurnerGenerator("turbine-generator"){{
|
||||
requirements(Category.power, ItemStack.with(Items.copper, 70, Items.graphite, 50, Items.lead, 80, Items.silicon, 60));
|
||||
powerProduction = 6f;
|
||||
itemDuration = 30f;
|
||||
@@ -930,15 +1033,15 @@ public class Blocks implements ContentList{
|
||||
size = 2;
|
||||
}};
|
||||
|
||||
differentialGenerator = new DifferentialGenerator("differential-generator"){{
|
||||
differentialGenerator = new ItemLiquidGenerator(true, true, "differential-generator"){{
|
||||
requirements(Category.power, ItemStack.with(Items.copper, 140, Items.titanium, 100, Items.lead, 200, Items.silicon, 130, Items.metaglass, 100));
|
||||
powerProduction = 13f;
|
||||
itemDuration = 50f;
|
||||
consumes.remove(ConsumeItemFilter.class);
|
||||
consumes.remove(ConsumeLiquidFilter.class);
|
||||
hasLiquids = true;
|
||||
size = 3;
|
||||
|
||||
consumes.item(Items.pyratite);
|
||||
consumes.liquid(Liquids.cryofluid, 0.2f);
|
||||
size = 3;
|
||||
}};
|
||||
|
||||
rtgGenerator = new DecayGenerator("rtg-generator"){{
|
||||
@@ -973,7 +1076,7 @@ public class Blocks implements ContentList{
|
||||
size = 4;
|
||||
health = 900;
|
||||
powerProduction = 80f;
|
||||
useTime = 40f;
|
||||
itemDuration = 40f;
|
||||
consumes.power(23f);
|
||||
consumes.item(Items.blastCompound);
|
||||
consumes.liquid(Liquids.cryofluid, 0.8f);
|
||||
@@ -988,6 +1091,7 @@ public class Blocks implements ContentList{
|
||||
drillTime = 600;
|
||||
size = 2;
|
||||
drawMineItem = true;
|
||||
consumes.liquid(Liquids.water, 0.05f).optional(true);
|
||||
}};
|
||||
|
||||
pneumaticDrill = new Drill("pneumatic-drill"){{
|
||||
@@ -1367,7 +1471,6 @@ public class Blocks implements ContentList{
|
||||
);
|
||||
reload = 6f;
|
||||
coolantMultiplier = 0.5f;
|
||||
maxCoolantUsed = 1.5f;
|
||||
restitution = 0.1f;
|
||||
ammoUseEffect = Fx.shellEjectBig;
|
||||
range = 200f;
|
||||
@@ -1381,6 +1484,7 @@ public class Blocks implements ContentList{
|
||||
shootCone = 24f;
|
||||
|
||||
health = 155 * size * size;
|
||||
consumes.add(new ConsumeLiquidFilter(liquid -> liquid.temperature <= 0.5f && liquid.flammability < 0.1f, 2f)).update(false).optional(true);
|
||||
}};
|
||||
|
||||
meltdown = new LaserTurret("meltdown"){{
|
||||
|
||||
@@ -69,7 +69,7 @@ public class Items implements ContentList{
|
||||
|
||||
plastanium = new Item("plastanium", Color.valueOf("cbd97f")){{
|
||||
type = ItemType.material;
|
||||
flammability = 0.2f;
|
||||
flammability = 0.1f;
|
||||
explosiveness = 0.2f;
|
||||
cost = 1.3f;
|
||||
}};
|
||||
|
||||
@@ -287,11 +287,11 @@ public class UI implements ApplicationListener{
|
||||
|
||||
public String formatAmount(int number){
|
||||
if(number >= 1000000){
|
||||
return Strings.toFixed(number / 1000000f, 1) + "[gray]mil[]";
|
||||
return Strings.fixed(number / 1000000f, 1) + "[gray]mil[]";
|
||||
}else if(number >= 10000){
|
||||
return number / 1000 + "[gray]k[]";
|
||||
}else if(number >= 1000){
|
||||
return Strings.toFixed(number / 1000f, 1) + "[gray]k[]";
|
||||
return Strings.fixed(number / 1000f, 1) + "[gray]k[]";
|
||||
}else{
|
||||
return number + "";
|
||||
}
|
||||
|
||||
@@ -184,7 +184,7 @@ public class WaveInfoDialog extends FloatingDialog{
|
||||
}).width(80f);
|
||||
|
||||
a.add(" + ");
|
||||
a.addField(Strings.toFixed(Math.max((Mathf.isZero(group.unitScaling) ? 0 : 1f/group.unitScaling), 0), 2), TextFieldFilter.floatsOnly, text -> {
|
||||
a.addField(Strings.fixed(Math.max((Mathf.isZero(group.unitScaling) ? 0 : 1f/group.unitScaling), 0), 2), TextFieldFilter.floatsOnly, text -> {
|
||||
if(Strings.canParsePositiveFloat(text)){
|
||||
group.unitScaling = 1f / Strings.parseFloat(text);
|
||||
updateWaves();
|
||||
|
||||
@@ -5,17 +5,17 @@ import io.anuke.annotations.Annotations.Remote;
|
||||
import io.anuke.arc.Events;
|
||||
import io.anuke.arc.collection.Array;
|
||||
import io.anuke.arc.collection.ObjectSet;
|
||||
import io.anuke.mindustry.entities.Effects;
|
||||
import io.anuke.mindustry.entities.EntityGroup;
|
||||
import io.anuke.mindustry.entities.impl.BaseEntity;
|
||||
import io.anuke.mindustry.entities.traits.HealthTrait;
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.arc.math.geom.Point2;
|
||||
import io.anuke.arc.math.geom.Vector2;
|
||||
import io.anuke.arc.util.Interval;
|
||||
import io.anuke.arc.util.Time;
|
||||
import io.anuke.mindustry.content.Fx;
|
||||
import io.anuke.mindustry.entities.Effects;
|
||||
import io.anuke.mindustry.entities.EntityGroup;
|
||||
import io.anuke.mindustry.entities.bullet.Bullet;
|
||||
import io.anuke.mindustry.entities.impl.BaseEntity;
|
||||
import io.anuke.mindustry.entities.traits.HealthTrait;
|
||||
import io.anuke.mindustry.entities.traits.TargetTrait;
|
||||
import io.anuke.mindustry.game.EventType.BlockDestroyEvent;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
@@ -24,7 +24,6 @@ import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Edges;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.defense.Wall;
|
||||
import io.anuke.mindustry.world.consumers.Consume;
|
||||
import io.anuke.mindustry.world.modules.ConsumeModule;
|
||||
import io.anuke.mindustry.world.modules.ItemModule;
|
||||
import io.anuke.mindustry.world.modules.LiquidModule;
|
||||
@@ -44,6 +43,7 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
|
||||
public static int sleepingEntities = 0;
|
||||
|
||||
public Tile tile;
|
||||
public Block block;
|
||||
public Interval timer;
|
||||
public float health;
|
||||
public float timeScale = 1f, timeScaleDuration;
|
||||
@@ -81,10 +81,10 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
|
||||
this.tile = tile;
|
||||
x = tile.drawx();
|
||||
y = tile.drawy();
|
||||
block = tile.block();
|
||||
|
||||
health = tile.block().health;
|
||||
|
||||
timer = new Interval(tile.block().timers);
|
||||
health = block.health;
|
||||
timer = new Interval(block.timers);
|
||||
|
||||
if(shouldAdd){
|
||||
add();
|
||||
@@ -139,7 +139,7 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
|
||||
}
|
||||
|
||||
public void collision(Bullet other){
|
||||
tile.block().handleBulletHit(this, other);
|
||||
block.handleBulletHit(this, other);
|
||||
}
|
||||
|
||||
public void kill(){
|
||||
@@ -151,7 +151,7 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
|
||||
|
||||
float preHealth = health;
|
||||
|
||||
Call.onTileDamage(tile, health - tile.block().handleDamage(tile, damage));
|
||||
Call.onTileDamage(tile, health - block.handleDamage(tile, damage));
|
||||
|
||||
if(health <= 0){
|
||||
Call.onTileDestroyed(tile);
|
||||
@@ -170,14 +170,10 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
|
||||
return tile;
|
||||
}
|
||||
|
||||
public boolean consumed(Class<? extends Consume> type){
|
||||
return tile.block().consumes.get(type).valid(tile.block(), this);
|
||||
}
|
||||
|
||||
public void removeFromProximity(){
|
||||
tile.block().onProximityRemoved(tile);
|
||||
block.onProximityRemoved(tile);
|
||||
|
||||
Point2[] nearby = Edges.getEdges(tile.block().size);
|
||||
Point2[] nearby = Edges.getEdges(block.size);
|
||||
for(Point2 point : nearby){
|
||||
Tile other = world.tile(tile.x + point.x, tile.y + point.y);
|
||||
//remove this tile from all nearby tile's proximities
|
||||
@@ -195,7 +191,7 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
|
||||
tmpTiles.clear();
|
||||
proximity.clear();
|
||||
|
||||
Point2[] nearby = Edges.getEdges(tile.block().size);
|
||||
Point2[] nearby = Edges.getEdges(block.size);
|
||||
for(Point2 point : nearby){
|
||||
Tile other = world.tile(tile.x + point.x, tile.y + point.y);
|
||||
|
||||
@@ -218,8 +214,8 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
|
||||
proximity.add(tile);
|
||||
}
|
||||
|
||||
tile.block().onProximityAdded(tile);
|
||||
tile.block().onProximityUpdate(tile);
|
||||
block.onProximityAdded(tile);
|
||||
block.onProximityUpdate(tile);
|
||||
}
|
||||
|
||||
public Array<Tile> proximity(){
|
||||
@@ -238,7 +234,7 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
|
||||
|
||||
@Override
|
||||
public float maxHealth(){
|
||||
return tile.block().health;
|
||||
return block.health;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -250,7 +246,6 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
|
||||
public void onDeath(){
|
||||
if(!dead){
|
||||
dead = true;
|
||||
Block block = tile.block();
|
||||
|
||||
Events.fire(new BlockDestroyEvent(tile));
|
||||
block.onDestroyed(tile);
|
||||
@@ -273,22 +268,22 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
|
||||
@Override
|
||||
public void update(){
|
||||
//TODO better smoke effect, this one is awful
|
||||
if(health != 0 && health < tile.block().health && !(tile.block() instanceof Wall) &&
|
||||
Mathf.chance(0.009f * Time.delta() * (1f - health / tile.block().health))){
|
||||
if(health != 0 && health < block.health && !(block instanceof Wall) &&
|
||||
Mathf.chance(0.009f * Time.delta() * (1f - health / block.health))){
|
||||
Effects.effect(Fx.smoke, x + Mathf.range(4), y + Mathf.range(4));
|
||||
}
|
||||
|
||||
timeScaleDuration -= Time.delta();
|
||||
if(timeScaleDuration <= 0f || !tile.block().canOverdrive){
|
||||
if(timeScaleDuration <= 0f || !block.canOverdrive){
|
||||
timeScale = 1f;
|
||||
}
|
||||
|
||||
if(health <= 0){
|
||||
onDeath();
|
||||
}
|
||||
Block previous = tile.block();
|
||||
tile.block().update(tile);
|
||||
if(tile.block() == previous && cons != null){
|
||||
Block previous = block;
|
||||
block.update(tile);
|
||||
if(block == previous && cons != null){
|
||||
cons.update();
|
||||
}
|
||||
}
|
||||
|
||||
19
core/src/io/anuke/mindustry/type/LiquidStack.java
Normal file
19
core/src/io/anuke/mindustry/type/LiquidStack.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package io.anuke.mindustry.type;
|
||||
|
||||
public class LiquidStack{
|
||||
public Liquid liquid;
|
||||
public float amount;
|
||||
|
||||
public LiquidStack(Liquid liquid, float amount){
|
||||
this.liquid = liquid;
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return "LiquidStack{" +
|
||||
"liquid=" + liquid +
|
||||
", amount=" + amount +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.anuke.mindustry.ui;
|
||||
|
||||
import io.anuke.arc.Core;
|
||||
import io.anuke.arc.collection.Array;
|
||||
import io.anuke.arc.collection.OrderedMap;
|
||||
import io.anuke.arc.graphics.Color;
|
||||
import io.anuke.arc.scene.ui.layout.Table;
|
||||
@@ -45,7 +46,7 @@ public class ContentDisplay{
|
||||
BlockStats stats = block.stats;
|
||||
|
||||
for(StatCategory cat : stats.toMap().keys()){
|
||||
OrderedMap<BlockStat, StatValue> map = stats.toMap().get(cat);
|
||||
OrderedMap<BlockStat, Array<StatValue>> map = stats.toMap().get(cat);
|
||||
|
||||
if(map.size == 0) continue;
|
||||
|
||||
@@ -56,7 +57,13 @@ public class ContentDisplay{
|
||||
table.table(inset -> {
|
||||
inset.left();
|
||||
inset.add("[LIGHT_GRAY]" + stat.localized() + ":[] ");
|
||||
map.get(stat).display(inset);
|
||||
Array<StatValue> arr = map.get(stat);
|
||||
for(StatValue value : arr){
|
||||
value.display(inset);
|
||||
inset.add().size(10f);
|
||||
}
|
||||
|
||||
//map.get(stat).display(inset);
|
||||
}).fillX().padLeft(10);
|
||||
table.row();
|
||||
}
|
||||
@@ -201,7 +208,7 @@ public class ContentDisplay{
|
||||
|
||||
table.add(Core.bundle.format("unit.health", unit.health));
|
||||
table.row();
|
||||
table.add(Core.bundle.format("unit.speed", Strings.toFixed(unit.speed, 1)));
|
||||
table.add(Core.bundle.format("unit.speed", Strings.fixed(unit.speed, 1)));
|
||||
table.row();
|
||||
table.row();
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ public class ItemDisplay extends Table{
|
||||
}
|
||||
|
||||
public ItemDisplay(Item item, int amount){
|
||||
add(new ItemImage(new ItemStack(item, amount))).size(8*3);
|
||||
add(new ItemImage(new ItemStack(item, amount))).size(8*4);
|
||||
add(item.localizedName()).padLeft(4);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public class ItemImage extends Stack{
|
||||
}
|
||||
|
||||
public ItemImage(ItemStack stack){
|
||||
add(new Image(stack.item.icon(Icon.medium)));
|
||||
add(new Image(stack.item.icon(Icon.large)));
|
||||
|
||||
if(stack.amount != 0){
|
||||
Table t = new Table().left().bottom();
|
||||
|
||||
@@ -1,14 +1,31 @@
|
||||
package io.anuke.mindustry.ui;
|
||||
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.arc.graphics.Color;
|
||||
import io.anuke.arc.scene.ui.Image;
|
||||
import io.anuke.arc.scene.ui.layout.Stack;
|
||||
import io.anuke.arc.scene.ui.layout.Table;
|
||||
import io.anuke.arc.util.Strings;
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.mindustry.world.meta.StatUnit;
|
||||
|
||||
/**An ItemDisplay, but for liquids.*/
|
||||
public class LiquidDisplay extends Table{
|
||||
|
||||
public LiquidDisplay(Liquid liquid){
|
||||
add(new Image(liquid.getContentIcon())).size(8*3);
|
||||
add(liquid.localizedName()).padLeft(3);
|
||||
public LiquidDisplay(Liquid liquid, float amount, boolean perSecond){
|
||||
add(new Stack(){{
|
||||
add(new Image(liquid.getContentIcon()));
|
||||
|
||||
if(amount != 0){
|
||||
Table t = new Table().left().bottom();
|
||||
t.add(Strings.autoFixed(amount, 1));
|
||||
add(t);
|
||||
}
|
||||
}}).size(8*4).padRight(3);
|
||||
|
||||
if(perSecond){
|
||||
add(StatUnit.perSecond.localized()).padLeft(2).padRight(5).color(Color.LIGHT_GRAY);
|
||||
}
|
||||
|
||||
add(liquid.localizedName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,9 +187,9 @@ public class BlockInventoryFragment extends Fragment{
|
||||
private String round(float f){
|
||||
f = (int) f;
|
||||
if(f >= 1000000){
|
||||
return Strings.toFixed(f / 1000000f, 1) + "[gray]mil[]";
|
||||
return Strings.fixed(f / 1000000f, 1) + "[gray]mil[]";
|
||||
}else if(f >= 1000){
|
||||
return Strings.toFixed(f / 1000, 1) + "k";
|
||||
return Strings.fixed(f / 1000, 1) + "k";
|
||||
}else{
|
||||
return (int) f + "";
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ public class PlacementFragment extends Fragment{
|
||||
topTable.table(header -> {
|
||||
header.left();
|
||||
header.add(new Image(lastDisplay.icon(Icon.medium))).size(8 * 4);
|
||||
header.labelWrap(() -> !unlocked(lastDisplay) ? Core.bundle.get("blocks.unknown") : lastDisplay.localizedName)
|
||||
header.labelWrap(() -> !unlocked(lastDisplay) ? Core.bundle.get("block.unknown") : lastDisplay.localizedName)
|
||||
.left().width(190f).padLeft(5);
|
||||
header.add().growX();
|
||||
if(unlocked(lastDisplay)){
|
||||
|
||||
@@ -32,7 +32,7 @@ import io.anuke.mindustry.ui.Bar;
|
||||
import io.anuke.mindustry.ui.ContentDisplay;
|
||||
import io.anuke.mindustry.world.consumers.Consume;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeLiquid;
|
||||
import io.anuke.mindustry.world.consumers.ConsumePower;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeType;
|
||||
import io.anuke.mindustry.world.meta.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -108,6 +108,9 @@ public class Block extends BlockStorage{
|
||||
public BooleanProvider buildVisibility = () -> false;
|
||||
public boolean alwaysUnlocked = false;
|
||||
|
||||
protected TextureRegion[] cacheRegions = {};
|
||||
protected Array<String> cacheRegionStrings = new Array<>();
|
||||
|
||||
protected Array<Tile> tempTiles = new Array<>();
|
||||
protected TextureRegion[] icons = new TextureRegion[Icon.values().length];
|
||||
protected TextureRegion[] generatedIcons;
|
||||
@@ -316,12 +319,28 @@ public class Block extends BlockStorage{
|
||||
setStats();
|
||||
setBars();
|
||||
|
||||
consumes.checkRequired(this);
|
||||
consumes.init();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(){
|
||||
region = Core.atlas.find(name);
|
||||
|
||||
cacheRegions = new TextureRegion[cacheRegionStrings.size];
|
||||
for(int i = 0; i < cacheRegions.length; i++){
|
||||
cacheRegions[i] = Core.atlas.find(cacheRegionStrings.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
/**Adds a region by name to be loaded, with the final name "{name}-suffix". Returns an ID to looks this region up by in {@link #reg(int)}.*/
|
||||
protected int reg(String suffix){
|
||||
cacheRegionStrings.add(name + suffix);
|
||||
return cacheRegionStrings.size - 1;
|
||||
}
|
||||
|
||||
/**Returns an internally cached region by ID.*/
|
||||
protected TextureRegion reg(int id){
|
||||
return cacheRegions[id];
|
||||
}
|
||||
|
||||
/** Called when the block is tapped. */
|
||||
@@ -374,7 +393,7 @@ public class Block extends BlockStorage{
|
||||
stats.add(BlockStat.size, "{0}x{0}", size);
|
||||
stats.add(BlockStat.health, health, StatUnit.none);
|
||||
|
||||
consumes.forEach(cons -> cons.display(stats));
|
||||
consumes.display(stats);
|
||||
|
||||
// Note: Power stats are added by the consumers.
|
||||
if(hasLiquids) stats.add(BlockStat.liquidCapacity, liquidCapacity, StatUnit.liquidUnits);
|
||||
@@ -386,25 +405,25 @@ public class Block extends BlockStorage{
|
||||
|
||||
if(hasLiquids){
|
||||
Function<TileEntity, Liquid> current;
|
||||
if(consumes.has(ConsumeLiquid.class)){
|
||||
Liquid liquid = consumes.liquid();
|
||||
if(consumes.has(ConsumeType.liquid) && consumes.get(ConsumeType.liquid) instanceof ConsumeLiquid){
|
||||
Liquid liquid = consumes.<ConsumeLiquid>get(ConsumeType.liquid).liquid;
|
||||
current = entity -> liquid;
|
||||
}else{
|
||||
current = entity -> entity.liquids.current();
|
||||
}
|
||||
bars.add("liquid", entity -> new Bar(() -> entity.liquids.get(current.get(entity)) <= 0.001f ? Core.bundle.get("blocks.liquid") : current.get(entity).localizedName(), () -> current.get(entity).color, () -> entity.liquids.get(current.get(entity)) / liquidCapacity));
|
||||
bars.add("liquid", entity -> new Bar(() -> entity.liquids.get(current.get(entity)) <= 0.001f ? Core.bundle.get("bar.liquid") : current.get(entity).localizedName(), () -> current.get(entity).color, () -> entity.liquids.get(current.get(entity)) / liquidCapacity));
|
||||
}
|
||||
|
||||
if(hasPower && consumes.has(ConsumePower.class)){
|
||||
boolean buffered = consumes.get(ConsumePower.class).isBuffered;
|
||||
float capacity = consumes.get(ConsumePower.class).powerCapacity;
|
||||
if(hasPower && consumes.hasPower()){
|
||||
boolean buffered = consumes.getPower().isBuffered;
|
||||
float capacity = consumes.getPower().powerCapacity;
|
||||
|
||||
bars.add("power", entity -> new Bar(() -> buffered ? Core.bundle.format("blocks.powerbalance", Float.isNaN(entity.power.satisfaction * capacity) ? "<ERROR>" : (int)(entity.power.satisfaction * capacity)) :
|
||||
Core.bundle.get("blocks.power"), () -> Pal.powerBar, () -> entity.power.satisfaction));
|
||||
bars.add("power", entity -> new Bar(() -> buffered ? Core.bundle.format("bar.powerbalance", Float.isNaN(entity.power.satisfaction * capacity) ? "<ERROR>" : (int)(entity.power.satisfaction * capacity)) :
|
||||
Core.bundle.get("bar.power"), () -> Pal.powerBar, () -> entity.power.satisfaction));
|
||||
}
|
||||
|
||||
if(hasItems && configurable){
|
||||
bars.add("items", entity -> new Bar(() -> Core.bundle.format("blocks.items", entity.items.total()), () -> Pal.items, () -> (float)entity.items.total() / itemCapacity));
|
||||
bars.add("items", entity -> new Bar(() -> Core.bundle.format("bar.items", entity.items.total()), () -> Pal.items, () -> (float)entity.items.total() / itemCapacity));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -456,8 +475,8 @@ public class Block extends BlockStorage{
|
||||
explosiveness += tile.entity.liquids.sum((liquid, amount) -> liquid.flammability * amount / 2f);
|
||||
}
|
||||
|
||||
if(consumes.has(ConsumePower.class) && consumes.get(ConsumePower.class).isBuffered){
|
||||
power += tile.entity.power.satisfaction * consumes.get(ConsumePower.class).powerCapacity;
|
||||
if(consumes.hasPower() && consumes.getPower().isBuffered){
|
||||
power += tile.entity.power.satisfaction * consumes.getPower().powerCapacity;
|
||||
}
|
||||
|
||||
if(hasLiquids){
|
||||
|
||||
@@ -12,15 +12,10 @@ import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.entities.type.Unit;
|
||||
import io.anuke.mindustry.game.UnlockableContent;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.type.ItemStack;
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeItem;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeItems;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeLiquid;
|
||||
import io.anuke.mindustry.world.consumers.Consumers;
|
||||
import io.anuke.mindustry.world.meta.BlockBars;
|
||||
import io.anuke.mindustry.world.meta.BlockStats;
|
||||
import io.anuke.mindustry.world.meta.Producers;
|
||||
|
||||
public abstract class BlockStorage extends UnlockableContent{
|
||||
public boolean hasItems;
|
||||
@@ -28,7 +23,6 @@ public abstract class BlockStorage extends UnlockableContent{
|
||||
public boolean hasPower;
|
||||
|
||||
public boolean outputsLiquid = false;
|
||||
public boolean singleLiquid = true;
|
||||
public boolean consumesPower = true;
|
||||
public boolean outputsPower = false;
|
||||
|
||||
@@ -39,7 +33,6 @@ public abstract class BlockStorage extends UnlockableContent{
|
||||
public final BlockStats stats = new BlockStats();
|
||||
public final BlockBars bars = new BlockBars();
|
||||
public final Consumers consumes = new Consumers();
|
||||
public final Producers produces = new Producers();
|
||||
|
||||
public BlockStorage(String name){
|
||||
super(name);
|
||||
@@ -98,21 +91,11 @@ public abstract class BlockStorage extends UnlockableContent{
|
||||
}
|
||||
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
if(tile.entity != null && consumes.has(ConsumeItems.class)){
|
||||
for(ItemStack stack : consumes.items()){
|
||||
if(stack.item == item){
|
||||
return tile.entity.items.get(item) < getMaximumAccepted(tile, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
return tile.entity != null && consumes.has(ConsumeItem.class) && consumes.item() == item &&
|
||||
tile.entity.items.get(item) < getMaximumAccepted(tile, item);
|
||||
return consumes.itemFilters[item.id] && tile.entity.items.get(item) < getMaximumAccepted(tile, item);
|
||||
}
|
||||
|
||||
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
||||
return hasLiquids && tile.entity.liquids.get(liquid) + amount < liquidCapacity &&
|
||||
(!singleLiquid || (tile.entity.liquids.current() == liquid || tile.entity.liquids.get(tile.entity.liquids.current()) < 0.2f)) &&
|
||||
(!consumes.has(ConsumeLiquid.class) || consumes.liquid() == liquid);
|
||||
return hasLiquids && tile.entity.liquids.get(liquid) + amount < liquidCapacity && consumes.liquidfilters[liquid.id];
|
||||
}
|
||||
|
||||
public void handleLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
||||
@@ -128,7 +111,7 @@ public abstract class BlockStorage extends UnlockableContent{
|
||||
Tile other = proximity.get((i + dump) % proximity.size);
|
||||
Tile in = Edges.getFacingEdge(tile, other);
|
||||
|
||||
if(other.getTeamID() == tile.getTeamID() && other.block().hasLiquids && canDumpLiquid(tile, other, liquid)){
|
||||
if(other.getTeam() == tile.getTeam() && other.block().hasLiquids && canDumpLiquid(tile, other, liquid)){
|
||||
float ofract = other.entity.liquids.get(liquid) / other.block().liquidCapacity;
|
||||
float fract = tile.entity.liquids.get(liquid) / liquidCapacity;
|
||||
|
||||
@@ -156,7 +139,7 @@ public abstract class BlockStorage extends UnlockableContent{
|
||||
|
||||
next = next.target();
|
||||
|
||||
if(next.getTeamID() == tile.getTeamID() && next.block().hasLiquids && tile.entity.liquids.get(liquid) > 0f){
|
||||
if(next.getTeam() == tile.getTeam() && next.block().hasLiquids && tile.entity.liquids.get(liquid) > 0f){
|
||||
|
||||
if(next.block().acceptLiquid(next, tile, liquid, 0f)){
|
||||
float ofract = next.entity.liquids.get(liquid) / next.block().liquidCapacity;
|
||||
@@ -206,7 +189,7 @@ public abstract class BlockStorage extends UnlockableContent{
|
||||
incrementDump(tile, proximity.size);
|
||||
Tile other = proximity.get((i + dump) % proximity.size);
|
||||
Tile in = Edges.getFacingEdge(tile, other);
|
||||
if(other.getTeamID() == tile.getTeamID() && other.block().acceptItem(item, other, in) && canDump(tile, other, item)){
|
||||
if(other.getTeam() == tile.getTeam() && other.block().acceptItem(item, other, in) && canDump(tile, other, item)){
|
||||
other.block().handleItem(item, other, in);
|
||||
return;
|
||||
}
|
||||
@@ -215,9 +198,7 @@ public abstract class BlockStorage extends UnlockableContent{
|
||||
handleItem(item, tile, tile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Try dumping any item near the tile.
|
||||
*/
|
||||
/**Try dumping any item near the tile.*/
|
||||
public boolean tryDump(Tile tile){
|
||||
return tryDump(tile, null);
|
||||
}
|
||||
@@ -246,7 +227,7 @@ public abstract class BlockStorage extends UnlockableContent{
|
||||
for(int ii = 0; ii < Vars.content.items().size; ii++){
|
||||
Item item = Vars.content.item(ii);
|
||||
|
||||
if(other.getTeamID() == tile.getTeamID() && entity.items.has(item) && other.block().acceptItem(item, other, in) && canDump(tile, other, item)){
|
||||
if(other.getTeam() == tile.getTeam() && entity.items.has(item) && other.block().acceptItem(item, other, in) && canDump(tile, other, item)){
|
||||
other.block().handleItem(item, other, in);
|
||||
tile.entity.items.remove(item, 1);
|
||||
incrementDump(tile, proximity.size);
|
||||
@@ -255,7 +236,7 @@ public abstract class BlockStorage extends UnlockableContent{
|
||||
}
|
||||
}else{
|
||||
|
||||
if(other.getTeamID() == tile.getTeamID() && other.block().acceptItem(todump, other, in) && canDump(tile, other, todump)){
|
||||
if(other.getTeam() == tile.getTeam() && other.block().acceptItem(todump, other, in) && canDump(tile, other, todump)){
|
||||
other.block().handleItem(todump, other, in);
|
||||
tile.entity.items.remove(todump, 1);
|
||||
incrementDump(tile, proximity.size);
|
||||
|
||||
@@ -21,6 +21,7 @@ import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeLiquidFilter;
|
||||
import io.anuke.mindustry.world.consumers.ConsumePower;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeType;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.StatUnit;
|
||||
|
||||
@@ -54,7 +55,7 @@ public class ForceProjector extends Block {
|
||||
canOverdrive = false;
|
||||
hasLiquids = true;
|
||||
hasItems = true;
|
||||
consumes.add(new ConsumeLiquidFilter(liquid -> liquid.temperature <= 0.5f && liquid.flammability < 0.1f, 0.1f)).optional(true).boost(true).update(false);
|
||||
consumes.add(new ConsumeLiquidFilter(liquid -> liquid.temperature <= 0.5f && liquid.flammability < 0.1f, 0.1f)).optional(true).update(false);
|
||||
consumePower = new ConsumeForceProjectorPower(60f, 60f);
|
||||
consumes.add(consumePower);
|
||||
}
|
||||
@@ -71,6 +72,8 @@ public class ForceProjector extends Block {
|
||||
|
||||
stats.add(BlockStat.powerUse, basePowerDraw * 60f, StatUnit.powerSecond);
|
||||
stats.add(BlockStat.powerDamage, powerDamage, StatUnit.powerUnits);
|
||||
|
||||
stats.add(BlockStat.boostEffect, phaseRadiusBoost/tilesize, StatUnit.blocks);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -83,10 +86,10 @@ public class ForceProjector extends Block {
|
||||
entity.shield.add();
|
||||
}
|
||||
|
||||
entity.phaseHeat = Mathf.lerpDelta(entity.phaseHeat, (float)entity.items.get(consumes.item()) / itemCapacity, 0.1f);
|
||||
entity.phaseHeat = Mathf.lerpDelta(entity.phaseHeat, Mathf.num(entity.cons.optionalValid()), 0.1f);
|
||||
|
||||
if(entity.cons.valid() && !entity.broken && entity.timer.get(timerUse, phaseUseTime) && entity.items.total() > 0){
|
||||
entity.items.remove(consumes.item(), 1);
|
||||
if(entity.cons.optionalValid() && !entity.broken && entity.timer.get(timerUse, phaseUseTime)){
|
||||
entity.cons.trigger();
|
||||
}
|
||||
|
||||
entity.radscl = Mathf.lerpDelta(entity.radscl, entity.broken ? 0f : 1f, 0.05f);
|
||||
@@ -95,7 +98,7 @@ public class ForceProjector extends Block {
|
||||
Effects.effect(Fx.reactorsmoke, tile.drawx() + Mathf.range(tilesize/2f), tile.drawy() + Mathf.range(tilesize/2f));
|
||||
}
|
||||
|
||||
// Use Cases:
|
||||
//use cases:
|
||||
// - There is enough power in the buffer, and there are no shots fired => Draw base power and keep shield up
|
||||
// - There is enough power in the buffer, but not enough power to cope for shots being fired => Draw all power and break shield
|
||||
// - There is enough power in the buffer and enough power to cope for shots being fired => Draw base power + additional power based on shots absorbed
|
||||
@@ -120,8 +123,9 @@ public class ForceProjector extends Block {
|
||||
|
||||
if(entity.buildup > 0){
|
||||
float scale = !entity.broken ? cooldownNormal : cooldownBrokenBase;
|
||||
if(consumes.get(ConsumeLiquidFilter.class).valid(this, entity)){
|
||||
consumes.get(ConsumeLiquidFilter.class).update(this, entity);
|
||||
ConsumeLiquidFilter cons = consumes.get(ConsumeType.liquid);
|
||||
if(cons.valid(entity)){
|
||||
cons.update(entity);
|
||||
scale *= (cooldownLiquid * (1f+(entity.liquids.current().heatCapacity-0.4f)*0.9f));
|
||||
}
|
||||
|
||||
@@ -268,8 +272,8 @@ public class ForceProjector extends Block {
|
||||
super(powerCapacity / ticksToFill, powerCapacity, true);
|
||||
}
|
||||
@Override
|
||||
public boolean valid(Block block, TileEntity entity){
|
||||
return entity.power.satisfaction >= basePowerDraw / powerCapacity && super.valid(block, entity);
|
||||
public boolean valid(TileEntity entity){
|
||||
return entity.power.satisfaction >= basePowerDraw / powerCapacity && super.valid(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +60,9 @@ public class MendProjector extends Block{
|
||||
|
||||
stats.add(BlockStat.repairTime, (int)(100f / healPercent * reload / 60f), StatUnit.seconds);
|
||||
stats.add(BlockStat.range, range / tilesize, StatUnit.blocks);
|
||||
|
||||
stats.add(BlockStat.boostEffect, phaseRangeBoost/tilesize, StatUnit.blocks);
|
||||
stats.add(BlockStat.boostEffect, (phaseBoost + healPercent) / healPercent, StatUnit.timesSpeed);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -68,10 +71,10 @@ public class MendProjector extends Block{
|
||||
entity.heat = Mathf.lerpDelta(entity.heat, entity.cons.valid() || tile.isEnemyCheat() ? 1f : 0f, 0.08f);
|
||||
entity.charge += entity.heat * entity.delta();
|
||||
|
||||
entity.phaseHeat = Mathf.lerpDelta(entity.phaseHeat, (float)entity.items.get(consumes.item()) / itemCapacity, 0.1f);
|
||||
entity.phaseHeat = Mathf.lerpDelta(entity.phaseHeat, Mathf.num(entity.cons.optionalValid()), 0.1f);
|
||||
|
||||
if(entity.cons.valid() && entity.timer.get(timerUse, useTime) && entity.items.total() > 0){
|
||||
entity.items.remove(consumes.item(), 1);
|
||||
if(entity.cons.optionalValid() && entity.timer.get(timerUse, useTime)){
|
||||
entity.cons.trigger();
|
||||
}
|
||||
|
||||
if(entity.charge >= reload){
|
||||
|
||||
@@ -12,6 +12,8 @@ import io.anuke.arc.util.Time;
|
||||
import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.StatUnit;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
@@ -50,16 +52,27 @@ public class OverdriveProjector extends Block{
|
||||
topRegion = Core.atlas.find(name + "-top");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
|
||||
stats.add(BlockStat.speedIncrease, (int)(100f * speedBoost), StatUnit.percent);
|
||||
stats.add(BlockStat.range, range / tilesize, StatUnit.blocks);
|
||||
|
||||
stats.add(BlockStat.boostEffect, phaseRangeBoost/tilesize, StatUnit.blocks);
|
||||
stats.add(BlockStat.boostEffect, (int)((speedBoost + speedBoostPhase) * 100f), StatUnit.percent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
OverdriveEntity entity = tile.entity();
|
||||
entity.heat = Mathf.lerpDelta(entity.heat, entity.cons.valid() ? 1f : 0f, 0.08f);
|
||||
entity.charge += entity.heat * Time.delta();
|
||||
|
||||
entity.phaseHeat = Mathf.lerpDelta(entity.phaseHeat, (float)entity.items.get(consumes.item()) / itemCapacity, 0.1f);
|
||||
entity.phaseHeat = Mathf.lerpDelta(entity.phaseHeat, Mathf.num(entity.cons.optionalValid()), 0.1f);
|
||||
|
||||
if(entity.timer.get(timerUse, useTime) && entity.items.total() > 0){
|
||||
entity.items.remove(consumes.item(), 1);
|
||||
if(entity.timer.get(timerUse, useTime)){
|
||||
entity.cons.trigger();
|
||||
}
|
||||
|
||||
if(entity.charge >= reload){
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
package io.anuke.mindustry.world.blocks.defense.turrets;
|
||||
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.arc.util.Time;
|
||||
import io.anuke.mindustry.content.Fx;
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeLiquidFilter;
|
||||
import io.anuke.mindustry.entities.Effects;
|
||||
import io.anuke.mindustry.entities.Effects.Effect;
|
||||
import io.anuke.arc.util.Time;
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeLiquidBase;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeLiquidFilter;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeType;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.StatUnit;
|
||||
|
||||
import static io.anuke.mindustry.Vars.tilesize;
|
||||
|
||||
public class CooledTurret extends Turret{
|
||||
/**How much reload is lowered by for each unit of liquid of heat capacity 1.*/
|
||||
protected float coolantMultiplier = 1f;
|
||||
/**Max coolant used per tick.*/
|
||||
protected float maxCoolantUsed = 1f;
|
||||
/**How much reload is lowered by for each unit of liquid of heat capacity.*/
|
||||
protected float coolantMultiplier = 2f;
|
||||
protected Effect coolEffect = Fx.fuelburn;
|
||||
|
||||
public CooledTurret(String name){
|
||||
@@ -23,17 +25,28 @@ public class CooledTurret extends Turret{
|
||||
hasLiquids = true;
|
||||
liquidCapacity = 20f;
|
||||
|
||||
consumes.add(new ConsumeLiquidFilter(liquid -> liquid.temperature <= 0.5f && liquid.flammability < 0.1f, 0.01f)).update(false).optional(true);
|
||||
consumes.add(new ConsumeLiquidFilter(liquid -> liquid.temperature <= 0.5f && liquid.flammability < 0.1f, 0.5f)).update(false).optional(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
|
||||
float maxUsed = consumes.<ConsumeLiquidBase>get(ConsumeType.liquid).amount;
|
||||
|
||||
stats.add(BlockStat.boostEffect, 1f + maxUsed * coolantMultiplier, StatUnit.timesSpeed);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateShooting(Tile tile){
|
||||
super.updateShooting(tile);
|
||||
|
||||
float maxUsed = consumes.<ConsumeLiquidBase>get(ConsumeType.liquid).amount;
|
||||
|
||||
TurretEntity entity = tile.entity();
|
||||
Liquid liquid = entity.liquids.current();
|
||||
|
||||
float used = Math.min(Math.min(entity.liquids.get(liquid), maxCoolantUsed * Time.delta()), Math.max(0, ((reload - entity.reload) / coolantMultiplier) / liquid.heatCapacity));
|
||||
float used = Math.min(Math.min(entity.liquids.get(liquid), maxUsed * Time.delta()), Math.max(0, ((reload - entity.reload) / coolantMultiplier) / liquid.heatCapacity));
|
||||
entity.reload += (used * liquid.heatCapacity) / liquid.heatCapacity;
|
||||
entity.liquids.remove(liquid, used);
|
||||
|
||||
@@ -41,9 +54,4 @@ public class CooledTurret extends Turret{
|
||||
Effects.effect(coolEffect, tile.drawx() + Mathf.range(size * tilesize / 2f), tile.drawy() + Mathf.range(size * tilesize / 2f));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
||||
return super.acceptLiquid(tile, source, liquid, amount) && liquid.temperature <= 0.5f;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
package io.anuke.mindustry.world.blocks.defense.turrets;
|
||||
|
||||
import io.anuke.mindustry.entities.Effects;
|
||||
import io.anuke.arc.math.Angles;
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.arc.util.Time;
|
||||
import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.entities.Effects;
|
||||
import io.anuke.mindustry.entities.bullet.Bullet;
|
||||
import io.anuke.mindustry.entities.bullet.BulletType;
|
||||
import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeLiquidBase;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeLiquidFilter;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeType;
|
||||
|
||||
import static io.anuke.mindustry.Vars.tilesize;
|
||||
|
||||
@@ -21,7 +23,6 @@ public class LaserTurret extends PowerTurret{
|
||||
super(name);
|
||||
canOverdrive = false;
|
||||
|
||||
consumes.remove(ConsumeLiquidFilter.class);
|
||||
consumes.add(new ConsumeLiquidFilter(liquid -> liquid.temperature <= 0.5f && liquid.flammability < 0.1f, 0.01f)).update(false);
|
||||
}
|
||||
|
||||
@@ -61,8 +62,9 @@ public class LaserTurret extends PowerTurret{
|
||||
entity.reload = 0f;
|
||||
}else{
|
||||
Liquid liquid = entity.liquids.current();
|
||||
float maxUsed = consumes.<ConsumeLiquidBase>get(ConsumeType.liquid).amount;
|
||||
|
||||
float used = Math.min(Math.min(entity.liquids.get(liquid), maxCoolantUsed * Time.delta()), Math.max(0, ((reload - entity.reload) / coolantMultiplier) / liquid.heatCapacity));
|
||||
float used = Math.min(Math.min(entity.liquids.get(liquid), maxUsed * Time.delta()), Math.max(0, ((reload - entity.reload) / coolantMultiplier) / liquid.heatCapacity));
|
||||
entity.reload += (used * liquid.heatCapacity) / liquid.heatCapacity;
|
||||
entity.liquids.remove(liquid, used);
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package io.anuke.mindustry.world.blocks.defense.turrets;
|
||||
|
||||
import io.anuke.mindustry.entities.bullet.BulletType;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.consumers.ConsumePower;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.StatUnit;
|
||||
|
||||
@@ -20,7 +19,7 @@ public abstract class PowerTurret extends CooledTurret{
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
|
||||
stats.add(BlockStat.powerShot, powerUsed * consumes.get(ConsumePower.class).powerCapacity, StatUnit.powerUnits);
|
||||
stats.add(BlockStat.powerShot, powerUsed * consumes.getPower().powerCapacity, StatUnit.powerUnits);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -125,7 +125,7 @@ public class MassDriver extends Block{
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
|
||||
stats.add(BlockStat.powerShot, consumes.get(ConsumePower.class).powerCapacity * powerPercentageUsed, StatUnit.powerUnits);
|
||||
stats.add(BlockStat.powerShot, consumes.getPower().powerCapacity * powerPercentageUsed, StatUnit.powerUnits);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
package io.anuke.mindustry.world.blocks.power;
|
||||
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeItem;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeLiquid;
|
||||
|
||||
public class DifferentialGenerator extends TurbineGenerator{
|
||||
|
||||
public DifferentialGenerator(String name){
|
||||
super(name);
|
||||
|
||||
hasLiquids = true;
|
||||
consumes.require(ConsumeItem.class);
|
||||
consumes.require(ConsumeLiquid.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
return hasItems && consumes.item() == item && tile.entity.items.total() < itemCapacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
||||
return hasLiquids && consumes.liquid() == liquid && tile.entity.liquids.get(liquid) < liquidCapacity;
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,8 @@ import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.graphics.Pal;
|
||||
import io.anuke.mindustry.ui.Bar;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.consumers.ConsumePower;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.StatUnit;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
@@ -29,7 +30,7 @@ public class ImpactReactor extends PowerGenerator{
|
||||
|
||||
protected int plasmas = 4;
|
||||
protected float warmupSpeed = 0.001f;
|
||||
protected float useTime = 60f;
|
||||
protected float itemDuration = 60f;
|
||||
protected int explosionRadius = 30;
|
||||
protected int explosionDamage = 180;
|
||||
|
||||
@@ -51,12 +52,21 @@ public class ImpactReactor extends PowerGenerator{
|
||||
super.setBars();
|
||||
|
||||
bars.add("poweroutput", entity -> new Bar(() ->
|
||||
Core.bundle.format("blocks.poweroutput",
|
||||
Strings.toFixed(Math.max(entity.tile.block().getPowerProduction(entity.tile) - consumes.get(ConsumePower.class).powerPerTick, 0)*60 * entity.delta(), 1)),
|
||||
Core.bundle.format("bar.poweroutput",
|
||||
Strings.fixed(Math.max(entity.tile.block().getPowerProduction(entity.tile) - consumes.getPower().powerPerTick, 0)*60 * entity.delta(), 1)),
|
||||
() -> Pal.powerBar,
|
||||
() -> ((GeneratorEntity)entity).productionEfficiency));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
|
||||
if(hasItems){
|
||||
stats.add(BlockStat.productionTime, itemDuration / 60f, StatUnit.seconds);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
FusionReactorEntity entity = tile.entity();
|
||||
@@ -64,8 +74,8 @@ public class ImpactReactor extends PowerGenerator{
|
||||
if(entity.cons.valid()){
|
||||
entity.warmup = Mathf.lerpDelta(entity.warmup, 1f, warmupSpeed);
|
||||
|
||||
if(entity.timer.get(timerUse, useTime)){
|
||||
entity.items.remove(consumes.item(), consumes.itemAmount());
|
||||
if(entity.timer.get(timerUse, itemDuration)){
|
||||
entity.cons.trigger();
|
||||
}
|
||||
}else{
|
||||
entity.warmup = Mathf.lerpDelta(entity.warmup, 0f, 0.01f);
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
package io.anuke.mindustry.world.blocks.power;
|
||||
|
||||
import io.anuke.arc.Core;
|
||||
import io.anuke.mindustry.entities.Effects;
|
||||
import io.anuke.arc.graphics.Color;
|
||||
import io.anuke.arc.graphics.g2d.Draw;
|
||||
import io.anuke.arc.graphics.g2d.TextureRegion;
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.arc.util.Time;
|
||||
import io.anuke.mindustry.content.Fx;
|
||||
import io.anuke.mindustry.entities.Effects;
|
||||
import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeItemFilter;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeLiquidFilter;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.StatUnit;
|
||||
|
||||
import static io.anuke.mindustry.Vars.content;
|
||||
import static io.anuke.mindustry.Vars.tilesize;
|
||||
@@ -44,11 +46,11 @@ public class ItemLiquidGenerator extends PowerGenerator{
|
||||
this.hasLiquids = hasLiquids;
|
||||
|
||||
if(hasItems){
|
||||
consumes.add(new ConsumeItemFilter(item -> getItemEfficiency(item) >= minItemEfficiency)).update(false).optional(true);
|
||||
consumes.add(new ConsumeItemFilter(item -> getItemEfficiency(item) >= minItemEfficiency)).update(false);
|
||||
}
|
||||
|
||||
if(hasLiquids){
|
||||
consumes.add(new ConsumeLiquidFilter(liquid -> getLiquidEfficiency(liquid) >= minLiquidEfficiency, 0.001f, true)).update(false).optional(true);
|
||||
consumes.add(new ConsumeLiquidFilter(liquid -> getLiquidEfficiency(liquid) >= minLiquidEfficiency, maxLiquidGenerate)).update(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +62,15 @@ public class ItemLiquidGenerator extends PowerGenerator{
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
|
||||
if(hasItems){
|
||||
stats.add(BlockStat.productionTime, itemDuration / 60f, StatUnit.seconds);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
ItemLiquidGeneratorEntity entity = tile.entity();
|
||||
|
||||
@@ -12,9 +12,15 @@ import io.anuke.mindustry.entities.Damage;
|
||||
import io.anuke.mindustry.entities.Effects;
|
||||
import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.graphics.Pal;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.mindustry.ui.Bar;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeItems;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeLiquid;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeType;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.StatUnit;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
@@ -29,7 +35,7 @@ public class NuclearReactor extends PowerGenerator{
|
||||
|
||||
protected Color coolColor = new Color(1, 1, 1, 0f);
|
||||
protected Color hotColor = Color.valueOf("ff9575a3");
|
||||
protected int fuelUseTime = 120; //time to consume 1 fuel
|
||||
protected int itemDuration = 120; //time to consume 1 fuel
|
||||
protected float heating = 0.01f; //heating per frame * fullness
|
||||
protected float smokeThreshold = 0.3f; //threshold at which block starts smoking
|
||||
protected int explosionRadius = 19;
|
||||
@@ -47,6 +53,15 @@ public class NuclearReactor extends PowerGenerator{
|
||||
hasLiquids = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
|
||||
if(hasItems){
|
||||
stats.add(BlockStat.productionTime, itemDuration / 60f, StatUnit.seconds);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(){
|
||||
super.load();
|
||||
@@ -58,27 +73,30 @@ public class NuclearReactor extends PowerGenerator{
|
||||
@Override
|
||||
public void setBars(){
|
||||
super.setBars();
|
||||
bars.add("heat", entity -> new Bar("blocks.heat", Pal.lightOrange, () -> ((NuclearReactorEntity)entity).heat));
|
||||
bars.add("heat", entity -> new Bar("bar.heat", Pal.lightOrange, () -> ((NuclearReactorEntity)entity).heat));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
NuclearReactorEntity entity = tile.entity();
|
||||
|
||||
int fuel = entity.items.get(consumes.item());
|
||||
ConsumeLiquid cliquid = consumes.get(ConsumeType.liquid);
|
||||
Item item = consumes.<ConsumeItems>get(ConsumeType.item).items[0].item;
|
||||
|
||||
int fuel = entity.items.get(item);
|
||||
float fullness = (float) fuel / itemCapacity;
|
||||
entity.productionEfficiency = fullness;
|
||||
|
||||
if(fuel > 0){
|
||||
entity.heat += fullness * heating * Math.min(entity.delta(), 4f);
|
||||
|
||||
if(entity.timer.get(timerFuel, fuelUseTime)){
|
||||
if(entity.timer.get(timerFuel, itemDuration)){
|
||||
entity.cons.trigger();
|
||||
}
|
||||
}
|
||||
|
||||
Liquid liquid = consumes.liquid();
|
||||
float liquidAmount = consumes.liquidAmount();
|
||||
Liquid liquid = cliquid.liquid;
|
||||
float liquidAmount = cliquid.amount;
|
||||
|
||||
if(entity.heat > 0){
|
||||
float maxUsed = Math.min(Math.min(entity.liquids.get(liquid), entity.heat / coolantPower), liquidAmount * entity.delta());
|
||||
@@ -109,7 +127,7 @@ public class NuclearReactor extends PowerGenerator{
|
||||
|
||||
NuclearReactorEntity entity = tile.entity();
|
||||
|
||||
int fuel = entity.items.get(consumes.item());
|
||||
int fuel = entity.items.get(consumes.<ConsumeItems>get(ConsumeType.item).items[0].item);
|
||||
|
||||
if(fuel < 5 && entity.heat < 0.5f) return;
|
||||
|
||||
|
||||
@@ -37,10 +37,10 @@ public class PowerGenerator extends PowerDistributor{
|
||||
public void setBars(){
|
||||
super.setBars();
|
||||
|
||||
if(hasPower && outputsPower && !consumes.has(ConsumePower.class)){
|
||||
if(hasPower && outputsPower && !consumes.hasPower()){
|
||||
bars.add("power", entity -> new Bar(() ->
|
||||
Core.bundle.format("blocks.poweroutput",
|
||||
Strings.toFixed(entity.tile.block().getPowerProduction(entity.tile)*60 * entity.timeScale, 1)),
|
||||
Core.bundle.format("bar.poweroutput",
|
||||
Strings.fixed(entity.tile.block().getPowerProduction(entity.tile)*60 * entity.timeScale, 1)),
|
||||
() -> Pal.powerBar,
|
||||
() -> ((GeneratorEntity)entity).productionEfficiency));
|
||||
}
|
||||
|
||||
@@ -54,8 +54,8 @@ public class PowerGraph{
|
||||
float powerNeeded = 0f;
|
||||
for(Tile consumer : consumers){
|
||||
Consumers consumes = consumer.block().consumes;
|
||||
if(consumes.has(ConsumePower.class)){
|
||||
ConsumePower consumePower = consumes.get(ConsumePower.class);
|
||||
if(consumes.hasPower()){
|
||||
ConsumePower consumePower = consumes.getPower();
|
||||
if(otherConsumersAreValid(consumer, consumePower)){
|
||||
powerNeeded += consumePower.requestedPower(consumer.block(), consumer.entity) * consumer.entity.delta();
|
||||
}
|
||||
@@ -68,8 +68,8 @@ public class PowerGraph{
|
||||
float totalAccumulator = 0f;
|
||||
for(Tile battery : batteries){
|
||||
Consumers consumes = battery.block().consumes;
|
||||
if(consumes.has(ConsumePower.class)){
|
||||
totalAccumulator += battery.entity.power.satisfaction * consumes.get(ConsumePower.class).powerCapacity;
|
||||
if(consumes.hasPower()){
|
||||
totalAccumulator += battery.entity.power.satisfaction * consumes.getPower().powerCapacity;
|
||||
}
|
||||
}
|
||||
return totalAccumulator;
|
||||
@@ -79,8 +79,8 @@ public class PowerGraph{
|
||||
float totalCapacity = 0f;
|
||||
for(Tile battery : batteries){
|
||||
Consumers consumes = battery.block().consumes;
|
||||
if(consumes.has(ConsumePower.class)){
|
||||
totalCapacity += consumes.get(ConsumePower.class).requestedPower(battery.block(), battery.entity) * battery.entity.delta();
|
||||
if(consumes.hasPower()){
|
||||
totalCapacity += consumes.getPower().requestedPower(battery.block(), battery.entity) * battery.entity.delta();
|
||||
}
|
||||
}
|
||||
return totalCapacity;
|
||||
@@ -94,8 +94,8 @@ public class PowerGraph{
|
||||
float consumedPowerPercentage = Math.min(1.0f, needed / stored);
|
||||
for(Tile battery : batteries){
|
||||
Consumers consumes = battery.block().consumes;
|
||||
if(consumes.has(ConsumePower.class)){
|
||||
ConsumePower consumePower = consumes.get(ConsumePower.class);
|
||||
if(consumes.hasPower()){
|
||||
ConsumePower consumePower = consumes.getPower();
|
||||
if(consumePower.powerCapacity > 0f){
|
||||
battery.entity.power.satisfaction = Math.max(0.0f, battery.entity.power.satisfaction - consumedPowerPercentage);
|
||||
}
|
||||
@@ -110,8 +110,8 @@ public class PowerGraph{
|
||||
|
||||
for(Tile battery : batteries){
|
||||
Consumers consumes = battery.block().consumes;
|
||||
if(consumes.has(ConsumePower.class)){
|
||||
ConsumePower consumePower = consumes.get(ConsumePower.class);
|
||||
if(consumes.hasPower()){
|
||||
ConsumePower consumePower = consumes.getPower();
|
||||
if(consumePower.powerCapacity > 0f){
|
||||
float additionalPowerPercentage = Math.min(1.0f, excess / consumePower.powerCapacity);
|
||||
battery.entity.power.satisfaction = Math.min(1.0f, battery.entity.power.satisfaction + additionalPowerPercentage);
|
||||
@@ -126,8 +126,8 @@ public class PowerGraph{
|
||||
float coverage = Mathf.isZero(needed) ? 1f : Math.min(1, produced / needed);
|
||||
for(Tile consumer : consumers){
|
||||
Consumers consumes = consumer.block().consumes;
|
||||
if(consumes.has(ConsumePower.class)){
|
||||
ConsumePower consumePower = consumes.get(ConsumePower.class);
|
||||
if(consumes.hasPower()){
|
||||
ConsumePower consumePower = consumes.getPower();
|
||||
//currently satisfies power even if it's not required yet
|
||||
if(consumePower.isBuffered){
|
||||
if(!Mathf.isZero(consumePower.powerCapacity)){
|
||||
@@ -176,7 +176,7 @@ public class PowerGraph{
|
||||
}
|
||||
|
||||
public void add(Tile tile){
|
||||
if(tile.block().consumes.has(ConsumePower.class) && !tile.block().consumes.get(ConsumePower.class).isBuffered){
|
||||
if(tile.block().consumes.hasPower() && !tile.block().consumes.getPower().isBuffered){
|
||||
//reset satisfaction to zero in case of direct consumer. There is no reason to clear power from buffered consumers.
|
||||
tile.entity.power.satisfaction = 0.0f;
|
||||
}
|
||||
@@ -184,7 +184,7 @@ public class PowerGraph{
|
||||
tile.entity.power.graph = this;
|
||||
all.add(tile);
|
||||
|
||||
if(tile.block().outputsPower && tile.block().consumesPower && !tile.block().consumes.get(ConsumePower.class).isBuffered){
|
||||
if(tile.block().outputsPower && tile.block().consumesPower && !tile.block().consumes.getPower().isBuffered){
|
||||
producers.add(tile);
|
||||
consumers.add(tile);
|
||||
}else if(tile.block().outputsPower && tile.block().consumesPower){
|
||||
@@ -259,7 +259,7 @@ public class PowerGraph{
|
||||
|
||||
private boolean otherConsumersAreValid(Tile tile, Consume consumePower){
|
||||
for(Consume cons : tile.block().consumes.all()){
|
||||
if(cons != consumePower && !cons.isOptional() && !cons.valid(tile.block(), tile.entity())){
|
||||
if(cons != consumePower && !cons.isOptional() && !cons.valid(tile.entity())){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,8 +92,8 @@ public class PowerNode extends PowerBlock{
|
||||
public void setBars(){
|
||||
super.setBars();
|
||||
bars.add("power", entity -> new Bar(() ->
|
||||
Core.bundle.format("blocks.powerbalance",
|
||||
((entity.power.graph.getPowerBalance() >= 0 ? "+" : "") + Strings.toFixed(entity.power.graph.getPowerBalance()*60, 1))),
|
||||
Core.bundle.format("bar.powerbalance",
|
||||
((entity.power.graph.getPowerBalance() >= 0 ? "+" : "") + Strings.fixed(entity.power.graph.getPowerBalance()*60, 1))),
|
||||
() -> Pal.powerBar,
|
||||
() -> Mathf.clamp(entity.power.graph.getPowerProduced() / entity.power.graph.getPowerNeeded())));
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public class ThermalGenerator extends PowerGenerator{
|
||||
|
||||
@Override
|
||||
public void drawPlace(int x, int y, int rotation, boolean valid){
|
||||
drawPlaceText(Core.bundle.formatDouble("blocks.efficiency", sumAttribute(Attribute.heat, x, y)*100, 1), x, y, valid);
|
||||
drawPlaceText(Core.bundle.formatFloat("bar.efficiency", sumAttribute(Attribute.heat, x, y)*100, 1), x, y, valid);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
package io.anuke.mindustry.world.blocks.power;
|
||||
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeLiquid;
|
||||
|
||||
public class TurbineGenerator extends BurnerGenerator{
|
||||
|
||||
public TurbineGenerator(String name){
|
||||
super(name);
|
||||
singleLiquid = false;
|
||||
|
||||
consumes.require(ConsumeLiquid.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
||||
return (liquid == consumes.liquid() && tile.entity.liquids.get(consumes.liquid()) < liquidCapacity);
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
package io.anuke.mindustry.world.blocks.production;
|
||||
|
||||
import io.anuke.arc.Core;
|
||||
import io.anuke.arc.graphics.Color;
|
||||
import io.anuke.arc.graphics.g2d.TextureRegion;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.production.GenericCrafter.GenericCrafterEntity;
|
||||
import io.anuke.arc.graphics.g2d.Draw;
|
||||
import io.anuke.arc.math.Mathf;
|
||||
|
||||
public class Compressor extends PowerCrafter{
|
||||
protected TextureRegion liquidRegion, topRegion;
|
||||
protected TextureRegion[] frameRegions;
|
||||
|
||||
public Compressor(String name){
|
||||
super(name);
|
||||
hasLiquids = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(){
|
||||
super.load();
|
||||
|
||||
frameRegions = new TextureRegion[3];
|
||||
for(int i = 0; i < 3; i++){
|
||||
frameRegions[i] = Core.atlas.find(name + "-frame" + i);
|
||||
}
|
||||
|
||||
liquidRegion = Core.atlas.find(name + "-liquid");
|
||||
topRegion = Core.atlas.find(name + "-top");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Tile tile){
|
||||
GenericCrafterEntity entity = tile.entity();
|
||||
|
||||
Draw.rect(region, tile.drawx(), tile.drawy());
|
||||
Draw.rect(frameRegions[(int) Mathf.absin(entity.totalProgress, 5f, 2.999f)], tile.drawx(), tile.drawy());
|
||||
Draw.color(Color.CLEAR, tile.entity.liquids.current().color, tile.entity.liquids.total() / liquidCapacity);
|
||||
Draw.rect(liquidRegion, tile.drawx(), tile.drawy());
|
||||
Draw.color();
|
||||
Draw.rect(topRegion, tile.drawx(), tile.drawy());
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureRegion[] generateIcons(){
|
||||
return new TextureRegion[]{Core.atlas.find(name), Core.atlas.find(name + "-top")};
|
||||
}
|
||||
}
|
||||
@@ -53,7 +53,7 @@ public class Cultivator extends GenericCrafter{
|
||||
public void setBars(){
|
||||
super.setBars();
|
||||
bars.add("multiplier", entity -> new Bar(() ->
|
||||
Core.bundle.formatDouble("blocks.efficiency",
|
||||
Core.bundle.formatFloat("bar.efficiency",
|
||||
((((CultivatorEntity)entity).boost + 1f) * ((CultivatorEntity)entity).warmup)*100f,1),
|
||||
() -> Pal.ammo,
|
||||
() -> ((CultivatorEntity)entity).warmup));
|
||||
@@ -61,7 +61,7 @@ public class Cultivator extends GenericCrafter{
|
||||
|
||||
@Override
|
||||
public void drawPlace(int x, int y, int rotation, boolean valid){
|
||||
drawPlaceText(Core.bundle.formatDouble("blocks.efficiency", (1+sumAttribute(Attribute.spores, x, y))*100, 1), x, y, valid);
|
||||
drawPlaceText(Core.bundle.formatFloat("bar.efficiency", (1+sumAttribute(Attribute.spores, x, y))*100, 1), x, y, valid);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -11,7 +11,6 @@ import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.arc.util.Strings;
|
||||
import io.anuke.arc.util.Time;
|
||||
import io.anuke.mindustry.content.Fx;
|
||||
import io.anuke.mindustry.content.Liquids;
|
||||
import io.anuke.mindustry.entities.Effects;
|
||||
import io.anuke.mindustry.entities.Effects.Effect;
|
||||
import io.anuke.mindustry.entities.type.TileEntity;
|
||||
@@ -22,7 +21,6 @@ import io.anuke.mindustry.type.ItemType;
|
||||
import io.anuke.mindustry.ui.Bar;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeLiquid;
|
||||
import io.anuke.mindustry.world.meta.BlockGroup;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.StatUnit;
|
||||
@@ -33,7 +31,6 @@ public class Drill extends Block{
|
||||
protected final static float hardnessDrillMultiplier = 50f;
|
||||
protected final int timerDump = timers++;
|
||||
|
||||
protected final Array<Tile> drawTiles = new Array<>();
|
||||
protected final ObjectIntMap<Item> oreCount = new ObjectIntMap<>();
|
||||
protected final Array<Item> itemArray = new Array<>();
|
||||
|
||||
@@ -41,8 +38,6 @@ public class Drill extends Block{
|
||||
protected int tier;
|
||||
/**Base time to drill one ore, in frames.*/
|
||||
protected float drillTime = 300;
|
||||
/**Whether the liquid is required to drill. If false, then it will be used as a speed booster.*/
|
||||
protected boolean liquidRequired = false;
|
||||
/**How many times faster the drill will progress when boosted by liquid.*/
|
||||
protected float liquidBoostIntensity = 1.6f;
|
||||
/**Speed at which the drill speeds up.*/
|
||||
@@ -75,8 +70,6 @@ public class Drill extends Block{
|
||||
hasLiquids = true;
|
||||
liquidCapacity = 5f;
|
||||
hasItems = true;
|
||||
|
||||
consumes.liquid(Liquids.water, 0.05f).optional(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -86,7 +79,7 @@ public class Drill extends Block{
|
||||
bars.add("drillspeed", e -> {
|
||||
DrillEntity entity = (DrillEntity)e;
|
||||
|
||||
return new Bar(() -> Core.bundle.format("blocks.outputspeed", Strings.toFixed(entity.lastDrillSpeed * 60 * entity.timeScale, 2)), () -> Pal.ammo, () -> entity.warmup);
|
||||
return new Bar(() -> Core.bundle.format("bar.drillspeed", Strings.fixed(entity.lastDrillSpeed * 60 * entity.timeScale, 2)), () -> Pal.ammo, () -> entity.warmup);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -162,6 +155,7 @@ public class Drill extends Block{
|
||||
});
|
||||
|
||||
stats.add(BlockStat.drillSpeed, 60f / drillTime * size * size, StatUnit.itemsSecond);
|
||||
stats.add(BlockStat.boostEffect, liquidBoostIntensity, StatUnit.timesSpeed);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -210,9 +204,10 @@ public class Drill extends Block{
|
||||
|
||||
float speed = 1f;
|
||||
|
||||
if(entity.consumed(ConsumeLiquid.class) && !liquidRequired){
|
||||
if(entity.cons.optionalValid()){
|
||||
speed = liquidBoostIntensity;
|
||||
}
|
||||
|
||||
if(hasPower){
|
||||
speed *= entity.power.satisfaction; // Drill slower when not at full power
|
||||
}
|
||||
@@ -275,14 +270,14 @@ public class Drill extends Block{
|
||||
}
|
||||
|
||||
public static class DrillEntity extends TileEntity{
|
||||
public float progress;
|
||||
public int index;
|
||||
public float warmup;
|
||||
public float drillTime;
|
||||
public float lastDrillSpeed;
|
||||
float progress;
|
||||
int index;
|
||||
float warmup;
|
||||
float drillTime;
|
||||
float lastDrillSpeed;
|
||||
|
||||
public int dominantItems;
|
||||
public Item dominantItem;
|
||||
int dominantItems;
|
||||
Item dominantItem;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package io.anuke.mindustry.world.blocks.production;
|
||||
|
||||
import io.anuke.arc.Core;
|
||||
import io.anuke.arc.graphics.g2d.Draw;
|
||||
import io.anuke.arc.graphics.g2d.TextureRegion;
|
||||
import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeItem;
|
||||
import io.anuke.arc.graphics.g2d.Draw;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.StatUnit;
|
||||
|
||||
public class Fracker extends SolidPump{
|
||||
protected final float itemUseTime = 100f;
|
||||
@@ -18,9 +18,13 @@ public class Fracker extends SolidPump{
|
||||
public Fracker(String name){
|
||||
super(name);
|
||||
hasItems = true;
|
||||
singleLiquid = false;
|
||||
}
|
||||
|
||||
consumes.require(ConsumeItem.class);
|
||||
@Override
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
|
||||
stats.add(BlockStat.productionTime, itemUseTime / 60f, StatUnit.seconds);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -55,14 +59,13 @@ public class Fracker extends SolidPump{
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
FrackerEntity entity = tile.entity();
|
||||
Item item = consumes.item();
|
||||
|
||||
while(entity.accumulator >= itemUseTime && entity.items.has(item, 1)){
|
||||
entity.items.remove(item, 1);
|
||||
entity.accumulator -= itemUseTime;
|
||||
}
|
||||
|
||||
if(entity.cons.valid() && entity.accumulator < itemUseTime){
|
||||
if(entity.accumulator >= itemUseTime){
|
||||
entity.cons.trigger();
|
||||
entity.accumulator -= itemUseTime;
|
||||
}
|
||||
|
||||
super.update(tile);
|
||||
entity.accumulator += entity.delta() * entity.power.satisfaction;
|
||||
}else{
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package io.anuke.mindustry.world.blocks.production;
|
||||
|
||||
import io.anuke.arc.graphics.g2d.Draw;
|
||||
import io.anuke.arc.function.Consumer;
|
||||
import io.anuke.arc.function.Supplier;
|
||||
import io.anuke.arc.graphics.g2d.TextureRegion;
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.arc.util.Time;
|
||||
import io.anuke.mindustry.content.Fx;
|
||||
@@ -8,8 +10,12 @@ import io.anuke.mindustry.entities.Effects;
|
||||
import io.anuke.mindustry.entities.Effects.Effect;
|
||||
import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.type.ItemStack;
|
||||
import io.anuke.mindustry.type.LiquidStack;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeLiquidBase;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeType;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.StatUnit;
|
||||
|
||||
@@ -20,13 +26,17 @@ import java.io.IOException;
|
||||
public class GenericCrafter extends Block{
|
||||
protected final int timerDump = timers++;
|
||||
|
||||
protected Item output;
|
||||
protected ItemStack outputItem;
|
||||
protected LiquidStack outputLiquid;
|
||||
|
||||
protected float craftTime = 80;
|
||||
protected Effect craftEffect = Fx.purify;
|
||||
protected Effect updateEffect = Fx.none;
|
||||
protected float updateEffectChance = 0.04f;
|
||||
|
||||
protected Consumer<Tile> drawer = null;
|
||||
protected Supplier<TextureRegion[]> drawIcons = null;
|
||||
|
||||
public GenericCrafter(String name){
|
||||
super(name);
|
||||
update = true;
|
||||
@@ -34,44 +44,52 @@ public class GenericCrafter extends Block{
|
||||
health = 60;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(){
|
||||
super.init();
|
||||
|
||||
produces.set(output);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStats(){
|
||||
if(consumes.has(ConsumeType.liquid)){
|
||||
ConsumeLiquidBase cons = consumes.get(ConsumeType.liquid);
|
||||
cons.timePeriod = craftTime;
|
||||
}
|
||||
|
||||
super.setStats();
|
||||
stats.add(BlockStat.craftSpeed, 60f / craftTime, StatUnit.itemsSecond);
|
||||
stats.add(BlockStat.outputItem, output);
|
||||
stats.add(BlockStat.productionTime, craftTime / 60f, StatUnit.seconds);
|
||||
|
||||
if(outputItem != null){
|
||||
stats.add(BlockStat.output, outputItem);
|
||||
}
|
||||
|
||||
if(outputLiquid != null){
|
||||
stats.add(BlockStat.output, outputLiquid.liquid, outputLiquid.amount, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Tile tile){
|
||||
Draw.rect(name, tile.drawx(), tile.drawy());
|
||||
if(drawer == null){
|
||||
super.draw(tile);
|
||||
}else{
|
||||
drawer.accept(tile);
|
||||
}
|
||||
}
|
||||
|
||||
if(!hasLiquids) return;
|
||||
|
||||
Draw.color(tile.entity.liquids.current().color);
|
||||
Draw.alpha(tile.entity.liquids.total() / liquidCapacity);
|
||||
Draw.rect("blank", tile.drawx(), tile.drawy(), 2, 2);
|
||||
Draw.color();
|
||||
@Override
|
||||
public TextureRegion[] generateIcons(){
|
||||
return drawIcons == null ? super.generateIcons() : drawIcons.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
GenericCrafterEntity entity = tile.entity();
|
||||
|
||||
if(entity.cons.valid() && tile.entity.items.get(output) < itemCapacity){
|
||||
if(entity.cons.valid()){
|
||||
|
||||
entity.progress += getProgressIncrease(entity, craftTime);
|
||||
entity.totalProgress += entity.delta();
|
||||
entity.warmup = Mathf.lerpDelta(entity.warmup, 1f, 0.02f);
|
||||
|
||||
if(Mathf.chance(Time.delta() * updateEffectChance))
|
||||
if(Mathf.chance(Time.delta() * updateEffectChance)){
|
||||
Effects.effect(updateEffect, entity.x + Mathf.range(size * 4f), entity.y + Mathf.range(size * 4));
|
||||
}
|
||||
}else{
|
||||
entity.warmup = Mathf.lerp(entity.warmup, 0f, 0.02f);
|
||||
}
|
||||
@@ -79,14 +97,28 @@ public class GenericCrafter extends Block{
|
||||
if(entity.progress >= 1f){
|
||||
entity.cons.trigger();
|
||||
|
||||
useContent(tile, output);
|
||||
offloadNear(tile, output);
|
||||
if(outputItem != null){
|
||||
useContent(tile, outputItem.item);
|
||||
for(int i = 0; i < outputItem.amount; i++){
|
||||
offloadNear(tile, outputItem.item);
|
||||
}
|
||||
}
|
||||
|
||||
if(outputLiquid != null){
|
||||
useContent(tile, outputLiquid.liquid);
|
||||
handleLiquid(tile, tile, outputLiquid.liquid, outputLiquid.amount);
|
||||
}
|
||||
|
||||
Effects.effect(craftEffect, tile.drawx(), tile.drawy());
|
||||
entity.progress = 0f;
|
||||
}
|
||||
|
||||
if(tile.entity.timer.get(timerDump, 5)){
|
||||
tryDump(tile, output);
|
||||
if(outputItem != null && tile.entity.timer.get(timerDump, 5)){
|
||||
tryDump(tile, outputItem.item);
|
||||
}
|
||||
|
||||
if(outputLiquid != null){
|
||||
tryDumpLiquid(tile, outputLiquid.liquid);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package io.anuke.mindustry.world.blocks.production;
|
||||
|
||||
import io.anuke.arc.Core;
|
||||
import io.anuke.arc.graphics.Color;
|
||||
import io.anuke.arc.graphics.g2d.Draw;
|
||||
import io.anuke.arc.graphics.g2d.Fill;
|
||||
import io.anuke.arc.graphics.g2d.TextureRegion;
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.arc.util.Time;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
|
||||
/**A GenericCrafter with a new glowing region drawn on top.*/
|
||||
public class GenericSmelter extends GenericCrafter{
|
||||
protected Color flameColor = Color.valueOf("ffc999");
|
||||
protected TextureRegion topRegion;
|
||||
|
||||
public GenericSmelter(String name){
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(){
|
||||
super.load();
|
||||
topRegion = Core.atlas.find(name + "-top");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Tile tile){
|
||||
super.draw(tile);
|
||||
|
||||
GenericCrafterEntity entity = tile.entity();
|
||||
|
||||
//draw glowing center
|
||||
if(entity.warmup > 0f && flameColor.a > 0.001f){
|
||||
float g = 0.3f;
|
||||
float r = 0.06f;
|
||||
float cr = Mathf.random(0.1f);
|
||||
|
||||
Draw.alpha(((1f - g) + Mathf.absin(Time.time(), 8f, g) + Mathf.random(r) - r) * entity.warmup);
|
||||
|
||||
Draw.tint(flameColor);
|
||||
Fill.circle(tile.drawx(), tile.drawy(), 3f + Mathf.absin(Time.time(), 5f, 2f) + cr);
|
||||
Draw.color(1f, 1f, 1f, entity.warmup);
|
||||
Draw.rect(topRegion, tile.drawx(), tile.drawy());
|
||||
Fill.circle(tile.drawx(), tile.drawy(), 1.9f + Mathf.absin(Time.time(), 5f, 1f) + cr);
|
||||
|
||||
Draw.color();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
package io.anuke.mindustry.world.blocks.production;
|
||||
|
||||
import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.LiquidBlock;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeLiquid;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.StatUnit;
|
||||
import io.anuke.mindustry.world.modules.LiquidModule;
|
||||
import io.anuke.arc.graphics.g2d.Draw;
|
||||
|
||||
public class LiquidMixer extends LiquidBlock{
|
||||
protected Liquid outputLiquid;
|
||||
protected float liquidPerItem = 50f;
|
||||
|
||||
public LiquidMixer(String name){
|
||||
super(name);
|
||||
hasItems = true;
|
||||
rotate = false;
|
||||
solid = true;
|
||||
singleLiquid = false;
|
||||
outputsLiquid = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(){
|
||||
super.init();
|
||||
|
||||
produces.set(outputLiquid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
|
||||
stats.add(BlockStat.liquidOutput, outputLiquid);
|
||||
stats.add(BlockStat.liquidOutputSpeed, 60f * consumes.get(ConsumeLiquid.class).used(), StatUnit.liquidSecond);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldConsume(Tile tile){
|
||||
return tile.entity.liquids.get(outputLiquid) < liquidCapacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
LiquidMixerEntity entity = tile.entity();
|
||||
|
||||
if(tile.entity.cons.valid()){
|
||||
float use = Math.min(consumes.get(ConsumeLiquid.class).used() * entity.delta(), liquidCapacity - entity.liquids.get(outputLiquid));
|
||||
if(hasPower){
|
||||
use *= entity.power.satisfaction; // Produce less liquid if power is not maxed
|
||||
}
|
||||
entity.accumulator += use;
|
||||
entity.liquids.add(outputLiquid, use);
|
||||
for(int i = 0; i < (int) (entity.accumulator / liquidPerItem); i++){
|
||||
if(!entity.items.has(consumes.item())) break;
|
||||
entity.items.remove(consumes.item(), 1);
|
||||
entity.accumulator -= liquidPerItem;
|
||||
}
|
||||
}
|
||||
|
||||
tryDumpLiquid(tile, outputLiquid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Tile tile){
|
||||
LiquidModule mod = tile.entity.liquids;
|
||||
|
||||
int rotation = rotate ? tile.getRotation() * 90 : 0;
|
||||
|
||||
Draw.rect(bottomRegion, tile.drawx(), tile.drawy(), rotation);
|
||||
|
||||
if(mod.total() > 0.001f){
|
||||
Draw.color(outputLiquid.color);
|
||||
Draw.alpha(mod.get(outputLiquid) / liquidCapacity);
|
||||
Draw.rect(liquidRegion, tile.drawx(), tile.drawy(), rotation);
|
||||
Draw.color();
|
||||
}
|
||||
|
||||
Draw.rect(topRegion, tile.drawx(), tile.drawy(), rotation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity newEntity(){
|
||||
return new LiquidMixerEntity();
|
||||
}
|
||||
|
||||
static class LiquidMixerEntity extends TileEntity{
|
||||
float accumulator;
|
||||
}
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
package io.anuke.mindustry.world.blocks.production;
|
||||
|
||||
import io.anuke.arc.Core;
|
||||
import io.anuke.arc.graphics.g2d.Draw;
|
||||
import io.anuke.arc.graphics.g2d.Lines;
|
||||
import io.anuke.arc.graphics.g2d.TextureRegion;
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.graphics.Pal;
|
||||
import io.anuke.mindustry.graphics.Shaders;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
|
||||
public class PhaseWeaver extends PowerSmelter{
|
||||
protected TextureRegion bottomRegion;
|
||||
protected TextureRegion weaveRegion;
|
||||
|
||||
public PhaseWeaver(String name){
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(){
|
||||
super.load();
|
||||
|
||||
bottomRegion = Core.atlas.find(name + "-bottom");
|
||||
weaveRegion = Core.atlas.find(name + "-weave");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureRegion[] generateIcons(){
|
||||
return new TextureRegion[]{Core.atlas.find(name + "-bottom"), Core.atlas.find(name)};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Tile tile){
|
||||
PowerSmelterEntity entity = tile.entity();
|
||||
|
||||
Draw.rect(bottomRegion, tile.drawx(), tile.drawy());
|
||||
|
||||
float progress = 0.5f;
|
||||
|
||||
Shaders.build.region = weaveRegion;
|
||||
Shaders.build.progress = progress;
|
||||
Shaders.build.color.set(Pal.accent);
|
||||
Shaders.build.color.a = entity.heat;
|
||||
Shaders.build.time = -entity.time / 10f;
|
||||
|
||||
Draw.shader(Shaders.build, false);
|
||||
Shaders.build.apply();
|
||||
Draw.rect(weaveRegion, tile.drawx(), tile.drawy(), entity.time);
|
||||
Draw.shader();
|
||||
|
||||
Draw.color(Pal.accent);
|
||||
Draw.alpha(entity.heat);
|
||||
|
||||
Lines.lineAngleCenter(
|
||||
tile.drawx() + Mathf.sin(entity.time, 6f, Vars.tilesize / 3f * size),
|
||||
tile.drawy(),
|
||||
90,
|
||||
size * Vars.tilesize / 2f);
|
||||
|
||||
Draw.reset();
|
||||
|
||||
Draw.rect(region, tile.drawx(), tile.drawy());
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package io.anuke.mindustry.world.blocks.production;
|
||||
|
||||
import io.anuke.arc.Core;
|
||||
import io.anuke.arc.graphics.g2d.TextureRegion;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.arc.graphics.g2d.Draw;
|
||||
import io.anuke.arc.math.Mathf;
|
||||
|
||||
public class PlastaniumCompressor extends GenericCrafter{
|
||||
protected TextureRegion topRegion;
|
||||
|
||||
public PlastaniumCompressor(String name){
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(){
|
||||
super.load();
|
||||
|
||||
topRegion = Core.atlas.find(name + "-top");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Tile tile){
|
||||
super.draw(tile);
|
||||
|
||||
GenericCrafterEntity entity = tile.entity();
|
||||
|
||||
Draw.alpha(Mathf.absin(entity.totalProgress, 3f, 0.9f) * entity.warmup);
|
||||
Draw.rect(topRegion, tile.drawx(), tile.drawy());
|
||||
Draw.reset();
|
||||
}
|
||||
}
|
||||
@@ -1,111 +0,0 @@
|
||||
package io.anuke.mindustry.world.blocks.production;
|
||||
|
||||
import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.production.GenericCrafter.GenericCrafterEntity;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
|
||||
/**Similar to GenericCrafter, but also optionally outputs liquids.
|
||||
* TODO consolidate into one class*/
|
||||
public class PowerCrafter extends Block{
|
||||
protected final int timerDump = timers++;
|
||||
protected final int timerContentCheck = timers++;
|
||||
|
||||
/**Optional.*/
|
||||
protected Item outputItem;
|
||||
/**Optional. Set hasLiquids to true when using.*/
|
||||
protected Liquid outputLiquid;
|
||||
protected float outputLiquidAmount;
|
||||
protected float craftTime;
|
||||
|
||||
public PowerCrafter(String name){
|
||||
super(name);
|
||||
solid = true;
|
||||
update = true;
|
||||
hasPower = true;
|
||||
hasItems = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(){
|
||||
super.init();
|
||||
|
||||
if(outputLiquid != null){
|
||||
outputsLiquid = true;
|
||||
}
|
||||
|
||||
if(outputLiquid != null){
|
||||
produces.set(outputLiquid);
|
||||
}else if(outputItem != null){
|
||||
produces.set(outputItem);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
|
||||
if(outputItem != null){
|
||||
stats.add(BlockStat.outputItem, outputItem);
|
||||
}
|
||||
|
||||
if(outputLiquid != null){
|
||||
stats.add(BlockStat.liquidOutput, outputLiquid);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canProduce(Tile tile){
|
||||
if(outputItem != null && tile.entity.items.get(outputItem) >= itemCapacity){
|
||||
return false;
|
||||
}
|
||||
return outputLiquid == null || !(tile.entity.liquids.get(outputLiquid) >= liquidCapacity - 0.01f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
GenericCrafterEntity entity = tile.entity();
|
||||
|
||||
if(entity.cons.valid()){
|
||||
entity.progress += getProgressIncrease(entity, craftTime);
|
||||
entity.totalProgress += entity.delta();
|
||||
}
|
||||
|
||||
if(entity.progress >= 1f){
|
||||
entity.items.remove(consumes.item(), consumes.itemAmount());
|
||||
if(outputItem != null){
|
||||
offloadNear(tile, outputItem);
|
||||
useContent(tile, outputItem);
|
||||
}
|
||||
|
||||
if(outputLiquid != null){
|
||||
handleLiquid(tile, tile, outputLiquid, outputLiquidAmount);
|
||||
if(tile.entity.liquids.currentAmount() > 0f && tile.entity.timer.get(timerContentCheck, 10)){
|
||||
useContent(tile, outputLiquid);
|
||||
}
|
||||
}
|
||||
entity.progress = 0f;
|
||||
}
|
||||
|
||||
if(outputItem != null && entity.timer.get(timerDump, 5)){
|
||||
tryDump(tile, outputItem);
|
||||
}
|
||||
|
||||
if(outputLiquid != null){
|
||||
tryDumpLiquid(tile, entity.liquids.current());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity newEntity(){
|
||||
return new GenericCrafterEntity();
|
||||
}
|
||||
}
|
||||
@@ -1,175 +0,0 @@
|
||||
package io.anuke.mindustry.world.blocks.production;
|
||||
|
||||
import io.anuke.arc.Core;
|
||||
import io.anuke.mindustry.entities.Effects;
|
||||
import io.anuke.mindustry.entities.Effects.Effect;
|
||||
import io.anuke.arc.graphics.Color;
|
||||
import io.anuke.arc.graphics.g2d.Draw;
|
||||
import io.anuke.arc.graphics.g2d.Fill;
|
||||
import io.anuke.arc.graphics.g2d.TextureRegion;
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.arc.util.Time;
|
||||
import io.anuke.mindustry.content.Fx;
|
||||
import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.type.ItemStack;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.PowerBlock;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.StatUnit;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
||||
public class PowerSmelter extends PowerBlock{
|
||||
protected final int timerDump = timers++;
|
||||
|
||||
protected Item output;
|
||||
|
||||
protected float heatUpTime = 80f;
|
||||
protected float minHeat = 0.5f;
|
||||
|
||||
protected float craftTime = 20f; //time to craft one item, so max 3 items per second by default
|
||||
protected float burnEffectChance = 0.01f;
|
||||
protected Effect craftEffect = Fx.smelt,
|
||||
burnEffect = Fx.fuelburn;
|
||||
protected Color flameColor = Color.valueOf("ffc999");
|
||||
|
||||
protected TextureRegion topRegion;
|
||||
|
||||
public PowerSmelter(String name){
|
||||
super(name);
|
||||
hasItems = true;
|
||||
update = true;
|
||||
solid = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(){
|
||||
super.init();
|
||||
|
||||
produces.set(output);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(){
|
||||
super.load();
|
||||
topRegion = Core.atlas.find(name + "-top");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
|
||||
stats.add(BlockStat.outputItem, output);
|
||||
stats.add(BlockStat.craftSpeed, 60f / craftTime, StatUnit.itemsSecond);
|
||||
stats.add(BlockStat.inputItemCapacity, itemCapacity, StatUnit.items);
|
||||
stats.add(BlockStat.outputItemCapacity, itemCapacity, StatUnit.items);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
|
||||
PowerSmelterEntity entity = tile.entity();
|
||||
|
||||
if(entity.timer.get(timerDump, 5) && entity.items.has(output)){
|
||||
tryDump(tile, output);
|
||||
}
|
||||
|
||||
//heat it up if there's enough power
|
||||
if(entity.cons.valid()){
|
||||
entity.heat += 1f / heatUpTime * entity.delta();
|
||||
if(Mathf.chance(entity.delta() * burnEffectChance))
|
||||
Effects.effect(burnEffect, entity.x + Mathf.range(size * 4f), entity.y + Mathf.range(size * 4));
|
||||
}else{
|
||||
entity.heat -= 1f / heatUpTime * Time.delta();
|
||||
}
|
||||
|
||||
entity.heat = Mathf.clamp(entity.heat);
|
||||
entity.time += entity.heat * entity.delta();
|
||||
|
||||
if(!entity.cons.valid()){
|
||||
return;
|
||||
}
|
||||
|
||||
entity.craftTime += entity.delta() * entity.power.satisfaction;
|
||||
|
||||
if(entity.items.get(output) >= itemCapacity //output full
|
||||
|| entity.heat <= minHeat //not burning
|
||||
|| entity.craftTime < craftTime){ //not yet time
|
||||
return;
|
||||
}
|
||||
|
||||
entity.craftTime = 0f;
|
||||
|
||||
for(ItemStack item : consumes.items()){
|
||||
entity.items.remove(item.item, item.amount);
|
||||
}
|
||||
|
||||
offloadNear(tile, output);
|
||||
Effects.effect(craftEffect, flameColor, tile.drawx(), tile.drawy());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
|
||||
for(ItemStack stack : consumes.items()){
|
||||
if(stack.item == item){
|
||||
return tile.entity.items.get(item) < itemCapacity;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaximumAccepted(Tile tile, Item item){
|
||||
return itemCapacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Tile tile){
|
||||
super.draw(tile);
|
||||
|
||||
PowerSmelterEntity entity = tile.entity();
|
||||
|
||||
//draw glowing center
|
||||
if(entity.heat > 0f && flameColor.a > 0.001f){
|
||||
float g = 0.3f;
|
||||
float r = 0.06f;
|
||||
float cr = Mathf.random(0.1f);
|
||||
|
||||
Draw.alpha(((1f - g) + Mathf.absin(Time.time(), 8f, g) + Mathf.random(r) - r) * entity.heat);
|
||||
|
||||
Draw.tint(flameColor);
|
||||
Fill.circle(tile.drawx(), tile.drawy(), 3f + Mathf.absin(Time.time(), 5f, 2f) + cr);
|
||||
Draw.color(1f, 1f, 1f, entity.heat);
|
||||
Draw.rect(topRegion, tile.drawx(), tile.drawy());
|
||||
Fill.circle(tile.drawx(), tile.drawy(), 1.9f + Mathf.absin(Time.time(), 5f, 1f) + cr);
|
||||
|
||||
Draw.color();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity newEntity(){
|
||||
return new PowerSmelterEntity();
|
||||
}
|
||||
|
||||
class PowerSmelterEntity extends TileEntity{
|
||||
public float heat;
|
||||
public float time;
|
||||
public float craftTime;
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
stream.writeFloat(heat);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream) throws IOException{
|
||||
heat = stream.readFloat();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package io.anuke.mindustry.world.blocks.production;
|
||||
|
||||
import io.anuke.arc.Core;
|
||||
import io.anuke.arc.graphics.g2d.TextureRegion;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.arc.graphics.g2d.Draw;
|
||||
|
||||
public class Pulverizer extends GenericCrafter{
|
||||
protected TextureRegion rotatorRegion;
|
||||
|
||||
public Pulverizer(String name){
|
||||
super(name);
|
||||
hasItems = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(){
|
||||
super.load();
|
||||
|
||||
rotatorRegion = Core.atlas.find(name + "-rotator");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Tile tile){
|
||||
GenericCrafterEntity entity = tile.entity();
|
||||
|
||||
Draw.rect(region, tile.drawx(), tile.drawy());
|
||||
Draw.rect(rotatorRegion, tile.drawx(), tile.drawy(), entity.totalProgress * 2f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureRegion[] generateIcons(){
|
||||
return new TextureRegion[]{Core.atlas.find(name), Core.atlas.find(name + "-rotator")};
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,16 @@
|
||||
package io.anuke.mindustry.world.blocks.production;
|
||||
|
||||
import io.anuke.arc.Core;
|
||||
import io.anuke.arc.graphics.g2d.TextureRegion;
|
||||
import io.anuke.arc.collection.Array;
|
||||
import io.anuke.arc.graphics.g2d.Draw;
|
||||
import io.anuke.arc.graphics.g2d.TextureRegion;
|
||||
import io.anuke.mindustry.graphics.Layer;
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.LiquidBlock;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeLiquid;
|
||||
import io.anuke.mindustry.world.meta.BlockGroup;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.StatUnit;
|
||||
import io.anuke.arc.graphics.g2d.Draw;
|
||||
|
||||
public class Pump extends LiquidBlock{
|
||||
protected final Array<Tile> drawTiles = new Array<>();
|
||||
@@ -40,7 +39,7 @@ public class Pump extends LiquidBlock{
|
||||
@Override
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
stats.add(BlockStat.liquidOutputSpeed, 60f * pumpAmount, StatUnit.liquidSecond);
|
||||
stats.add(BlockStat.output, 60f * pumpAmount, StatUnit.liquidSecond);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -107,11 +106,6 @@ public class Pump extends LiquidBlock{
|
||||
tryDumpLiquid(tile, tile.entity.liquids.current());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
||||
return consumes.has(ConsumeLiquid.class) && consumes.liquid() == liquid && super.acceptLiquid(tile, source, liquid, amount);
|
||||
}
|
||||
|
||||
protected boolean isValid(Tile tile){
|
||||
return tile != null && tile.floor().liquidDrop != null;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
package io.anuke.mindustry.world.blocks.production;
|
||||
|
||||
import io.anuke.arc.Core;
|
||||
import io.anuke.arc.graphics.Color;
|
||||
import io.anuke.arc.graphics.g2d.Draw;
|
||||
import io.anuke.arc.graphics.g2d.Lines;
|
||||
import io.anuke.arc.graphics.g2d.TextureRegion;
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
@@ -12,8 +10,10 @@ import io.anuke.mindustry.type.ItemStack;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.production.GenericCrafter.GenericCrafterEntity;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeItem;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeLiquidBase;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeType;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.StatUnit;
|
||||
import io.anuke.mindustry.world.meta.values.ItemFilterValue;
|
||||
|
||||
/**
|
||||
@@ -23,14 +23,14 @@ public class Separator extends Block{
|
||||
protected final int timerDump = timers++;
|
||||
|
||||
protected ItemStack[] results;
|
||||
protected float filterTime;
|
||||
protected float craftTime;
|
||||
protected float spinnerRadius = 2.5f;
|
||||
protected float spinnerLength = 1f;
|
||||
protected float spinnerThickness = 1f;
|
||||
protected float spinnerSpeed = 2f;
|
||||
|
||||
protected Color color = Color.valueOf("858585");
|
||||
protected TextureRegion liquidRegion;
|
||||
protected int liquidRegion;
|
||||
|
||||
public Separator(String name){
|
||||
super(name);
|
||||
@@ -38,25 +38,28 @@ public class Separator extends Block{
|
||||
solid = true;
|
||||
hasItems = true;
|
||||
hasLiquids = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(){
|
||||
super.load();
|
||||
|
||||
liquidRegion = Core.atlas.find(name + "-liquid");
|
||||
liquidRegion = reg("liquid");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStats(){
|
||||
if(consumes.has(ConsumeType.liquid)){
|
||||
ConsumeLiquidBase cons = consumes.get(ConsumeType.liquid);
|
||||
cons.timePeriod = craftTime;
|
||||
}
|
||||
|
||||
super.setStats();
|
||||
|
||||
stats.add(BlockStat.outputItem, new ItemFilterValue(item -> {
|
||||
stats.add(BlockStat.output, new ItemFilterValue(item -> {
|
||||
for(ItemStack i : results){
|
||||
if(item == i.item) return true;
|
||||
}
|
||||
return false;
|
||||
}));
|
||||
|
||||
stats.add(BlockStat.productionTime, craftTime / 60f, StatUnit.seconds);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -67,7 +70,7 @@ public class Separator extends Block{
|
||||
|
||||
Draw.color(tile.entity.liquids.current().color);
|
||||
Draw.alpha(tile.entity.liquids.total() / liquidCapacity);
|
||||
Draw.rect(liquidRegion, tile.drawx(), tile.drawy());
|
||||
Draw.rect(reg(liquidRegion), tile.drawx(), tile.drawy());
|
||||
|
||||
Draw.color(color);
|
||||
Lines.stroke(spinnerThickness);
|
||||
@@ -82,7 +85,7 @@ public class Separator extends Block{
|
||||
entity.totalProgress += entity.warmup * entity.delta();
|
||||
|
||||
if(entity.cons.valid()){
|
||||
entity.progress += getProgressIncrease(entity, filterTime);
|
||||
entity.progress += getProgressIncrease(entity, craftTime);
|
||||
entity.warmup = Mathf.lerpDelta(entity.warmup, 1f, 0.02f);
|
||||
}else{
|
||||
entity.warmup = Mathf.lerpDelta(entity.warmup, 0f, 0.02f);
|
||||
@@ -106,9 +109,7 @@ public class Separator extends Block{
|
||||
count += stack.amount;
|
||||
}
|
||||
|
||||
if(consumes.has(ConsumeItem.class)){
|
||||
entity.items.remove(consumes.item(), consumes.itemAmount());
|
||||
}
|
||||
entity.cons.trigger();
|
||||
|
||||
if(item != null && entity.items.get(item) < itemCapacity){
|
||||
offloadNear(tile, item);
|
||||
|
||||
@@ -1,148 +0,0 @@
|
||||
package io.anuke.mindustry.world.blocks.production;
|
||||
|
||||
import io.anuke.mindustry.entities.Effects;
|
||||
import io.anuke.mindustry.entities.Effects.Effect;
|
||||
import io.anuke.arc.graphics.Color;
|
||||
import io.anuke.arc.graphics.g2d.Draw;
|
||||
import io.anuke.arc.graphics.g2d.Fill;
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.arc.util.Time;
|
||||
import io.anuke.mindustry.content.Fx;
|
||||
import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.type.ItemStack;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeItem;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeItems;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.StatUnit;
|
||||
|
||||
public class Smelter extends Block{
|
||||
protected final int timerDump = timers++;
|
||||
|
||||
protected Item result;
|
||||
|
||||
protected float craftTime = 20f;
|
||||
protected float burnDuration = 50f;
|
||||
protected Effect craftEffect = Fx.smelt, burnEffect = Fx.fuelburn;
|
||||
protected Color flameColor = Color.valueOf("ffb879");
|
||||
|
||||
public Smelter(String name){
|
||||
super(name);
|
||||
update = true;
|
||||
hasItems = true;
|
||||
solid = true;
|
||||
|
||||
consumes.require(ConsumeItems.class);
|
||||
consumes.require(ConsumeItem.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
|
||||
stats.add(BlockStat.fuelBurnTime, burnDuration / 60f, StatUnit.seconds);
|
||||
stats.add(BlockStat.outputItem, result);
|
||||
stats.add(BlockStat.craftSpeed, 60f / craftTime, StatUnit.itemsSecond);
|
||||
stats.add(BlockStat.inputItemCapacity, itemCapacity, StatUnit.items);
|
||||
stats.add(BlockStat.outputItemCapacity, itemCapacity, StatUnit.items);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(){
|
||||
super.init();
|
||||
produces.set(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
SmelterEntity entity = tile.entity();
|
||||
|
||||
if(entity.timer.get(timerDump, 5) && entity.items.has(result)){
|
||||
tryDump(tile, result);
|
||||
}
|
||||
|
||||
//add fuel
|
||||
if(entity.consumed(ConsumeItem.class) && entity.burnTime <= 0f){
|
||||
entity.items.remove(consumes.item(), 1);
|
||||
entity.burnTime += burnDuration;
|
||||
Effects.effect(burnEffect, entity.x + Mathf.range(2f), entity.y + Mathf.range(2f));
|
||||
}
|
||||
|
||||
//decrement burntime
|
||||
if(entity.burnTime > 0){
|
||||
entity.burnTime -= entity.delta();
|
||||
entity.heat = Mathf.lerpDelta(entity.heat, 1f, 0.02f);
|
||||
}else{
|
||||
entity.heat = Mathf.lerpDelta(entity.heat, 0f, 0.02f);
|
||||
}
|
||||
|
||||
//make sure it has all the items
|
||||
if(!entity.cons.valid()){
|
||||
return;
|
||||
}
|
||||
|
||||
entity.craftTime += entity.delta();
|
||||
|
||||
if(entity.items.get(result) >= itemCapacity //output full
|
||||
|| entity.burnTime <= 0 //not burning
|
||||
|| entity.craftTime < craftTime){ //not yet time
|
||||
return;
|
||||
}
|
||||
|
||||
entity.craftTime = 0f;
|
||||
for(ItemStack item : consumes.items()){
|
||||
entity.items.remove(item.item, item.amount);
|
||||
}
|
||||
|
||||
offloadNear(tile, result);
|
||||
Effects.effect(craftEffect, flameColor, tile.drawx(), tile.drawy());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
boolean isInput = false;
|
||||
|
||||
for(ItemStack req : consumes.items()){
|
||||
if(req.item == item){
|
||||
isInput = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return (isInput && tile.entity.items.get(item) < itemCapacity) || (item == consumes.item() && tile.entity.items.get(consumes.item()) < itemCapacity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Tile tile){
|
||||
super.draw(tile);
|
||||
|
||||
SmelterEntity entity = tile.entity();
|
||||
|
||||
//draw glowing center
|
||||
if(entity.heat > 0f){
|
||||
float g = 0.1f;
|
||||
|
||||
Draw.alpha(((1f - g) + Mathf.absin(Time.time(), 8f, g)) * entity.heat);
|
||||
|
||||
Draw.tint(flameColor);
|
||||
Fill.circle(tile.drawx(), tile.drawy(), 2f + Mathf.absin(Time.time(), 5f, 0.8f));
|
||||
Draw.color(1f, 1f, 1f, entity.heat);
|
||||
Fill.circle(tile.drawx(), tile.drawy(), 1f + Mathf.absin(Time.time(), 5f, 0.7f));
|
||||
|
||||
Draw.color();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity newEntity(){
|
||||
return new SmelterEntity();
|
||||
}
|
||||
|
||||
public class SmelterEntity extends TileEntity{
|
||||
public float burnTime;
|
||||
public float heat;
|
||||
public float craftTime;
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,7 @@ public class SolidPump extends Pump{
|
||||
@Override
|
||||
public void drawPlace(int x, int y, int rotation, boolean valid){
|
||||
if(attribute != null){
|
||||
drawPlaceText(Core.bundle.formatDouble("blocks.efficiency", (sumAttribute(attribute, x, y) + 1f)*100, 1), x, y, valid);
|
||||
drawPlaceText(Core.bundle.formatFloat("bar.efficiency", (sumAttribute(attribute, x, y) + 1f)*100, 1), x, y, valid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public class SolidPump extends Pump{
|
||||
public void setBars(){
|
||||
super.setBars();
|
||||
bars.add("efficiency", entity -> new Bar(() ->
|
||||
Core.bundle.formatDouble("blocks.efficiency",
|
||||
Core.bundle.formatFloat("bar.efficiency",
|
||||
((((SolidPumpEntity)entity).boost + 1f) * ((SolidPumpEntity)entity).warmup) * 100, 1),
|
||||
() -> Pal.ammo,
|
||||
() -> ((SolidPumpEntity)entity).warmup));
|
||||
@@ -60,7 +60,8 @@ public class SolidPump extends Pump{
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
|
||||
stats.add(BlockStat.liquidOutput, result);
|
||||
stats.remove(BlockStat.output);
|
||||
stats.add(BlockStat.output, result, 60f * pumpAmount, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,6 +23,8 @@ import io.anuke.mindustry.graphics.Shaders;
|
||||
import io.anuke.mindustry.type.Mech;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.StatUnit;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
@@ -45,6 +47,13 @@ public class MechPad extends Block{
|
||||
hasPower = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
|
||||
stats.add(BlockStat.productionTime, buildTime/60f, StatUnit.seconds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(){
|
||||
super.init();
|
||||
|
||||
@@ -25,10 +25,10 @@ import io.anuke.mindustry.ui.Bar;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeItems;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeType;
|
||||
import io.anuke.mindustry.world.meta.BlockFlag;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.StatUnit;
|
||||
import io.anuke.mindustry.world.modules.ItemModule;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
@@ -45,6 +45,7 @@ public class UnitFactory extends Block{
|
||||
protected float launchVelocity = 0f;
|
||||
protected TextureRegion topRegion;
|
||||
protected int maxSpawn = 2;
|
||||
protected int[] capacities;
|
||||
|
||||
public UnitFactory(String name){
|
||||
super(name);
|
||||
@@ -53,8 +54,6 @@ public class UnitFactory extends Block{
|
||||
hasItems = true;
|
||||
solid = false;
|
||||
flags = EnumSet.of(BlockFlag.producer);
|
||||
|
||||
consumes.require(ConsumeItems.class);
|
||||
}
|
||||
|
||||
@Remote(called = Loc.server)
|
||||
@@ -79,6 +78,19 @@ public class UnitFactory extends Block{
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(){
|
||||
super.init();
|
||||
|
||||
capacities = new int[Vars.content.items().size];
|
||||
if(consumes.has(ConsumeType.item)){
|
||||
ConsumeItems cons = consumes.get(ConsumeType.item);
|
||||
for(ItemStack stack : cons.items){
|
||||
capacities[stack.item.id] = stack.amount*2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(){
|
||||
super.load();
|
||||
@@ -89,8 +101,8 @@ public class UnitFactory extends Block{
|
||||
@Override
|
||||
public void setBars(){
|
||||
super.setBars();
|
||||
bars.add("progress", entity -> new Bar("blocks.progress", Pal.ammo, () -> ((UnitFactoryEntity)entity).buildTime / produceTime));
|
||||
bars.add("spawned", entity -> new Bar(() -> Core.bundle.format("blocks.spawned", ((UnitFactoryEntity)entity).spawned, maxSpawn), () -> Pal.command, () -> (float)((UnitFactoryEntity)entity).spawned / maxSpawn));
|
||||
bars.add("progress", entity -> new Bar("bar.progress", Pal.ammo, () -> ((UnitFactoryEntity)entity).buildTime / produceTime));
|
||||
bars.add("spawned", entity -> new Bar(() -> Core.bundle.format("bar.spawned", ((UnitFactoryEntity)entity).spawned, maxSpawn), () -> Pal.command, () -> (float)((UnitFactoryEntity)entity).spawned / maxSpawn));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -102,7 +114,8 @@ public class UnitFactory extends Block{
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
|
||||
stats.add(BlockStat.craftSpeed, produceTime / 60f, StatUnit.seconds);
|
||||
stats.remove(BlockStat.itemCapacity);
|
||||
stats.add(BlockStat.productionTime, produceTime / 60f, StatUnit.seconds);
|
||||
stats.add(BlockStat.maxUnits, maxSpawn, StatUnit.none);
|
||||
}
|
||||
|
||||
@@ -162,7 +175,7 @@ public class UnitFactory extends Block{
|
||||
|
||||
if(!tile.isEnemyCheat()){
|
||||
//player-made spawners have default behavior
|
||||
if(hasRequirements(entity.items, entity.buildTime / produceTime) && entity.cons.valid()){
|
||||
if(entity.cons.valid()){
|
||||
entity.time += entity.delta() * entity.speedScl;
|
||||
entity.buildTime += entity.delta() * entity.power.satisfaction;
|
||||
entity.speedScl = Mathf.lerpDelta(entity.speedScl, 1f, 0.05f);
|
||||
@@ -186,30 +199,13 @@ public class UnitFactory extends Block{
|
||||
Call.onUnitFactorySpawn(tile, entity.spawned + 1);
|
||||
useContent(tile, type);
|
||||
|
||||
for(ItemStack stack : consumes.items()){
|
||||
entity.items.remove(stack.item, stack.amount);
|
||||
}
|
||||
entity.cons.trigger();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
for(ItemStack stack : consumes.items()){
|
||||
if(item == stack.item && tile.entity.items.get(item) < stack.amount * 2){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaximumAccepted(Tile tile, Item item){
|
||||
for(ItemStack stack : consumes.items()){
|
||||
if(item == stack.item){
|
||||
return stack.amount * 2;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return capacities[item.id];
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -223,21 +219,12 @@ public class UnitFactory extends Block{
|
||||
return entity.spawned < maxSpawn;
|
||||
}
|
||||
|
||||
protected boolean hasRequirements(ItemModule inv, float fraction){
|
||||
for(ItemStack stack : consumes.items()){
|
||||
if(!inv.has(stack.item, (int) (fraction * stack.amount))){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static class UnitFactoryEntity extends TileEntity{
|
||||
public float buildTime;
|
||||
public float time;
|
||||
public float speedScl;
|
||||
public float warmup; //only for enemy spawners
|
||||
public int spawned;
|
||||
float buildTime;
|
||||
float time;
|
||||
float speedScl;
|
||||
float warmup; //only for enemy spawners
|
||||
int spawned;
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
|
||||
@@ -2,14 +2,25 @@ package io.anuke.mindustry.world.consumers;
|
||||
|
||||
import io.anuke.arc.scene.ui.layout.Table;
|
||||
import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.meta.BlockStats;
|
||||
|
||||
/**An abstract class that defines a type of resource that a block can consume.*/
|
||||
public abstract class Consume{
|
||||
protected boolean optional;
|
||||
protected boolean update = true, boost = false;
|
||||
protected boolean update = true;
|
||||
|
||||
/**Apply a filter to items accepted.
|
||||
* This should set all item IDs that are present in the filter to true.*/
|
||||
public void applyItemFilter(boolean[] filter){
|
||||
|
||||
}
|
||||
|
||||
/**Apply a filter to liquids accepted.
|
||||
* This should set all liquid IDs that are present in the filter to true.*/
|
||||
public void applyLiquidFilter(boolean[] filter){
|
||||
|
||||
}
|
||||
|
||||
public Consume optional(boolean optional){
|
||||
this.optional = optional;
|
||||
@@ -21,11 +32,6 @@ public abstract class Consume{
|
||||
return this;
|
||||
}
|
||||
|
||||
public Consume boost(boolean boost){
|
||||
this.boost = boost;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isOptional(){
|
||||
return optional;
|
||||
}
|
||||
@@ -34,18 +40,20 @@ public abstract class Consume{
|
||||
return update;
|
||||
}
|
||||
|
||||
public abstract ConsumeType type();
|
||||
|
||||
public abstract void build(Tile tile, Table table);
|
||||
|
||||
/**Called when a consumption is triggered manually.*/
|
||||
public void trigger(Block block, TileEntity entity){
|
||||
public void trigger(TileEntity entity){
|
||||
|
||||
}
|
||||
|
||||
public abstract String getIcon();
|
||||
|
||||
public abstract void update(Block block, TileEntity entity);
|
||||
public abstract void update(TileEntity entity);
|
||||
|
||||
public abstract boolean valid(Block block, TileEntity entity);
|
||||
public abstract boolean valid(TileEntity entity);
|
||||
|
||||
public abstract void display(BlockStats stats);
|
||||
}
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
package io.anuke.mindustry.world.consumers;
|
||||
|
||||
import io.anuke.arc.scene.ui.layout.Table;
|
||||
import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.type.Item.Icon;
|
||||
import io.anuke.mindustry.type.ItemStack;
|
||||
import io.anuke.mindustry.ui.ItemImage;
|
||||
import io.anuke.mindustry.ui.ReqImage;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.BlockStats;
|
||||
|
||||
public class ConsumeItem extends Consume{
|
||||
private final Item item;
|
||||
private final int amount;
|
||||
|
||||
public ConsumeItem(Item item){
|
||||
this.item = item;
|
||||
this.amount = 1;
|
||||
}
|
||||
|
||||
public ConsumeItem(Item item, int amount){
|
||||
this.item = item;
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public int getAmount(){
|
||||
return amount;
|
||||
}
|
||||
|
||||
public Item get(){
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void trigger(Block block, TileEntity entity){
|
||||
entity.items.remove(item, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(Tile tile, Table table){
|
||||
table.add(new ReqImage(new ItemImage(item.icon(Icon.large), amount), () -> valid(tile.block(), tile.entity))).size(8*4);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIcon(){
|
||||
return "icon-item";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Block block, TileEntity entity){
|
||||
//doesn't update because consuming items is very specific
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valid(Block block, TileEntity entity){
|
||||
return entity != null && entity.items != null && entity.items.has(item, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void display(BlockStats stats){
|
||||
stats.add(boost ? BlockStat.boostItem : BlockStat.inputItem, new ItemStack(item, amount));
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import io.anuke.mindustry.type.Item.Icon;
|
||||
import io.anuke.mindustry.ui.ItemImage;
|
||||
import io.anuke.mindustry.ui.MultiReqImage;
|
||||
import io.anuke.mindustry.ui.ReqImage;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.BlockStats;
|
||||
@@ -18,12 +17,22 @@ import io.anuke.mindustry.world.meta.values.ItemFilterValue;
|
||||
import static io.anuke.mindustry.Vars.content;
|
||||
|
||||
public class ConsumeItemFilter extends Consume{
|
||||
private final Predicate<Item> filter;
|
||||
public final Predicate<Item> filter;
|
||||
|
||||
public ConsumeItemFilter(Predicate<Item> item){
|
||||
this.filter = item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyItemFilter(boolean[] arr){
|
||||
content.items().each(filter, item -> arr[item.id] = true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConsumeType type(){
|
||||
return ConsumeType.item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(Tile tile, Table table){
|
||||
Array<Item> list = content.items().select(filter);
|
||||
@@ -39,12 +48,12 @@ public class ConsumeItemFilter extends Consume{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Block block, TileEntity entity){
|
||||
public void update(TileEntity entity){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void trigger(Block block, TileEntity entity){
|
||||
public void trigger(TileEntity entity){
|
||||
for(int i = 0; i < content.items().size; i++){
|
||||
Item item = content.item(i);
|
||||
if(entity.items != null && entity.items.has(item) && this.filter.test(item)){
|
||||
@@ -55,7 +64,7 @@ public class ConsumeItemFilter extends Consume{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valid(Block block, TileEntity entity){
|
||||
public boolean valid(TileEntity entity){
|
||||
for(int i = 0; i < content.items().size; i++){
|
||||
Item item = content.item(i);
|
||||
if(entity.items != null && entity.items.has(item) && this.filter.test(item)){
|
||||
@@ -67,6 +76,6 @@ public class ConsumeItemFilter extends Consume{
|
||||
|
||||
@Override
|
||||
public void display(BlockStats stats){
|
||||
stats.add(boost ? BlockStat.boostItem : BlockStat.inputItem, new ItemFilterValue(filter));
|
||||
stats.add(optional ? BlockStat.booster : BlockStat.input, new ItemFilterValue(filter));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,21 +6,28 @@ import io.anuke.mindustry.type.Item.Icon;
|
||||
import io.anuke.mindustry.type.ItemStack;
|
||||
import io.anuke.mindustry.ui.ItemImage;
|
||||
import io.anuke.mindustry.ui.ReqImage;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.BlockStats;
|
||||
import io.anuke.mindustry.world.meta.values.ItemListValue;
|
||||
|
||||
public class ConsumeItems extends Consume{
|
||||
private ItemStack[] items;
|
||||
public final ItemStack[] items;
|
||||
|
||||
public ConsumeItems(ItemStack[] items){
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
public ItemStack[] getItems(){
|
||||
return items;
|
||||
@Override
|
||||
public void applyItemFilter(boolean[] filter){
|
||||
for(ItemStack stack : items){
|
||||
filter[stack.item.id] = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConsumeType type(){
|
||||
return ConsumeType.item;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -36,24 +43,24 @@ public class ConsumeItems extends Consume{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Block block, TileEntity entity){
|
||||
public void update(TileEntity entity){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void trigger(Block block, TileEntity entity){
|
||||
public void trigger(TileEntity entity){
|
||||
for(ItemStack stack : items){
|
||||
entity.items.remove(stack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valid(Block block, TileEntity entity){
|
||||
public boolean valid(TileEntity entity){
|
||||
return entity.items != null && entity.items.has(items);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void display(BlockStats stats){
|
||||
stats.add(boost ? BlockStat.boostItem : BlockStat.inputItems, new ItemListValue(items));
|
||||
stats.add(optional ? BlockStat.booster : BlockStat.input, new ItemListValue(items));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,32 +4,26 @@ import io.anuke.arc.scene.ui.layout.Table;
|
||||
import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.mindustry.ui.ReqImage;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.BlockStats;
|
||||
import io.anuke.mindustry.world.meta.StatUnit;
|
||||
|
||||
public class ConsumeLiquid extends Consume{
|
||||
protected final float use;
|
||||
protected final Liquid liquid;
|
||||
public class ConsumeLiquid extends ConsumeLiquidBase{
|
||||
public final Liquid liquid;
|
||||
|
||||
public ConsumeLiquid(Liquid liquid, float use){
|
||||
public ConsumeLiquid(Liquid liquid, float amount){
|
||||
super(amount);
|
||||
this.liquid = liquid;
|
||||
this.use = use;
|
||||
}
|
||||
|
||||
public float used(){
|
||||
return use;
|
||||
}
|
||||
|
||||
public Liquid get(){
|
||||
return liquid;
|
||||
@Override
|
||||
public void applyLiquidFilter(boolean[] filter){
|
||||
filter[liquid.id] = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(Tile tile, Table table){
|
||||
table.add(new ReqImage(liquid.getContentIcon(), () -> valid(tile.block(), tile.entity))).size(8*4);
|
||||
table.add(new ReqImage(liquid.getContentIcon(), () -> valid(tile.entity))).size(8*4);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -38,26 +32,17 @@ public class ConsumeLiquid extends Consume{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Block block, TileEntity entity){
|
||||
entity.liquids.remove(liquid, Math.min(use(block, entity), entity.liquids.get(liquid)));
|
||||
public void update(TileEntity entity){
|
||||
entity.liquids.remove(liquid, Math.min(use(entity), entity.liquids.get(liquid)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valid(Block block, TileEntity entity){
|
||||
return entity != null && entity.liquids != null && entity.liquids.get(liquid) >= use(block, entity);
|
||||
public boolean valid(TileEntity entity){
|
||||
return entity != null && entity.liquids != null && entity.liquids.get(liquid) >= use(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void display(BlockStats stats){
|
||||
if(!boost){
|
||||
stats.add(BlockStat.liquidUse, use * 60f, StatUnit.liquidSecond);
|
||||
stats.add(BlockStat.inputLiquid, liquid);
|
||||
}else{
|
||||
stats.add(BlockStat.boostLiquid, liquid);
|
||||
}
|
||||
}
|
||||
|
||||
float use(Block block, TileEntity entity){
|
||||
return Math.min(use * entity.delta(), block.liquidCapacity);
|
||||
stats.add(optional ? BlockStat.booster : BlockStat.input, liquid, amount * timePeriod, timePeriod == 60);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package io.anuke.mindustry.world.consumers;
|
||||
|
||||
import io.anuke.mindustry.entities.type.TileEntity;
|
||||
|
||||
public abstract class ConsumeLiquidBase extends Consume{
|
||||
/**amount used per frame*/
|
||||
public final float amount;
|
||||
/**How much time is taken to use this liquid, in ticks. Used only for visual purposes.
|
||||
* Example: a normal ConsumeLiquid with 10/s and a 10 second timePeriod would display as "100 seconds".
|
||||
* Without a time override, it would display as "10 liquid/second".
|
||||
* This is used for generic crafters.*/
|
||||
public float timePeriod = 60;
|
||||
|
||||
public ConsumeLiquidBase(float amount){
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConsumeType type(){
|
||||
return ConsumeType.liquid;
|
||||
}
|
||||
|
||||
protected float use(TileEntity entity){
|
||||
return Math.min(amount * entity.delta(), entity.block.liquidCapacity);
|
||||
}
|
||||
}
|
||||
@@ -7,35 +7,31 @@ import io.anuke.mindustry.entities.type.TileEntity;
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.mindustry.ui.MultiReqImage;
|
||||
import io.anuke.mindustry.ui.ReqImage;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.BlockStats;
|
||||
import io.anuke.mindustry.world.meta.StatUnit;
|
||||
import io.anuke.mindustry.world.meta.values.LiquidFilterValue;
|
||||
|
||||
import static io.anuke.mindustry.Vars.content;
|
||||
|
||||
public class ConsumeLiquidFilter extends Consume{
|
||||
private final Predicate<Liquid> filter;
|
||||
private final float use;
|
||||
private final boolean isFuel;
|
||||
|
||||
public ConsumeLiquidFilter(Predicate<Liquid> liquid, float amount, boolean isFuel){
|
||||
this.filter = liquid;
|
||||
this.use = amount;
|
||||
this.isFuel = isFuel;
|
||||
}
|
||||
public class ConsumeLiquidFilter extends ConsumeLiquidBase{
|
||||
public final Predicate<Liquid> filter;
|
||||
|
||||
public ConsumeLiquidFilter(Predicate<Liquid> liquid, float amount){
|
||||
this(liquid, amount, false);
|
||||
super(amount);
|
||||
this.filter = liquid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyLiquidFilter(boolean[] arr){
|
||||
content.liquids().each(filter, item -> arr[item.id] = true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(Tile tile, Table table){
|
||||
Array<Liquid> list = content.liquids().select(l -> !l.isHidden() && filter.test(l));
|
||||
MultiReqImage image = new MultiReqImage();
|
||||
list.each(liquid -> image.add(new ReqImage(liquid.getContentIcon(), () -> tile.entity != null && tile.entity.liquids != null && tile.entity.liquids.get(liquid) >= use(tile.block(), tile.entity))));
|
||||
list.each(liquid -> image.add(new ReqImage(liquid.getContentIcon(), () -> tile.entity != null && tile.entity.liquids != null && tile.entity.liquids.get(liquid) >= use(tile.entity))));
|
||||
|
||||
table.add(image).size(8*4);
|
||||
}
|
||||
@@ -46,29 +42,17 @@ public class ConsumeLiquidFilter extends Consume{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Block block, TileEntity entity){
|
||||
entity.liquids.remove(entity.liquids.current(), use(block, entity));
|
||||
public void update(TileEntity entity){
|
||||
entity.liquids.remove(entity.liquids.current(), use(entity));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valid(Block block, TileEntity entity){
|
||||
return entity != null && entity.liquids != null && filter.test(entity.liquids.current()) && entity.liquids.currentAmount() >= use(block, entity);
|
||||
public boolean valid(TileEntity entity){
|
||||
return entity != null && entity.liquids != null && filter.test(entity.liquids.current()) && entity.liquids.currentAmount() >= use(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void display(BlockStats stats){
|
||||
if(boost){
|
||||
stats.add(BlockStat.boostLiquid, new LiquidFilterValue(filter));
|
||||
}else if(isFuel){
|
||||
stats.add(BlockStat.inputLiquidFuel, new LiquidFilterValue(filter));
|
||||
stats.add(BlockStat.liquidFuelUse, 60f * use, StatUnit.liquidSecond);
|
||||
}else {
|
||||
stats.add(BlockStat.inputLiquid, new LiquidFilterValue(filter));
|
||||
stats.add(BlockStat.liquidUse, 60f * use, StatUnit.liquidSecond);
|
||||
}
|
||||
}
|
||||
|
||||
float use(Block block, TileEntity entity){
|
||||
return Math.min(use * entity.delta(), block.liquidCapacity);
|
||||
stats.add(optional ? BlockStat.booster : BlockStat.input, new LiquidFilterValue(filter, amount * timePeriod, timePeriod == 60f));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,11 @@ public class ConsumePower extends Consume{
|
||||
this.isBuffered = isBuffered;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConsumeType type(){
|
||||
return ConsumeType.power;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(Tile tile, Table table){
|
||||
//No tooltip for power, for now
|
||||
@@ -35,12 +40,12 @@ public class ConsumePower extends Consume{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Block block, TileEntity entity){
|
||||
public void update(TileEntity entity){
|
||||
// Nothing to do since PowerGraph directly updates entity.power.satisfaction
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valid(Block block, TileEntity entity){
|
||||
public boolean valid(TileEntity entity){
|
||||
if(isBuffered){
|
||||
return true;
|
||||
}else{
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package io.anuke.mindustry.world.consumers;
|
||||
|
||||
public enum ConsumeType{
|
||||
item,
|
||||
power,
|
||||
liquid
|
||||
}
|
||||
@@ -1,39 +1,39 @@
|
||||
package io.anuke.mindustry.world.consumers;
|
||||
|
||||
import io.anuke.arc.collection.Array;
|
||||
import io.anuke.arc.collection.ObjectMap;
|
||||
import io.anuke.arc.collection.ObjectSet;
|
||||
import io.anuke.arc.function.Consumer;
|
||||
import io.anuke.arc.util.Structs;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.type.ItemStack;
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.meta.BlockStats;
|
||||
|
||||
public class Consumers{
|
||||
private ObjectMap<Class<? extends Consume>, Consume> map = new ObjectMap<>();
|
||||
private ObjectSet<Class<? extends Consume>> required = new ObjectSet<>();
|
||||
private Array<Consume> results = new Array<>();
|
||||
private Consume[] map = new Consume[ConsumeType.values().length];
|
||||
private Consume[] results, optionalResults;
|
||||
|
||||
public void require(Class<? extends Consume> type){
|
||||
required.add(type);
|
||||
public final boolean[] itemFilters = new boolean[Vars.content.items().size];
|
||||
public final boolean[] liquidfilters = new boolean[Vars.content.liquids().size];
|
||||
|
||||
public void init(){
|
||||
results = Structs.filter(Consume.class, map, m -> m != null);
|
||||
optionalResults = Structs.filter(Consume.class, map, m -> m != null && m.isOptional());
|
||||
|
||||
for(Consume cons : results){
|
||||
cons.applyItemFilter(itemFilters);
|
||||
cons.applyLiquidFilter(liquidfilters);
|
||||
}
|
||||
}
|
||||
|
||||
public void checkRequired(Block block){
|
||||
for(Class<? extends Consume> c : required){
|
||||
if(!map.containsKey(c)){
|
||||
throw new RuntimeException("Missing required consumer of type \"" + c + "\" in block \"" + block.name + "\"!");
|
||||
}
|
||||
}
|
||||
public ConsumePower getPower(){
|
||||
return get(ConsumeType.power);
|
||||
}
|
||||
|
||||
for(Consume cons : map.values()){
|
||||
results.add(cons);
|
||||
}
|
||||
public boolean hasPower(){
|
||||
return has(ConsumeType.power);
|
||||
}
|
||||
|
||||
public ConsumeLiquid liquid(Liquid liquid, float amount){
|
||||
ConsumeLiquid c = new ConsumeLiquid(liquid, amount);
|
||||
add(c);
|
||||
return c;
|
||||
return add(new ConsumeLiquid(liquid, amount));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -42,9 +42,7 @@ public class Consumers{
|
||||
* @return the created consumer object.
|
||||
*/
|
||||
public ConsumePower power(float powerPerTick){
|
||||
ConsumePower c = new ConsumePower(powerPerTick, 0.0f, false);
|
||||
add(c);
|
||||
return c;
|
||||
return add(new ConsumePower(powerPerTick, 0.0f, false));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,83 +60,55 @@ public class Consumers{
|
||||
* @param ticksToFill The number of ticks it shall take to fill the buffer.
|
||||
*/
|
||||
public ConsumePower powerBuffered(float powerCapacity, float ticksToFill){
|
||||
ConsumePower c = new ConsumePower(powerCapacity / ticksToFill, powerCapacity, true);
|
||||
add(c);
|
||||
return c;
|
||||
return add(new ConsumePower(powerCapacity / ticksToFill, powerCapacity, true));
|
||||
}
|
||||
|
||||
public ConsumeItem item(Item item){
|
||||
public ConsumeItems item(Item item){
|
||||
return item(item, 1);
|
||||
}
|
||||
|
||||
public ConsumeItem item(Item item, int amount){
|
||||
ConsumeItem i = new ConsumeItem(item, amount);
|
||||
add(i);
|
||||
return i;
|
||||
public ConsumeItems item(Item item, int amount){
|
||||
return add(new ConsumeItems(new ItemStack[]{new ItemStack(item, amount)}));
|
||||
}
|
||||
|
||||
public ConsumeItems items(ItemStack... items){
|
||||
ConsumeItems i = new ConsumeItems(items);
|
||||
add(i);
|
||||
return i;
|
||||
return add(new ConsumeItems(items));
|
||||
}
|
||||
|
||||
public Item item(){
|
||||
return get(ConsumeItem.class).get();
|
||||
}
|
||||
|
||||
public ItemStack[] items(){
|
||||
return get(ConsumeItems.class).getItems();
|
||||
}
|
||||
|
||||
public int itemAmount(){
|
||||
return get(ConsumeItem.class).getAmount();
|
||||
}
|
||||
|
||||
public Liquid liquid(){
|
||||
return get(ConsumeLiquid.class).get();
|
||||
}
|
||||
|
||||
public float liquidAmount(){
|
||||
return get(ConsumeLiquid.class).use;
|
||||
}
|
||||
|
||||
public Consume add(Consume consume){
|
||||
map.put((consume instanceof ConsumePower ? ConsumePower.class : consume.getClass()), consume);
|
||||
public <T extends Consume> T add(T consume){
|
||||
map[consume.type().ordinal()] = consume;
|
||||
return consume;
|
||||
}
|
||||
|
||||
public void remove(Class<? extends Consume> type){
|
||||
map.remove(type);
|
||||
public void remove(ConsumeType type){
|
||||
map[type.ordinal()] = null;
|
||||
}
|
||||
|
||||
public boolean has(Class<? extends Consume> type){
|
||||
return map.containsKey(type);
|
||||
public boolean has(ConsumeType type){
|
||||
return map[type.ordinal()] != null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends Consume> T get(Class<T> type){
|
||||
if(!map.containsKey(type)){
|
||||
public <T extends Consume> T get(ConsumeType type){
|
||||
if(map[type.ordinal()] == null){
|
||||
throw new IllegalArgumentException("Block does not contain consumer of type '" + type + "'!");
|
||||
}
|
||||
return (T) map.get(type);
|
||||
return (T) map[type.ordinal()];
|
||||
}
|
||||
|
||||
public Iterable<Consume> all(){
|
||||
return map.values();
|
||||
}
|
||||
|
||||
public Array<Consume> array(){
|
||||
public Consume[] all(){
|
||||
return results;
|
||||
}
|
||||
|
||||
public boolean hasAny(){
|
||||
return map.size > 0;
|
||||
public Consume[] optionals(){
|
||||
return optionalResults;
|
||||
}
|
||||
|
||||
public void forEach(Consumer<Consume> cons){
|
||||
for(Consume c : all()){
|
||||
cons.accept(c);
|
||||
public void display(BlockStats stats){
|
||||
for(Consume c : map){
|
||||
if(c != null){
|
||||
c.display(stats);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,38 +10,25 @@ public enum BlockStat{
|
||||
size(StatCategory.general),
|
||||
|
||||
itemCapacity(StatCategory.items),
|
||||
inputItemCapacity(StatCategory.items),
|
||||
outputItemCapacity(StatCategory.items),
|
||||
itemsMoved(StatCategory.items),
|
||||
launchTime(StatCategory.items),
|
||||
|
||||
liquidCapacity(StatCategory.liquids),
|
||||
liquidOutput(StatCategory.liquids),
|
||||
liquidOutputSpeed(StatCategory.liquids),
|
||||
coolant(StatCategory.liquids),
|
||||
coolantUse(StatCategory.liquids),
|
||||
|
||||
powerCapacity(StatCategory.power),
|
||||
powerUse(StatCategory.power),
|
||||
powerDamage(StatCategory.power),
|
||||
powerRange(StatCategory.power),
|
||||
powerTransferSpeed(StatCategory.power),
|
||||
basePowerGeneration(StatCategory.power),
|
||||
inputLiquidFuel(StatCategory.power),
|
||||
liquidFuelUse(StatCategory.power),
|
||||
|
||||
inputLiquid(StatCategory.crafting),
|
||||
liquidUse(StatCategory.crafting),
|
||||
inputItem(StatCategory.crafting),
|
||||
inputItems(StatCategory.crafting),
|
||||
inputFuel(StatCategory.crafting),
|
||||
fuelBurnTime(StatCategory.crafting),
|
||||
craftSpeed(StatCategory.crafting),
|
||||
outputItem(StatCategory.crafting),
|
||||
input(StatCategory.crafting),
|
||||
output(StatCategory.crafting),
|
||||
productionTime(StatCategory.crafting),
|
||||
drillTier(StatCategory.crafting),
|
||||
drillSpeed(StatCategory.crafting),
|
||||
maxUnits(StatCategory.crafting),
|
||||
|
||||
speedIncrease(StatCategory.shooting),
|
||||
repairTime(StatCategory.shooting),
|
||||
range(StatCategory.shooting),
|
||||
shootRange(StatCategory.shooting),
|
||||
@@ -53,9 +40,8 @@ public enum BlockStat{
|
||||
targetsGround(StatCategory.shooting),
|
||||
ammo(StatCategory.shooting),
|
||||
|
||||
boostItem(StatCategory.optional),
|
||||
boostLiquid(StatCategory.optional),
|
||||
|
||||
booster(StatCategory.optional),
|
||||
boostEffect(StatCategory.optional)
|
||||
;
|
||||
|
||||
public final StatCategory category;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.anuke.mindustry.world.meta;
|
||||
|
||||
import io.anuke.arc.collection.Array;
|
||||
import io.anuke.arc.collection.ObjectMap.Entry;
|
||||
import io.anuke.arc.collection.OrderedMap;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
@@ -9,7 +10,7 @@ import io.anuke.mindustry.world.meta.values.*;
|
||||
|
||||
/**Hold and organizes a list of block stats.*/
|
||||
public class BlockStats{
|
||||
private final OrderedMap<StatCategory, OrderedMap<BlockStat, StatValue>> map = new OrderedMap<>();
|
||||
private final OrderedMap<StatCategory, OrderedMap<BlockStat, Array<StatValue>>> map = new OrderedMap<>();
|
||||
private boolean dirty;
|
||||
|
||||
/**Adds a single float value with this stat, formatted to 2 decimal places.*/
|
||||
@@ -24,17 +25,17 @@ public class BlockStats{
|
||||
|
||||
/**Adds an item value.*/
|
||||
public void add(BlockStat stat, Item item){
|
||||
add(stat, new ItemValue(new ItemStack(item, 1)));
|
||||
}
|
||||
|
||||
/**Adds a liquid value.*/
|
||||
public void add(BlockStat stat, Liquid liquid){
|
||||
add(stat, new LiquidValue(liquid));
|
||||
add(stat, new ItemListValue(new ItemStack(item, 1)));
|
||||
}
|
||||
|
||||
/**Adds an item value.*/
|
||||
public void add(BlockStat stat, ItemStack item){
|
||||
add(stat, new ItemValue(item));
|
||||
add(stat, new ItemListValue(item));
|
||||
}
|
||||
|
||||
/**Adds an item value.*/
|
||||
public void add(BlockStat stat, Liquid liquid, float amount, boolean perSecond){
|
||||
add(stat, new LiquidValue(liquid, amount, perSecond));
|
||||
}
|
||||
|
||||
/**Adds a single string value with this stat.*/
|
||||
@@ -44,15 +45,11 @@ public class BlockStats{
|
||||
|
||||
/**Adds a stat value.*/
|
||||
public void add(BlockStat stat, StatValue value){
|
||||
if(map.containsKey(stat.category) && map.get(stat.category).containsKey(stat)){
|
||||
throw new RuntimeException("Duplicate stat entry: \"" + stat + "\" in block.");
|
||||
}
|
||||
|
||||
if(!map.containsKey(stat.category)){
|
||||
map.put(stat.category, new OrderedMap<>());
|
||||
}
|
||||
|
||||
map.get(stat.category).put(stat, value);
|
||||
map.get(stat.category).getOr(stat, Array::new).add(value);
|
||||
|
||||
dirty = true;
|
||||
}
|
||||
@@ -68,11 +65,11 @@ public class BlockStats{
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
public OrderedMap<StatCategory, OrderedMap<BlockStat, StatValue>> toMap(){
|
||||
public OrderedMap<StatCategory, OrderedMap<BlockStat, Array<StatValue>>> toMap(){
|
||||
//sort stats by index if they've been modified
|
||||
if(dirty){
|
||||
map.orderedKeys().sort();
|
||||
for(Entry<StatCategory, OrderedMap<BlockStat, StatValue>> entry : map.entries()){
|
||||
for(Entry<StatCategory, OrderedMap<BlockStat, Array<StatValue>>> entry : map.entries()){
|
||||
entry.value.orderedKeys().sort();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
package io.anuke.mindustry.world.meta;
|
||||
|
||||
import io.anuke.mindustry.game.UnlockableContent;
|
||||
|
||||
public interface ContentStatValue extends StatValue{
|
||||
UnlockableContent[] getValueContent();
|
||||
}
|
||||
@@ -16,9 +16,22 @@ public enum StatUnit{
|
||||
powerUnits,
|
||||
degrees,
|
||||
seconds,
|
||||
perSecond,
|
||||
timesSpeed(false),
|
||||
percent(false),
|
||||
none,
|
||||
items;
|
||||
|
||||
public final boolean space;
|
||||
|
||||
StatUnit(boolean space){
|
||||
this.space = space;
|
||||
}
|
||||
|
||||
StatUnit(){
|
||||
this(true);
|
||||
}
|
||||
|
||||
public String localized(){
|
||||
if(this == none) return "";
|
||||
return Core.bundle.get("unit." + name().toLowerCase(Locale.ROOT));
|
||||
|
||||
@@ -38,14 +38,14 @@ public class AmmoListValue<T extends UnlockableContent> implements StatValue{
|
||||
}
|
||||
|
||||
if(type.splashDamage > 0){
|
||||
sep(bt, Core.bundle.format("bullet.splashdamage", (int)type.splashDamage, Strings.toFixed(type.splashDamageRadius / tilesize, 1)));
|
||||
sep(bt, Core.bundle.format("bullet.splashdamage", (int)type.splashDamage, Strings.fixed(type.splashDamageRadius / tilesize, 1)));
|
||||
}
|
||||
|
||||
if(!Mathf.isEqual(type.ammoMultiplier, 1f)) sep(bt, Core.bundle.format("bullet.multiplier", (int)type.ammoMultiplier));
|
||||
if(!Mathf.isEqual(type.reloadMultiplier, 1f)) sep(bt, Core.bundle.format("bullet.reload", Strings.toFixed(type.reloadMultiplier, 1)));
|
||||
if(!Mathf.isEqual(type.reloadMultiplier, 1f)) sep(bt, Core.bundle.format("bullet.reload", Strings.fixed(type.reloadMultiplier, 1)));
|
||||
|
||||
if(type.knockback > 0){
|
||||
sep(bt, Core.bundle.format("bullet.knockback", Strings.toFixed(type.knockback, 1)));
|
||||
sep(bt, Core.bundle.format("bullet.knockback", Strings.fixed(type.knockback, 1)));
|
||||
}
|
||||
|
||||
if((type.status == StatusEffects.burning || type.status == StatusEffects.melting) || type.incendAmount > 0){
|
||||
|
||||
@@ -1,49 +1,21 @@
|
||||
package io.anuke.mindustry.world.meta.values;
|
||||
|
||||
import io.anuke.mindustry.game.UnlockableContent;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.arc.scene.ui.layout.Table;
|
||||
import io.anuke.mindustry.type.ItemStack;
|
||||
import io.anuke.mindustry.ui.ItemDisplay;
|
||||
import io.anuke.mindustry.world.meta.ContentStatValue;
|
||||
import io.anuke.arc.scene.ui.layout.Table;
|
||||
import io.anuke.mindustry.world.meta.StatValue;
|
||||
|
||||
public class ItemListValue implements ContentStatValue{
|
||||
private final Item[] items;
|
||||
public class ItemListValue implements StatValue{
|
||||
private final ItemStack[] stacks;
|
||||
|
||||
public ItemListValue(Item[] items){
|
||||
this.items = items;
|
||||
this.stacks = null;
|
||||
}
|
||||
|
||||
public ItemListValue(ItemStack[] stacks){
|
||||
public ItemListValue(ItemStack... stacks){
|
||||
this.stacks = stacks;
|
||||
this.items = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnlockableContent[] getValueContent(){
|
||||
if(items != null){
|
||||
return items;
|
||||
}else{
|
||||
Item[] res = new Item[stacks.length];
|
||||
for(int i = 0; i < res.length; i++){
|
||||
res[i] = stacks[i].item;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void display(Table table){
|
||||
if(items != null){
|
||||
for(Item item : items){
|
||||
table.add(new ItemDisplay(item)).padRight(5);
|
||||
}
|
||||
}else{
|
||||
for(ItemStack stack : stacks){
|
||||
table.add(new ItemDisplay(stack.item, stack.amount)).padRight(5);
|
||||
}
|
||||
for(ItemStack stack : stacks){
|
||||
table.add(new ItemDisplay(stack.item, stack.amount)).padRight(5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
package io.anuke.mindustry.world.meta.values;
|
||||
|
||||
import io.anuke.mindustry.game.UnlockableContent;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.type.ItemStack;
|
||||
import io.anuke.mindustry.ui.ItemDisplay;
|
||||
import io.anuke.mindustry.world.meta.ContentStatValue;
|
||||
import io.anuke.arc.scene.ui.layout.Table;
|
||||
|
||||
public class ItemValue implements ContentStatValue{
|
||||
private final ItemStack item;
|
||||
|
||||
public ItemValue(ItemStack item){
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnlockableContent[] getValueContent(){
|
||||
return new Item[]{item.item};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void display(Table table){
|
||||
table.add(new ItemDisplay(item.item, item.amount));
|
||||
}
|
||||
}
|
||||
@@ -11,9 +11,13 @@ import static io.anuke.mindustry.Vars.content;
|
||||
|
||||
public class LiquidFilterValue implements StatValue{
|
||||
private final Predicate<Liquid> filter;
|
||||
private final float amount;
|
||||
private final boolean perSecond;
|
||||
|
||||
public LiquidFilterValue(Predicate<Liquid> filter){
|
||||
public LiquidFilterValue(Predicate<Liquid> filter, float amount, boolean perSecond){
|
||||
this.filter = filter;
|
||||
this.amount = amount;
|
||||
this.perSecond = perSecond;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -25,7 +29,7 @@ public class LiquidFilterValue implements StatValue{
|
||||
}
|
||||
|
||||
for(int i = 0; i < list.size; i++){
|
||||
table.add(new LiquidDisplay(list.get(i))).padRight(5);
|
||||
table.add(new LiquidDisplay(list.get(i), amount, perSecond)).padRight(5);
|
||||
|
||||
if(i != list.size - 1){
|
||||
table.add("/");
|
||||
|
||||
@@ -1,25 +1,23 @@
|
||||
package io.anuke.mindustry.world.meta.values;
|
||||
|
||||
import io.anuke.mindustry.game.UnlockableContent;
|
||||
import io.anuke.arc.scene.ui.layout.Table;
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.mindustry.ui.LiquidDisplay;
|
||||
import io.anuke.mindustry.world.meta.ContentStatValue;
|
||||
import io.anuke.arc.scene.ui.layout.Table;
|
||||
import io.anuke.mindustry.world.meta.StatValue;
|
||||
|
||||
public class LiquidValue implements ContentStatValue{
|
||||
public class LiquidValue implements StatValue{
|
||||
private final Liquid liquid;
|
||||
private final float amount;
|
||||
private final boolean perSecond;
|
||||
|
||||
public LiquidValue(Liquid liquid){
|
||||
public LiquidValue(Liquid liquid, float amount, boolean perSecond){
|
||||
this.liquid = liquid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnlockableContent[] getValueContent(){
|
||||
return new UnlockableContent[]{liquid};
|
||||
this.amount = amount;
|
||||
this.perSecond = perSecond;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void display(Table table){
|
||||
table.add(new LiquidDisplay(liquid));
|
||||
table.add(new LiquidDisplay(liquid, amount, perSecond));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,10 +20,9 @@ public class NumberValue implements StatValue{
|
||||
|
||||
@Override
|
||||
public void display(Table table){
|
||||
float diff = Math.abs((int) value - value);
|
||||
int precision = diff <= 0.01f ? 0 : diff <= 0.1f ? 1 : 2;
|
||||
int precision = Math.abs((int) value - value) <= 0.001f ? 0 : Math.abs((int) (value * 10) - value * 10) <= 0.001f ? 1 : 2;
|
||||
|
||||
table.add(Strings.toFixed(value, precision));
|
||||
table.add(" " + unit.localized());
|
||||
table.add(Strings.fixed(value, precision));
|
||||
table.add((unit.space ? " " : "") + unit.localized());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
||||
public class ConsumeModule extends BlockModule{
|
||||
private boolean valid;
|
||||
private boolean valid, optionalValid;
|
||||
private final TileEntity entity;
|
||||
|
||||
public ConsumeModule(TileEntity entity){
|
||||
@@ -18,22 +18,31 @@ public class ConsumeModule extends BlockModule{
|
||||
public void update(){
|
||||
boolean prevValid = valid();
|
||||
valid = true;
|
||||
optionalValid = true;
|
||||
boolean docons = entity.tile.block().shouldConsume(entity.tile);
|
||||
|
||||
for(Consume cons : entity.tile.block().consumes.all()){
|
||||
if(docons && cons.isUpdate() && prevValid && cons.valid(entity.getTile().block(), entity)){
|
||||
cons.update(entity.getTile().block(), entity);
|
||||
if(docons && cons.isUpdate() && prevValid && cons.valid(entity)){
|
||||
cons.update(entity);
|
||||
}
|
||||
|
||||
if(!cons.isOptional()){
|
||||
valid &= cons.valid(entity.getTile().block(), entity);
|
||||
valid &= cons.valid(entity);
|
||||
}
|
||||
}
|
||||
|
||||
for(Consume cons : entity.tile.block().consumes.optionals()){
|
||||
if(docons && cons.isUpdate() && prevValid && cons.valid(entity)){
|
||||
cons.update(entity);
|
||||
}
|
||||
|
||||
optionalValid &= cons.valid(entity);
|
||||
}
|
||||
}
|
||||
|
||||
public void trigger(){
|
||||
for(Consume cons : entity.tile.block().consumes.all()){
|
||||
cons.trigger(entity.tile.block(), entity);
|
||||
cons.trigger(entity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +50,10 @@ public class ConsumeModule extends BlockModule{
|
||||
return valid && entity.tile.block().canProduce(entity.tile);
|
||||
}
|
||||
|
||||
public boolean optionalValid(){
|
||||
return valid() && optionalValid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
stream.writeBoolean(valid);
|
||||
|
||||
Reference in New Issue
Block a user