oh no
This commit is contained in:
@@ -1,83 +0,0 @@
|
||||
package mindustry.world.blocks;
|
||||
|
||||
import mindustry.type.Item;
|
||||
import mindustry.type.Liquid;
|
||||
import mindustry.world.Block;
|
||||
import mindustry.world.Tile;
|
||||
|
||||
/**
|
||||
* Used for multiblocks. Each block that is not the center of the multiblock is a part.
|
||||
* Think of these as delegates to the actual block; all events are passed to the target block.
|
||||
* They are made to share all properties from the linked tile/block.
|
||||
*/
|
||||
public class BlockPart extends Block{
|
||||
public final static int maxSize = 9;
|
||||
private final static BlockPart[][] parts = new BlockPart[maxSize][maxSize];
|
||||
|
||||
private final int dx, dy;
|
||||
|
||||
public BlockPart(int dx, int dy){
|
||||
super("part_" + dx + "_" + dy);
|
||||
this.dx = dx;
|
||||
this.dy = dy;
|
||||
solid = false;
|
||||
hasPower = hasItems = hasLiquids = true;
|
||||
parts[dx + maxSize/2][dy + maxSize/2] = this;
|
||||
}
|
||||
|
||||
public static BlockPart get(int dx, int dy){
|
||||
if(dx == -maxSize/2 && dy == -maxSize/2) throw new IllegalArgumentException("Why are you getting a [0,0] blockpart? Stop it.");
|
||||
return parts[dx + maxSize/2][dy + maxSize/2];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
return tile.link().block().acceptItem(item, tile.link(), source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleItem(Item item, Tile tile, Tile source){
|
||||
tile.link().block().handleItem(item, tile.link(), source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
||||
Block block = tile.link().block();
|
||||
block.handleLiquid(tile.link(), source, liquid, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptLiquid(Tile tile, Tile source, Liquid liquid, float amount){
|
||||
Block block = tile.link().block();
|
||||
return block.hasLiquids && block.acceptLiquid(tile.link(), source, liquid, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tile linked(Tile tile){
|
||||
Tile out = tile.getNearby(-dx, -dy);
|
||||
return out == null ? tile : out;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawTeam(Tile tile){}
|
||||
|
||||
@Override
|
||||
public void draw(Tile tile){}
|
||||
|
||||
@Override
|
||||
public boolean synthetic(){
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHidden(){
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return "BlockPart[" + dx + ", " + dy + "]";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -63,7 +63,7 @@ public class BuildBlock extends Block{
|
||||
public static void onConstructFinish(Tile tile, Block block, int builderID, byte rotation, Team team, boolean skipConfig){
|
||||
if(tile == null) return;
|
||||
float healthf = tile.entity == null ? 1f : tile.entity.healthf();
|
||||
tile.set(block, team, rotation);
|
||||
tile.setBlock(block, team, (int)rotation);
|
||||
if(tile.entity != null){
|
||||
tile.entity.health(block.health * healthf);
|
||||
}
|
||||
@@ -265,8 +265,8 @@ public class BuildBlock extends Block{
|
||||
|
||||
if(clampedAmount > 0 && accumulated > 0){ //if it's positive, add it to the core
|
||||
if(core != null){
|
||||
int accepting = core.tile().block().acceptStack(requirements[i].item, accumulated, core.tile(), builder);
|
||||
core.tile().block().handleStack(requirements[i].item, accepting, core.tile(), builder);
|
||||
int accepting = core.tile().block().acceptStack(core.tile(), requirements[i].item, accumulated, builder);
|
||||
core.tile().block().handleStack(core.tile(), requirements[i].item, accepting, builder);
|
||||
accumulator[i] -= accepting;
|
||||
}else{
|
||||
accumulator[i] -= accumulated;
|
||||
|
||||
@@ -10,6 +10,7 @@ import mindustry.world.*;
|
||||
|
||||
import static mindustry.Vars.net;
|
||||
|
||||
//TODO remove ?
|
||||
public class RespawnBlock{
|
||||
|
||||
public static void drawRespawn(Tile tile, float heat, float progress, float time, Playerc player, UnitType to){
|
||||
|
||||
@@ -18,8 +18,6 @@ import mindustry.world.consumers.*;
|
||||
import mindustry.world.meta.*;
|
||||
import mindustry.world.meta.values.*;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class ItemTurret extends CooledTurret{
|
||||
@@ -45,7 +43,7 @@ public class ItemTurret extends CooledTurret{
|
||||
stats.add(BlockStat.ammo, new AmmoListValue<>(ammo));
|
||||
consumes.add(new ConsumeItemFilter(i -> ammo.containsKey(i)){
|
||||
@Override
|
||||
public void build(Tile tile, Table table){
|
||||
public void build(Tilec tile, Table table){
|
||||
MultiReqImage image = new MultiReqImage();
|
||||
content.items().each(i -> filter.get(i) && (!state.isCampaign() || data.isUnlocked(i)), item -> image.add(new ReqImage(new ItemImage(item.icon(Cicon.medium)),
|
||||
() -> tile.entity != null && !((ItemTurretEntity)tile.entity).ammo.isEmpty() && ((ItemEntry)tile.<ItemTurretEntity>ent().ammo.peek()).item == item)));
|
||||
@@ -72,7 +70,7 @@ public class ItemTurret extends CooledTurret{
|
||||
|
||||
//add first ammo item to cheaty blocks so they can shoot properly
|
||||
if(tile.isEnemyCheat() && ammo.size > 0){
|
||||
handleItem(ammo.entries().next().key, tile, tile);
|
||||
handleItem(tile, tile, ammo.entries().next().key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +85,7 @@ public class ItemTurret extends CooledTurret{
|
||||
}
|
||||
|
||||
@Override
|
||||
public int acceptStack(Item item, int amount, Tile tile, Teamc source){
|
||||
public int acceptStack(Tile tile, Item item, int amount, Teamc source){
|
||||
TurretEntity entity = tile.ent();
|
||||
|
||||
BulletType type = ammo.get(item);
|
||||
@@ -98,9 +96,9 @@ public class ItemTurret extends CooledTurret{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleStack(Item item, int amount, Tile tile, Teamc source){
|
||||
public void handleStack(Tile tile, Item item, int amount, Teamc source){
|
||||
for(int i = 0; i < amount; i++){
|
||||
handleItem(item, tile, null);
|
||||
handleItem(tile, null, item);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,7 +109,7 @@ public class ItemTurret extends CooledTurret{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleItem(Item item, Tile tile, Tile source){
|
||||
public void handleItem(Tile tile, Tile source, Item item){
|
||||
TurretEntity entity = tile.ent();
|
||||
if(entity == null) return;
|
||||
|
||||
@@ -144,7 +142,7 @@ public class ItemTurret extends CooledTurret{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
public boolean acceptItem(Tile tile, Tile source, Item item){
|
||||
TurretEntity entity = tile.ent();
|
||||
|
||||
return ammo != null && ammo.get(item) != null && entity.totalAmmo + ammo.get(item).ammoMultiplier <= maxAmmo;
|
||||
|
||||
@@ -123,7 +123,7 @@ public class LiquidTurret extends Turret{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
public boolean acceptItem(Tile tile, Tile source, Item item){
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,8 +10,8 @@ public class ArmoredConveyor extends Conveyor{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
return super.acceptItem(item, tile, source) && (source.block() instanceof Conveyor || Edges.getFacingEdge(source, tile).relativeTo(tile) == tile.rotation());
|
||||
public boolean acceptItem(Tile tile, Tile source, Item item){
|
||||
return super.acceptItem(tile, source, item) && (source.block() instanceof Conveyor || Edges.getFacingEdge(source, tile).relativeTo(tile) == tile.rotation());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,8 +5,6 @@ import arc.util.io.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.*;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class BufferedItemBridge extends ExtendingItemBridge{
|
||||
public final int timerAccept = timers++;
|
||||
|
||||
@@ -29,9 +27,9 @@ public class BufferedItemBridge extends ExtendingItemBridge{
|
||||
}
|
||||
|
||||
Item item = entity.buffer.poll();
|
||||
if(entity.timer(timerAccept, 4) && item != null && other.block().acceptItem(item, other, tile)){
|
||||
if(entity.timer(timerAccept, 4) && item != null && other.block().acceptItem(other, tile, item)){
|
||||
entity.cycleSpeed = Mathf.lerpDelta(entity.cycleSpeed, 4f, 0.05f);
|
||||
other.block().handleItem(item, other, tile);
|
||||
other.block().handleItem(other, tile, item);
|
||||
entity.buffer.remove();
|
||||
}else{
|
||||
entity.cycleSpeed = Mathf.lerpDelta(entity.cycleSpeed, 0f, 0.008f);
|
||||
|
||||
@@ -19,8 +19,6 @@ import mindustry.world.*;
|
||||
import mindustry.world.blocks.*;
|
||||
import mindustry.world.meta.*;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class Conveyor extends Block implements Autotiler{
|
||||
@@ -251,18 +249,18 @@ public class Conveyor extends Block implements Autotiler{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getStackOffset(Item item, Tile tile, Vec2 trns){
|
||||
public void getStackOffset(Tile tile, Item item, Vec2 trns){
|
||||
trns.trns(tile.rotation() * 90 + 180f, tilesize / 2f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int acceptStack(Item item, int amount, Tile tile, Teamc source){
|
||||
public int acceptStack(Tile tile, Item item, int amount, Teamc source){
|
||||
ConveyorEntity entity = tile.ent();
|
||||
return Math.min((int)(entity.minitem / itemSpace), amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleStack(Item item, int amount, Tile tile, Teamc source){
|
||||
public void handleStack(Tile tile, Item item, int amount, Teamc source){
|
||||
ConveyorEntity e = tile.ent();
|
||||
amount = Math.min(amount, itemCapacity - e.len);
|
||||
|
||||
@@ -278,7 +276,7 @@ public class Conveyor extends Block implements Autotiler{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
public boolean acceptItem(Tile tile, Tile source, Item item){
|
||||
ConveyorEntity e = tile.ent();
|
||||
if(e.len >= capacity) return false;
|
||||
int direction = source == null ? 0 : Math.abs(source.relativeTo(tile.x, tile.y) - tile.rotation());
|
||||
@@ -286,7 +284,7 @@ public class Conveyor extends Block implements Autotiler{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleItem(Item item, Tile tile, Tile source){
|
||||
public void handleItem(Tile tile, Tile source, Item item){
|
||||
ConveyorEntity e = tile.ent();
|
||||
if(e.len >= capacity) return;
|
||||
|
||||
|
||||
@@ -200,8 +200,8 @@ public class ItemBridge extends Block{
|
||||
|
||||
if(entity.uptime >= 0.5f && entity.timer(timerTransport, transportTime)){
|
||||
Item item = entity.items().take();
|
||||
if(item != null && other.block().acceptItem(item, other, tile)){
|
||||
other.block().handleItem(item, other, tile);
|
||||
if(item != null && other.block().acceptItem(other, tile, item)){
|
||||
other.block().handleItem(other, tile, item);
|
||||
entity.cycleSpeed = Mathf.lerpDelta(entity.cycleSpeed, 4f, 0.05f);
|
||||
}else{
|
||||
entity.cycleSpeed = Mathf.lerpDelta(entity.cycleSpeed, 1f, 0.01f);
|
||||
@@ -252,7 +252,7 @@ public class ItemBridge extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
public boolean acceptItem(Tile tile, Tile source, Item item){
|
||||
if(tile.team() != source.team()) return false;
|
||||
|
||||
ItemBridgeEntity entity = tile.ent();
|
||||
|
||||
@@ -10,8 +10,6 @@ import mindustry.world.DirectionalItemBuffer;
|
||||
import mindustry.world.Tile;
|
||||
import mindustry.world.meta.BlockGroup;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static mindustry.Vars.content;
|
||||
|
||||
public class Junction extends Block{
|
||||
@@ -28,7 +26,7 @@ public class Junction extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public int acceptStack(Item item, int amount, Tile tile, Teamc source){
|
||||
public int acceptStack(Tile tile, Item item, int amount, Teamc source){
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -55,11 +53,11 @@ public class Junction extends Block{
|
||||
if(dest != null) dest = dest.link();
|
||||
|
||||
//skip blocks that don't want the item, keep waiting until they do
|
||||
if(dest == null || !dest.block().acceptItem(item, dest, tile) || dest.team() != tile.team()){
|
||||
if(dest == null || !dest.block().acceptItem(dest, tile, item) || dest.team() != tile.team()){
|
||||
continue;
|
||||
}
|
||||
|
||||
dest.block().handleItem(item, dest, tile);
|
||||
dest.block().handleItem(dest, tile, item);
|
||||
System.arraycopy(buffer.buffers[i], 1, buffer.buffers[i], 0, buffer.indexes[i] - 1);
|
||||
buffer.indexes[i] --;
|
||||
}
|
||||
@@ -68,14 +66,14 @@ public class Junction extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleItem(Item item, Tile tile, Tile source){
|
||||
public void handleItem(Tile tile, Tile source, Item item){
|
||||
JunctionEntity entity = tile.ent();
|
||||
int relative = source.relativeTo(tile.x, tile.y);
|
||||
entity.buffer.accept(relative, item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
public boolean acceptItem(Tile tile, Tile source, Item item){
|
||||
JunctionEntity entity = tile.ent();
|
||||
int relative = source.relativeTo(tile.x, tile.y);
|
||||
|
||||
|
||||
@@ -221,7 +221,7 @@ public class MassDriver extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
public boolean acceptItem(Tile tile, Tile source, Item item){
|
||||
//mass drivers that ouput only cannot accept items
|
||||
return tile.entity.items().total() < itemCapacity && linkValid(tile);
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public class OverflowGate extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public int acceptStack(Item item, int amount, Tile tile, Teamc source){
|
||||
public int acceptStack(Tile tile, Item item, int amount, Teamc source){
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ public class OverflowGate extends Block{
|
||||
|
||||
if(target != null && (entity.time >= 1f)){
|
||||
getTileTarget(tile, entity.lastItem, entity.lastInput, true);
|
||||
target.block().handleItem(entity.lastItem, target, Edges.getFacingEdge(tile, target));
|
||||
target.block().handleItem(target, Edges.getFacingEdge(tile, target), entity.lastItem);
|
||||
entity.items().remove(entity.lastItem, 1);
|
||||
entity.lastItem = null;
|
||||
}
|
||||
@@ -71,14 +71,14 @@ public class OverflowGate extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
public boolean acceptItem(Tile tile, Tile source, Item item){
|
||||
OverflowGateEntity entity = tile.ent();
|
||||
|
||||
return tile.team() == source.team() && entity.lastItem == null && entity.items().total() == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleItem(Item item, Tile tile, Tile source){
|
||||
public void handleItem(Tile tile, Tile source, Item item){
|
||||
OverflowGateEntity entity = tile.ent();
|
||||
entity.items().add(item, 1);
|
||||
entity.lastItem = item;
|
||||
@@ -94,13 +94,13 @@ public class OverflowGate extends Block{
|
||||
Tile to = tile.getNearby((from + 2) % 4);
|
||||
if(to == null) return null;
|
||||
Tile edge = Edges.getFacingEdge(tile, to);
|
||||
boolean canForward = to.block().acceptItem(item, to, edge) && to.team() == tile.team() && !(to.block() instanceof OverflowGate);
|
||||
boolean canForward = to.block().acceptItem(to, edge, item) && to.team() == tile.team() && !(to.block() instanceof OverflowGate);
|
||||
|
||||
if(!canForward || invert){
|
||||
Tile a = tile.getNearby(Mathf.mod(from - 1, 4));
|
||||
Tile b = tile.getNearby(Mathf.mod(from + 1, 4));
|
||||
boolean ac = a != null && a.block().acceptItem(item, a, edge) && !(a.block() instanceof OverflowGate) && a.team() == tile.team();
|
||||
boolean bc = b != null && b.block().acceptItem(item, b, edge) && !(b.block() instanceof OverflowGate) && b.team() == tile.team();
|
||||
boolean ac = a != null && a.block().acceptItem(a, edge, item) && !(a.block() instanceof OverflowGate) && a.team() == tile.team();
|
||||
boolean bc = b != null && b.block().acceptItem(b, edge, item) && !(b.block() instanceof OverflowGate) && b.team() == tile.team();
|
||||
|
||||
if(!ac && !bc){
|
||||
return invert && canForward ? to : null;
|
||||
|
||||
@@ -36,7 +36,7 @@ public class Router extends Block{
|
||||
|
||||
if(target != null && (entity.time >= 1f || !(target.block() instanceof Router))){
|
||||
getTileTarget(tile, entity.lastItem, entity.lastInput, true);
|
||||
target.block().handleItem(entity.lastItem, target, Edges.getFacingEdge(tile, target));
|
||||
target.block().handleItem(target, Edges.getFacingEdge(tile, target), entity.lastItem);
|
||||
entity.items().remove(entity.lastItem, 1);
|
||||
entity.lastItem = null;
|
||||
}
|
||||
@@ -44,14 +44,14 @@ public class Router extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
public boolean acceptItem(Tile tile, Tile source, Item item){
|
||||
RouterEntity entity = tile.ent();
|
||||
|
||||
return tile.team() == source.team() && entity.lastItem == null && entity.items().total() == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleItem(Item item, Tile tile, Tile source){
|
||||
public void handleItem(Tile tile, Tile source, Item item){
|
||||
RouterEntity entity = tile.ent();
|
||||
entity.items().add(item, 1);
|
||||
entity.lastItem = item;
|
||||
@@ -66,7 +66,7 @@ public class Router extends Block{
|
||||
Tile other = proximity.get((i + counter) % proximity.size);
|
||||
if(set) tile.rotation((byte)((tile.rotation() + 1) % proximity.size));
|
||||
if(other == from && from.block() == Blocks.overflowGate) continue;
|
||||
if(other.block().acceptItem(item, other, Edges.getFacingEdge(tile, other))){
|
||||
if(other.block().acceptItem(other, Edges.getFacingEdge(tile, other), item)){
|
||||
return other;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,17 +77,17 @@ public class Sorter extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
public boolean acceptItem(Tile tile, Tile source, Item item){
|
||||
Tile to = getTileTarget(item, tile, source, false);
|
||||
|
||||
return to != null && to.block().acceptItem(item, to, tile) && to.team() == tile.team();
|
||||
return to != null && to.block().acceptItem(to, tile, item) && to.team() == tile.team();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleItem(Item item, Tile tile, Tile source){
|
||||
public void handleItem(Tile tile, Tile source, Item item){
|
||||
Tile to = getTileTarget(item, tile, source, true);
|
||||
|
||||
to.block().handleItem(item, to, tile);
|
||||
to.block().handleItem(to, tile, item);
|
||||
}
|
||||
|
||||
boolean isSame(Tile tile, Tile other){
|
||||
@@ -112,9 +112,9 @@ public class Sorter extends Block{
|
||||
Tile a = dest.getNearby(Mathf.mod(dir - 1, 4));
|
||||
Tile b = dest.getNearby(Mathf.mod(dir + 1, 4));
|
||||
boolean ac = a != null && !(a.block().instantTransfer && source.block().instantTransfer) &&
|
||||
a.block().acceptItem(item, a, dest);
|
||||
a.block().acceptItem(a, dest, item);
|
||||
boolean bc = b != null && !(b.block().instantTransfer && source.block().instantTransfer) &&
|
||||
b.block().acceptItem(item, b, dest);
|
||||
b.block().acceptItem(b, dest, item);
|
||||
|
||||
if(ac && !bc){
|
||||
to = a;
|
||||
|
||||
@@ -54,7 +54,7 @@ public class LiquidBridge extends ItemBridge{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
public boolean acceptItem(Tile tile, Tile source, Item item){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public class LiquidExtendingBridge extends ExtendingItemBridge{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
public boolean acceptItem(Tile tile, Tile source, Item item){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
package mindustry.world.blocks.power;
|
||||
|
||||
import arc.*;
|
||||
import arc.struct.*;
|
||||
import arc.math.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.world.consumers.*;
|
||||
|
||||
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 static Queue<Tilec> queue = new Queue<>();
|
||||
private final static Array<Tilec> outArray1 = new Array<>();
|
||||
private final static Array<Tilec> outArray2 = new Array<>();
|
||||
private final static IntSet closedSet = new IntSet();
|
||||
|
||||
private final ObjectSet<Tile> producers = new ObjectSet<>();
|
||||
private final ObjectSet<Tile> consumers = new ObjectSet<>();
|
||||
private final ObjectSet<Tile> batteries = new ObjectSet<>();
|
||||
private final ObjectSet<Tile> all = new ObjectSet<>();
|
||||
private final ObjectSet<Tilec> producers = new ObjectSet<>();
|
||||
private final ObjectSet<Tilec> consumers = new ObjectSet<>();
|
||||
private final ObjectSet<Tilec> batteries = new ObjectSet<>();
|
||||
private final ObjectSet<Tilec> all = new ObjectSet<>();
|
||||
|
||||
private final WindowedMean powerBalance = new WindowedMean(60);
|
||||
private float lastPowerProduced, lastPowerNeeded, lastUsageFraction;
|
||||
@@ -62,21 +62,21 @@ public class PowerGraph{
|
||||
|
||||
public float getPowerProduced(){
|
||||
float powerProduced = 0f;
|
||||
for(Tile producer : producers){
|
||||
for(Tilec producer : producers){
|
||||
if(producer.entity == null) continue;
|
||||
powerProduced += producer.block().getPowerProduction(producer) * producer.entity.delta();
|
||||
powerProduced += producer.block().getPowerProduction(producer) * producer.delta();
|
||||
}
|
||||
return powerProduced;
|
||||
}
|
||||
|
||||
public float getPowerNeeded(){
|
||||
float powerNeeded = 0f;
|
||||
for(Tile consumer : consumers){
|
||||
for(Tilec consumer : consumers){
|
||||
Consumers consumes = consumer.block().consumes;
|
||||
if(consumes.hasPower()){
|
||||
ConsumePower consumePower = consumes.getPower();
|
||||
if(otherConsumersAreValid(consumer, consumePower)){
|
||||
powerNeeded += consumePower.requestedPower(consumer.entity) * consumer.entity.delta();
|
||||
powerNeeded += consumePower.requestedPower(consumer) * consumer.delta();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -85,10 +85,10 @@ public class PowerGraph{
|
||||
|
||||
public float getBatteryStored(){
|
||||
float totalAccumulator = 0f;
|
||||
for(Tile battery : batteries){
|
||||
for(Tilec battery : batteries){
|
||||
Consumers consumes = battery.block().consumes;
|
||||
if(consumes.hasPower()){
|
||||
totalAccumulator += battery.entity.power().status * consumes.getPower().capacity;
|
||||
totalAccumulator += battery.power().status * consumes.getPower().capacity;
|
||||
}
|
||||
}
|
||||
return totalAccumulator;
|
||||
@@ -96,10 +96,10 @@ public class PowerGraph{
|
||||
|
||||
public float getBatteryCapacity(){
|
||||
float totalCapacity = 0f;
|
||||
for(Tile battery : batteries){
|
||||
for(Tilec battery : batteries){
|
||||
if(battery.block().consumes.hasPower()){
|
||||
ConsumePower power = battery.block().consumes.getPower();
|
||||
totalCapacity += (1f - battery.entity.power().status) * power.capacity;
|
||||
totalCapacity += (1f - battery.power().status) * power.capacity;
|
||||
}
|
||||
}
|
||||
return totalCapacity;
|
||||
@@ -107,7 +107,7 @@ public class PowerGraph{
|
||||
|
||||
public float getTotalBatteryCapacity(){
|
||||
float totalCapacity = 0f;
|
||||
for(Tile battery : batteries){
|
||||
for(Tilec battery : batteries){
|
||||
if(battery.block().consumes.hasPower()){
|
||||
totalCapacity += battery.block().consumes.getPower().capacity;
|
||||
}
|
||||
@@ -121,10 +121,10 @@ public class PowerGraph{
|
||||
|
||||
float used = Math.min(stored, needed);
|
||||
float consumedPowerPercentage = Math.min(1.0f, needed / stored);
|
||||
for(Tile battery : batteries){
|
||||
for(Tilec battery : batteries){
|
||||
Consumers consumes = battery.block().consumes;
|
||||
if(consumes.hasPower()){
|
||||
battery.entity.power().status *= (1f-consumedPowerPercentage);
|
||||
battery.power().status *= (1f-consumedPowerPercentage);
|
||||
}
|
||||
}
|
||||
return used;
|
||||
@@ -136,12 +136,12 @@ public class PowerGraph{
|
||||
float chargedPercent = Math.min(excess/capacity, 1f);
|
||||
if(Mathf.equal(capacity, 0f)) return 0f;
|
||||
|
||||
for(Tile battery : batteries){
|
||||
for(Tilec battery : batteries){
|
||||
Consumers consumes = battery.block().consumes;
|
||||
if(consumes.hasPower()){
|
||||
ConsumePower consumePower = consumes.getPower();
|
||||
if(consumePower.capacity > 0f){
|
||||
battery.entity.power().status += (1f-battery.entity.power().status) * chargedPercent;
|
||||
battery.power().status += (1f-battery.power().status) * chargedPercent;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -151,25 +151,25 @@ public class PowerGraph{
|
||||
public void distributePower(float needed, float produced){
|
||||
//distribute even if not needed. this is because some might be requiring power but not using it; it updates consumers
|
||||
float coverage = Mathf.zero(needed) && Mathf.zero(produced) ? 0f : Mathf.zero(needed) ? 1f : Math.min(1, produced / needed);
|
||||
for(Tile consumer : consumers){
|
||||
for(Tilec consumer : consumers){
|
||||
Consumers consumes = consumer.block().consumes;
|
||||
if(consumes.hasPower()){
|
||||
ConsumePower consumePower = consumes.getPower();
|
||||
if(consumePower.buffered){
|
||||
if(!Mathf.zero(consumePower.capacity)){
|
||||
// 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();
|
||||
consumer.entity.power().status = Mathf.clamp(consumer.entity.power().status + maximumRate / consumePower.capacity);
|
||||
float maximumRate = consumePower.requestedPower(consumer) * coverage * consumer.delta();
|
||||
consumer.power().status = Mathf.clamp(consumer.power().status + maximumRate / consumePower.capacity);
|
||||
}
|
||||
}else{
|
||||
//valid consumers get power as usual
|
||||
if(otherConsumersAreValid(consumer, consumePower)){
|
||||
consumer.entity.power().status = coverage;
|
||||
consumer.power().status = coverage;
|
||||
}else{ //invalid consumers get an estimate, if they were to activate
|
||||
consumer.entity.power().status = Math.min(1, produced / (needed + consumePower.usage * consumer.entity.delta()));
|
||||
consumer.power().status = Math.min(1, produced / (needed + consumePower.usage * consumer.delta()));
|
||||
//just in case
|
||||
if(Float.isNaN(consumer.entity.power().status)){
|
||||
consumer.entity.power().status = 0f;
|
||||
if(Float.isNaN(consumer.power().status)){
|
||||
consumer.power().status = 0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -180,10 +180,10 @@ public class PowerGraph{
|
||||
public void update(){
|
||||
if(Core.graphics.getFrameId() == lastFrameUpdated){
|
||||
return;
|
||||
}else if(!consumers.isEmpty() && consumers.first().isEnemyCheat()){
|
||||
}else if(!consumers.isEmpty() && consumers.first().tile().isEnemyCheat()){
|
||||
//when cheating, just set status to 1
|
||||
for(Tile tile : consumers){
|
||||
tile.entity.power().status = 1f;
|
||||
for(Tilec tile : consumers){
|
||||
tile.power().status = 1f;
|
||||
}
|
||||
|
||||
lastPowerNeeded = lastPowerProduced = lastUsageFraction = 1f;
|
||||
@@ -224,14 +224,14 @@ public class PowerGraph{
|
||||
}
|
||||
|
||||
public void add(PowerGraph graph){
|
||||
for(Tile tile : graph.all){
|
||||
for(Tilec tile : graph.all){
|
||||
add(tile);
|
||||
}
|
||||
}
|
||||
|
||||
public void add(Tile tile){
|
||||
if(tile.entity == null || tile.entity.power() == null) return;
|
||||
tile.entity.power().graph = this;
|
||||
public void add(Tilec tile){
|
||||
if(tile.entity == null || tile.power() == null) return;
|
||||
tile.power().graph = this;
|
||||
all.add(tile);
|
||||
|
||||
if(tile.block().outputsPower && tile.block().consumesPower && !tile.block().consumes.getPower().buffered){
|
||||
@@ -246,14 +246,14 @@ public class PowerGraph{
|
||||
}
|
||||
}
|
||||
|
||||
public void reflow(Tile tile){
|
||||
public void reflow(Tilec tile){
|
||||
queue.clear();
|
||||
queue.addLast(tile);
|
||||
closedSet.clear();
|
||||
while(queue.size > 0){
|
||||
Tile child = queue.removeFirst();
|
||||
Tilec child = queue.removeFirst();
|
||||
add(child);
|
||||
for(Tile next : child.block().getPowerConnections(child, outArray2)){
|
||||
for(Tilec next : child.block().getPowerConnections(child, outArray2)){
|
||||
if(!closedSet.contains(next.pos())){
|
||||
queue.addLast(next);
|
||||
closedSet.add(next.pos());
|
||||
@@ -262,22 +262,22 @@ public class PowerGraph{
|
||||
}
|
||||
}
|
||||
|
||||
private void removeSingle(Tile tile){
|
||||
private void removeSingle(Tilec tile){
|
||||
all.remove(tile);
|
||||
producers.remove(tile);
|
||||
consumers.remove(tile);
|
||||
batteries.remove(tile);
|
||||
}
|
||||
|
||||
public void remove(Tile tile){
|
||||
public void remove(Tilec tile){
|
||||
removeSingle(tile);
|
||||
//begin by clearing the closed set
|
||||
closedSet.clear();
|
||||
|
||||
//go through all the connections of this tile
|
||||
for(Tile other : tile.block().getPowerConnections(tile, outArray1)){
|
||||
for(Tilec other : tile.block().getPowerConnections(tile, outArray1)){
|
||||
//a graph has already been assigned to this tile from a previous call, skip it
|
||||
if(other.entity.power().graph != this) continue;
|
||||
if(other.power().graph != this) continue;
|
||||
|
||||
//create graph for this branch
|
||||
PowerGraph graph = new PowerGraph();
|
||||
@@ -287,16 +287,16 @@ public class PowerGraph{
|
||||
queue.addLast(other);
|
||||
while(queue.size > 0){
|
||||
//get child from queue
|
||||
Tile child = queue.removeFirst();
|
||||
Tilec child = queue.removeFirst();
|
||||
//remove it from this graph
|
||||
removeSingle(child);
|
||||
//add it to the new branch graph
|
||||
graph.add(child);
|
||||
//go through connections
|
||||
for(Tile next : child.block().getPowerConnections(child, outArray2)){
|
||||
for(Tilec next : child.block().getPowerConnections(child, outArray2)){
|
||||
//make sure it hasn't looped back, and that the new graph being assigned hasn't already been assigned
|
||||
//also skip closed tiles
|
||||
if(next != tile && next.entity.power().graph != graph && !closedSet.contains(next.pos())){
|
||||
if(next != tile && next.power().graph != graph && !closedSet.contains(next.pos())){
|
||||
queue.addLast(next);
|
||||
closedSet.add(next.pos());
|
||||
}
|
||||
@@ -307,9 +307,9 @@ public class PowerGraph{
|
||||
}
|
||||
}
|
||||
|
||||
private boolean otherConsumersAreValid(Tile tile, Consume consumePower){
|
||||
private boolean otherConsumersAreValid(Tilec tile, Consume consumePower){
|
||||
for(Consume cons : tile.block().consumes.all()){
|
||||
if(cons != consumePower && !cons.isOptional() && !cons.valid(tile.ent())){
|
||||
if(cons != consumePower && !cons.isOptional() && !cons.valid(tile)){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -313,12 +313,12 @@ public class PowerNode extends PowerBlock{
|
||||
return tile.entity.power().links.contains(other.pos());
|
||||
}
|
||||
|
||||
public boolean linkValid(Tile tile, Tile link){
|
||||
public boolean linkValid(Tilec tile, Tilec link){
|
||||
return linkValid(tile, link, true);
|
||||
}
|
||||
|
||||
public boolean linkValid(Tile tile, Tile link, boolean checkMaxNodes){
|
||||
if(tile == link || link == null || link.entity == null || tile.entity == null || !link.block().hasPower || tile.team() != link.team()) return false;
|
||||
public boolean linkValid(Tilec tile, Tilec link, boolean checkMaxNodes){
|
||||
if(tile == link || link == null || !link.block().hasPower || tile.team() != link.team()) return false;
|
||||
|
||||
if(overlaps(tile, link, laserRange * tilesize) || (link.block() instanceof PowerNode && overlaps(link, tile, link.<PowerNode>cblock().laserRange * tilesize))){
|
||||
if(checkMaxNodes && link.block() instanceof PowerNode){
|
||||
@@ -369,8 +369,8 @@ public class PowerNode extends PowerBlock{
|
||||
Draw.color();
|
||||
}
|
||||
|
||||
public static boolean insulated(Tile tile, Tile other){
|
||||
return insulated(tile.x, tile.y, other.x, other.y);
|
||||
public static boolean insulated(Tilec tile, Tilec other){
|
||||
return insulated(tile.tileX(), tile.tileY(), other.tileX(), other.tileY());
|
||||
}
|
||||
|
||||
public static boolean insulated(int x, int y, int x2, int y2){
|
||||
|
||||
@@ -59,8 +59,8 @@ public class GenericCrafter extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldIdleSound(Tile tile){
|
||||
return tile.entity.cons().valid();
|
||||
public boolean shouldIdleSound(Tilec tile){
|
||||
return tile.cons().valid();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -59,14 +59,14 @@ public class Incinerator extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleItem(Item item, Tile tile, Tile source){
|
||||
public void handleItem(Tile tile, Tile source, Item item){
|
||||
if(Mathf.chance(0.3)){
|
||||
effect.at(tile.drawx(), tile.drawy());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
public boolean acceptItem(Tile tile, Tile source, Item item){
|
||||
IncineratorEntity entity = tile.ent();
|
||||
return entity.heat > 0.5f;
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ public class ItemSource extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
public boolean acceptItem(Tile tile, Tile source, Item item){
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,11 +12,11 @@ public class ItemVoid extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleItem(Item item, Tile tile, Tile source){
|
||||
public void handleItem(Tile tile, Tile source, Item item){
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
public boolean acceptItem(Tile tile, Tile source, Item item){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ public class CoreBlock extends StorageBlock{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
public boolean acceptItem(Tile tile, Tile source, Item item){
|
||||
return tile.entity.items().get(item) < getMaximumAccepted(tile, item);
|
||||
}
|
||||
|
||||
@@ -191,9 +191,9 @@ public class CoreBlock extends StorageBlock{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleItem(Item item, Tile tile, Tile source){
|
||||
public void handleItem(Tile tile, Tile source, Item item){
|
||||
if(net.server() || !net.active()){
|
||||
super.handleItem(item, tile, source);
|
||||
super.handleItem(tile, source, item);
|
||||
if(state.rules.tutorial){
|
||||
Events.fire(new CoreItemDeliverEvent());
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public class LaunchPad extends StorageBlock{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
public boolean acceptItem(Tile tile, Tile source, Item item){
|
||||
return item.type == ItemType.material && tile.entity.items().total() < itemCapacity;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,9 +15,9 @@ public abstract class StorageBlock extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptItem(Item item, Tile tile, Tile source){
|
||||
public boolean acceptItem(Tile tile, Tile source, Item item){
|
||||
StorageBlockEntity entity = tile.ent();
|
||||
return entity.linkedCore != null ? entity.linkedCore.block().acceptItem(item, entity.linkedCore, source) : tile.entity.items().get(item) < getMaximumAccepted(tile, item);
|
||||
return entity.linkedCore != null ? entity.linkedCore.block().acceptItem(entity.linkedCore, source, item) : tile.entity.items().get(item) < getMaximumAccepted(tile, item);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user