2024-03-04 16:04:40 +01:00
|
|
|
extends MovementBehaviour
|
|
|
|
|
class_name MovementBehaviourAnt
|
2024-03-14 19:30:18 +01:00
|
|
|
|
|
|
|
|
# Ant uses a modified BFS? It's basically a supercharged spider with limitlesss movement range
|
|
|
|
|
# Naive approach: BFS from all neighbours, don't go to already visited cells, check if can reach
|
|
|
|
|
# Maybe better: Get al "placecable tiles" from the map, go over those. Might be faster but more complicated
|
|
|
|
|
|
|
|
|
|
func simulate_move_recursive(start: Vector4i, exclude: Array[Vector4i], map: HexGrid, visited_cells: Array[Vector4i] = []) -> Array[Vector4i]:
|
|
|
|
|
var possible: Array[Vector4i] = []
|
|
|
|
|
|
|
|
|
|
for neighbour in map.get_empty_neighbours(start):
|
2024-03-14 21:17:16 +01:00
|
|
|
if neighbour in visited_cells:
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
if not map.is_position_on_hive(neighbour):
|
2024-03-14 19:30:18 +01:00
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
if not map.can_reach(start, neighbour):
|
|
|
|
|
continue
|
|
|
|
|
|
2024-03-14 21:17:16 +01:00
|
|
|
visited_cells.push_back(neighbour)
|
|
|
|
|
simulate_move_recursive(neighbour, exclude, map, visited_cells)
|
|
|
|
|
|
2024-03-14 19:30:18 +01:00
|
|
|
var same_neighbours = map.get_same_neighbours(start, neighbour)
|
|
|
|
|
for e in exclude:
|
|
|
|
|
same_neighbours.erase(e)
|
|
|
|
|
|
2024-03-14 21:17:16 +01:00
|
|
|
return visited_cells
|
2024-03-14 19:30:18 +01:00
|
|
|
|
|
|
|
|
func get_available_spaces(pos: Vector4i, map: HexGrid) -> Array[Vector4i]:
|
|
|
|
|
var possible_places: Array[Vector4i] = []
|
|
|
|
|
|
|
|
|
|
possible_places = simulate_move_recursive(pos, [pos], map)
|
|
|
|
|
|
|
|
|
|
return possible_places
|