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

;; name: cty-attack-controller.gc
;; name in dgo: cty-attack-controller
;; dgos: DESRESC, WWD, CWI

;; +++city-target-type
(defenum city-target-type
  (unk1 1)
  (unk2 2)
  (guard-tazer 3)
  (guard-rifle 4)
  (guard-grenade 5)
  (grunt 6)
  (flitter 7)
  (unknown 8)
  (roboguard 9)
  (turret 10)
  (spydroid 11)
  (roboguard-giant 12)
  )
;; ---city-target-type


;; +++cty-faction
(defenum cty-faction
  :type uint8
  (ff 0)
  (kg 1)
  (mh 2)
  (invalid 128)
  )
;; ---cty-faction


;; DECOMP BEGINS

;; WARN: Return type mismatch int vs cty-faction.
(defun city-target-type->cty-faction ((arg0 city-target-type))
  (let ((v1-0 arg0))
    (the-as
      cty-faction
      (cond
        ((or (= v1-0 (city-target-type guard-tazer))
             (= v1-0 (city-target-type guard-rifle))
             (= v1-0 (city-target-type guard-grenade))
             (= v1-0 (city-target-type unk1))
             (= v1-0 (city-target-type unk2))
             )
         (the-as cty-faction (cty-faction ff))
         )
        ((or (= v1-0 (city-target-type grunt)) (= v1-0 (city-target-type flitter)) (= v1-0 (city-target-type unknown)))
         (the-as cty-faction (cty-faction mh))
         )
        ((or (= v1-0 (city-target-type roboguard))
             (= v1-0 (city-target-type turret))
             (= v1-0 (city-target-type spydroid))
             (= v1-0 (city-target-type roboguard-giant))
             )
         (the-as cty-faction (cty-faction kg))
         )
        (else
          (the-as cty-faction (cty-faction invalid))
          )
        )
      )
    )
  )

;; WARN: Return type mismatch int vs traffic-type.
(defun city-target-type->traffic-object-type ((arg0 city-target-type))
  (let ((v1-0 arg0))
    (the-as
      traffic-type
      (cond
        ((or (= v1-0 (city-target-type guard-tazer))
             (= v1-0 (city-target-type guard-rifle))
             (= v1-0 (city-target-type guard-grenade))
             )
         (the-as traffic-type (traffic-type guard-a))
         )
        ((= v1-0 (city-target-type grunt))
         (the-as traffic-type (traffic-type metalhead-grunt))
         )
        ((= v1-0 (city-target-type flitter))
         (the-as traffic-type (traffic-type metalhead-flitter))
         )
        ((= v1-0 (city-target-type unknown))
         (the-as traffic-type (traffic-type metalhead-predator))
         )
        ((or (= v1-0 (city-target-type roboguard)) (= v1-0 (city-target-type roboguard-giant)))
         (the-as traffic-type (traffic-type roboguard))
         )
        ((= v1-0 (city-target-type turret))
         (the-as traffic-type (traffic-type flying-turret))
         )
        ((= v1-0 (city-target-type spydroid))
         (the-as traffic-type (traffic-type spydroid))
         )
        (else
          (the-as traffic-type (traffic-type invalid0))
          )
        )
      )
    )
  )

