Prepared Movement behaviour. Fixed multi-tile placement bug

This commit is contained in:
Sch1nken 2024-03-29 02:51:06 +01:00
parent 62eef907d3
commit 397082f966
17 changed files with 395 additions and 75 deletions

View file

@ -9,6 +9,7 @@ func simulate_move_recursive(start: Vector4i, max_num: int, exclude: Array[Vecto
visited.append(start)
if max_num < 1:
return [start]
@ -19,8 +20,8 @@ func simulate_move_recursive(start: Vector4i, max_num: int, exclude: Array[Vecto
neighbours = map.get_empty_neighbours(start)
for neighbour in neighbours:
if neighbour in visited:
continue
#if neighbour in visited:
# continue
#var same_neighbours = map.get_same_neighbours(start, neighbour)
#for e in exclude:
@ -28,6 +29,7 @@ func simulate_move_recursive(start: Vector4i, max_num: int, exclude: Array[Vecto
#if same_neighbours.size() > 0:
visited.append(neighbour)
possible.append_array(simulate_move_recursive(neighbour, max_num - 1, exclude, map, visited))
return possible
@ -36,5 +38,12 @@ 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)
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())
return possible_places

View file

@ -2,12 +2,13 @@ extends MovementBehaviour
class_name MovementBehaviourMosquito
func get_available_spaces(pos: Vector4i, map: HexGrid) -> Array[Vector4i]:
var target_spaces: Array[Vector4i] = []
for neighbour in map.get_neighbours(pos):
if map.is_cell_empty(neighbour):
continue
target_spaces.append_array(map.get_tile(neighbour).resource.movement_behaviour.get_available_spaces(pos, map))
return target_spaces
return []
#var target_spaces: Array[Vector4i] = []
#
#for neighbour in map.get_neighbours(pos):
#if map.is_cell_empty(neighbour):
#continue
#
#target_spaces.append_array(map.get_tile(neighbour).resource.movement_behaviour.get_available_spaces(pos, map))
#
#return target_spaces