update obstacles

This commit is contained in:
2025-03-21 11:44:12 +08:00
parent 50e5298009
commit 679961aa77
6 changed files with 323 additions and 327 deletions
+13 -44
View File
@@ -67,8 +67,8 @@ enum ActionState {
}
# Obstacle
# Add these properties to track the current obstacle direction
var current_obstacle_orientation = ObstacleOrientation.NORTH # Default to NORTH
# Add these properties to track current obstacle settings
var current_obstacle_orientation = ObstacleOrientation.NORTH
var current_obstacle_item = 12 # Starting with first obstacle item (12)
enum ObstacleDirection {
@@ -77,10 +77,10 @@ enum ObstacleDirection {
}
enum ObstacleOrientation {
NORTH = 0,
EAST = 1,
SOUTH = 2,
WEST = 3
NORTH = 0, # Blocks movement to the north (top)
EAST = 1, # Blocks movement to the east (right)
SOUTH = 2, # Blocks movement to the south (bottom)
WEST = 3 # Blocks movement to the west (left)
}
var current_action_state = ActionState.NONE
@@ -229,43 +229,6 @@ func set_action_state(new_state):
ActionState.PLACING_OBSTACLE:
local_player_character.highlight_valid_obstacle_cells()
# Update the place_obstacle function for floor 3
#func place_obstacle(grid_position: Vector2i):
#if not local_player_character or local_player_character.action_points < 1:
#return false
#
#var floor_index = 3 # Always place on floor 3
#var direction = EnhancedGridMap.Direction.BLOCKED_NORTH
#
#match current_obstacle_direction:
#ObstacleDirection.VERTICAL:
#direction = EnhancedGridMap.Direction.BLOCKED_NORTH # Block movement along east-west axis
#ObstacleDirection.HORIZONTAL:
#direction = EnhancedGridMap.Direction.BLOCKED_EAST # Block movement along north-south axis
#
#var success = $EnhancedGridMap.place_obstacle(
#Vector3i(grid_position.x, floor_index, grid_position.y),
#current_obstacle_item,
#direction
#)
#
#if success:
#local_player_character.action_points -= 1
#local_player_character.clear_highlights()
#
## Don't exit the obstacle placement mode to allow multiple placements
#local_player_character.highlight_valid_obstacle_cells()
#
## Exit obstacle placement mode and return to default state
#set_action_state(ActionState.NONE)
#
## Sync the obstacle with other clients
#if is_multiplayer_authority():
#rpc("sync_place_obstacle", grid_position.x, grid_position.y, floor_index, current_obstacle_item, direction)
#
#return true
#return false
func place_obstacle(grid_position: Vector2i):
if not local_player_character or local_player_character.action_points < 1:
return false
@@ -294,9 +257,15 @@ func place_obstacle(grid_position: Vector2i):
return true
return false
# Updated function to cycle through the four orientations
# Updated function to cycle through the four orientations
func cycle_obstacle_orientation():
var orientations = [ObstacleOrientation.NORTH, ObstacleOrientation.EAST, ObstacleOrientation.SOUTH, ObstacleOrientation.WEST]
var orientations = [
ObstacleOrientation.NORTH,
ObstacleOrientation.EAST,
ObstacleOrientation.SOUTH,
ObstacleOrientation.WEST
]
var current_index = orientations.find(current_obstacle_orientation)
current_index = (current_index + 1) % orientations.size()
current_obstacle_orientation = orientations[current_index]
+2 -2
View File
@@ -39,13 +39,13 @@ turn_based_mode = false
mesh_library = ExtResource("1_110wo")
cell_size = Vector3(1, 1, 1)
data = {
"cells": PackedInt32Array(0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 3, 0, 0, 4, 0, 0, 5, 0, 0, 6, 0, 0, 7, 0, 0, 8, 0, 0, 9, 0, 0, 10, 0, 0, 11, 0, 1, 0, 0, 1, 1, 0, 1, 2, 0, 1, 3, 0, 1, 4, 0, 1, 5, 0, 1, 6, 0, 1, 7, 0, 1, 8, 0, 1, 9, 0, 1, 10, 0, 1, 11, 0, 2, 0, 0, 2, 1, 0, 2, 2, 0, 2, 3, 0, 2, 4, 0, 2, 5, 0, 2, 6, 0, 2, 7, 0, 2, 8, 0, 2, 9, 0, 2, 10, 0, 2, 11, 0, 3, 0, 0, 3, 1, 0, 3, 2, 0, 3, 3, 0, 3, 4, 0, 3, 5, 0, 3, 6, 0, 3, 7, 0, 3, 8, 0, 3, 9, 0, 3, 10, 0, 3, 11, 0, 4, 0, 0, 4, 1, 0, 4, 2, 0, 4, 3, 0, 4, 4, 0, 4, 5, 0, 4, 6, 0, 4, 7, 0, 4, 8, 0, 4, 9, 0, 4, 10, 0, 4, 11, 0, 5, 0, 0, 5, 1, 0, 5, 2, 0, 5, 3, 0, 5, 4, 0, 5, 5, 0, 5, 6, 0, 5, 7, 0, 5, 8, 0, 5, 9, 0, 5, 10, 0, 5, 11, 0, 6, 0, 0, 6, 1, 0, 6, 2, 0, 6, 3, 0, 6, 4, 0, 6, 5, 0, 6, 6, 0, 6, 7, 0, 6, 8, 0, 6, 9, 0, 6, 10, 0, 6, 11, 0, 7, 0, 0, 7, 1, 0, 7, 2, 0, 7, 3, 0, 7, 4, 0, 7, 5, 0, 7, 6, 0, 7, 7, 0, 7, 8, 0, 7, 9, 0, 7, 10, 0, 7, 11, 0, 8, 0, 0, 8, 1, 0, 8, 2, 0, 8, 3, 0, 8, 4, 0, 8, 5, 0, 8, 6, 0, 8, 7, 0, 8, 8, 0, 8, 9, 0, 8, 10, 0, 8, 11, 0, 9, 0, 0, 9, 1, 0, 9, 2, 0, 9, 3, 0, 9, 4, 0, 9, 5, 0, 9, 6, 0, 9, 7, 0, 9, 8, 0, 9, 9, 0, 9, 10, 0, 9, 11, 0, 10, 0, 0, 10, 1, 0, 10, 2, 0, 10, 3, 0, 10, 4, 0, 10, 5, 0, 10, 6, 0, 10, 7, 0, 10, 8, 0, 10, 9, 0, 10, 10, 0, 10, 11, 0, 11, 0, 0, 11, 1, 0, 11, 2, 0, 11, 3, 0, 11, 4, 0, 11, 5, 0, 11, 6, 0, 11, 7, 0, 11, 8, 0, 11, 9, 0, 11, 10, 0, 11, 11, 0, 12, 0, 0, 12, 1, 0, 12, 2, 0, 12, 3, 0, 12, 4, 0, 12, 5, 0, 12, 6, 0, 12, 7, 0, 12, 8, 0, 12, 9, 0, 12, 10, 0, 12, 11, 0, 13, 0, 0, 13, 1, 0, 13, 2, 0, 13, 3, 0, 13, 4, 0, 13, 5, 0, 13, 6, 0, 13, 7, 0, 13, 8, 0, 13, 9, 0, 13, 10, 0, 13, 11, 0, 65537, 1, 9, 65537, 2, 9, 65537, 3, 10, 65537, 4, 7, 65537, 5, 10, 65537, 6, 7, 65537, 7, 7, 65537, 8, 8, 65537, 9, 7, 65537, 10, 10, 65537, 11, 8, 65538, 1, 8, 65538, 2, 8, 65538, 3, 10, 65538, 4, 8, 65538, 5, 10, 65538, 6, 8, 65538, 7, 9, 65538, 8, 9, 65538, 9, 7, 65538, 10, 7, 65538, 11, 9, 65539, 0, 8, 65539, 1, 9, 65539, 2, 7, 65539, 3, 10, 65539, 4, 9, 65539, 5, 7, 65539, 6, 8, 65539, 7, 9, 65539, 8, 7, 65539, 9, 7, 65539, 10, 7, 65539, 11, 9, 65540, 0, 9, 65540, 1, 9, 65540, 2, 10, 65540, 3, 8, 65540, 4, 9, 65540, 5, 10, 65540, 6, 7, 65540, 7, 10, 65540, 8, 9, 65540, 9, 10, 65540, 10, 9, 65540, 11, 10, 65541, 0, 8, 65541, 1, 8, 65541, 2, 8, 65541, 3, 10, 65541, 4, 7, 65541, 5, 9, 65541, 6, 8, 65541, 7, 10, 65541, 8, 9, 65541, 9, 8, 65541, 10, 10, 65541, 11, 9, 65542, 0, 7, 65542, 1, 8, 65542, 2, 9, 65542, 3, 10, 65542, 4, 9, 65542, 5, 10, 65542, 6, 10, 65542, 7, 7, 65542, 8, 7, 65542, 9, 10, 65542, 10, 7, 65542, 11, 7, 65543, 0, 9, 65543, 1, 8, 65543, 2, 10, 65543, 3, 7, 65543, 4, 7, 65543, 5, 10, 65543, 6, 9, 65543, 7, 8, 65543, 8, 9, 65543, 9, 7, 65543, 10, 7, 65543, 11, 9, 65544, 0, 7, 65544, 1, 7, 65544, 2, 10, 65544, 3, 10, 65544, 4, 7, 65544, 5, 7, 65544, 6, 9, 65544, 7, 10, 65544, 8, 7, 65544, 9, 7, 65544, 10, 8, 65544, 11, 9, 65545, 0, 9, 65545, 1, 10, 65545, 2, 9, 65545, 3, 9, 65545, 4, 9, 65545, 5, 9, 65545, 6, 9, 65545, 7, 9, 65545, 8, 10, 65545, 9, 7, 65545, 10, 7, 65545, 11, 9, 65546, 0, 8, 65546, 1, 8, 65546, 2, 7, 65546, 3, 10, 65546, 4, 7, 65546, 5, 9, 65546, 6, 9, 65546, 7, 9, 65546, 8, 7, 65546, 9, 9, 65546, 10, 10, 65546, 11, 10, 65547, 0, 10, 65547, 1, 8, 65547, 2, 7, 65547, 3, 8, 65547, 4, 10, 65547, 5, 7, 65547, 6, 10, 65547, 7, 7, 65547, 8, 10, 65547, 9, 8, 65547, 10, 7, 65547, 11, 8, 65548, 0, 7, 65548, 1, 9, 65548, 2, 10, 65548, 3, 9, 65548, 4, 7, 65548, 5, 9, 65548, 6, 8, 65548, 7, 10, 65548, 8, 10, 65548, 9, 8, 65548, 10, 9, 65548, 11, 9, 65538, 0, 10, 65537, 0, 7, 131075, 8, 524300, 131075, 7, 524300)
"cells": PackedInt32Array(0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 3, 0, 0, 4, 0, 0, 5, 0, 0, 6, 0, 0, 7, 0, 0, 8, 0, 0, 9, 0, 0, 10, 0, 0, 11, 0, 1, 0, 0, 1, 1, 0, 1, 2, 0, 1, 3, 0, 1, 4, 0, 1, 5, 0, 1, 6, 0, 1, 7, 0, 1, 8, 0, 1, 9, 0, 1, 10, 0, 1, 11, 0, 2, 0, 0, 2, 1, 0, 2, 2, 0, 2, 3, 0, 2, 4, 0, 2, 5, 0, 2, 6, 0, 2, 7, 0, 2, 8, 0, 2, 9, 0, 2, 10, 0, 2, 11, 0, 3, 0, 0, 3, 1, 0, 3, 2, 0, 3, 3, 0, 3, 4, 0, 3, 5, 0, 3, 6, 0, 3, 7, 0, 3, 8, 0, 3, 9, 0, 3, 10, 0, 3, 11, 0, 4, 0, 0, 4, 1, 0, 4, 2, 0, 4, 3, 0, 4, 4, 0, 4, 5, 0, 4, 6, 0, 4, 7, 0, 4, 8, 0, 4, 9, 0, 4, 10, 0, 4, 11, 0, 5, 0, 0, 5, 1, 0, 5, 2, 0, 5, 3, 0, 5, 4, 0, 5, 5, 0, 5, 6, 0, 5, 7, 0, 5, 8, 0, 5, 9, 0, 5, 10, 0, 5, 11, 0, 6, 0, 0, 6, 1, 0, 6, 2, 0, 6, 3, 0, 6, 4, 0, 6, 5, 0, 6, 6, 0, 6, 7, 0, 6, 8, 0, 6, 9, 0, 6, 10, 0, 6, 11, 0, 7, 0, 0, 7, 1, 0, 7, 2, 0, 7, 3, 0, 7, 4, 0, 7, 5, 0, 7, 6, 0, 7, 7, 0, 7, 8, 0, 7, 9, 0, 7, 10, 0, 7, 11, 0, 8, 0, 0, 8, 1, 0, 8, 2, 0, 8, 3, 0, 8, 4, 0, 8, 5, 0, 8, 6, 0, 8, 7, 0, 8, 8, 0, 8, 9, 0, 8, 10, 0, 8, 11, 0, 9, 0, 0, 9, 1, 0, 9, 2, 0, 9, 3, 0, 9, 4, 0, 9, 5, 0, 9, 6, 0, 9, 7, 0, 9, 8, 0, 9, 9, 0, 9, 10, 0, 9, 11, 0, 10, 0, 0, 10, 1, 0, 10, 2, 0, 10, 3, 0, 10, 4, 0, 10, 5, 0, 10, 6, 0, 10, 7, 0, 10, 8, 0, 10, 9, 0, 10, 10, 0, 10, 11, 0, 11, 0, 0, 11, 1, 0, 11, 2, 0, 11, 3, 0, 11, 4, 0, 11, 5, 0, 11, 6, 0, 11, 7, 0, 11, 8, 0, 11, 9, 0, 11, 10, 0, 11, 11, 0, 12, 0, 0, 12, 1, 0, 12, 2, 0, 12, 3, 0, 12, 4, 0, 12, 5, 0, 12, 6, 0, 12, 7, 0, 12, 8, 0, 12, 9, 0, 12, 10, 0, 12, 11, 0, 13, 0, 0, 13, 1, 0, 13, 2, 0, 13, 3, 0, 13, 4, 0, 13, 5, 0, 13, 6, 0, 13, 7, 0, 13, 8, 0, 13, 9, 0, 13, 10, 0, 13, 11, 0, 65537, 1, 9, 65537, 2, 9, 65537, 3, 10, 65537, 4, 7, 65537, 5, 10, 65537, 6, 7, 65537, 7, 7, 65537, 8, 8, 65537, 9, 7, 65537, 10, 10, 65537, 11, 8, 65538, 1, 8, 65538, 2, 8, 65538, 3, 10, 65538, 4, 8, 65538, 5, 10, 65538, 6, 8, 65538, 7, 9, 65538, 8, 9, 65538, 9, 7, 65538, 10, 7, 65538, 11, 9, 65539, 0, 8, 65539, 1, 9, 65539, 2, 7, 65539, 3, 10, 65539, 4, 9, 65539, 5, 7, 65539, 6, 8, 65539, 8, 7, 65539, 9, 7, 65539, 10, 7, 65539, 11, 9, 65540, 0, 9, 65540, 1, 9, 65540, 2, 10, 65540, 3, 8, 65540, 4, 9, 65540, 5, 10, 65540, 6, 7, 65540, 7, 10, 65540, 8, 9, 65540, 9, 10, 65540, 10, 9, 65540, 11, 10, 65541, 0, 8, 65541, 1, 8, 65541, 2, 8, 65541, 3, 10, 65541, 4, 7, 65541, 5, 9, 65541, 6, 8, 65541, 7, 10, 65541, 8, 9, 65541, 9, 8, 65541, 10, 10, 65541, 11, 9, 65542, 0, 7, 65542, 1, 8, 65542, 2, 9, 65542, 3, 10, 65542, 4, 9, 65542, 5, 10, 65542, 6, 10, 65542, 7, 7, 65542, 8, 7, 65542, 9, 10, 65542, 10, 7, 65542, 11, 7, 65543, 0, 9, 65543, 1, 8, 65543, 2, 10, 65543, 3, 7, 65543, 4, 7, 65543, 5, 10, 65543, 6, 9, 65543, 7, 8, 65543, 8, 9, 65543, 9, 7, 65543, 10, 7, 65543, 11, 9, 65544, 0, 7, 65544, 1, 7, 65544, 2, 10, 65544, 3, 10, 65544, 4, 7, 65544, 5, 7, 65544, 6, 9, 65544, 7, 10, 65544, 8, 7, 65544, 9, 7, 65544, 10, 8, 65544, 11, 9, 65545, 0, 9, 65545, 1, 10, 65545, 2, 9, 65545, 3, 9, 65545, 4, 9, 65545, 5, 9, 65545, 6, 9, 65545, 7, 9, 65545, 8, 10, 65545, 9, 7, 65545, 10, 7, 65545, 11, 9, 65546, 0, 8, 65546, 1, 8, 65546, 2, 7, 65546, 3, 10, 65546, 4, 7, 65546, 5, 9, 65546, 6, 9, 65546, 7, 9, 65546, 8, 7, 65546, 9, 9, 65546, 10, 10, 65546, 11, 10, 65547, 0, 10, 65547, 1, 8, 65547, 2, 7, 65547, 3, 8, 65547, 4, 10, 65547, 5, 7, 65547, 6, 10, 65547, 7, 7, 65547, 8, 10, 65547, 9, 8, 65547, 10, 7, 65547, 11, 8, 65548, 0, 7, 65548, 1, 9, 65548, 2, 10, 65548, 3, 9, 65548, 4, 7, 65548, 5, 9, 65548, 6, 8, 65548, 7, 10, 65548, 8, 10, 65548, 9, 8, 65548, 10, 9, 65548, 11, 9, 65538, 0, 10, 65537, 0, 7, 65539, 7, 9)
}
script = ExtResource("2_hbe1v")
columns = 14
rows = 12
obstacle_items = Array[int]([12])
metadata/_editor_floor_ = Vector3(0, 2, 0)
metadata/_editor_floor_ = Vector3(0, -2, 0)
[node name="Camera3D" type="Camera3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 0.422618, 0.906308, 0, -0.906308, 0.422618, 7, 26, 17)
+187 -28
View File
@@ -844,50 +844,209 @@ func highlight_cells_if_authorized(cells_to_highlight: Array):
enhanced_gridmap.hover_item
)
# Modify highlight functions to use the new authorized highlight method
## Update highlight_movement_range to respect obstacle blocking
#func highlight_movement_range():
#if not is_multiplayer_authority() or is_bot or is_in_group("Bots"):
#return
#
#clear_highlights()
#var cells_to_highlight = []
#
## Get neighboring cells that are directly accessible (not blocked by obstacles)
#var direct_neighbors = []
#var directions = [
#Vector2i(0, -1), # North
#Vector2i(1, 0), # East
#Vector2i(0, 1), # South
#Vector2i(-1, 0), # West
#]
#
## Add diagonal directions if enabled
#if enhanced_gridmap.diagonal_movement:
#directions.append(Vector2i(-1, -1)) # Northwest
#directions.append(Vector2i(1, -1)) # Northeast
#directions.append(Vector2i(-1, 1)) # Southwest
#directions.append(Vector2i(1, 1)) # Southeast
#
## First, get direct neighbors that aren't blocked
#for dir in directions:
#var neighbor_pos = current_position + dir
#
## Check if position is valid and walkable
#if enhanced_gridmap.is_position_valid(neighbor_pos) and \
#enhanced_gridmap.is_cell_walkable(neighbor_pos, 0) and \
#not is_position_occupied(neighbor_pos):
#
## Check if movement is blocked by obstacle
#if not enhanced_gridmap.is_movement_blocked(current_position, neighbor_pos, 3):
#direct_neighbors.append(neighbor_pos)
#
## Now, add all cells that are within movement range
## and can be reached via the direct neighbors
#for x in range(max(0, current_position.x - movement_range),
#min(enhanced_gridmap.columns, current_position.x + movement_range + 1)):
#for z in range(max(0, current_position.y - movement_range),
#min(enhanced_gridmap.rows, current_position.y + movement_range + 1)):
#var test_pos = Vector2i(x, z)
#
## Skip the current position
#if test_pos == current_position:
#continue
#
## Check if within movement range
#if is_within_movement_range(test_pos):
#var cell_item = enhanced_gridmap.get_cell_item(Vector3i(x, 0, z))
#
## Basic walkability check
#if cell_item != -1 and not (cell_item in enhanced_gridmap.non_walkable_items) and \
#not is_position_occupied(test_pos):
#
## Check if we can reach this position through one of our direct neighbors
#var can_reach = false
#
## Direct neighbors are always reachable
#if test_pos in direct_neighbors:
#can_reach = true
#else:
## For other cells, check if there's a valid path through direct neighbors
#for neighbor in direct_neighbors:
## Check if we can move from the neighbor to the target position
## without being blocked by an obstacle
#if not enhanced_gridmap.is_blocked_by_obstacle(neighbor, test_pos, 3):
#var manhattan_dist = abs(neighbor.x - test_pos.x) + abs(neighbor.y - test_pos.y)
#var remaining_range = movement_range - 1 # -1 for the first step
#
## Check if the remaining distance is within our movement range
#if manhattan_dist <= remaining_range:
#can_reach = true
#break
#
#if can_reach:
#cells_to_highlight.append(test_pos)
#
#highlight_cells_if_authorized(cells_to_highlight)
# Update highlight_movement_range to respect the expanded obstacle blocking
func highlight_movement_range():
if not is_multiplayer_authority() or is_bot or is_in_group("Bots"):
return
clear_highlights()
var cells_to_highlight = []
# For each position within movement range
for x in range(max(0, current_position.x - movement_range), min(enhanced_gridmap.columns, current_position.x + movement_range + 1)):
for z in range(max(0, current_position.y - movement_range), min(enhanced_gridmap.rows, current_position.y + movement_range + 1)):
# First, identify all cells that are blocked by obstacles
var blocked_cells = []
# Check all cells for obstacles and get their blocked cells
for x in range(enhanced_gridmap.columns):
for z in range(enhanced_gridmap.rows):
var cell_pos = Vector2i(x, z)
var cell_pos3d = Vector3i(x, 3, z)
if enhanced_gridmap.has_obstacle_at(cell_pos3d):
var orientation = enhanced_gridmap.get_obstacle_orientation(cell_pos3d)
blocked_cells.append_array(enhanced_gridmap.get_cells_blocked_by_obstacle(cell_pos, orientation, 3))
# Now highlight all cells within movement range that aren't blocked
for x in range(max(0, current_position.x - movement_range),
min(enhanced_gridmap.columns, current_position.x + movement_range + 1)):
for z in range(max(0, current_position.y - movement_range),
min(enhanced_gridmap.rows, current_position.y + movement_range + 1)):
var test_pos = Vector2i(x, z)
# Skip the current position
# Skip current position
if test_pos == current_position:
continue
# Check if within movement range
if is_within_movement_range(test_pos):
var cell_item = enhanced_gridmap.get_cell_item(Vector3i(x, 0, z))
# Skip if blocked by obstacle
if test_pos in blocked_cells:
continue
# Basic walkability check
if cell_item != -1 and not (cell_item in enhanced_gridmap.non_walkable_items) and not is_position_occupied(test_pos):
# Check if there's a direct path without obstacles
var path_blocked = false
# For orthogonal movement
if test_pos.x == current_position.x or test_pos.y == current_position.y:
path_blocked = enhanced_gridmap.is_blocked_by_obstacle(current_position, test_pos, 3)
else:
# For diagonal movement, check if both orthogonal paths are blocked
var mid1 = Vector2i(test_pos.x, current_position.y)
var mid2 = Vector2i(current_position.x, test_pos.y)
var path1_blocked = enhanced_gridmap.is_blocked_by_obstacle(current_position, mid1, 3)
var path2_blocked = enhanced_gridmap.is_blocked_by_obstacle(current_position, mid2, 3)
# Only completely block if both paths are blocked
path_blocked = path1_blocked and path2_blocked
if not path_blocked:
cells_to_highlight.append(test_pos)
# Check basic walkability
var cell_item = enhanced_gridmap.get_cell_item(Vector3i(x, 0, z))
if cell_item == -1 or cell_item in enhanced_gridmap.non_walkable_items or is_position_occupied(test_pos):
continue
# Check if there's a valid path to this cell
if can_reach_cell(test_pos, blocked_cells):
cells_to_highlight.append(test_pos)
highlight_cells_if_authorized(cells_to_highlight)
# Helper function to check if a cell can be reached given the blocked cells
func can_reach_cell(target_pos: Vector2i, blocked_cells: Array) -> bool:
# Simple BFS to find if there's a path
var queue = [current_position]
var visited = {current_position: true}
var steps = {current_position: 0}
while not queue.is_empty():
var current = queue.pop_front()
# If we've found the target, check if it's within movement range
if current == target_pos:
return steps[current] <= movement_range
# If we've used all movement, don't explore further
if steps[current] >= movement_range:
continue
# Try all adjacent cells
var directions = [
Vector2i(0, -1), # North
Vector2i(1, 0), # East
Vector2i(0, 1), # South
Vector2i(-1, 0), # West
]
# Add diagonal directions if enabled
if enhanced_gridmap.diagonal_movement:
directions.append(Vector2i(-1, -1)) # Northwest
directions.append(Vector2i(1, -1)) # Northeast
directions.append(Vector2i(-1, 1)) # Southwest
directions.append(Vector2i(1, 1)) # Southeast
for dir in directions:
var next_pos = current + dir
# Skip if already visited, blocked, or not valid
if visited.has(next_pos) or next_pos in blocked_cells:
continue
if not enhanced_gridmap.is_position_valid(next_pos) or not enhanced_gridmap.is_cell_walkable(next_pos, 0):
continue
if is_position_occupied(next_pos) and next_pos != target_pos:
continue
# Check if movement between cells is blocked by an obstacle
if not is_diagonal_direction(dir) and enhanced_gridmap.is_movement_blocked(current, next_pos, 3):
continue
# For diagonal movement, check if both orthogonal paths are blocked
if is_diagonal_direction(dir):
var mid1 = Vector2i(next_pos.x, current.y)
var mid2 = Vector2i(current.x, next_pos.y)
var path1_blocked = mid1 in blocked_cells or enhanced_gridmap.is_movement_blocked(current, mid1, 3)
var path2_blocked = mid2 in blocked_cells or enhanced_gridmap.is_movement_blocked(current, mid2, 3)
if path1_blocked and path2_blocked:
continue
# Add to queue
queue.append(next_pos)
visited[next_pos] = true
steps[next_pos] = steps[current] + 1
return false
# Helper function to check if a direction is diagonal
func is_diagonal_direction(direction: Vector2i) -> bool:
return direction.x != 0 and direction.y != 0
func highlight_adjacent_cells():
if not is_multiplayer_authority() or is_bot or is_in_group("Bots"):
return