From 7557a57266778043b680f48e555ed0e2e51bc093 Mon Sep 17 00:00:00 2001 From: Anuken Date: Wed, 28 Sep 2022 21:07:04 -0400 Subject: [PATCH] Experimental changes to make RTS AI "smarter" --- core/src/mindustry/ai/RtsAI.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/core/src/mindustry/ai/RtsAI.java b/core/src/mindustry/ai/RtsAI.java index 8e20579158..778af14657 100644 --- a/core/src/mindustry/ai/RtsAI.java +++ b/core/src/mindustry/ai/RtsAI.java @@ -113,7 +113,7 @@ public class RtsAI{ squad.truncate(data.team.rules().rtsMaxSquad); //remove overlapping squads - squad.removeAll(u -> (u != unit && used.contains(u.id)) || !u.isCommandable() || u.command().hasCommand()); + squad.removeAll(u -> (u != unit && used.contains(u.id)) || !u.isCommandable() || u.command().hasCommand() || ((u.flag == 0) != (unit.flag == 0))); //mark used so other squads can't steal them for(var item : squad){ used.add(item.id); @@ -174,7 +174,7 @@ public class RtsAI{ //defend when close, or this is the only squad defending //TODO will always rush to defense no matter what - if(best != null && (best instanceof CoreBuild || units.size >= data.team.rules().rtsMinSquad || best.within(ax, ay, 500f))){ + if(best != null && (best instanceof CoreBuild || (units.size >= data.team.rules().rtsMinSquad || (units.size > 0 && units.first().flag != 0)) || best.within(ax, ay, 500f))){ defend = best; if(debug){ @@ -194,7 +194,9 @@ public class RtsAI{ //TODO could be made faster by storing bullet shooter Unit aggressor = Units.closestEnemy(data.team, defend.x, defend.y, checkRange, u -> u.checkTarget(tair, tground)); if(aggressor != null){ - defendTarget = aggressor; + //do not target it directly - target the position? + //defendTarget = aggressor; + defendPos = new Vec2(aggressor.x, aggressor.y); }else if(false){ //TODO currently ignored, no use defending against nothing //should it even go there if there's no aggressor found? Tile closest = defend.findClosestEdge(units.first(), Tile::solid); @@ -234,6 +236,8 @@ public class RtsAI{ }else{ //TODO stopAtTarget parameter could be false, could be tweaked unit.command().commandTarget(defendTarget == null ? build : defendTarget, defendTarget != null); + //assign a flag, so it will be "mobilized" more easily later + unit.flag = 1; } } }