Fixed Spider movement (it was not excluding itself after the first move

This commit is contained in:
Sch1nken 2024-03-14 22:13:33 +01:00
parent 76e4d6be34
commit 5722ffab48
9 changed files with 64 additions and 22 deletions

View file

@ -175,7 +175,27 @@ func get_left_neighbour(pos: Vector4i) -> Vector4i:
func get_right_neighbour(pos: Vector4i) -> Vector4i:
return Vector4i(-pos.y, -pos.z, -pos.x, 0)
func can_reach(start: Vector4i, target: Vector4i) -> bool:
var debug_labels = []
func debug_label(pos, text) -> void:
var label = Label3D.new()
label.billboard = BaseMaterial3D.BILLBOARD_ENABLED
label.text = text
var p = cube_to_world_pos(pos)
label.position = Vector3(p.x, 0.2, p.y)
add_child(label)
debug_labels.push_back(label)
func clear_debug_labels() -> void:
for label in debug_labels:
label.queue_free()
debug_labels.clear()
func can_reach(start: Vector4i, target: Vector4i, exclude: Array[Vector4i] = []) -> bool:
if start.w != target.w:
return true
# if we have 5 potential spaces it can never be blocked
var offset: Vector4i = Vector4i.ZERO
@ -185,9 +205,14 @@ func can_reach(start: Vector4i, target: Vector4i) -> bool:
var left = get_left_neighbour(offset)
var right = get_right_neighbour(offset)
var left_coord = Vector4i(left.x + start.x, left.y + start.y, left.z + start.z, start.w)
var right_coord = Vector4i(right.x + start.x, right.y + start.y, right.z + start.z, start.w)
if left_coord in exclude or right_coord in exclude:
print("excluded?")
return true
return is_cell_empty(left_coord) or is_cell_empty(right_coord)
@ -305,7 +330,7 @@ func _on_insect_placed(resource: TileResource, is_black: bool, pos: Vector4i) ->
func can_move(tile: InsectTile) -> bool:
return can_hive_exist_without_tile(tile)
func _on_insect_tile_selected(tile: InsectTile) -> void:
func _on_insect_tile_selected(tile: InsectTile) -> void:
if not can_hive_exist_without_tile(tile):
print("Would break hive")
return