AI keeps storing out soldiers
This might be related to #871?
Identified the issue:
- AI tries to attack the castle above. Distance from building->castle=40 (max attack distance)
- soldier leaves and goes to flag -> distance is 1 longer (walked away from castle)
- as distance=41 > max distance the soldier returns home
- AI repeats this
The obvious bug is, that the distance calculation is done using the building position and not the building flag position. Fixing this would solve THIS problem.
BUT: On starting to walk to building the soldier looks for a point on or around the flag to go to. So in the above situation IF there are already soldiers on or around the flag, the soldier may need to walk to a further point. So although the distance from building flag to castle is (just) short enough, the distance the soldier has to walk maybe to long.
How to solve this?
- Do not check max running distance in soldier
- Should be ok as not noticeable in almost all cases
- If something is changed after the attack command it may walk VERY far
- Add 4 to the walk check in the soldier
- valid points are in radius 3 around the flag (should be made a named constant)
- hence if the building is reachable in maxDistance steps, we can reach all points in radius 3 around the flag in maxDistance+4 (1 for flag 3 for radius)
IMO 2 is the right thing to do
Just one more thing I'm thinking about for this: If soldiers finally block their position for other soldiers, and there is a "traffic" jam as soldiers start fighting etc. wouldn't that also cause the problem again? So only a +4 wont help at all I guess. Or am I wrong at this point?
Not sure how the "soldiers block position" should work. What happens in the original when you attack a building with massive amounts of soldiers through a path where only 1 soldier can pass through?

that way
Nice thanks. Can I get a save game to see this in action?
Also could you find out what the maximum attack distance in the original is? We have 40 steps from building to building (actual steps for humans) but from flag to flag makes more sense. Or is it from flag to building?
I don't think that you can attack at a distance of 40 nodes, buildings are flagged inland, aren't they?
Used the following setup:

But it was useless as soldiers actually passed the area not regarding those tiny rivers - although they do in RttR which seems an issue then.
Also used this setup:

which resulted in 3 soldiers ready for attacking the enemy. The distance should be 40 nodes as well. Not sure which map setup could help testing this.
Added this:
Which resulted in soldiers still ignoring that water...
Added some lava
Soldiers walking through lava...
So I opened the map with the original mapeditor and saved it again.

Finally leads to this result - Which shows that the walk distances is not as important as building distance at all. Overall I think our 40 steps are wrong.
Noticed something else as well: When attacking the HQ that is 40 nodes away from my fortress, soldiers fought one fight and went home. When attacking the HQ right over my Fortress (maybe 10 nodes away) they kept fighting till the end. Not sure what that means - maybe soldiers had some kind of action points but were always able to attack at least once or something like that?
And your savegame: SAVE.zip
The short water distance is ignored which is ok if it is 1 side of a terrain triangle. For attacking in rttr there are 2 distances used: absolute distance not taking terrain into account (less than 40) and max walking distance which is currently 40 Your tests look good maybe it is really just the 1 node water which was not enough. And maybe these 40 nodes were plain wrong.
Is you U-shape test more than 40 nodes? Direct air distance or waking distance? Can you try to bring it to extreme? So air distance that you can attack with all soldiers but long walking distance (as much as works)?
The inland check uses air/direct distance so 40 steps walking distance but much less direct distance.
Distances between both buildings was exactly 40 nodes.
At a 50 node (walk distance from building into building) it was still possible to attack. 52 - working 54 - working 56 - working 58 - working 60 - working 62 - working 64 - not working (still 3 soldiers attack option) Important: It was 64 nodes from inside building a) to inside building b) - distance between those buildings themselves should be 40 nodes. But it might explain why only 3 soldiers could attack, 40/64 = 62,5%, 62% of 9 soldiers is 5,6 soldiers stay - so 6.
So there is a solid 64 node walk distance. I think this is simply caused by the pathfinding. As I checked how far you can automatically build a road , the limit is less than 30 nodes for that although it's just a straight road.
