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

;; name: widow-baron.gc
;; name in dgo: widow-baron
;; dgos: TOA

(declare-type baron-pod process-drawable)
(declare-type tomb-boss-pillar process-drawable)

;; DECOMP BEGINS

(deftype widow-float-seeker (structure)
  ((target       float)
   (value        float)
   (vel          float)
   (accel        float)
   (max-vel      float)
   (max-partial  float)
   (bounce-high  float)
   )
  :allow-misaligned
  (:methods
    (widow-float-seeker-method-9 (_type_ float float float float float) none)
    (widow-float-seeker-method-10 (_type_ (pointer float)) none)
    (widow-float-seeker-method-11 (_type_ float) none)
    (widow-float-seeker-method-12 (_type_ float) none)
    )
  )


(defmethod widow-float-seeker-method-9 ((this widow-float-seeker) (arg0 float) (arg1 float) (arg2 float) (arg3 float) (arg4 float))
  (set! (-> this target) arg0)
  (set! (-> this value) arg0)
  (set! (-> this vel) 0.0)
  (set! (-> this accel) arg1)
  (set! (-> this max-vel) arg2)
  (set! (-> this max-partial) arg3)
  (set! (-> this bounce-high) arg4)
  0
  (none)
  )

(defmethod widow-float-seeker-method-10 ((this widow-float-seeker) (arg0 (pointer float)))
  (set! (-> this target) (-> arg0 0))
  (set! (-> this value) (-> arg0 1))
  (set! (-> this vel) (-> arg0 2))
  (set! (-> this accel) (-> arg0 3))
  (set! (-> this max-vel) (-> arg0 4))
  (set! (-> this max-partial) (-> arg0 5))
  (set! (-> this bounce-high) (-> arg0 6))
  0
  (none)
  )

(defmethod widow-float-seeker-method-11 ((this widow-float-seeker) (arg0 float))
  (with-pp
    0.0
    0.0
    (let* ((f1-2 (- (+ (-> this target) arg0) (-> this value)))
           (f0-6 (if (= (-> this target) 0.0)
                     (* (-> this max-partial) (fabs f1-2))
                     (-> this max-vel)
                     )
                 )
           )
      (let ((f1-3 (* f1-2 (* (-> this accel) (-> pp clock time-adjust-ratio)))))
        (+! (-> this vel) f1-3)
        )
      (let ((f1-6 (fabs (-> this vel)))
            (f0-7 (fmin f0-6 (-> this max-vel)))
            )
        (if (< f0-7 f1-6)
            (set! (-> this vel) (* (-> this vel) (/ f0-7 f1-6)))
            )
        )
      )
    (let ((f0-11 (* (-> this vel) (-> pp clock time-adjust-ratio))))
      (+! (-> this value) f0-11)
      )
    (when (and (!= (-> this target) 0.0) (>= (-> this value) (-> this target)) (< 0.0 (-> this vel)))
      (set! (-> this value) (-> this target))
      (set! (-> this vel) (* (-> this vel) (- (-> this bounce-high))))
      )
    0
    (none)
    )
  )

(defmethod widow-float-seeker-method-12 ((this widow-float-seeker) (arg0 float))
  (set! (-> this value) (+ (-> this target) arg0))
  (set! (-> this vel) 0.0)
  0
  (none)
  )

(deftype widow-rand-vector (structure)
  ((min-time  int32)
   (max-time  int32)
   (xz-max    float)
   (y-max     float)
   (timer     int32)
   (value     vector  :inline)
   )
  (:methods
    (init (_type_ int int float float) none)
    (widow-rand-vector-method-10 (_type_) none)
    )
  )


(defmethod init ((this widow-rand-vector) (arg0 int) (arg1 int) (arg2 float) (arg3 float))
  (set! (-> this min-time) arg0)
  (set! (-> this max-time) arg1)
  (set! (-> this xz-max) (/ arg2 2))
  (set! (-> this y-max) (/ arg3 2))
  (set! (-> this timer) 0)
  (vector-reset! (-> this value))
  0
  (none)
  )

(defmethod widow-rand-vector-method-10 ((this widow-rand-vector))
  (with-pp
    (set! (-> this timer)
          (- (the-as time-frame (-> this timer)) (- (current-time) (-> pp clock old-frame-counter)))
          )
    (when (<= (-> this timer) 0)
      (set! (-> this timer) (rand-vu-int-range (-> this min-time) (-> this max-time)))
      (set! (-> this value x) (rand-vu-float-range (- (-> this xz-max)) (-> this xz-max)))
      (set! (-> this value y) (rand-vu-float-range (- (-> this y-max)) (-> this y-max)))
      (set! (-> this value z) (rand-vu-float-range (- (-> this xz-max)) (-> this xz-max)))
      )
    0
    (none)
    )
  )

(deftype widow-oscillator (structure)
  ((target   vector  :inline)
   (value    vector  :inline)
   (vel      vector  :inline)
   (accel    float)
   (max-vel  float)
   (damping  float)
   )
  (:methods
    (widow-oscillator-method-9 (_type_ vector float float float) none)
    (widow-oscillator-method-10 (_type_ vector) none)
    )
  )


