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

;; name: fordumpa-obs.gc
;; name in dgo: fordumpa-obs
;; dgos: FDA

;; DECOMP BEGINS

(deftype fort-elec-switch (process-drawable)
  ((root                collide-shape :override)
   (l-bolt              lightning-control)
   (notify-actor        entity-actor)
   (tank-actor          entity-actor)
   (switch-group        (pointer actor-group))
   (switch-group-count  int32)
   )
  (:state-methods
    idle
    play-hint
    die
    )
  )


(defskelgroup skel-fort-elec-switch fort-elec-switch fort-elec-switch-lod0-jg fort-elec-switch-idle-ja
              ((fort-elec-switch-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 2 0 3)
              )

(defstate idle (fort-elec-switch)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('attack)
       (go-virtual die)
       'push
       )
      (('hint)
       (go-virtual play-hint)
       )
      )
    )
  :code sleep-code
  )

(defstate play-hint (fort-elec-switch)
  :virtual #t
  :event (-> (method-of-type fort-elec-switch idle) event)
  :code (behavior ()
    (suspend-for (seconds 16))
    (until (logtest? (-> self draw status) (draw-control-status on-screen))
      (suspend)
      )
    (suspend-for (seconds 0.4))
    (talker-spawn-func (-> *talker-speech* 86) *entity-pool* (target-pos 0) (the-as region #f))
    (sleep-code)
    )
  :post (-> (method-of-type fort-elec-switch idle) post)
  )

(defstate die (fort-elec-switch)
  :virtual #t
  :enter (behavior ()
    (process-entity-status! self (entity-perm-status subtask-complete) #t)
    (let ((v1-0 (-> self l-bolt))
          (v0-1 3)
          )
      (let ((a0-2 (!= v0-1 (-> v1-0 state mode))))
        (case v0-1
          ((3)
           (if a0-2
               (set! (-> v1-0 state counter) 0.0)
               )
           )
          ((1)
           (set! (-> v1-0 state start-color) (-> v1-0 spec start-color))
           (set! (-> v1-0 state end-color) (-> v1-0 spec end-color))
           )
          )
        )
      (set! (-> v1-0 state mode) (the-as lightning-mode v0-1))
      )
    )
  :code (behavior ()
    (let ((v1-1 (-> self root root-prim)))
      (set! (-> v1-1 prim-core collide-as) (collide-spec))
      (set! (-> v1-1 prim-core collide-with) (collide-spec))
      )
    0
    (logior! (-> self draw status) (draw-control-status no-draw))
    (let ((gp-0 (new 'stack-no-clear 'vector)))
      (set! (-> gp-0 quad) (-> self root trans quad))
      (+! (-> gp-0 y) 8192.0)
      (let ((s5-0 (get-process *default-dead-pool* part-tracker #x4000)))
        (when s5-0
          (let ((t9-1 (method-of-type part-tracker activate)))
            (t9-1
              (the-as part-tracker s5-0)
              *entity-pool*
              (symbol->string (-> part-tracker symbol))
              (the-as pointer #x70004000)
              )
            )
          (let ((t9-2 run-function-in-process)
                (a0-6 s5-0)
                (a1-2 part-tracker-init)
                (a2-4 (-> *part-group-id-table* 125))
                (a3-1 0)
                (t0-0 #f)
                (t1-0 #f)
                (t2-0 #f)
                (t3-0 *launch-matrix*)
                )
            (set! (-> t3-0 trans quad) (-> gp-0 quad))
            ((the-as (function object object object object object object object object none) t9-2)
             a0-6
             a1-2
             a2-4
             a3-1
             t0-0
             t1-0
             t2-0
             t3-0
             )
            )
          (-> s5-0 ppointer)
          )
        )
      )
    (sound-play "elec-switch")
    (suspend-for (seconds 0.5))
    (let ((v1-22 #t))
      (when (-> self switch-group)
        (dotimes (a0-11 (-> self switch-group-count))
          (let ((a1-6 (-> self switch-group a0-11)))
            (dotimes (a2-7 (-> a1-6 length))
              (if (not (logtest? (-> a1-6 data a2-7 actor extra perm status) (entity-perm-status subtask-complete)))
                  (set! v1-22 #f)
                  )
              )
            )
          )
        )
      (when v1-22
        (set-setting! 'entity-name "camera-180" 0.0 0)
        (set-setting! 'process-mask 'set 0.0 (process-mask movie enemy))
        (process-grab? *target* #f)
        (let ((a1-13 (new 'stack-no-clear 'event-message-block)))
          (set! (-> a1-13 from) (process->ppointer self))
          (set! (-> a1-13 num-params) 0)
          (set! (-> a1-13 message) 'fire-suppress-on)
          (let ((t9-8 send-event-function)
                (v1-30 (-> self tank-actor))
                )
            (t9-8
              (if v1-30
                  (-> v1-30 extra process)
                  )
              a1-13
              )
            )
          )
        (suspend-for (seconds 0.75))
        (let ((a1-14 (new 'stack-no-clear 'event-message-block)))
          (set! (-> a1-14 from) (process->ppointer self))
          (set! (-> a1-14 num-params) 0)
          (set! (-> a1-14 message) 'shutdown)
          (let ((t9-9 send-event-function)
                (v1-40 (-> self notify-actor))
                )
            (t9-9
              (if v1-40
                  (-> v1-40 extra process)
                  )
              a1-14
              )
            )
          )
        (suspend-for (seconds 1.5))
        (remove-setting! 'entity-name)
        (remove-setting! 'process-mask)
        (process-release? *target*)
        (let ((a1-17 (new 'stack-no-clear 'event-message-block)))
          (set! (-> a1-17 from) (process->ppointer self))
          (set! (-> a1-17 num-params) 0)
          (set! (-> a1-17 message) 'fire-suppress-off)
          (let ((t9-13 send-event-function)
                (v1-54 (-> self tank-actor))
                )
            (t9-13
              (if v1-54
                  (-> v1-54 extra process)
                  )
              a1-17
              )
            )
          )
        )
      )
    (cleanup-for-death self)
    )
  )

;; WARN: Return type mismatch process-drawable vs fort-elec-switch.
(defmethod relocate ((this fort-elec-switch) (offset int))
  (if (nonzero? (-> this l-bolt))
      (&+! (-> this l-bolt) offset)
      )
  (the-as fort-elec-switch ((method-of-type process-drawable relocate) this offset))
  )

;; WARN: Return type mismatch object vs none.
(defmethod init-from-entity! ((this fort-elec-switch) (arg0 entity-actor))
  "Typically the method that does the initial setup on the process, potentially using the [[entity-actor]] provided as part of that.
   This commonly includes things such as:
   - stack size
   - collision information
   - loading the skeleton group / bones
   - sounds"
  (local-vars (sv-16 res-tag))
  ;; og:preserve-this added
  (stack-size-set! (-> this top-thread) 512)
  (let ((s4-0 (new 'process 'collide-shape this (collide-list-enum usually-hit-by-player))))
    (let ((v1-2 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 0) (the-as uint 0))))
      (set! (-> v1-2 prim-core collide-as) (collide-spec obstacle))
      (set! (-> v1-2 prim-core collide-with) (collide-spec jak bot player-list))
      (set! (-> v1-2 prim-core action) (collide-action solid))
      (set! (-> v1-2 transform-index) 3)
      (set-vector! (-> v1-2 local-sphere) 0.0 8192.0 0.0 12288.0)
      (set! (-> s4-0 total-prims) (the-as uint 1))
      (set! (-> s4-0 root-prim) v1-2)
      )
    (set! (-> s4-0 nav-radius) (* 0.75 (-> s4-0 root-prim local-sphere w)))
    (let ((v1-5 (-> s4-0 root-prim)))
      (set! (-> s4-0 backup-collide-as) (-> v1-5 prim-core collide-as))
      (set! (-> s4-0 backup-collide-with) (-> v1-5 prim-core collide-with))
      )
    (set! (-> this root) s4-0)
    )
  (process-drawable-from-entity! this arg0)
  (initialize-skeleton
    this
    (the-as skeleton-group (art-group-get-by-name *level* "skel-fort-elec-switch" (the-as (pointer uint32) #f)))
    (the-as pair 0)
    )
  (set! (-> this notify-actor) (entity-actor-lookup arg0 'alt-actor 0))
  (set! (-> this tank-actor) (entity-actor-lookup arg0 'alt-actor 1))
  (set! sv-16 (new 'static 'res-tag))
  (let ((v1-11 (res-lump-data (-> this entity) 'actor-groups pointer :tag-ptr (& sv-16))))
    (cond
      ((and v1-11 (nonzero? (-> sv-16 elt-count)))
       (set! (-> this switch-group) (the-as (pointer actor-group) v1-11))
       (set! (-> this switch-group-count) (the-as int (-> sv-16 elt-count)))
       )
      (else
        (set! (-> this switch-group) (the-as (pointer actor-group) #f))
        (set! (-> this switch-group-count) 0)
        0
        )
      )
    )
  (let ((a0-18 (-> this skel root-channel 0)))
    (set! (-> a0-18 frame-group) (the-as art-joint-anim (-> this draw art-group data 2)))
    (set! (-> a0-18 frame-num) 0.0)
    (joint-control-channel-group! a0-18 (the-as art-joint-anim (-> this draw art-group data 2)) num-func-identity)
    )
  (transform-post)
  (let ((a2-8 (new 'static 'lightning-spec
                :name #f
                :flags (lightning-spec-flags lsf2)
                :start-color (new 'static 'rgba :r #xff :g #xff :b #xff :a #x80)
                :end-color (new 'static 'rgba :a #x80)
                :fade-to-color (new 'static 'rgba :r #xbf :b #x8f :a #x5)
                :fade-start-factor 0.2
                :fade-time 120.0
                :texture (new 'static 'texture-id :index #x83 :page #xc)
                :reduction 0.42
                :num-points 8
                :box-size 3072.0
                :merge-factor 0.5
                :merge-count 2
                :radius 3072.0
                :duration -1.0
                :sound #f
                )
              )
        )
    (set! (-> this l-bolt) (new 'process 'lightning-control a2-8 this 0.0))
    )
  (let ((a0-20 (new 'stack-no-clear 'vector))
        (v1-26 (new 'stack-no-clear 'vector))
        )
    (set! (-> a0-20 quad) (-> this root trans quad))
    (set! (-> v1-26 quad) (-> this root trans quad))
    (+! (-> a0-20 y) 4915.2)
    (+! (-> v1-26 y) 17203.2)
    (set! (-> this l-bolt state meet data 0 quad) (-> a0-20 quad))
    (let ((a0-22 (-> this l-bolt)))
      (set! (-> a0-22 state meet data (+ (-> a0-22 state points-to-draw) -1) quad) (-> v1-26 quad))
      )
    )
  (go (method-of-object this idle))
  (none)
  )

(deftype fort-fence (process-drawable)
  ((root       collide-shape :override)
   (anim       spool-anim)
   (exit-anim  basic)
   (loading?   symbol)
   (tank       handle)
   )
  (:state-methods
    idle
    breaking
    )
  (:methods
    (fort-fence-method-22 (_type_) none)
    (fort-fence-method-23 (_type_) none)
    )
  )


(defskelgroup skel-fort-fence-a fort-fence fort-fence-a-lod0-jg fort-fence-a-idle-ja
              ((fort-fence-a-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 5.6 0 16)
              )

(defskelgroup skel-fort-fence-b fort-fence fort-fence-b-lod0-jg fort-fence-b-idle-ja
              ((fort-fence-b-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 11 0 18)
              )

(defmethod fort-fence-method-22 ((this fort-fence))
  0
  (none)
  )

(defmethod fort-fence-method-23 ((this fort-fence))
  0
  (none)
  )

(defstate idle (fort-fence)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('break)
       (go-virtual breaking)
       )
      (('start-loading)
       (set! (-> self tank) (process->handle proc))
       (let ((v0-0 (the-as object #t)))
         (set! (-> self loading?) (the-as symbol v0-0))
         v0-0
         )
       )
      )
    )
  :trans (behavior ()
    (when (-> self loading?)
      (let ((a1-0 (new 'stack-no-clear 'event-message-block)))
        (set! (-> a1-0 from) (process->ppointer self))
        (set! (-> a1-0 num-params) 0)
        (set! (-> a1-0 message) 'trans)
        (let ((a1-1 (send-event-function (handle->process (-> self tank)) a1-0)))
          (when a1-1
            (let ((f0-0 (vector-vector-distance (-> self root trans) (the-as vector a1-1))))
              (gui-control-method-12
                *gui-control*
                self
                (gui-channel art-load)
                (gui-action queue)
                (-> self anim name)
                0
                (lerp-scale 1.0 100.0 f0-0 163840.0 327680.0)
                (new 'static 'sound-id)
                )
              )
            )
          )
        )
      )
    )
  :code sleep-code
  )

(defstate breaking (fort-fence)
  :virtual #t
  :enter (behavior ()
    (set! (-> self draw bounds w) 327680.0)
    (let* ((a0-0 (the-as collide-shape-prim-group (-> self root root-prim)))
           (v1-4 (-> a0-0 child 0))
           )
      (let ((a0-2 (-> a0-0 child 1)))
        (set! (-> a0-2 prim-core collide-as) (-> v1-4 prim-core collide-as))
        )
      (set! (-> v1-4 prim-core collide-as) (collide-spec))
      )
    0
    )
  :exit (behavior ()
    (let ((a0-0 (-> self anim)))
      (when (and a0-0 (= (-> *setting-control* user-current spooling) (process->ppointer self)))
        (ja-abort-spooled-anim a0-0 (the-as art-joint-anim #f) -1)
        (ja-channel-set! 1)
        (ja :group! (-> self exit-anim) :num! min)
        )
      )
    )
  :code (behavior ()
    (logclear! (-> self mask) (process-mask actor-pause))
    (ja-play-spooled-anim
      (-> self anim)
      (ja-group)
      (the-as art-joint-anim (-> self exit-anim))
      (the-as (function process-drawable symbol) false-func)
      )
    (logior! (-> self mask) (process-mask sleep))
    (suspend)
    0
    )
  :post transform-post
  )

;; WARN: Return type mismatch object vs none.
(defmethod init-from-entity! ((this fort-fence) (arg0 entity-actor))
  "Typically the method that does the initial setup on the process, potentially using the [[entity-actor]] provided as part of that.
   This commonly includes things such as:
   - stack size
   - collision information
   - loading the skeleton group / bones
   - sounds"
  (stack-size-set! (-> this main-thread) 512)
  (fort-fence-method-23 this)
  (process-drawable-from-entity! this arg0)
  (fort-fence-method-22 this)
  (process-entity-status! this (entity-perm-status no-kill) #t)
  (set! (-> this loading?) #f)
  (let ((a0-6 (-> this skel root-channel 0)))
    (set! (-> a0-6 frame-group) (if (> (-> this skel active-channels) 0)
                                    (-> this skel root-channel 0 frame-group)
                                    )
          )
    (set! (-> a0-6 frame-num) 0.0)
    (joint-control-channel-group!
      a0-6
      (if (> (-> this skel active-channels) 0)
          (-> this skel root-channel 0 frame-group)
          )
      num-func-identity
      )
    )
  (transform-post)
  (go (method-of-object this idle))
  (none)
  )

(deftype fort-fence-a (fort-fence)
  ()
  )


(deftype fort-fence-b (fort-fence)
  ()
  )


(defmethod fort-fence-method-22 ((this fort-fence-a))
  (initialize-skeleton
    this
    (the-as skeleton-group (art-group-get-by-name *level* "skel-fort-fence-a" (the-as (pointer uint32) #f)))
    (the-as pair 0)
    )
  (set! (-> this anim)
        (new 'static 'spool-anim :name "fort-fence-a" :anim-name "a-break" :parts 2 :command-list '())
        )
  (set! (-> this exit-anim) (-> this draw art-group data 3))
  0
  (none)
  )

(defmethod fort-fence-method-22 ((this fort-fence-b))
  (initialize-skeleton
    this
    (the-as skeleton-group (art-group-get-by-name *level* "skel-fort-fence-b" (the-as (pointer uint32) #f)))
    (the-as pair 0)
    )
  (set! (-> this anim)
        (new 'static 'spool-anim :name "fort-fence-b" :anim-name "b-break" :parts 2 :command-list '())
        )
  (set! (-> this exit-anim) (-> this draw art-group data 8))
  0
  (none)
  )

(defmethod fort-fence-method-23 ((this fort-fence-a))
  (let ((s5-0 (new 'process 'collide-shape this (collide-list-enum usually-hit-by-player))))
    (let ((s4-0 (new 'process 'collide-shape-prim-group s5-0 (the-as uint 2) 0)))
      (set! (-> s5-0 total-prims) (the-as uint 3))
      (set! (-> s4-0 prim-core collide-as) (collide-spec obstacle camera-blocker))
      (set! (-> s4-0 prim-core action) (collide-action solid))
      (set-vector! (-> s4-0 local-sphere) 0.0 22937.6 0.0 65536.0)
      (set! (-> s5-0 root-prim) s4-0)
      )
    (let ((v1-7 (new 'process 'collide-shape-prim-mesh s5-0 (the-as uint 1) (the-as uint 0))))
      (set! (-> v1-7 prim-core collide-as) (collide-spec obstacle camera-blocker))
      (set! (-> v1-7 prim-core action) (collide-action solid))
      (set! (-> v1-7 transform-index) 3)
      (set-vector! (-> v1-7 local-sphere) 0.0 22937.6 0.0 65536.0)
      )
    (let ((v1-9 (new 'process 'collide-shape-prim-mesh s5-0 (the-as uint 0) (the-as uint 0))))
      (set! (-> v1-9 prim-core collide-as) (collide-spec))
      (set! (-> v1-9 prim-core action) (collide-action solid))
      (set! (-> v1-9 transform-index) 3)
      (set-vector! (-> v1-9 local-sphere) 0.0 22937.6 0.0 65536.0)
      )
    (set! (-> s5-0 nav-radius) (* 0.75 (-> s5-0 root-prim local-sphere w)))
    (let ((v1-12 (-> s5-0 root-prim)))
      (set! (-> s5-0 backup-collide-as) (-> v1-12 prim-core collide-as))
      (set! (-> s5-0 backup-collide-with) (-> v1-12 prim-core collide-with))
      )
    (set! (-> this root) s5-0)
    )
  0
  (none)
  )

(defmethod fort-fence-method-23 ((this fort-fence-b))
  (let ((s5-0 (new 'process 'collide-shape this (collide-list-enum usually-hit-by-player))))
    (let ((s4-0 (new 'process 'collide-shape-prim-group s5-0 (the-as uint 2) 0)))
      (set! (-> s5-0 total-prims) (the-as uint 3))
      (set! (-> s4-0 prim-core collide-as) (collide-spec obstacle camera-blocker))
      (set! (-> s4-0 prim-core action) (collide-action solid))
      (set-vector! (-> s4-0 local-sphere) 0.0 22937.6 0.0 65536.0)
      (set! (-> s5-0 root-prim) s4-0)
      )
    (let ((v1-7 (new 'process 'collide-shape-prim-mesh s5-0 (the-as uint 1) (the-as uint 0))))
      (set! (-> v1-7 prim-core collide-as) (collide-spec obstacle camera-blocker))
      (set! (-> v1-7 prim-core action) (collide-action solid))
      (set! (-> v1-7 transform-index) 13)
      (set-vector! (-> v1-7 local-sphere) 0.0 -16384.0 0.0 73728.0)
      )
    (let ((v1-9 (new 'process 'collide-shape-prim-mesh s5-0 (the-as uint 0) (the-as uint 0))))
      (set! (-> v1-9 prim-core collide-as) (collide-spec))
      (set! (-> v1-9 prim-core action) (collide-action solid))
      (set! (-> v1-9 transform-index) 13)
      (set-vector! (-> v1-9 local-sphere) 0.0 -16384.0 0.0 73728.0)
      )
    (set! (-> s5-0 nav-radius) (* 0.75 (-> s5-0 root-prim local-sphere w)))
    (let ((v1-12 (-> s5-0 root-prim)))
      (set! (-> s5-0 backup-collide-as) (-> v1-12 prim-core collide-as))
      (set! (-> s5-0 backup-collide-with) (-> v1-12 prim-core collide-with))
      )
    (set! (-> this root) s5-0)
    )
  0
  (none)
  )
