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

;; name: sig-task.gc
;; name in dgo: sig-task
;; dgos: ATE, UNB

;; DECOMP BEGINS

(defmethod reset-task! ((this sigt-wait-spot))
  (set! (-> this check-done) #f)
  (set! (-> this which-spot) -1)
  (set! (-> this num-spots) (the-as uint 0))
  0
  (none)
  )

(defmethod ai-task-method-11 ((this sigt-wait-spot) (arg0 bot))
  (let ((s4-0 (-> this which-spot)))
    (when (>= s4-0 0)
      (let ((s3-0 (-> arg0 course spots (-> this spot-indexes s4-0))))
        (if (and (not (outside-spot-radius? arg0 s3-0 (the-as vector #f) #f)) (player-blocking-spot? arg0 s3-0))
            (set! s4-0 -1)
            )
        )
      )
    (when (< s4-0 0)
      (set! s4-0 (choose-spot arg0 (the-as int (-> this num-spots)) (the-as (pointer uint) (-> this spot-indexes))))
      (set! (-> this which-spot) s4-0)
      (mem-copy!
        (the-as pointer (-> arg0 spot))
        (the-as pointer (-> arg0 course spots (-> this spot-indexes s4-0)))
        20
        )
      )
    (if (logtest? *display-bot-marks* (bot-marks-controls bmc16))
        (bot-debug-draw-spot-sphere
          arg0
          (the-as int (-> this num-spots))
          (the-as (pointer uint) (-> this spot-indexes))
          (the-as int (-> this spot-indexes s4-0))
          )
        )
    )
  (when (not ((-> this check-done) this (the-as sig arg0)))
    (let ((a1-10 (handle->process (-> arg0 focus handle))))
      (cond
        ((and a1-10
              (attacked-by-player? arg0 (the-as process-focusable a1-10))
              (not (logtest? (-> arg0 focus-status) (focus-status grabbed)))
              )
         (get-task-by-type (-> arg0 ai-ctrl) sigt-fight-focus arg0)
         (ai-task-control-method-10 (-> arg0 ai-ctrl) arg0)
         )
        ((logtest? (bot-flags bf19) (-> arg0 bot-flags))
         (get-task-by-type (-> arg0 ai-ctrl) sigt-repair-gun arg0)
         (ai-task-control-method-10 (-> arg0 ai-ctrl) arg0)
         )
        )
      )
    )
  (none)
  )

;; WARN: Return type mismatch object vs none.
(defmethod ai-task-method-11 ((this sigt-fight-focus) (arg0 bot))
  (let ((a1-1 (handle->process (-> arg0 focus handle))))
    (if (and a1-1
             (attacked-by-player? arg0 (the-as process-focusable a1-1))
             (not (logtest? (-> arg0 focus-status) (focus-status grabbed)))
             )
        (logior! (-> arg0 bot-flags) (bot-flags bf00))
        (ai-task-control-method-14 (-> arg0 ai-ctrl) this arg0)
        )
    )
  (none)
  )

;; WARN: Return type mismatch bot-flags vs none.
(defmethod ai-task-method-10 ((this sigt-fight-focus) (arg0 bot))
  (logclear! (-> arg0 bot-flags) (bot-flags bf00))
  (none)
  )

(defmethod ai-task-method-11 ((this sigt-repair-gun) (arg0 bot))
  (cond
    ((not (logtest? (bot-flags bf19) (-> arg0 bot-flags)))
     (ai-task-control-method-14 (-> arg0 ai-ctrl) this arg0)
     )
    (else
      (let ((a1-4 (handle->process (-> arg0 focus handle))))
        (when (and a1-4
                   (attacked-by-player? arg0 (the-as process-focusable a1-4))
                   (not (logtest? (-> arg0 focus-status) (focus-status grabbed)))
                   )
          (get-task-by-type (-> arg0 ai-ctrl) sigt-fight-focus arg0)
          (ai-task-control-method-10 (-> arg0 ai-ctrl) arg0)
          )
        )
      )
    )
  (none)
  )

(defmethod sigt-choose-piston-method-14 ((this sigt-choose-piston) (arg0 sig) (arg1 int))
  (let* ((v1-2 (-> arg0 course spots (-> this spot-indexes arg1)))
         (a0-6 (-> arg0 actor-group 0 data (-> this actor-indexes arg1) actor))
         (gp-0 (if a0-6
                   (-> a0-6 extra process)
                   )
               )
         )
    (or (player-blocking-spot? arg0 v1-2)
        (or (not gp-0)
            (>= 14336.0 (vector-vector-xz-distance (target-pos 0) (-> (the-as process-focusable gp-0) root trans)))
            )
        )
    )
  )

(defmethod sigt-choose-piston-method-13 ((this sigt-choose-piston) (arg0 sig))
  (let ((s4-0 0))
    (let ((f30-0 -1.0)
          (s3-0 (-> arg0 root trans))
          )
      (countdown (s2-0 (-> this num-spots))
        (let* ((v1-3 (-> this spot-indexes s2-0))
               (f28-0 (vector-vector-xz-distance s3-0 (the-as vector (-> arg0 course spots v1-3))))
               )
          (when (and (or (< f30-0 0.0) (< f28-0 f30-0)) (not (sigt-choose-piston-method-14 this arg0 (the-as int s2-0))))
            (set! f30-0 f28-0)
            (set! s4-0 (the-as int s2-0))
            )
          )
        )
      )
    (set! (-> this which-spot) s4-0)
    (mem-copy!
      (the-as pointer (-> arg0 spot))
      (the-as pointer (-> arg0 course spots (-> this spot-indexes s4-0)))
      20
      )
    (let* ((v1-22 (-> arg0 actor-group 0 data (-> this actor-indexes s4-0) actor))
           (a0-6 (if v1-22
                     (-> v1-22 extra process)
                     )
                 )
           )
      (if a0-6
          (set! (-> arg0 poi-handle) (process->handle a0-6))
          )
      )
    )
  (none)
  )

(defmethod sigt-choose-piston-method-12 ((this sigt-choose-piston) (arg0 sig))
  (with-pp
    (when (and (outside-spot-radius? arg0 (the-as bot-spot #f) (the-as vector #f) #f)
               (not (sigt-choose-piston-method-14 this arg0 (-> this which-spot)))
               )
      (let* ((v1-12 (-> arg0 actor-group 0 data (-> this actor-indexes (-> this which-spot)) actor))
             (s5-1 (if v1-12
                       (-> v1-12 extra process)
                       )
                   )
             )
        (when s5-1
          (let ((a1-3 (new 'stack-no-clear 'event-message-block)))
            (set! (-> a1-3 from) (process->ppointer pp))
            (set! (-> a1-3 num-params) 0)
            (set! (-> a1-3 message) 'sync)
            (let ((v1-19
                    (- ((method-of-type sync-info get-timeframe-offset!) (the-as sync-info (send-event-function s5-1 a1-3)) 0)
                       (current-time)
                       )
                    )
                  )
              (when (and (< v1-19 (seconds 0.5)) (< (seconds 0.2) v1-19))
                (let ((v1-22 (-> (the-as process-focusable s5-1) root))
                      (s4-0 (-> arg0 root))
                      )
                  (when (>= 10012.445
                            (fabs
                              (deg-
                                (atan (- (-> v1-22 trans x) (-> s4-0 trans x)) (- (-> v1-22 trans z) (-> s4-0 trans z)))
                                (quaternion-y-angle (-> s4-0 quat))
                                )
                              )
                            )
                    (set! (-> arg0 enemy-flags)
                          (the-as enemy-flag (logclear (-> arg0 enemy-flags) (enemy-flag jump-check-blocked)))
                          )
                    (when (send-event arg0 'jump 4 (-> (the-as process-focusable s5-1) root trans))
                      (set! (-> arg0 spot center quad) (-> (the-as process-focusable s5-1) root trans quad))
                      (set! (-> arg0 spot center w) 10240.0)
                      (return #t)
                      )
                    )
                  )
                )
              )
            )
          )
        )
      )
    #f
    )
  )

(defmethod reset-task! ((this sigt-choose-piston))
  (set! (-> this check-done) #f)
  (set! (-> this which-spot) -1)
  (set! (-> this num-spots) (the-as uint 0))
  0
  (none)
  )

(defmethod ai-task-method-11 ((this sigt-choose-piston) (arg0 bot))
  (let ((s4-0 (-> this which-spot)))
    (cond
      ((< s4-0 0)
       (sigt-choose-piston-method-13 this (the-as sig arg0))
       )
      ((sigt-choose-piston-method-14 this (the-as sig arg0) s4-0)
       (sigt-choose-piston-method-13 this (the-as sig arg0))
       )
      )
    (if (logtest? *display-bot-marks* (bot-marks-controls bmc16))
        (bot-debug-draw-spot-sphere
          arg0
          (the-as int (-> this num-spots))
          (the-as (pointer uint) (-> this spot-indexes))
          (the-as int (-> this spot-indexes s4-0))
          )
        )
    )
  (when (not ((-> this check-done) this (the-as sig arg0)))
    (let ((a1-6 (handle->process (-> arg0 focus handle))))
      (when (and a1-6
                 (attacked-by-player? arg0 (the-as process-focusable a1-6))
                 (not (logtest? (-> arg0 focus-status) (focus-status grabbed)))
                 )
        (get-task-by-type (-> arg0 ai-ctrl) sigt-fight-focus arg0)
        (ai-task-control-method-10 (-> arg0 ai-ctrl) arg0)
        )
      )
    )
  (none)
  )

(defmethod ai-task-method-10 ((this sigt-choose-piston) (arg0 bot))
  (clear-poi-and-focus! arg0)
  (none)
  )

(defmethod sigt-riding-piston-method-12 ((this sigt-riding-piston) (arg0 sig))
  (with-pp
    (when (not (player-blocking-spot? arg0 (-> arg0 course spots (-> this spot-indexes (-> this which-spot)))))
      (let* ((v1-9 (-> arg0 actor-group 0 data (-> arg0 platform-index) actor))
             (a0-4 (if v1-9
                       (-> v1-9 extra process)
                       )
                   )
             )
        (when a0-4
          (let ((a1-6 (new 'stack-no-clear 'event-message-block)))
            (set! (-> a1-6 from) (process->ppointer pp))
            (set! (-> a1-6 num-params) 0)
            (set! (-> a1-6 message) 'sync)
            (let ((v1-16
                    (- ((method-of-type sync-info get-timeframe-offset!) (the-as sync-info (send-event-function a0-4 a1-6)) 0)
                       (current-time)
                       )
                    )
                  )
              (when (and (< v1-16 (seconds 2.8)) (< (seconds 1.8) v1-16))
                (let ((v1-19 (-> arg0 nav)))
                  (set! (-> v1-19 target-speed) 0.0)
                  )
                0
                (let ((s5-1 (-> arg0 course spots (-> this spot-indexes (-> this which-spot)))))
                  (set! (-> arg0 enemy-flags)
                        (the-as enemy-flag (logclear (-> arg0 enemy-flags) (enemy-flag jump-check-blocked)))
                        )
                  (when (send-event arg0 'jump 0 (-> s5-1 center))
                    (mem-copy! (the-as pointer (-> arg0 spot)) (the-as pointer s5-1) 20)
                    (return #t)
                    )
                  )
                )
              )
            )
          )
        )
      )
    #f
    )
  )

(defmethod reset-task! ((this sigt-riding-piston))
  (set! (-> this check-done) #f)
  (set! (-> this which-spot) -1)
  (set! (-> this num-spots) (the-as uint 0))
  0
  (none)
  )

;; WARN: Return type mismatch symbol vs none.
(defmethod ai-task-method-11 ((this sigt-riding-piston) (arg0 bot))
  (let ((s4-0 (-> this which-spot)))
    (when (or (< s4-0 0) (player-blocking-spot? arg0 (-> arg0 course spots (-> this spot-indexes s4-0))))
      (set! s4-0 (choose-spot arg0 (the-as int (-> this num-spots)) (the-as (pointer uint) (-> this spot-indexes))))
      (set! (-> this which-spot) s4-0)
      (send-event
        (ppointer->process (-> arg0 my-simple-focus))
        'move-trans
        (-> arg0 course spots (-> this spot-indexes s4-0))
        )
      (set! (-> arg0 poi-handle) (ppointer->handle (-> arg0 my-simple-focus)))
      )
    (if (logtest? *display-bot-marks* (bot-marks-controls bmc16))
        (bot-debug-draw-spot-sphere
          arg0
          (the-as int (-> this num-spots))
          (the-as (pointer uint) (-> this spot-indexes))
          (the-as int (-> this spot-indexes s4-0))
          )
        )
    )
  ((-> this check-done) this (the-as sig arg0))
  (none)
  )

(defmethod ai-task-method-10 ((this sigt-riding-piston) (arg0 bot))
  (clear-poi-and-focus! arg0)
  (none)
  )

(defmethod reset-task! ((this sigt-charge-plasma))
  (set! (-> this check-done) #f)
  (set! (-> this which-spot) -1)
  (set! (-> this num-spots) (the-as uint 0))
  0
  (none)
  )

(defmethod ai-task-method-11 ((this sigt-charge-plasma) (arg0 bot))
  (let ((s4-0 (-> this which-spot)))
    (when (>= s4-0 0)
      (let ((s3-0 (-> (the-as sig arg0) course spots (-> this spot-indexes s4-0))))
        (if (and (not (outside-spot-radius? (the-as sig arg0) s3-0 (the-as vector #f) #f))
                 (player-blocking-spot? (the-as sig arg0) s3-0)
                 )
            (set! s4-0 -1)
            )
        )
      )
    (when (< s4-0 0)
      (set! s4-0
            (choose-spot
              (the-as sig arg0)
              (the-as int (-> this num-spots))
              (the-as (pointer uint) (-> this spot-indexes))
              )
            )
      (set! (-> this which-spot) s4-0)
      (mem-copy!
        (the-as pointer (-> (the-as sig arg0) spot))
        (the-as pointer (-> (the-as sig arg0) course spots (-> this spot-indexes s4-0)))
        20
        )
      )
    (if (logtest? *display-bot-marks* (bot-marks-controls bmc16))
        (bot-debug-draw-spot-sphere
          (the-as sig arg0)
          (the-as int (-> this num-spots))
          (the-as (pointer uint) (-> this spot-indexes))
          (the-as int (-> this spot-indexes s4-0))
          )
        )
    (let* ((v1-24 (-> (the-as sig arg0) actor-group 0 data (-> this actor-index) actor))
           (s3-1 (when v1-24
                   (let ((s2-0 (-> v1-24 extra process)))
                     (if (type? s2-0 process-focusable)
                         s2-0
                         )
                     )
                   )
                 )
           )
      (cond
        (s3-1
          (set! (-> (the-as sig arg0) poi-handle) (process->handle s3-1))
          (set! (-> (the-as sig arg0) focus-mode) 1)
          (let ((a1-10 (-> (the-as sig arg0) course spots (-> this spot-indexes s4-0))))
            (if (and (outside-spot-radius? (the-as sig arg0) a1-10 (the-as vector #f) #f)
                     (enemy-method-95 (the-as sig arg0) (get-trans (the-as process-focusable s3-1) 3) 10012.445)
                     )
                (logior! (-> (the-as sig arg0) plasma flags) (plasma-flags pf00))
                (logclear! (-> (the-as sig arg0) plasma flags) (plasma-flags pf00))
                )
            )
          )
        (else
          (clear-poi-and-focus! (the-as sig arg0))
          (logclear! (-> (the-as sig arg0) plasma flags) (plasma-flags pf00))
          (set! (-> (the-as sig arg0) focus-mode) 0)
          0
          )
        )
      )
    )
  (when (not ((-> this check-done) this (the-as sig arg0)))
    (let ((a1-14 (handle->process (-> (the-as sig arg0) focus handle))))
      (when (and a1-14
                 (attacked-by-player? (the-as sig arg0) (the-as process-focusable a1-14))
                 (not (logtest? (-> (the-as sig arg0) focus-status) (focus-status grabbed)))
                 )
        (get-task-by-type (-> (the-as sig arg0) ai-ctrl) sigt-fight-focus (the-as sig arg0))
        (ai-task-control-method-10 (-> (the-as sig arg0) ai-ctrl) (the-as sig arg0))
        )
      )
    )
  (none)
  )

(defmethod ai-task-method-10 ((this sigt-charge-plasma) (arg0 bot))
  (clear-poi-and-focus! (the-as sig arg0))
  (logclear! (-> (the-as sig arg0) plasma flags) (plasma-flags pf00))
  (set! (-> (the-as sig arg0) focus-mode) 0)
  0
  (none)
  )
