Refactored to use Vector4i. Added Spider/Grasshopper. TODO: Ant
This commit is contained in:
parent
ff4aa93845
commit
11f8a71f52
19 changed files with 482 additions and 326 deletions
|
|
@ -1,38 +1,13 @@
|
|||
extends MovementBehaviour
|
||||
class_name MovementBehaviourBee
|
||||
|
||||
func can_reach(start: HexGrid.CubeCoordinates, target: HexGrid.CubeCoordinates, map: HexGrid) -> bool:
|
||||
# if we have 5 potential spaces it can never be blocked
|
||||
var cubepos: HexGrid.CubeCoordinates = start
|
||||
var cubecoord: HexGrid.CubeCoordinates = target
|
||||
|
||||
var cubetest: HexGrid.CubeCoordinates = HexGrid.CubeCoordinates.new(0, 0, 0)
|
||||
|
||||
cubetest.q = cubecoord.q - cubepos.q
|
||||
cubetest.r = cubecoord.r - cubepos.r
|
||||
cubetest.s = cubecoord.s - cubepos.s
|
||||
|
||||
var left = get_left_neighbour(cubetest)
|
||||
var right = get_right_neighbour(cubetest)
|
||||
|
||||
var left_coord = HexGrid.CubeCoordinates.new(left.q + cubepos.q, left.r + cubepos.r, left.s + cubepos.s)
|
||||
var right_coord = HexGrid.CubeCoordinates.new(right.q + cubepos.q, right.r + cubepos.r, right.s + cubepos.s)
|
||||
|
||||
return map.is_cell_empty(left_coord) or map.is_cell_empty(right_coord)
|
||||
|
||||
func get_left_neighbour(pos: HexGrid.CubeCoordinates) -> HexGrid.CubeCoordinates:
|
||||
return HexGrid.CubeCoordinates.new(-pos.s, -pos.q, -pos.r)
|
||||
|
||||
func get_right_neighbour(pos: HexGrid.CubeCoordinates) -> HexGrid.CubeCoordinates:
|
||||
return HexGrid.CubeCoordinates.new(-pos.r, -pos.s, -pos.q)
|
||||
|
||||
func get_available_spaces(pos: HexGrid.CubeCoordinates, map: HexGrid) -> Array[HexGrid.CubeCoordinates]:
|
||||
func get_available_spaces(pos: Vector4i, map: HexGrid) -> Array[Vector4i]:
|
||||
var potential_spaces = map.get_empty_neighbours(pos)
|
||||
|
||||
var target_spaces: Array[HexGrid.CubeCoordinates] = []
|
||||
var target_spaces: Array[Vector4i] = []
|
||||
|
||||
for neighbour in potential_spaces:
|
||||
if can_reach(pos, neighbour, map):
|
||||
for neighbour in potential_spaces:
|
||||
if map.can_reach(pos, neighbour):
|
||||
target_spaces.append(neighbour)
|
||||
|
||||
return target_spaces
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue