diff --git a/core/src/io/anuke/mindustry/content/blocks/ProductionBlocks.java b/core/src/io/anuke/mindustry/content/blocks/ProductionBlocks.java index 81eadc7561..9cb2ff315e 100644 --- a/core/src/io/anuke/mindustry/content/blocks/ProductionBlocks.java +++ b/core/src/io/anuke/mindustry/content/blocks/ProductionBlocks.java @@ -75,12 +75,12 @@ public class ProductionBlocks extends BlockList implements ContentList{ waterextractor = new SolidPump("water-extractor"){{ result = Liquids.water; - pumpAmount = 0.1f; + pumpAmount = 0.065f; size = 2; liquidCapacity = 30f; rotateSpeed = 1.4f; - consumes.power(0.15f); + consumes.power(0.13f); }}; oilextractor = new Fracker("oil-extractor"){{ diff --git a/core/src/io/anuke/mindustry/entities/TileEntity.java b/core/src/io/anuke/mindustry/entities/TileEntity.java index be42b41258..a484dc3e6c 100644 --- a/core/src/io/anuke/mindustry/entities/TileEntity.java +++ b/core/src/io/anuke/mindustry/entities/TileEntity.java @@ -179,19 +179,19 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{ for(GridPoint2 point : nearby){ Tile other = world.tile(tile.x + point.x, tile.y + point.y); - if(other != null){ - other.block().onProximityUpdate(other); - other = other.target(); + if(other == null || other.entity == null || other.getTeamID() != tile.getTeamID()) continue; + other = other.target(); + + if(other.entity.power != null) other.block().updatePowerGraph(other); + other.block().onProximityUpdate(other); + + tmpTiles.add(other); + + //add this tile to proximity of nearby tiles + if(!other.entity.proximity.contains(tile, true)){ + other.entity.proximity.add(tile); } - if(other != null && other.entity != null){ - tmpTiles.add(other); - - //add this tile to proximity of nearby tiles - if(!other.entity.proximity.contains(tile, true)){ - other.entity.proximity.add(tile); - } - } } //using a set to prevent duplicates @@ -199,6 +199,7 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{ proximity.add(tile); } + if(power != null) tile.block().updatePowerGraph(tile); tile.block().onProximityUpdate(tile); } diff --git a/core/src/io/anuke/mindustry/world/BaseBlock.java b/core/src/io/anuke/mindustry/world/BaseBlock.java index e3a1ff92fd..864989ffb4 100644 --- a/core/src/io/anuke/mindustry/world/BaseBlock.java +++ b/core/src/io/anuke/mindustry/world/BaseBlock.java @@ -25,6 +25,7 @@ public abstract class BaseBlock extends MappableContent{ public boolean outputsLiquid = false; public boolean singleLiquid = true; + public boolean outputsPower = false; public int itemCapacity; public float liquidCapacity = 10f; diff --git a/core/src/io/anuke/mindustry/world/Block.java b/core/src/io/anuke/mindustry/world/Block.java index 7453de15e5..e5f3da8e31 100644 --- a/core/src/io/anuke/mindustry/world/Block.java +++ b/core/src/io/anuke/mindustry/world/Block.java @@ -19,6 +19,7 @@ import io.anuke.mindustry.input.CursorType; import io.anuke.mindustry.type.ContentType; import io.anuke.mindustry.type.Item; import io.anuke.mindustry.type.ItemStack; +import io.anuke.mindustry.world.blocks.power.PowerGraph; import io.anuke.mindustry.world.meta.*; import io.anuke.ucore.core.Timers; import io.anuke.ucore.graphics.Draw; @@ -138,6 +139,26 @@ public class Block extends BaseBlock { return drops != null && drops.item == item; } + public void updatePowerGraph(Tile tile){ + TileEntity entity = tile.entity(); + + if(entity.power.graph == null){ + + for(Tile other : entity.proximity()){ + other = other.target(); + if(other.entity.power != null){ + entity.power.graph = other.entity.power.graph; + return; + } + } + + entity.power.graph = new PowerGraph(); + entity.power.graph.add(tile); + }else{ + //TODO + } + } + public boolean isLayer(Tile tile){ return true; } diff --git a/core/src/io/anuke/mindustry/world/blocks/power/PowerDistributor.java b/core/src/io/anuke/mindustry/world/blocks/power/PowerDistributor.java index 4b4410b485..e4b6836506 100644 --- a/core/src/io/anuke/mindustry/world/blocks/power/PowerDistributor.java +++ b/core/src/io/anuke/mindustry/world/blocks/power/PowerDistributor.java @@ -1,66 +1,17 @@ package io.anuke.mindustry.world.blocks.power; -import com.badlogic.gdx.math.GridPoint2; -import io.anuke.mindustry.entities.TileEntity; -import io.anuke.mindustry.world.Edges; import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.blocks.PowerBlock; -import io.anuke.ucore.core.Timers; public class PowerDistributor extends PowerBlock{ public PowerDistributor(String name){ super(name); - } - - protected void distributePower(Tile tile){ - TileEntity entity = tile.entity; - int sources = 0; - - if(entity == null) return; - - if(Float.isNaN(entity.power.amount)){ - entity.power.amount = 0f; - } - - for(GridPoint2 point : Edges.getEdges(size)){ - Tile target = tile.getNearby(point); - if(target != null && target.block().hasPower && - shouldDistribute(tile, target)) sources++; - } - - if(sources == 0) return; - - float result = entity.power.amount / sources; - - for(GridPoint2 point : Edges.getEdges(size)){ - Tile target = tile.getNearby(point); - if(target == null) continue; - target = target.target(); - - if(target.block().hasPower && shouldDistribute(tile, target)){ - float diff = (tile.entity.power.amount / powerCapacity - target.entity.power.amount / target.block().powerCapacity) / 1.4f; - - float transmit = Math.min(result * Timers.delta(), diff * powerCapacity); - if(target.block().acceptPower(target, tile, transmit)){ - float transferred = target.block().addPower(target, transmit); - entity.power.amount -= transferred; - } - } - } - } - - protected boolean shouldDistribute(Tile tile, Tile other){ - other = other.target(); - //only generators can distribute to other generators - return other.getTeamID() == tile.getTeamID() && (!(other.block() instanceof PowerGenerator) || tile.block() instanceof PowerGenerator) - && other.entity != null - && other.block().hasPower - && other.entity.power.amount / other.block().powerCapacity < tile.entity.power.amount / powerCapacity; + outputsPower = true; } @Override public void update(Tile tile){ - distributePower(tile); + tile.entity.power.graph.distribute(tile); } } diff --git a/core/src/io/anuke/mindustry/world/blocks/power/PowerGraph.java b/core/src/io/anuke/mindustry/world/blocks/power/PowerGraph.java new file mode 100644 index 0000000000..0390aa7679 --- /dev/null +++ b/core/src/io/anuke/mindustry/world/blocks/power/PowerGraph.java @@ -0,0 +1,27 @@ +package io.anuke.mindustry.world.blocks.power; + +import com.badlogic.gdx.utils.ObjectSet; +import io.anuke.mindustry.world.Tile; + +public class PowerGraph{ + private ObjectSet producers = new ObjectSet<>(); + private ObjectSet consumers = new ObjectSet<>(); + private ObjectSet all = new ObjectSet<>(); + + public void distribute(Tile tile){ + + } + + public void add(Tile tile){ + all.add(tile); + if(tile.block().outputsPower){ + producers.add(tile); + } + } + + public void remove(Tile tile){ + all.add(tile); + producers.remove(tile); + consumers.remove(tile); + } +} diff --git a/core/src/io/anuke/mindustry/world/blocks/power/PowerNode.java b/core/src/io/anuke/mindustry/world/blocks/power/PowerNode.java index d24921139f..3e66dbb588 100644 --- a/core/src/io/anuke/mindustry/world/blocks/power/PowerNode.java +++ b/core/src/io/anuke/mindustry/world/blocks/power/PowerNode.java @@ -49,6 +49,7 @@ public class PowerNode extends PowerBlock{ layer = Layer.power; powerCapacity = 5f; configurable = true; + outputsPower = true; } @Remote(targets = Loc.both, called = Loc.server, forward = true) diff --git a/core/src/io/anuke/mindustry/world/modules/PowerModule.java b/core/src/io/anuke/mindustry/world/modules/PowerModule.java index 320408ec5e..2647a442c1 100644 --- a/core/src/io/anuke/mindustry/world/modules/PowerModule.java +++ b/core/src/io/anuke/mindustry/world/modules/PowerModule.java @@ -1,5 +1,7 @@ package io.anuke.mindustry.world.modules; +import io.anuke.mindustry.world.blocks.power.PowerGraph; + import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; @@ -8,6 +10,7 @@ public class PowerModule extends BlockModule{ public float amount; public float capacity = 10f; public float voltage = 0.0001f; + public PowerGraph graph; public boolean acceptsPower(){ return amount + 0.001f <= capacity;