Swarm/MovementBehaviour/Prefabs/MovementBehaviourBee.gd

38 lines
1.5 KiB
GDScript

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]:
var potential_spaces = map.get_empty_neighbours(pos)
var target_spaces: Array[HexGrid.CubeCoordinates] = []
for neighbour in potential_spaces:
if can_reach(pos, neighbour, map):
target_spaces.append(neighbour)
return target_spaces