Added PowerType enum
This commit is contained in:
@@ -12,6 +12,7 @@ import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeItem;
|
||||
import io.anuke.mindustry.world.consumers.ConsumeLiquid;
|
||||
import io.anuke.mindustry.world.consumers.Consumers;
|
||||
import io.anuke.mindustry.world.meta.PowerType;
|
||||
import io.anuke.mindustry.world.meta.Producers;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
@@ -25,7 +26,7 @@ public abstract class BaseBlock extends MappableContent{
|
||||
|
||||
public boolean outputsLiquid = false;
|
||||
public boolean singleLiquid = true;
|
||||
public boolean outputsPower = false;
|
||||
public PowerType powerType = PowerType.consumer;
|
||||
|
||||
public int itemCapacity;
|
||||
public float liquidCapacity = 10f;
|
||||
|
||||
@@ -141,7 +141,7 @@ public class Block extends BaseBlock {
|
||||
public void updatePowerGraph(Tile tile){
|
||||
TileEntity entity = tile.entity();
|
||||
|
||||
for(Tile other : entity.proximity()){
|
||||
for(Tile other : getPowerConnections(tile, tempTiles)){
|
||||
if(other.entity.power != null){
|
||||
other.entity.power.graph.add(entity.power.graph);
|
||||
}
|
||||
@@ -152,6 +152,16 @@ public class Block extends BaseBlock {
|
||||
tile.entity.power.graph.remove(tile);
|
||||
}
|
||||
|
||||
public Array<Tile> getPowerConnections(Tile tile, Array<Tile> out){
|
||||
out.clear();
|
||||
for(Tile other : tile.entity.proximity()){
|
||||
if(other.entity.power != null && !(powerType == PowerType.consumer && other.block().powerType == PowerType.consumer)){
|
||||
out.add(other);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
public boolean isLayer(Tile tile){
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2,12 +2,13 @@ package io.anuke.mindustry.world.blocks.power;
|
||||
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.PowerBlock;
|
||||
import io.anuke.mindustry.world.meta.PowerType;
|
||||
|
||||
public class PowerDistributor extends PowerBlock{
|
||||
|
||||
public PowerDistributor(String name){
|
||||
super(name);
|
||||
outputsPower = true;
|
||||
powerType = PowerType.producer;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
package io.anuke.mindustry.world.blocks.power;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.ObjectSet;
|
||||
import com.badlogic.gdx.utils.Queue;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.util.Log;
|
||||
import io.anuke.mindustry.world.meta.PowerType;
|
||||
|
||||
import static io.anuke.mindustry.Vars.threads;
|
||||
|
||||
public class PowerGraph{
|
||||
private final static Queue<Tile> queue = new Queue<>();
|
||||
private final static Array<Tile> outArray1 = new Array<>();
|
||||
private final static Array<Tile> outArray2 = new Array<>();
|
||||
|
||||
private final ObjectSet<Tile> producers = new ObjectSet<>();
|
||||
private final ObjectSet<Tile> consumers = new ObjectSet<>();
|
||||
@@ -71,12 +74,11 @@ public class PowerGraph{
|
||||
public void add(Tile tile){
|
||||
tile.entity.power.graph = this;
|
||||
all.add(tile);
|
||||
if(tile.block().outputsPower){
|
||||
if(tile.block().powerType == PowerType.producer){
|
||||
producers.add(tile);
|
||||
}else{
|
||||
}else if(tile.block().powerType == PowerType.consumer){
|
||||
consumers.add(tile);
|
||||
}
|
||||
Log.info("New graph: {0} produce {1} consume {2} total", producers.size, consumers.size, all.size);
|
||||
}
|
||||
|
||||
public void remove(Tile tile){
|
||||
@@ -88,8 +90,8 @@ public class PowerGraph{
|
||||
producers.remove(tile);
|
||||
consumers.remove(tile);
|
||||
|
||||
for(Tile other : tile.entity.proximity()){
|
||||
if(other.entity.power == null || (other.entity.power != null && other.entity.power.graph != null)) continue;
|
||||
for(Tile other : tile.block().getPowerConnections(tile, outArray1)){
|
||||
if(other.entity.power == null || other.entity.power.graph != null) continue;
|
||||
PowerGraph graph = new PowerGraph();
|
||||
queue.clear();
|
||||
queue.addLast(other);
|
||||
@@ -97,7 +99,7 @@ public class PowerGraph{
|
||||
Tile child = queue.removeFirst();
|
||||
child.entity.power.graph = graph;
|
||||
add(child);
|
||||
for(Tile next : child.entity.proximity()){
|
||||
for(Tile next : child.block().getPowerConnections(child, outArray2)){
|
||||
if(next != tile && next.entity.power != null && next.entity.power.graph == null){
|
||||
queue.addLast(next);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import io.anuke.mindustry.world.Edges;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.PowerBlock;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.PowerType;
|
||||
import io.anuke.mindustry.world.meta.StatUnit;
|
||||
import io.anuke.ucore.core.Settings;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
@@ -49,7 +50,7 @@ public class PowerNode extends PowerBlock{
|
||||
layer = Layer.power;
|
||||
powerCapacity = 5f;
|
||||
configurable = true;
|
||||
outputsPower = true;
|
||||
powerType = PowerType.bridge;
|
||||
}
|
||||
|
||||
@Remote(targets = Loc.both, called = Loc.server, forward = true)
|
||||
|
||||
7
core/src/io/anuke/mindustry/world/meta/PowerType.java
Normal file
7
core/src/io/anuke/mindustry/world/meta/PowerType.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package io.anuke.mindustry.world.meta;
|
||||
|
||||
public enum PowerType{
|
||||
consumer,
|
||||
producer,
|
||||
bridge
|
||||
}
|
||||
Reference in New Issue
Block a user