Implemented Pillbug/Mosquito actions. Implemented pre-game settings. TODO: Game settings + bug testing

This commit is contained in:
Sch1nken 2024-03-30 01:43:38 +01:00
parent 397082f966
commit 2343638749
15 changed files with 477 additions and 70 deletions

View file

@ -293,7 +293,7 @@ func can_move(tile: InsectTile) -> bool:
if not can_hive_exist_without_tile(tile):
return false
var spaces = tile.resource.movement_behaviour.get_available_spaces(tile.coordinates, self)
var spaces = tile.get_movement_behaviour().get_available_spaces(tile.coordinates, self)
if spaces.is_empty():
return false
@ -301,10 +301,10 @@ func can_move(tile: InsectTile) -> bool:
return true
func has_action_targets(tile: InsectTile) -> bool:
if tile.resource.action_behaviour == null:
if tile.get_action_behaviour() == null:
return false
var targets: Array[InsectTile] = tile.resource.action_behaviour.get_targets(tile.coordinates, self)
var targets: Array[InsectTile] = tile.get_action_behaviour().get_targets(tile.coordinates, self)
return !targets.is_empty()
@ -315,13 +315,110 @@ func _on_insect_tile_move_started(tile: InsectTile) -> void:
do_move(tile)
func do_action(tile: InsectTile) -> void:
# get possible targets, pass the resource action callable with binds of source and target tile
var targets = tile.get_action_behaviour().get_targets(tile.coordinates, self)
for target in targets:
print("target?")
target.action_callback = tile.get_action_behaviour().do_action.bind(tile, target, self)
target.selected_for_action = true
target.highlight_for_action()
pass
pass
func do_move_as(source: InsectTile, copy: InsectTile) -> void:
if not can_hive_exist_without_tile(source):
print("Cant to do move as. Cant exist without hive")
return
for child in placement_visualizer.get_children():
child.queue_free()
var spaces = copy.get_movement_behaviour().get_available_spaces(source.coordinates, self)
if spaces.is_empty():
print("empty?")
#GameEvents.insect_tile_selection_request_failed.emit(tile)
return
for space in spaces:
var neighbours = get_neighbours(space)
var non_empty_neighbours = neighbours.filter(is_cell_not_empty)
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. (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 == source.coordinates:
# TODO: Check if this is stil correct?
continue
var layer: int = 0
var temp_tile: InsectTile = null
if is_cell_not_empty(space):
temp_tile = used_cells.get(space)
layer = 1
while temp_tile.hat != null:
layer += 1
temp_tile = temp_tile.hat
#print(layer)
space.w = layer
var outline = HEX_OUTLINE.instantiate()
var hex_pos = cube_to_world_pos(space) # flat_hex_to_world_position(AxialCoordinates.new(space.x, space.y))
outline.position = Vector3(hex_pos.x, layer * layer_height, hex_pos.y)
outline.coordinates = space
outline.visible = true
outline.insect_tile = source
outline.is_moving = true
outline.insect_resource = source.resource
outline.is_black = source.is_black
placement_visualizer.add_child(outline)
placements[space] = outline
func create_move_tiles(tile: InsectTile, coords: Array[Vector4i]) -> void:
for space in coords:
var layer: int = 0
var temp_tile: InsectTile = null
if is_cell_not_empty(space):
temp_tile = used_cells.get(space)
layer = 1
while temp_tile.hat != null:
layer += 1
temp_tile = temp_tile.hat
space.w = layer
var outline = HEX_OUTLINE.instantiate()
var hex_pos = cube_to_world_pos(space) # flat_hex_to_world_position(AxialCoordinates.new(space.x, space.y))
outline.position = Vector3(hex_pos.x, layer * layer_height, hex_pos.y)
outline.coordinates = space
outline.visible = true
outline.insect_tile = tile
outline.is_moving = true
outline.insect_resource = tile.resource
outline.is_black = tile.is_black
placement_visualizer.add_child(outline)
placements[space] = outline
func do_move(tile: InsectTile) -> void:
for child in placement_visualizer.get_children():
child.queue_free()
var spaces = tile.resource.movement_behaviour.get_available_spaces(tile.coordinates, self)
var spaces = tile.get_movement_behaviour().get_available_spaces(tile.coordinates, self)
if spaces.is_empty():
print("empty?")
@ -384,7 +481,7 @@ func _on_insect_tile_selected(tile: InsectTile) -> void:
return
else:
# if tile has an action
if tile.resource.action_behaviour != null:
if tile.get_action_behaviour() != null:
GameEvents.choose_action_or_move.emit(tile, has_action_targets(tile), can_move(tile))
return