Use the sum of graph batteries from both sides
This commit is contained in:
@@ -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.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.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.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.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.battery-large.description = Stores much more power than a regular battery.
|
||||||
block.combustion-generator.description = Generates power by burning flammable materials, such as coal.
|
block.combustion-generator.description = Generates power by burning flammable materials, such as coal.
|
||||||
|
|||||||
@@ -3,13 +3,12 @@ package io.anuke.mindustry.world.blocks.power;
|
|||||||
import io.anuke.arc.Core;
|
import io.anuke.arc.Core;
|
||||||
import io.anuke.arc.graphics.g2d.Draw;
|
import io.anuke.arc.graphics.g2d.Draw;
|
||||||
import io.anuke.arc.graphics.g2d.TextureRegion;
|
import io.anuke.arc.graphics.g2d.TextureRegion;
|
||||||
import io.anuke.arc.math.Mathf;
|
|
||||||
import io.anuke.mindustry.world.Block;
|
import io.anuke.mindustry.world.Block;
|
||||||
import io.anuke.mindustry.world.Tile;
|
import io.anuke.mindustry.world.Tile;
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.world;
|
import static io.anuke.mindustry.Vars.world;
|
||||||
|
|
||||||
public class PowerDiode extends Block {
|
public class PowerDiode extends Block{
|
||||||
|
|
||||||
protected TextureRegion arrow;
|
protected TextureRegion arrow;
|
||||||
|
|
||||||
@@ -28,24 +27,18 @@ public class PowerDiode extends Block {
|
|||||||
Tile back = getNearby(tile, (tile.rotation() + 2) % 4);
|
Tile back = getNearby(tile, (tile.rotation() + 2) % 4);
|
||||||
Tile front = getNearby(tile, tile.rotation());
|
Tile front = getNearby(tile, tile.rotation());
|
||||||
|
|
||||||
if(back.block() != null && back.block() instanceof Battery &&
|
if(back.block() == null || front.block() == null) return;
|
||||||
front.block() != null && front.block() instanceof Battery){
|
if(!back.block().hasPower || !front.block().hasPower) return;
|
||||||
|
|
||||||
float backCapacity = back.block().consumes.getPower().capacity;
|
PowerGraph backGraph = back.entity.power.graph;
|
||||||
float frontCapacity = front.block().consumes.getPower().capacity;
|
PowerGraph frontGraph = front.entity.power.graph;
|
||||||
|
if(backGraph == frontGraph) return;
|
||||||
|
|
||||||
float backPower = backCapacity * back.entity.power.satisfaction;
|
if(backGraph.getBatteryStored() > 0f && backGraph.getBatteryStored() > frontGraph.getBatteryStored()){
|
||||||
float frontPower = frontCapacity * front.entity.power.satisfaction;
|
float send = (backGraph.getBatteryStored() - frontGraph.getBatteryStored()) / 2;
|
||||||
|
|
||||||
if(backPower > frontPower && front.entity.power.satisfaction < 1f){
|
backGraph.useBatteries(send);
|
||||||
float send = Mathf.clamp((backPower - frontPower) / 2, 0f, frontCapacity);
|
frontGraph.chargeBatteries(send);
|
||||||
|
|
||||||
back.entity.power.satisfaction -= send / backCapacity;
|
|
||||||
front.entity.power.satisfaction += send / frontCapacity;
|
|
||||||
}
|
|
||||||
tile.entity.noSleep();
|
|
||||||
}else{
|
|
||||||
tile.entity.sleep();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user