Fixed move penalty

This commit is contained in:
Sch1nken 2024-03-30 19:41:23 +01:00
parent e7baa34859
commit b42b1ae39f
3 changed files with 37 additions and 9 deletions

View file

@ -42,6 +42,19 @@ func get_targets(source_pos: Vector4i, map: HexGrid) -> Array[InsectTile]:
for neighbour in neighbours: for neighbour in neighbours:
var tile = map.get_tile(neighbour) var tile = map.get_tile(neighbour)
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
if tile != null: if tile != null:
if not tile.is_in_stack() and tile.can_move(): if not tile.is_in_stack() and tile.can_move():
if can_move_through(source_pos, neighbour, map): if can_move_through(source_pos, neighbour, map):

View file

@ -315,6 +315,9 @@ func _on_insect_tile_move_started(tile: InsectTile) -> void:
do_move(tile) do_move(tile)
func do_action(tile: InsectTile) -> void: func do_action(tile: InsectTile) -> void:
for child in placement_visualizer.get_children():
child.queue_free()
# get possible targets, pass the resource action callable with binds of source and target tile # 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) var targets = tile.get_action_behaviour().get_targets(tile.coordinates, self)
@ -331,13 +334,13 @@ func do_action(tile: InsectTile) -> void:
pass pass
func do_move_as(source: InsectTile, copy: InsectTile) -> void: func do_move_as(source: InsectTile, copy: InsectTile) -> void:
for child in placement_visualizer.get_children():
child.queue_free()
if not can_hive_exist_without_tile(source): if not can_hive_exist_without_tile(source):
print("Cant to do move as. Cant exist without hive") print("Cant to do move as. Cant exist without hive")
return return
for child in placement_visualizer.get_children():
child.queue_free()
var spaces = copy.get_movement_behaviour().get_available_spaces(source.coordinates, self) var spaces = copy.get_movement_behaviour().get_available_spaces(source.coordinates, self)
if spaces.is_empty(): if spaces.is_empty():
@ -390,6 +393,9 @@ func do_move_as(source: InsectTile, copy: InsectTile) -> void:
placements[space] = outline placements[space] = outline
func create_move_tiles(tile: InsectTile, coords: Array[Vector4i]) -> void: func create_move_tiles(tile: InsectTile, coords: Array[Vector4i]) -> void:
for child in placement_visualizer.get_children():
child.queue_free()
for space in coords: for space in coords:
var layer: int = 0 var layer: int = 0
var temp_tile: InsectTile = null var temp_tile: InsectTile = null
@ -516,6 +522,8 @@ func move_insect_tile(tile_coords: Vector4i, target: Vector4i) -> void:
tile.coordinates = target tile.coordinates = target
#tile.move_round_penalty = 2
used_cells[tile.coordinates] = tile used_cells[tile.coordinates] = tile
if tile.coordinates.w > 0: if tile.coordinates.w > 0:

View file

@ -103,6 +103,7 @@ func _ready() -> void:
GameEvents.insect_action_cancelled.connect(_on_action_cancelled) GameEvents.insect_action_cancelled.connect(_on_action_cancelled)
GameEvents.turn_started.connect(_on_turn_started) GameEvents.turn_started.connect(_on_turn_started)
GameEvents.turn_ended.connect(_on_turn_ended)
func _on_action_cancelled() -> void: func _on_action_cancelled() -> void:
selected_for_action = false selected_for_action = false
@ -124,18 +125,22 @@ func _on_selection_failed(tile: InsectTile) -> void:
# Show selection failed mat # Show selection failed mat
func _on_turn_started(turn_num: int, map: HexGrid, _is_blacks_turn: bool) -> void: func _on_turn_ended(turn_num: int, map: HexGrid) -> void:
is_blacks_turn = _is_blacks_turn move_round_penalty = move_round_penalty - 1
move_round_penalty -= 1
if move_round_penalty < 0: if move_round_penalty < 0:
move_round_penalty = 0 move_round_penalty = 0
func _on_turn_started(turn_num: int, map: HexGrid, _is_blacks_turn: bool) -> void:
is_blacks_turn = _is_blacks_turn
can_be_selected = GameData.bees_placed.has(is_black) can_be_selected = GameData.bees_placed.has(is_black)
#print(GameData.has_bee_been_placed) #print(GameData.has_bee_been_placed)
if turn_num >= 7 and not GameData.bees_placed.has(is_black): if turn_num >= 7 and not GameData.bees_placed.has(is_black):
can_be_selected = false can_be_selected = false
if not can_move():
can_be_selected = false
if can_be_selected: if can_be_selected:
tween_normal() tween_normal()
else: else:
@ -172,7 +177,7 @@ func _on_insect_tile_moved(tile: InsectTile, to: Vector4i) -> void:
action_callback = Callable() action_callback = Callable()
if tile == self: if tile == self:
move_round_penalty == 2 move_round_penalty = 1
func _on_insect_tile_deselected(tile: InsectTile) -> void: func _on_insect_tile_deselected(tile: InsectTile) -> void:
selected = false selected = false
@ -212,7 +217,6 @@ func _on_insect_placement_cancelled() -> void:
else: else:
tween_disabled() tween_disabled()
func _on_insect_selected(button: InsectButton, is_black: bool) -> void: func _on_insect_selected(button: InsectButton, is_black: bool) -> void:
deactivated = true deactivated = true
@ -229,6 +233,9 @@ func _input_event(camera, event, position, normal, shape_idx):
if not can_be_selected: if not can_be_selected:
return return
if not can_move():
return
#if not hovered: #if not hovered:
#return #return