Bug #2509
openAI fails to move settlers when no land to improve available exists
Added by Frostblade metablaster 4 days ago. Updated about 7 hours ago.
0%
Description
AI fails to move settlers, instead holding them all around the map and never moving.
Happens when autoworker finds no land to improve.
Files
| settler.patch (409 Bytes) settler.patch | Frostblade metablaster, 11/28/2026 11:59 PM | ||
| AI_autoworker_idling_settler_if_no_work.patch (389 Bytes) AI_autoworker_idling_settler_if_no_work.patch | Frostblade metablaster, 11/29/2026 12:42 AM | ||
| 0001-AI-Shelter-auto-worker-if-no-tile-to-improve.patch (1.32 KB) 0001-AI-Shelter-auto-worker-if-no-tile-to-improve.patch | Frostblade metablaster, 11/29/2026 02:21 AM | ||
| 0001-AI-Shelter-auto-worker-stuck-in-non-allied-territory.patch (1.78 KB) 0001-AI-Shelter-auto-worker-stuck-in-non-allied-territory.patch | Frostblade metablaster, 11/29/2026 03:58 PM | ||
| 0001-AI-Shelter-auto-worker-stuck-in-non-allied-territory.patch (2 KB) 0001-AI-Shelter-auto-worker-stuck-in-non-allied-territory.patch | Frostblade metablaster, 12/02/2026 04:14 PM |
Updated by Sweet Tea Dorminy 4 days ago
Thanks for the patch! :)))
I don't think this is quite optimal in worker_evaluate_improvements() because that function is just trying to decide the best improvement, not implement it. In particular, it gets used in daicity.c with a virtual unit to decide the benefits of building a worker; and a human autoworker is already getting moved to shelter in auto_worker_findwork().
Instead, maybe let's move this code to the place where the AI is deciding what to do and gives up on doing anything, in ai/default/daisettler.c:dai_auto_settler_run()?
Also, if you had the energy to do it, a commit message helps future readers understand the what/why -- https://cbea.ms/git-commit/ is a fine introduction to writing a good message -- and then git format-patch gets a commit into a nice patch format.
Thanks!!
Updated by Marko Lindqvist 4 days ago
Sweet Tea Dorminy wrote in #note-1:
Also, if you had the energy to do it, a commit message helps future readers understand the what/why -- https://cbea.ms/git-commit/ is a fine introduction to writing a good message -- and then git format-patch gets a commit into a nice patch format.
Freeciv commit message instructions are at https://www.freeciv.org/wiki/Commit_rules#Commit_message
Updated by Frostblade metablaster 4 days ago
- File AI_autoworker_idling_settler_if_no_work.patch AI_autoworker_idling_settler_if_no_work.patch added
Thanks for guiding me, I did as you suggested, tested as well and works fine.
However I can't seem to update ticket title.
Updated by Sweet Tea Dorminy 4 days ago
Nice!
I think there's one more case in the same function to consider: you've dealt with the settler case, but there's also the worker/engineer case further down in the same function. Can you fix that too, the best_tile == nullptr case?
Updated by Frostblade metablaster 4 days ago
- File 0001-AI-Shelter-auto-worker-if-no-tile-to-improve.patch 0001-AI-Shelter-auto-worker-if-no-tile-to-improve.patch added
OK, that's done and the new patch is properly formatted. (other 2 patches can be deleted)
Thanks again for patience and help.
Updated by Sweet Tea Dorminy 4 days ago
Awesome! Code-wise, this looks fine to me.
I would propose the following commit improvements:
1) Use a real email address for authorship? Maybe a name too?
2) Commit message. Something like:
Currently, when an AI settler/worker decides to do something different with its life than previously planned, and finds itself in the middle of 'enemy' territory, it gets stuck. Every tile in non-allied territory is considered impassible for the purpose of pathing to somewhere to improve or settle.
Use the new adv_seek_shelter() helper in such cases to send the unit to the nearest city, where it will be able to make a new decision.
Suggested-by: Sweet Tea Dorminy <sweettea-kernel@dorminy.me>
Signed-off-by: Frostblade Metablaster <frostblade@themetablaster.com>
Reviewed-by: Sweet Tea Dorminy <sweettea-kernel@dorminy.me>
Updated by Frostblade metablaster 3 days ago
- File 0001-AI-Shelter-auto-worker-stuck-in-non-allied-territory.patch 0001-AI-Shelter-auto-worker-stuck-in-non-allied-territory.patch added
Thank you for review, I did as you suggested.
If there is still room to improve let me know.
I pretty much now get it how to contribute, will read some more docs later when I'm home.
Updated by Marko Lindqvist about 16 hours ago
Are you sure AUT_AUTO_WORKER advisor task is correct in the branch where ai task is just set to be AIUNIT_NONE? Shouldn't it be AUT_NONE? It's also within cityfounding block, so also AUT_BUILD_CITY could be the right value.
Updated by Marko Lindqvist about 16 hours ago
Indentation of auto_worker_setup_work() call parameter list is off as the function name itself moved to the right but parameters in the following lines didn't.
Updated by Sweet Tea Dorminy about 14 hours ago
Are you sure AUT_AUTO_WORKER advisor task is correct in the branch where ai task is just set to be AIUNIT_NONE? Shouldn't it be AUT_NONE? It's also within cityfounding block, so also AUT_BUILD_CITY could be the right value.
Good point.
AUT_BUILD_CITY: No, that would send us with a goto tile, and next turn this routine would treat it as a city mission to that tile. city_can_be_built_here() fails since there's already a city, so the settler idles for a turn.
AUT_AUTO_WORKER: I guess we call dai_unit_new_task(AIUNIT_NONE) leaves adv at AUT_NONE; adv_seek_shelter(AUT_AUTO_WORKER) -> adv_unit_new_task(AUT_AUTO_WORKER) -> different than AUT_NONE, dai_unit_new_adv_task() -> dai_unit_new_task(AIUNIT_AUTO_WORKER). So yeah, that is harmless but it undoes the AIUNIT_NONE just set and does extra work it shouldn't.
So, yeah, @Frostblade, I agree that branch should be AUT_NONE so it just walks. Worker branch keeps AUTO_WORKER though. And the indentation point, if you're up for respinning the patch.
Updated by Frostblade metablaster about 7 hours ago
- File 0001-AI-Shelter-auto-worker-stuck-in-non-allied-territory.patch 0001-AI-Shelter-auto-worker-stuck-in-non-allied-territory.patch added
I've addressed your points, attaching new patch, let me know if I misunderstood your review.