2024-03-14 22:13:33 +01:00
|
|
|
extends ActionBehaviour
|
|
|
|
|
class_name ActionBehaviourPillbug
|
2024-03-15 03:24:32 +01:00
|
|
|
|
2024-03-30 01:43:38 +01:00
|
|
|
func can_move_through(cellA: Vector4i, cellB: Vector4i, map: HexGrid) -> bool:
|
|
|
|
|
cellA.w = 1
|
|
|
|
|
cellB.w = 1
|
|
|
|
|
|
|
|
|
|
return map.get_same_neighbours(cellA, cellB).size() < 2
|
|
|
|
|
|
2024-03-29 02:51:06 +01:00
|
|
|
func do_action(source_tile: InsectTile, action_tile: InsectTile, map: HexGrid) -> void:
|
2024-03-30 01:43:38 +01:00
|
|
|
# get action tile
|
|
|
|
|
# place hex outline for action tile around source_tile
|
|
|
|
|
var tiles: Array[Vector4i] = map.get_empty_neighbours(source_tile.coordinates)
|
|
|
|
|
var possible_tiles: Array[Vector4i] = []
|
|
|
|
|
|
|
|
|
|
for tile in tiles:
|
|
|
|
|
if can_move_through(source_tile.coordinates, tile, map):
|
|
|
|
|
possible_tiles.push_back(tile)
|
|
|
|
|
|
|
|
|
|
map.create_move_tiles(action_tile, possible_tiles)
|
2024-03-29 02:51:06 +01:00
|
|
|
|
|
|
|
|
func get_targets(source_pos: Vector4i, map: HexGrid) -> Array[InsectTile]:
|
2024-03-15 03:24:32 +01:00
|
|
|
var neighbours = map.get_neighbours(source_pos)
|
|
|
|
|
var possible_action_targets: Array[InsectTile] = []
|
2024-03-30 01:43:38 +01:00
|
|
|
|
|
|
|
|
var tiles: Array[Vector4i] = map.get_empty_neighbours(source_pos)
|
|
|
|
|
var possible_tiles: Array[Vector4i] = []
|
|
|
|
|
|
|
|
|
|
if tiles.is_empty():
|
|
|
|
|
# no empty spaces left to move to
|
|
|
|
|
print("no spaces left")
|
|
|
|
|
return []
|
|
|
|
|
|
|
|
|
|
for tile in tiles:
|
|
|
|
|
if can_move_through(source_pos, tile, map):
|
|
|
|
|
possible_tiles.push_back(tile)
|
|
|
|
|
|
|
|
|
|
if possible_tiles.size() == 0:
|
|
|
|
|
print("no possible tiles?")
|
|
|
|
|
# no possible spaces to move TO
|
|
|
|
|
return []
|
2024-03-29 02:51:06 +01:00
|
|
|
|
2024-03-15 03:24:32 +01:00
|
|
|
for neighbour in neighbours:
|
|
|
|
|
var tile = map.get_tile(neighbour)
|
2024-03-30 19:41:23 +01:00
|
|
|
if tile == null:
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
print(tile.move_round_penalty)
|
|
|
|
|
if not tile.can_move():
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not map.can_hive_exist_without_tile(tile):
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-03-15 03:24:32 +01:00
|
|
|
if tile != null:
|
2024-03-29 02:51:06 +01:00
|
|
|
if not tile.is_in_stack() and tile.can_move():
|
2024-03-30 01:43:38 +01:00
|
|
|
if can_move_through(source_pos, neighbour, map):
|
|
|
|
|
# this tile can be picked up
|
|
|
|
|
possible_action_targets.push_back(tile)
|
2024-03-29 02:51:06 +01:00
|
|
|
|
|
|
|
|
#GameEvents.insect_tiles_selected_for_action.emit(source_pos, possible_action_targets)
|
2024-03-15 03:24:32 +01:00
|
|
|
|
2024-03-29 02:51:06 +01:00
|
|
|
return possible_action_targets
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 2nd level has to be clear (move through narrow gap rule)
|
|
|
|
|
# We could do the following: Get neighbours in 2nd level of source (pillbug) and target
|
|
|
|
|
# we we have two overlapping/same neighbours, we have a narrow gap and can't move the target
|