Fixed #5588
This commit is contained in:
@@ -19,6 +19,7 @@ public class BuilderAI extends AIController{
|
|||||||
@Nullable Unit following;
|
@Nullable Unit following;
|
||||||
@Nullable Teamc enemy;
|
@Nullable Teamc enemy;
|
||||||
float retreatTimer;
|
float retreatTimer;
|
||||||
|
@Nullable BlockPlan lastPlan;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateMovement(){
|
public void updateMovement(){
|
||||||
@@ -43,6 +44,7 @@ public class BuilderAI extends AIController{
|
|||||||
//set to follower's first build plan, whatever that is
|
//set to follower's first build plan, whatever that is
|
||||||
unit.plans.clear();
|
unit.plans.clear();
|
||||||
unit.plans.addFirst(following.buildPlan());
|
unit.plans.addFirst(following.buildPlan());
|
||||||
|
lastPlan = null;
|
||||||
}else if(unit.buildPlan() == null){
|
}else if(unit.buildPlan() == null){
|
||||||
//not following anyone or building
|
//not following anyone or building
|
||||||
if(timer.get(timerTarget4, 40)){
|
if(timer.get(timerTarget4, 40)){
|
||||||
@@ -78,10 +80,11 @@ public class BuilderAI extends AIController{
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean valid =
|
boolean valid =
|
||||||
(req.tile() != null && req.tile().build instanceof ConstructBuild cons && cons.current == req.block) ||
|
!(lastPlan != null && lastPlan.removed) &&
|
||||||
(req.breaking ?
|
((req.tile() != null && req.tile().build instanceof ConstructBuild cons && cons.current == req.block) ||
|
||||||
Build.validBreak(unit.team(), req.x, req.y) :
|
(req.breaking ?
|
||||||
Build.validPlace(req.block, unit.team(), req.x, req.y, req.rotation));
|
Build.validBreak(unit.team(), req.x, req.y) :
|
||||||
|
Build.validPlace(req.block, unit.team(), req.x, req.y, req.rotation)));
|
||||||
|
|
||||||
if(valid){
|
if(valid){
|
||||||
//move toward the request
|
//move toward the request
|
||||||
@@ -89,6 +92,7 @@ public class BuilderAI extends AIController{
|
|||||||
}else{
|
}else{
|
||||||
//discard invalid request
|
//discard invalid request
|
||||||
unit.plans.removeFirst();
|
unit.plans.removeFirst();
|
||||||
|
lastPlan = null;
|
||||||
}
|
}
|
||||||
}else{
|
}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){
|
if(world.tile(block.x, block.y) != null && world.tile(block.x, block.y).block().id == block.block){
|
||||||
blocks.removeFirst();
|
blocks.removeFirst();
|
||||||
}else if(Build.validPlace(content.block(block.block), unit.team(), block.x, block.y, block.rotation)){ //it's valid.
|
}else if(Build.validPlace(content.block(block.block), unit.team(), block.x, block.y, block.rotation)){ //it's valid.
|
||||||
|
lastPlan = block;
|
||||||
//add build request.
|
//add build request.
|
||||||
unit.addBuild(new BuildPlan(block.x, block.y, block.rotation, content.block(block.block), block.config));
|
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.
|
//shift build plan to tail so next unit builds something else.
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ public class Logic implements ApplicationListener{
|
|||||||
BlockPlan b = it.next();
|
BlockPlan b = it.next();
|
||||||
Block block = content.block(b.block);
|
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))){
|
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();
|
it.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -320,6 +320,7 @@ public class Teams{
|
|||||||
public static class BlockPlan{
|
public static class BlockPlan{
|
||||||
public final short x, y, rotation, block;
|
public final short x, y, rotation, block;
|
||||||
public final Object config;
|
public final Object config;
|
||||||
|
public boolean removed;
|
||||||
|
|
||||||
public BlockPlan(int x, int y, short rotation, short block, Object config){
|
public BlockPlan(int x, int y, short rotation, short block, Object config){
|
||||||
this.x = (short)x;
|
this.x = (short)x;
|
||||||
|
|||||||
@@ -145,6 +145,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||||||
|
|
||||||
for(int pos : positions){
|
for(int pos : positions){
|
||||||
if(req.x == Point2.x(pos) && req.y == Point2.y(pos)){
|
if(req.x == Point2.x(pos) && req.y == Point2.y(pos)){
|
||||||
|
req.removed = true;
|
||||||
it.remove();
|
it.remove();
|
||||||
continue outer;
|
continue outer;
|
||||||
}
|
}
|
||||||
@@ -887,13 +888,10 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||||||
removed.clear();
|
removed.clear();
|
||||||
|
|
||||||
//remove blocks to rebuild
|
//remove blocks to rebuild
|
||||||
Iterator<BlockPlan> broken = player.team().data().blocks.iterator();
|
for(BlockPlan req : player.team().data().blocks){
|
||||||
while(broken.hasNext()){
|
|
||||||
BlockPlan req = broken.next();
|
|
||||||
Block block = content.block(req.block);
|
Block block = content.block(req.block);
|
||||||
if(block.bounds(req.x, req.y, Tmp.r2).overlaps(Tmp.r1)){
|
if(block.bounds(req.x, req.y, Tmp.r2).overlaps(Tmp.r1)){
|
||||||
removed.add(Point2.pack(req.x, req.y));
|
removed.add(Point2.pack(req.x, req.y));
|
||||||
broken.remove();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user