mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-01-05 21:10:53 +07:00
Merge branch 'new-pathfinding' of https://github.com/Anuken/Mindustry
This commit is contained in:
commit
32957b63b9
File diff suppressed because it is too large
Load Diff
@ -77,6 +77,7 @@ public class RtsAI{
|
||||
}
|
||||
|
||||
public void update(){
|
||||
|
||||
if(timer.get(timeUpdate, 60f * 2f)){
|
||||
assignSquads();
|
||||
checkBuilding();
|
||||
|
@ -4,7 +4,6 @@ import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import mindustry.*;
|
||||
import mindustry.ai.*;
|
||||
import mindustry.core.*;
|
||||
import mindustry.entities.*;
|
||||
@ -35,7 +34,6 @@ public class CommandAI extends AIController{
|
||||
|
||||
protected boolean stopAtTarget, stopWhenInRange;
|
||||
protected Vec2 lastTargetPos;
|
||||
protected int pathId = -1;
|
||||
protected boolean blockingUnit;
|
||||
protected float timeSpentBlocked;
|
||||
|
||||
@ -205,6 +203,8 @@ public class CommandAI extends AIController{
|
||||
}
|
||||
}
|
||||
|
||||
boolean alwaysArrive = false;
|
||||
|
||||
if(targetPos != null){
|
||||
boolean move = true, isFinalPoint = commandQueue.size == 0;
|
||||
vecOut.set(targetPos);
|
||||
@ -221,6 +221,7 @@ public class CommandAI extends AIController{
|
||||
}
|
||||
|
||||
if(unit.isGrounded() && stance != UnitStance.ram){
|
||||
//TODO: blocking enable or disable?
|
||||
if(timer.get(timerTarget3, avoidInterval)){
|
||||
Vec2 dstPos = Tmp.v1.trns(unit.rotation, unit.hitSize/2f);
|
||||
float max = unit.hitSize/2f;
|
||||
@ -248,8 +249,9 @@ public class CommandAI extends AIController{
|
||||
timeSpentBlocked = 0f;
|
||||
}
|
||||
|
||||
//if you've spent 3 seconds stuck, something is wrong, move regardless
|
||||
move = Vars.controlPath.getPathPosition(unit, pathId, vecMovePos, vecOut, noFound) && (!blockingUnit || timeSpentBlocked > maxBlockTime);
|
||||
move = controlPath.getPathPosition(unit, vecMovePos, targetPos, vecOut, noFound) && (!blockingUnit || timeSpentBlocked > maxBlockTime);
|
||||
//rare case where unit must be perfectly aligned (happens with 1-tile gaps)
|
||||
alwaysArrive = vecOut.epsilonEquals(unit.tileX() * tilesize, unit.tileY() * tilesize);
|
||||
//we've reached the final point if the returned coordinate is equal to the supplied input
|
||||
isFinalPoint &= vecMovePos.epsilonEquals(vecOut, 4.1f);
|
||||
|
||||
@ -277,7 +279,7 @@ public class CommandAI extends AIController{
|
||||
attackTarget != null && unit.within(attackTarget, engageRange) && stance != UnitStance.ram ? engageRange :
|
||||
unit.isGrounded() ? 0f :
|
||||
attackTarget != null && stance != UnitStance.ram ? engageRange :
|
||||
0f, unit.isFlying() ? 40f : 100f, false, null, isFinalPoint);
|
||||
0f, unit.isFlying() ? 40f : 100f, false, null, isFinalPoint || alwaysArrive);
|
||||
}
|
||||
}
|
||||
|
||||
@ -417,7 +419,6 @@ public class CommandAI extends AIController{
|
||||
//this is an allocation, but it's relatively rarely called anyway, and outside mutations must be prevented
|
||||
targetPos = lastTargetPos = pos.cpy();
|
||||
attackTarget = null;
|
||||
pathId = Vars.controlPath.nextTargetId();
|
||||
this.stopWhenInRange = stopWhenInRange;
|
||||
}
|
||||
|
||||
@ -432,7 +433,6 @@ public class CommandAI extends AIController{
|
||||
public void commandTarget(Teamc moveTo, boolean stopAtTarget){
|
||||
attackTarget = moveTo;
|
||||
this.stopAtTarget = stopAtTarget;
|
||||
pathId = Vars.controlPath.nextTargetId();
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -3,7 +3,6 @@ package mindustry.ai.types;
|
||||
import arc.math.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import mindustry.*;
|
||||
import mindustry.ai.*;
|
||||
import mindustry.entities.units.*;
|
||||
import mindustry.gen.*;
|
||||
@ -86,7 +85,7 @@ public class LogicAI extends AIController{
|
||||
if(unit.isFlying()){
|
||||
moveTo(Tmp.v1.set(moveX, moveY), 1f, 30f);
|
||||
}else{
|
||||
if(Vars.controlPath.getPathPosition(unit, lastPathId, Tmp.v2.set(moveX, moveY), Tmp.v1, null)){
|
||||
if(controlPath.getPathPosition(unit, Tmp.v2.set(moveX, moveY), Tmp.v2, Tmp.v1, null)){
|
||||
moveTo(Tmp.v1, 1f, Tmp.v2.epsilonEquals(Tmp.v1, 4.1f) ? 30f : 0f);
|
||||
}
|
||||
}
|
||||
|
@ -2584,7 +2584,7 @@ public class Fx{
|
||||
if(!(e.data instanceof Vec2[] vec)) return;
|
||||
|
||||
Draw.color(e.color);
|
||||
Lines.stroke(1f);
|
||||
Lines.stroke(2f);
|
||||
|
||||
if(vec.length == 2){
|
||||
Lines.line(vec[0].x, vec[0].y, vec[1].x, vec[1].y);
|
||||
@ -2596,5 +2596,15 @@ public class Fx{
|
||||
}
|
||||
|
||||
Draw.reset();
|
||||
}),
|
||||
debugRect = new Effect(90f, 1000000000000f, e -> {
|
||||
if(!(e.data instanceof Rect rect)) return;
|
||||
|
||||
Draw.color(e.color);
|
||||
Lines.stroke(2f);
|
||||
|
||||
Lines.rect(rect);
|
||||
|
||||
Draw.reset();
|
||||
});
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ abstract class HitboxComp implements Posc, Sized, QuadTreeObject{
|
||||
|
||||
public void hitboxTile(Rect rect){
|
||||
//tile hitboxes are never bigger than a tile, otherwise units get stuck
|
||||
float size = Math.min(hitSize * 0.66f, 7.9f);
|
||||
float size = Math.min(hitSize * 0.66f, 7.8f);
|
||||
//TODO: better / more accurate version is
|
||||
//float size = hitSize * 0.85f;
|
||||
//- for tanks?
|
||||
|
@ -51,7 +51,7 @@ abstract class TankComp implements Posc, Flyingc, Hitboxc, Unitc, ElevationMovec
|
||||
}
|
||||
|
||||
//calculate overlapping tiles so it slows down when going "over" walls
|
||||
int r = Math.max(Math.round(hitSize * 0.6f / tilesize), 1);
|
||||
int r = Math.max((int)(hitSize * 0.6f / tilesize), 0);
|
||||
|
||||
int solids = 0, total = (r*2+1)*(r*2+1);
|
||||
for(int dx = -r; dx <= r; dx++){
|
||||
|
@ -402,7 +402,7 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
|
||||
return type.allowLegStep && type.legPhysicsLayer ? PhysicsProcess.layerLegs : isGrounded() ? PhysicsProcess.layerGround : PhysicsProcess.layerFlying;
|
||||
}
|
||||
|
||||
/** @return pathfinder path type for calculating costs */
|
||||
/** @return pathfinder path type for calculating costs. This is used for wave AI only. (TODO: remove) */
|
||||
public int pathType(){
|
||||
return Pathfinder.costGround;
|
||||
}
|
||||
|
@ -341,7 +341,7 @@ public class AIController implements UnitController{
|
||||
vec.setLength(speed * length);
|
||||
}
|
||||
|
||||
//do not move when infinite vectors are used or if its zero.
|
||||
//ignore invalid movement values
|
||||
if(vec.isNaN() || vec.isInfinite() || vec.isZero()) return;
|
||||
|
||||
if(!unit.type.omniMovement && unit.type.rotateMoveFirst){
|
||||
|
@ -288,6 +288,8 @@ public class UnitType extends UnlockableContent implements Senseable{
|
||||
|
||||
/** Function used for calculating cost of moving with ControlPathfinder. Does not affect "normal" flow field pathfinding. */
|
||||
public @Nullable PathCost pathCost;
|
||||
/** ID for path cost, to be used in the control path finder. This is the value that actually matters; do not assign manually. Set in init(). */
|
||||
public int pathCostId;
|
||||
/** A sample of the unit that this type creates. Do not modify! */
|
||||
public @Nullable Unit sample;
|
||||
|
||||
@ -693,6 +695,9 @@ public class UnitType extends UnlockableContent implements Senseable{
|
||||
ControlPathfinder.costGround;
|
||||
}
|
||||
|
||||
pathCostId = ControlPathfinder.costTypes.indexOf(pathCost);
|
||||
if(pathCostId == -1) pathCostId = 0;
|
||||
|
||||
if(flying){
|
||||
envEnabled |= Env.space;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user