Files
Blockline/tests/bot_navigation.gd
T

65 lines
2.1 KiB
GDScript
Raw Normal View History

2026-09-12 11:01:37 +02:00
extends SceneTree
var failed := 0
var game: Node3D
func _initialize() -> void:
call_deferred("run")
func route_test(map_id: String, from: Vector3, to: Vector3) -> void:
game.select_map(map_id)
var p: Fighter = game.add_player(-1, "Route test", true, 0)
p.set_physics_process(false)
p.reset_at(from)
p.bot_target = to
p.bot_think = 1000
p.bot_path = game.bots.routes.path(from, to)
var arrived := false
for tick in 2100:
await physics_frame
game.bots.update(p, 1.0 / 60)
p.move_character(1.0 / 60)
if tick % 300 == 0: print("ROUTE ", map_id, " tick=", tick, " pos=", p.position, " next=", p.bot_path[0] if not p.bot_path.is_empty() else Vector3.INF)
if p.position.distance_to(to) < 0.85:
arrived = true
break
print("PASS " if arrived else "FAIL ", map_id, " stair route arrival ", p.position)
if not arrived: failed += 1
game.remove_player(-1)
await process_frame
func run() -> void:
create_timer(55).timeout.connect(func(): quit(2))
Engine.physics_ticks_per_second = 240
game = (load("res://scenes/main.tscn") as PackedScene).instantiate() as Node3D
root.add_child(game)
game.set_physics_process(false)
game.is_host = true
await physics_frame
await route_test("quarry", Vector3(-17, 0.15, 13.4), Vector3(-19.3, 7.4, 13.4))
await route_test("dust2", Vector3(-35, 5.0, 22), Vector3(-20, 8.15, 47))
# Opposing capsules meet in the same corridor and must pass each other.
var a: Fighter = game.add_player(-1, "A", true, 0)
var b: Fighter = game.add_player(-2, "B", true, 0)
for p in [a, b]:
p.set_physics_process(false)
p.team = 0
p.reset_at(Vector3(43, 5.1, -12 if p == a else -22))
p.bot_target = Vector3(43, 5.1, -22 if p == a else -12)
p.bot_think = 1000
p.bot_path = game.bots.routes.path(p.position, p.bot_target)
var passed := false
for tick in 900:
await physics_frame
for p in [a,b]:
game.bots.update(p, 1.0 / 60)
p.move_character(1.0 / 60)
if a.position.z < b.position.z - 2:
passed = true
break
print("PASS " if passed else "FAIL ", "opposing bots pass each other ", a.position, " / ", b.position)
if not passed: failed += 1
game.free()
print("BOT NAVIGATION failures=", failed)
quit(0 if failed == 0 else 1)