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

;; failed to figure out what this is:
(set! (-> *game-info* hint-control) (new 'static 'boxed-array :type level-hint-control
                                      (new 'static 'level-hint-control
                                        :id (game-text-id training-ironcrate)
                                        :num-attempts-before-playing 1
                                        :num-success-before-killing 3
                                        )
                                      (new 'static 'level-hint-control
                                        :id (game-text-id training-eco-reminder)
                                        :num-attempts-before-playing 3
                                        :num-success-before-killing -1
                                        )
                                      (new 'static 'level-hint-control
                                        :id (game-text-id sidekick-hint-crate-iron)
                                        :num-attempts-before-playing 3
                                        :num-success-before-killing 3
                                        )
                                      (new 'static 'level-hint-control
                                        :id (game-text-id sidekick-hint-crate-steel)
                                        :num-attempts-before-playing 1
                                        :num-success-before-killing 1
                                        )
                                      (new 'static 'level-hint-control
                                        :id (game-text-id sidekick-hint-orb-cache-top)
                                        :num-attempts-before-playing 1
                                        :num-success-before-killing 1
                                        )
                                      (new 'static 'level-hint-control
                                        :id (game-text-id beach-grottopole-increment)
                                        :num-attempts-before-playing 1
                                        :num-success-before-killing 1
                                        )
                                      (new 'static 'level-hint-control
                                        :delay-before-playing (seconds 3)
                                        :id (game-text-id sidekick-hint-ecorocks)
                                        :num-attempts-before-playing 1
                                        :num-success-before-killing 1
                                        )
                                      (new 'static 'level-hint-control
                                        :delay-before-playing (seconds 5)
                                        :id (game-text-id sidekick-hint-reflector-mirror)
                                        :num-attempts-before-playing 1
                                        :num-success-before-killing -1
                                        )
                                      (new 'static 'level-hint-control
                                        :delay-before-playing (seconds 3)
                                        :id (game-text-id sidekick-hint-precurbridge)
                                        :num-attempts-before-playing 1
                                        :num-success-before-killing -1
                                        )
                                      (new 'static 'level-hint-control
                                        :id (game-text-id misty-teetertotter)
                                        :num-attempts-before-playing 3
                                        :num-success-before-killing 1
                                        )
                                      (new 'static 'level-hint-control
                                        :delay-before-playing (seconds 3)
                                        :id (game-text-id misty-bone-bridge-hint)
                                        :num-attempts-before-playing 1
                                        :num-success-before-killing 1
                                        )
                                      (new 'static 'level-hint-control
                                        :delay-before-playing (seconds 5)
                                        :id (game-text-id rolling-plants-hint-eco-green)
                                        :num-attempts-before-playing 1
                                        :num-success-before-killing 1
                                        )
                                      (new 'static 'level-hint-control
                                        :delay-before-playing (seconds 15)
                                        :id (game-text-id sunken-bully-dive-hint)
                                        :num-attempts-before-playing 3
                                        :num-success-before-killing 2
                                        )
                                      (new 'static 'level-hint-control
                                        :delay-before-playing (seconds 60)
                                        :id (game-text-id sunken-qbert-plat-hint)
                                        :num-attempts-before-playing 3
                                        :num-success-before-killing -1
                                        )
                                      (new 'static 'level-hint-control
                                        :id (game-text-id sunken-blue-eco-charger-all-hint)
                                        :num-attempts-before-playing 3
                                        :num-success-before-killing -1
                                        )
                                      (new 'static 'level-hint-control
                                        :id (game-text-id sunken-blue-eco-charger-hint)
                                        :num-attempts-before-playing 3
                                        :num-success-before-killing 2
                                        )
                                      (new 'static 'level-hint-control
                                        :id (game-text-id swamp-tetherrock-eco-yellow-hint)
                                        :num-attempts-before-playing 1
                                        :num-success-before-killing 1
                                        )
                                      (new 'static 'level-hint-control
                                        :delay-before-playing (seconds 30)
                                        :id (game-text-id sunken-double-lurker-hint)
                                        :num-attempts-before-playing 3
                                        :num-success-before-killing 1
                                        )
                                      (new 'static 'level-hint-control
                                        :id (game-text-id sunken-hotpipes)
                                        :num-attempts-before-playing 3
                                        :num-success-before-killing -1
                                        )
                                      (new 'static 'level-hint-control
                                        :id (game-text-id snow-ram-boss-red-eco-hint)
                                        :num-attempts-before-playing 5
                                        :num-success-before-killing -1
                                        )
                                      (new 'static 'level-hint-control
                                        :delay-before-playing (seconds 3)
                                        :id (game-text-id darkcave-light-hint)
                                        :num-attempts-before-playing 1
                                        :num-success-before-killing -1
                                        )
                                      (new 'static 'level-hint-control
                                        :id (game-text-id cave-gnawers-look-around)
                                        :num-attempts-before-playing 4
                                        :num-success-before-killing -1
                                        )
                                      (new 'static 'level-hint-control
                                        :id (game-text-id lavatube-balls)
                                        :num-attempts-before-playing 1
                                        :num-success-before-killing 2
                                        )
                                      (new 'static 'level-hint-control
                                        :delay-before-playing (seconds 5)
                                        :id (game-text-id citadel-generator)
                                        :num-attempts-before-playing 1
                                        :num-success-before-killing 1
                                        )
                                      (new 'static 'level-hint-control
                                        :delay-before-playing (seconds 5)
                                        :id (game-text-id citadel-generator-no-mushroom)
                                        :num-attempts-before-playing 1
                                        :num-success-before-killing 1
                                        )
                                      )
      )

