Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GetTerrainLabel for label at the given position #4909

Merged
merged 1 commit into from
May 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion lua/sim/NavUtils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,8 @@ function PathToWithThreatThreshold(layer, origin, destination, aibrain, threatFu
return path, head, distance
end

--- Returns a label that indicates to what sub-graph it belongs to, these graphs can be visualised using the Nav UI
--- Returns a label that indicates to what sub-graph it belongs to. Unlike `GetTerrainLabel` this function will try to find the nearest valid neighbor
---@see GetTerrainLabel
---@param layer NavLayers
---@param position Vector
---@return number?
Expand Down Expand Up @@ -565,6 +566,42 @@ function GetLabel(layer, position)
return leaf.Label, nil
end

--- Returns a label that indicates to what sub-graph it belongs to. Unlike `GetLabel` this function does not try to find valid neighbors
---@see GetLabel
---@param layer NavLayers
---@param position Vector
---@return number?
---@return string?
function GetTerrainLabel(layer, position)
-- check if generated
if not NavGenerator.IsGenerated() then
WarnNoNavMesh()
return nil, 'Navigational mesh is not generated'
end

-- check layer argument
local grid = FindGrid(layer)
if not grid then
return nil, 'Invalid layer type - this is likely a typo. The layer is case sensitive'
end

-- check position argument
local leaf = grid:FindLeaf(position)
if not leaf then
return nil, 'Position is not inside the map'
end

if leaf.Label == 0 then
return nil, 'Position has no label assigned, report to the maintainers. This should not be possible'
end

if leaf.Label == -1 then
return nil, 'Position is unpathable'
end

return leaf.Label, nil
end

--- Returns the metadata of a label.
---@param id number
---@return NavLabelMetadata?
Expand Down
Loading