1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-09-06 19:44:15 -04:00
OpenDiablo2/d2common/path_tile.go

69 lines
1.5 KiB
Go
Raw Normal View History

2020-06-21 18:40:37 -04:00
package d2common
import (
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2astar"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2math/d2vector"
)
2020-06-21 18:40:37 -04:00
// PathTile represents a node in path finding
2020-06-21 18:40:37 -04:00
type PathTile struct {
Walkable bool
Up, Down *PathTile
Left, Right *PathTile
UpLeft, UpRight *PathTile
DownLeft, DownRight *PathTile
Position d2vector.Position
2020-06-21 18:40:37 -04:00
}
// PathNeighbors returns the direct neighboring nodes of this node which can be pathed to
func (t *PathTile) PathNeighbors() []d2astar.Pather {
result := make([]d2astar.Pather, 0, 8)
2020-06-21 18:40:37 -04:00
if t.Up != nil {
result = append(result, t.Up)
}
2020-06-21 18:40:37 -04:00
if t.Right != nil {
result = append(result, t.Right)
}
2020-06-21 18:40:37 -04:00
if t.Down != nil {
result = append(result, t.Down)
}
2020-06-21 18:40:37 -04:00
if t.Left != nil {
result = append(result, t.Left)
}
2020-06-21 18:40:37 -04:00
if t.UpLeft != nil {
result = append(result, t.UpLeft)
}
2020-06-21 18:40:37 -04:00
if t.UpRight != nil {
result = append(result, t.UpRight)
}
2020-06-21 18:40:37 -04:00
if t.DownLeft != nil {
result = append(result, t.DownLeft)
}
2020-06-21 18:40:37 -04:00
if t.DownRight != nil {
result = append(result, t.DownRight)
}
return result
}
// PathNeighborCost calculates the exact movement cost to neighbor nodes
func (t *PathTile) PathNeighborCost(_ d2astar.Pather) float64 {
2020-06-21 18:40:37 -04:00
return 1 // No cost specifics currently...
}
// PathEstimatedCost is a heuristic method for estimating movement costs between non-adjacent nodes
func (t *PathTile) PathEstimatedCost(to d2astar.Pather) float64 {
delta := to.(*PathTile).Position.Clone()
delta.Subtract(&t.Position.Vector)
delta.Abs()
return delta.X() + delta.Y()
2020-06-21 18:40:37 -04:00
}