2020-06-21 18:40:37 -04:00
|
|
|
package d2common
|
|
|
|
|
2020-06-23 02:04:17 -04:00
|
|
|
import "github.com/OpenDiablo2/OpenDiablo2/d2common/d2astar"
|
2020-06-21 18:40:37 -04:00
|
|
|
|
|
|
|
type PathTile struct {
|
|
|
|
Walkable bool
|
|
|
|
Up, Down, Left, Right, UpLeft, UpRight, DownLeft, DownRight *PathTile
|
|
|
|
X, Y float64
|
|
|
|
}
|
|
|
|
|
2020-06-23 02:04:17 -04:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
if t.Right != nil {
|
|
|
|
result = append(result, t.Right)
|
|
|
|
}
|
|
|
|
if t.Down != nil {
|
|
|
|
result = append(result, t.Down)
|
|
|
|
}
|
|
|
|
if t.Left != nil {
|
|
|
|
result = append(result, t.Left)
|
|
|
|
}
|
|
|
|
if t.UpLeft != nil {
|
|
|
|
result = append(result, t.UpLeft)
|
|
|
|
}
|
|
|
|
if t.UpRight != nil {
|
|
|
|
result = append(result, t.UpRight)
|
|
|
|
}
|
|
|
|
if t.DownLeft != nil {
|
|
|
|
result = append(result, t.DownLeft)
|
|
|
|
}
|
|
|
|
if t.DownRight != nil {
|
|
|
|
result = append(result, t.DownRight)
|
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2020-06-23 02:04:17 -04:00
|
|
|
func (t *PathTile) PathNeighborCost(to d2astar.Pather) float64 {
|
2020-06-21 18:40:37 -04:00
|
|
|
return 1 // No cost specifics currently...
|
|
|
|
}
|
|
|
|
|
2020-06-23 02:04:17 -04:00
|
|
|
func (t *PathTile) PathEstimatedCost(to d2astar.Pather) float64 {
|
2020-06-21 18:40:37 -04:00
|
|
|
toT := to.(*PathTile)
|
|
|
|
absX := toT.X - t.X
|
|
|
|
if absX < 0 {
|
|
|
|
absX = -absX
|
|
|
|
}
|
|
|
|
absY := toT.Y - t.Y
|
|
|
|
if absY < 0 {
|
|
|
|
absY = -absY
|
|
|
|
}
|
|
|
|
r := absX + absY
|
|
|
|
|
|
|
|
return r
|
|
|
|
}
|