From b672d79dd7fa6e3f01e946d9b765cf109ef9ef29 Mon Sep 17 00:00:00 2001 From: Anuken Date: Wed, 29 Jul 2020 13:22:13 -0400 Subject: [PATCH] Door chaining / p l a s t a n i u m b l e n d i n g --- .../mindustry/world/blocks/defense/Door.java | 55 +++++++++++++++++-- .../blocks/distribution/StackConveyor.java | 6 +- 2 files changed, 53 insertions(+), 8 deletions(-) diff --git a/core/src/mindustry/world/blocks/defense/Door.java b/core/src/mindustry/world/blocks/defense/Door.java index 705cd1c9aa..af36af68bf 100644 --- a/core/src/mindustry/world/blocks/defense/Door.java +++ b/core/src/mindustry/world/blocks/defense/Door.java @@ -4,6 +4,7 @@ import arc.Graphics.*; import arc.Graphics.Cursor.*; import arc.graphics.g2d.*; import arc.math.geom.*; +import arc.struct.*; import arc.util.*; import arc.util.io.*; import mindustry.annotations.Annotations.*; @@ -12,7 +13,7 @@ import mindustry.entities.*; import mindustry.entities.units.*; import mindustry.gen.*; -import static mindustry.Vars.pathfinder; +import static mindustry.Vars.*; public class Door extends Wall{ protected final static Rect rect = new Rect(); @@ -28,11 +29,14 @@ public class Door extends Wall{ solidifes = true; consumesTap = true; - config(Boolean.class, (DoorEntity entity, Boolean open) -> { - entity.open = open; - pathfinder.updateTile(entity.tile()); - (open ? closefx : openfx).at(entity); - Sounds.door.at(entity); + config(Boolean.class, (DoorEntity base, Boolean open) -> { + Sounds.door.at(base); + + for(DoorEntity entity : base.chained){ + entity.open = open; + pathfinder.updateTile(entity.tile()); + entity.effect(); + } }); } @@ -43,6 +47,45 @@ public class Door extends Wall{ public class DoorEntity extends Building{ public boolean open = false; + public ObjectSet chained = new ObjectSet<>(); + + @Override + public void onProximityAdded(){ + super.onProximityAdded(); + updateChained(); + } + + @Override + public void onProximityRemoved(){ + super.onProximityRemoved(); + + for(Building b : proximity){ + if(b instanceof DoorEntity){ + ((DoorEntity)b).updateChained(); + } + } + } + + public void effect(){ + (open ? closefx : openfx).at(this); + } + + public void updateChained(){ + chained = new ObjectSet<>(); + flow(chained); + } + + public void flow(ObjectSet set){ + if(!set.add(this)) return; + + this.chained = set; + + for(Building b : proximity){ + if(b instanceof DoorEntity){ + ((DoorEntity)b).flow(set); + } + } + } @Override public void draw(){ diff --git a/core/src/mindustry/world/blocks/distribution/StackConveyor.java b/core/src/mindustry/world/blocks/distribution/StackConveyor.java index 41b535db0e..4a09a3966b 100644 --- a/core/src/mindustry/world/blocks/distribution/StackConveyor.java +++ b/core/src/mindustry/world/blocks/distribution/StackConveyor.java @@ -57,10 +57,12 @@ public class StackConveyor extends Block implements Autotiler{ if(state == stateLoad){ //standard conveyor mode return otherblock.outputsItems() && lookingAtEither(tile, rotation, otherx, othery, otherrot, otherblock); }else if(state == stateUnload){ //router mode - return (otherblock.acceptsItems) && + return otherblock.acceptsItems && (notLookingAt(tile, rotation, otherx, othery, otherrot, otherblock) || (otherblock instanceof StackConveyor && facing(otherx, othery, otherrot, tile.x, tile.y))) && - !(world.build(otherx, othery) instanceof StackConveyorEntity && ((StackConveyorEntity)world.build(otherx, othery)).state == stateUnload); + !(world.build(otherx, othery) instanceof StackConveyorEntity && ((StackConveyorEntity)world.build(otherx, othery)).state == stateUnload) && + !(world.build(otherx, othery) instanceof StackConveyorEntity && ((StackConveyorEntity)world.build(otherx, othery)).state == stateMove && + !facing(otherx, othery, otherrot, tile.x, tile.y)); } } return otherblock.outputsItems() && blendsArmored(tile, rotation, otherx, othery, otherrot, otherblock) && otherblock instanceof StackConveyor;