- map::sees takes a trace: optical for sight (the default) or physical
for light and projectiles; flashes, projectiles, sonar and heat use
physical
- cached answers are dropped whenever the scene changes, not only when
the avatar's view does
- a check made between two builds first builds pending scene changes
Bugfix for pathfinding to not use the straight-line optimization when
there is some sort of non-normal tile between the source and target.
Mi-go will now path around fires if there is such a route.
There is an optimization in place before the A* pathfinder is invoked,
that checks for whether the target is reachable by a straight-line. In
such case, the A* pathfinder is not invoked, presumably because of
performance reasons. The evaluation of this straight-line optimization
does not use the same way of choosing whether or not each tile is
walkable or not. The real A* pathfinder will usually route around tiles
that are technically walkable but might be questionable (such as fires),
but the straight-line optimization only checks for whether it's
technically walkable. The real A* pathfinder might also pick a route
through such questionable tiles if there are no other choices. For
example, a monster might walk through fire if surrounded. So the
question of whether or not to pick the straight-line optimization is a
bit trickier than it might seem at first.
Because of these differences in the straight-line evaluation and the
real A* pathfinder, the straight-line optimization was previously chosen
even if the A* pathfinder would have picked a different path. For
example: before, a mi-go picked a straight-line path through fire, even
if it had `avoid_dangerous_fields` because, well, the tiles on fire are
technically walkable, right?
This commit instead aborts the straight-line optimization if any of the
tiles on the straight-line has any sort of non-normal characteristic. If
so, the A* pathfinder is invoked, which will choose the best route given
the circumstances. The route will probably walk around the fires, but if
there's no other way, it will walk through it.
This commit also adds `avoid_dangerous_fields` to all mi-gos, because
they're fairly intelligent and would likely not willingly walk into a
fire. There are likely more monsters that should also have the
`avoid_dangerous_fields`-flag set, such as most mammals?
Refactors pathfinding in `map::route` so that the target can not only be
a single point, but also an area or any adjacent point.
Reason for changing is purely to make the calling code shorter.
This is done by introducing a new struct `pathfinding_target` which
allows the caller to specify either:
* a single point (like before)
* any tile adjacent to or on a single point
* any tile within a radius of a point
The logic of the pathfinder is not changed. What is changed is that the
algorithm stops as soon as any of the target tiles have been found.
Since the pathfinder picks points with lower weights first, this ensures
that as soon as it has found any of the target tiles, it is therefore
also the shortest path.
Adds rudimentary tests for easy scenarios such as avoiding dangers or
passing through dangers when there are no other paths to pick.
* typified a bit of map.h/cpp + dependents
* demanded changes
* demanded master changes drawn to its conclusion
* second int should be in corresponding location
Fixes an issue where melee reach attacks would hit a wall before, even
if there were other possibilities to draw a straight line to the target.
The issue before was two issues:
* `map::sees` returned cached values even if `bresenham_slope` was
changed
* `map::find_clear_path` did not try different values for
`candidate_offset` if `start_sign` was 0
The first issue was that the algorithm being used in
`map::find_clear_path` tries to find a value for `bresenham_slope` (also
named `candidate_offset`) that creates a clear path to the target. But
in `map::sees` we create a cache key for an LRU cache using only the
from and to points, and the cache key specifically does not contain
`bresenham_slope`. This made it so that repeated calls to `map::sees`
using different values for `bresenham_slope` would always just return
the cached value from the first evaluation of the method.
The second issue was that in cases where `start_sign` was 0 in
`map::find_clear_path`, then the algorithm for finding a good value for
`bresenham_slope` always used `candidate_offset=0` since it incorrectly
multiplied the `horizontal_offset` with `0`. In effect, it previously
iterated several values for `horizontal_offset`, but all of them
resulted in `0` being tried for `bresenham_slope`.
This commit instead updates `map::sees` so that calls from
`map::find_clear_path` never allow cached results. The cache will still
be populated correctly once a path is chosen, but with this commit, it
will also allow calls to attempt using different values for
`bresenham_slope`.
The effect of this is that melee reach attacks will now correctly find a
straight path when being done adjacent to an obstacle. A side-effect is
also that ranged attacks that find a straight path from A to B should
now also find a straight path from B to A (they did not always do so
before).