;; failed to figure out what this is:
(set! (-> *game-info* task-hint-control)
      (new 'static 'boxed-array :type task-hint-control-group
        (new 'static 'task-hint-control-group
          :tasks (new 'static 'boxed-array :type task-hint-control
            (new 'static 'task-hint-control :task (game-task training-gimmie) :delay (seconds 600))
            (new 'static 'task-hint-control :task (game-task training-door) :delay (seconds 1200))
            (new 'static 'task-hint-control :task (game-task training-climb) :delay (seconds 1800))
            )
          )
        (new 'static 'task-hint-control-group)
        (new 'static 'task-hint-control-group
          :tasks (new 'static 'boxed-array :type task-hint-control
            (new 'static 'task-hint-control :task (game-task beach-gimmie) :delay (seconds 900))
            (new 'static 'task-hint-control :task (game-task beach-sentinel) :delay (seconds 1800))
            (new 'static 'task-hint-control :task (game-task beach-cannon) :delay (seconds 2700))
            )
          )
        (new 'static 'task-hint-control-group
          :tasks (new 'static 'boxed-array :type task-hint-control
            (new 'static 'task-hint-control :task (game-task jungle-plant) :delay (seconds 1200))
            (new 'static 'task-hint-control :task (game-task jungle-canyon-end) :delay (seconds 2400))
            )
          )
        (new 'static 'task-hint-control-group
          :tasks (new 'static 'boxed-array :type task-hint-control
            (new 'static 'task-hint-control :task (game-task misty-boat) :delay (seconds 1200))
            (new 'static 'task-hint-control :task (game-task misty-warehouse) :delay (seconds 1800))
            (new 'static 'task-hint-control :task (game-task misty-bike-jump) :delay (seconds 2400))
            (new 'static 'task-hint-control :task (game-task misty-eco-challenge) :delay (seconds 3000))
            )
          )
        (new 'static 'task-hint-control-group)
        (new 'static 'task-hint-control-group)
        (new 'static 'task-hint-control-group
          :tasks (new 'static 'boxed-array :type task-hint-control
            (new 'static 'task-hint-control :task (game-task sunken-spinning-room) :delay (seconds 1200))
            (new 'static 'task-hint-control :task (game-task sunken-sharks) :delay (seconds 1800))
            (new 'static 'task-hint-control :task (game-task sunken-slide) :delay (seconds 2400))
            )
          )
        (new 'static 'task-hint-control-group
          :tasks (new 'static 'boxed-array :type task-hint-control
            (new 'static 'task-hint-control :task (game-task swamp-battle) :delay (seconds 2400))
            )
          )
        (new 'static 'task-hint-control-group
          :tasks (new 'static 'boxed-array :type task-hint-control
            (new 'static 'task-hint-control :task (game-task rolling-lake) :delay (seconds 2400))
            )
          )
        (new 'static 'task-hint-control-group
          :tasks (new 'static 'boxed-array :type task-hint-control
            (new 'static 'task-hint-control :task (game-task ogre-secret) :delay (seconds 3600))
            )
          )
        (new 'static 'task-hint-control-group
          :tasks (new 'static 'boxed-array :type task-hint-control
            (new 'static 'task-hint-control :task (game-task village3-extra1) :delay (seconds 3600))
            )
          )
        (new 'static 'task-hint-control-group
          :tasks (new 'static 'boxed-array :type task-hint-control
            (new 'static 'task-hint-control :task (game-task snow-bumpers) :delay (seconds 1200))
            (new 'static 'task-hint-control :task (game-task snow-cage) :delay (seconds 1800))
            (new 'static 'task-hint-control :task (game-task snow-ball) :delay (seconds 2400))
            (new 'static 'task-hint-control :task (game-task snow-bunnies) :delay (seconds 3000))
            )
          )
        (new 'static 'task-hint-control-group
          :tasks (new 'static 'boxed-array :type task-hint-control
            (new 'static 'task-hint-control :task (game-task cave-dark-climb) :delay (seconds 1200))
            (new 'static 'task-hint-control :task (game-task cave-robot-climb) :delay (seconds 1800))
            (new 'static 'task-hint-control :task (game-task cave-swing-poles) :delay (seconds 2400))
            (new 'static 'task-hint-control :task (game-task cave-platforms) :delay (seconds 3000))
            )
          )
        (new 'static 'task-hint-control-group)
        (new 'static 'task-hint-control-group)
        )
      )

