This commit is contained in:
Anuken
2021-07-15 20:08:05 -04:00
parent 3f7dc66ac0
commit b0d4607798
4 changed files with 13 additions and 8 deletions
+9 -4
View File
@@ -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.