mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-03-09 20:29:06 +07:00
Fixed #5588
This commit is contained in:
parent
3f7dc66ac0
commit
b0d4607798
@ -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.
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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<BlockPlan> 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();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user