2024-03-04 16:04:40 +01:00
|
|
|
extends MovementBehaviour
|
|
|
|
|
class_name MovementBehaviourLadybug
|
2024-03-14 21:17:16 +01:00
|
|
|
|
|
|
|
|
@export var max_movement_reach: int = 3
|
|
|
|
|
|
|
|
|
|
func simulate_move_recursive(start: Vector4i, max_num: int, exclude: Array[Vector4i], map: HexGrid, visited_cells: Array[Vector4i] = []) -> Array[Vector4i]:
|
|
|
|
|
var visited = visited_cells.duplicate()
|
|
|
|
|
var possible: Array[Vector4i] = []
|
|
|
|
|
|
|
|
|
|
visited.append(start)
|
|
|
|
|
|
2024-03-29 02:51:06 +01:00
|
|
|
|
2024-03-14 21:17:16 +01:00
|
|
|
if max_num < 1:
|
|
|
|
|
return [start]
|
|
|
|
|
|
|
|
|
|
var neighbours: Array[Vector4i] = []
|
|
|
|
|
if max_num > 1:
|
|
|
|
|
neighbours = map.get_neighbours(start).filter(map.is_cell_not_empty)
|
|
|
|
|
else:
|
|
|
|
|
neighbours = map.get_empty_neighbours(start)
|
|
|
|
|
|
|
|
|
|
for neighbour in neighbours:
|
2024-03-29 02:51:06 +01:00
|
|
|
#if neighbour in visited:
|
|
|
|
|
# continue
|
2024-03-14 21:17:16 +01:00
|
|
|
|
|
|
|
|
#var same_neighbours = map.get_same_neighbours(start, neighbour)
|
|
|
|
|
#for e in exclude:
|
|
|
|
|
#same_neighbours.erase(e)
|
|
|
|
|
|
|
|
|
|
#if same_neighbours.size() > 0:
|
|
|
|
|
visited.append(neighbour)
|
2024-03-29 02:51:06 +01:00
|
|
|
|
2024-03-14 21:17:16 +01:00
|
|
|
possible.append_array(simulate_move_recursive(neighbour, max_num - 1, exclude, map, visited))
|
|
|
|
|
|
|
|
|
|
return possible
|
|
|
|
|
|
|
|
|
|
func get_available_spaces(pos: Vector4i, map: HexGrid) -> Array[Vector4i]:
|
|
|
|
|
var possible_places: Array[Vector4i] = []
|
|
|
|
|
|
|
|
|
|
possible_places = simulate_move_recursive(pos, max_movement_reach, [pos], map)
|
2024-03-29 02:51:06 +01:00
|
|
|
|
|
|
|
|
var possible_places_dict: Dictionary = {}
|
|
|
|
|
for p in possible_places:
|
|
|
|
|
possible_places_dict[p] = p
|
|
|
|
|
|
|
|
|
|
possible_places.clear()
|
|
|
|
|
possible_places.assign(possible_places_dict.values())
|
|
|
|
|
|
2024-03-14 21:17:16 +01:00
|
|
|
return possible_places
|