11 Commits

Author SHA1 Message Date
dobbry-vechur 3b6a3e04b4 Make line-of-sight checks follow the current scene
- 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
2026-10-03 16:44:01 +04:00
RenechCDDA da2aaffffd Add quick setup option to clear map 2026-06-22 15:07:51 -04:00
dumb-kevin 4761c817bc Fix main pathfinder routing through open air on upper floors 2026-03-06 04:51:51 +04:00
Andrew Krieger 0215b26cce Rewrite all tests to clear map without touching character map memory, for performance. 2026-02-08 23:05:55 -08:00
inogenous 7c6ed5320d Bugfix: Mi-go pathfinding avoids fire
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?
2025-04-18 19:04:23 +02:00
inogenous 7d55aaa12f Refactor pathfind: allow multiple targets
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.
2025-04-18 06:38:45 +02:00
moxian c44d65a8ae Run IWYU again to pick up the changes 2025-02-11 13:02:19 -08:00
moxian 2ee44002fd Mechanically IWYU the tests
python3 ~/github/include-what-you-use/iwyu_tool.py -j5 -p build $( find
src/ tests/ -maxdepth 1 -name '*.cpp' | grep -v -f
tools/iwyu/bad_files.txt )  --  -Xiwyu --comment_style=long -Xiwyu -
-max_line_length=1000 -Xiwyu --cxx17ns -Xiwyu
--mapping_file=../tools/iwyu/cata.imp   | tee out/iwyu/f-a-01.txt >
/dev/null

followed by

cat out/iwyu/f-a-02.txt | python3
~/github/include-what-you-use/fix_includes.py --reorder --nosafe_headers

followed by manual fixups of <stddef.h> -> <cstddef> and similar.

tests/generic_factory_test.cpp gets mangled very badly (IWYU bug) so
it's excluded from the list.

Code size:
includes:
$ cat obj/tiles/*.inc | wc
 288068  576136 17898260
$ cat tests/obj/tiles/*.inc | wc
 167044  334088 10465766

post-processed source (clang -E):
./make_preproc.sh src/
68567896 177775140 2134075721
./make_preproc.sh tests/
39341957 102891720 1243323710
2025-02-10 00:46:57 -08:00
Clarence "Sparr" Risher 8b27b967ae Replace point constants with static class members 2024-11-26 10:14:26 -05:00
PatrikLundell c5c01140ba typified a bit of map.h/cpp + dependents (#76712)
* typified a bit of map.h/cpp + dependents

* demanded changes

* demanded master changes drawn to its conclusion

* second int should be in corresponding location
2024-10-02 23:34:12 -05:00
inogenous 04fcfa7fc1 Reach attack around corners (#75939)
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).
2024-08-25 21:37:03 -04:00