Fixed more movement bugs, disabled expansions for now. Added turnendbehaviour (for bee, should add trigger by turn end signal)
This commit is contained in:
parent
5722ffab48
commit
26fec25a6e
14 changed files with 154 additions and 37 deletions
|
|
@ -113,6 +113,19 @@ func is_cell_not_empty(coords: Vector4i) -> bool:
|
|||
func get_empty_neighbours(coords: Vector4i) -> Array[Vector4i]:
|
||||
return get_neighbours(coords).filter(is_cell_empty)
|
||||
|
||||
func get_highest_in_stack(coords: Vector4i) -> Vector4i:
|
||||
if not used_cells.has(coords):
|
||||
print("ground")
|
||||
return coords
|
||||
|
||||
var top: InsectTile = used_cells[coords]
|
||||
while top.hat != null:
|
||||
top = top.hat
|
||||
|
||||
print("found top")
|
||||
print(top.coordinates)
|
||||
return top.coordinates
|
||||
|
||||
func get_neighbours(coords: Vector4i, ground_layer: bool = false) -> Array[Vector4i]:
|
||||
var layer: int = coords.w
|
||||
if ground_layer:
|
||||
|
|
@ -147,7 +160,13 @@ func get_placeable_positions(button: InsectButton) -> Array[Vector4i]:
|
|||
var possible_placements: Dictionary = {}
|
||||
var positions: Array[Vector4i] = []
|
||||
|
||||
for hex in used_cells.keys():
|
||||
for hex in used_cells.keys().filter(func(coords): return coords.w == 0):
|
||||
# We filter here because we only want neighbours of ground level tiles
|
||||
# Otherwise we spawn an oultine on ground level but with an internal
|
||||
# Coordinate of somewhere higher up
|
||||
# Visually everything will be correct but internally the resulting hex
|
||||
# Will count as higher layer tile leading to nasty bugs
|
||||
|
||||
for neighbour in get_empty_neighbours(hex):
|
||||
if not used_cells.has(neighbour):
|
||||
possible_placements[neighbour] = true
|
||||
|
|
@ -218,7 +237,7 @@ func can_reach(start: Vector4i, target: Vector4i, exclude: Array[Vector4i] = [])
|
|||
|
||||
func _on_insect_selected(button: InsectButton, is_black: bool) -> void:
|
||||
var positions = get_placeable_positions(button)
|
||||
for p in positions:
|
||||
for p in positions:
|
||||
var outline = HEX_OUTLINE.instantiate()
|
||||
var hex_pos = cube_to_world_pos(p)
|
||||
outline.position = Vector3(hex_pos.x, 0.0, hex_pos.y)
|
||||
|
|
@ -317,6 +336,7 @@ func _on_insect_placed(resource: TileResource, is_black: bool, pos: Vector4i) ->
|
|||
tile_copy.resource = resource
|
||||
tile_copy.is_black = is_black
|
||||
tile_copy.coordinates = pos
|
||||
print(pos)
|
||||
tile_copy.map_reference = self
|
||||
var target_pos = Vector3(hex_pos.x, 0.0, hex_pos.y)
|
||||
|
||||
|
|
@ -339,6 +359,9 @@ func _on_insect_tile_selected(tile: InsectTile) -> void:
|
|||
print("no movement behaviour")
|
||||
return
|
||||
|
||||
#if tile.resource.action_behaviour != null:
|
||||
#tile.resource.action_behaviour.select_targets(tile.coordinates, self)
|
||||
|
||||
var spaces = tile.resource.movement_behaviour.get_available_spaces(tile.coordinates, self)
|
||||
|
||||
if spaces.is_empty():
|
||||
|
|
@ -353,9 +376,14 @@ func _on_insect_tile_selected(tile: InsectTile) -> void:
|
|||
if non_empty_neighbours.size() == 1:
|
||||
# NOTE: This is correct! But seemed wrong when testing the beetle movement
|
||||
# If there are only two tiles (beetle + some other) the beetle can't climb ontop of the other
|
||||
# tile. This fixes itself automatically when there are more than two tiles present
|
||||
# tile. (would not necessarily split the hive, but the simple logic I use thinks so).
|
||||
# This fixes itself automatically when there are more than two tiles present
|
||||
# And since you can't move unless you place the bee, there will always be at least 3 tiles
|
||||
# before you can move your beetle
|
||||
|
||||
# NOTE: This MIGHT result in a bug when you stack beetles... but no I don't think so
|
||||
# You'd need to have a bee to be able to move, so yeah
|
||||
|
||||
var occupied_neighbour = non_empty_neighbours.front()
|
||||
if occupied_neighbour == tile.coordinates:
|
||||
continue
|
||||
|
|
@ -365,9 +393,10 @@ func _on_insect_tile_selected(tile: InsectTile) -> void:
|
|||
if is_cell_not_empty(space):
|
||||
temp_tile = used_cells.get(space)
|
||||
layer = 1
|
||||
while tile.hat != null:
|
||||
while temp_tile.hat != null:
|
||||
layer += 1
|
||||
tile = tile.hat
|
||||
temp_tile = temp_tile.hat
|
||||
print(layer)
|
||||
|
||||
space.w = layer
|
||||
|
||||
|
|
@ -387,15 +416,20 @@ func get_tile(pos: Vector4i) -> InsectTile:
|
|||
return used_cells.get(pos)
|
||||
|
||||
func _on_insect_tile_moved(tile: InsectTile, target: Vector4i) -> void:
|
||||
# Remove from old stack
|
||||
if tile.coordinates.w > 0:
|
||||
var below: Vector4i = tile.coordinates + Vector4i(0, 0, 0, -1)
|
||||
used_cells[below].hat = null
|
||||
|
||||
used_cells.erase(tile.coordinates)
|
||||
|
||||
var new_hex_pos = cube_to_world_pos(target)
|
||||
var sky_new_hex_pos = Vector3(new_hex_pos.x, 20.0, new_hex_pos.y)
|
||||
var ground_new_hex_pos = Vector3(new_hex_pos.x, target.w * layer_height, new_hex_pos.y)
|
||||
#
|
||||
|
||||
var current_hex_pos = tile.position
|
||||
var sky_current_hex_pos = tile.position + Vector3(0.0, 20.0, 0.0)
|
||||
#
|
||||
|
||||
var tween = get_tree().create_tween()
|
||||
tween.tween_property(tile, "position", sky_current_hex_pos, 0.5).set_ease(Tween.EASE_IN).set_trans(Tween.TRANS_EXPO)
|
||||
tween.tween_property(tile, "position", sky_new_hex_pos, 0.0)
|
||||
|
|
@ -404,6 +438,12 @@ func _on_insect_tile_moved(tile: InsectTile, target: Vector4i) -> void:
|
|||
tile.coordinates = target
|
||||
|
||||
used_cells[tile.coordinates] = tile
|
||||
|
||||
if tile.coordinates.w > 0:
|
||||
var below: Vector4i = tile.coordinates + Vector4i(0, 0, 0, -1)
|
||||
used_cells[below].hat = tile
|
||||
|
||||
# Add to new stack
|
||||
|
||||
func get_same_neighbours(cell1: Vector4i, cell2: Vector4i) -> Array[Vector4i]:
|
||||
var neighbours1 = get_neighbours(cell1).filter(is_cell_not_empty)
|
||||
|
|
@ -423,14 +463,17 @@ func is_position_on_hive(pos: Vector4i) -> bool:
|
|||
return get_empty_neighbours(pos).size() < 6
|
||||
|
||||
func can_hive_exist_without_tile(tile: InsectTile) -> bool:
|
||||
# TODO: BFS-Search from random cell to see if all other cells could still be reached when this
|
||||
if tile.coordinates.w != 0:
|
||||
return true
|
||||
|
||||
# TODO: BFS-Search from random cell to see if all other cells could still be reached when this
|
||||
# tile would be empty space
|
||||
if get_empty_neighbours(tile.coordinates).size() == 5: # we only have one real neighbour, so can't break anything
|
||||
return true
|
||||
|
||||
# DO BFS
|
||||
var tiles_reached: Array = []
|
||||
var tiles_available: Array = used_cells.keys().filter(func(coords): return coords != tile.coordinates).filter(func(coords): coords.w != tile.coordinates.w)
|
||||
var tiles_available: Array = used_cells.keys().filter(func(coords): return coords != tile.coordinates).filter(func(coords): return coords.w == 0)
|
||||
|
||||
if tiles_available.size() <= 1:
|
||||
# If we only have 1 or 2 total tiles, we can always move
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue