diff --git a/core/src/io/anuke/mindustry/entities/type/TileEntity.java b/core/src/io/anuke/mindustry/entities/type/TileEntity.java index 5fa2ea9aae..3438eac854 100644 --- a/core/src/io/anuke/mindustry/entities/type/TileEntity.java +++ b/core/src/io/anuke/mindustry/entities/type/TileEntity.java @@ -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(); diff --git a/core/src/io/anuke/mindustry/world/Block.java b/core/src/io/anuke/mindustry/world/Block.java index 54ea767849..45b7fcb61d 100644 --- a/core/src/io/anuke/mindustry/world/Block.java +++ b/core/src/io/anuke/mindustry/world/Block.java @@ -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) ? "" : (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) ? "" : (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){ diff --git a/core/src/io/anuke/mindustry/world/blocks/defense/ForceProjector.java b/core/src/io/anuke/mindustry/world/blocks/defense/ForceProjector.java index 52977033f3..0ef91424a3 100644 --- a/core/src/io/anuke/mindustry/world/blocks/defense/ForceProjector.java +++ b/core/src/io/anuke/mindustry/world/blocks/defense/ForceProjector.java @@ -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; } diff --git a/core/src/io/anuke/mindustry/world/blocks/defense/MendProjector.java b/core/src/io/anuke/mindustry/world/blocks/defense/MendProjector.java index 30c261e0e1..57488c659a 100644 --- a/core/src/io/anuke/mindustry/world/blocks/defense/MendProjector.java +++ b/core/src/io/anuke/mindustry/world/blocks/defense/MendProjector.java @@ -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()); } diff --git a/core/src/io/anuke/mindustry/world/blocks/defense/OverdriveProjector.java b/core/src/io/anuke/mindustry/world/blocks/defense/OverdriveProjector.java index a9177fa1c7..2b571e04dc 100644 --- a/core/src/io/anuke/mindustry/world/blocks/defense/OverdriveProjector.java +++ b/core/src/io/anuke/mindustry/world/blocks/defense/OverdriveProjector.java @@ -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; diff --git a/core/src/io/anuke/mindustry/world/blocks/defense/turrets/PowerTurret.java b/core/src/io/anuke/mindustry/world/blocks/defense/turrets/PowerTurret.java index 2150fdac4d..7e4c54ace4 100644 --- a/core/src/io/anuke/mindustry/world/blocks/defense/turrets/PowerTurret.java +++ b/core/src/io/anuke/mindustry/world/blocks/defense/turrets/PowerTurret.java @@ -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; } } diff --git a/core/src/io/anuke/mindustry/world/blocks/distribution/ItemBridge.java b/core/src/io/anuke/mindustry/world/blocks/distribution/ItemBridge.java index b380ce61a8..a5ed073e6d 100644 --- a/core/src/io/anuke/mindustry/world/blocks/distribution/ItemBridge.java +++ b/core/src/io/anuke/mindustry/world/blocks/distribution/ItemBridge.java @@ -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); diff --git a/core/src/io/anuke/mindustry/world/blocks/distribution/LiquidBridge.java b/core/src/io/anuke/mindustry/world/blocks/distribution/LiquidBridge.java index d282321114..b676950594 100644 --- a/core/src/io/anuke/mindustry/world/blocks/distribution/LiquidBridge.java +++ b/core/src/io/anuke/mindustry/world/blocks/distribution/LiquidBridge.java @@ -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{ diff --git a/core/src/io/anuke/mindustry/world/blocks/distribution/MassDriver.java b/core/src/io/anuke/mindustry/world/blocks/distribution/MassDriver.java index 04a8af5b9b..61caaa5fae 100644 --- a/core/src/io/anuke/mindustry/world/blocks/distribution/MassDriver.java +++ b/core/src/io/anuke/mindustry/world/blocks/distribution/MassDriver.java @@ -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 && diff --git a/core/src/io/anuke/mindustry/world/blocks/power/ImpactReactor.java b/core/src/io/anuke/mindustry/world/blocks/power/ImpactReactor.java index 3dd3e6be3e..03ef45e1d0 100644 --- a/core/src/io/anuke/mindustry/world/blocks/power/ImpactReactor.java +++ b/core/src/io/anuke/mindustry/world/blocks/power/ImpactReactor.java @@ -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); diff --git a/core/src/io/anuke/mindustry/world/blocks/power/PowerGraph.java b/core/src/io/anuke/mindustry/world/blocks/power/PowerGraph.java index 038ff2010e..07ebe96040 100644 --- a/core/src/io/anuke/mindustry/world/blocks/power/PowerGraph.java +++ b/core/src/io/anuke/mindustry/world/blocks/power/PowerGraph.java @@ -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; diff --git a/core/src/io/anuke/mindustry/world/blocks/production/Drill.java b/core/src/io/anuke/mindustry/world/blocks/production/Drill.java index ab9af6ea9e..d3756dbd35 100644 --- a/core/src/io/anuke/mindustry/world/blocks/production/Drill.java +++ b/core/src/io/anuke/mindustry/world/blocks/production/Drill.java @@ -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); diff --git a/core/src/io/anuke/mindustry/world/blocks/production/Fracker.java b/core/src/io/anuke/mindustry/world/blocks/production/Fracker.java index 632fe30b7d..3e77f8f666 100644 --- a/core/src/io/anuke/mindustry/world/blocks/production/Fracker.java +++ b/core/src/io/anuke/mindustry/world/blocks/production/Fracker.java @@ -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); } diff --git a/core/src/io/anuke/mindustry/world/blocks/production/LiquidConverter.java b/core/src/io/anuke/mindustry/world/blocks/production/LiquidConverter.java index 7c9da8619d..6fa9477e69 100644 --- a/core/src/io/anuke/mindustry/world/blocks/production/LiquidConverter.java +++ b/core/src/io/anuke/mindustry/world/blocks/production/LiquidConverter.java @@ -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); diff --git a/core/src/io/anuke/mindustry/world/blocks/production/Pump.java b/core/src/io/anuke/mindustry/world/blocks/production/Pump.java index a2e989d81c..9b91d8b98f 100644 --- a/core/src/io/anuke/mindustry/world/blocks/production/Pump.java +++ b/core/src/io/anuke/mindustry/world/blocks/production/Pump.java @@ -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); } diff --git a/core/src/io/anuke/mindustry/world/blocks/production/SolidPump.java b/core/src/io/anuke/mindustry/world/blocks/production/SolidPump.java index 9f5c2bcc96..efe34f5dfb 100644 --- a/core/src/io/anuke/mindustry/world/blocks/production/SolidPump.java +++ b/core/src/io/anuke/mindustry/world/blocks/production/SolidPump.java @@ -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)) diff --git a/core/src/io/anuke/mindustry/world/blocks/units/RepairPoint.java b/core/src/io/anuke/mindustry/world/blocks/units/RepairPoint.java index 28c700caee..917f2748d6 100644 --- a/core/src/io/anuke/mindustry/world/blocks/units/RepairPoint.java +++ b/core/src/io/anuke/mindustry/world/blocks/units/RepairPoint.java @@ -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; diff --git a/core/src/io/anuke/mindustry/world/blocks/units/UnitFactory.java b/core/src/io/anuke/mindustry/world/blocks/units/UnitFactory.java index 1090f84015..2747093746 100644 --- a/core/src/io/anuke/mindustry/world/blocks/units/UnitFactory.java +++ b/core/src/io/anuke/mindustry/world/blocks/units/UnitFactory.java @@ -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); diff --git a/core/src/io/anuke/mindustry/world/consumers/ConsumePower.java b/core/src/io/anuke/mindustry/world/consumers/ConsumePower.java index dcdc1fd487..3343332fc4 100644 --- a/core/src/io/anuke/mindustry/world/consumers/ConsumePower.java +++ b/core/src/io/anuke/mindustry/world/consumers/ConsumePower.java @@ -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)); diff --git a/core/src/io/anuke/mindustry/world/modules/PowerModule.java b/core/src/io/anuke/mindustry/world/modules/PowerModule.java index ad82a5aedb..ad1a958fb7 100644 --- a/core/src/io/anuke/mindustry/world/modules/PowerModule.java +++ b/core/src/io/anuke/mindustry/world/modules/PowerModule.java @@ -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; } } diff --git a/tests/src/test/java/power/DirectConsumerTests.java b/tests/src/test/java/power/DirectConsumerTests.java index 7fdc9ef612..89ed331c8b 100644 --- a/tests/src/test/java/power/DirectConsumerTests.java +++ b/tests/src/test/java/power/DirectConsumerTests.java @@ -50,6 +50,6 @@ public class DirectConsumerTests extends PowerTestFixture{ consumerTile.entity.update(); graph.update(); - assertEquals(expectedSatisfaction, consumerTile.entity.power.satisfaction); + assertEquals(expectedSatisfaction, consumerTile.entity.power.status); } } diff --git a/tests/src/test/java/power/ItemLiquidGeneratorTests.java b/tests/src/test/java/power/ItemLiquidGeneratorTests.java index a4c0c78608..77f5b67570 100644 --- a/tests/src/test/java/power/ItemLiquidGeneratorTests.java +++ b/tests/src/test/java/power/ItemLiquidGeneratorTests.java @@ -20,7 +20,7 @@ import static org.junit.jupiter.api.DynamicTest.dynamicTest; * All tests are run with a fixed delta of 0.5 so delta considerations can be tested as well. * Additionally, each PowerGraph::update() call will have its own thread frame, i.e. the method will never be called twice within the same frame. * Both of these constraints are handled by FakeThreadHandler within PowerTestFixture. - * Any expected power amount (produced, consumed, buffered) should be affected by FakeThreadHandler.fakeDelta but satisfaction should not! + * Any expected power amount (produced, consumed, buffered) should be affected by FakeThreadHandler.fakeDelta but status should not! */ public class ItemLiquidGeneratorTests extends PowerTestFixture{ diff --git a/tests/src/test/java/power/PowerTests.java b/tests/src/test/java/power/PowerTests.java index 3c6e20e288..6b253e4f29 100644 --- a/tests/src/test/java/power/PowerTests.java +++ b/tests/src/test/java/power/PowerTests.java @@ -16,7 +16,7 @@ import static org.junit.jupiter.api.DynamicTest.dynamicTest; * All tests are run with a fixed delta of 0.5 so delta considerations can be tested as well. * Additionally, each PowerGraph::update() call will have its own thread frame, i.e. the method will never be called twice within the same frame. * Both of these constraints are handled by FakeThreadHandler within PowerTestFixture. - * Any power amount (produced, consumed, buffered) should be affected by Time.delta() but satisfaction should not! + * Any power amount (produced, consumed, buffered) should be affected by Time.delta() but status should not! */ public class PowerTests extends PowerTestFixture{ @@ -29,9 +29,9 @@ public class PowerTests extends PowerTestFixture{ class PowerGraphTests{ /** - * Tests the satisfaction of a single consumer after a single update of the power graph which contains a single producer. + * Tests the status of a single consumer after a single update of the power graph which contains a single producer. *

- * Assumption: When the consumer requests zero power, satisfaction does not change. Default is 0.0f. + * Assumption: When the consumer requests zero power, status does not change. Default is 0.0f. */ @TestFactory DynamicTest[] directConsumerSatisfactionIsAsExpected(){ @@ -61,13 +61,13 @@ public class PowerTests extends PowerTestFixture{ assertEquals(producedPower * Time.delta(), powerGraph.getPowerProduced(), Mathf.FLOAT_ROUNDING_ERROR); assertEquals(requiredPower * Time.delta(), powerGraph.getPowerNeeded(), Mathf.FLOAT_ROUNDING_ERROR); - // Update and check for the expected power satisfaction of the consumer + // Update and check for the expected power status of the consumer powerGraph.update(); - assertEquals(expectedSatisfaction, directConsumerTile.entity.power.satisfaction, Mathf.FLOAT_ROUNDING_ERROR, parameterDescription + ": Satisfaction of direct consumer did not match"); + assertEquals(expectedSatisfaction, directConsumerTile.entity.power.status, Mathf.FLOAT_ROUNDING_ERROR, parameterDescription + ": Satisfaction of direct consumer did not match"); } /** - * Tests the satisfaction of a single direct consumer after a single update of the power graph which contains a single producer and a single battery. + * Tests the status of a single direct consumer after a single update of the power graph which contains a single producer and a single battery. * The used battery is created with a maximum capacity of 100 and receives ten power per tick. */ @TestFactory @@ -101,14 +101,14 @@ public class PowerTests extends PowerTestFixture{ } float maxCapacity = 100f; Tile batteryTile = createFakeTile(0, 2, createFakeBattery(maxCapacity)); - batteryTile.entity.power.satisfaction = initialBatteryCapacity / maxCapacity; + batteryTile.entity.power.status = initialBatteryCapacity / maxCapacity; powerGraph.add(batteryTile); powerGraph.update(); - assertEquals(expectedBatteryCapacity / maxCapacity, batteryTile.entity.power.satisfaction, Mathf.FLOAT_ROUNDING_ERROR, parameterDescription + ": Expected battery satisfaction did not match"); + assertEquals(expectedBatteryCapacity / maxCapacity, batteryTile.entity.power.status, Mathf.FLOAT_ROUNDING_ERROR, parameterDescription + ": Expected battery status did not match"); if(directConsumerTile != null){ - assertEquals(expectedSatisfaction, directConsumerTile.entity.power.satisfaction, Mathf.FLOAT_ROUNDING_ERROR, parameterDescription + ": Satisfaction of direct consumer did not match"); + assertEquals(expectedSatisfaction, directConsumerTile.entity.power.status, Mathf.FLOAT_ROUNDING_ERROR, parameterDescription + ": Satisfaction of direct consumer did not match"); } } @@ -124,13 +124,13 @@ public class PowerTests extends PowerTestFixture{ powerGraph.add(consumerTile); powerGraph.update(); - assertEquals(1.0f, consumerTile.entity.power.satisfaction, Mathf.FLOAT_ROUNDING_ERROR); + assertEquals(1.0f, consumerTile.entity.power.status, Mathf.FLOAT_ROUNDING_ERROR); powerGraph.remove(producerTile); powerGraph.add(consumerTile); powerGraph.update(); - assertEquals(0.0f, consumerTile.entity.power.satisfaction, Mathf.FLOAT_ROUNDING_ERROR); + assertEquals(0.0f, consumerTile.entity.power.status, Mathf.FLOAT_ROUNDING_ERROR); if(consumerTile.block().consumes.hasPower()){ ConsumePower consumePower = consumerTile.block().consumes.getPower(); assertFalse(consumePower.valid(consumerTile.entity()));