Fix hex grid support for movement, channeling range, and terramorpha
Movement (_bfs_path): was using 4 square directions for pathfinding, causing units on hex grids to take indirect multi-step routes when a single diagonal step exists. Now uses 6 hex dirs when grid is Hexagon. Channeling (_valid_play_tiles Spirit): was using Manhattan distance instead of hex cube distance, producing a diamond-shaped channel range on hex boards. Now delegates to _board_distance for both grid types. Terramorpha (three fixes): - Initial valid-play highlights now filter by _tile_bodies so only real tiles are highlighted (not every grid position in the bbox) - Adjacency validation for Di/Tri multi-pick now uses _board_distance instead of abs(dx)+abs(dy), enabling all 6 hex neighbours - Next-pick highlight loop now uses 6 hex dirs and guards with _tile_bodies check, consistent with the reachability BFS Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
@@ -1344,7 +1344,7 @@ func _try_load_tile_bottom(body_ref: Variant, url: String) -> void:
|
||||
|
||||
# Scale to fit the tile footprint. Now that the node is in the tree,
|
||||
# the internal _model_local_aabb call returns a valid AABB.
|
||||
_fit_model_to_tile(bottom_node, 0.98)
|
||||
_fit_model_to_tile(bottom_node, 0.75)
|
||||
|
||||
# After _fit_model_to_tile: the model's AABB bottom (spike tip) is at
|
||||
# body-local Y=0 and the AABB top (wide base) is at body-local Y = scaled_h.
|
||||
@@ -2160,7 +2160,7 @@ func _update_prev_state(state: Dictionary) -> void:
|
||||
(pd as Dictionary).get("y", 0))
|
||||
|
||||
|
||||
## 4-directional BFS on the game grid.
|
||||
## BFS on the game grid using the correct neighbour set for the current grid type.
|
||||
## blocked: Dictionary[Vector2i → true] of impassable tiles;
|
||||
## the destination 'to' is always reachable regardless.
|
||||
## Returns the path steps NOT including 'from', including 'to'.
|
||||
@@ -2170,7 +2170,12 @@ func _bfs_path(from: Vector2i, to: Vector2i, blocked: Dictionary) -> Array[Vecto
|
||||
return []
|
||||
var bw := Game.board_width()
|
||||
var bh := Game.board_height()
|
||||
var DIRS : Array[Vector2i] = [Vector2i(1,0), Vector2i(-1,0), Vector2i(0,1), Vector2i(0,-1)]
|
||||
var DIRS : Array[Vector2i]
|
||||
if _board_grid_type == "Hexagon":
|
||||
DIRS = [Vector2i(1,0), Vector2i(-1,0), Vector2i(0,1), Vector2i(0,-1),
|
||||
Vector2i(1,-1), Vector2i(-1,1)]
|
||||
else:
|
||||
DIRS = [Vector2i(1,0), Vector2i(-1,0), Vector2i(0,1), Vector2i(0,-1)]
|
||||
var visited : Dictionary = {from: true}
|
||||
# Queue entries: [pos: Vector2i, path: Array[Vector2i]]
|
||||
var queue : Array = [[from, []]]
|
||||
@@ -2505,7 +2510,7 @@ func _valid_play_tiles(card: Dictionary) -> Array:
|
||||
for tx in range(bw):
|
||||
for ty in range(bh):
|
||||
if not _tile_bodies.has("%d,%d" % [tx, ty]): continue
|
||||
var dist : int = abs(tx - ax) + abs(ty - ay)
|
||||
var dist : int = _board_distance(tx, ty, ax, ay)
|
||||
if dist < min_r or dist > max_r: continue
|
||||
var tile : Dictionary = Game.get_tile(tx, ty)
|
||||
if tile.get("occupantId"): continue
|
||||
@@ -2515,6 +2520,7 @@ func _valid_play_tiles(card: Dictionary) -> Array:
|
||||
"Terramorpha":
|
||||
for tx in range(bw):
|
||||
for ty in range(bh):
|
||||
if not _tile_bodies.has("%d,%d" % [tx, ty]): continue
|
||||
results.append(Vector2i(tx, ty))
|
||||
|
||||
"Repentance", "Instinct", "Ruin":
|
||||
@@ -2908,7 +2914,7 @@ func _handle_board_click(mouse_pos: Vector2) -> void:
|
||||
if _terra_targets.size() > 0:
|
||||
print("_terra_targets: ", _terra_targets.size())
|
||||
var last : Vector2i = _terra_targets.back()
|
||||
if abs(coord.x - last.x) + abs(coord.y - last.y) != 1:
|
||||
if _board_distance(coord.x, coord.y, last.x, last.y) != 1:
|
||||
return # must be adjacent
|
||||
# Avoid duplicates.
|
||||
print("Handle Board Click: terra targets: ", _terra_targets)
|
||||
@@ -2931,10 +2937,17 @@ func _handle_board_click(mouse_pos: Vector2) -> void:
|
||||
var last2 : Vector2i = _terra_targets.back()
|
||||
var bw2 := Game.board_width()
|
||||
var bh2 := Game.board_height()
|
||||
for d: Vector2i in [Vector2i(1,0), Vector2i(-1,0), Vector2i(0,1), Vector2i(0,-1)]:
|
||||
var terra_dirs : Array[Vector2i]
|
||||
if _board_grid_type == "Hexagon":
|
||||
terra_dirs = [Vector2i(1,0), Vector2i(-1,0), Vector2i(0,1), Vector2i(0,-1),
|
||||
Vector2i(1,-1), Vector2i(-1,1)]
|
||||
else:
|
||||
terra_dirs = [Vector2i(1,0), Vector2i(-1,0), Vector2i(0,1), Vector2i(0,-1)]
|
||||
for d: Vector2i in terra_dirs:
|
||||
var nx := last2.x + d.x
|
||||
var ny := last2.y + d.y
|
||||
if nx < 0 or ny < 0 or nx >= bw2 or ny >= bh2: continue
|
||||
if not _tile_bodies.has("%d,%d" % [nx, ny]): continue
|
||||
if _terra_targets.has(Vector2i(nx, ny)): continue
|
||||
_add_highlight(nx, ny, "movement")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user