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

;; definition of type battlecontroller-spawner
(deftype battlecontroller-spawner (structure)
  ((path          path-control  :offset-assert   0)
   (creature      handle        :offset-assert   8)
   (trigger-actor entity-actor  :offset-assert  16)
   (blocker-actor entity-actor  :offset-assert  20)
   (state         int8          :offset-assert  24)
   (enabled       symbol        :offset-assert  28)
   )
  :method-count-assert 9
  :size-assert         #x20
  :flag-assert         #x900000020
  )

;; definition for method 3 of type battlecontroller-spawner
(defmethod inspect battlecontroller-spawner ((obj battlecontroller-spawner))
  (format #t "[~8x] ~A~%" obj 'battlecontroller-spawner)
  (format #t "~Tpath: ~A~%" (-> obj path))
  (format #t "~Tcreature: ~D~%" (-> obj creature))
  (format #t "~Ttrigger-actor: ~A~%" (-> obj trigger-actor))
  (format #t "~Tblocker-actor: ~A~%" (-> obj blocker-actor))
  (format #t "~Tstate: ~D~%" (-> obj state))
  (format #t "~Tenabled: ~A~%" (-> obj enabled))
  obj
  )

;; definition of type battlecontroller-creature-type
(deftype battlecontroller-creature-type (structure)
  ((type2            type         :offset-assert   0)
   (percent          float        :offset-assert   4)
   (pickup-percent   float        :offset-assert   8)
   (pickup-type      pickup-type  :offset-assert  12)
   (max-pickup-count int8         :offset-assert  16)
   (pickup-count     int8         :offset-assert  17)
   )
  :allow-misaligned
  :method-count-assert 9
  :size-assert         #x12
  :flag-assert         #x900000012
  )

;; definition for method 3 of type battlecontroller-creature-type
(defmethod inspect battlecontroller-creature-type ((obj battlecontroller-creature-type))
  (format #t "[~8x] ~A~%" obj 'battlecontroller-creature-type)
  (format #t "~Ttype2: ~A~%" (-> obj type2))
  (format #t "~Tpercent: ~f~%" (-> obj percent))
  (format #t "~Tpickup-percent: ~f~%" (-> obj pickup-percent))
  (format #t "~Tpickup-type: ~D~%" (-> obj pickup-type))
  (format #t "~Tmax-pickup-count: ~D~%" (-> obj max-pickup-count))
  (format #t "~Tpickup-count: ~D~%" (-> obj pickup-count))
  obj
  )

;; definition of type battlecontroller
(deftype battlecontroller (process-drawable)
  ((final-pickup-spawn-point    vector                         :inline   :offset-assert 176)
   (activate-distance           float                                    :offset-assert 192)
   (max-spawn-count             int16                                    :offset-assert 196)
   (spawn-count                 int16                                    :offset-assert 198)
   (die-count                   int16                                    :offset-assert 200)
   (target-count                int8                                     :offset-assert 202)
   (spawner-count               int8                                     :offset-assert 203)
   (creature-type-count         int8                                     :offset-assert 204)
   (spawner-array               battlecontroller-spawner       8 :inline :offset-assert 208)
   (spawn-period                time-frame                               :offset-assert 464)
   (path-spawn                  path-control                             :offset-assert 472)
   (creature-type-array         battlecontroller-creature-type 4 :inline :offset-assert 476)
   (final-pickup-type           pickup-type                              :offset-assert 604)
   (prespawn                    symbol                                   :offset-assert 608)
   (noticed-player              symbol                                   :offset-assert 612)
   (camera-on                   symbol                                   :offset-assert 616)
   (misty-ambush-collision-hack symbol                                   :offset-assert 620)
   (disable-ocean               symbol                                   :offset-assert 624)
   (disable-near-ocean          symbol                                   :offset-assert 628)
   (disable-mid-ocean           symbol                                   :offset-assert 632)
   )
  :heap-base #x210
  :method-count-assert 29
  :size-assert         #x27c
  :flag-assert         #x1d0210027c
  (:methods
    (dummy-20 () none 20)
    (battlecontroller-idle () _type_ :state 21)
    (battlecontroller-play-intro-camera () _type_ :state 22)
    (dummy-23 () none 23)
    (battlecontroller-active () _type_ :state 24)
    (dummy-25 () none 25)
    (battlecontroller-die () _type_ :state 26)
    (TODO-RENAME-27 (_type_) none 27)
    (cleanup-if-finished! (_type_) none 28)
    )
  )

;; definition for method 3 of type battlecontroller
(defmethod inspect battlecontroller ((obj battlecontroller))
  (let ((t9-0 (method-of-type process-drawable inspect)))
    (t9-0 obj)
    )
  (format #t "~T~Tfinal-pickup-spawn-point: #<vector @ #x~X>~%" (-> obj final-pickup-spawn-point))
  (format #t "~T~Tactivate-distance: ~f~%" (-> obj activate-distance))
  (format #t "~T~Tmax-spawn-count: ~D~%" (-> obj max-spawn-count))
  (format #t "~T~Tspawn-count: ~D~%" (-> obj spawn-count))
  (format #t "~T~Tdie-count: ~D~%" (-> obj die-count))
  (format #t "~T~Ttarget-count: ~D~%" (-> obj target-count))
  (format #t "~T~Tspawner-count: ~D~%" (-> obj spawner-count))
  (format #t "~T~Tcreature-type-count: ~D~%" (-> obj creature-type-count))
  (format #t "~T~Tspawner-array[8] @ #x~X~%" (-> obj spawner-array))
  (format #t "~T~Tspawn-period: ~D~%" (-> obj spawn-period))
  (format #t "~T~Tpath-spawn: ~A~%" (-> obj path-spawn))
  (format #t "~T~Tcreature-type-array[4] @ #x~X~%" (-> obj creature-type-array))
  (format #t "~T~Tfinal-pickup-type: ~D~%" (-> obj final-pickup-type))
  (format #t "~T~Tprespawn: ~A~%" (-> obj prespawn))
  (format #t "~T~Tnoticed-player: ~A~%" (-> obj noticed-player))
  (format #t "~T~Tcamera-on: ~A~%" (-> obj camera-on))
  (format #t "~T~Tmisty-ambush-collision-hack: ~A~%" (-> obj misty-ambush-collision-hack))
  (format #t "~T~Tdisable-ocean: ~A~%" (-> obj disable-ocean))
  (format #t "~T~Tdisable-near-ocean: ~A~%" (-> obj disable-near-ocean))
  (format #t "~T~Tdisable-mid-ocean: ~A~%" (-> obj disable-mid-ocean))
  obj
  )

;; definition for function battlecontroller-spawners-full?
(defbehavior battlecontroller-spawners-full? battlecontroller ()
  (dotimes (v1-0 (-> self spawner-count))
    (if (= (-> self spawner-array v1-0 creature) #f)
        (return #f)
        )
    )
  #t
  )

;; definition for function battlecontroller-default-event-handler
;; Used lq/sq
(defbehavior battlecontroller-default-event-handler battlecontroller ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
  (case arg2
    (('child-die)
     (+! (-> self die-count) 1)
     (when (= (-> self die-count) (-> self max-spawn-count))
       (let ((v1-4 (the-as process-drawable arg0)))
         (when v1-4
           (set! (-> self final-pickup-spawn-point quad) (-> v1-4 root trans quad))
           (case (-> self final-pickup-type)
             (((pickup-type fuel-cell))
              #f
              )
             (else
               (set! (-> v1-4 fact pickup-type) (-> self final-pickup-type))
               (set! (-> v1-4 fact pickup-amount) 1.0)
               (let ((f0-1 0.0))
                 (set! (-> v1-4 fact pickup-spawn-amount) f0-1)
                 f0-1
                 )
               )
             )
           )
         )
       )
     )
    (('trigger)
     (go-virtual battlecontroller-die)
     )
    )
  )

;; failed to figure out what this is:
battlecontroller-default-event-handler

;; definition for function battlecontroller-draw-debug
;; INFO: Return type mismatch int vs none.
(defbehavior battlecontroller-draw-debug battlecontroller ()
  (dotimes (gp-0 (-> self spawner-count))
    (dummy-9 (-> self spawner-array gp-0 path))
    )
  0
  (none)
  )

;; definition for function battlecontroller-camera-on
;; INFO: Return type mismatch int vs object.
(defbehavior battlecontroller-camera-on battlecontroller ()
  (when (not (-> self camera-on))
    (set! (-> self camera-on) #t)
    (let ((v1-4 (res-lump-struct (-> self entity) 'camera-name structure)))
      (if v1-4
          (send-event *camera* 'change-to-entity-by-name v1-4)
          )
      )
    )
  (the-as object 0)
  )

;; definition for function battlecontroller-camera-off
;; INFO: Return type mismatch int vs none.
(defbehavior battlecontroller-camera-off battlecontroller ()
  (set! (-> self camera-on) #f)
  (send-event *camera* 'clear-entity)
  0
  (none)
  )

;; definition for function battlecontroller-update-spawners
;; INFO: Return type mismatch int vs none.
(defbehavior battlecontroller-update-spawners battlecontroller ()
  (dotimes (gp-0 (-> self spawner-count))
    (let* ((s5-0 (-> self spawner-array gp-0))
           (s4-0 (handle->process (-> s5-0 creature)))
           )
      (when (and s4-0 (logtest? (-> (the-as nav-enemy s4-0) nav-enemy-flags) (nav-enemy-flags navenmf11)))
        (cond
          ((< (-> s5-0 state) (-> s5-0 path curve num-cverts))
           (when (or (-> self noticed-player) (= (-> s5-0 state) 1))
             (let ((s3-0 (new 'stack-no-clear 'vector)))
               (eval-path-curve-div! (-> s5-0 path) s3-0 (the float (-> s5-0 state)) 'interp)
               (send-event s4-0 'cue-jump-to-point s3-0)
               )
             (if (zero? (logand (-> (the-as nav-enemy s4-0) nav-enemy-flags) (nav-enemy-flags navenmf11)))
                 (+! (-> s5-0 state) 1)
                 )
             )
           )
          (else
            (send-event s4-0 'cue-chase)
            (set! (-> s5-0 creature) (the-as handle #f))
            )
          )
        )
      )
    )
  0
  (none)
  )

;; definition for function battlecontroller-spawn-creature
;; INFO: Return type mismatch int vs handle.
(defbehavior battlecontroller-spawn-creature battlecontroller ((arg0 vector) (arg1 vector))
  (local-vars (v1-25 pickup-type))
  (let ((f0-0 (rand-vu))
        (v1-0 0)
        )
    (dotimes (a0-1 (-> self creature-type-count))
      (when (>= f0-0 0.0)
        (set! f0-0 (- f0-0 (-> self creature-type-array a0-1 percent)))
        (if (< f0-0 0.0)
            (set! v1-0 a0-1)
            )
        )
      )
    (let* ((s5-0 (-> self creature-type-array v1-0))
           (s2-0 (-> s5-0 type2))
           (s1-0 (the-as nav-enemy (get-process *default-dead-pool* s2-0 #x4000)))
           (gp-0 (when s1-0
                   (let ((t9-2 (method-of-type process activate)))
                     (t9-2 s1-0 self s2-0 (the-as pointer #x70004000))
                     )
                   (run-now-in-process s1-0 nav-enemy-init-by-other self arg0 arg1)
                   (-> s1-0 ppointer)
                   )
                 )
           )
      (if (and gp-0 (zero? (-> (the-as (pointer nav-enemy) gp-0) 0 enemy-info)))
          (set! gp-0 (the-as (pointer process) #f))
          )
      (when (the-as (pointer nav-enemy) gp-0)
        (logclear! (-> (the-as (pointer nav-enemy) gp-0) 0 mask) (process-mask actor-pause))
        (if (-> self misty-ambush-collision-hack)
            (logior! (-> (the-as (pointer nav-enemy) gp-0) 0 nav-enemy-flags) (nav-enemy-flags navenmf15))
            )
        (+! (-> self spawn-count) 1)
        (-> self fact pickup-type)
        (cond
          ((and (< (-> s5-0 pickup-count) (-> s5-0 max-pickup-count)) (rand-vu-percent? (-> s5-0 pickup-percent)))
           (+! (-> s5-0 pickup-count) 1)
           (set! v1-25 (-> s5-0 pickup-type))
           )
          (else
            (set! v1-25 (-> self fact pickup-type))
            )
          )
        (set! (-> (the-as (pointer nav-enemy) gp-0) 0 enemy-info pickup-type) v1-25)
        (cond
          ((= v1-25 (pickup-type eco-pill))
           )
          ((= v1-25 (pickup-type none))
           (set! (-> (the-as (pointer nav-enemy) gp-0) 0 enemy-info pickup-amount) 0.0)
           (set! (-> (the-as (pointer nav-enemy) gp-0) 0 enemy-info pickup-spawn-amount) 0.0)
           )
          (else
            (set! (-> (the-as (pointer nav-enemy) gp-0) 0 enemy-info pickup-amount) 1.0)
            (set! (-> (the-as (pointer nav-enemy) gp-0) 0 enemy-info pickup-spawn-amount) 0.0)
            (logior! (-> (the-as (pointer nav-enemy) gp-0) 0 enemy-info options) (fact-options fade))
            (set! (-> (the-as (pointer nav-enemy) gp-0) 0 enemy-info fade-time) (seconds 4))
            )
          )
        )
      (the-as handle (ppointer->handle gp-0))
      )
    )
  )

;; definition for function battlecontroller-spawn-creature-at-spawner
;; INFO: Return type mismatch int vs none.
(defbehavior battlecontroller-spawn-creature-at-spawner battlecontroller ((arg0 int) (arg1 int))
  (let* ((s5-0 (-> self spawner-array arg0))
         (s3-0 (-> s5-0 path))
         (s4-0 (eval-path-curve-div! s3-0 (new 'stack-no-clear 'vector) (the float arg1) 'interp))
         (a1-3 (eval-path-curve-div! s3-0 (new 'stack-no-clear 'vector) (the float (+ arg1 1)) 'interp))
         )
    (when (and (not (handle->process (-> s5-0 creature))) (< (-> self spawn-count) (-> self max-spawn-count)))
      (let ((v1-10 (battlecontroller-spawn-creature s4-0 a1-3)))
        (when (handle->process v1-10)
          (set! (-> s5-0 creature) v1-10)
          (set! (-> s5-0 state) (+ arg1 1))
          )
        )
      )
    )
  0
  (none)
  )

;; definition for function battlecontroller-spawn-creature-random-spawner
;; INFO: Return type mismatch int vs none.
(defbehavior battlecontroller-spawn-creature-random-spawner battlecontroller ()
  (let* ((gp-0 (rand-vu-int-count (-> self spawner-count)))
         (v1-2 (-> self spawner-array gp-0))
         )
    (when (and (-> v1-2 enabled) (-> v1-2 blocker-actor))
      (when (logtest? (-> v1-2 blocker-actor extra perm status) (entity-perm-status complete))
        (set! (-> v1-2 enabled) #f)
        (let ((a0-9 0))
          (dotimes (a1-0 (-> self spawner-count))
            (if (-> self spawner-array a1-0 enabled)
                (+! a0-9 1)
                )
            )
          (if (zero? a0-9)
              (set! (-> self spawn-count) (-> self max-spawn-count))
              )
          )
        )
      )
    (when (and (-> v1-2 enabled) (not (handle->process (-> v1-2 creature))))
      (let ((a1-7 (new 'stack-no-clear 'event-message-block)))
        (set! (-> a1-7 from) self)
        (set! (-> a1-7 num-params) 0)
        (set! (-> a1-7 message) 'spawn)
        (let ((t9-1 send-event-function)
              (v1-3 (-> v1-2 trigger-actor))
              )
          (t9-1
            (if v1-3
                (-> v1-3 extra process)
                )
            a1-7
            )
          )
        )
      (battlecontroller-spawn-creature-at-spawner gp-0 0)
      )
    )
  0
  (none)
  )

;; definition for function battlecontroller-fill-all-spawners
;; INFO: Return type mismatch int vs none.
(defbehavior battlecontroller-fill-all-spawners battlecontroller ()
  (dotimes (gp-0 (-> self spawner-count))
    (battlecontroller-spawn-creature-at-spawner gp-0 1)
    )
  (when (nonzero? (-> self path-spawn))
    (let ((gp-1 (new 'stack-no-clear 'vector)))
      (dotimes (s5-0 (-> self path-spawn curve num-cverts))
        (eval-path-curve-div! (-> self path-spawn) gp-1 (the float s5-0) 'interp)
        (let ((s4-0 (battlecontroller-spawn-creature gp-1 (-> self root trans))))
          (when (handle->process s4-0)
            (suspend)
            (send-event (handle->process s4-0) 'cue-chase)
            )
          )
        )
      )
    )
  0
  (none)
  )

;; definition for function battlecontroller-battle-begin
;; INFO: Return type mismatch int vs none.
(defbehavior battlecontroller-battle-begin battlecontroller ()
  (set-setting! 'music 'danger 0.0 0)
  (let ((gp-0 (entity-actor-count (-> self entity) 'kill-actor)))
    (dotimes (s5-0 gp-0)
      (let ((v1-2 (entity-actor-lookup (-> self entity) 'kill-actor s5-0)))
        (if v1-2
            (logior! (-> v1-2 extra perm status) (entity-perm-status bit-9))
            )
        )
      )
    )
  (let ((gp-1 (entity-actor-count (-> self entity) 'trigger-actor)))
    (dotimes (s5-1 gp-1)
      (let ((s4-0 (new 'stack-no-clear 'event-message-block)))
        (set! (-> s4-0 from) self)
        (set! (-> s4-0 num-params) 0)
        (set! (-> s4-0 message) 'trigger)
        (let ((s3-0 send-event-function)
              (v1-7 (entity-actor-lookup (-> self entity) 'trigger-actor s5-1))
              )
          (s3-0
            (if v1-7
                (-> v1-7 extra process)
                )
            s4-0
            )
          )
        )
      )
    )
  (level-hint-spawn (game-text-id zero) (the-as string #f) (-> self entity) *entity-pool* (game-task none))
  0
  (none)
  )

;; definition for function battlecontroller-off
;; INFO: Return type mismatch int vs none.
(defbehavior battlecontroller-off battlecontroller ()
  (remove-setting! 'music)
  (let ((gp-0 (entity-actor-count (-> self entity) 'kill-actor)))
    (dotimes (s5-0 gp-0)
      (let ((v1-2 (entity-actor-lookup (-> self entity) 'kill-actor s5-0)))
        (if v1-2
            (logclear! (-> v1-2 extra perm status) (entity-perm-status bit-9))
            )
        )
      )
    )
  0
  (none)
  )

;; definition for function battlecontroller-battle-end
(defbehavior battlecontroller-battle-end battlecontroller ()
  (case (-> (level-get-target-inside *level*) name)
    (('citadel)
     (level-hint-spawn
       (game-text-id citadel-battle-end)
       "sksp0378"
       (the-as entity #f)
       *entity-pool*
       (game-task none)
       )
     )
    )
  (battlecontroller-off)
  (none)
  )

;; failed to figure out what this is:
(defstate battlecontroller-idle (battlecontroller)
  :virtual #t
  :event battlecontroller-default-event-handler
  :trans (behavior ()
    0
    (none)
    )
  :code (behavior ()
    (set! (-> self state-time) (-> *display* base-frame-counter))
    (if (-> self prespawn)
        (battlecontroller-fill-all-spawners)
        )
    (loop
      (when (>= (- (-> *display* base-frame-counter) (-> self state-time)) (seconds 0.1))
        (set! (-> self state-time) (-> *display* base-frame-counter))
        (when (and *target*
                   (>= (-> self activate-distance) (vector-vector-distance (-> self root trans) (-> *target* control trans)))
                   )
          (set! (-> self noticed-player) #t)
          (battlecontroller-battle-begin)
          (when (not (-> self prespawn))
            (battlecontroller-fill-all-spawners)
            (suspend)
            0
            )
          (go-virtual battlecontroller-play-intro-camera)
          )
        )
      (suspend)
      )
    (none)
    )
  :post (the-as (function none :behavior battlecontroller) #f)
  )

;; failed to figure out what this is:
(defstate battlecontroller-play-intro-camera (battlecontroller)
  :virtual #t
  :event battlecontroller-default-event-handler
  :enter (behavior ()
    (process-entity-status! self (entity-perm-status bit-3) #t)
    (none)
    )
  :exit (behavior ()
    (process-entity-status! self (entity-perm-status bit-3) #f)
    (none)
    )
  :code (behavior ()
    (go-virtual battlecontroller-active)
    (none)
    )
  )

;; definition for function battlecontroller-disable-ocean
;; INFO: Return type mismatch int vs none.
(defbehavior battlecontroller-disable-ocean battlecontroller ()
  (set! *ocean-off* (-> self disable-ocean))
  (set! *ocean-mid-off* (-> self disable-mid-ocean))
  (set! *ocean-near-off* (-> self disable-near-ocean))
  0
  (none)
  )

;; failed to figure out what this is:
(defstate battlecontroller-active (battlecontroller)
  :virtual #t
  :event battlecontroller-default-event-handler
  :trans (behavior ()
    (if (and *target*
             (>= (-> self activate-distance) (vector-vector-distance (-> self root trans) (-> *target* control trans)))
             )
        (level-hint-spawn (game-text-id zero) (the-as string #f) (-> self entity) *entity-pool* (game-task none))
        )
    (battlecontroller-disable-ocean)
    (battlecontroller-update-spawners)
    (none)
    )
  :code (behavior ()
    (set! (-> self state-time) (-> *display* base-frame-counter))
    (battlecontroller-camera-on)
    (loop
      (when (>= (- (-> *display* base-frame-counter) (-> self state-time)) (seconds 0.1))
        (set! (-> self state-time) (-> *display* base-frame-counter))
        (let ((gp-0 0))
          (let ((v1-8 (-> self child)))
            (while v1-8
              (+! gp-0 1)
              (set! v1-8 (-> v1-8 0 brother))
              (nop!)
              (nop!)
              )
            )
          (if (and (zero? gp-0) (= (-> self spawn-count) (-> self max-spawn-count)))
              (go-virtual battlecontroller-die)
              )
          (when (< gp-0 (-> self target-count))
            (let ((gp-1 (-> *display* base-frame-counter)))
              (until (>= (- (-> *display* base-frame-counter) gp-1) (-> self spawn-period))
                (suspend)
                )
              )
            (battlecontroller-spawn-creature-random-spawner)
            )
          )
        )
      (suspend)
      )
    (none)
    )
  :post (the-as (function none :behavior battlecontroller) #f)
  )

;; definition for function battlecontroller-special-contents?
(defbehavior battlecontroller-special-contents? battlecontroller ()
  (= (-> self final-pickup-type) (pickup-type fuel-cell))
  )

;; definition for function battlecontroller-special-contents-collected?
(defbehavior battlecontroller-special-contents-collected? battlecontroller ()
  (= (-> self entity extra perm user-int8 0) 2)
  )

;; definition for function battlecontroller-set-special-contents-collected
;; INFO: Return type mismatch int vs none.
(defbehavior battlecontroller-set-special-contents-collected battlecontroller ()
  (let ((v1-2 (-> self entity extra perm)))
    (logior! (-> v1-2 status) (entity-perm-status user-set-from-cstage))
    (set! (-> v1-2 user-int8 0) 2)
    )
  0
  (none)
  )

;; definition for function battlecontroller-task-completed?
(defbehavior battlecontroller-task-completed? battlecontroller ()
  (>= (-> self entity extra perm user-int8 0) 1)
  )

;; definition for function battlecontroller-set-task-completed
;; INFO: Return type mismatch int vs none.
(defbehavior battlecontroller-set-task-completed battlecontroller ()
  (let ((v1-2 (-> self entity extra perm)))
    (logior! (-> v1-2 status) (entity-perm-status user-set-from-cstage))
    (set! (-> v1-2 user-int8 0) 1)
    )
  0
  (none)
  )

;; failed to figure out what this is:
(defstate battlecontroller-die (battlecontroller)
  :virtual #t
  :event (the-as
    (function process int symbol event-message-block object :behavior battlecontroller)
    process-drawable-fuel-cell-handler
    )
  :code (behavior ()
    (sound-play "money-pickup" :pitch -1.5 :position #f)
    (battlecontroller-battle-end)
    (battlecontroller-camera-off)
    (battlecontroller-set-task-completed)
    (countdown (gp-1 (entity-actor-count (-> self entity) 'fade-actor))
      (let ((s5-1 (new 'stack-no-clear 'event-message-block)))
        (set! (-> s5-1 from) self)
        (set! (-> s5-1 num-params) 0)
        (set! (-> s5-1 message) 'fade)
        (let ((s4-0 send-event-function)
              (v1-2 (entity-actor-lookup (-> self entity) 'fade-actor gp-1))
              )
          (s4-0
            (if v1-2
                (-> v1-2 extra process)
                )
            s5-1
            )
          )
        )
      )
    (countdown (gp-2 (entity-actor-count (-> self entity) 'alt-actor))
      (let ((s5-2 (new 'stack-no-clear 'event-message-block)))
        (set! (-> s5-2 from) self)
        (set! (-> s5-2 num-params) 0)
        (set! (-> s5-2 message) 'trigger)
        (let ((s4-1 send-event-function)
              (v1-8 (entity-actor-lookup (-> self entity) 'alt-actor gp-2))
              )
          (s4-1
            (if v1-8
                (-> v1-8 extra process)
                )
            s5-2
            )
          )
        )
      )
    (when (and (battlecontroller-special-contents?) (not (battlecontroller-special-contents-collected?)))
      (label cfg-15)
      (birth-pickup-at-point
        (-> self final-pickup-spawn-point)
        (-> self final-pickup-type)
        (the float (-> self entity extra perm task))
        #f
        self
        (the-as fact-info #f)
        )
      (when (not (-> self child))
        (suspend)
        (goto cfg-15)
        )
      (while (-> self child)
        (suspend)
        )
      (battlecontroller-set-special-contents-collected)
      )
    (while (-> self child)
      (suspend)
      )
    (process-entity-status! self (entity-perm-status dead) #t)
    (none)
    )
  :post (the-as (function none :behavior battlecontroller) #f)
  )

;; definition for method 7 of type battlecontroller
;; INFO: Return type mismatch process-drawable vs battlecontroller.
(defmethod relocate battlecontroller ((obj battlecontroller) (arg0 int))
  (dotimes (v1-0 (-> obj spawner-count))
    (let ((a0-3 (-> obj spawner-array v1-0)))
      (if (nonzero? (-> a0-3 path))
          (&+! (-> a0-3 path) arg0)
          )
      )
    )
  (if (nonzero? (-> obj path-spawn))
      (&+! (-> obj path-spawn) arg0)
      )
  (the-as
    battlecontroller
    ((the-as (function process-drawable int process-drawable) (find-parent-method battlecontroller 7)) obj arg0)
    )
  )

;; definition for method 10 of type battlecontroller
;; INFO: Return type mismatch int vs none.
(defmethod deactivate battlecontroller ((obj battlecontroller))
  (with-pp
    (let ((gp-0 pp))
      (set! pp obj)
      (battlecontroller-off)
      (set! pp gp-0)
      )
    ((the-as (function process-drawable none) (find-parent-method battlecontroller 10)) obj)
    0
    (none)
    )
  )

;; definition for method 27 of type battlecontroller
;; INFO: Return type mismatch int vs none.
;; Used lq/sq
(defmethod TODO-RENAME-27 battlecontroller ((obj battlecontroller))
  (local-vars (sv-16 res-tag))
  (set! (-> obj fact)
        (new 'process 'fact-info obj (pickup-type eco-pill-random) (-> *FACT-bank* default-pill-inc))
        )
  (set! (-> obj path) (new 'process 'path-control obj 'path 0.0))
  (logior! (-> obj path flags) (path-control-flag display draw-line draw-point draw-text))
  (set! (-> obj activate-distance) 122880.0)
  (let ((s5-0 0))
    (let* ((s4-0 '(patha pathb pathc pathd pathe pathf pathg pathh))
           (s2-0 (car s4-0))
           )
      (while (not (null? s4-0))
        (let ((v1-7 (res-lump-struct (-> obj entity) (the-as symbol s2-0) structure))
              (s3-0 (-> obj spawner-array s5-0))
              )
          (when (and v1-7 (< s5-0 8))
            (set! (-> s3-0 path) (new 'process 'path-control obj (the-as symbol s2-0) 0.0))
            (set! (-> s3-0 creature) (the-as handle #f))
            (set! (-> s3-0 trigger-actor) #f)
            (set! (-> s3-0 blocker-actor) #f)
            (set! (-> s3-0 enabled) #t)
            (logior! (-> s3-0 path flags) (path-control-flag display draw-line draw-point draw-text))
            (+! s5-0 1)
            )
          )
        (set! s4-0 (cdr s4-0))
        (set! s2-0 (car s4-0))
        )
      )
    (set! (-> obj spawner-count) s5-0)
    )
  0
  (if (res-lump-struct (-> obj entity) 'pathspawn structure)
      (set! (-> obj path-spawn) (new 'process 'path-control obj 'pathspawn 0.0))
      )
  (let ((s5-1 (entity-actor-count (-> obj entity) 'spawner-trigger-actor)))
    (dotimes (s4-1 s5-1)
      (if (< s4-1 (-> obj spawner-count))
          (set! (-> obj spawner-array s4-1 trigger-actor)
                (entity-actor-lookup (-> obj entity) 'spawner-trigger-actor s4-1)
                )
          )
      )
    )
  (let ((s5-2 (entity-actor-count (-> obj entity) 'spawner-blocker-actor)))
    (dotimes (s4-2 s5-2)
      (if (< s4-2 (-> obj spawner-count))
          (set! (-> obj spawner-array s4-2 blocker-actor)
                (entity-actor-lookup (-> obj entity) 'spawner-blocker-actor s4-2)
                )
          )
      )
    )
  (set! (-> obj spawn-period)
        (the-as time-frame (the int (* 300.0 (res-lump-float (-> obj entity) 'delay :default 0.1))))
        )
  (set! (-> obj target-count) 10)
  (set! (-> obj max-spawn-count) 100)
  (set! (-> obj spawn-count) 0)
  (set! (-> obj die-count) 0)
  (set! (-> obj creature-type-count) 1)
  (set! (-> obj noticed-player) #f)
  (set! (-> obj camera-on) #f)
  (let ((v1-46 (res-lump-data (-> obj entity) 'num-lurkers (pointer int32))))
    (when v1-46
      (set! (-> obj target-count) (-> v1-46 0))
      (set! (-> obj max-spawn-count) (-> v1-46 1))
      )
    )
  (set! (-> obj creature-type-array 0 type2) babak)
  (set! (-> obj creature-type-array 0 percent) 1.0)
  (let ((s5-3 0))
    (set! sv-16 (new 'static 'res-tag))
    (let ((v1-49 (res-lump-data (-> obj entity) 'lurker-type pointer :tag-ptr (& sv-16))))
      (when v1-49
        (dotimes (a0-22 (the-as int (-> sv-16 elt-count)))
          (let ((a1-15 (-> (the-as (pointer uint32) (&+ v1-49 (* a0-22 4))))))
            (when (nonzero? a1-15)
              (set! (-> obj creature-type-array s5-3 type2) (the-as type a1-15))
              (+! s5-3 1)
              )
            )
          )
        )
      )
    (set! (-> obj creature-type-count) s5-3)
    )
  (let ((v1-52 (res-lump-data (-> obj entity) 'percent pointer))
        (f0-6 0.0)
        )
    (when v1-52
      (dotimes (a0-26 (-> obj creature-type-count))
        (set! (-> obj creature-type-array a0-26 percent) (fabs (-> (the-as (pointer float) (&+ v1-52 (* a0-26 4))))))
        (+! f0-6 (-> obj creature-type-array a0-26 percent))
        )
      (cond
        ((= f0-6 0.0)
         (set! (-> obj creature-type-count) 1)
         (set! (-> obj creature-type-array 0 percent) 1.0)
         )
        (else
          (let ((f0-9 (/ 1.0 f0-6)))
            (dotimes (v1-57 (-> obj creature-type-count))
              (set! (-> obj creature-type-array 0 percent) (* (-> obj creature-type-array 0 percent) f0-9))
              )
            )
          )
        )
      )
    )
  (set! (-> obj final-pickup-type)
        (res-lump-value (-> obj entity) 'final-pickup pickup-type :default (the-as uint128 7))
        )
  (let ((s5-4 (res-lump-data (-> obj entity) 'pickup-type pointer))
        (s4-3 (res-lump-data (-> obj entity) 'max-pickup-count pointer))
        (v1-63 (res-lump-data (-> obj entity) 'pickup-percent pointer))
        )
    (dotimes (a0-34 (-> obj creature-type-count))
      (let ((a1-34 (-> obj creature-type-array a0-34)))
        (set! (-> a1-34 pickup-count) 0)
        (if s5-4
            (set! (-> a1-34 pickup-type) (the-as pickup-type (-> (the-as (pointer int32) (&+ s5-4 (* a0-34 4))))))
            )
        (if s4-3
            (set! (-> a1-34 max-pickup-count) (-> (the-as (pointer int32) (&+ s4-3 (* a0-34 4)))))
            )
        (if v1-63
            (set! (-> a1-34 pickup-percent) (-> (the-as (pointer float) (&+ v1-63 (* a0-34 4)))))
            )
        )
      )
    )
  (set! (-> obj misty-ambush-collision-hack) #f)
  (set! (-> obj disable-ocean) #f)
  (set! (-> obj disable-mid-ocean) #f)
  (set! (-> obj disable-near-ocean) #t)
  (set! (-> obj final-pickup-spawn-point quad) (-> obj root trans quad))
  (set! (-> obj prespawn) (= (res-lump-value (-> obj entity) 'mode uint128) 1))
  0
  (none)
  )

;; definition for method 28 of type battlecontroller
;; INFO: Return type mismatch int vs none.
(defmethod cleanup-if-finished! battlecontroller ((obj battlecontroller))
  (if (battlecontroller-task-completed?)
      (go (method-of-object obj battlecontroller-die))
      (go (method-of-object obj battlecontroller-idle))
      )
  0
  (none)
  )

;; definition for method 11 of type battlecontroller
(defmethod init-from-entity! battlecontroller ((obj battlecontroller) (arg0 entity-actor))
  (set! (-> obj mask) (logior (process-mask enemy) (-> obj mask)))
  (set! (-> obj root) (new 'process 'trsqv))
  (process-drawable-from-entity! obj arg0)
  (TODO-RENAME-27 obj)
  (cleanup-if-finished! obj)
  (none)
  )
