<!-- SAGA-STAGING · part 94 -->
d.z)<.001);reset();R.calculateShadowMotion(.05,{moveX:1,moveZ:1},0,new THREE.Vector3());t("DIAGONAL NORMALIZED",Math.abs(S.desired.length()-R.physics.walkSpeed)<.001);reset();R.calculateShadowMotion(.05,{moveX:0,moveZ:1},Math.PI/2,new THREE.Vector3());t("CAMERA ROTATION",Math.abs(S.desired.z+R.physics.walkSpeed)<.001&&Math.abs(S.desired.x)<.001);t("ACCEL BOUNDED",S.velocity.length()<=R.physics.acceleration*.05+.001);var moving=S.velocity.length();R.calculateShadowMotion(.05,{moveX:0,moveZ:0},0,new THREE.Vector3());t("BRAKING",S.velocity.length()<moving);reset();var base=new THREE.Vector3(10,5,20);R.calculateShadowMotion(.05,{moveX:0,moveZ:1},0,base);t("PREDICTION MOVES",S.predicted.distanceTo(base)>0);t("PREDICTION KEEPS Y",Math.abs(S.predicted.y-base.y)<.001);t("NO KINGPOS WRITE",real.distanceTo(kingPos)<.0001);t("AUTHORITY LEGACY",R.authority==="legacy"&&R.enabled===false);var n=r.filter(function(x){return x.indexOf("PASS")===0;}).length;R.debug.showingTest=true;if(!R.debug.mobile)R.toggleDebug();R.debugElement.textContent="AI SHADOW MOTION TEST v206\n\n"+r.join("\n")+"\n\n"+n+" / "+r.length+" PASS\n\nDESIRED SPEED  "+S.desired.length().toFixed(2)+"\nSHADOW SPEED   "+S.velocity.length().toFixed(2)+"\nREAL PLAYER    UNCHANGED\nAUTHORITY      "+String(R.authority).toUpperCase();}};
    CODES.airtest = {cat:"Special",desc:"Run V205 synthetic airborne test",fn:function(){var R=window.ACTOR_RUNTIME,real=kingPos.clone(),virtualPos=kingPos.clone();virtualPos.y+=100;var P=R.senseWorld(virtualPos),r=[];function t(n,v){r.push((v?"PASS  ":"FAIL  ")+n);}t("VIRTUAL POSITION",virtualPos.y===real.y+100);t("NO LOCAL SUPPORT",P.support===false);t("NOT GROUNDED",P.grounded===false);t("AIRBORNE",P.airborne===true);t("NOT SAFE",P.safeStand===false&&P.safeSave===false);t("NO SURFACE",P.surface==="NONE");t("NO GROUND Y",P.groundY===null);t("NO DELTA",P.delta===null);t("NO KINGPOS WRITE",real.distanceTo(kingPos)<0.0001);t("AUTHORITY LEGACY",R.authority==="legacy"&&R.enabled===false);var n=r.filter(function(x){return x.indexOf("PASS")===0;}).length;R.debug.showingTest=true;if(!R.debug.mobile)R.toggleDebug();R.debugElement.textContent="AI AIRBORNE SELF TEST v205\n\n"+r.join("\n")+"\n\n"+n+" / "+r.length+" PASS\n\nVIRTUAL HEIGHT  +100\nSUPPORT   "+(P.support?"YES":"NO")+"\nGROUNDED  "+(P.grounded?"YES":"NO")+"\nAIRBORNE  "+(P.airborne?"YES":"NO")+"\nSAFE      "+(P.safeStand?"YES":"NO")+"\n\nREAL PLAYER UNCHANGED\nMOVEMENT AUTHORITY  "+String(R.authority).toUpperCase();}};
    CODES.perceptiontest = {cat:"Special",desc:"Run V205 perception self-test",fn:function(){var R=window.ACTOR_RUNTIME,P=R&&R.senseWorld?R.senseWorld():null,pos=(typeof kingPos!=="undefined"&&kingPos)?kingPos.clone():null,r=[];function t(n,v){r.push((v?"PASS  ":"FAIL  ")+n);}t("PERCEPTION API",!!(R&&R.senseWorld));t("FOUNDATION LINK",!!window.WORLD_FOUNDATION);t("POSITION READ",!!pos);t("SUPPORT BOOLEAN",!!P&&typeof P.support==="boolean");t("GROUNDED BOOLEAN",!!P&&typeof P.grounded==="boolean");t("AIRBORNE INVERSE",!!P&&P.airborne===!P.grounded);t("SURFACE VALUE",!!P&&typeof P.surface==="string");t("SLOPE VALUE",!!P&&(P.slope===null||Number.isFinite(P.slope)));t("GROUND Y VALUE",!!P&&(P.groundY===null||Number.isFinite(P.groundY)));t("SAFE SAVE RULE",!!P&&P.safeSave===P.safeStand);t("NO KINGPOS WRITE",!!pos&&pos.distanceTo(kingPos)<0.0001);t("AUTHORITY LEGACY",!!R&&R.authority==="legacy"&&R.enabled===false);var n=r.filter(function(x){return x.indexOf("PASS")===0;}).length;R.debug.showingTest=true;if(!R.debug.mobile)R.toggleDebug();R.debugElement.textContent="AI PERCEPTION SELF TEST v205\n\n"+r.join("\n")+"\n\n"+n+" / "+r.length+" PASS\n\nWORLD SENSE\nSUPPORT   "+(P.support?"YES":"NO")+"\nGROUNDED  "+(P.grounded?"YES":"NO")+"\nAIRBORNE  "+(P.airborne?"YES":"NO")+"\nFALLING   "+(P.falling?"YES":"NO")+"\nSURFACE   "+P.surface+"\nGROUND Y  "+(P.groundY===null?"NONE":P.groundY.toFixed(2))+"\nDELTA     "+(P.delta===null?"NONE":P.delta.toFixed(2))+"\nSLOPE     "+(P.slope===null?"NONE":P.slope.toFixed(1))+"\nSAFE      "+(P.safeStand?"YES":"NO")+"\n\nMOVEMENT AUTHORITY  "+String(R.authority).toUpperCase();}};
    CODES.actortest = {cat:"Special",desc:"Run AI Actor controller self-test",fn:function(){ if(window.ACTOR_RUNTIME) window.ACTOR_RUNTIME.runControllerTest(); }};
    CODES.actordebug = {cat:"Special",desc:"Toggle Actor Runtime debugger",fn:function(){ if(window.ACTOR_RUNTIME) window.ACTOR_RUNTIME.toggleDebug(); }};
      CODES.worlddebug = {
      cat:'Special',
      desc:'Toggle Foundation 1 debugger',
      fn:function(){
        WF.toggleDebug();
      }
    };
  }

  /*
   * Base plane exists by this point in the current script.
   * Mountain list can continue changing, so syncMountains() is
   * idempotently called by debug observation.
   */
  /*
   * v184 FOUNDATION STARTUP TRACE
   * UI diagnostics only. Never touches world state.
   */
  function foundationTrace(message){
    var el = document.getElementById('foundation-