;; definition for function find-hint-control-index
(defun find-hint-control-index ((arg0 game-text-id))
  (let ((gp-0 -1))
    (let ((v1-2 (length (-> *game-info* hint-control))))
      (dotimes (a0-2 v1-2)
        (when (= (-> *game-info* hint-control a0-2 id) arg0)
          (set! gp-0 a0-2)
          (set! a0-2 v1-2)
          )
        )
      )
    gp-0
    )
  )

;; definition for function start-hint-timer
;; INFO: Return type mismatch int vs none.
(defun start-hint-timer ((arg0 game-text-id))
  (let ((v1-0 (find-hint-control-index arg0)))
    (when (and (>= v1-0 0)
               (zero? (-> *game-info* hint-control v1-0 start-time))
               (!= (-> *game-info* hint-control v1-0 num-attempts-before-playing) 1)
               )
      (set! (-> *game-info* hint-control v1-0 start-time) (-> *display* base-frame-counter))
      0
      )
    )
  0
  (none)
  )

;; definition for function increment-success-for-hint
;; INFO: Return type mismatch int vs none.
(defun increment-success-for-hint ((arg0 game-text-id))
  (let ((gp-0 (find-hint-control-index arg0)))
    (when (>= gp-0 0)
      (seekl! (-> *game-info* hint-control gp-0 num-success) 127 1)
      0
      )
    )
  0
  (none)
  )

