Skip to content

Commit

Permalink
Merge pull request #53 from devw4r/master
Browse files Browse the repository at this point in the history
- Expose LineOfSight doodads flag.
  • Loading branch information
namreeb authored Jul 30, 2023
2 parents a8a0b73 + 18d7ad5 commit 57fba2e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,7 @@
/MapViewer/Include/vertexShader.hpp
/CMakeSettings.json
/out
/build
/*.idea
/cmake-build-debug
/cmake-build-release
4 changes: 2 additions & 2 deletions pathfind/Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -840,11 +840,11 @@ bool Map::ZoneAndArea(const math::Vertex& position, unsigned int& zone,
return rayResult || adtResult;
}

bool Map::LineOfSight(const math::Vertex& start, const math::Vertex& stop) const
bool Map::LineOfSight(const math::Vertex& start, const math::Vertex& stop, bool doodads) const
{
math::Ray ray {start, stop};
// RayCast() returns true when an obstacle is hit
return !RayCast(ray, false);
return !RayCast(ray, doodads);
}

bool Map::RayCast(math::Ray& ray, bool doodads) const
Expand Down
3 changes: 2 additions & 1 deletion pathfind/Map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ class Map
// Returns true when there is line of sight from the start position to
// the stop position. The intended use of this is for spells and NPC
// aggro, so doodads and temporary obstacles will be ignored.
bool LineOfSight(const math::Vertex& start, const math::Vertex& stop) const;
bool LineOfSight(const math::Vertex& start, const math::Vertex& stop,
bool doodads) const;

const dtNavMesh& GetNavMesh() const { return m_navMesh; }
const dtNavMeshQuery& GetNavMeshQuery() const { return m_navQuery; }
Expand Down
7 changes: 5 additions & 2 deletions pathfind/python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,13 @@ py::object python_query_z(const pathfind::Map& map, float start_x, float start_y
}

py::object los(const pathfind::Map& map, float start_x, float start_y, float start_z,
float stop_x, float stop_y, float stop_z)
float stop_x, float stop_y, float stop_z, bool doodads)
{
return py::object(
map.LineOfSight({start_x, start_y, start_z}, {stop_x, stop_y, stop_z}));
map.LineOfSight(
{start_x, start_y, start_z},
{stop_x, stop_y, stop_z},
doodads));
}

py::object get_zone_and_area(pathfind::Map& map, float x, float y, float z)
Expand Down
8 changes: 4 additions & 4 deletions test/smoke_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,22 @@ def compute_path_length(path):
print("Zone check succeeded")

should_fail = map_data.line_of_sight(16268.3809, 16812.7148, 36.1483,
16266.5781, 16782.623, 38.5035019)
16266.5781, 16782.623, 38.5035019, False)

if should_fail:
raise Exception("Should-fail LoS check passed")

print("Should-fail LoS check failed correctly")

should_pass = map_data.line_of_sight(16873.2168, 16926.9551, 15.9072571,
16987.4277, 16950.0742, 69.4590912)
16987.4277, 16950.0742, 69.4590912, False)
if should_pass is False:
raise Exception("Should-pass LoS check failed")

print("Should-pass LoS check succeeded")

should_pass_doodad = map_data.line_of_sight(16275.6895, 16853.9023, 37.8341751,
16251.0332, 16858.2988, 34.9305573)
16251.0332, 16858.2988, 34.9305573, False)
if should_pass_doodad is False:
raise Exception("Should-pass doodad LoS check failed")

Expand Down Expand Up @@ -139,4 +139,4 @@ def main():

if __name__ == "__main__":
main()
sys.exit(0)
sys.exit(0)

0 comments on commit 57fba2e

Please sign in to comment.