(defmethod widow-oscillator-method-9 ((this widow-oscillator) (arg0 vector) (arg1 float) (arg2 float) (arg3 float))
  (cond
    (arg0
      (set! (-> this target quad) (-> arg0 quad))
      (set! (-> this value quad) (-> arg0 quad))
      )
    (else
      (vector-reset! (-> this target))
      (vector-reset! (-> this value))
      )
    )
  (vector-reset! (-> this vel))
  (set! (-> this accel) arg1)
  (set! (-> this max-vel) arg2)
  (set! (-> this damping) arg3)
  0
  (none)
  )

(defmethod widow-oscillator-method-10 ((this widow-oscillator) (arg0 vector))
  (with-pp
    (let ((gp-0 (new 'stack-no-clear 'vector)))
      (let ((f30-0 (fmax (-> this max-vel) (vector-length (-> this vel)))))
        (cond
          (arg0
            (vector+! gp-0 (-> this target) arg0)
            (vector-! gp-0 gp-0 (-> this value))
            )
          (else
            (vector-! gp-0 (-> this target) (-> this value))
            )
          )
        (vector-normalize! gp-0 (* (-> this accel) (-> pp clock time-adjust-ratio)))
        (vector+! (-> this vel) (-> this vel) gp-0)
        (let ((f0-3 (vector-length (-> this vel))))
          (if (< f30-0 f0-3)
              (vector-float*! (-> this vel) (-> this vel) (/ f30-0 f0-3))
              )
          )
        )
      (vector-float*! (-> this vel) (-> this vel) (-> this damping))
      (vector-float*! gp-0 (-> this vel) (-> pp clock time-adjust-ratio))
      (vector+! (-> this value) (-> this value) gp-0)
      )
    0
    (none)
    )
  )

(defskelgroup skel-widow widow widow-lod0-jg widow-drill-ja
              ((widow-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 0 0 12)
              :shadow widow-shadow-mg
              :origin-joint-index 3
              )

(deftype widow-shot (guard-shot)
  ()
  )


(deftype widow (process-drawable)
  ((bomb                          handle              8)
   (next-launch                   int32)
   (launch-dest                   vector              :inline)
   (next-jumper                   int32)
   (ammos                         handle              2)
   (ammo-timers                   time-frame          2)
   (bomb-hits                     int32)
   (circle-center                 vector              :inline)
   (theta                         cam-float-seeker    :inline)
   (traj                          trajectory          :inline)
   (osc                           widow-oscillator    :inline)
   (noise-osc                     widow-oscillator    :inline)
   (rand-vec                      widow-rand-vector   :inline)
   (attack-from-high-deg          symbol)
   (which-gun                     int32)
   (which-pod                     int32)
   (left-cover-angle              widow-float-seeker  :inline :offset 620)
   (right-cover-angle             widow-float-seeker  :inline :offset 648)
   (left-cover-jm                 joint-mod)
   (right-cover-jm                joint-mod)
   (drill-speed                   cam-float-seeker    :inline)
   (drill-angle                   float)
   (left-drill-jm                 joint-mod)
   (right-drill-jm                joint-mod)
   (flying                        symbol)
   (previous-anim                 int32)
   (launched-a-bomb               symbol)
   (old-bomb-hits                 int32)
   (catwalk                       handle              8)
   (heart                         handle)
   (pod                           handle)
   (baron                         (pointer manipy))
   (drill-spark-part              sparticle-launch-control)
   (drill-spark-part-alt          sparticle-launch-control)
   (extract-stone-time            time-frame)
   (extract-stone-part            sparticle-launch-control)
   (insert-stone-time             time-frame)
   (insert-stone-part             sparticle-launch-control)
   (land-part                     sparticle-launch-control)
   (green-charge-part             sparticle-launch-control)
   (green-fire-part               sparticle-launch-control)
   (lightning                     lightning-control   5)
   (stop-catwalk-sound            symbol)
   (catwalk-sound                 sound-id)
   (drill-sound                   sound-id)
   (drill-sound-playing           symbol)
   (drill-sweeten-sound           sound-id)
   (drill-sweeten-sound-playing   symbol)
   (movie-handle                  handle)
   (tilt                          cam-float-seeker    :inline)
   (targetted-catwalk             int32)
   (hover-sound                   sound-id)
   (hover-sound-playing           symbol)
   (shake-sound                   sound-id)
   (shake-sound-playing           symbol)
   (hud                           handle)
   (last-want-stone-talker        int8)
   (last-general-flying-talker    int8)
   (last-launch-droids-talker     int8)
   (last-launch-bombs-talker      int8)
   (last-shoot-gun-talker         int8)
   (last-stone-charge-up-talker   int8)
   (last-after-stone-shot-talker  int8)
   (last-leave-perch-talker       int8)
   (last-damaged-talker           int8)
   (kicked-bombs                  int8)
   (launch-stages-completed       int8)
   (current-shoot-stage           int16)
   (last-gun-hit-stage            int16)
   (gun-hits                      int16)
   (last-attack-id                uint32)
   )
  (:state-methods
    beaten
    kaboom
    hover-low-stage-3
    hover-shooting-stage-3
    hover-launch-bombs-stage-3
    hover-big-blast-stage-3
    hover-rise-stage-3
    hover-jump-down-stage-3
    big-reaction-stage-2
    watch-bombs-stage-2
    launch-bombs-stage-2
    back-to-perch-stage-2
    hover-low-stage-2
    hover-shooting-stage-2
    hover-rise-stage-2
    hover-seek-under-stage-2
    hover-jump-down-stage-2
    launch-droids-stage-2
    big-reaction-stage-1
    watch-bombs-stage-1
    launch-bombs-stage-1
    watch-droids-stage-1
    launch-droids-stage-1
    hidden
    )
  (:methods
    (widow-method-44 (_type_ vector vector) symbol)
    (widow-method-45 (_type_ vector vector vector) none)
    (widow-method-46 (_type_ vector int) none)
    )
  )


(deftype baron-pod (process-drawable)
  ((red-tip-change-time  time-frame)
   (alt-red-tip-on       symbol)
   (blink-time           time-frame)
   (blink-mask           int32)
   (has-stone            symbol)
   )
  (:state-methods
    idle
    )
  (:methods
    (baron-pod-method-21 (_type_ symbol) none)
    )
  )


(defskelgroup skel-baron-pod baron-pod baron-pod-lod0-jg baron-pod-idle-ja
              ((baron-pod-lod0-mg (meters 999999)))
              :bounds (static-spherem 0 0 0 3)
              :shadow baron-pod-shadow-mg
              :origin-joint-index 3
              )

(defmethod baron-pod-method-21 ((this baron-pod) (arg0 symbol))
  (when (>= (- (current-time) (-> this red-tip-change-time)) 0)
    (set! (-> this alt-red-tip-on) (not (-> this alt-red-tip-on)))
    (set! (-> this red-tip-change-time) (+ (current-time) (seconds 0.5)))
    (set! arg0 #t)
    )
  (when (>= (- (current-time) (-> this blink-time)) 0)
    (set! (-> this blink-mask) 0)
    (dotimes (s5-0 10)
      (let* ((f30-0 0.5)
             (v1-17 (/ (the-as int (rand-uint31-gen *random-generator*)) 256))
             (v1-18 (the-as number (logior #x3f800000 v1-17)))
             )
        (if (< f30-0 (+ -1.0 (the-as float v1-18)))
            (logior! (-> this blink-mask) (ash 1 s5-0))
            )
        )
      )
    (set! (-> this blink-time) (+ (current-time) (the int (* 300.0 (rand-vu-float-range 0.25 0.75)))))
    (set! arg0 #t)
    )
  (when arg0
    (remove-from-process *part-engine* this)
    (add-connection *part-engine* this 13 this 3264 (new 'static 'vector :w 819200.0))
    (add-connection *part-engine* this 14 this 3264 (new 'static 'vector :w 819200.0))
    (if (-> this alt-red-tip-on)
        (add-connection *part-engine* this 5 this 3251 (new 'static 'vector :w 819200.0))
        (add-connection *part-engine* this 6 this 3251 (new 'static 'vector :w 819200.0))
        )
    (let ((s5-2 (-> this blink-mask)))
      (if (logtest? s5-2 1)
          (add-connection *part-engine* this 8 this 3252 (new 'static 'vector :w 819200.0))
          )
      (if (logtest? s5-2 2)
          (add-connection *part-engine* this 9 this 3252 (new 'static 'vector :w 819200.0))
          )
      (if (logtest? s5-2 4)
          (add-connection *part-engine* this 10 this 3252 (new 'static 'vector :w 819200.0))
          )
      (if (logtest? s5-2 8)
          (add-connection *part-engine* this 11 this 3252 (new 'static 'vector :w 819200.0))
          )
      (if (logtest? s5-2 16)
          (add-connection *part-engine* this 12 this 3252 (new 'static 'vector :w 819200.0))
          )
      (if (logtest? s5-2 32)
          (add-connection *part-engine* this 15 this 3252 (new 'static 'vector :w 819200.0))
          )
      (if (logtest? s5-2 64)
          (add-connection *part-engine* this 16 this 3252 (new 'static 'vector :w 819200.0))
          )
      (if (logtest? s5-2 128)
          (add-connection *part-engine* this 17 this 3252 (new 'static 'vector :w 819200.0))
          )
      (if (logtest? s5-2 256)
          (add-connection *part-engine* this 18 this 3252 (new 'static 'vector :w 819200.0))
          )
      (if (logtest? s5-2 512)
          (add-connection *part-engine* this 19 this 3252 (new 'static 'vector :w 819200.0))
          )
      )
    (cond
      ((-> this has-stone)
       (add-connection *part-engine* this 4 this 3258 (new 'static 'vector :y 4096.0 :w 819200.0))
       (add-connection *part-engine* this 4 this 3259 (new 'static 'vector :y 4096.0 :w 819200.0))
       )
      (else
        (add-connection *part-engine* this 4 this 3256 (new 'static 'vector :y 4096.0 :w 819200.0))
        (add-connection *part-engine* this 4 this 3257 (new 'static 'vector :y 4096.0 :w 819200.0))
        )
      )
    )
  (if (-> this has-stone)
      (spawn (-> this part) (-> this root trans))
      )
  0
  (none)
  )

(defstate idle (baron-pod)
  :virtual #t
  :event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
    (case message
      (('frame)
       (let ((v1-3 (ja-group)))
         (when (not (and v1-3 (= v1-3 baron-pod-grab-success-ja)))
           (ja :group! baron-pod-grab-success-ja :num! min)
           (set! (-> self draw bounds w) 81920.0)
           )
         )
       (when (and (< (ja-aframe-num 0) 834.0) (>= (the-as float (-> block param 0)) 834.0))
         (setup-masks (-> self draw) 4 2)
         (set! (-> self has-stone) #t)
         (baron-pod-method-21 self #t)
         )
       )
      (('finale)
       (setup-masks (-> self draw) 8 0)
       )
      )
    )
  :trans (behavior ()
    (baron-pod-method-21 self #f)
    )
  :code sleep-code
  :post transform-post
  )

;; WARN: Return type mismatch object vs none.
(defbehavior baron-pod-init-by-other baron-pod ((arg0 vector))
  (let ((s5-0 (new 'process 'collide-shape-moving self (collide-list-enum hit-by-player))))
    (set! (-> s5-0 dynam) (copy *standard-dynamics* 'process))
    (set! (-> s5-0 reaction) cshape-reaction-default)
    (set! (-> s5-0 no-reaction)
          (the-as (function collide-shape-moving collide-query vector vector object) nothing)
          )
    (set! (-> s5-0 penetrated-by) (the-as penetrate -1))
    (let ((v1-7 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 0))))
      (set! (-> v1-7 transform-index) 3)
      (set-vector! (-> v1-7 local-sphere) 0.0 0.0 9216.0 4096.0)
      (set! (-> s5-0 total-prims) (the-as uint 1))
      (set! (-> s5-0 root-prim) v1-7)
      )
    (set! (-> s5-0 nav-radius) 8192.0)
    (let ((v1-9 (-> s5-0 root-prim)))
      (set! (-> s5-0 backup-collide-as) (-> v1-9 prim-core collide-as))
      (set! (-> s5-0 backup-collide-with) (-> v1-9 prim-core collide-with))
      )
    (set! (-> self root) s5-0)
    )
  (set! (-> self root trans quad) (-> arg0 quad))
  (initialize-skeleton
    self
    (the-as skeleton-group (art-group-get-by-name *level* "skel-baron-pod" (the-as (pointer uint32) #f)))
    (the-as pair 0)
    )
  (setup-masks (-> self draw) 0 12)
  (set! (-> self root pause-adjust-distance) 245760.0)
  (let ((v1-21 (-> self node-list data)))
    (set! (-> v1-21 0 param0) (the-as (function cspace transformq none) cspace<-parent-joint!))
    (set! (-> v1-21 0 param1) (the-as basic (-> self parent)))
    (set! (-> v1-21 0 param2) (the-as basic 3))
    )
  (set! (-> self blink-time) 0)
  (set! (-> self red-tip-change-time) 0)
  (set! (-> self has-stone) #f)
  (set! (-> self part) (create-launch-control group-widow-green-cannon-glow-rays self))
  (baron-pod-method-21 self #t)
  (go-virtual idle)
  (none)
  )

(deftype tomb-boss-bridge (process-drawable)
  ()
  (:state-methods
    idle
    )
  )


(defstate idle (tomb-boss-bridge)
  :virtual #t
  :trans (behavior ()
    (when (task-node-closed? (game-task-node tomb-boss-introduction))
      (cleanup-for-death self)
      (deactivate self)
      )
    )
  :code sleep-code
  )

;; WARN: Return type mismatch object vs none.
(defmethod init-from-entity! ((this tomb-boss-bridge) (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"
  (case ((method-of-type res-lump get-property-struct)
         (-> this entity)
         'tomb-boss-bridge-type
         'interp
         -1000000000.0
         (the-as structure 'a)
         (the-as (pointer res-tag) #f)
         *res-static-buf*
         )
    (('b)
     (set! (-> this root) (new 'process 'trsqv))
     (process-drawable-from-entity! this arg0)
     (initialize-skeleton
       this
       (the-as skeleton-group (art-group-get-by-name *level* "skel-tomb-boss-bridge-b" (the-as (pointer uint32) #f)))
       (the-as pair 0)
       )
     )
    (else
      (set! (-> this root) (new 'process 'trsqv))
      (process-drawable-from-entity! this arg0)
      (initialize-skeleton
        this
        (the-as skeleton-group (art-group-get-by-name *level* "skel-tomb-boss-bridge-a" (the-as (pointer uint32) #f)))
        (the-as pair 0)
        )
      )
    )
  (set! (-> this draw light-index) (the-as uint 2))
  (ja-post)
  (go (method-of-object this idle))
  (none)
  )

(defbehavior widow-want-stone-talker widow ()
  (if (or (>= (-> self bomb-hits) 4) (let* ((f30-0 0.001)
                                            (v1-4 (/ (the-as int (rand-uint31-gen *random-generator*)) 256))
                                            (v1-5 (the-as number (logior #x3f800000 v1-4)))
                                            )
                                       (< f30-0 (+ -1.0 (the-as float v1-5)))
                                       )
          )
      (return (the-as sound-id #f))
      )
  (let ((v1-9 (rand-vu-int-count 5)))
    (if (>= v1-9 (-> self last-want-stone-talker))
        (+! v1-9 1)
        )
    (set! (-> self last-want-stone-talker) v1-9)
    (cond
      ((zero? v1-9)
       (talker-spawn-func (-> *talker-speech* 241) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-9 1)
       (talker-spawn-func (-> *talker-speech* 242) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-9 2)
       (talker-spawn-func (-> *talker-speech* 243) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-9 3)
       (talker-spawn-func (-> *talker-speech* 244) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-9 4)
       (talker-spawn-func (-> *talker-speech* 245) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-9 5)
       (talker-spawn-func (-> *talker-speech* 246) *entity-pool* (target-pos 0) (the-as region #f))
       )
      )
    )
  )

(defbehavior widow-general-flying-talker widow ()
  (if (or (>= (-> self bomb-hits) 4) (let* ((f30-0 0.002)
                                            (v1-4 (/ (the-as int (rand-uint31-gen *random-generator*)) 256))
                                            (v1-5 (the-as number (logior #x3f800000 v1-4)))
                                            )
                                       (< f30-0 (+ -1.0 (the-as float v1-5)))
                                       )
          )
      (return (the-as sound-id #f))
      )
  (let ((v1-9 (rand-vu-int-count 4)))
    (if (>= v1-9 (-> self last-general-flying-talker))
        (+! v1-9 1)
        )
    (set! (-> self last-general-flying-talker) v1-9)
    (cond
      ((zero? v1-9)
       (talker-spawn-func (-> *talker-speech* 273) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-9 1)
       (talker-spawn-func (-> *talker-speech* 288) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-9 2)
       (talker-spawn-func (-> *talker-speech* 289) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-9 3)
       (talker-spawn-func (-> *talker-speech* 290) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-9 4)
       (talker-spawn-func (-> *talker-speech* 291) *entity-pool* (target-pos 0) (the-as region #f))
       )
      )
    )
  )

(defbehavior widow-launch-droids-talker widow ()
  (if (or (>= (-> self bomb-hits) 4) (let* ((f30-0 0.9)
                                            (v1-4 (/ (the-as int (rand-uint31-gen *random-generator*)) 256))
                                            (v1-5 (the-as number (logior #x3f800000 v1-4)))
                                            )
                                       (< f30-0 (+ -1.0 (the-as float v1-5)))
                                       )
          )
      (return (the-as sound-id #f))
      )
  (let ((v1-9 (rand-vu-int-count 4)))
    (if (>= v1-9 (-> self last-launch-droids-talker))
        (+! v1-9 1)
        )
    (set! (-> self last-launch-droids-talker) v1-9)
    (cond
      ((zero? v1-9)
       (talker-spawn-func (-> *talker-speech* 247) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-9 1)
       (talker-spawn-func (-> *talker-speech* 248) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-9 2)
       (talker-spawn-func (-> *talker-speech* 249) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-9 3)
       (talker-spawn-func (-> *talker-speech* 250) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-9 4)
       (talker-spawn-func (-> *talker-speech* 299) *entity-pool* (target-pos 0) (the-as region #f))
       )
      )
    )
  )

(defbehavior widow-launch-bombs-talker widow ()
  (if (or (>= (-> self bomb-hits) 4) (let* ((f30-0 0.9)
                                            (v1-4 (/ (the-as int (rand-uint31-gen *random-generator*)) 256))
                                            (v1-5 (the-as number (logior #x3f800000 v1-4)))
                                            )
                                       (< f30-0 (+ -1.0 (the-as float v1-5)))
                                       )
          )
      (return (the-as sound-id #f))
      )
  (let ((v1-9 (rand-vu-int-count 5)))
    (if (>= v1-9 (-> self last-launch-bombs-talker))
        (+! v1-9 1)
        )
    (set! (-> self last-launch-bombs-talker) v1-9)
    (cond
      ((zero? v1-9)
       (talker-spawn-func (-> *talker-speech* 251) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-9 1)
       (talker-spawn-func (-> *talker-speech* 252) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-9 2)
       (talker-spawn-func (-> *talker-speech* 255) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-9 3)
       (talker-spawn-func (-> *talker-speech* 256) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-9 4)
       (talker-spawn-func (-> *talker-speech* 267) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-9 5)
       (talker-spawn-func (-> *talker-speech* 272) *entity-pool* (target-pos 0) (the-as region #f))
       )
      )
    )
  )

(defbehavior widow-shoot-gun-talker widow ()
  (if (or (>= (-> self bomb-hits) 4) (let* ((f30-0 0.7)
                                            (v1-4 (/ (the-as int (rand-uint31-gen *random-generator*)) 256))
                                            (v1-5 (the-as number (logior #x3f800000 v1-4)))
                                            )
                                       (< f30-0 (+ -1.0 (the-as float v1-5)))
                                       )
          )
      (return (the-as sound-id #f))
      )
  (let ((v1-9 (rand-vu-int-count 10)))
    (if (>= v1-9 (-> self last-shoot-gun-talker))
        (+! v1-9 1)
        )
    (set! (-> self last-shoot-gun-talker) v1-9)
    (cond
      ((zero? v1-9)
       (talker-spawn-func (-> *talker-speech* 253) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-9 1)
       (talker-spawn-func (-> *talker-speech* 254) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-9 2)
       (talker-spawn-func (-> *talker-speech* 257) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-9 3)
       (talker-spawn-func (-> *talker-speech* 258) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-9 4)
       (talker-spawn-func (-> *talker-speech* 286) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-9 5)
       (talker-spawn-func (-> *talker-speech* 268) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-9 6)
       (talker-spawn-func (-> *talker-speech* 269) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-9 7)
       (talker-spawn-func (-> *talker-speech* 292) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-9 8)
       (talker-spawn-func (-> *talker-speech* 293) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-9 9)
       (talker-spawn-func (-> *talker-speech* 300) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-9 10)
       (talker-spawn-func (-> *talker-speech* 274) *entity-pool* (target-pos 0) (the-as region #f))
       )
      )
    )
  )

(defbehavior widow-stone-charge-up-talker widow ()
  (if (or (>= (-> self bomb-hits) 4) (let* ((f30-0 0.6)
                                            (v1-4 (/ (the-as int (rand-uint31-gen *random-generator*)) 256))
                                            (v1-5 (the-as number (logior #x3f800000 v1-4)))
                                            )
                                       (< f30-0 (+ -1.0 (the-as float v1-5)))
                                       )
          )
      (return (the-as sound-id #f))
      )
  (let ((v1-9 (rand-vu-int-count 5)))
    (if (>= v1-9 (-> self last-stone-charge-up-talker))
        (+! v1-9 1)
        )
    (set! (-> self last-stone-charge-up-talker) v1-9)
    (cond
      ((zero? v1-9)
       (talker-spawn-func (-> *talker-speech* 259) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-9 1)
       (talker-spawn-func (-> *talker-speech* 260) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-9 2)
       (talker-spawn-func (-> *talker-speech* 264) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-9 3)
       (talker-spawn-func (-> *talker-speech* 296) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-9 4)
       (talker-spawn-func (-> *talker-speech* 298) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-9 5)
       (talker-spawn-func (-> *talker-speech* 266) *entity-pool* (target-pos 0) (the-as region #f))
       )
      )
    )
  )

(defbehavior widow-after-stone-shot-talker widow ()
  (if (or (>= (-> self bomb-hits) 4) (let* ((f30-0 0.6)
                                            (v1-4 (/ (the-as int (rand-uint31-gen *random-generator*)) 256))
                                            (v1-5 (the-as number (logior #x3f800000 v1-4)))
                                            )
                                       (< f30-0 (+ -1.0 (the-as float v1-5)))
                                       )
          )
      (return (the-as sound-id #f))
      )
  (let ((v1-9 (rand-vu-int-count 5)))
    (if (>= v1-9 (-> self last-after-stone-shot-talker))
        (+! v1-9 1)
        )
    (set! (-> self last-after-stone-shot-talker) v1-9)
    (cond
      ((zero? v1-9)
       (talker-spawn-func (-> *talker-speech* 261) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-9 1)
       (talker-spawn-func (-> *talker-speech* 262) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-9 2)
       (talker-spawn-func (-> *talker-speech* 263) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-9 3)
       (talker-spawn-func (-> *talker-speech* 297) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-9 4)
       (talker-spawn-func (-> *talker-speech* 271) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-9 5)
       (talker-spawn-func (-> *talker-speech* 265) *entity-pool* (target-pos 0) (the-as region #f))
       )
      )
    )
  )

(defbehavior widow-leave-perch-talker widow ()
  (if (or (>= (-> self bomb-hits) 4) (let* ((f30-0 0.4)
                                            (v1-4 (/ (the-as int (rand-uint31-gen *random-generator*)) 256))
                                            (v1-5 (the-as number (logior #x3f800000 v1-4)))
                                            )
                                       (< f30-0 (+ -1.0 (the-as float v1-5)))
                                       )
          )
      (return (the-as sound-id #f))
      )
  (let ((v1-9 (rand-vu-int-count 4)))
    (if (>= v1-9 (-> self last-leave-perch-talker))
        (+! v1-9 1)
        )
    (set! (-> self last-leave-perch-talker) v1-9)
    (cond
      ((zero? v1-9)
       (talker-spawn-func (-> *talker-speech* 270) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-9 1)
       (talker-spawn-func (-> *talker-speech* 277) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-9 2)
       (talker-spawn-func (-> *talker-speech* 275) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-9 3)
       (talker-spawn-func (-> *talker-speech* 276) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-9 4)
       (talker-spawn-func (-> *talker-speech* 285) *entity-pool* (target-pos 0) (the-as region #f))
       )
      )
    )
  )

(defbehavior widow-damaged-talker widow ()
  (let* ((f30-0 0.99)
         (v1-2 (/ (the-as int (rand-uint31-gen *random-generator*)) 256))
         (v1-3 (the-as number (logior #x3f800000 v1-2)))
         )
    (if (< f30-0 (+ -1.0 (the-as float v1-3)))
        (return (the-as sound-id #f))
        )
    )
  (let ((v1-7 (rand-vu-int-count 11)))
    (if (>= v1-7 (-> self last-damaged-talker))
        (+! v1-7 1)
        )
    (set! (-> self last-damaged-talker) v1-7)
    (cond
      ((zero? v1-7)
       (talker-spawn-func (-> *talker-speech* 278) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-7 1)
       (talker-spawn-func (-> *talker-speech* 279) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-7 2)
       (talker-spawn-func (-> *talker-speech* 280) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-7 3)
       (talker-spawn-func (-> *talker-speech* 281) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-7 4)
       (talker-spawn-func (-> *talker-speech* 282) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-7 5)
       (talker-spawn-func (-> *talker-speech* 283) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-7 6)
       (talker-spawn-func (-> *talker-speech* 284) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-7 7)
       (talker-spawn-func (-> *talker-speech* 294) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-7 8)
       (talker-spawn-func (-> *talker-speech* 295) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-7 9)
       (talker-spawn-func (-> *talker-speech* 287) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-7 10)
       (talker-spawn-func (-> *talker-speech* 307) *entity-pool* (target-pos 0) (the-as region #f))
       )
      ((= v1-7 11)
       (talker-spawn-func (-> *talker-speech* 304) *entity-pool* (target-pos 0) (the-as region #f))
       )
      )
    )
  )

(defbehavior widow-handler widow ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
  (local-vars (v0-0 object) (sv-224 symbol) (sv-240 symbol) (sv-256 vector) (sv-272 matrix))
  (case arg2
    (('attack)
     (let ((v1-1 (the-as object (-> arg3 param 1))))
       (when (and (logtest? (attack-mask penetrate-using) (-> (the-as attack-info v1-1) mask))
                  (logtest? (penetrate dark-bomb) (-> (the-as attack-info v1-1) penetrate-using))
                  (!= (-> self last-attack-id) (-> (the-as attack-info v1-1) id))
                  )
         (set! (-> self last-attack-id) (-> (the-as attack-info v1-1) id))
         (send-event self 'bomb-hit (target-pos 0) 4)
         (let ((gp-2 (get-process *default-dead-pool* part-tracker #x4000)))
           (when gp-2
             (let ((t9-3 (method-of-type part-tracker activate)))
               (t9-3
                 (the-as part-tracker gp-2)
                 *entity-pool*
                 (symbol->string (-> part-tracker symbol))
                 (the-as pointer #x70004000)
                 )
               )
             (let ((s5-0 run-function-in-process)
                   (s4-0 gp-2)
                   (s3-0 part-tracker-init)
                   (s2-0 group-spydroid-explode)
                   (s1-0 600)
                   (s0-0 #f)
                   )
               (set! sv-224 (the-as symbol #f))
               (set! sv-240 (the-as symbol #f))
               (set! sv-272 *launch-matrix*)
               (set! sv-256 (-> sv-272 trans))
               (let ((v1-16 (-> (vector<-cspace! (new 'stack-no-clear 'vector) (joint-node widow-lod0-jg Lwrist)) quad)))
                 (set! (-> sv-256 quad) v1-16)
                 )
               ((the-as (function object object object object object object object object none) s5-0)
                s4-0
                s3-0
                s2-0
                s1-0
                s0-0
                sv-224
                sv-240
                sv-272
                )
               )
             (-> gp-2 ppointer)
             )
           )
         )
       )
     )
    (('shot-hit-target)
     (when (< (-> self last-gun-hit-stage) (-> self current-shoot-stage))
       (+! (-> self gun-hits) 1)
       (set! v0-0 (-> self current-shoot-stage))
       (set! (-> self last-gun-hit-stage) (the-as int v0-0))
       v0-0
       )
     )
    (('bomb-kicked)
     (set! v0-0 (+ (-> self kicked-bombs) 1))
     (set! (-> self kicked-bombs) (the-as int v0-0))
     v0-0
     )
    (('widow-get-center)
     (-> self circle-center)
     )
    (('debris-hit)
     (when (< -819.2 (-> self osc vel y))
       (sound-play "wid-debris-hit")
       (case (-> arg3 param 0)
         ((1)
          (set! (-> self osc vel y) (+ -3072.0 (-> self osc vel y)))
          )
         ((2)
          (set! (-> self osc vel y) (+ -2048.0 (-> self osc vel y)))
          )
         )
       )
     )
    (('catwalk-hit)
     (let ((v1-26 (-> arg3 param 0)))
       (when (and (> (the-as int v1-26) 0) (< (the-as int v1-26) 8))
         (let ((v1-28 (new 'stack-no-clear 'event-message-block)))
           (set! (-> v1-28 from) (process->ppointer arg0))
           (set! (-> v1-28 num-params) arg1)
           (set! (-> v1-28 message) arg2)
           (set! (-> v1-28 param 0) (-> arg3 param 0))
           (set! (-> v1-28 param 1) (-> arg3 param 1))
           (set! (-> v1-28 param 2) (-> arg3 param 2))
           (set! (-> v1-28 param 3) (-> arg3 param 3))
           (set! (-> v1-28 param 4) (-> arg3 param 4))
           (set! (-> v1-28 param 5) (-> arg3 param 5))
           (send-event-function (handle->process (-> self catwalk 0)) v1-28)
           )
         )
       )
     )
    (('child-jumped)
     (set! v0-0 (logclear (-> (the-as spydroid arg0) enemy-flags) (enemy-flag directed)))
     (set! (-> (the-as spydroid arg0) enemy-flags) (the-as enemy-flag v0-0))
     v0-0
     )
    (('bomb-hit)
     (set! (-> self bomb-hits) (min 4 (+ (-> self bomb-hits) (-> arg3 param 1))))
     (let ((v1-33 (handle->process (-> self hud))))
       (if v1-33
           (set! (-> (the-as hud-widow v1-33) values 1 target) (/ (* 100 (- 4 (-> self bomb-hits))) 4))
           )
       )
     (when (and (not (-> self flying)) (< (-> self bomb-hits) 4))
       (let* ((s4-2 (-> arg3 param 0))
              (v0-9 (vector<-cspace! (new 'stack-no-clear 'vector) (joint-node widow-lod0-jg main)))
              (s5-2 (-> self node-list data 3 bone transform))
              (s4-3 (vector-normalize! (vector-! (new 'stack-no-clear 'vector) (the-as vector s4-2) v0-9) 1.0))
              (f30-0 (vector-dot s4-3 (vector-normalize-copy! (new 'stack-no-clear 'vector) (-> s5-2 vector 2) 1.0)))
              (f28-0 (vector-dot s4-3 (vector-normalize-copy! (new 'stack-no-clear 'vector) (-> s5-2 vector 0) 1.0)))
              )
         (ja-channel-push! 1 (seconds 0.03))
         (set! (-> self drill-speed target) 0.0)
         (cond
           ((< (cos 5461.3335) f30-0)
            (ja :group! widow-hit-front-ja :num! min)
            (setup-masks (-> self draw) 2 128)
            )
           ((and (< (cos 8192.0) f30-0) (< 0.0 f28-0))
            (ja :group! widow-hit-gun-left-ja :num! min)
            (setup-masks (-> self draw) 4 256)
            )
           ((< (cos 8192.0) f30-0)
            (ja :group! widow-hit-gun-right-ja :num! min)
            (setup-masks (-> self draw) 8 512)
            )
           ((< 0.0 f28-0)
            (ja :group! widow-hit-pod-left-ja :num! min)
            (setup-masks (-> self draw) 16 1024)
            )
           (else
             (ja :group! widow-hit-pod-right-ja :num! min)
             (setup-masks (-> self draw) 32 2048)
             )
           )
         )
       )
     (when (-> self flying)
       (set! (-> self drill-speed target) 0.0)
       (cond
         ((>= (-> self bomb-hits) 4)
          #f
          )
         ((begin
            (ja-channel-push! 1 (seconds 0.03))
            (let* ((gp-3 (-> arg3 param 0))
                   (v0-28 (vector<-cspace! (new 'stack-no-clear 'vector) (joint-node widow-lod0-jg main)))
                   (s5-8 (-> self node-list data 3 bone transform))
                   (f0-20 (vector-dot
                            (vector-normalize! (vector-! (new 'stack-no-clear 'vector) (the-as vector gp-3) v0-28) 1.0)
                            (vector-normalize-copy! (new 'stack-no-clear 'vector) (-> s5-8 vector 0) 1.0)
                            )
                          )
                   )
              (< 0.0 f0-20)
              )
            )
          (ja :group! widow-flight-hit-left-ja :num! min)
          (setup-masks (-> self draw) 16 1024)
          )
         (else
           (ja :group! widow-flight-hit-right-ja :num! min)
           (setup-masks (-> self draw) 32 2048)
           )
         )
       )
     )
    )
  )
