Skip to content

Commit

Permalink
Better^2 Insect AI. Smarter and less clunky.
Browse files Browse the repository at this point in the history
  • Loading branch information
Slotterleet committed May 11, 2024
1 parent 302ac36 commit 302fb31
Show file tree
Hide file tree
Showing 12 changed files with 616 additions and 51 deletions.
7 changes: 3 additions & 4 deletions src/fos/ai/BugAI.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import static mindustry.Vars.tilesize;

public class BugAI extends AIController implements TargetableAI {
public class BugAI extends AIController implements FOSPathfindAI {
private Bugc bug;

@Override
Expand Down Expand Up @@ -45,7 +45,6 @@ public void updateUnit() {

@Override
public void updateMovement() {
// FIXME: bugs spinning around for no reason
Tile tile = unit.tileOn();
Tile targetTile = tile;

Expand All @@ -60,7 +59,7 @@ public void updateMovement() {
unit.moveAt(vec);
return;
} else {
targetTile = pathfindTarget(target, unit);
targetTile = pathfind(unit);
}
}
} else if (bug.following() != null) {
Expand All @@ -79,7 +78,7 @@ public void updateMovement() {
int y = Mathf.random(-40, 40);
Tile t = Vars.world.tileWorld(unit.x + x, unit.y + y);
if (t != null && t.block() == Blocks.air) {
targetTile = pathfindTarget(vec.set(unit).add(x*8, y*8), unit);
targetTile = pathfind(unit);
foundTile = true;
bug.idle(true);
}
Expand Down
21 changes: 21 additions & 0 deletions src/fos/ai/FOSPathfindAI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package fos.ai;

import fos.core.FOSVars;
import mindustry.entities.units.AIController;
import mindustry.gen.Unit;
import mindustry.world.Tile;

/**
* An interface for {@link AIController} that supports custom targeting options.
* Utilizes a modified pathfinder.
* @author Slotterleet
*/
public interface FOSPathfindAI {
/** @return next tile to travel to */
default Tile pathfind(Unit unit) {
Tile tile = unit.tileOn();
//TODO: mod conflict is, even though VERY unlikely, still possible
FOSPathfinder.FOSFlowfield ff = FOSVars.pathfinder.getField(unit.team, unit.pathType(), FOSPathfinder.costBugLegs);
return FOSVars.pathfinder.getTargetTile(tile, ff);
}
}
Loading

0 comments on commit 302fb31

Please sign in to comment.