Proper path cost support
This commit is contained in:
@@ -992,8 +992,8 @@ public class HierarchyPathFinder implements Runnable{
|
||||
return ControlPathfinder.costTypes.get(costId);
|
||||
}
|
||||
|
||||
public boolean getPathPosition(Unit unit, int pathId, Vec2 destination, Vec2 mainDestination, Vec2 out, @Nullable boolean[] noResultFound){
|
||||
int costId = 0;
|
||||
public boolean getPathPosition(Unit unit, Vec2 destination, Vec2 mainDestination, Vec2 out, @Nullable boolean[] noResultFound){
|
||||
int costId = unit.type.pathCostId;
|
||||
PathCost cost = idToCost(costId);
|
||||
|
||||
int
|
||||
@@ -1006,6 +1006,7 @@ public class HierarchyPathFinder implements Runnable{
|
||||
actualDestY = World.toTile(destination.y),
|
||||
destPos = destX + destY * wwidth;
|
||||
|
||||
//TODO: what if the destination is different...?
|
||||
PathRequest request = unitRequests.get(unit);
|
||||
|
||||
//if the destination can be trivially reached in a straight line, do that.
|
||||
|
||||
@@ -248,7 +248,7 @@ public class CommandAI extends AIController{
|
||||
}
|
||||
|
||||
//if you've spent 3 seconds stuck, something is wrong, move regardless
|
||||
move = hpath.getPathPosition(unit, pathId, vecMovePos, targetPos, vecOut, noFound) && (!blockingUnit || timeSpentBlocked > maxBlockTime);
|
||||
move = hpath.getPathPosition(unit, vecMovePos, targetPos, vecOut, noFound) && (!blockingUnit || timeSpentBlocked > maxBlockTime);
|
||||
//we've reached the final point if the returned coordinate is equal to the supplied input
|
||||
isFinalPoint &= vecMovePos.epsilonEquals(vecOut, 4.1f);
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ public class LogicAI extends AIController{
|
||||
if(unit.isFlying()){
|
||||
moveTo(Tmp.v1.set(moveX, moveY), 1f, 30f);
|
||||
}else{
|
||||
if(hpath.getPathPosition(unit, lastPathId, Tmp.v2.set(moveX, moveY), Tmp.v2, Tmp.v1, null)){
|
||||
if(hpath.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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -403,7 +403,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;
|
||||
}
|
||||
|
||||
@@ -286,6 +286,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;
|
||||
|
||||
@@ -689,6 +691,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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user