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

;; name: ruf-states.gc
;; name in dgo: ruf-states
;; dgos: SEB, SWB, UNB

;; DECOMP BEGINS

(defstate waiting-idle (ruffian)
  :virtual #t
  :event enemy-event-handler
  :enter (behavior ()
    (set-time! (-> self state-time))
    (let ((v1-2 self))
      (set! (-> v1-2 enemy-flags) (the-as enemy-flag (logclear (-> v1-2 enemy-flags) (enemy-flag enemy-flag36))))
      (set! (-> v1-2 nav callback-info) *nav-enemy-null-callback-info*)
      )
    0
    (nav-enemy-method-167 self)
    (let ((v1-7 self))
      (set! (-> v1-7 enemy-flags) (the-as enemy-flag (logclear (-> v1-7 enemy-flags) (enemy-flag enemy-flag37))))
      )
    0
    (look-at-target! self (enemy-flag look-at-focus))
    (set! (-> self travel-anim-interp) 0.0)
    )
  :trans (behavior ()
    (bot-method-223 self #f)
    (when (not (focus-test? self grabbed))
      (cond
        ((bot-method-214 self)
         (go-hostile self)
         )
        ((not (outside-spot-radius? self (the-as bot-spot #f) (the-as vector #f) #f))
         (go-virtual traveling)
         )
        ((and (-> self focus-info fproc) (>= (fabs (-> self focus-info ry-diff)) 9102.223))
         (ruffian-method-241 self)
         )
        ((ruffian-method-243 self)
         (go-virtual plant-bomb)
         )
        )
      )
    (if (logtest? (bot-flags bf19) (-> self bot-flags))
        (ruffian-method-240 self)
        )
    )
  :code nothing
  :post nav-enemy-simple-post
  )

(defstate waiting-turn (ruffian)
  :virtual #t
  :event enemy-event-handler
  :enter (behavior ()
    (set-time! (-> self state-time))
    (let ((v1-2 self))
      (set! (-> v1-2 enemy-flags) (the-as enemy-flag (logclear (-> v1-2 enemy-flags) (enemy-flag enemy-flag36))))
      (set! (-> v1-2 nav callback-info) *nav-enemy-null-callback-info*)
      )
    0
    (nav-enemy-method-167 self)
    (let ((v1-7 self))
      (set! (-> v1-7 enemy-flags) (the-as enemy-flag (logclear (-> v1-7 enemy-flags) (enemy-flag enemy-flag37))))
      )
    0
    (look-at-target! self (enemy-flag look-at-focus))
    (set! (-> self travel-anim-interp) 0.0)
    )
  :trans (behavior ()
    (bot-method-223 self #f)
    (when (not (focus-test? self grabbed))
      (cond
        ((bot-method-214 self)
         (go-hostile self)
         )
        ((not (outside-spot-radius? self (the-as bot-spot #f) (the-as vector #f) #f))
         (go-virtual traveling)
         )
        )
      )
    )
  :code nothing
  :post (behavior ()
    (seek-toward-heading-vec! (-> self root) (-> self focus-info bullseye-xz-dir) 49152.0 (seconds 0.05))
    (nav-enemy-simple-post)
    )
  )

(defstate scared-idle (ruffian)
  :virtual #t
  :event enemy-event-handler
  :enter (behavior ()
    (set-time! (-> self state-time))
    (let ((v1-2 self))
      (set! (-> v1-2 enemy-flags) (the-as enemy-flag (logclear (-> v1-2 enemy-flags) (enemy-flag enemy-flag36))))
      (set! (-> v1-2 nav callback-info) *nav-enemy-null-callback-info*)
      )
    0
    (nav-enemy-method-167 self)
    (let ((v1-7 self))
      (set! (-> v1-7 enemy-flags) (the-as enemy-flag (logclear (-> v1-7 enemy-flags) (enemy-flag enemy-flag37))))
      )
    0
    (look-at-target! self (enemy-flag look-at-focus))
    (set! (-> self travel-anim-interp) 0.0)
    )
  :trans (behavior ()
    (bot-method-223 self #f)
    (when (not (focus-test? self grabbed))
      (cond
        ((bot-method-214 self)
         (go-hostile self)
         )
        ((not (outside-spot-radius? self (the-as bot-spot #f) (the-as vector #f) #f))
         (go-virtual traveling)
         )
        ((and (-> self focus-info fproc) (>= (fabs (-> self focus-info ry-diff)) 9102.223))
         (ruffian-method-241 self)
         )
        )
      )
    (if (not (logtest? (bot-flags bf19) (-> self bot-flags)))
        (ruffian-method-240 self)
        )
    )
  :code nothing
  :post nav-enemy-simple-post
  )

(defstate scared-turn (ruffian)
  :virtual #t
  :event enemy-event-handler
  :enter (behavior ()
    (set-time! (-> self state-time))
    (let ((v1-2 self))
      (set! (-> v1-2 enemy-flags) (the-as enemy-flag (logclear (-> v1-2 enemy-flags) (enemy-flag enemy-flag36))))
      (set! (-> v1-2 nav callback-info) *nav-enemy-null-callback-info*)
      )
    0
    (nav-enemy-method-167 self)
    (let ((v1-7 self))
      (set! (-> v1-7 enemy-flags) (the-as enemy-flag (logclear (-> v1-7 enemy-flags) (enemy-flag enemy-flag37))))
      )
    0
    (look-at-target! self (enemy-flag look-at-focus))
    (set! (-> self travel-anim-interp) 0.0)
    )
  :trans (behavior ()
    (bot-method-223 self #f)
    (when (not (focus-test? self grabbed))
      (cond
        ((bot-method-214 self)
         (go-hostile self)
         )
        ((not (outside-spot-radius? self (the-as bot-spot #f) (the-as vector #f) #f))
         (go-virtual traveling)
         )
        )
      )
    )
  :code nothing
  :post (behavior ()
    (seek-toward-heading-vec! (-> self root) (-> self focus-info bullseye-xz-dir) 49152.0 (seconds 0.05))
    (nav-enemy-simple-post)
    )
  )

(defstate alert-idle (ruffian)
  :virtual #t
  :event enemy-event-handler
  :enter (-> (method-of-type ruffian scared-idle) enter)
  :trans (behavior ()
    (bot-method-223 self #t)
    (when (time-elapsed? (-> self state-time) (seconds 0.1))
      (cond
        ((not (bot-method-214 self))
         (react-to-focus self)
         )
        ((ruffian-method-238 self)
         (go-virtual kick)
         )
        ((ruffian-method-237 self)
         (go-virtual blast)
         )
        )
      )
    (if (and (-> self focus-info fproc) (>= (fabs (-> self focus-info ry-diff)) 9102.223))
        (ruffian-method-241 self)
        )
    )
  :code nothing
  :post nav-enemy-simple-post
  )

(defstate alert-turn (ruffian)
  :virtual #t
  :event enemy-event-handler
  :enter (behavior ()
    (set-time! (-> self state-time))
    (let ((v1-2 self))
      (set! (-> v1-2 enemy-flags) (the-as enemy-flag (logclear (-> v1-2 enemy-flags) (enemy-flag enemy-flag36))))
      (set! (-> v1-2 nav callback-info) *nav-enemy-null-callback-info*)
      )
    0
    (nav-enemy-method-167 self)
    (let ((v1-7 self))
      (set! (-> v1-7 enemy-flags) (the-as enemy-flag (logclear (-> v1-7 enemy-flags) (enemy-flag enemy-flag37))))
      )
    0
    (look-at-target! self (enemy-flag look-at-focus))
    (set! (-> self travel-anim-interp) 0.0)
    )
  :trans (behavior ()
    (bot-method-223 self #t)
    )
  :code nothing
  :post (behavior ()
    (seek-toward-heading-vec! (-> self root) (-> self focus-info bullseye-xz-dir) 49152.0 (seconds 0.05))
    (nav-enemy-simple-post)
    )
  )

(defstate traveling (ruffian)
  :virtual #t
  :event enemy-event-handler
  :enter (behavior ()
    (set-time! (-> self state-time))
    (let ((v1-2 self))
      (if (not (logtest? (enemy-flag enemy-flag36) (-> v1-2 enemy-flags)))
          (set! (-> v1-2 enemy-flags) (the-as enemy-flag (logior (enemy-flag enemy-flag38) (-> v1-2 enemy-flags))))
          )
      (set! (-> v1-2 enemy-flags) (the-as enemy-flag (logior (enemy-flag enemy-flag36) (-> v1-2 enemy-flags))))
      (set! (-> v1-2 nav callback-info) (-> v1-2 enemy-info callback-info))
      )
    0
    (let ((v1-5 self))
      (set! (-> v1-5 enemy-flags) (the-as enemy-flag (logior (enemy-flag enemy-flag37) (-> v1-5 enemy-flags))))
      )
    0
    (stop-looking-at-target! self)
    (nav-enemy-method-166 self)
    (set! (-> self player-blocking) 0.0)
    )
  :trans (behavior ()
    (bot-method-223 self #f)
    (cond
      ((bot-method-214 self)
       (go-hostile self)
       )
      ((outside-spot-radius? self (the-as bot-spot #f) (the-as vector #f) #t)
       (ruffian-method-240 self)
       )
      ((and (time-elapsed? (-> self state-time) (seconds 0.5)) (bot-method-208 self))
       (go-virtual traveling-blocked)
       )
      ((and (nav-enemy-method-163 self) (time-elapsed? (-> self state-time) (-> self reaction-time)))
       (go-stare2 self)
       )
      )
    0
    )
  :code (behavior ()
    (until #f
      (ruffian-method-244 self)
      (suspend)
      )
    #f
    )
  :post (behavior ()
    (let ((a0-0 (-> self nav state))
          (v1-1 (-> self spot))
          )
      (logclear! (-> a0-0 flags) (nav-state-flag directional-mode))
      (logior! (-> a0-0 flags) (nav-state-flag target-poly-dirty))
      (set! (-> a0-0 target-post quad) (-> v1-1 center quad))
      )
    0
    (nav-enemy-travel-post)
    )
  )

(defstate traveling-blocked (ruffian)
  :virtual #t
  :event enemy-event-handler
  :enter (behavior ()
    (set-time! (-> self state-time))
    (let ((v1-2 self))
      (set! (-> v1-2 enemy-flags) (the-as enemy-flag (logclear (-> v1-2 enemy-flags) (enemy-flag enemy-flag36))))
      (set! (-> v1-2 nav callback-info) *nav-enemy-null-callback-info*)
      )
    0
    (nav-enemy-method-167 self)
    (let ((v1-7 self))
      (set! (-> v1-7 enemy-flags) (the-as enemy-flag (logclear (-> v1-7 enemy-flags) (enemy-flag enemy-flag37))))
      )
    0
    (look-at-target! self (enemy-flag look-at-focus))
    (set! (-> self travel-anim-interp) 0.0)
    )
  :trans (behavior ()
    (bot-method-223 self #f)
    (cond
      ((bot-method-214 self)
       (go-hostile self)
       )
      ((and (time-elapsed? (-> self state-time) (seconds 1)) (not (bot-method-208 self)))
       (go-virtual traveling)
       )
      )
    )
  :code nothing
  :post nav-enemy-simple-post
  )

(defstate stare (ruffian)
  :virtual #t
  :enter (behavior ()
    (let ((t9-0 (-> (method-of-type bot stare) enter)))
      (if t9-0
          (t9-0)
          )
      )
    (let ((v1-4 self))
      (set! (-> v1-4 enemy-flags) (the-as enemy-flag (logclear (-> v1-4 enemy-flags) (enemy-flag enemy-flag37))))
      )
    0
    (set! (-> self travel-anim-interp) 0.0)
    )
  :trans (behavior ()
    (bot-method-223 self #f)
    (when (time-elapsed? (-> self state-time) (seconds 0.1))
      (if (bot-method-214 self)
          (go-hostile self)
          )
      (if (not (nav-enemy-method-163 self))
          (go-virtual traveling)
          )
      )
    )
  :code nothing
  )

(defstate kick (ruffian)
  :virtual #t
  :event enemy-event-handler
  :enter (behavior ()
    ((-> (method-of-type nav-enemy hostile) enter))
    (let ((v1-2 self))
      (set! (-> v1-2 enemy-flags) (the-as enemy-flag (logclear (-> v1-2 enemy-flags) (enemy-flag enemy-flag36))))
      (set! (-> v1-2 nav callback-info) *nav-enemy-null-callback-info*)
      )
    0
    (nav-enemy-method-167 self)
    (logior! (-> self enemy-flags) (enemy-flag lock-focus))
    (logior! (-> self focus-status) (focus-status dangerous))
    (let* ((v1-11 *game-info*)
           (a0-6 (+ (-> v1-11 attack-id) 1))
           )
      (set! (-> v1-11 attack-id) a0-6)
      (set! (-> self attack-id) a0-6)
      )
    (set! (-> self travel-anim-interp) 0.0)
    )
  :exit (behavior ()
    (logclear! (-> self enemy-flags) (enemy-flag lock-focus))
    (if (logtest? (-> self enemy-flags) (enemy-flag dangerous-backup))
        (logior! (-> self focus-status) (focus-status dangerous))
        (logclear! (-> self focus-status) (focus-status dangerous))
        )
    )
  :trans (behavior ()
    (bot-method-223 self #f)
    )
  :code nothing
  :post (behavior ()
    (seek-toward-heading-vec! (-> self root) (-> self focus-info bullseye-xz-dir) 131072.0 (seconds 0.05))
    (nav-enemy-simple-post)
    )
  )

(defstate blast (ruffian)
  :virtual #t
  :event enemy-event-handler
  :enter (behavior ()
    ((-> (method-of-type nav-enemy hostile) enter))
    (let ((v1-2 self))
      (set! (-> v1-2 enemy-flags) (the-as enemy-flag (logclear (-> v1-2 enemy-flags) (enemy-flag enemy-flag36))))
      (set! (-> v1-2 nav callback-info) *nav-enemy-null-callback-info*)
      )
    0
    (nav-enemy-method-167 self)
    (logior! (-> self enemy-flags) (enemy-flag lock-focus))
    (if (not (handle->process (-> self focus handle)))
        (react-to-focus self)
        )
    (set! (-> self travel-anim-interp) 0.0)
    )
  :exit (behavior ()
    (logclear! (-> self enemy-flags) (enemy-flag lock-focus))
    )
  :code nothing
  :post nav-enemy-simple-post
  )

(defstate bomb-recoil (ruffian)
  :virtual #t
  :event enemy-event-handler
  :enter (behavior ()
    (let ((v1-0 self))
      (set! (-> v1-0 enemy-flags) (the-as enemy-flag (logclear (-> v1-0 enemy-flags) (enemy-flag enemy-flag36))))
      (set! (-> v1-0 nav callback-info) *nav-enemy-null-callback-info*)
      )
    0
    (nav-enemy-method-167 self)
    (set! (-> self travel-anim-interp) 0.0)
    )
  :code nothing
  :post nav-enemy-simple-post
  )

(defstate hit (ruffian)
  :virtual #t
  :enter (behavior ()
    (let ((t9-0 (-> (method-of-type bot hit) enter)))
      (if t9-0
          (t9-0)
          )
      )
    (set! (-> self travel-anim-interp) 0.0)
    (set! (-> self next-fire-time) 0)
    0
    )
  :code nothing
  )

(defstate knocked (ruffian)
  :virtual #t
  :enter (behavior ()
    (let ((t9-0 (-> (method-of-type bot knocked) enter)))
      (if t9-0
          (t9-0)
          )
      )
    (logclear! (-> self bot-flags) (bot-flags bf24))
    (when (and (nonzero? (-> self hit-points)) (zero? (-> self fated-time)))
      (if (logtest? (-> self bot-flags) (bot-flags bf04))
          (logior! (-> self bot-flags) (bot-flags bf12))
          (logior! (-> self bot-flags) (bot-flags bf24))
          )
      )
    (set! (-> self travel-anim-interp) 0.0)
    )
  :trans (behavior ()
    (let ((t9-0 (-> (method-of-type bot knocked) trans)))
      (if t9-0
          (t9-0)
          )
      )
    (when (and (logtest? (bot-flags bf24) (-> self bot-flags)) (!= (-> self state-time) (current-time)))
      (logclear! (-> self bot-flags) (bot-flags bf24))
      (ruffian-method-242 self)
      )
    )
  )

(defstate die-falling (ruffian)
  :virtual #t
  :enter (behavior ()
    (let ((t9-0 (-> (method-of-type bot die-falling) enter)))
      (if t9-0
          (t9-0)
          )
      )
    (set! (-> self travel-anim-interp) 0.0)
    )
  )

(defstate failed (ruffian)
  :virtual #t
  :enter (behavior ()
    (let ((t9-0 (-> (method-of-type bot failed) enter)))
      (if t9-0
          (t9-0)
          )
      )
    (set! (-> self travel-anim-interp) 0.0)
    )
  :code nothing
  )

(defstate plant-bomb (ruffian)
  :virtual #t
  :event enemy-event-handler
  :enter (behavior ()
    (set-time! (-> self state-time))
    (let ((v1-2 self))
      (set! (-> v1-2 enemy-flags) (the-as enemy-flag (logclear (-> v1-2 enemy-flags) (enemy-flag enemy-flag36))))
      (set! (-> v1-2 nav callback-info) *nav-enemy-null-callback-info*)
      )
    0
    (nav-enemy-method-167 self)
    (let ((v1-7 self))
      (set! (-> v1-7 enemy-flags) (the-as enemy-flag (logclear (-> v1-7 enemy-flags) (enemy-flag enemy-flag37))))
      )
    0
    (stop-looking-at-target! self)
    (set! (-> self travel-anim-interp) 0.0)
    )
  :trans (behavior ()
    (bot-method-223 self #f)
    (cond
      ((bot-method-214 self)
       (go-hostile self)
       )
      ((not (outside-spot-radius? self (the-as bot-spot #f) (the-as vector #f) #f))
       (go-virtual traveling)
       )
      ((and (not (ruffian-method-243 self)) (not (logtest? (bot-flags bf21) (-> self bot-flags))))
       (react-to-focus self)
       )
      )
    )
  :code nothing
  :post nav-enemy-simple-post
  )
