;;-*-Lisp-*-
(in-package goal)

;; name: nav-graph.gc
;; name in dgo: nav-graph
;; dgos: CWI

;; DECOMP BEGINS

(defmethod set-density ((this nav-branch) (arg0 float))
  (set! (-> this density) (the-as uint (max 0 (min 255 (the int (+ 0.5 (* 128.0 arg0)))))))
  0
  (none)
  )

(defmethod set-speed-limit ((this nav-branch) (arg0 float))
  (set! (-> this speed-limit) (the-as uint (max 0 (min 255 (the int (+ 0.5 (/ arg0 1024)))))))
  0
  (none)
  )

(defmethod set-width ((this nav-branch) (arg0 float))
  (set! (-> this width) (the-as uint (max 0 (min 255 (the int (+ 0.5 (/ arg0 256)))))))
  0
  (none)
  )

(defmethod set-src-node ((this nav-branch) (arg0 nav-node))
  (set! (-> this src-node) arg0)
  0
  (none)
  )

(defmethod set-dst-node ((this nav-branch) (arg0 nav-node))
  (set! (-> this dest-node) arg0)
  0
  (none)
  )

(defmethod set-default-density-speed-and-width ((this nav-branch))
  (set-density this 0.25)
  (set-speed-limit this 61440.0)
  (set-width this 16384.0)
  0
  (none)
  )

