;;-*-Lisp-*-
(in-package goal)
(bundles "VI1.DGO")
(require "engine/common-obs/process-taskable.gc")

;; DECOMP BEGINS

(deftype farmer (process-taskable) ())

(defskelgroup *farmer-sg*
  farmer
  farmer-lod0-jg
  farmer-sitting-cycle-ja
  ((farmer-lod0-mg (meters 20)) (farmer-lod1-mg (meters 999999)))
  :bounds (static-spherem 0 0 0 4)
  :shadow farmer-shadow-mg)

(defmethod play-anim! ((this farmer) (arg0 symbol))
  (case (current-status (-> this tasks))
    (((task-status need-hint) (task-status need-introduction))
     (if arg0 (close-status! (-> this tasks) (task-status need-introduction)))
     (new 'static 'spool-anim :name "farmer-introduction" :index 6 :parts 5 :command-list '()))
    (((task-status need-reminder))
     (set! (-> this skippable) #t)
     (cond
       ((zero? (get-reminder (-> this tasks) 0))
        (if arg0 (save-reminder (-> this tasks) 1 0))
        (new 'static 'spool-anim :name "farmer-reminder-1" :index 7 :parts 2 :command-list '()))
       (else
        (if arg0 (save-reminder (-> this tasks) 0 0))
        (new 'static 'spool-anim :name "farmer-reminder-2" :index 8 :parts 2 :command-list '()))))
    (((task-status need-reward-speech))
     (when arg0
       (set! (-> this cell-for-task) (current-task (-> this tasks)))
       (close-current! (-> this tasks)))
     (new 'static 'spool-anim :name "farmer-resolution" :index 9 :parts 4 :command-list '()))
    (else
     (if arg0
       (format 0
               "ERROR: <GMJ>: ~S playing anim for task status ~S~%"
               (-> this name)
               (task-status->string (current-status (-> this tasks)))))
     (-> this draw art-group data 4))))

(defmethod get-art-elem ((this farmer))
  (case (current-status (-> this tasks))
    (((task-status need-hint) (task-status need-introduction) (task-status need-resolution) (task-status invalid))
     (-> this draw art-group data 4))
    (else (-> this draw art-group data 5))))

(defmethod process-taskable-method-43 ((this farmer))
  (when (ambient-control-method-10 (-> this ambient) (new 'stack-no-clear 'vector) (seconds 30) 122880.0 this)
    (let ((f0-2 (rand-float-gen)))
      (cond
        ((< 0.8333333 f0-2) (play-ambient (-> this ambient) "FAR-LO1A" #f (-> this root trans)))
        ((< 0.6666667 f0-2) (play-ambient (-> this ambient) "FAR-AM01" #f (-> this root trans)))
        ((< 0.5 f0-2) #f)
        ((< 0.33333334 f0-2) (play-ambient (-> this ambient) "FAR-AM2A" #f (-> this root trans)))
        ((< 0.16666667 f0-2) (play-ambient (-> this ambient) "FAR-AM02" #f (-> this root trans)))
        (else #f)))))

(defmethod initialize-collision ((this farmer) (arg0 int) (arg1 vector))
  (let ((s5-0 (new 'process 'collide-shape this (collide-list-enum hit-by-player))))
    (let ((s4-0 (new 'process 'collide-shape-prim-group s5-0 (the-as uint 2) 0)))
      (set! (-> s4-0 prim-core collide-as) (collide-kind enemy))
      (set! (-> s4-0 collide-with) (collide-kind target))
      (set! (-> s4-0 prim-core action) (collide-action solid))
      (set! (-> s4-0 prim-core offense) (collide-offense indestructible))
      (set-vector! (-> s4-0 local-sphere) 4096.0 8192.0 -4096.0 12288.0)
      (set-root-prim! s5-0 s4-0)
      (let ((s3-0 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 0))))
        (set! (-> s3-0 prim-core collide-as) (collide-kind enemy))
        (set! (-> s3-0 collide-with) (collide-kind target))
        (set! (-> s3-0 prim-core action) (collide-action solid))
        (set! (-> s3-0 prim-core offense) (collide-offense indestructible))
        (set-vector! (-> s3-0 local-sphere) 4096.0 6144.0 -4096.0 8192.0)
        (append-prim s4-0 s3-0))
      (let ((s3-1 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 0))))
        (set! (-> s3-1 prim-core collide-as) (collide-kind enemy))
        (set! (-> s3-1 collide-with) (collide-kind target))
        (set! (-> s3-1 prim-core action) (collide-action solid))
        (set! (-> s3-1 prim-core offense) (collide-offense indestructible))
        (set-vector! (-> s3-1 local-sphere) 4096.0 10240.0 -4096.0 8192.0)
        (append-prim s4-0 s3-1)))
    (set! (-> s5-0 nav-radius) (* 0.75 (-> s5-0 root-prim local-sphere w)))
    (backup-collide-with-as s5-0)
    (set! (-> this root) s5-0))
  0
  (none))

(defmethod init-from-entity! ((this farmer) (arg0 entity-actor))
  (process-taskable-method-40 this arg0 *farmer-sg* 3 25 (new 'static 'vector :w 4096.0) 5)
  (set! (-> this root nav-radius) 40960.0)
  (nav-mesh-connect this (-> this root) (the-as nav-control #f))
  (set! (-> this tasks) (get-task-control (game-task village1-yakow)))
  (process-taskable-method-42 this)
  (none))
