Skip to content

Commit

Permalink
AI fixed earlier, now time to change it slightly.
Browse files Browse the repository at this point in the history
  • Loading branch information
Slotterleet committed Jan 19, 2025
1 parent 70c3a80 commit 166095f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/fos/ai/FOSPathfinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ protected void getPositions(IntSeq out) {
var added = false;
for (var f : flags) {
for (Building other : indexer.getEnemy(team, f)) {
if (other.efficiency < 0.5f) continue;
out.add(other.tile.array());
added = true;
}
Expand Down
8 changes: 4 additions & 4 deletions src/fos/ai/bugs/BugAI.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,9 @@ public void updateMovement() {

if (targetTile == tile) return;

if (!unit.inRange(target))
if (target == null || !unit.inRange(target))
unit.movePref(vec.trns(unit.angleTo(targetTile.worldx(), targetTile.worldy()), unit.speed()));
// NEVER EVER UNCOMMENT THIS. TODO: Why did I even want this?
//unit.lookAt(unit.angleTo(target));
else unit.lookAt(unit.angleTo(target));
}

@Override
Expand All @@ -102,7 +101,8 @@ public Teamc target(float x, float y, float range, boolean air, boolean ground)
for (BlockFlag flag : unit.type.targetFlags) {
Teamc target = null;
if (flag != null) {
target = targetFlag(x, y, flag, true);
var other = (Building) targetFlag(x, y, flag, true);
if (other != null && other.efficiency >= 0.5f) target = other;
}

if (target != null) return target;
Expand Down
11 changes: 7 additions & 4 deletions src/fos/ai/bugs/ScoutBugAI.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import arc.Events;
import arc.math.Mathf;
import arc.struct.Seq;
import arc.util.Reflect;
import fos.core.*;
import arc.util.*;
import fos.core.FOSVars;
import fos.mod.FOSEventTypes;
import mindustry.entities.units.AIController;
import mindustry.game.Team;
Expand All @@ -17,17 +17,20 @@
public class ScoutBugAI extends AIController {
public Tile dest;
public Seq<Building> foundTurrets = new Seq<>();
public float lastCheckedTime = 0f;

@Override
public void updateMovement() {
if (lastCheckedTime == 0f) lastCheckedTime = Time.time;

if (dest == null) {
int x = Mathf.random(world.width()-1);
int y = Mathf.random(world.height()-1);
dest = world.tile(x, y);
}

if (dest == null || isDiscovered(unit.team, dest.x, dest.y) || unit.tileOn() == dest) {
// pick a different not yet discovered tile
// pick an undiscovered tile, or go anywhere if failed to find one within 5 seconds
if (dest == null || (isDiscovered(unit.team, dest.x, dest.y) && Time.time - lastCheckedTime < 300f) || unit.tileOn() == dest) {
dest = null;
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/fos/type/units/types/BugUnitType.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import arc.graphics.Color;
import fos.ai.bugs.*;
import fos.content.*;
import fos.mod.FOSEventTypes;
import fos.gen.Bugc;
import fos.mod.FOSEventTypes;
import mindustry.content.StatusEffects;
import mindustry.gen.*;
import mindustry.world.meta.BlockFlag;
Expand Down Expand Up @@ -34,7 +34,7 @@ public <T extends Unit> BugUnitType(String name, Class<T> type, boolean flying)
targetAir = flying;
targetGround = true;
playerControllable = false;
targetFlags = new BlockFlag[]{BlockFlag.drill, BlockFlag.factory, BlockFlag.core, null};
targetFlags = new BlockFlag[]{BlockFlag.generator, BlockFlag.drill, BlockFlag.factory, BlockFlag.core};
controller = u -> flying ? new FlyingBugAI() : new BugAI();
}
public <T extends Unit> BugUnitType(String name, Class<T> type, boolean flying, boolean melee) {
Expand Down

0 comments on commit 166095f

Please sign in to comment.