Change power "satisfaction" -> "status", use efficiency() in blocks
This commit is contained in:
@@ -87,6 +87,11 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
|
||||
return Time.delta() * timeScale;
|
||||
}
|
||||
|
||||
/** Base efficiency. If this entity has non-buffered power, returns the power %, otherwise returns 1. */
|
||||
public float efficiency(){
|
||||
return power != null && !block.consumes.getPower().buffered ? power.status : 1f;
|
||||
}
|
||||
|
||||
/** Call when nothing is happening to the entity. This increments the internal sleep timer. */
|
||||
public void sleep(){
|
||||
sleepTime += Time.delta();
|
||||
|
||||
@@ -223,7 +223,7 @@ public class Block extends BlockStorage{
|
||||
protected float getProgressIncrease(TileEntity entity, float baseTime){
|
||||
float progressIncrease = 1f / baseTime * entity.delta();
|
||||
if(hasPower){
|
||||
progressIncrease *= entity.power.satisfaction; // Reduced increase in case of low power
|
||||
progressIncrease *= entity.power.status; // Reduced increase in case of low power
|
||||
}
|
||||
return progressIncrease;
|
||||
}
|
||||
@@ -532,8 +532,8 @@ public class Block extends BlockStorage{
|
||||
boolean buffered = cons.buffered;
|
||||
float capacity = cons.capacity;
|
||||
|
||||
bars.add("power", entity -> new Bar(() -> buffered ? Core.bundle.format("bar.poweramount", Float.isNaN(entity.power.satisfaction * capacity) ? "<ERROR>" : (int)(entity.power.satisfaction * capacity)) :
|
||||
Core.bundle.get("bar.power"), () -> Pal.powerBar, () -> Mathf.zero(cons.requestedPower(entity)) && entity.power.graph.getPowerProduced() + entity.power.graph.getBatteryStored() > 0f ? 1f : entity.power.satisfaction));
|
||||
bars.add("power", entity -> new Bar(() -> buffered ? Core.bundle.format("bar.poweramount", Float.isNaN(entity.power.status * capacity) ? "<ERROR>" : (int)(entity.power.status * capacity)) :
|
||||
Core.bundle.get("bar.power"), () -> Pal.powerBar, () -> Mathf.zero(cons.requestedPower(entity)) && entity.power.graph.getPowerProduced() + entity.power.graph.getBatteryStored() > 0f ? 1f : entity.power.status));
|
||||
}
|
||||
|
||||
if(hasItems && configurable){
|
||||
@@ -594,7 +594,7 @@ public class Block extends BlockStorage{
|
||||
}
|
||||
|
||||
if(consumes.hasPower() && consumes.getPower().buffered){
|
||||
power += tile.entity.power.satisfaction * consumes.getPower().capacity;
|
||||
power += tile.entity.power.status * consumes.getPower().capacity;
|
||||
}
|
||||
|
||||
if(hasLiquids){
|
||||
|
||||
@@ -108,12 +108,12 @@ public class ForceProjector extends Block{
|
||||
Effects.effect(Fx.reactorsmoke, tile.drawx() + Mathf.range(tilesize / 2f), tile.drawy() + Mathf.range(tilesize / 2f));
|
||||
}
|
||||
|
||||
entity.warmup = Mathf.lerpDelta(entity.warmup, entity.power.satisfaction, 0.1f);
|
||||
entity.warmup = Mathf.lerpDelta(entity.warmup, entity.efficiency(), 0.1f);
|
||||
|
||||
/*
|
||||
if(entity.power.satisfaction < relativePowerDraw){
|
||||
if(entity.power.status < relativePowerDraw){
|
||||
entity.warmup = Mathf.lerpDelta(entity.warmup, 0f, 0.15f);
|
||||
entity.power.satisfaction = 0f;
|
||||
entity.power.status = 0f;
|
||||
if(entity.warmup <= 0.09f){
|
||||
entity.broken = true;
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ public class MendProjector extends Block{
|
||||
|
||||
entity.phaseHeat = Mathf.lerpDelta(entity.phaseHeat, Mathf.num(entity.cons.optionalValid()), 0.1f);
|
||||
|
||||
if(entity.cons.optionalValid() && entity.timer.get(timerUse, useTime) && entity.power.satisfaction > 0){
|
||||
if(entity.cons.optionalValid() && entity.timer.get(timerUse, useTime) && entity.efficiency() > 0){
|
||||
entity.cons.trigger();
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ public class MendProjector extends Block{
|
||||
if(other == null) continue;
|
||||
|
||||
if(other.getTeamID() == tile.getTeamID() && !healed.contains(other.pos()) && other.entity != null && other.entity.health < other.entity.maxHealth()){
|
||||
other.entity.healBy(other.entity.maxHealth() * (healPercent + entity.phaseHeat * phaseBoost) / 100f * entity.power.satisfaction);
|
||||
other.entity.healBy(other.entity.maxHealth() * (healPercent + entity.phaseHeat * phaseBoost) / 100f * entity.efficiency());
|
||||
Effects.effect(Fx.healBlockFull, Tmp.c1.set(color).lerp(phase, entity.phaseHeat), other.drawx(), other.drawy(), other.block().size);
|
||||
healed.add(other.pos());
|
||||
}
|
||||
|
||||
@@ -74,13 +74,13 @@ public class OverdriveProjector extends Block{
|
||||
|
||||
entity.phaseHeat = Mathf.lerpDelta(entity.phaseHeat, Mathf.num(entity.cons.optionalValid()), 0.1f);
|
||||
|
||||
if(entity.timer.get(timerUse, useTime) && entity.power.satisfaction > 0){
|
||||
if(entity.timer.get(timerUse, useTime) && entity.efficiency() > 0){
|
||||
entity.cons.trigger();
|
||||
}
|
||||
|
||||
if(entity.charge >= reload){
|
||||
float realRange = range + entity.phaseHeat * phaseRangeBoost;
|
||||
float realBoost = (speedBoost + entity.phaseHeat * speedBoostPhase) * entity.power.satisfaction;
|
||||
float realBoost = (speedBoost + entity.phaseHeat * speedBoostPhase) * entity.efficiency();
|
||||
|
||||
entity.charge = 0f;
|
||||
|
||||
|
||||
@@ -47,6 +47,6 @@ public class PowerTurret extends CooledTurret{
|
||||
|
||||
@Override
|
||||
protected float baseReloadSpeed(Tile tile){
|
||||
return tile.isEnemyCheat() ? 1f : tile.entity.power.satisfaction;
|
||||
return tile.isEnemyCheat() ? 1f : tile.entity.power.status;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,7 +196,7 @@ public class ItemBridge extends Block{
|
||||
entity.uptime = 0f;
|
||||
}else{
|
||||
|
||||
if(entity.cons.valid() && (!hasPower || Mathf.zero(1f - entity.power.satisfaction))){
|
||||
if(entity.cons.valid() && Mathf.zero(1f - entity.efficiency())){
|
||||
entity.uptime = Mathf.lerpDelta(entity.uptime, 1f, 0.04f);
|
||||
}else{
|
||||
entity.uptime = Mathf.lerpDelta(entity.uptime, 0f, 0.02f);
|
||||
|
||||
@@ -32,7 +32,7 @@ public class LiquidBridge extends ItemBridge{
|
||||
if(entity.cons.valid()){
|
||||
float alpha = 0.04f;
|
||||
if(hasPower){
|
||||
alpha *= entity.power.satisfaction; // Exceed boot time unless power is at max.
|
||||
alpha *= entity.efficiency(); // Exceed boot time unless power is at max.
|
||||
}
|
||||
entity.uptime = Mathf.lerpDelta(entity.uptime, 1f, alpha);
|
||||
}else{
|
||||
|
||||
@@ -77,7 +77,7 @@ public class MassDriver extends Block{
|
||||
|
||||
//reload regardless of state
|
||||
if(entity.reload > 0f){
|
||||
entity.reload = Mathf.clamp(entity.reload - entity.delta() / reloadTime * entity.power.satisfaction);
|
||||
entity.reload = Mathf.clamp(entity.reload - entity.delta() / reloadTime * entity.efficiency());
|
||||
}
|
||||
|
||||
//cleanup waiting shooters that are not valid
|
||||
@@ -113,7 +113,7 @@ public class MassDriver extends Block{
|
||||
}
|
||||
|
||||
//align to shooter rotation
|
||||
entity.rotation = Mathf.slerpDelta(entity.rotation, tile.angleTo(entity.currentShooter()), rotateSpeed * entity.power.satisfaction);
|
||||
entity.rotation = Mathf.slerpDelta(entity.rotation, tile.angleTo(entity.currentShooter()), rotateSpeed * entity.efficiency());
|
||||
}else if(entity.state == DriverState.shooting){
|
||||
//if there's nothing to shoot at OR someone wants to shoot at this thing, bail
|
||||
if(!hasLink || (!entity.waitingShooters.isEmpty() && (itemCapacity - entity.items.total() >= minDistribute))){
|
||||
@@ -133,7 +133,7 @@ public class MassDriver extends Block{
|
||||
if(entity.reload <= 0.0001f){
|
||||
|
||||
//align to target location
|
||||
entity.rotation = Mathf.slerpDelta(entity.rotation, targetRotation, rotateSpeed * entity.power.satisfaction);
|
||||
entity.rotation = Mathf.slerpDelta(entity.rotation, targetRotation, rotateSpeed * entity.efficiency());
|
||||
|
||||
//fire when it's the first in the queue and angles are ready.
|
||||
if(other.currentShooter() == tile &&
|
||||
|
||||
@@ -71,7 +71,7 @@ public class ImpactReactor extends PowerGenerator{
|
||||
public void update(Tile tile){
|
||||
FusionReactorEntity entity = tile.entity();
|
||||
|
||||
if(entity.cons.valid() && entity.power.satisfaction >= 0.99f){
|
||||
if(entity.cons.valid() && entity.power.status >= 0.99f){
|
||||
boolean prevOut = getPowerProduction(tile) <= consumes.getPower().requestedPower(entity);
|
||||
|
||||
entity.warmup = Mathf.lerpDelta(entity.warmup, 1f, warmupSpeed);
|
||||
|
||||
@@ -83,7 +83,7 @@ public class PowerGraph{
|
||||
for(Tile battery : batteries){
|
||||
Consumers consumes = battery.block().consumes;
|
||||
if(consumes.hasPower()){
|
||||
totalAccumulator += battery.entity.power.satisfaction * consumes.getPower().capacity;
|
||||
totalAccumulator += battery.entity.power.status * consumes.getPower().capacity;
|
||||
}
|
||||
}
|
||||
return totalAccumulator;
|
||||
@@ -94,7 +94,7 @@ public class PowerGraph{
|
||||
for(Tile battery : batteries){
|
||||
if(battery.block().consumes.hasPower()){
|
||||
ConsumePower power = battery.block().consumes.getPower();
|
||||
totalCapacity += (1f - battery.entity.power.satisfaction) * power.capacity;
|
||||
totalCapacity += (1f - battery.entity.power.status) * power.capacity;
|
||||
}
|
||||
}
|
||||
return totalCapacity;
|
||||
@@ -119,7 +119,7 @@ public class PowerGraph{
|
||||
for(Tile battery : batteries){
|
||||
Consumers consumes = battery.block().consumes;
|
||||
if(consumes.hasPower()){
|
||||
battery.entity.power.satisfaction *= (1f-consumedPowerPercentage);
|
||||
battery.entity.power.status *= (1f-consumedPowerPercentage);
|
||||
}
|
||||
}
|
||||
return used;
|
||||
@@ -136,7 +136,7 @@ public class PowerGraph{
|
||||
if(consumes.hasPower()){
|
||||
ConsumePower consumePower = consumes.getPower();
|
||||
if(consumePower.capacity > 0f){
|
||||
battery.entity.power.satisfaction += (1f-battery.entity.power.satisfaction) * chargedPercent;
|
||||
battery.entity.power.status += (1f-battery.entity.power.status) * chargedPercent;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -154,17 +154,17 @@ public class PowerGraph{
|
||||
if(!Mathf.zero(consumePower.capacity)){
|
||||
// Add an equal percentage of power to all buffers, based on the global power coverage in this graph
|
||||
float maximumRate = consumePower.requestedPower(consumer.entity) * coverage * consumer.entity.delta();
|
||||
consumer.entity.power.satisfaction = Mathf.clamp(consumer.entity.power.satisfaction + maximumRate / consumePower.capacity);
|
||||
consumer.entity.power.status = Mathf.clamp(consumer.entity.power.status + maximumRate / consumePower.capacity);
|
||||
}
|
||||
}else{
|
||||
//valid consumers get power as usual
|
||||
if(otherConsumersAreValid(consumer, consumePower)){
|
||||
consumer.entity.power.satisfaction = coverage;
|
||||
consumer.entity.power.status = coverage;
|
||||
}else{ //invalid consumers get an estimate, if they were to activate
|
||||
consumer.entity.power.satisfaction = Math.min(1, produced / (needed + consumePower.usage * consumer.entity.delta()));
|
||||
consumer.entity.power.status = Math.min(1, produced / (needed + consumePower.usage * consumer.entity.delta()));
|
||||
//just in case
|
||||
if(Float.isNaN(consumer.entity.power.satisfaction)){
|
||||
consumer.entity.power.satisfaction = 0f;
|
||||
if(Float.isNaN(consumer.entity.power.status)){
|
||||
consumer.entity.power.status = 0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -176,9 +176,9 @@ public class PowerGraph{
|
||||
if(Core.graphics.getFrameId() == lastFrameUpdated){
|
||||
return;
|
||||
}else if(!consumers.isEmpty() && consumers.first().isEnemyCheat()){
|
||||
//when cheating, just set satisfaction to 1
|
||||
//when cheating, just set status to 1
|
||||
for(Tile tile : consumers){
|
||||
tile.entity.power.satisfaction = 1f;
|
||||
tile.entity.power.status = 1f;
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
@@ -257,9 +257,7 @@ public class Drill extends Block{
|
||||
speed = liquidBoostIntensity;
|
||||
}
|
||||
|
||||
if(hasPower){
|
||||
speed *= entity.power.satisfaction; // Drill slower when not at full power
|
||||
}
|
||||
speed *= entity.efficiency(); // Drill slower when not at full power
|
||||
|
||||
entity.lastDrillSpeed = (speed * entity.dominantItems * entity.warmup) / (drillTime + hardnessDrillMultiplier * entity.dominantItem.hardness);
|
||||
entity.warmup = Mathf.lerpDelta(entity.warmup, speed, warmupSpeed);
|
||||
|
||||
@@ -79,7 +79,7 @@ public class Fracker extends SolidPump{
|
||||
}
|
||||
|
||||
super.update(tile);
|
||||
entity.accumulator += entity.delta() * entity.power.satisfaction;
|
||||
entity.accumulator += entity.delta() * entity.efficiency();
|
||||
}else{
|
||||
tryDumpLiquid(tile, result);
|
||||
}
|
||||
|
||||
@@ -38,10 +38,8 @@ public class LiquidConverter extends GenericCrafter{
|
||||
ConsumeLiquidBase cl = consumes.get(ConsumeType.liquid);
|
||||
|
||||
if(tile.entity.cons.valid()){
|
||||
float use = Math.min(cl.amount * entity.delta(), liquidCapacity - entity.liquids.get(outputLiquid.liquid));
|
||||
if(hasPower){
|
||||
use *= entity.power.satisfaction; // Produce less liquid if power is not maxed
|
||||
}
|
||||
float use = Math.min(cl.amount * entity.delta(), liquidCapacity - entity.liquids.get(outputLiquid.liquid)) * entity.efficiency();
|
||||
|
||||
useContent(tile, outputLiquid.liquid);
|
||||
entity.progress += use / cl.amount / craftTime;
|
||||
entity.liquids.add(outputLiquid.liquid, use);
|
||||
|
||||
@@ -119,10 +119,7 @@ public class Pump extends LiquidBlock{
|
||||
}
|
||||
|
||||
if(tile.entity.cons.valid() && liquidDrop != null){
|
||||
float maxPump = Math.min(liquidCapacity - tile.entity.liquids.total(), tiles * pumpAmount * tile.entity.delta() / size / size);
|
||||
if(hasPower){
|
||||
maxPump *= tile.entity.power.satisfaction; // Produce slower if not at full power
|
||||
}
|
||||
float maxPump = Math.min(liquidCapacity - tile.entity.liquids.total(), tiles * pumpAmount * tile.entity.delta() / size / size) * tile.entity.efficiency();
|
||||
tile.entity.liquids.add(liquidDrop, maxPump);
|
||||
}
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ public class SolidPump extends Pump{
|
||||
fraction += entity.boost;
|
||||
|
||||
if(tile.entity.cons.valid() && typeLiquid(tile) < liquidCapacity - 0.001f){
|
||||
float maxPump = Math.min(liquidCapacity - typeLiquid(tile), pumpAmount * entity.delta() * fraction * entity.power.satisfaction);
|
||||
float maxPump = Math.min(liquidCapacity - typeLiquid(tile), pumpAmount * entity.delta() * fraction * entity.efficiency());
|
||||
tile.entity.liquids.add(result, maxPump);
|
||||
entity.warmup = Mathf.lerpDelta(entity.warmup, 1f, 0.02f);
|
||||
if(Mathf.chance(entity.delta() * updateEffectChance))
|
||||
|
||||
@@ -100,7 +100,7 @@ public class RepairPoint extends Block{
|
||||
if(entity.target != null && (entity.target.isDead() || entity.target.dst(tile) > repairRadius || entity.target.health >= entity.target.maxHealth())){
|
||||
entity.target = null;
|
||||
}else if(entity.target != null && entity.cons.valid()){
|
||||
entity.target.health += repairSpeed * Time.delta() * entity.strength * entity.power.satisfaction;
|
||||
entity.target.health += repairSpeed * Time.delta() * entity.strength * entity.efficiency();
|
||||
entity.target.clampHealth();
|
||||
entity.rotation = Mathf.slerpDelta(entity.rotation, entity.angleTo(entity.target), 0.5f);
|
||||
targetIsBeingRepaired = true;
|
||||
|
||||
@@ -159,8 +159,8 @@ public class UnitFactory extends Block{
|
||||
}
|
||||
|
||||
if(entity.cons.valid() || tile.isEnemyCheat()){
|
||||
entity.time += entity.delta() * entity.speedScl * Vars.state.rules.unitBuildSpeedMultiplier * entity.power.satisfaction;
|
||||
entity.buildTime += entity.delta() * entity.power.satisfaction * Vars.state.rules.unitBuildSpeedMultiplier;
|
||||
entity.time += entity.delta() * entity.speedScl * Vars.state.rules.unitBuildSpeedMultiplier * entity.efficiency();
|
||||
entity.buildTime += entity.delta() * entity.efficiency() * Vars.state.rules.unitBuildSpeedMultiplier;
|
||||
entity.speedScl = Mathf.lerpDelta(entity.speedScl, 1f, 0.05f);
|
||||
}else{
|
||||
entity.speedScl = Mathf.lerpDelta(entity.speedScl, 0f, 0.05f);
|
||||
|
||||
@@ -42,7 +42,7 @@ public class ConsumePower extends Consume{
|
||||
|
||||
@Override
|
||||
public void update(TileEntity entity){
|
||||
// Nothing to do since PowerGraph directly updates entity.power.satisfaction
|
||||
// Nothing to do since PowerGraph directly updates entity.power.status
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -50,7 +50,7 @@ public class ConsumePower extends Consume{
|
||||
if(buffered){
|
||||
return true;
|
||||
}else{
|
||||
return entity.power.satisfaction > 0f;
|
||||
return entity.power.status > 0f;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ public class ConsumePower extends Consume{
|
||||
public float requestedPower(TileEntity entity){
|
||||
if(entity.tile.entity == null) return 0f;
|
||||
if(buffered){
|
||||
return (1f-entity.power.satisfaction)*capacity;
|
||||
return (1f-entity.power.status)*capacity;
|
||||
}else{
|
||||
try{
|
||||
return usage * Mathf.num(entity.block.shouldConsume(entity.tile));
|
||||
|
||||
@@ -13,7 +13,7 @@ public class PowerModule extends BlockModule{
|
||||
* Blocks will work at a reduced efficiency if this is not equal to 1.0f.
|
||||
* In case of buffered consumers, this is the percentage of power stored in relation to the maximum capacity.
|
||||
*/
|
||||
public float satisfaction = 0.0f;
|
||||
public float status = 0.0f;
|
||||
public PowerGraph graph = new PowerGraph();
|
||||
public IntArray links = new IntArray();
|
||||
|
||||
@@ -23,7 +23,7 @@ public class PowerModule extends BlockModule{
|
||||
for(int i = 0; i < links.size; i++){
|
||||
stream.writeInt(links.get(i));
|
||||
}
|
||||
stream.writeFloat(satisfaction);
|
||||
stream.writeFloat(status);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -32,7 +32,7 @@ public class PowerModule extends BlockModule{
|
||||
for(int i = 0; i < amount; i++){
|
||||
links.add(stream.readInt());
|
||||
}
|
||||
satisfaction = stream.readFloat();
|
||||
if(Float.isNaN(satisfaction) || Float.isInfinite(satisfaction)) satisfaction = 0f;
|
||||
status = stream.readFloat();
|
||||
if(Float.isNaN(status) || Float.isInfinite(status)) status = 0f;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user