extends RefCounted var failures=0 func check(value,label): if not value:failures+=1;push_error("DELIVERY QA: "+label) func soul(g): g.workshop.spawn();var s=g.souls.back();s.required=[0];s.served=[];s.entering=false;s.entry_time=1;return s func run(g): await g.get_tree().create_timer(.3).timeout g.start_game();g.paused=true var w=g.workshop for s in g.souls:s.node.queue_free() g.souls.clear();w.reset();w.unlock=5 var first=w.add_station(0,Vector3(1,0,0));var other=w.add_station(0,Vector3(5,0,0));w.rebuild_nav();w.add_helper() var carried=soul(g);var manual=soul(g) w.helpers[0].root.position=Vector3(-4,0,4) w.update_helpers(.001) var h=w.helpers[0] check(h.soul==carried.id and first.reserved==0,"helper reserves destination in advance") w.sentences.pickup(manual);g.player.position=w.approach(first) check(w.try_player_attach(0),"player arriving first can place despite helper reservation") check(first.soul==manual.id and g.held==-1,"manual placement commits once and clears carried selection") check(h.station==1 and other.reserved==0 and first.reserved==-1,"helper reroutes to alternative and releases old reservation") check(h.soul==carried.id and h.state=="collect" and carried.state=="reserved","rerouting before collection preserves the assigned soul") # The same conflict after collection, with no alternative available. h.state="deliver";carried.state="transit";w.sentences.float_pose(carried) var second_manual=soul(g);w.sentences.pickup(second_manual);g.player.position=w.approach(other) check(w.try_player_attach(1),"first arrival also overrides a helper already transporting") check(h.station==-1 and h.state=="deliver" and h.soul==carried.id and carried.state=="transit","no alternate: helper keeps soul and waits") w.update_helpers(.01) check(first.soul==manual.id and other.soul==second_manual.id and h.soul==carried.id,"waiting helper cannot overwrite an occupied apparatus") var rejected=soul(g);w.sentences.pickup(rejected) check(not w.try_player_attach(1) and g.held==rejected.id,"occupied apparatus cannot be stolen by player") w.drop_held() # Vacate the first device and ensure the waiting delivery resumes. first.soul=-1;manual.node.queue_free();g.souls.erase(manual) w.update_helpers(.001) check(h.station==0 and first.reserved==0,"waiting helper retries when an apparatus becomes available") h.root.position=w.approach(first);h.path=PackedVector2Array();h.destination=w.cell(w.approach(first));h.revision=w.revision w.update_helpers(.001) check(first.soul==carried.id and h.soul==-1 and h.state=="idle","delivery resumes without loss or duplicate assignment") check(g.souls.filter(func(s):return s.id==carried.id).size()==1,"rerouting does not duplicate souls") if failures==0:print("ALL DELIVERY PRIORITY TESTS PASSED: first arrival, collect/deliver reroutes, waiting, retry, occupied protection, no lost or duplicate souls") g.get_tree().quit(1 if failures else 0)