pathfinding

package
v1.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 16, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GROUND_HEIGHT_TOLERANCE = 0.05
	DEFAULT_HEIGHT_SEARCH   = 50.0
	// Z_OFFSET_FIND_HEIGHT matches AzerothCore SharedDefines.h
	Z_OFFSET_FIND_HEIGHT = 2.0
	// DEFAULT_COLLISION_HEIGHT matches AzerothCore ObjectDefines.h (most common model value)
	DEFAULT_COLLISION_HEIGHT = 2.03128
)
View Source
const (
	VMAP_MAGIC     = "VMAP_3.0"
	VMAP_MAGIC_48  = "VMAP_4.8"
	INVALID_HEIGHT = -100000.0
	VMAP_mid       = 32.0 * 533.3333 // for internal <-> game conversion used inside vmaps

)

Constants from AC

View Source
const (
	BIH_LEAF_MASK = 3 << 30
	BIH_BVH2_MASK = 1 << 29
)

BIH node encoding (from AC)

Variables

This section is empty.

Functions

This section is empty.

Types

type AABox

type AABox struct {
	Low, High Vector3
}

AABox

func (AABox) IntersectRay

func (b AABox) IntersectRay(ray Ray, maxDist *float32) bool

type BIH

type BIH struct {
	// contains filtered or unexported fields
}

BIH simple port for ray intersect (for height we use downward)

type GroupModel

type GroupModel struct {
	TriFlags uint32
	Mesh     []MeshTriangle
	Vertices []Vector3
	// contains filtered or unexported fields
}

GroupModel

type MMapManager

type MMapManager struct {
	// contains filtered or unexported fields
}

MMapManager manages lazy loading of navigation meshes and their tiles. It is safe for concurrent use.

func NewMMapManager

func NewMMapManager(mmapsDir string) *MMapManager

NewMMapManager creates a new MMapManager that reads files from mmapsDir.

func (*MMapManager) CreateQuery

func (m *MMapManager) CreateQuery(mapID uint32) (*detour.DtNavMeshQuery, error)

CreateQuery creates a new DtNavMeshQuery for the given map. Each query instance is NOT thread-safe and should be used from a single goroutine.

func (*MMapManager) EnsureAllTilesLoaded

func (m *MMapManager) EnsureAllTilesLoaded(mapID uint32) error

EnsureAllTilesLoaded loads every .mmtile present for the map to ensure complete nav graph (matches runtime server behavior for pathing).

func (*MMapManager) EnsureTileLoaded

func (m *MMapManager) EnsureTileLoaded(mapID uint32, x, y int32) error

EnsureTileLoaded ensures the tile at (x, y) for the given map is loaded.

func (*MMapManager) GetNavMesh

func (m *MMapManager) GetNavMesh(mapID uint32) (*detour.DtNavMesh, error)

GetNavMesh returns the nav mesh for the given map, loading it lazily if needed.

type MeshTriangle

type MeshTriangle struct {
	// contains filtered or unexported fields
}

type ModelInstance

type ModelInstance struct {
	// contains filtered or unexported fields
}

ModelInstance (simplified for height)

type ModelSpawn

type ModelSpawn struct {
	Flags uint32
	ADTId uint16
	ID    uint32
	// contains filtered or unexported fields
}

ModelSpawn

type PathFinder

type PathFinder struct {
	// contains filtered or unexported fields
}

PathFinder provides pathfinding capabilities using MMap data. Each PathFinder instance owns a DtNavMeshQuery which is NOT thread-safe. Use the pool-based PathFindingService for concurrent access.

func NewPathFinder

func NewPathFinder(mmapMgr *MMapManager, terrainMgr *TerrainManager, vmapMgr *VMapManager, mapID uint32) (*PathFinder, error)

NewPathFinder creates a PathFinder for the given map.

func (*PathFinder) FindPath

func (pf *PathFinder) FindPath(start, dest Point3D) (*PathResult, error)

FindPath computes a path from start to dest using smooth path generation.

func (*PathFinder) FindRandomPointAroundCircle

func (pf *PathFinder) FindRandomPointAroundCircle(center Point3D, radius float32) (*PathResult, error)

FindRandomPointAroundCircle finds a random valid point within radius of the center.

func (*PathFinder) GetHeight

func (pf *PathFinder) GetHeight(x, y, z float32) (float32, bool)

GetHeight returns the ground Z at (x,y), preferring vmap collision when available. The incoming z is the "pre-correction" value (e.g. poly height or input Z from smooth path). We replicate WorldObject::GetMapHeight by adding Z_OFFSET_FIND_HEIGHT to the search origin.

func (*PathFinder) HaveTile

func (pf *PathFinder) HaveTile(p Point3D) bool

HaveTile checks whether the tile containing the game position is loaded in the navmesh.

type PathFindingService

type PathFindingService struct {
	// contains filtered or unexported fields
}

PathFindingService is a thread-safe service that manages a pool of PathFinder instances.

func NewPathFindingService

func NewPathFindingService(mmapsDir, mapsDir string) *PathFindingService

NewPathFindingService creates a new PathFindingService from separate mmaps and maps directories. For convenience when using a single ac-data root containing mmaps/, maps/, vmaps/ subdirectories, prefer NewPathFindingServiceFromDataDir instead.

func NewPathFindingServiceFromDataDir

func NewPathFindingServiceFromDataDir(dataDir string) *PathFindingService