;; WARN: Return type mismatch int vs city-target-type.
(defun symbol->city-target-type ((arg0 symbol))
  (let ((v1-0 arg0))
    (the-as city-target-type (cond
                               ((= v1-0 'roboguard)
                                (the-as city-target-type (city-target-type roboguard))
                                )
                               ((= v1-0 'roboguard-giant)
                                (the-as city-target-type (city-target-type roboguard-giant))
                                )
                               ((= v1-0 'guard-rifle)
                                (the-as city-target-type (city-target-type guard-rifle))
                                )
                               ((= v1-0 'guard-tazer)
                                (the-as city-target-type (city-target-type guard-tazer))
                                )
                               ((= v1-0 'guard-grenade)
                                (the-as city-target-type (city-target-type guard-grenade))
                                )
                               ((= v1-0 'turret)
                                (the-as city-target-type (city-target-type turret))
                                )
                               ((= v1-0 'spydroid)
                                (the-as city-target-type (city-target-type spydroid))
                                )
                               ((= v1-0 'flitter)
                                (the-as city-target-type (city-target-type flitter))
                                )
                               ((= v1-0 'grunt)
                                (the-as city-target-type (city-target-type grunt))
                                )
                               (else
                                 (the-as city-target-type (city-target-type unknown))
                                 )
                               )
            )
    )
  )

(deftype cty-attack-controller (mission-squad-control)
  ((guard-angry-hatred-info-index  int8)
   )
  )


(define-perm *cty-attack-controller* cty-attack-controller #f)

(defun initialize-cty-attack-controller ()
  (set! *cty-attack-controller* (new 'loading-level 'cty-attack-controller))
  (init! *cty-attack-controller* 64 17 22)
  (none)
  )

(defun cty-attack-reset ((arg0 symbol) (arg1 symbol) (arg2 symbol))
  (if arg0
      (init-attackers *cty-attack-controller*)
      (reset-hatred *cty-attack-controller*)
      )
  (init-attack-controller *cty-attack-controller*)
  (none)
  )

;; WARN: Function (method 15 cty-attack-controller) has a return type of none, but the expression builder found a return statement.
(defmethod init-attack-controller ((this cty-attack-controller))
  (if (< (-> this hatred-vals allocated-length) 17)
      (return 0)
      )
  (let ((s5-0 (push-back-hatred this)))
    (set! (-> s5-0 hatred) 0.5)
    (set! (-> s5-0 hatred-dist) 163840.0)
    (set! (-> s5-0 dist-scale) 0.1)
    (set! (-> s5-0 attacker-scale) 0.01)
    (set! (-> s5-0 max-consider-dist) 409600.0)
    (set-hatred-indices this s5-0 3 9)
    (set-hatred-indices this s5-0 3 12)
    (set-hatred-indices this s5-0 3 10)
    (set-hatred-indices this s5-0 3 11)
    (set-hatred-indices this s5-0 3 6)
    (set-hatred-indices this s5-0 3 7)
    (set-hatred-indices this s5-0 3 8)
    )
  (let ((s5-1 (push-back-hatred this)))
    (set! (-> s5-1 hatred) 0.5)
    (set! (-> s5-1 hatred-dist) 245760.0)
    (set! (-> s5-1 dist-scale) 0.25)
    (set! (-> s5-1 attacker-scale) 0.01)
    (set! (-> s5-1 max-consider-dist) 409600.0)
    (set-hatred-indices this s5-1 5 6)
    (set-hatred-indices this s5-1 5 7)
    (set-hatred-indices this s5-1 5 8)
    (set-hatred-indices this s5-1 5 11)
    )
  (let ((s5-2 (push-back-hatred this)))
    (set! (-> s5-2 hatred) 0.7)
    (set! (-> s5-2 hatred-dist) 245760.0)
    (set! (-> s5-2 dist-scale) 0.25)
    (set! (-> s5-2 attacker-scale) 0.01)
    (set! (-> s5-2 max-consider-dist) 409600.0)
    (set-hatred-indices this s5-2 5 9)
    (set-hatred-indices this s5-2 5 12)
    )
  (let ((a1-13 (push-back-hatred this)))
    (set! (-> a1-13 hatred) 0.2)
    (set! (-> a1-13 hatred-dist) 245760.0)
    (set! (-> a1-13 dist-scale) 0.25)
    (set! (-> a1-13 attacker-scale) 0.01)
    (set! (-> a1-13 max-consider-dist) 163840.0)
    (set-hatred-indices this a1-13 5 10)
    )
  (let ((a1-14 (push-back-hatred this)))
    (set! (-> a1-14 hatred) 0.7)
    (set! (-> a1-14 hatred-dist) 245760.0)
    (set! (-> a1-14 dist-scale) 0.5)
    (set! (-> a1-14 attacker-scale) 0.01)
    (set! (-> a1-14 max-consider-dist) 409600.0)
    (set-hatred-indices this a1-14 4 10)
    )
  (let ((s5-3 (push-back-hatred this)))
    (set! (-> s5-3 hatred) 0.5)
    (set! (-> s5-3 hatred-dist) 245760.0)
    (set! (-> s5-3 dist-scale) 0.5)
    (set! (-> s5-3 attacker-scale) 0.01)
    (set! (-> s5-3 max-consider-dist) 409600.0)
    (set-hatred-indices this s5-3 4 9)
    (set-hatred-indices this s5-3 4 12)
    (set-hatred-indices this s5-3 4 11)
    (set-hatred-indices this s5-3 4 6)
    (set-hatred-indices this s5-3 4 7)
    (set-hatred-indices this s5-3 4 8)
    )
  (let ((s5-4 (push-back-hatred this)))
    (set! (-> s5-4 hatred) 0.6)
    (set! (-> s5-4 hatred-dist) 245760.0)
    (set! (-> s5-4 dist-scale) 0.25)
    (set! (-> s5-4 attacker-scale) 0.0)
    (set! (-> s5-4 max-consider-dist) 409600.0)
    (set-hatred-indices this s5-4 9 0)
    (set-hatred-indices this s5-4 12 0)
    (set-hatred-indices this s5-4 10 0)
    (set-hatred-indices this s5-4 11 0)
    (set-hatred-indices this s5-4 6 0)
    (set-hatred-indices this s5-4 7 0)
    (set-hatred-indices this s5-4 8 0)
    )
  (let ((s5-5 (push-back-hatred this)))
    (set! (-> s5-5 hatred) 0.5)
    (set! (-> s5-5 hatred-dist) 245760.0)
    (set! (-> s5-5 dist-scale) 0.25)
    (set! (-> s5-5 attacker-scale) 0.01)
    (set! (-> s5-5 max-consider-dist) 409600.0)
    (set-hatred-indices this s5-5 9 5)
    (set-hatred-indices this s5-5 12 5)
    (set-hatred-indices this s5-5 10 5)
    (set-hatred-indices this s5-5 11 5)
    (set-hatred-indices this s5-5 6 5)
    (set-hatred-indices this s5-5 7 5)
    (set-hatred-indices this s5-5 8 5)
    (set-hatred-indices this s5-5 9 4)
    (set-hatred-indices this s5-5 12 4)
    (set-hatred-indices this s5-5 10 4)
    (set-hatred-indices this s5-5 11 4)
    (set-hatred-indices this s5-5 6 4)
    (set-hatred-indices this s5-5 7 4)
    (set-hatred-indices this s5-5 8 4)
    (set-hatred-indices this s5-5 12 3)
    (set-hatred-indices this s5-5 9 3)
    (set-hatred-indices this s5-5 10 3)
    (set-hatred-indices this s5-5 11 3)
    (set-hatred-indices this s5-5 6 3)
    (set-hatred-indices this s5-5 7 3)
    (set-hatred-indices this s5-5 8 3)
    )
  (let ((s5-6 (push-back-hatred this)))
    (set! (-> s5-6 hatred) 0.1)
    (set! (-> s5-6 hatred-dist) 163840.0)
    (set! (-> s5-6 dist-scale) 0.25)
    (set! (-> s5-6 attacker-scale) 0.01)
    (set! (-> s5-6 max-consider-dist) 163840.0)
    (set-hatred-indices this s5-6 12 1)
    (set-hatred-indices this s5-6 9 1)
    (set-hatred-indices this s5-6 10 1)
    (set-hatred-indices this s5-6 11 1)
    (set-hatred-indices this s5-6 6 1)
    (set-hatred-indices this s5-6 7 1)
    (set-hatred-indices this s5-6 8 1)
    )
  (let ((s5-7 (push-back-hatred this)))
    (set! (-> s5-7 hatred) 0.05)
    (set! (-> s5-7 hatred-dist) 163840.0)
    (set! (-> s5-7 dist-scale) 0.25)
    (set! (-> s5-7 attacker-scale) 0.01)
    (set! (-> s5-7 max-consider-dist) 163840.0)
    (set-hatred-indices this s5-7 12 2)
    (set-hatred-indices this s5-7 9 2)
    (set-hatred-indices this s5-7 10 2)
    (set-hatred-indices this s5-7 8 2)
    )
  (let ((v1-184 (push-back-hatred this)))
    (set! (-> v1-184 hatred) 0.4)
    (set! (-> v1-184 hatred-dist) 184320.0)
    (set! (-> v1-184 dist-scale) 0.25)
    (set! (-> v1-184 attacker-scale) 0.01)
    (set! (-> v1-184 max-consider-dist) 327680.0)
    (set! (-> this guard-angry-hatred-info-index) (the-as int (-> v1-184 index)))
    )
  (none)
  )
