diff --git a/src/game/engine/scenes/tests/auto_play.gd b/src/game/engine/scenes/tests/auto_play.gd index f6020586..d5160312 100644 --- a/src/game/engine/scenes/tests/auto_play.gd +++ b/src/game/engine/scenes/tests/auto_play.gd @@ -404,34 +404,29 @@ func _try_attack_adjacent(unit: Variant, game_map: RefCounted) -> void: if nearby_enemies == 0: print(" no enemies within 2 hexes of %s" % unit.position) - # Check current hex AND adjacent hexes for enemies - var neighbors: Array[Vector2i] = HexUtilsScript.get_neighbors(unit.position) - neighbors.append(unit.position) # Also check same hex - for n: Vector2i in neighbors: - var norm: Vector2i = HexUtilsScript.normalize_position( - n, game_map.width, game_map.height, game_map.wrap_mode - ) - # Look for enemy unit at this position - for enemy: Variant in all_units: - if enemy.get("owner", -1) == player.index: - continue - if not enemy.is_alive(): - continue - if enemy.position == norm: - print(" ATTACKING: %s at %s -> enemy at %s" % [unit.type_id, unit.position, norm]) - var resolver_script: GDScript = load("res://engine/src/modules/combat/combat_resolver.gd") - var resolver: RefCounted = resolver_script.new() - resolver.resolve(unit, enemy, game_map, all_units) - unit.movement_remaining = 0 - return + # Find closest enemy unit or city within attack range (distance <= 1) + for enemy: Variant in all_units: + if enemy.get("owner") == player.index: + continue + if not enemy.is_alive(): + continue + var dist: int = HexUtilsScript.hex_distance(unit.position, enemy.position) + if dist <= 1: + print(" ATTACKING: %s at %s -> enemy at %s (dist=%d)" % [unit.type_id, unit.position, enemy.position, dist]) + var resolver_script: GDScript = load("res://engine/src/modules/combat/combat_resolver.gd") + var resolver: RefCounted = resolver_script.new() + resolver.resolve(unit, enemy, game_map, all_units) + unit.movement_remaining = 0 + return - # Also check for enemy city + # Check enemy cities for p: Variant in GameState.players: if p.index == player.index: continue for c: Variant in p.cities: - if HexUtilsScript.hex_distance(unit.position, c.position) <= 1: - print(" ATTACKING CITY: %s at %s -> city at %s" % [unit.type_id, unit.position, c.position]) + var dist: int = HexUtilsScript.hex_distance(unit.position, c.position) + if dist <= 1: + print(" ATTACKING CITY: %s at %s -> city at %s (dist=%d)" % [unit.type_id, unit.position, c.position, dist]) var resolver_script: GDScript = load("res://engine/src/modules/combat/combat_resolver.gd") var resolver: RefCounted = resolver_script.new() resolver.resolve(unit, c, game_map, all_units)