Project

General

Profile

Actions

Bug #2509

open

AI fails to move settlers when no land to improve available exists

Added by Frostblade metablaster 4 days ago. Updated about 7 hours ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
AI
Target version:
-
Start date:
11/28/2026
Due date:
% Done:

0%

Estimated time:

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

Actions #1

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!!

Actions #2

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

Actions #3

Updated by Frostblade metablaster 4 days ago

Thanks for guiding me, I did as you suggested, tested as well and works fine.

However I can't seem to update ticket title.

Actions #4

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?

Actions #5

Updated by Frostblade metablaster 4 days ago

OK, that's done and the new patch is properly formatted. (other 2 patches can be deleted)

Thanks again for patience and help.

Actions #6

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 <>
Signed-off-by: Frostblade Metablaster <>
Reviewed-by: Sweet Tea Dorminy <>

Actions #7

Updated by Frostblade metablaster 3 days ago

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.

Actions #8

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.

Actions #9

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.

Actions #10

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.

Actions #11

Updated by Frostblade metablaster about 7 hours ago

I've addressed your points, attaching new patch, let me know if I misunderstood your review.

Actions

Also available in: Atom PDF