From b0d460779858ac50e9063f71c1f295e7ab411b74 Mon Sep 17 00:00:00 2001 From: Anuken Date: Thu, 15 Jul 2021 20:08:05 -0400 Subject: [PATCH] Fixed #5588 --- core/src/mindustry/ai/types/BuilderAI.java | 13 +++++++++---- core/src/mindustry/core/Logic.java | 1 + core/src/mindustry/game/Teams.java | 1 + core/src/mindustry/input/InputHandler.java | 6 ++---- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/core/src/mindustry/ai/types/BuilderAI.java b/core/src/mindustry/ai/types/BuilderAI.java index 5a3c5b00f8..3f171df120 100644 --- a/core/src/mindustry/ai/types/BuilderAI.java +++ b/core/src/mindustry/ai/types/BuilderAI.java @@ -19,6 +19,7 @@ public class BuilderAI extends AIController{ @Nullable Unit following; @Nullable Teamc enemy; float retreatTimer; + @Nullable BlockPlan lastPlan; @Override public void updateMovement(){ @@ -43,6 +44,7 @@ public class BuilderAI extends AIController{ //set to follower's first build plan, whatever that is unit.plans.clear(); unit.plans.addFirst(following.buildPlan()); + lastPlan = null; }else if(unit.buildPlan() == null){ //not following anyone or building if(timer.get(timerTarget4, 40)){ @@ -78,10 +80,11 @@ public class BuilderAI extends AIController{ } boolean valid = - (req.tile() != null && req.tile().build instanceof ConstructBuild cons && cons.current == req.block) || - (req.breaking ? - Build.validBreak(unit.team(), req.x, req.y) : - Build.validPlace(req.block, unit.team(), req.x, req.y, req.rotation)); + !(lastPlan != null && lastPlan.removed) && + ((req.tile() != null && req.tile().build instanceof ConstructBuild cons && cons.current == req.block) || + (req.breaking ? + Build.validBreak(unit.team(), req.x, req.y) : + Build.validPlace(req.block, unit.team(), req.x, req.y, req.rotation))); if(valid){ //move toward the request @@ -89,6 +92,7 @@ public class BuilderAI extends AIController{ }else{ //discard invalid request unit.plans.removeFirst(); + lastPlan = null; } }else{ @@ -127,6 +131,7 @@ public class BuilderAI extends AIController{ if(world.tile(block.x, block.y) != null && world.tile(block.x, block.y).block().id == block.block){ blocks.removeFirst(); }else if(Build.validPlace(content.block(block.block), unit.team(), block.x, block.y, block.rotation)){ //it's valid. + lastPlan = block; //add build request. unit.addBuild(new BuildPlan(block.x, block.y, block.rotation, content.block(block.block), block.config)); //shift build plan to tail so next unit builds something else. diff --git a/core/src/mindustry/core/Logic.java b/core/src/mindustry/core/Logic.java index 96de35d5e7..b9ddb2cef9 100644 --- a/core/src/mindustry/core/Logic.java +++ b/core/src/mindustry/core/Logic.java @@ -49,6 +49,7 @@ public class Logic implements ApplicationListener{ BlockPlan b = it.next(); Block block = content.block(b.block); if(event.tile.block().bounds(event.tile.x, event.tile.y, Tmp.r1).overlaps(block.bounds(b.x, b.y, Tmp.r2))){ + b.removed = true; it.remove(); } } diff --git a/core/src/mindustry/game/Teams.java b/core/src/mindustry/game/Teams.java index 2fb9c23f69..9d73661ef5 100644 --- a/core/src/mindustry/game/Teams.java +++ b/core/src/mindustry/game/Teams.java @@ -320,6 +320,7 @@ public class Teams{ public static class BlockPlan{ public final short x, y, rotation, block; public final Object config; + public boolean removed; public BlockPlan(int x, int y, short rotation, short block, Object config){ this.x = (short)x; diff --git a/core/src/mindustry/input/InputHandler.java b/core/src/mindustry/input/InputHandler.java index e0f2b88116..0c9c2fc1a6 100644 --- a/core/src/mindustry/input/InputHandler.java +++ b/core/src/mindustry/input/InputHandler.java @@ -145,6 +145,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{ for(int pos : positions){ if(req.x == Point2.x(pos) && req.y == Point2.y(pos)){ + req.removed = true; it.remove(); continue outer; } @@ -887,13 +888,10 @@ public abstract class InputHandler implements InputProcessor, GestureListener{ removed.clear(); //remove blocks to rebuild - Iterator broken = player.team().data().blocks.iterator(); - while(broken.hasNext()){ - BlockPlan req = broken.next(); + for(BlockPlan req : player.team().data().blocks){ Block block = content.block(req.block); if(block.bounds(req.x, req.y, Tmp.r2).overlaps(Tmp.r1)){ removed.add(Point2.pack(req.x, req.y)); - broken.remove(); } }