Use the sum of graph batteries from both sides

This commit is contained in:
Patrick 'Quezler' Mounier
2019-10-31 16:19:23 +01:00
parent 7fb8693ad1
commit e06ef72899
2 changed files with 11 additions and 18 deletions

View File

@@ -1121,7 +1121,7 @@ block.phase-conduit.description = Advanced liquid transport block. Uses power to
block.power-node.description = Transmits power to connected nodes. The node will receive power from or supply power to any adjacent blocks.
block.power-node-large.description = An advanced power node with greater range.
block.surge-tower.description = An extremely long-range power node with fewer available connections.
block.diode.description = Forwards power in only one direction. Needs batteries on either end.
block.diode.description = Battery power can flow through this block in only one direction, but only if the other side has less power stored.
block.battery.description = Stores power as a buffer in times of surplus energy. Outputs power in times of deficit.
block.battery-large.description = Stores much more power than a regular battery.
block.combustion-generator.description = Generates power by burning flammable materials, such as coal.

View File

@@ -3,13 +3,12 @@ package io.anuke.mindustry.world.blocks.power;
import io.anuke.arc.Core;
import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.graphics.g2d.TextureRegion;
import io.anuke.arc.math.Mathf;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
import static io.anuke.mindustry.Vars.world;
public class PowerDiode extends Block {
public class PowerDiode extends Block{
protected TextureRegion arrow;
@@ -28,24 +27,18 @@ public class PowerDiode extends Block {
Tile back = getNearby(tile, (tile.rotation() + 2) % 4);
Tile front = getNearby(tile, tile.rotation());
if(back.block() != null && back.block() instanceof Battery &&
front.block() != null && front.block() instanceof Battery){
if(back.block() == null || front.block() == null) return;
if(!back.block().hasPower || !front.block().hasPower) return;
float backCapacity = back.block().consumes.getPower().capacity;
float frontCapacity = front.block().consumes.getPower().capacity;
PowerGraph backGraph = back.entity.power.graph;
PowerGraph frontGraph = front.entity.power.graph;
if(backGraph == frontGraph) return;
float backPower = backCapacity * back.entity.power.satisfaction;
float frontPower = frontCapacity * front.entity.power.satisfaction;
if(backGraph.getBatteryStored() > 0f && backGraph.getBatteryStored() > frontGraph.getBatteryStored()){
float send = (backGraph.getBatteryStored() - frontGraph.getBatteryStored()) / 2;
if(backPower > frontPower && front.entity.power.satisfaction < 1f){
float send = Mathf.clamp((backPower - frontPower) / 2, 0f, frontCapacity);
back.entity.power.satisfaction -= send / backCapacity;
front.entity.power.satisfaction += send / frontCapacity;
}
tile.entity.noSleep();
}else{
tile.entity.sleep();
backGraph.useBatteries(send);
frontGraph.chargeBatteries(send);
}
}