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;
|
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. */
|
/** Call when nothing is happening to the entity. This increments the internal sleep timer. */
|
||||||
public void sleep(){
|
public void sleep(){
|
||||||
sleepTime += Time.delta();
|
sleepTime += Time.delta();
|
||||||
|
|||||||
@@ -223,7 +223,7 @@ public class Block extends BlockStorage{
|
|||||||
protected float getProgressIncrease(TileEntity entity, float baseTime){
|
protected float getProgressIncrease(TileEntity entity, float baseTime){
|
||||||
float progressIncrease = 1f / baseTime * entity.delta();
|
float progressIncrease = 1f / baseTime * entity.delta();
|
||||||
if(hasPower){
|
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;
|
return progressIncrease;
|
||||||
}
|
}
|
||||||
@@ -532,8 +532,8 @@ public class Block extends BlockStorage{
|
|||||||
boolean buffered = cons.buffered;
|
boolean buffered = cons.buffered;
|
||||||
float capacity = cons.capacity;
|
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)) :
|
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.satisfaction));
|
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){
|
if(hasItems && configurable){
|
||||||
@@ -594,7 +594,7 @@ public class Block extends BlockStorage{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(consumes.hasPower() && consumes.getPower().buffered){
|
if(consumes.hasPower() && consumes.getPower().buffered){
|
||||||
power += tile.entity.power.satisfaction * consumes.getPower().capacity;
|
power += tile.entity.power.status * consumes.getPower().capacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(hasLiquids){
|
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));
|
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.warmup = Mathf.lerpDelta(entity.warmup, 0f, 0.15f);
|
||||||
entity.power.satisfaction = 0f;
|
entity.power.status = 0f;
|
||||||
if(entity.warmup <= 0.09f){
|
if(entity.warmup <= 0.09f){
|
||||||
entity.broken = true;
|
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);
|
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();
|
entity.cons.trigger();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@ public class MendProjector extends Block{
|
|||||||
if(other == null) continue;
|
if(other == null) continue;
|
||||||
|
|
||||||
if(other.getTeamID() == tile.getTeamID() && !healed.contains(other.pos()) && other.entity != null && other.entity.health < other.entity.maxHealth()){
|
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);
|
Effects.effect(Fx.healBlockFull, Tmp.c1.set(color).lerp(phase, entity.phaseHeat), other.drawx(), other.drawy(), other.block().size);
|
||||||
healed.add(other.pos());
|
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);
|
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();
|
entity.cons.trigger();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(entity.charge >= reload){
|
if(entity.charge >= reload){
|
||||||
float realRange = range + entity.phaseHeat * phaseRangeBoost;
|
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;
|
entity.charge = 0f;
|
||||||
|
|
||||||
|
|||||||
@@ -47,6 +47,6 @@ public class PowerTurret extends CooledTurret{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected float baseReloadSpeed(Tile tile){
|
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;
|
entity.uptime = 0f;
|
||||||
}else{
|
}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);
|
entity.uptime = Mathf.lerpDelta(entity.uptime, 1f, 0.04f);
|
||||||
}else{
|
}else{
|
||||||
entity.uptime = Mathf.lerpDelta(entity.uptime, 0f, 0.02f);
|
entity.uptime = Mathf.lerpDelta(entity.uptime, 0f, 0.02f);
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ public class LiquidBridge extends ItemBridge{
|
|||||||
if(entity.cons.valid()){
|
if(entity.cons.valid()){
|
||||||
float alpha = 0.04f;
|
float alpha = 0.04f;
|
||||||
if(hasPower){
|
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);
|
entity.uptime = Mathf.lerpDelta(entity.uptime, 1f, alpha);
|
||||||
}else{
|
}else{
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ public class MassDriver extends Block{
|
|||||||
|
|
||||||
//reload regardless of state
|
//reload regardless of state
|
||||||
if(entity.reload > 0f){
|
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
|
//cleanup waiting shooters that are not valid
|
||||||
@@ -113,7 +113,7 @@ public class MassDriver extends Block{
|
|||||||
}
|
}
|
||||||
|
|
||||||
//align to shooter rotation
|
//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){
|
}else if(entity.state == DriverState.shooting){
|
||||||
//if there's nothing to shoot at OR someone wants to shoot at this thing, bail
|
//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))){
|
if(!hasLink || (!entity.waitingShooters.isEmpty() && (itemCapacity - entity.items.total() >= minDistribute))){
|
||||||
@@ -133,7 +133,7 @@ public class MassDriver extends Block{
|
|||||||
if(entity.reload <= 0.0001f){
|
if(entity.reload <= 0.0001f){
|
||||||
|
|
||||||
//align to target location
|
//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.
|
//fire when it's the first in the queue and angles are ready.
|
||||||
if(other.currentShooter() == tile &&
|
if(other.currentShooter() == tile &&
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ public class ImpactReactor extends PowerGenerator{
|
|||||||
public void update(Tile tile){
|
public void update(Tile tile){
|
||||||
FusionReactorEntity entity = tile.entity();
|
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);
|
boolean prevOut = getPowerProduction(tile) <= consumes.getPower().requestedPower(entity);
|
||||||
|
|
||||||
entity.warmup = Mathf.lerpDelta(entity.warmup, 1f, warmupSpeed);
|
entity.warmup = Mathf.lerpDelta(entity.warmup, 1f, warmupSpeed);
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ public class PowerGraph{
|
|||||||
for(Tile battery : batteries){
|
for(Tile battery : batteries){
|
||||||
Consumers consumes = battery.block().consumes;
|
Consumers consumes = battery.block().consumes;
|
||||||
if(consumes.hasPower()){
|
if(consumes.hasPower()){
|
||||||
totalAccumulator += battery.entity.power.satisfaction * consumes.getPower().capacity;
|
totalAccumulator += battery.entity.power.status * consumes.getPower().capacity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return totalAccumulator;
|
return totalAccumulator;
|
||||||
@@ -94,7 +94,7 @@ public class PowerGraph{
|
|||||||
for(Tile battery : batteries){
|
for(Tile battery : batteries){
|
||||||
if(battery.block().consumes.hasPower()){
|
if(battery.block().consumes.hasPower()){
|
||||||
ConsumePower power = battery.block().consumes.getPower();
|
ConsumePower power = battery.block().consumes.getPower();
|
||||||
totalCapacity += (1f - battery.entity.power.satisfaction) * power.capacity;
|
totalCapacity += (1f - battery.entity.power.status) * power.capacity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return totalCapacity;
|
return totalCapacity;
|
||||||
@@ -119,7 +119,7 @@ public class PowerGraph{
|
|||||||
for(Tile battery : batteries){
|
for(Tile battery : batteries){
|
||||||
Consumers consumes = battery.block().consumes;
|
Consumers consumes = battery.block().consumes;
|
||||||
if(consumes.hasPower()){
|
if(consumes.hasPower()){
|
||||||
battery.entity.power.satisfaction *= (1f-consumedPowerPercentage);
|
battery.entity.power.status *= (1f-consumedPowerPercentage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return used;
|
return used;
|
||||||
@@ -136,7 +136,7 @@ public class PowerGraph{
|
|||||||
if(consumes.hasPower()){
|
if(consumes.hasPower()){
|
||||||
ConsumePower consumePower = consumes.getPower();
|
ConsumePower consumePower = consumes.getPower();
|
||||||
if(consumePower.capacity > 0f){
|
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)){
|
if(!Mathf.zero(consumePower.capacity)){
|
||||||
// Add an equal percentage of power to all buffers, based on the global power coverage in this graph
|
// 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();
|
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{
|
}else{
|
||||||
//valid consumers get power as usual
|
//valid consumers get power as usual
|
||||||
if(otherConsumersAreValid(consumer, consumePower)){
|
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
|
}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
|
//just in case
|
||||||
if(Float.isNaN(consumer.entity.power.satisfaction)){
|
if(Float.isNaN(consumer.entity.power.status)){
|
||||||
consumer.entity.power.satisfaction = 0f;
|
consumer.entity.power.status = 0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -176,9 +176,9 @@ public class PowerGraph{
|
|||||||
if(Core.graphics.getFrameId() == lastFrameUpdated){
|
if(Core.graphics.getFrameId() == lastFrameUpdated){
|
||||||
return;
|
return;
|
||||||
}else if(!consumers.isEmpty() && consumers.first().isEnemyCheat()){
|
}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){
|
for(Tile tile : consumers){
|
||||||
tile.entity.power.satisfaction = 1f;
|
tile.entity.power.status = 1f;
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -257,9 +257,7 @@ public class Drill extends Block{
|
|||||||
speed = liquidBoostIntensity;
|
speed = liquidBoostIntensity;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(hasPower){
|
speed *= entity.efficiency(); // Drill slower when not at full power
|
||||||
speed *= entity.power.satisfaction; // Drill slower when not at full power
|
|
||||||
}
|
|
||||||
|
|
||||||
entity.lastDrillSpeed = (speed * entity.dominantItems * entity.warmup) / (drillTime + hardnessDrillMultiplier * entity.dominantItem.hardness);
|
entity.lastDrillSpeed = (speed * entity.dominantItems * entity.warmup) / (drillTime + hardnessDrillMultiplier * entity.dominantItem.hardness);
|
||||||
entity.warmup = Mathf.lerpDelta(entity.warmup, speed, warmupSpeed);
|
entity.warmup = Mathf.lerpDelta(entity.warmup, speed, warmupSpeed);
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ public class Fracker extends SolidPump{
|
|||||||
}
|
}
|
||||||
|
|
||||||
super.update(tile);
|
super.update(tile);
|
||||||
entity.accumulator += entity.delta() * entity.power.satisfaction;
|
entity.accumulator += entity.delta() * entity.efficiency();
|
||||||
}else{
|
}else{
|
||||||
tryDumpLiquid(tile, result);
|
tryDumpLiquid(tile, result);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,10 +38,8 @@ public class LiquidConverter extends GenericCrafter{
|
|||||||
ConsumeLiquidBase cl = consumes.get(ConsumeType.liquid);
|
ConsumeLiquidBase cl = consumes.get(ConsumeType.liquid);
|
||||||
|
|
||||||
if(tile.entity.cons.valid()){
|
if(tile.entity.cons.valid()){
|
||||||
float use = Math.min(cl.amount * entity.delta(), liquidCapacity - entity.liquids.get(outputLiquid.liquid));
|
float use = Math.min(cl.amount * entity.delta(), liquidCapacity - entity.liquids.get(outputLiquid.liquid)) * entity.efficiency();
|
||||||
if(hasPower){
|
|
||||||
use *= entity.power.satisfaction; // Produce less liquid if power is not maxed
|
|
||||||
}
|
|
||||||
useContent(tile, outputLiquid.liquid);
|
useContent(tile, outputLiquid.liquid);
|
||||||
entity.progress += use / cl.amount / craftTime;
|
entity.progress += use / cl.amount / craftTime;
|
||||||
entity.liquids.add(outputLiquid.liquid, use);
|
entity.liquids.add(outputLiquid.liquid, use);
|
||||||
|
|||||||
@@ -119,10 +119,7 @@ public class Pump extends LiquidBlock{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(tile.entity.cons.valid() && liquidDrop != null){
|
if(tile.entity.cons.valid() && liquidDrop != null){
|
||||||
float maxPump = Math.min(liquidCapacity - tile.entity.liquids.total(), tiles * pumpAmount * tile.entity.delta() / size / size);
|
float maxPump = Math.min(liquidCapacity - tile.entity.liquids.total(), tiles * pumpAmount * tile.entity.delta() / size / size) * tile.entity.efficiency();
|
||||||
if(hasPower){
|
|
||||||
maxPump *= tile.entity.power.satisfaction; // Produce slower if not at full power
|
|
||||||
}
|
|
||||||
tile.entity.liquids.add(liquidDrop, maxPump);
|
tile.entity.liquids.add(liquidDrop, maxPump);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ public class SolidPump extends Pump{
|
|||||||
fraction += entity.boost;
|
fraction += entity.boost;
|
||||||
|
|
||||||
if(tile.entity.cons.valid() && typeLiquid(tile) < liquidCapacity - 0.001f){
|
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);
|
tile.entity.liquids.add(result, maxPump);
|
||||||
entity.warmup = Mathf.lerpDelta(entity.warmup, 1f, 0.02f);
|
entity.warmup = Mathf.lerpDelta(entity.warmup, 1f, 0.02f);
|
||||||
if(Mathf.chance(entity.delta() * updateEffectChance))
|
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())){
|
if(entity.target != null && (entity.target.isDead() || entity.target.dst(tile) > repairRadius || entity.target.health >= entity.target.maxHealth())){
|
||||||
entity.target = null;
|
entity.target = null;
|
||||||
}else if(entity.target != null && entity.cons.valid()){
|
}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.target.clampHealth();
|
||||||
entity.rotation = Mathf.slerpDelta(entity.rotation, entity.angleTo(entity.target), 0.5f);
|
entity.rotation = Mathf.slerpDelta(entity.rotation, entity.angleTo(entity.target), 0.5f);
|
||||||
targetIsBeingRepaired = true;
|
targetIsBeingRepaired = true;
|
||||||
|
|||||||
@@ -159,8 +159,8 @@ public class UnitFactory extends Block{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(entity.cons.valid() || tile.isEnemyCheat()){
|
if(entity.cons.valid() || tile.isEnemyCheat()){
|
||||||
entity.time += entity.delta() * entity.speedScl * Vars.state.rules.unitBuildSpeedMultiplier * entity.power.satisfaction;
|
entity.time += entity.delta() * entity.speedScl * Vars.state.rules.unitBuildSpeedMultiplier * entity.efficiency();
|
||||||
entity.buildTime += entity.delta() * entity.power.satisfaction * Vars.state.rules.unitBuildSpeedMultiplier;
|
entity.buildTime += entity.delta() * entity.efficiency() * Vars.state.rules.unitBuildSpeedMultiplier;
|
||||||
entity.speedScl = Mathf.lerpDelta(entity.speedScl, 1f, 0.05f);
|
entity.speedScl = Mathf.lerpDelta(entity.speedScl, 1f, 0.05f);
|
||||||
}else{
|
}else{
|
||||||
entity.speedScl = Mathf.lerpDelta(entity.speedScl, 0f, 0.05f);
|
entity.speedScl = Mathf.lerpDelta(entity.speedScl, 0f, 0.05f);
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ public class ConsumePower extends Consume{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(TileEntity entity){
|
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
|
@Override
|
||||||
@@ -50,7 +50,7 @@ public class ConsumePower extends Consume{
|
|||||||
if(buffered){
|
if(buffered){
|
||||||
return true;
|
return true;
|
||||||
}else{
|
}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){
|
public float requestedPower(TileEntity entity){
|
||||||
if(entity.tile.entity == null) return 0f;
|
if(entity.tile.entity == null) return 0f;
|
||||||
if(buffered){
|
if(buffered){
|
||||||
return (1f-entity.power.satisfaction)*capacity;
|
return (1f-entity.power.status)*capacity;
|
||||||
}else{
|
}else{
|
||||||
try{
|
try{
|
||||||
return usage * Mathf.num(entity.block.shouldConsume(entity.tile));
|
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.
|
* 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.
|
* 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 PowerGraph graph = new PowerGraph();
|
||||||
public IntArray links = new IntArray();
|
public IntArray links = new IntArray();
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ public class PowerModule extends BlockModule{
|
|||||||
for(int i = 0; i < links.size; i++){
|
for(int i = 0; i < links.size; i++){
|
||||||
stream.writeInt(links.get(i));
|
stream.writeInt(links.get(i));
|
||||||
}
|
}
|
||||||
stream.writeFloat(satisfaction);
|
stream.writeFloat(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -32,7 +32,7 @@ public class PowerModule extends BlockModule{
|
|||||||
for(int i = 0; i < amount; i++){
|
for(int i = 0; i < amount; i++){
|
||||||
links.add(stream.readInt());
|
links.add(stream.readInt());
|
||||||
}
|
}
|
||||||
satisfaction = stream.readFloat();
|
status = stream.readFloat();
|
||||||
if(Float.isNaN(satisfaction) || Float.isInfinite(satisfaction)) satisfaction = 0f;
|
if(Float.isNaN(status) || Float.isInfinite(status)) status = 0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,6 +50,6 @@ public class DirectConsumerTests extends PowerTestFixture{
|
|||||||
consumerTile.entity.update();
|
consumerTile.entity.update();
|
||||||
graph.update();
|
graph.update();
|
||||||
|
|
||||||
assertEquals(expectedSatisfaction, consumerTile.entity.power.satisfaction);
|
assertEquals(expectedSatisfaction, consumerTile.entity.power.status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.
|
* 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.
|
* 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.
|
* 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{
|
public class ItemLiquidGeneratorTests extends PowerTestFixture{
|
||||||
|
|
||||||
|
|||||||
@@ -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.
|
* 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.
|
* 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.
|
* 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{
|
public class PowerTests extends PowerTestFixture{
|
||||||
|
|
||||||
@@ -29,9 +29,9 @@ public class PowerTests extends PowerTestFixture{
|
|||||||
class PowerGraphTests{
|
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.
|
||||||
* <p>
|
* <p>
|
||||||
* 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
|
@TestFactory
|
||||||
DynamicTest[] directConsumerSatisfactionIsAsExpected(){
|
DynamicTest[] directConsumerSatisfactionIsAsExpected(){
|
||||||
@@ -61,13 +61,13 @@ public class PowerTests extends PowerTestFixture{
|
|||||||
assertEquals(producedPower * Time.delta(), powerGraph.getPowerProduced(), Mathf.FLOAT_ROUNDING_ERROR);
|
assertEquals(producedPower * Time.delta(), powerGraph.getPowerProduced(), Mathf.FLOAT_ROUNDING_ERROR);
|
||||||
assertEquals(requiredPower * Time.delta(), powerGraph.getPowerNeeded(), 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();
|
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.
|
* The used battery is created with a maximum capacity of 100 and receives ten power per tick.
|
||||||
*/
|
*/
|
||||||
@TestFactory
|
@TestFactory
|
||||||
@@ -101,14 +101,14 @@ public class PowerTests extends PowerTestFixture{
|
|||||||
}
|
}
|
||||||
float maxCapacity = 100f;
|
float maxCapacity = 100f;
|
||||||
Tile batteryTile = createFakeTile(0, 2, createFakeBattery(maxCapacity));
|
Tile batteryTile = createFakeTile(0, 2, createFakeBattery(maxCapacity));
|
||||||
batteryTile.entity.power.satisfaction = initialBatteryCapacity / maxCapacity;
|
batteryTile.entity.power.status = initialBatteryCapacity / maxCapacity;
|
||||||
|
|
||||||
powerGraph.add(batteryTile);
|
powerGraph.add(batteryTile);
|
||||||
|
|
||||||
powerGraph.update();
|
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){
|
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.add(consumerTile);
|
||||||
powerGraph.update();
|
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.remove(producerTile);
|
||||||
powerGraph.add(consumerTile);
|
powerGraph.add(consumerTile);
|
||||||
powerGraph.update();
|
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()){
|
if(consumerTile.block().consumes.hasPower()){
|
||||||
ConsumePower consumePower = consumerTile.block().consumes.getPower();
|
ConsumePower consumePower = consumerTile.block().consumes.getPower();
|
||||||
assertFalse(consumePower.valid(consumerTile.entity()));
|
assertFalse(consumePower.valid(consumerTile.entity()));
|
||||||
|
|||||||
Reference in New Issue
Block a user