Pathfind command

This commit is contained in:
Anuken
2020-10-05 17:09:27 -04:00
parent c24112e405
commit efbc871967
8 changed files with 58 additions and 20 deletions

View File

@@ -34,14 +34,14 @@ public class GroundAI extends AIController{
if(spawner != null && unit.within(spawner, state.rules.dropZoneRadius + 120f)) move = false;
}
if(move) moveTo(Pathfinder.fieldCore);
if(move) pathfind(Pathfinder.fieldCore);
}
if(command() == UnitCommand.rally){
Teamc target = targetFlag(unit.x, unit.y, BlockFlag.rally, false);
if(target != null && !unit.within(target, 70f)){
moveTo(Pathfinder.fieldRally);
pathfind(Pathfinder.fieldRally);
}
}
@@ -72,16 +72,4 @@ public class GroundAI extends AIController{
}
}*/
}
protected void moveTo(int pathTarget){
int costType = unit.pathType();
Tile tile = unit.tileOn();
if(tile == null) return;
Tile targetTile = pathfinder.getTargetTile(tile, pathfinder.getField(unit.team, costType, pathTarget));
if(tile == targetTile || (costType == Pathfinder.costWater && !targetTile.floor().isLiquid)) return;
unit.moveAt(vec.trns(unit.angleTo(targetTile), unit.type().speed));
}
}

View File

@@ -2,20 +2,26 @@ package mindustry.ai.types;
import arc.struct.*;
import arc.util.*;
import mindustry.ai.*;
import mindustry.entities.units.*;
import mindustry.gen.*;
import mindustry.logic.LExecutor.*;
import mindustry.logic.*;
import mindustry.world.*;
import mindustry.world.meta.*;
import static mindustry.Vars.*;
public class LogicAI extends AIController{
/** Minimum delay between item transfers. */
public static final float transferDelay = 60f * 2f;
/** Time after which the unit resets its controlled and reverts to a normal unit. */
public static final float logicControlTimeout = 15f * 60f;
public static final float logicControlTimeout = 10f * 60f;
public LUnitControl control = LUnitControl.stop;
public float moveX, moveY, moveRad;
public float itemTimer, controlTimer = logicControlTimeout, targetTimer;
public Building controller;
//type of aiming to use
public LUnitControl aimControl = LUnitControl.stop;
@@ -43,7 +49,7 @@ public class LogicAI extends AIController{
}
//timeout when not controlled by logic for a while
if(controlTimer > 0){
if(controlTimer > 0 && controller != null && controller.isValid()){
controlTimer -= Time.delta;
}else{
unit.resetController();
@@ -57,6 +63,28 @@ public class LogicAI extends AIController{
case approach -> {
moveTo(Tmp.v1.set(moveX, moveY), moveRad, 10f);
}
case pathfind -> {
Building core = unit.closestEnemyCore();
if((core == null || !unit.within(core, unit.range() * 0.5f)) && command() == UnitCommand.attack){
boolean move = true;
if(state.rules.waves && unit.team == state.rules.defaultTeam){
Tile spawner = getClosestSpawner();
if(spawner != null && unit.within(spawner, state.rules.dropZoneRadius + 120f)) move = false;
}
if(move) pathfind(Pathfinder.fieldCore);
}
if(command() == UnitCommand.rally){
Teamc target = targetFlag(unit.x, unit.y, BlockFlag.rally, false);
if(target != null && !unit.within(target, 70f)){
pathfind(Pathfinder.fieldRally);
}
}
}
}
//look where moving if there's nothing to aim at

View File

@@ -67,10 +67,10 @@ public class SuicideAI extends GroundAI{
Teamc target = targetFlag(unit.x, unit.y, BlockFlag.rally, false);
if(target != null && !unit.within(target, 70f)){
moveTo(Pathfinder.fieldRally);
pathfind(Pathfinder.fieldRally);
}
}else if(command() == UnitCommand.attack && core != null){
moveTo(Pathfinder.fieldCore);
pathfind(Pathfinder.fieldCore);
}
if(unit.moving()) unit.lookAt(unit.vel().angle());