;; definition for function can-hint-be-played?
;; WARN: disable def twice: 139. This may happen when a cond (no else) is nested inside of another conditional, but it should be rare.
(defun can-hint-be-played? ((arg0 game-text-id) (arg1 entity) (arg2 string))
  (let ((v1-0 (not (str-is-playing?))))
    (if (and v1-0 (nonzero? arg0))
        (set! v1-0 (not (seen-text? *game-info* arg0)))
        )
    (when v1-0
      (when *hint-semaphore*
        (set! v1-0 (appeared-for-long-enough? (the-as level-hint (ppointer->process *hint-semaphore*))))
        0
        )
      (when (and v1-0 (< (- (-> *display* base-frame-counter) (-> *game-info* hint-play-time)) (seconds 0.1)))
        (set! v1-0 #f)
        0
        )
      (set! v1-0 (and v1-0
                      (not (-> *setting-control* current talking))
                      (not (-> *setting-control* current spooling))
                      (not (-> *setting-control* current hint))
                      (not (-> *setting-control* current ambient))
                      (>= (-> *display* base-frame-counter) (-> *game-info* blackout-time))
                      )
            )
      0
      )
    (cond
      (v1-0
        (let ((v1-16 (find-hint-control-index arg0)))
          (cond
            ((< v1-16 0)
             #t
             )
            (else
              (let ((gp-1 (-> *game-info* hint-control v1-16))
                    (a0-24 (- (-> *display* base-frame-counter) (-> *game-info* hint-control v1-16 last-time-called)))
                    (v1-21 #t)
                    )
                (if (and (= (-> gp-1 num-attempts-before-playing) 1) (< a0-24 (seconds 0.1)))
                    (+! (-> gp-1 start-time) a0-24)
                    )
                (cond
                  ((and (!= (-> gp-1 num-attempts-before-playing) 1)
                        (nonzero? (-> gp-1 last-time-called))
                        (< (- (-> *display* base-frame-counter) (-> gp-1 last-time-called)) (seconds 0.5))
                        )
                   (set! (-> gp-1 last-time-called) (-> *display* base-frame-counter))
                   #f
                   )
                  (else
                    (set! (-> gp-1 last-time-called) (-> *display* base-frame-counter))
                    (when (nonzero? (-> gp-1 delay-before-playing))
                      (if (< (-> gp-1 start-time) (-> gp-1 delay-before-playing))
                          (set! v1-21 #f)
                          )
                      0
                      )
                    (cond
                      (v1-21
                        (seekl! (-> gp-1 num-attempts) 127 1)
                        (and (>= (-> gp-1 num-attempts) (-> gp-1 num-attempts-before-playing))
                             (or (= (-> gp-1 num-success-before-killing) -1)
                                 (< (-> gp-1 num-success) (-> gp-1 num-success-before-killing))
                                 )
                             )
                        )
                      (else
                        #f
                        )
                      )
                    )
                  )
                )
              )
            )
          )
        )
      (else
        #f
        )
      )
    )
  )

;; definition for function reset-all-hint-controls
;; INFO: Return type mismatch int vs none.
(defun reset-all-hint-controls ()
  (let ((v1-2 (length (-> *game-info* hint-control))))
    (dotimes (a0-1 v1-2)
      (let ((a1-2 (-> *game-info* hint-control a0-1)))
        (set! (-> a1-2 start-time) 0)
        (set! (-> a1-2 last-time-called) 0)
        (set! (-> a1-2 num-attempts) 0)
        (set! (-> a1-2 num-success) 0)
        )
      0
      )
    )
  0
  (none)
  )

;; definition for function update-task-hints
;; INFO: Return type mismatch int vs none.
(defun update-task-hints ()
  (when *target*
    (let ((a0-0 (+ (-> *target* current-level info index) -1))
          (v1-7 (-> *game-info* task-hint-control))
          )
      (when (and (>= a0-0 0) (< a0-0 (-> *level-task-data-remap* length)))
        (let ((a0-3 (-> *level-task-data-remap* a0-0)))
          (when (< a0-3 (-> v1-7 length))
            (let ((gp-0 (-> v1-7 a0-3 tasks)))
              (when (and (!= gp-0 0) (nonzero? (-> gp-0 length)))
                (let ((s5-0 (-> *game-info* in-level-time a0-3)))
                  (dotimes (s4-0 (-> gp-0 length))
                    (case (get-task-status (-> gp-0 s4-0 task))
                      (((task-status need-hint) (task-status unknown))
                       (if (< (the-as uint (-> gp-0 s4-0 delay)) (the-as uint s5-0))
                           (close-specific-task! (-> gp-0 s4-0 task) (task-status need-hint))
                           )
                       )
                      )
                    )
                  )
                )
              )
            )
          )
        )
      )
    )
  0
  (none)
  )
