feat: Add EnhancedGridMap for dynamic grid generation, pathfinding, and network synchronization, and introduce core game scripts for Tekton entities and managers.

This commit is contained in:
Yogi Wiguna
2026-02-13 13:14:37 +08:00
parent 0ee5051ebd
commit ad16f5942b
9 changed files with 354 additions and 75 deletions
+36 -13
View File
@@ -393,30 +393,22 @@ func _try_move() -> bool:
# Extract immediate next step from path
next_step = Vector2i(path[1].x, path[1].y)
else:
# Fallback: Pathfinding failed or target is too close?
# Fallback: Pathfinding failed or target is too close?
# Check if target is adjacent and we can move directly
var dist = abs(final_target.x - actor.current_position.x) + abs(final_target.y - actor.current_position.y)
if dist == 1:
next_step = final_target
else:
return false
# Redundant safety check (simple_move_to also checks this)
# Removed to allow PUSHING mechanics (simple_move_to handles occupancy/pushing)
# if actor.is_position_occupied(next_step):
# return false
# PATHFINDING FAILED! (Likely stuck on wall/stand)
# Attempt UNSTUCK move to any adjacent valid tile
print("[BotController] Pathfinding failed for %s. Attempting UNSTUCK move." % actor.name)
return await _try_unstuck_move()
# Execute SINGLE STEP movement using player manager
if actor.movement_manager.simple_move_to(next_step):
_is_processing_action = true
_current_action = "moving"
# Wait for movement to finish or timeout (safety)
# Race: Signal vs Timeout
# Since Godot 4 doesn't support 'await' racing easily without helper,
# we'll just wait for the signal but ensure movement manager emits it.
# safer approach: check if is_moving goes false
# Safety timeout to prevent infinite loop
var max_wait_time = 2.0
var elapsed = 0.0
@@ -435,6 +427,37 @@ func _try_move() -> bool:
return false
func _try_unstuck_move() -> bool:
"""Randomly move to ANY adjacent valid tile to escape sticky situations."""
var neighbors = enhanced_gridmap.get_neighbors(actor.current_position, 0)
neighbors.shuffle() # Randomize to avoid oscillating
for n in neighbors:
if not n.is_walkable: continue
var cell = Vector3i(n.position.x, 0, n.position.y) # Check Floor 0
var item = enhanced_gridmap.get_cell_item(cell)
# Ensure we don't walk into a wall (Item 4) or Void (-1)
# Obstacles should be checked by is_walkable but let's be sure
if item == 4 or item == -1: continue
# Attempt move
if actor.movement_manager.simple_move_to(n.position):
_is_processing_action = true
_current_action = "moving_unstuck"
print("[BotController] Unstuck move to %s" % n.position)
# Wait for move
await _wait_with_variance(action_delay)
if not is_instance_valid(self): return true
_is_processing_action = false
_current_action = "idle"
return true
print("[BotController] %s is TRULY stuck! No valid neighbors." % actor.name)
return false
# =============================================================================
# Put Tiles Back
# =============================================================================