ondras / rot.js

ROguelike Toolkit in JavaScript. Cool dungeon-related stuff, interactive manual, documentation, tests!
https://ondras.github.io/rot.js/hp/
BSD 3-Clause "New" or "Revised" License
2.33k stars 254 forks source link

What about passing coords of 'from cell' to passableCallback when pathfinding? #103

Open walsh9 opened 7 years ago

walsh9 commented 7 years ago

To determine whether a cell is traversable in cases like thin walls (like dig dug), tiles with z-height (e.g. enemy that can only fall to a 'lower' tile and not climb to 'higher' ones), and other sorts of one-way terrain, you need to know what cell you are coming from.

Could the passableCallback receive 4 parameters (x, y, fromX, fromY) instead of just the current (x, y).

Honestly, I'm having a little trouble completely wrapping my head around pathfinding and not sure this would work for all possible pathfinders but I sketched out some Dijkstra maps on graph paper with these kinds of rules and it seemed to work out.

If this makes sense and is a desirable feature I'd be happy to work on a pull request.

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/38496749-what-about-passing-coords-of-from-cell-to-passablecallback-when-pathfinding?utm_campaign=plugin&utm_content=tracker%2F297828&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F297828&utm_medium=issues&utm_source=github).
ondras commented 7 years ago

I see, this makes sense. The current pathfinder consideres all directions equal, so a cell's passability is a boolean value. But I suppose you might want to make your cell accessible from one direction and inaccessible from other -- and the proposed change is backwards compatible, so +1 for a PR :-) Thanks!