NewPathFindingServiceFromDataDir creates a PathFindingService from a single data directory root (e.g. ac-data/) that is expected to contain:

  • mmaps/
  • maps/
  • vmaps/ (optional, for accurate height)

Subdirectories are resolved automatically.

func NewPathFindingServiceWithMMapMgr

func NewPathFindingServiceWithMMapMgr(mmapMgr *MMapManager, terrainMgr *TerrainManager, vmapMgr *VMapManager) *PathFindingService

NewPathFindingServiceWithMMapMgr creates a new PathFindingService using an existing MMapManager (and optional terrain/vmap).

func (*PathFindingService) FindPath

func (s *PathFindingService) FindPath(mapID uint32, start, dest Point3D) (*PathResult, error)

FindPath finds a path from start to dest within the same map.

func (*PathFindingService) FindRandomPath

func (s *PathFindingService) FindRandomPath(mapID uint32, center Point3D, radius float32) (*PathResult, error)

FindRandomPath finds a random valid path within radius of center.

func (*PathFindingService) GetHeight

func (s *PathFindingService) GetHeight(mapID uint32, x, y, z float32) (float32, bool)

GetHeight returns the ground height (Z) at (x,y) using best available source: vmap collision first, terrain next, then navmesh poly as a fallback. This provides values aligned with what path correction and AC use.

func (*PathFindingService) GetTerrainHeight

func (s *PathFindingService) GetTerrainHeight(mapID uint32, x, y float32) (float32, bool)

GetTerrainHeight returns the raw map grid height at (x,y), without using the caller's Z hint or navmesh poly height. Bot movement uses this for final path Z snapping so downhill terrain can pull dense wander samples down.

type PathResult

type PathResult struct {
	Type   PathType
	Points []Point3D
}

PathResult contains the output of a pathfinding query.

func (*PathResult) PathLength

func (r *PathResult) PathLength() float32

PathLength computes the total length of the path.

type PathType

type PathType uint32

PathType describes the result status of a pathfinding query.

const (
	PathfindBlank            PathType = 0x00
	PathfindNormal           PathType = 0x01
	PathfindShortcut         PathType = 0x02
	PathfindIncomplete       PathType = 0x04
	PathfindNopath           PathType = 0x08
	PathfindNotUsingPath     PathType = 0x10
	PathfindShort            PathType = 0x20
	PathfindFarFromPolyStart PathType = 0x40
	PathfindFarFromPolyEnd   PathType = 0x80
)

type Point3D

type Point3D struct {
	X, Y, Z float32
}

Point3D represents a 3D point in game coordinates.

type Ray

type Ray struct {
	Origin, Direction Vector3
}

Ray

func NewRay

func NewRay(origin, dir Vector3) Ray

type StaticMapTree

type StaticMapTree struct {
	// contains filtered or unexported fields
}

StaticMapTree minimal port focused on height.

func (*StaticMapTree) InitMap

func (s *StaticMapTree) InitMap(fname string) bool

func (*StaticMapTree) LoadMapTile

func (s *StaticMapTree) LoadMapTile(tileX, tileY uint32) error

type TerrainManager

type TerrainManager struct {
	// contains filtered or unexported fields
}

TerrainManager manages lazy loading of .map terrain data for height queries. It is safe for concurrent use.

func NewTerrainManager

func NewTerrainManager(mapsDir string) *TerrainManager

NewTerrainManager creates a TerrainManager reading .map files from mapsDir.

func (*TerrainManager) EnsureGridLoaded

func (tm *TerrainManager) EnsureGridLoaded(mapID uint32, gx, gy int32) error

EnsureGridLoaded forces load for a grid (useful for preloading).

func (*TerrainManager) GetGridHeight

func (tm *TerrainManager) GetGridHeight(mapID uint32, x, y float32) (float32, bool)

GetGridHeight returns the raw interpolated grid height (no z check).

func (*TerrainManager) GetHeight

func (tm *TerrainManager) GetHeight(mapID uint32, x, y, z float32) (float32, bool)

GetHeight returns the terrain height at (x, y) using the same interpolation as AzerothCore GridTerrainData. Matches AC: only returns the grid height if the search z is not below it by more than tolerance.

func (*TerrainManager) GetLiquidStatus

func (tm *TerrainManager) GetLiquidStatus(mapID uint32, x, y, z float32) uint8

GetLiquidStatus is a simplified stub; full liquid not required for basic Z alignment now.

type VMapManager

type VMapManager struct {
	// contains filtered or unexported fields
}

VMapManager manages vmap data per map for height queries.

func NewVMapManager

func NewVMapManager(vmapsDir string) *VMapManager

func (*VMapManager) GetHeight

func (vm *VMapManager) GetHeight(mapID uint32, x, y, z float32, maxSearch float32) (float32, bool)

GetHeight returns ground height by downward ray using vmap if available, else -inf.

type Vector3

type Vector3 struct {
	X, Y, Z float32
}

Vector3 simple

func (Vector3) Add

func (v Vector3) Add(o Vector3) Vector3

func (Vector3) Cross

func (v Vector3) Cross(o Vector3) Vector3

func (Vector3) Dot

func (v Vector3) Dot(o Vector3) float32

func (Vector3) Mul

func (v Vector3) Mul(s float32) Vector3

func (Vector3) Sub

func (v Vector3) Sub(o Vector3) Vector3

type WorldModel

type WorldModel struct {
	RootWMOID uint32
	// contains filtered or unexported fields
}

WorldModel simplified

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL