jak-project/goal_src/jak1/levels/snow/target-ice.gc
Matt Dallmeyer 4fd0a57046
Create abutton-idx enum, replace magic numbers across codebase (#3646)
Found out the hard way that the `abutton` array for pressure sensitivity
uses a different order than the `pad-buttons` enum, so I created a new
enum for abutton indexing.

I replaced any magic numbers across the codebase where it made sense,
e.g.
`(-> *cpad-list* cpads (-> self control unknown-cpad-info00 number)
abutton 6)`
becomes
`(-> *cpad-list* cpads (-> self control unknown-cpad-info00 number)
abutton (abutton-idx x))`
2024-09-01 09:29:23 -04:00

199 lines
9.1 KiB
Common Lisp

;;-*-Lisp-*-
(in-package goal)
(bundles "SNO.DGO")
(require "engine/target/target-handler.gc")
;; DECOMP BEGINS
(defstate target-ice-stance (target)
:event target-standard-event-handler
:enter
(behavior ()
(set! (-> self control unknown-surface00) *walk-mods*))
:exit target-state-hook-exit
:trans
(behavior ()
((-> self state-hook))
(if (!= (-> self control ground-pat material) (pat-material ice)) (go target-stance))
(when (move-legs?)
(remove-exit)
(go target-ice-walk))
(when (and (cpad-hold? (-> self control unknown-cpad-info00 number) l1 r1) (can-duck?))
(remove-exit)
(go target-duck-stance))
;; og:preserve-this - High FPS Fix
(if (and (recently-pressed? x) (can-jump? #f))
(go target-jump (-> *TARGET-bank* jump-height-min) (-> *TARGET-bank* jump-height-max) (the-as surface #f)))
;; og:preserve-this - High FPS Fix
(if (and (recently-pressed? circle) (can-feet?)) (go target-attack))
(if (can-hands? #t) (go target-running-attack))
(slide-down-test)
(fall-test))
:code
(behavior ()
(let ((gp-0 60))
(let ((v1-2 (ja-group)))
(cond
((or (= v1-2 eichar-jump-ja) (= v1-2 eichar-jump-loop-ja)) (set! gp-0 21))
((ja-group? eichar-wheel-flip-ja)
(ja-no-eval :group! eichar-wheel-flip-land-ja :num! (seek!) :frame-num 0.0)
(until (ja-done? 0)
(suspend)
(ja :num! (seek!))))
((ja-group? eichar-attack-from-stance-ja)
(cond
((rand-vu-percent? 0.3)
(ja-no-eval :group! eichar-attack-from-stance-alt-end-ja :num! (seek!) :frame-num 0.0)
(until (ja-done? 0)
(suspend)
(ja :num! (seek!))))
(else
(ja-no-eval :group! eichar-attack-from-stance-end-ja :num! (seek!) :frame-num 0.0)
(until (ja-done? 0)
(suspend)
(ja :num! (seek!))))))
((ja-group? eichar-smack-surface-ja)
(ja-no-eval :group! eichar-smack-surface-end-ja :num! (seek!) :frame-num 0.0)
(until (ja-done? 0)
(suspend)
(ja :num! (seek!))))
((ja-group? eichar-yellow-running-blast-ja)
(ja-no-eval :group! eichar-yellow-running-blast-end-ja :num! (seek!) :frame-num 0.0)
(until (ja-done? 0)
(suspend)
(ja :num! (seek!)))
(set! gp-0 0))
((ja-group? eichar-attack-punch-ja)
(set! (-> self control unknown-float81) (-> self control unknown-float80))
(set! (-> self control unknown-surface00) *walk-no-turn-mods*)
(ja-no-eval :group!
(if (rand-vu-percent? 0.3) eichar-attack-punch-alt-end-ja eichar-attack-punch-end-ja)
:num! (seek!)
:frame-num 0.0)
(until (ja-done? 0)
(seek! (-> self control unknown-float81) 0.0 (seconds-per-frame))
(suspend)
(ja :num! (seek!)))
(set! (-> self control unknown-surface00) *walk-mods*)
(set! (-> self control unknown-float81) 0.0)
(rot->dir-targ! (-> self control)))
((let ((v1-188 (ja-group))) (or (= v1-188 eichar-duck-stance-ja) (= v1-188 eichar-duck-walk-ja)))
(ja-channel-push! 1 (seconds 0.04))
(ja-no-eval :group! eichar-stance-to-duck-ja :num! (seek! 0.0 1.2) :frame-num max)
(until (ja-done? 0)
(suspend)
(ja :num! (seek! 0.0 1.2)))
(set! gp-0 60))))
(while (< 16384.0 (-> self control unknown-float01))
(cond
((ja-group? eichar-ice-slide-ja))
(else (ja-channel-push! 1 (the-as time-frame gp-0)) (set! gp-0 150) (ja :group! eichar-ice-slide-ja)))
(suspend)
(ja :num! (loop!)))
(when (not (ja-group? eichar-ice-stance-ja))
(ja-channel-push! 1 (the-as time-frame gp-0))
(ja :group! eichar-ice-stance-ja)))
(loop
(suspend)
(ja :num! (loop!))))
:post target-post)
(defstate target-ice-walk (target)
:event target-standard-event-handler
:enter
(behavior ()
(set-time! (-> self state-time))
(set! (-> self control unknown-surface00) *walk-mods*))
:exit
(behavior ()
(target-effect-exit)
(target-state-hook-exit))
:trans
(behavior ()
((-> self state-hook))
(when (!= (-> self control ground-pat material) (pat-material ice))
(remove-exit)
(go target-walk))
;; og:preserve-this - High FPS Fix
(if (and (recently-pressed? l1 r1)
(and (time-elapsed? (-> *TARGET-bank* wheel-timeout) (-> self control unknown-dword30))
(and (!= (-> *cpad-list* cpads (-> self control unknown-cpad-info00 number) stick0-speed) 0.0) (can-wheel?))))
(go target-wheel))
(when (and (cpad-hold? (-> self control unknown-cpad-info00 number) l1 r1) (can-duck?))
(target-effect-exit)
(remove-exit)
(go target-duck-stance))
(when (and (not (move-legs?))
(let ((gp-0 (ja-group))
(f0-1 (ja-aframe-num 0)))
(if (and (= gp-0 eichar-ice-skate-ja) (>= f0-1 30.0) (>= 35.0 f0-1)) #t)))
(target-effect-exit)
(remove-exit)
(go target-ice-stance))
;; og:preserve-this - High FPS Fix
(if (and (recently-pressed? x) (can-jump? #f))
(go target-jump (-> *TARGET-bank* jump-height-min) (-> *TARGET-bank* jump-height-max) (the-as surface #f)))
;; og:preserve-this - High FPS Fix
(if (and (recently-pressed? circle) (can-feet?)) (go target-attack))
(if (can-hands? #t) (go target-running-attack))
(slide-down-test)
(fall-test))
:code
(behavior ()
(cond
((ja-group? eichar-walk-ja)
(let ((f30-0 (ja-aframe-num 0)))
(ja-channel-push! 1 (seconds 0.1))
(ja :group! eichar-ice-skate-ja :num! (identity f30-0))))
((ja-group? eichar-ice-skate-ja))
(else
(let ((v1-18 (ja-group)))
(cond
((or (= v1-18 eichar-attack-punch-end-ja) (= v1-18 eichar-attack-punch-alt-end-ja))
(set! (-> self control unknown-float81) (-> self control unknown-float80))
(set! (-> self control unknown-surface00) *walk-no-turn-mods*)
(while (< (ja-aframe-num 0) 42.0)
(suspend)
(ja :num! (seek!)))
(set! (-> self control unknown-surface00) *walk-mods*)
(set! (-> self control unknown-float81) 0.0)
(ja-channel-push! 1 (seconds 0.1))
(ja :group! eichar-ice-skate-ja :num! (identity (ja-aframe 34.0 0)))
(while (!= (-> self skel root-channel 0) (-> self skel channel))
(suspend)))
((ja-group? eichar-attack-punch-ja)
(set! (-> self control unknown-float81) (-> self control unknown-float80))
(set! (-> self control unknown-surface00) *walk-no-turn-mods*)
(ja-no-eval :group! eichar-attack-punch-end-ja :num! (seek! (ja-aframe 42.0 0)) :frame-num 0.0)
(until (ja-done? 0)
(suspend)
(ja :num! (seek! (ja-aframe 42.0 0))))
(set! (-> self control unknown-surface00) *walk-mods*)
(set! (-> self control unknown-float81) 0.0)
(ja-channel-push! 1 (seconds 0.1))
(ja :group! eichar-ice-skate-ja :num! (identity (ja-aframe 34.0 0)))
(while (!= (-> self skel root-channel 0) (-> self skel channel))
(suspend)))
(else (ja-channel-push! 1 (seconds 0.05)) (ja :group! eichar-ice-skate-ja))))))
(loop
(suspend)
(let* ((s5-0 (vector-normalize-copy! (new 'stack-no-clear 'vector) (-> self control unknown-vector01) 1.0))
;; og:preserve-this modified to avoid dividing by zero when jak's speed is 0.
;; this fixes the issue where jak gets stuck on frame 60 of the ice-walk animation
;; instead of switching to stance (due to making zero progress here),
;; _and_ it fixes the issue where we get a NaN frame number in daxter, causing the eye animation
;; to read bogus memory.
(vector01-len (vector-length (-> self control unknown-vector01)))
(gp-6 (vector-float*! (new 'stack-no-clear 'vector)
(-> self control unknown-vector00)
;; og:preserve-this
(/ 1.0 (if (= vector01-len 0) 0.001 vector01-len)) ;; added the .001 case here.
))
(f0-18 (fmax -1.0 (fmin 1.0 (vector-dot s5-0 gp-6)))))
(ja :num!
(loop! (cond
((< f0-18 0.0) (lerp-scale 2.0 1.0 f0-18 -1.0 0.5))
((< 0.5 f0-18) (lerp-scale 1.0 0.75 f0-18 0.5 1.0))
(else (lerp-scale 1.33 1.0 f0-18 0.0 0.5))))))))
:post target-post)