Files
jak-project/goal_src/jak1/engine/game/task/hint-control.gc
T
Tyler Wilding c162c66118 g/j1: Cleanup all main issues in the formatter and format all of goal_src/jak1 (#3535)
This PR does two main things:
1. Work through the main low-hanging fruit issues in the formatter
keeping it from feeling mature and usable
2. Iterate and prove that point by formatting all of the Jak 1 code
base. **This has removed around 100K lines in total.**
- The decompiler will now format it's results for jak 1 to keep things
from drifting back to where they were. This is controlled by a new
config flag `format_code`.

How am I confident this hasn't broken anything?:
- I compiled the entire project and stored it's `out/jak1/obj` files
separately
- I then recompiled the project after formatting and wrote a script that
md5's each file and compares it (`compare-compilation-outputs.py`
- The results (eventually) were the same:

![Screenshot 2024-05-25
132900](https://github.com/open-goal/jak-project/assets/13153231/015e6f20-8d19-49b7-9951-97fa88ddc6c2)
> This proves that the only difference before and after is non-critical
whitespace for all code/macros that is actually in use.

I'm still aware of improvements that could be made to the formatter, as
well as general optimization of it's performance. But in general these
are for rare or non-critical situations in my opinion and I'll work
through them before doing Jak 2. The vast majority looks great and is
working properly at this point. Those known issues are the following if
you are curious:

![image](https://github.com/open-goal/jak-project/assets/13153231/0edfaba1-6d36-40f5-ab23-0642209867c4)
2024-06-05 22:17:31 -04:00

372 lines
16 KiB
Common Lisp

;;-*-Lisp-*-
(in-package goal)
(bundles "ENGINE.CGO" "GAME.CGO")
(require "engine/game/task/game-task-h.gc")
(require "engine/game/game-info.gc")
(require "engine/draw/drawable-ambient-h.gc")
(require "engine/ui/text-h.gc")
;; DECOMP BEGINS
(set! (-> *game-info* hint-control)
(new 'static
'boxed-array
:type
level-hint-control
(new 'static
'level-hint-control
:id (text-id training-ironcrate)
:num-attempts-before-playing 1
:num-success-before-killing 3)
(new 'static
'level-hint-control
:id (text-id training-eco-reminder)
:num-attempts-before-playing 3
:num-success-before-killing -1)
(new 'static
'level-hint-control
:id (text-id sidekick-hint-crate-iron)
:num-attempts-before-playing 3
:num-success-before-killing 3)
(new 'static
'level-hint-control
:id (text-id sidekick-hint-crate-steel)
:num-attempts-before-playing 1
:num-success-before-killing 1)
(new 'static
'level-hint-control
:id (text-id sidekick-hint-orb-cache-top)
:num-attempts-before-playing 1
:num-success-before-killing 1)
(new 'static
'level-hint-control
:id (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 (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 (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 (text-id sidekick-hint-precurbridge)
:num-attempts-before-playing 1
:num-success-before-killing -1)
(new 'static
'level-hint-control
:id (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 (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 (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 (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 (text-id sunken-qbert-plat-hint)
:num-attempts-before-playing 3
:num-success-before-killing -1)
(new 'static
'level-hint-control
:id (text-id sunken-blue-eco-charger-all-hint)
:num-attempts-before-playing 3
:num-success-before-killing -1)
(new 'static
'level-hint-control
:id (text-id sunken-blue-eco-charger-hint)
:num-attempts-before-playing 3
:num-success-before-killing 2)
(new 'static
'level-hint-control
:id (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 (text-id sunken-double-lurker-hint)
:num-attempts-before-playing 3
:num-success-before-killing 1)
(new 'static
'level-hint-control
:id (text-id sunken-hotpipes)
:num-attempts-before-playing 3
:num-success-before-killing -1)
(new 'static
'level-hint-control
:id (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 (text-id darkcave-light-hint)
:num-attempts-before-playing 1
:num-success-before-killing -1)
(new 'static
'level-hint-control
:id (text-id cave-gnawers-look-around)
:num-attempts-before-playing 4
:num-success-before-killing -1)
(new 'static
'level-hint-control
:id (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 (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 (text-id citadel-generator-no-mushroom)
:num-attempts-before-playing 1
:num-success-before-killing 1)))
(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)))
(defun find-hint-control-index ((arg0 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))
(defun start-hint-timer ((arg0 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-time! (-> *game-info* hint-control v1-0 start-time))
0))
0
(none))
(defun increment-success-for-hint ((arg0 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))
;; 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 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 (not (time-elapsed? (-> *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))
(>= (current-time) (-> *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 (- (current-time) (-> *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))
(not (time-elapsed? (-> gp-1 last-time-called) (seconds 0.5))))
(set-time! (-> gp-1 last-time-called))
#f)
(else
(set-time! (-> gp-1 last-time-called))
(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))))
(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))
(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))