fix: Improve corridor generation logic to ensure minimum segment length
This commit is contained in:
+29
-4
@@ -115,17 +115,42 @@ func _get_manhattan_points(start: Vector2i, end: Vector2i, v_first: bool) -> Arr
|
||||
var pts: Array[Vector2i] = []
|
||||
var x_step: int = sign(end.x - start.x) if end.x != start.x else 1
|
||||
var y_step: int = sign(end.y - start.y) if end.y != start.y else 1
|
||||
var min_len: int = 2 # Minimum segment length before changing direction
|
||||
|
||||
if v_first:
|
||||
for y in range(start.y, end.y + y_step, y_step):
|
||||
var y_len: int = abs(end.y - start.y)
|
||||
var y_end: int = start.y
|
||||
if y_len < min_len:
|
||||
y_end = start.y + y_step * min_len
|
||||
# Clamp to end.y if overshoot
|
||||
if (y_step > 0 and y_end > end.y) or (y_step < 0 and y_end < end.y):
|
||||
y_end = end.y
|
||||
else:
|
||||
y_end = end.y
|
||||
for y in range(start.y, y_end + y_step, y_step):
|
||||
pts.append(Vector2i(start.x, y))
|
||||
for x in range(start.x + x_step, end.x + x_step, x_step):
|
||||
pts.append(Vector2i(x, end.y))
|
||||
pts.append(Vector2i(x, y_end))
|
||||
# If y_end != end.y, finish remaining y segment
|
||||
if y_end != end.y:
|
||||
for y in range(y_end + y_step, end.y + y_step, y_step):
|
||||
pts.append(Vector2i(end.x, y))
|
||||
else:
|
||||
for x in range(start.x, end.x + x_step, x_step):
|
||||
var x_len: int = abs(end.x - start.x)
|
||||
var x_end: int = start.x
|
||||
if x_len < min_len:
|
||||
x_end = start.x + x_step * min_len
|
||||
if (x_step > 0 and x_end > end.x) or (x_step < 0 and x_end < end.x):
|
||||
x_end = end.x
|
||||
else:
|
||||
x_end = end.x
|
||||
for x in range(start.x, x_end + x_step, x_step):
|
||||
pts.append(Vector2i(x, start.y))
|
||||
for y in range(start.y + y_step, end.y + y_step, y_step):
|
||||
pts.append(Vector2i(end.x, y))
|
||||
pts.append(Vector2i(x_end, y))
|
||||
if x_end != end.x:
|
||||
for x in range(x_end + x_step, end.x + x_step, x_step):
|
||||
pts.append(Vector2i(x, end.y))
|
||||
return pts
|
||||
|
||||
# Returns true if the corridor path does not violate the 2-tile gap rule between rooms.
|
||||
|
||||
Reference in New Issue
Block a user