Original problem was bug https://bugs.openmw.org/issues/1317. where Erene Llenim did not wander because his wander distance was not big enough to include 2 waypoints. In Vanilla, Erine walks between the two waypoints closest to his starting point.
The first attempted fix was, when an NPC has a non-zero wander distance, expand the wander distance until two waypoints are available.
Unfortunately, this introduced two unwanted side effects, due to pathgrids not being uniformly supplied.
- Aquatic creatures would appear on land (because there are very few waypoints in water.
- #2726 NPCs would walk out of position. When the nearest pathgrid points in the cell were some distance from the NPCs location, the NPCs would wander away from their expected locations.
- There's over 700 NPCs and creatures which have wander distances between 10 and 128 units (inclusive), which is less than the typical distance between waypoints. Implying the NPCs are supposed to wander a only a few steps from their starting locations. (Aside, Why they have such a range of small values I have no good idea, other than at the time of writing Bethesda had no standard, so different artists just plugged in any old value. With Tribunal and Bloodmoon the distances are much more uniform.)
cc9cii wrote: FWIW, I don't believe vanilla works this way at all. i.e. AIWander does not require pathgrid points. You can see that by creatures with AiWander in places where there are no pathgrid points. OpenMW's implementation that relies on pathgrid points will require these kinds of workarounds.
scrawl wrote:Yeah, I'm not fond of the expanding idea. The correct fix is to support wandering with no pathgrid nodes. This PR is much better than the current behaviour though (not sure how that slipped past review). So let's merge it.
TorbinC wrote: This is not correct.
Expansion may feel nice for now but it is entirely a
band-aid solution and I don't think merging would be a good idea.
Wandering with no pathgrid nodes was an issue involved in the pathgrid
format itself if I remember correctly, which is why I didn't implement it.
The true pathgrid also creates nodes for the initial position of each NPC
on the map and also allows for stopping in between path nodes. Meaning
everywhere there is a line between nodes, the NPC can go there as a final
destination with AIWander. As well as anywhere (even places not linked to
with path nodes) that an NPC was placed on the ground when initially
loading the cell, is also a usable destination for building a path.
I am heavily against merging this, but it is not up to me.
@TorbinCTorbinC wrote: Actually, creatures do rely on pathgrids in vanilla if I remember correctly. Morrowind generates a blanket pathgrid for exterior cells that do not have one, this pathgrid is very basic and just has holes for static objects and water (being the reason NPCs and creatures in the wild walk around like idiots a lot of the time).
If we correct the pathgrid generation in OpenMW and adjust AIWander to work with it, the current implementation would be vanilla accurate.
Even if this is correct, it will not solve all cases. e.g. https://bugs.openmw.org/issues/2726 refers to the "GhostGate" cell. This cell does have a path grid, it's just that none of the points are in the camp where two NPCs start at. (The screenshot associated with #2726 which shows the pathgrid has been taken from the position of the camp.)
It also doesn't solve the case of what to do when wander distances are smaller than the grid size, but non-zero.
(Note, if distance is < 256, I think we can assume ground is going to be close enough to flat (in most cases) to just move that distance in a random direction.)
edit: corrected quote attribution.