Implemented most movement. TODO: Pillbug ability. And find and fix bugs witht he movement. TODO: Deselect when not movable
This commit is contained in:
parent
11f8a71f52
commit
76e4d6be34
33 changed files with 184 additions and 61 deletions
|
|
@ -6,29 +6,26 @@ class_name MovementBehaviourAnt
|
|||
# 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 visited = visited_cells
|
||||
var possible: Array[Vector4i] = []
|
||||
|
||||
#if max_num < 1:
|
||||
# return [start]
|
||||
|
||||
for neighbour in map.get_empty_neighbours(start):
|
||||
if neighbour in visited:
|
||||
if neighbour in visited_cells:
|
||||
continue
|
||||
|
||||
if not map.is_position_on_hive(neighbour):
|
||||
continue
|
||||
|
||||
if not map.can_reach(start, neighbour):
|
||||
continue
|
||||
|
||||
visited_cells.push_back(neighbour)
|
||||
simulate_move_recursive(neighbour, exclude, map, visited_cells)
|
||||
|
||||
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)
|
||||
print("yay?")
|
||||
possible.append_array(simulate_move_recursive(neighbour, exclude, map, visited))
|
||||
|
||||
return possible
|
||||
return visited_cells
|
||||
|
||||
func get_available_spaces(pos: Vector4i, map: HexGrid) -> Array[Vector4i]:
|
||||
var possible_places: Array[Vector4i] = []
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ class_name MovementBehaviourBee
|
|||
|
||||
func get_available_spaces(pos: Vector4i, map: HexGrid) -> Array[Vector4i]:
|
||||
var potential_spaces = map.get_empty_neighbours(pos)
|
||||
|
||||
print(potential_spaces)
|
||||
|
||||
var target_spaces: Array[Vector4i] = []
|
||||
|
||||
|
|
|
|||
|
|
@ -1,2 +1,33 @@
|
|||
extends MovementBehaviour
|
||||
class_name MovementBehaviourBeetle
|
||||
|
||||
@export var max_movement_reach: int = 1
|
||||
|
||||
func simulate_move_recursive(start: Vector4i, max_num: int, map: HexGrid, visited_cells: Array[Vector4i] = []) -> Array[Vector4i]:
|
||||
var visited = visited_cells.duplicate()
|
||||
var possible: Array[Vector4i] = []
|
||||
|
||||
visited.append(start)
|
||||
|
||||
if max_num < 1:
|
||||
return [start]
|
||||
|
||||
for neighbour in map.get_neighbours(start, true):
|
||||
if neighbour in visited:
|
||||
continue
|
||||
|
||||
# can reach... can_reach should only apply to our current level
|
||||
if not map.can_reach(start, neighbour):
|
||||
continue
|
||||
|
||||
visited.append(neighbour)
|
||||
possible.append_array(simulate_move_recursive(neighbour, max_num - 1, 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, map)
|
||||
|
||||
return possible_places
|
||||
|
|
|
|||
|
|
@ -1,2 +1,40 @@
|
|||
extends MovementBehaviour
|
||||
class_name MovementBehaviourLadybug
|
||||
|
||||
@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)
|
||||
|
||||
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:
|
||||
if neighbour in visited:
|
||||
continue
|
||||
|
||||
#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)
|
||||
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)
|
||||
|
||||
return possible_places
|
||||
|
|
|
|||
|
|
@ -1,2 +1,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
|
||||
|
|
|
|||
|
|
@ -1,2 +1,13 @@
|
|||
extends MovementBehaviour
|
||||
class_name MovementBehaviourPillbug
|
||||
|
||||
func get_available_spaces(pos: Vector4i, map: HexGrid) -> Array[Vector4i]:
|
||||
var potential_spaces = map.get_empty_neighbours(pos)
|
||||
|
||||
var target_spaces: Array[Vector4i] = []
|
||||
|
||||
for neighbour in potential_spaces:
|
||||
if map.can_reach(pos, neighbour):
|
||||
target_spaces.append(neighbour)
|
||||
|
||||
return target_spaces
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ func simulate_move_recursive(start: Vector4i, max_num: int, exclude: Array[Vecto
|
|||
|
||||
if same_neighbours.size() > 0:
|
||||
visited.append(neighbour)
|
||||
print("yay?")
|
||||
possible.append_array(simulate_move_recursive(neighbour, max_num - 1, exclude, map, visited))
|
||||
|
||||
return possible
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue