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

(import "goal_src/jak1/import/teetertotter-ag.gc")

;; definition of type teetertotter
(deftype teetertotter (process-drawable)
  ((launched-player   basic  :offset-assert 176)
   (in-launch-window  basic  :offset-assert 180)
   (rock-is-dangerous basic  :offset-assert 184)
   )
  :heap-base #x50
  :method-count-assert 20
  :size-assert         #xbc
  :flag-assert         #x14005000bc
  (:states
    teetertotter-bend
    teetertotter-idle
    teetertotter-launch
    )
  )

;; definition for method 3 of type teetertotter
(defmethod inspect teetertotter ((obj teetertotter))
  (let ((t9-0 (method-of-type process-drawable inspect)))
    (t9-0 obj)
    )
  (format #t "~T~Tlaunched-player: ~A~%" (-> obj launched-player))
  (format #t "~T~Tin-launch-window: ~A~%" (-> obj in-launch-window))
  (format #t "~T~Trock-is-dangerous: ~A~%" (-> obj rock-is-dangerous))
  obj
  )

;; failed to figure out what this is:
(defskelgroup *teetertotter-sg* teetertotter teetertotter-lod0-jg teetertotter-idle-ja
              ((teetertotter-lod0-mg (meters 20)) (teetertotter-lod1-mg (meters 40)) (teetertotter-lod2-mg (meters 999999)))
              :bounds (static-spherem 0 0 0 8)
              )

;; definition for function target-on-end-of-teetertotter?
;; INFO: Used lq/sq
(defun target-on-end-of-teetertotter? ((arg0 teetertotter))
  (let ((gp-1 (vector-! (new-stack-vector0) (-> *target* control trans) (-> arg0 root trans))))
    (if (< (vector-dot (vector-x-quaternion! (new-stack-vector0) (-> arg0 root quat)) gp-1) -8192.0)
        #t
        )
    )
  )

;; failed to figure out what this is:
(defstate teetertotter-idle (teetertotter)
  :event (behavior ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
    (case arg2
      (('attack)
       (case (-> arg3 param 1)
         (('flop)
          (when (target-on-end-of-teetertotter? self)
            (set! (-> self in-launch-window) #f)
            (increment-success-for-hint (game-text-id misty-teetertotter))
            (go teetertotter-launch)
            )
          )
         )
       )
      (('bonk)
       (when (target-on-end-of-teetertotter? self)
         (level-hint-spawn
           (game-text-id misty-teetertotter)
           "sksp0070"
           (the-as entity #f)
           *entity-pool*
           (game-task none)
           )
         (go teetertotter-bend)
         )
       )
      )
    )
  :code (behavior ()
    (ja :group! (-> self draw art-group data 4) :num! min)
    (loop
      (suspend)
      )
    (none)
    )
  :post (the-as (function none :behavior teetertotter) transform-post)
  )

;; failed to figure out what this is:
(defstate teetertotter-launch (teetertotter)
  :event (behavior ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block))
    (the-as
      object
      (when (= arg2 'touch)
        (if (and ((method-of-type touching-shapes-entry prims-touching?)
                  (the-as touching-shapes-entry (-> arg3 param 0))
                  (the-as collide-shape-moving (-> self root))
                  (the-as uint 1)
                  )
                 (-> self rock-is-dangerous)
                 )
            (send-event arg0 'attack (-> arg3 param 0) (static-attack-info ((mode 'deadly))))
            )
        (when (and ((method-of-type touching-shapes-entry prims-touching?)
                    (the-as touching-shapes-entry (-> arg3 param 0))
                    (the-as collide-shape-moving (-> self root))
                    (the-as uint 2)
                    )
                   (target-on-end-of-teetertotter? self)
                   (not (-> self launched-player))
                   (-> self in-launch-window)
                   )
          (when (send-event
                  arg0
                  'shove
                  #f
                  (static-attack-info ((shove-back (meters 0)) (shove-up (meters 13)) (angle 'jump) (control 1.0)))
                  )
            (let ((v0-0 #t))
              (set! (-> self launched-player) v0-0)
              v0-0
              )
            )
          )
        )
      )
    )
  :code (behavior ()
    (set! (-> self launched-player) #f)
    (ja-no-eval :group! (-> self draw art-group data 4) :num! (seek!) :frame-num 0.0)
    (until (ja-done? 0)
      (let ((f0-4 (ja-aframe-num 0)))
        (set! (-> self in-launch-window) (and (>= f0-4 76.0) (>= 82.0 f0-4)))
        (let ((v1-16 (>= f0-4 12.0)))
          (set! (-> self rock-is-dangerous) (and v1-16 (>= 76.0 f0-4)))
          )
        )
      (suspend)
      (ja :num! (seek!))
      )
    (go teetertotter-idle)
    (none)
    )
  :post (the-as (function none :behavior teetertotter) rider-post)
  )

;; failed to figure out what this is:
(defstate teetertotter-bend (teetertotter)
  :code (behavior ()
    (ja-no-eval :group! (-> self draw art-group data 5) :num! (seek!) :frame-num 0.0)
    (until (ja-done? 0)
      (suspend)
      (ja :num! (seek!))
      )
    (go teetertotter-idle)
    (none)
    )
  :post (the-as (function none :behavior teetertotter) rider-post)
  )

;; definition for method 11 of type teetertotter
;; INFO: Return type mismatch object vs none.
(defmethod init-from-entity! teetertotter ((obj teetertotter) (arg0 entity-actor))
  (let ((s4-0 (new 'process 'collide-shape-moving obj (collide-list-enum hit-by-player))))
    (set! (-> s4-0 dynam) (copy *standard-dynamics* 'process))
    (set! (-> s4-0 reaction) default-collision-reaction)
    (set! (-> s4-0 no-reaction)
          (the-as (function collide-shape-moving collide-shape-intersect vector vector none) nothing)
          )
    (alloc-riders s4-0 1)
    (let ((s3-0 (new 'process 'collide-shape-prim-group s4-0 (the-as uint 5) 0)))
      (set! (-> s3-0 prim-core collide-as) (collide-kind ground-object))
      (set! (-> s3-0 collide-with) (collide-kind target))
      (set! (-> s3-0 prim-core action) (collide-action solid))
      (set-vector! (-> s3-0 local-sphere) 0.0 12288.0 0.0 36864.0)
      (set-root-prim! s4-0 s3-0)
      (let ((s2-0 (new 'process 'collide-shape-prim-sphere s4-0 (the-as uint 1))))
        (set! (-> s2-0 prim-core collide-as) (collide-kind ground-object))
        (set! (-> s2-0 collide-with) (collide-kind target))
        (set! (-> s2-0 prim-core action) (collide-action solid))
        (set! (-> s2-0 prim-core offense) (collide-offense indestructible))
        (set! (-> s2-0 transform-index) 5)
        (set-vector! (-> s2-0 local-sphere) -4096.0 2048.0 0.0 5120.0)
        (append-prim s3-0 s2-0)
        )
      (let ((s2-1 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 0) (the-as uint 2))))
        (set! (-> s2-1 prim-core collide-as) (collide-kind ground-object))
        (set! (-> s2-1 collide-with) (collide-kind target))
        (set! (-> s2-1 prim-core action) (collide-action solid ca-1))
        (set! (-> s2-1 prim-core offense) (collide-offense indestructible))
        (set! (-> s2-1 transform-index) 7)
        (set-vector! (-> s2-1 local-sphere) 0.0 0.0 0.0 32768.0)
        (append-prim s3-0 s2-1)
        )
      (let ((s2-2 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 1) (the-as uint 0))))
        (set! (-> s2-2 prim-core collide-as) (collide-kind ground-object))
        (set! (-> s2-2 collide-with) (collide-kind target))
        (set! (-> s2-2 prim-core action) (collide-action solid))
        (set! (-> s2-2 prim-core offense) (collide-offense indestructible))
        (set! (-> s2-2 transform-index) 4)
        (set-vector! (-> s2-2 local-sphere) 0.0 0.0 0.0 32768.0)
        (append-prim s3-0 s2-2)
        )
      (let ((s2-3 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 2) (the-as uint 0))))
        (set! (-> s2-3 prim-core collide-as) (collide-kind ground-object))
        (set! (-> s2-3 collide-with) (collide-kind target))
        (set! (-> s2-3 prim-core action) (collide-action solid))
        (set! (-> s2-3 prim-core offense) (collide-offense indestructible))
        (set! (-> s2-3 transform-index) 3)
        (set-vector! (-> s2-3 local-sphere) 0.0 0.0 0.0 32768.0)
        (append-prim s3-0 s2-3)
        )
      (let ((s2-4 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 3) (the-as uint 2))))
        (set! (-> s2-4 prim-core collide-as) (collide-kind ground-object))
        (set! (-> s2-4 collide-with) (collide-kind target))
        (set! (-> s2-4 prim-core action) (collide-action solid ca-1))
        (set! (-> s2-4 prim-core offense) (collide-offense indestructible))
        (set! (-> s2-4 transform-index) 3)
        (set-vector! (-> s2-4 local-sphere) 0.0 0.0 0.0 32768.0)
        (append-prim s3-0 s2-4)
        )
      )
    (set! (-> s4-0 nav-radius) (* 0.75 (-> s4-0 root-prim local-sphere w)))
    (backup-collide-with-as s4-0)
    (set! (-> obj root) s4-0)
    )
  (process-drawable-from-entity! obj arg0)
  (initialize-skeleton obj *teetertotter-sg* '())
  (set! (-> obj launched-player) #f)
  (set! (-> obj in-launch-window) #f)
  (set! (-> obj rock-is-dangerous) #f)
  (go teetertotter-idle)
  (none)
  )
