Anuken / Mindustry

The automation tower defense RTS
https://mindustrygame.github.io
GNU General Public License v3.0
22.72k stars 2.98k forks source link

AI Targeting #1372

Closed CaribbeanMax closed 4 years ago

CaribbeanMax commented 4 years ago

Platform: Mac

Build: Steam 102.3

Issue: Target priorization is even more messed up now. Even without blocks from different priority groups in range, the AI will now almost always aim at the last block scanned by findTile in BlockIndexer.java.

AItargeting

Steps to reproduce: See picture.

Suggestion: I am not going to make a PR for this myself because i can't test the change right now. build 101 original in findTile BlockIndexer.java:

if(ndst < range && (closest == null || ndst < dst || (usePriority && closest.block.priority.ordinal() < e.block.priority.ordinal()))){
    dst = ndst;
    closest = e;
}

what i did propose as a fix via discord back then:

if(ndst < range && (closest == null || (ndst < dst && (!usePriority || closest.block.priority.ordinal() <= e.block.priority.ordinal())))){
    dst = ndst;
    closest = e;
}

what got changed from v101 to 102 instead:

if(ndst < range && (closest == null || ndst < dst || (usePriority && closest.block.priority.ordinal() <= e.block.priority.ordinal()))){
    dst = ndst;
    closest = e;
}

So just the "<" -> "<=" happened and none of the other minor tweaks to the logic.

Anuken commented 4 years ago

I've taken a proper look at this now (without blindly changing things), and your solution isn't completely correct either. The targeting needs to prefer blocks with higher priority, even if they are further away.

Incorrect (wall is found first, and since the ndst < dst condition is not met for the turret, it is not targeted) image

Correct (turret priority is checked against wall, and picked due to higher priority) image