Readded buffered and direct consumers as three classes
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package io.anuke.mindustry.world.consumers;
|
||||
|
||||
import io.anuke.ucore.scene.ui.layout.Table;
|
||||
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.BlockStats;
|
||||
import io.anuke.mindustry.world.meta.StatUnit;
|
||||
|
||||
/** Consumer class for blocks which consume power while being connected to a power graph. */
|
||||
public abstract class ConsumePower extends Consume{
|
||||
/** The maximum amount of power which can be processed per tick. This might influence efficiency or load a buffer. */
|
||||
protected final float powerPerTick;
|
||||
|
||||
public ConsumePower(float powerPerTick){
|
||||
this.powerPerTick = powerPerTick;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildTooltip(Table table){
|
||||
// No tooltip for power
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIcon(){
|
||||
return "icon-power";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Block block, TileEntity entity){
|
||||
// Nothing to do since PowerGraph directly updates entity.power.satisfaction
|
||||
}
|
||||
|
||||
// valid(...) is implemented in subclass
|
||||
// display(...) is implemented in subclass
|
||||
|
||||
/**
|
||||
* Retrieves the amount of power which is requested for the given block and entity.
|
||||
* @param block The block which needs power.
|
||||
* @param entity The entity which contains the power module.
|
||||
* @return The amount of power which is requested per tick.
|
||||
*/
|
||||
public float requestedPower(Block block, TileEntity entity){
|
||||
// TODO Is it possible to make the block not consume power while items/liquids are missing?
|
||||
return powerPerTick;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package io.anuke.mindustry.world.consumers;
|
||||
|
||||
import io.anuke.ucore.scene.ui.layout.Table;
|
||||
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.BlockStats;
|
||||
import io.anuke.mindustry.world.meta.StatUnit;
|
||||
|
||||
/** Consumer class for blocks which directly consume power without buffering it. */
|
||||
public class ConsumePowerBuffered extends ConsumePower{
|
||||
/** The maximum power capacity in power units. */
|
||||
protected final float powerCapacity;
|
||||
|
||||
/**
|
||||
* Adds a power buffer to the owner which takes ticksToFill number of ticks to be filled.
|
||||
* Note that this object does not remove power from the buffer.
|
||||
* @param powerCapacity The maximum capacity in power units.
|
||||
* @param ticksToFill The number of ticks it shall take to fill the buffer.
|
||||
*/
|
||||
public ConsumePowerBuffered(float powerCapacity, float ticksToFill){
|
||||
super(powerCapacity / ticksToFill);
|
||||
this.powerCapacity = powerCapacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valid(Block block, TileEntity entity){
|
||||
// TODO - Verify: It might be necessary to know about the power required per shot/event here.
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void display(BlockStats stats){
|
||||
stats.add(BlockStat.powerCapacity, powerCapacity, StatUnit.powerSecond);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float requestedPower(Block block, TileEntity entity){
|
||||
// Only request power until the capacity is full
|
||||
return Math.max(powerPerTick, powerCapacity * (1 - entity.power.satisfaction));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package io.anuke.mindustry.world.consumers;
|
||||
|
||||
import io.anuke.ucore.scene.ui.layout.Table;
|
||||
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.BlockStats;
|
||||
import io.anuke.mindustry.world.meta.StatUnit;
|
||||
|
||||
/** Consumer class for blocks which directly consume power without buffering it. */
|
||||
public class ConsumePowerDirect extends ConsumePower{
|
||||
/** The minimum power satisfaction (fraction of powerPerTick) which must be achieved before the module may work. */
|
||||
protected final float minimumSatisfaction;
|
||||
|
||||
/**
|
||||
* Makes the owner consume powerPerTick each tick and disables it unless 60% of that power is being supplied.
|
||||
* @param powerPerTick The maximum amount of power which is required per tick for 100% efficiency.
|
||||
*/
|
||||
public ConsumePowerDirect(float powerPerTick){
|
||||
this(powerPerTick, 0.75f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the owner consume powerPerTick each tick and disables it unless minimumSatisfaction (1.0 = 100%) of that power is being supplied.
|
||||
* @param powerPerTick The maximum amount of power which is required per tick for 100% efficiency.
|
||||
* @param minimumSatisfaction The percentage of powerPerTick which must be available for the module to work.
|
||||
*/
|
||||
public ConsumePowerDirect(float powerPerTick, float minimumSatisfaction){
|
||||
super(powerPerTick);
|
||||
this.minimumSatisfaction = minimumSatisfaction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valid(Block block, TileEntity entity){
|
||||
return entity.power.satisfaction >= minimumSatisfaction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void display(BlockStats stats){
|
||||
stats.add(BlockStat.powerUse, powerPerTick * 60f, StatUnit.powerSecond);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user