(defmethod debug-draw ((this nav-node))
  (rlet ((vf0 :class vf)
         (vf4 :class vf)
         (vf5 :class vf)
         (vf6 :class vf)
         )
    (init-vf0-vector)
    (let ((gp-0 (new 'stack-no-clear 'vector))
          (s4-0 (new 'stack-no-clear 'sphere))
          )
      (let ((a1-0 this)
            (v1-0 gp-0)
            )
        (set! (-> v1-0 quad) (-> a1-0 position quad))
        (set! (-> v1-0 w) 1.0)
        )
      (set! (-> s4-0 quad) (-> gp-0 quad))
      (let ((v1-2 this))
        (set! (-> s4-0 r) (* 1024.0 (the float (-> v1-2 radius))))
        )
      (when (logtest? (-> this flags) (nav-node-flag-byte selected))
        (let ((v1-8 (new 'stack-no-clear 'nav-graph-link)))
          (let ((a1-3 (&-> v1-8 id)))
            (let ((a0-6 gp-0))
              (let ((a2-1 -8192.0))
                (.mov vf6 a2-1)
                )
              (.lvf vf4 (&-> a0-6 quad))
              )
            (.add.x.vf.w vf5 vf0 vf0)
            (.add.x.vf.xyz vf5 vf4 vf6)
            (.svf (the-as (pointer uint128) (&-> a1-3 0)) vf5)
            )
          (let ((a1-4 (-> v1-8 dummy-node)))
            (let ((a0-7 gp-0))
              (let ((a2-3 8192.0))
                (.mov vf6 a2-3)
                )
              (.lvf vf4 (&-> a0-7 quad))
              )
            (.add.x.vf.w vf5 vf0 vf0)
            (.add.x.vf.xyz vf5 vf4 vf6)
            (.svf (&-> a1-4 position quad) vf5)
            )
          (add-debug-box
            #t
            (bucket-id debug2)
            (the-as vector (&-> v1-8 id))
            (the-as vector (-> v1-8 dummy-node))
            *color-yellow*
            )
          )
        )
      (when (and (not (logtest? (-> this flags) (nav-node-flag-byte hidden)))
                 (let ((f0-6 (vector-vector-distance-squared gp-0 (camera-pos)))
                       (f1-2 327680.0)
                       )
                   (and (< f0-6 (* f1-2 f1-2)) (sphere-in-view-frustum? s4-0))
                   )
                 )
        (add-debug-x #t (bucket-id debug2) gp-0 *color-red*)
        (let ((s4-1 add-debug-text-3d)
              (s3-1 #t)
              (s2-1 324)
              )
          (format (clear *temp-string*) "~D ~D" (-> this id) (-> this nav-mesh-id))
          (s4-1
            s3-1
            (the-as bucket-id s2-1)
            *temp-string*
            gp-0
            (if (logtest? (-> this flags) (nav-node-flag-byte blocked))
                (font-color red)
                (font-color cyan)
                )
            (the-as vector2h #f)
            )
          )
        (let ((s4-2 add-debug-vector)
              (s3-2 #t)
              (s2-2 324)
              (s1-1 (new 'stack-no-clear 'vector))
              )
          (let ((f0-8 (the float (-> this angle)))
                (s5-1 (new 'stack-no-clear 'vector))
                )
            (sincos! s5-1 f0-8)
            (set! (-> s1-1 x) (-> s5-1 y))
            (set! (-> s1-1 y) 0.0)
            (set! (-> s1-1 z) (- (-> s5-1 x)))
            )
          (set! (-> s1-1 w) 1.0)
          (s4-2 s3-2 (the-as bucket-id s2-2) gp-0 s1-1 (meters 2) *color-green*)
          )
        )
      )
    0
    (none)
    )
  )

(defmethod debug-print ((this nav-branch) (arg0 object) (arg1 int))
  (format arg0 "~S~T~T~T     (new-nav-branch :dest-node-id ~d~%" arg1 (-> this dest-node id))
  (let ((t9-1 format)
        (a0-2 arg0)
        (a1-2 "~S~T~T~T~T~T     :density ~4,,3f~%")
        (a2-2 arg1)
        (v1-1 this)
        )
    (t9-1 a0-2 a1-2 a2-2 (* 0.0078125 (the float (-> v1-1 density))))
    )
  (let ((t9-2 format)
        (a0-3 arg0)
        (a1-3 "~S~T~T~T~T~T     :width ~4,,3M~%")
        (a2-3 arg1)
        (v1-3 this)
        )
    (t9-2 a0-3 a1-3 a2-3 (* 256.0 (the float (-> v1-3 width))))
    )
  (let ((t9-3 format)
        (a0-4 arg0)
        (a1-4 "~S~T~T~T~T~T     :speed-limit ~4,,3M~%")
        (a2-4 arg1)
        (v1-5 this)
        )
    (t9-3 a0-4 a1-4 a2-4 (* 1024.0 (the float (-> v1-5 speed-limit))))
    )
  (when (nonzero? (-> this clock-type))
    (let ((t9-4 format)
          (a0-5 arg0)
          (a1-5 "~S~T~T~T~T~T     :clock-type ~S~%")
          (a2-5 arg1)
          (v1-9 (-> this clock-type))
          )
      (t9-4 a0-5 a1-5 a2-5 (cond
                             ((= v1-9 (nav-branch-clock-type clock3))
                              "clock3"
                              )
                             ((= v1-9 (nav-branch-clock-type no-clock))
                              "no-clock"
                              )
                             ((= v1-9 (nav-branch-clock-type clock2))
                              "clock2"
                              )
                             ((= v1-9 (nav-branch-clock-type clock4))
                              "clock4"
                              )
                             (else
                               "*unknown*"
                               )
                             )
            )
      )
    (format arg0 "~S~T~T~T~T~T     :clock-mask (" arg1)
    (let ((s4-1 (-> this clock-mask)))
      (if (= (logand s4-1 (nav-branch-clock-mask phase-1a)) (nav-branch-clock-mask phase-1a))
          (format arg0 "phase-1a ")
          )
      (if (= (logand s4-1 (nav-branch-clock-mask phase-2a)) (nav-branch-clock-mask phase-2a))
          (format arg0 "phase-2a ")
          )
      (if (= (logand s4-1 (nav-branch-clock-mask phase-1)) (nav-branch-clock-mask phase-1))
          (format arg0 "phase-1 ")
          )
      (if (= (logand s4-1 (nav-branch-clock-mask phase-3a)) (nav-branch-clock-mask phase-3a))
          (format arg0 "phase-3a ")
          )
      (if (= (logand s4-1 (nav-branch-clock-mask phase-2)) (nav-branch-clock-mask phase-2))
          (format arg0 "phase-2 ")
          )
      (if (= (logand s4-1 (nav-branch-clock-mask phase-4a)) (nav-branch-clock-mask phase-4a))
          (format arg0 "phase-4a ")
          )
      (if (= (logand s4-1 (nav-branch-clock-mask phase-3)) (nav-branch-clock-mask phase-3))
          (format arg0 "phase-3 ")
          )
      (if (= (logand s4-1 (nav-branch-clock-mask phase-4)) (nav-branch-clock-mask phase-4))
          (format arg0 "phase-4 ")
          )
      )
    (format arg0 ")~%")
    )
  (format arg0 "~S~T~T~T~T~T     )~%" arg1)
  0
  (none)
  )

(defmethod debug-print ((this nav-node) (arg0 symbol) (arg1 string))
  (format arg0 "~S (new-nav-node :id ~d~%" arg1 (-> this id))
  (format arg0 "~S~T       :branch-list (~%" arg1)
  (dotimes (s3-0 (-> this branch-count))
    (debug-print (-> this branch-array s3-0) arg0 (the-as int arg1))
    )
  (format arg0 "~S~T~T~T     )~%" arg1)
  (let* ((v1-6 (-> this flags))
         (s3-1 (logclear v1-6 (nav-node-flag-byte visited blocked)))
         )
    (when (nonzero? s3-1)
      (format arg0 "~S~T       :flags (" arg1)
      (if (= (logand s3-1 (nav-node-flag-byte blocked)) (nav-node-flag-byte blocked))
          (format arg0 "blocked ")
          )
      (if (= (logand s3-1 (nav-node-flag-byte selected)) (nav-node-flag-byte selected))
          (format arg0 "selected ")
          )
      (if (= (logand s3-1 (nav-node-flag-byte pedestrian)) (nav-node-flag-byte pedestrian))
          (format arg0 "pedestrian ")
          )
      (if (= (logand s3-1 (nav-node-flag-byte visited)) (nav-node-flag-byte visited))
          (format arg0 "visited ")
          )
      (if (= (logand s3-1 (nav-node-flag-byte hidden)) (nav-node-flag-byte hidden))
          (format arg0 "hidden ")
          )
      (format arg0 ")~%")
      )
    )
  (let ((v1-24 (new 'stack-no-clear 'vector)))
    (let ((a2-6 this)
          (a0-19 v1-24)
          )
      (set! (-> a0-19 quad) (-> a2-6 position quad))
      (set! (-> a0-19 w) 1.0)
      )
    (format arg0 "~S~T       :position (~4,,2M ~4,,2M ~4,,2M)~%" arg1 (-> v1-24 x) (-> v1-24 y) (-> v1-24 z))
    )
  (format arg0 "~S~T       :angle ~4,,3f~%" arg1 (* 0.005493164 (the float (-> this angle))))
  (let ((t9-13 format)
        (a0-22 arg0)
        (a1-16 "~S~T       :radius ~4,,2M~%")
        (a2-11 arg1)
        (v1-30 this)
        )
    (t9-13 a0-22 a1-16 a2-11 (* 1024.0 (the float (-> v1-30 radius))))
    )
  (if (nonzero? (-> this nav-mesh-id))
      (format arg0 "~S~T       :nav-mesh-id ~d~%" arg1 (-> this nav-mesh-id))
      )
  (if (-> this level)
      (format arg0 "~S~T       :level ~s~%" arg1 (-> this level))
      )
  (format arg0 "~S~T       )~%" arg1)
  0
  (none)
  )

(defmethod set-pos-xyz ((this nav-node) (arg0 vector))
  (let ((f0-0 (-> this position w)))
    (set! (-> this position quad) (-> arg0 quad))
    (set! (-> this position w) f0-0)
    )
  0
  (none)
  )

(defmethod set-angle-from-heading ((this nav-node) (arg0 vector))
  (set! (-> this angle) (the-as uint (the int (atan (- (-> arg0 z)) (-> arg0 x)))))
  0
  (none)
  )

(defmethod set-radius ((this nav-node) (arg0 float))
  (set! (-> this radius) (the-as uint (max 0 (min 255 (the int (+ 0.5 (/ arg0 1024)))))))
  0
  (none)
  )

(defmethod set-angle ((this nav-node) (arg0 float))
  (set! (-> this angle) (the-as uint (the int (+ 0.5 arg0))))
  0
  (none)
  )

(defmethod set-id-and-link-branches-back ((this nav-node) (arg0 uint))
  (set! (-> this id) arg0)
  (dotimes (v1-0 (-> this branch-count))
    (set! (-> this branch-array v1-0 src-node) this)
    )
  0
  (none)
  )

(defmethod init-from-pt-and-heading ((this nav-node) (arg0 vector) (arg1 vector))
  (set-pos-xyz this arg0)
  (set-angle-from-heading this arg1)
  (set! (-> this flags) (nav-node-flag-byte pedestrian selected))
  (set-radius this 32768.0)
  (set! (-> this level) 'ctyport)
  (set! (-> this nav-mesh-id) (the-as uint 0))
  (dotimes (s5-1 (-> this branch-count))
    (set-default-density-speed-and-width (-> this branch-array s5-1))
    )
  0
  (none)
  )

(defmethod remove-branch-by-idx ((this nav-node) (arg0 int))
  (when (and (>= arg0 0) (< arg0 (-> this branch-count)))
    (let ((s5-0 (+ arg0 1))
          (s4-0 arg0)
          )
      (while (< s5-0 (-> this branch-count))
        (mem-copy! (the-as pointer (-> this branch-array s4-0)) (the-as pointer (-> this branch-array s5-0)) 16)
        (+! s5-0 1)
        (+! s4-0 1)
        )
      )
    (+! (-> this branch-count) -1)
    )
  0
  (none)
  )

(defmethod debug-reset-branch-array ((this nav-graph) (arg0 nav-node) (arg1 int))
  "kinda dangerous"
  (set! (-> arg0 branch-array) (the-as (inline-array nav-branch) (-> this branch-array (-> this branch-count))))
  (set! (-> arg0 branch-count) arg1)
  (+! (-> this branch-count) arg1)
  (dotimes (s4-0 arg1)
    (let ((s3-0 (-> arg0 branch-array s4-0)))
      (set-default-density-speed-and-width s3-0)
      (set! (-> s3-0 src-node) arg0)
      (set! (-> s3-0 dest-node) #f)
      )
    )
  0
  (none)
  )

(defmethod debug-add-node ((this nav-graph) (arg0 int))
  (let ((s4-0 (the-as nav-node #f)))
    (let ((s5-0 (-> this node-count))
          (v1-1 (+ arg0 -1 (-> this branch-count)))
          )
      (when (and (< s5-0 2000) (< v1-1 2500))
        (set! s4-0 (-> this node-array s5-0))
        (debug-reset-branch-array this s4-0 arg0)
        (set-id-and-link-branches-back s4-0 (the-as uint s5-0))
        (+! (-> this node-count) 1)
        )
      )
    s4-0
    )
  )

(defmethod debug-link-node-to-graph ((this nav-graph) (arg0 nav-node))
  (when (> (-> arg0 branch-count) 0)
    (let ((a0-1 (-> arg0 branch-array 0))
          (t9-0 (method-of-type nav-branch set-dst-node))
          (a2-0 this)
          (v1-4 (-> this first-node))
          (a1-1 (the-as nav-node #f))
          )
      (if (and (>= v1-4 0) (< v1-4 (-> a2-0 node-count)))
          (set! a1-1 (-> a2-0 node-array v1-4))
          )
      (t9-0 a0-1 a1-1)
      )
    (let ((v1-9 (+ (-> arg0 id) -1)))
      (when (>= v1-9 (the-as uint (-> this first-node)))
        (let ((v1-11 (-> this node-array v1-9)))
          (set! (-> v1-11 branch-count) 1)
          (set-dst-node (-> v1-11 branch-array 0) arg0)
          )
        )
      )
    )
  0
  (none)
  )

(defmethod nav-graph-method-13 ((this nav-graph) (arg0 int) (arg1 int))
  (when (and (< arg0 (-> this node-count)) (> arg1 0))
    (let ((s4-1 (min arg1 (- (-> this node-count) arg0))))
      (dotimes (s3-0 (-> this node-count))
        (let ((s2-0 (-> this node-array s3-0)))
          (dotimes (s1-0 (-> s2-0 branch-count))
            (let ((v1-9 (nav-graph-method-40 this (the-as int (-> s2-0 branch-array s1-0 dest-node)))))
              (when (and (>= v1-9 arg0) (< v1-9 (+ arg0 s4-1)))
                (let ((v1-11 (-> this node-array v1-9)))
                  (cond
                    ((= (-> v1-11 branch-count) 1)
                     (let ((v1-14 (-> v1-11 branch-array 0 dest-node id)))
                       (if (or (< v1-14 (the-as uint arg0)) (>= v1-14 (the-as uint (+ arg0 s4-1))))
                           (set-dst-node (-> s2-0 branch-array s1-0) (-> this node-array v1-14))
                           (remove-branch-by-idx s2-0 s1-0)
                           )
                       )
                     )
                    (else
                      (remove-branch-by-idx s2-0 s1-0)
                      )
                    )
                  )
                )
              )
            )
          )
        )
      (dotimes (s3-1 (-> this node-count))
        (let ((s2-1 (-> this node-array s3-1)))
          (dotimes (s1-1 (-> s2-1 branch-count))
            (let ((v1-28 (nav-graph-method-40 this (the-as int (-> s2-1 branch-array s1-1 dest-node)))))
              (if (>= v1-28 (+ arg0 s4-1))
                  (set-dst-node (-> s2-1 branch-array s1-1) (-> this node-array (- v1-28 s4-1)))
                  )
              )
            )
          )
        )
      (let ((s3-2 arg0)
            (s2-2 (-> this node-array (+ arg0 s4-1)))
            (s1-2 (-> this node-array arg0))
            )
        (countdown (s0-0 (- (-> this node-count) (+ arg0 s4-1)))
          (mem-copy! (the-as pointer s1-2) (the-as pointer s2-2) 32)
          (set-id-and-link-branches-back s1-2 (the-as uint s3-2))
          (&+! s2-2 32)
          (&+! s1-2 32)
          (+! s3-2 1)
          )
        )
      (set! (-> this node-count) (- (-> this node-count) s4-1))
      (if (< arg0 (-> this first-node))
          (set! (-> this first-node) (- (-> this first-node) s4-1))
          )
      )
    )
  0
  (none)
  )

(defmethod nav-graph-method-14 ((this nav-graph) (arg0 int) (arg1 int))
  (when (and (< arg0 (-> this node-count)) (> arg1 0))
    (dotimes (s3-0 (-> this node-count))
      (let ((s2-0 (-> this node-array s3-0)))
        (dotimes (s1-0 (-> s2-0 branch-count))
          (let ((v1-7 (nav-graph-method-40 this (the-as int (-> s2-0 branch-array s1-0 dest-node)))))
            (if (< arg0 v1-7)
                (set-dst-node (-> s2-0 branch-array s1-0) (-> this node-array (+ v1-7 arg1)))
                )
            )
          )
        )
      )
    (let* ((s3-1 (+ arg1 -1 (-> this node-count)))
           (s2-1 (-> this node-array (- s3-1 arg1)))
           (s1-1 (-> this node-array s3-1))
           )
      (countdown (s0-0 (- (-> this node-count) arg0))
        (mem-copy! (the-as pointer s1-1) (the-as pointer s2-1) 32)
        (set-id-and-link-branches-back s1-1 (the-as uint s3-1))
        ;; og:preserve-this
        (set! s2-1 (&+ s2-1 -32))
        (set! s1-1 (&+ s1-1 -32))
        (+! s3-1 -1)
        )
      )
    (+! (-> this node-count) arg1)
    (+! (-> this first-node) arg1)
    (let ((s3-2 (-> this node-array arg0))
          (s2-2 (-> this node-array arg0))
          )
      (dotimes (s1-2 arg1)
        (mem-copy! (the-as pointer s2-2) (the-as pointer s3-2) 32)
        (set-id-and-link-branches-back s2-2 (the-as uint arg0))
        (+! (-> s2-2 position y) (* 8192.0 (the float (+ s1-2 1))))
        (debug-reset-branch-array this s2-2 1)
        (set-dst-node (-> s2-2 branch-array 0) (-> this node-array (+ arg0 1)))
        (&+! s2-2 32)
        (+! arg0 1)
        )
      )
    )
  0
  (none)
  )

(defmethod debug-reset ((this nav-graph))
  (set! (-> this node-count) 0)
  (set! (-> this branch-count) 0)
  (set! (-> this first-node) 0)
  (set! (-> this patched) #f)
  0
  (none)
  )

(defmethod nav-graph-method-12 ((this nav-graph))
  (set! (-> this first-node) (-> this node-count))
  0
  (none)
  )

(defmethod print-selected-nodes ((this nav-graph))
  (let ((s4-0 0)
        (s1-0 0)
        (v1-0 #f)
        (s3-0 0)
        (gp-0 0)
        )
    (dotimes (s2-0 (-> this node-count))
      (let* ((a0-2 (-> this node-array s2-0))
             (s0-1 (logtest? (-> a0-2 flags) (nav-node-flag-byte selected)))
             )
        (when s0-1
          (+! gp-0 1)
          (if (not v1-0)
              (set! s4-0 s2-0)
              )
          (set! s1-0 s2-0)
          )
        (set! v1-0 (and (not s0-1) v1-0))
        (when (or v1-0 (and s0-1 (= s2-0 (+ (-> this node-count) -1))))
          (if (> s3-0 0)
              (format #t ", ")
              )
          (if (= s4-0 s1-0)
              (format #t "~d" s4-0)
              (format #t "~d-~d" s4-0 s1-0)
              )
          (+! s3-0 1)
          )
        (set! v1-0 s0-1)
        )
      )
    (format #t "~%")
    (format #t "~d nodes selected~%" gp-0)
    )
  0
  (none)
  )

(defmethod select-nodes-in-range ((this nav-graph) (arg0 int) (arg1 int))
  (when (< arg0 (-> this node-count))
    (let ((v1-3 (min arg1 (+ (-> this node-count) -1)))
          (a2-3 arg0)
          )
      (+ (- 1 arg0) v1-3)
      (while (>= v1-3 a2-3)
        (let ((a1-4 (-> this node-array a2-3)))
          (logior! (-> a1-4 flags) (nav-node-flag-byte selected))
          )
        (+! a2-3 1)
        )
      )
    )
  (print-selected-nodes this)
  0
  (none)
  )

(defmethod deselect-nodes-in-range ((this nav-graph) (arg0 int) (arg1 int))
  (when (< arg0 (-> this node-count))
    (let ((v1-3 (min arg1 (+ (-> this node-count) -1)))
          (a2-3 arg0)
          )
      (+ (- 1 arg0) v1-3)
      (while (>= v1-3 a2-3)
        (let ((a1-4 (-> this node-array a2-3)))
          (logclear! (-> a1-4 flags) (nav-node-flag-byte selected))
          )
        (+! a2-3 1)
        )
      )
    )
  (print-selected-nodes this)
  0
  (none)
  )

(defmethod toggle-select-nodes-in-range ((this nav-graph) (arg0 int) (arg1 int))
  (when (< arg0 (-> this node-count))
    (let ((v1-3 (min arg1 (+ (-> this node-count) -1)))
          (a2-3 arg0)
          )
      (+ (- 1 arg0) v1-3)
      (while (>= v1-3 a2-3)
        (let ((a1-4 (-> this node-array a2-3)))
          (logxor! (-> a1-4 flags) (nav-node-flag-byte selected))
          )
        (+! a2-3 1)
        )
      )
    )
  (print-selected-nodes this)
  0
  (none)
  )

(defmethod select-nodes-in-level ((this nav-graph) (arg0 symbol) (arg1 symbol))
  (dotimes (v1-0 (-> this node-count))
    (let* ((a3-1 (-> this node-array v1-0))
           (t0-2 (= (-> a3-1 level) arg0))
           )
      (case arg1
        (('set)
         (logclear! (-> a3-1 flags) (nav-node-flag-byte selected))
         (if t0-2
             (logior! (-> a3-1 flags) (nav-node-flag-byte selected))
             )
         )
        (('and)
         (if (not t0-2)
             (logclear! (-> a3-1 flags) (nav-node-flag-byte selected))
             )
         )
        (('or)
         (if t0-2
             (logior! (-> a3-1 flags) (nav-node-flag-byte selected))
             )
         )
        )
      )
    )
  (print-selected-nodes this)
  0
  (none)
  )

(defmethod select-nodes-by-nav-mesh-id ((this nav-graph) (arg0 int) (arg1 symbol))
  (dotimes (v1-0 (-> this node-count))
    (let* ((a3-1 (-> this node-array v1-0))
           (t0-2 (= (-> a3-1 nav-mesh-id) arg0))
           )
      (case arg1
        (('set)
         (logclear! (-> a3-1 flags) (nav-node-flag-byte selected))
         (if t0-2
             (logior! (-> a3-1 flags) (nav-node-flag-byte selected))
             )
         )
        (('and)
         (if (not t0-2)
             (logclear! (-> a3-1 flags) (nav-node-flag-byte selected))
             )
         )
        (('or)
         (if t0-2
             (logior! (-> a3-1 flags) (nav-node-flag-byte selected))
             )
         )
        )
      )
    )
  (print-selected-nodes this)
  0
  (none)
  )

(defmethod select-nodes-by-flags ((this nav-graph) (arg0 nav-node-flag-byte) (arg1 nav-node-flag-byte) (arg2 symbol))
  (dotimes (v1-0 (-> this node-count))
    (let* ((t0-1 (-> this node-array v1-0))
           (t1-3 (= (logand (-> t0-1 flags) arg1) arg0))
           )
      (case arg2
        (('set)
         (logclear! (-> t0-1 flags) (nav-node-flag-byte selected))
         (if t1-3
             (logior! (-> t0-1 flags) (nav-node-flag-byte selected))
             )
         )
        (('and)
         (if (not t1-3)
             (logclear! (-> t0-1 flags) (nav-node-flag-byte selected))
             )
         )
        (('or)
         (if t1-3
             (logior! (-> t0-1 flags) (nav-node-flag-byte selected))
             )
         )
        )
      )
    )
  (print-selected-nodes this)
  0
  (none)
  )

(defmethod assign-selected-nodes-to-level ((this nav-graph) (arg0 symbol))
  (dotimes (v1-0 (-> this node-count))
    (let ((a2-1 (-> this node-array v1-0)))
      (if (logtest? (-> a2-1 flags) (nav-node-flag-byte selected))
          (set! (-> a2-1 level) arg0)
          )
      )
    )
  0
  (none)
  )

(defmethod assign-selected-nodes-to-nav-mesh ((this nav-graph) (arg0 uint))
  (dotimes (v1-0 (-> this node-count))
    (let ((a2-1 (-> this node-array v1-0)))
      (if (logtest? (-> a2-1 flags) (nav-node-flag-byte selected))
          (set! (-> a2-1 nav-mesh-id) arg0)
          )
      )
    )
  0
  (none)
  )

(defmethod set-radius-of-selected-nodes ((this nav-graph) (arg0 float))
  (dotimes (s4-0 (-> this node-count))
    (let ((a0-2 (-> this node-array s4-0)))
      (if (logtest? (-> a0-2 flags) (nav-node-flag-byte selected))
          (set-radius a0-2 arg0)
          )
      )
    )
  0
  (none)
  )

(defmethod or-flags-of-selected-nodes ((this nav-graph) (arg0 nav-node-flag-byte))
  (dotimes (v1-0 (-> this node-count))
    (let ((a2-1 (-> this node-array v1-0)))
      (if (logtest? (-> a2-1 flags) (nav-node-flag-byte selected))
          (logior! (-> a2-1 flags) arg0)
          )
      )
    )
  0
  (none)
  )

(defmethod and-flags-of-selected-nodes ((this nav-graph) (arg0 nav-node-flag-byte))
  (let ((v1-0 (lognot arg0)))
    (dotimes (a1-1 (-> this node-count))
      (let ((a2-1 (-> this node-array a1-1)))
        (if (logtest? (-> a2-1 flags) (nav-node-flag-byte selected))
            (logand! (-> a2-1 flags) v1-0)
            )
        )
      )
    )
  0
  (none)
  )

(defmethod set-speed-limit-of-selected ((this nav-graph) (arg0 float))
  (dotimes (s4-0 (-> this node-count))
    (let ((s3-0 (-> this node-array s4-0)))
      (when (logtest? (-> s3-0 flags) (nav-node-flag-byte selected))
        (dotimes (s2-0 (-> s3-0 branch-count))
          (set-speed-limit (-> s3-0 branch-array s2-0) arg0)
          )
        )
      )
    )
  0
  (none)
  )

(defmethod set-density-of-selected ((this nav-graph) (arg0 float))
  (dotimes (s4-0 (-> this node-count))
    (let ((s3-0 (-> this node-array s4-0)))
      (when (logtest? (-> s3-0 flags) (nav-node-flag-byte selected))
        (dotimes (s2-0 (-> s3-0 branch-count))
          (set-density (-> s3-0 branch-array s2-0) arg0)
          )
        )
      )
    )
  0
  (none)
  )

(defmethod set-width-of-selected ((this nav-graph) (arg0 float))
  (dotimes (s4-0 (-> this node-count))
    (let ((s3-0 (-> this node-array s4-0)))
      (when (logtest? (-> s3-0 flags) (nav-node-flag-byte selected))
        (dotimes (s2-0 (-> s3-0 branch-count))
          (set-width (-> s3-0 branch-array s2-0) arg0)
          )
        )
      )
    )
  0
  (none)
  )

(defmethod offset-pos-of-selected ((this nav-graph) (arg0 vector))
  (let ((s4-0 (new 'stack-no-clear 'vector)))
    (dotimes (s3-0 (-> this node-count))
      (let ((a0-2 (-> this node-array s3-0)))
        (when (logtest? (-> a0-2 flags) (nav-node-flag-byte selected))
          (let ((a2-0 a0-2)
                (v1-4 s4-0)
                )
            (set! (-> v1-4 quad) (-> a2-0 position quad))
            (set! (-> v1-4 w) 1.0)
            )
          (vector+! s4-0 s4-0 arg0)
          (set-pos-xyz a0-2 s4-0)
          )
        )
      )
    )
  0
  (none)
  )

(defmethod nav-graph-method-38 ((this nav-graph))
  (let ((s5-0 (new 'stack-no-clear 'vehicle-controller))
        (s4-0 (new 'stack-no-clear 'vector))
        )
    (dotimes (s3-0 (-> this node-count))
      (let ((s2-0 (-> this node-array s3-0)))
        (when (and (logtest? (-> s2-0 flags) (nav-node-flag-byte selected)) (= (-> s2-0 branch-count) 1))
          (let ((a1-0 (-> s2-0 branch-array 0)))
            (-> a1-0 dest-node)
            (vehicle-controller-method-13 s5-0 a1-0 (-> s2-0 position))
            )
          (vehicle-controller-method-11 s5-0)
          (vector-! s4-0 (-> s5-0 target-point) (-> s2-0 position))
          (set! (-> s4-0 y) 0.0)
          (vector-normalize! s4-0 1.0)
          (set-angle-from-heading s2-0 s4-0)
          )
        )
      )
    )
  0
  (none)
  )

(defmethod debug-draw-nodes ((this nav-graph))
  (let ((s5-0 (new 'stack-no-clear 'matrix)))
    (dotimes (s4-0 (-> this node-count))
      (let ((s3-0 (-> this node-array s4-0)))
        (when (not (logtest? (-> s3-0 flags) (nav-node-flag-byte hidden)))
          (debug-draw s3-0)
          (let ((a1-0 s3-0)
                (v1-6 (-> s5-0 vector))
                )
            (set! (-> v1-6 0 quad) (-> a1-0 position quad))
            (set! (-> v1-6 0 w) 1.0)
            )
          (dotimes (s2-0 (-> s3-0 branch-count))
            (let ((v1-9 (-> s3-0 branch-array s2-0 dest-node)))
              (when v1-9
                (let ((a2-0 v1-9)
                      (a0-7 (-> s5-0 vector 1))
                      )
                  (set! (-> a0-7 quad) (-> a2-0 position quad))
                  (set! (-> a0-7 w) 1.0)
                  )
                (vector-! (-> s5-0 vector 2) (-> s5-0 vector 1) (the-as vector (-> s5-0 vector)))
                (let* ((f0-2 (vector-length (-> s5-0 vector 2)))
                       (f1-2 (fmax (* 0.75 f0-2) (+ -8192.0 f0-2)))
                       )
                  (vector-float*! (-> s5-0 vector 2) (-> s5-0 vector 2) (/ f1-2 f0-2))
                  )
                (vector+! (-> s5-0 trans) (the-as vector (-> s5-0 vector)) (-> s5-0 vector 2))
                (add-debug-line
                  #t
                  (bucket-id debug2)
                  (the-as vector (-> s5-0 vector))
                  (-> s5-0 trans)
                  (cond
                    ((= (-> v1-9 id) #xffff)
                     *color-dark-blue*
                     )
                    ((logtest? (-> s3-0 flags) (nav-node-flag-byte pedestrian))
                     *color-dark-red*
                     )
                    (else
                      *color-dark-green*
                      )
                    )
                  #f
                  *color-white*
                  )
                )
              )
            )
          )
        )
      )
    )
  0
  (none)
  )

;; WARN: Return type mismatch nav-node vs none.
(defmethod nav-graph-method-10 ((this nav-graph) (arg0 vector) (arg1 int))
  (let* ((gp-0 (the-as nav-node #f))
         (f0-0 409600000.0)
         (f30-0 (* f0-0 f0-0))
         )
    (dotimes (s2-0 (-> this node-count))
      (let ((s1-0 (-> this node-array s2-0))
            (a1-1 (new 'stack-no-clear 'vector))
            )
        (when (and (not (logtest? (-> s1-0 flags) (nav-node-flag-byte hidden)))
                   (or (not arg1) (and arg1 (logtest? (-> s1-0 flags) (nav-node-flag-byte selected))))
                   )
          (let ((a2-1 s1-0)
                (v1-8 a1-1)
                )
            (set! (-> v1-8 quad) (-> a2-1 position quad))
            (set! (-> v1-8 w) 1.0)
            )
          (let ((f0-3 (vector-vector-distance-squared arg0 a1-1)))
            (when (< f0-3 f30-0)
              (set! gp-0 s1-0)
              (set! f30-0 f0-3)
              )
            )
          )
        )
      )
    )
  (none)
  )

(defmethod move-selected-to-height-map-height ((this nav-graph))
  (dotimes (s5-0 (-> this node-count))
    (let ((s4-0 (-> this node-array s5-0))
          (s3-0 (new 'stack-no-clear 'vector))
          )
      (when (and (not (logtest? (-> s4-0 flags) (nav-node-flag-byte hidden)))
                 (not (logtest? (-> s4-0 flags) (nav-node-flag-byte pedestrian)))
                 (logtest? (-> s4-0 flags) (nav-node-flag-byte selected))
                 )
        (let ((a1-0 s4-0)
              (v1-8 s3-0)
              )
          (set! (-> v1-8 quad) (-> a1-0 position quad))
          (set! (-> v1-8 w) 1.0)
          )
        (let ((a1-3 s3-0))
          (set! (-> s3-0 y) (get-height-at-point *traffic-height-map* a1-3))
          )
        (set-pos-xyz s4-0 s3-0)
        )
      )
    )
  0
  (none)
  )

(defmethod nav-graph-method-39 ((this nav-graph))
  (local-vars (sv-80 entity-nav-mesh) (sv-96 entity-nav-mesh))
  (dotimes (s5-0 (-> this node-count))
    (let ((s4-0 (-> this node-array s5-0))
          (s3-0 (new 'stack-no-clear 'vector))
          )
      (let ((a1-0 s4-0)
            (v1-1 s3-0)
            )
        (set! (-> v1-1 quad) (-> a1-0 position quad))
        (set! (-> v1-1 w) 1.0)
        )
      (when (logtest? (-> s4-0 flags) (nav-node-flag-byte pedestrian))
        (dotimes (s2-0 (-> *level* length))
          (let ((v1-8 (-> *level* level s2-0)))
            (when (= (-> v1-8 status) 'active)
              (let ((s1-0 (-> v1-8 bsp nav-meshes)))
                (when (nonzero? s1-0)
                  (dotimes (s0-0 (-> s1-0 length))
                    (set! sv-80 (-> s1-0 s0-0))
                    (-> sv-80 aid)
                    (set! sv-96 sv-80)
                    (let ((v1-16 (if (type? sv-96 entity-nav-mesh)
                                     sv-96
                                     )
                                 )
                          )
                      (when v1-16
                        (let ((a0-10 (-> v1-16 nav-mesh))
                              (a1-5 (new 'stack-no-clear 'nav-find-poly-parms))
                              )
                          (vector-! (-> a1-5 point) s3-0 (-> a0-10 bounds))
                          (set! (-> a1-5 y-threshold) 40960.0)
                          (set! (-> a1-5 ignore) (the-as uint 2))
                          (if (find-poly-containing-point-local a0-10 a1-5)
                              (set! (-> s4-0 nav-mesh-id) (-> sv-80 aid))
                              )
                          )
                        )
                      )
                    )
                  )
                )
              )
            )
          )
        )
      )
    )
  0
  (none)
  )

(defmethod nav-graph-method-19 ((this nav-graph) (arg0 int) (arg1 int) (arg2 int) (arg3 int) (arg4 int) (arg5 int))
  (let ((gp-0 (-> this node-array arg0))
        (s0-0 (-> this node-array arg1))
        (s4-0 (-> this node-array arg2))
        (s2-0 (-> this node-array arg3))
        (s1-0 (-> this node-array arg4))
        (s3-0 (-> this node-array arg5))
        )
    (debug-reset-branch-array this s0-0 2)
    (set-dst-node (-> s0-0 branch-array 0) s4-0)
    (set-dst-node (-> s0-0 branch-array 1) s1-0)
    (debug-reset-branch-array this s2-0 2)
    (set-dst-node (-> s2-0 branch-array 0) s1-0)
    (set-dst-node (-> s2-0 branch-array 1) gp-0)
    (debug-reset-branch-array this s3-0 2)
    (set-dst-node (-> s3-0 branch-array 0) gp-0)
    (set-dst-node (-> s3-0 branch-array 1) s4-0)
    )
  (none)
  )

(defmethod nav-graph-method-40 ((this nav-graph) (arg0 int))
  -1
  (shr (- arg0 (the-as int (-> this node-array 0))) 5)
  )

(defmethod nav-graph-method-20 ((this nav-graph) (arg0 int) (arg1 int))
  (let ((gp-0 (-> this node-array arg0))
        (s5-0 (-> this node-array arg1))
        )
    (debug-reset-branch-array this gp-0 1)
    (set-dst-node (-> gp-0 branch-array 0) s5-0)
    )
  (none)
  )

(defmethod nav-graph-method-11 ((this nav-graph))
  (format #t "(define *traffic-nav-graph*~%")
  (format #t "    (new-nav-graph~%")
  (format #t "     :node-list (~%")
  (dotimes (s5-0 (-> this node-count))
    (let ((a0-5 (-> this node-array s5-0)))
      (set! (-> a0-5 id) (the-as uint s5-0))
      (debug-print a0-5 #t "		")
      )
    )
  (format #t "~T~T )~%")
  (format #t "     )~%")
  (format #t "  )~%")
  0
  (none)
  )

(defmethod patch-nodes ((this nav-graph))
  "Patch nodes. Node pointers are stored as indices into arrays to be allocated on the level heap
   and patched at runtime after loading."
  (when (not (-> this patched))
    (set! (-> this patched) #t)
    (let ((s5-0 0))
      (dotimes (s4-0 (-> this node-count))
        (let ((s3-0 (-> this node-array s4-0)))
          (dotimes (s2-0 (-> s3-0 branch-count))
            (let ((s1-0 (-> s3-0 branch-array s2-0)))
              (+! s5-0 1)
              (set-src-node s1-0 s3-0)
              (let ((v1-7 (the-as object (-> s1-0 dest-node))))
                (set-dst-node s1-0 (-> this node-array (the-as uint v1-7)))
                )
              )
            )
          )
        )
      )
    )
  0
  (none)
  )

;; WARN: Function (method 43 nav-graph) has a return type of none, but the expression builder found a return statement.
(defmethod copy-to-mysql-graph ((this nav-graph) (arg0 mysql-nav-graph) (arg1 string))
  (set! (-> arg0 node-array length) 0)
  (set! (-> arg0 edge-array length) 0)
  (set! (-> arg0 visnode-array length) 0)
  (let ((s3-0 (clear *temp-string*)))
    (format s3-0 "select nav_graph_id from nav_graph where name='~S'" arg1)
    (let ((a2-2 (sql-query s3-0)))
      (when (!= (-> a2-2 error) 'select)
        (format 0 "ERROR: sql: select error ~A for ~A~%" a2-2 this)
        (return #f)
        )
      (set! (-> arg0 nav_graph_id) (the-as uint (string->int (-> a2-2 data 0))))
      )
    )
  (dotimes (v1-7 (-> this node-count))
    (let ((a1-6 (-> arg0 node-array data (-> arg0 node-array length)))
          (a0-11 (-> this node-array v1-7))
          )
      (logior! (-> a1-6 mysql-save-flag) (mysql-save-flag insert))
      (set! (-> a1-6 runtime-id) (-> a0-11 id))
      (set! (-> a1-6 nav_graph_id) (-> arg0 nav_graph_id))
      (let ((t0-0 a0-11)
            (a2-8 (-> a1-6 position))
            )
        (set! (-> a2-8 quad) (-> t0-0 position quad))
        (set! (-> a2-8 w) 1.0)
        )
      (set! (-> a1-6 level_name) (-> a0-11 level))
      (set! (-> a1-6 angle) (the float (-> a0-11 angle)))
      (let ((a2-13 a0-11))
        (set! (-> a1-6 radius) (* 1024.0 (the float (-> a2-13 radius))))
        )
      (set! (-> a1-6 nav_node_flag) (the-as nav-node-flag (-> a0-11 flags)))
      (set! (-> a1-6 nav_mesh_id) (-> a0-11 nav-mesh-id))
      (+! (-> arg0 node-array length) 1)
      (dotimes (a1-10 (-> a0-11 branch-count))
        (let ((a2-22 (-> arg0 edge-array data (-> arg0 edge-array length)))
              (a3-8 (-> a0-11 branch-array a1-10))
              )
          (logior! (-> a2-22 mysql-save-flag) (mysql-save-flag insert))
          (set! (-> a2-22 nav_graph_id) (-> arg0 nav_graph_id))
          (set! (-> a2-22 runtime-id) (the-as uint (-> arg0 edge-array length)))
          (set! (-> a2-22 runtime-node-id-1) (the-as int (-> a0-11 id)))
          (set! (-> a2-22 runtime-node-id-2) (the-as int (-> a3-8 dest-node id)))
          (set! (-> a2-22 directionality) (nav-directionality default))
          (let ((t0-12 a3-8))
            (set! (-> a2-22 speed_limit) (* 1024.0 (the float (-> t0-12 speed-limit))))
            )
          (let ((t0-15 a3-8))
            (set! (-> a2-22 density) (* 0.0078125 (the float (-> t0-15 density))))
            )
          (set! (-> a2-22 nav_clock_mask) (the-as nav-clock-mask (-> a3-8 clock-mask)))
          (set! (-> a2-22 nav_clock_type) (the-as nav-clock-type (-> a3-8 clock-type)))
          (set! (-> a2-22 width) (* 256.0 (the float (-> a3-8 width))))
          )
        (+! (-> arg0 edge-array length) 1)
        )
      )
    )
  0
  (none)
  )

;; WARN: Return type mismatch object vs nav-graph.
(defmethod new nav-graph ((allocation symbol) (type-to-make type) (arg0 int) (arg1 int) (arg2 int) (arg3 uint))
  (let ((s1-0 (the-as object (object-new allocation type-to-make (the-as int (-> type-to-make size))))))
    (when (zero? (the-as nav-graph s1-0))
      (set! s1-0 0)
      (goto cfg-4)
      )
    (set! (-> (the-as nav-graph s1-0) node-count) arg0)
    (set! (-> (the-as nav-graph s1-0) branch-count) arg1)
    (set! (-> (the-as nav-graph s1-0) link-count) arg2)
    (set! (-> (the-as nav-graph s1-0) node-array)
          (the-as (inline-array nav-node) (malloc allocation (* arg0 32)))
          )
    (set! (-> (the-as nav-graph s1-0) branch-array)
          (the-as (inline-array nav-branch) (malloc allocation (* arg1 16)))
          )
    (set! (-> (the-as nav-graph s1-0) link-array)
          (the-as (inline-array nav-graph-link) (malloc allocation (* 48 arg2)))
          )
    (set! (-> (the-as nav-graph s1-0) first-node) 0)
    (set! (-> (the-as nav-graph s1-0) patched) #f)
    (set! (-> (the-as nav-graph s1-0) id) arg3)
    (label cfg-4)
    (the-as nav-graph s1-0)
    )
  )

(defmethod from-editor ((this nav-graph) (arg0 mysql-nav-graph) (arg1 symbol))
  (local-vars
    (v1-4 symbol)
    (v1-6 symbol)
    (v1-37 symbol)
    (sv-16 int)
    (sv-32 int)
    (sv-48 mysql-nav-node)
    (sv-64 nav-branch)
    (sv-80 nav-graph-link)
    (sv-96 nav-node)
    (sv-112 int)
    )
  (set! (-> this node-count) 0)
  (set! (-> this branch-count) 0)
  (set! (-> this link-count) 0)
  (mysql-nav-graph-method-20 arg0)
  (let ((s5-0 0))
    (let ((s2-0 0))
      (b! #t cfg-34 :delay (nop!))
      (label cfg-1)
      (let ((s0-0 (-> arg0 node-array data s2-0)))
        (let ((a0-3 (= arg1 #f)))
          (b! a0-3 cfg-4 :likely-delay (set! v1-4 a0-3))
          )
        (set! v1-4 (= arg1 (-> s0-0 level_name)))
        (label cfg-4)
        (b! (not v1-4) cfg-7 :likely-delay (set! v1-6 v1-4))
        (set! v1-6 (not (logtest? (-> s0-0 mysql-save-flag) (mysql-save-flag delete))))
        (label cfg-7)
        (b! (not v1-6) cfg-27 :delay (nop!))
        (set! sv-16 (temp-edge-size s0-0))
        (let ((s1-0 (debug-add-node this sv-16)))
          (b! (not s1-0) cfg-36 :delay (nop!))
          (set! (-> s1-0 id) (the-as uint (if arg1
                                              (-> s0-0 level-node-index)
                                              s2-0
                                              )
                                     )
                )
          (set! (-> s1-0 flags) (the-as nav-node-flag-byte (-> s0-0 nav_node_flag)))
          (set-pos-xyz s1-0 (-> s0-0 position))
          (set-angle s1-0 (-> s0-0 angle))
          (set-radius s1-0 (-> s0-0 radius))
          (set! (-> s1-0 level) (-> s0-0 level_name))
          (set! (-> s1-0 nav-mesh-id) (-> s0-0 nav_mesh_id))
          (when (!= (-> this branch-array s5-0) (-> s1-0 branch-array 0))
            (format 0 "nav-graph::from-editor: ERROR something went awry in allocate-branches~%")
            (break!)
            0
            )
          (let ((s0-1 (the-as object (-> s0-0 temp-edge-list))))
            (set! sv-32 sv-16)
            (b! #t cfg-25 :delay (nop!))
            (label cfg-15)
            (set! sv-32 (+ sv-32 -1))
            (set! sv-64 (-> this branch-array s5-0))
            (set-src-node sv-64 s1-0)
            (set-speed-limit sv-64 (-> (the-as mysql-nav-edge s0-1) speed_limit))
            (set-density sv-64 (-> (the-as mysql-nav-edge s0-1) density))
            (set-width sv-64 (-> (the-as mysql-nav-edge s0-1) width))
            (set! (-> sv-64 clock-type) (the-as nav-branch-clock-type (-> (the-as mysql-nav-edge s0-1) nav_clock_type)))
            (set! (-> sv-64 clock-mask) (the-as nav-branch-clock-mask (-> (the-as mysql-nav-edge s0-1) nav_clock_mask)))
            (set! sv-48 (-> arg0 node-array data (-> (the-as mysql-nav-edge s0-1) runtime-node-id-2)))
            (let ((a0-23 (= arg1 #f)))
              (b! a0-23 cfg-18 :likely-delay (set! v1-37 a0-23))
              )
            (set! v1-37 (= arg1 (-> sv-48 level_name)))
            (label cfg-18)
            (b! (not v1-37) cfg-23 :delay (nop!))
            (let ((t9-11 (method-of-type nav-branch set-dst-node))
                  (a1-11 (-> this node-array (if arg1
                                                 (-> sv-48 level-node-index)
                                                 (-> (the-as mysql-nav-edge s0-1) runtime-node-id-2)
                                                 )
                             )
                         )
                  )
              (t9-11 sv-64 a1-11)
              )
            (b! #t cfg-24 :delay (nop!))
            (label cfg-23)
            (set-dst-node sv-64 (the-as nav-node #f))
            (set! sv-112 (-> this link-count))
            (set! sv-80 (-> this link-array sv-112))
            (set! (-> sv-80 dest-graph-id) (-> (lookup-level-info2 arg0 sv-48 #f) level-id))
            (set! (-> sv-80 src-branch-id) (the-as uint s5-0))
            (set! (-> sv-80 dest-node-id) (the-as uint (-> sv-48 level-node-index)))
            (set! (-> sv-80 dest-graph) #f)
            (set! sv-96 (-> sv-80 dummy-node))
            (set! (-> sv-96 id) (the-as uint #xffff))
            (set! (-> sv-96 flags) (the-as nav-node-flag-byte (-> sv-48 nav_node_flag)))
            (set-pos-xyz sv-96 (-> sv-48 position))
            (set-angle sv-96 (-> sv-48 angle))
            (set-radius sv-96 (-> sv-48 radius))
            (set! (-> sv-96 level) (-> sv-48 level_name))
            (set! (-> sv-96 nav-mesh-id) (-> sv-48 nav_mesh_id))
            (set-dst-node sv-64 (-> sv-80 dummy-node))
            (format #t "outputting link ~d~%" sv-112)
            (+! (-> this link-count) 1)
            (label cfg-24)
            (+! s5-0 1)
            (set! s0-1 (-> (the-as mysql-nav-edge s0-1) temp-next-edge))
            )
          )
        (label cfg-25)
        (b! (nonzero? sv-32) cfg-15 :delay (nop!))
        (b! #t cfg-33 :delay (nop!))
        (label cfg-27)
        (let ((v1-78 (the-as object (-> s0-0 temp-edge-list))))
          (b! #t cfg-31 :delay (nop!))
          (label cfg-28)
          (when (= arg1 (-> arg0 node-array data (-> (the-as mysql-nav-edge v1-78) runtime-node-id-2) level_name))
            )
          (set! v1-78 (-> (the-as mysql-nav-edge v1-78) temp-next-edge))
          (label cfg-31)
          (b! v1-78 cfg-28 :delay (nop!))
          )
        )
      (label cfg-33)
      (+! s2-0 1)
      (label cfg-34)
      (b! (< s2-0 (-> arg0 node-array length)) cfg-1)
      )
    (format #t "branch-count ~d~%" s5-0)
    )
  (set! (-> this patched) #t)
  (label cfg-36)
  0
  (none)
  )

;; WARN: Return type mismatch nav-graph vs none.
(defun make-nav-graph ((arg0 mysql-nav-graph) (arg1 symbol))
  (mysql-nav-graph-method-20 arg0)
  (let ((s4-0 (the-as nav-graph #f))
        (v1-2 (the-as mysql-nav-graph-level-info #f))
        )
    (dotimes (a0-2 (-> arg0 level-info-array-length))
      (let ((a1-3 (-> arg0 level-info-array a0-2)))
        (if (= (-> a1-3 level) arg1)
            (set! v1-2 a1-3)
            )
        )
      )
    (when v1-2
      (set! s4-0
            (new 'debug 'nav-graph (-> v1-2 node-count) (-> v1-2 branch-count) (-> v1-2 to-link-count) (-> v1-2 level-id))
            )
      (if s4-0
          (from-editor s4-0 arg0 arg1)
          )
      )
    )
  (none)
  )
