jak-project/goal_src/jak2/engine/target/gun/gun-blue-shot.gc
ManDude cd68cb671e
deftype and defmethod syntax major changes (#3094)
Major change to how `deftype` shows up in our code:
- the decompiler will no longer emit the `offset-assert`,
`method-count-assert`, `size-assert` and `flag-assert` parameters. There
are extremely few cases where having this in the decompiled code is
helpful, as the types there come from `all-types` which already has
those parameters. This also doesn't break type consistency because:
  - the asserts aren't compared.
- the first step of the test uses `all-types`, which has the asserts,
which will throw an error if they're bad.
- the decompiler won't emit the `heap-base` parameter unless necessary
now.
- the decompiler will try its hardest to turn a fixed-offset field into
an `overlay-at` field. It falls back to the old offset if all else
fails.
- `overlay-at` now supports field "dereferencing" to specify the offset
that's within a field that's a structure, e.g.:
```lisp
(deftype foobar (structure)
  ((vec    vector  :inline)
   (flags  int32   :overlay-at (-> vec w))
   )
  )
```
in this structure, the offset of `flags` will be 12 because that is the
final offset of `vec`'s `w` field within this structure.
- **removed ID from all method declarations.** IDs are only ever
automatically assigned now. Fixes #3068.
- added an `:overlay` parameter to method declarations, in order to
declare a new method that goes on top of a previously-defined method.
Syntax is `:overlay <method-name>`. Please do not ever use this.
- added `state-methods` list parameter. This lets you quickly specify a
list of states to be put in the method table. Same syntax as the
`states` list parameter. The decompiler will try to put as many states
in this as it can without messing with the method ID order.

Also changes `defmethod` to make the first type definition (before the
arguments) optional. The type can now be inferred from the first
argument. Fixes #3093.

---------

Co-authored-by: Hat Kid <6624576+Hat-Kid@users.noreply.github.com>
2023-10-30 03:20:02 +00:00

316 lines
12 KiB
Common Lisp

;;-*-Lisp-*-
(in-package goal)
;; name: gun-blue-shot.gc
;; name in dgo: gun-blue-shot
;; dgos: ENGINE, GAME
;; DECOMP BEGINS
(defbehavior target-gun-fire-blue target ()
(let ((gp-0 (-> self gun))
(s4-0 (-> self gun fire-dir-out))
(s5-0 (new 'stack-no-clear 'vector))
)
(let ((s3-0 (new 'stack-no-clear 'quaternion)))
(quaternion-vector-angle! s3-0 s4-0 (* 182.04445 (rand-vu-float-range 0.0 360.0)))
(vector-rotate-y! s5-0 s4-0 (* 182.04445 (rand-vu-float-range 0.0 1.1)))
(vector-orient-by-quat! s5-0 s5-0 s3-0)
)
(let ((s4-1 (new 'stack-no-clear 'projectile-init-by-other-params)))
(set! (-> s4-1 ent) (-> self entity))
(set! (-> s4-1 charge) 1.0)
(set! (-> s4-1 options) (projectile-options account-for-target-velocity deal-damage proj-options-8000))
(set! (-> s4-1 pos quad) (-> gp-0 fire-point quad))
(set! (-> s4-1 vel quad) (-> s5-0 quad))
(set! (-> s4-1 notify-handle) (the-as handle #f))
(set! (-> s4-1 owner-handle) (the-as handle #f))
(set! (-> s4-1 ignore-handle) (process->handle (the-as process (send-event self 'get-vehicle))))
(let* ((v1-13 *game-info*)
(a0-15 (+ (-> v1-13 attack-id) 1))
)
(set! (-> v1-13 attack-id) a0-15)
(set! (-> s4-1 attack-id) a0-15)
)
(set! (-> s4-1 timeout) (seconds 4))
(spawn-projectile gun-blue-shot s4-1 (ppointer->process (-> gp-0 gun)) *default-dead-pool*)
)
)
)
(deftype gun-blue-shot (projectile)
((init-pos vector :inline)
(init-dir vector :inline)
(collide-normal vector :inline)
)
)
(defmethod draw-laser-sight ((this gun-blue-shot))
"TODO - confirm If applicable, draw the laser sight particles"
(let* ((s5-0 (ppointer->process (-> this parent)))
(s4-0 (-> *part-id-table* 196))
(s3-0 (get-field-spec-by-id s4-0 (sp-field-id spt-omega)))
(s5-1 (vector<-cspace! (new 'stack-no-clear 'vector) (-> (the-as projectile s5-0) node-list data 16)))
)
(when s3-0
(let ((s1-0 (vector-normalize-copy! (new 'stack-no-clear 'vector) (-> this starting-dir) 1.0))
(s2-0 (new 'stack-no-clear 'collide-query))
)
(vector-rotate-y! s1-0 s1-0 16384.0)
(vector+float*! s1-0 s5-1 s1-0 -8806.4)
(set! (-> s2-0 start-pos quad) (-> s1-0 quad))
(vector-float*! (-> s2-0 move-dist) (-> this root dynam gravity-normal) -81920.0)
(let ((v1-11 s2-0))
(set! (-> v1-11 radius) 1228.8)
(set! (-> v1-11 collide-with) (collide-spec backgnd obstacle hit-by-player-list hit-by-others-list))
(set! (-> v1-11 ignore-process0) this)
(set! (-> v1-11 ignore-process1) (ppointer->process (-> this parent)))
(set! (-> v1-11 ignore-pat) (new 'static 'pat-surface :noentity #x1 :nojak #x1 :probe #x1 :noendlessfall #x1))
(set! (-> v1-11 action-mask) (collide-action solid))
)
(if (>= (fill-and-probe-using-line-sphere *collide-cache* s2-0) 0.0)
(set! (-> s3-0 initial-valuef)
(fmin (+ 1638.4 (-> s2-0 best-other-tri intersect y)) (+ -1228.8 (-> this starting-pos y)))
)
(set! (-> s3-0 initial-valuef) (+ -81920.0 (-> this starting-pos y)))
)
)
)
(let ((s4-1 (get-field-spec-by-id s4-0 (sp-field-id spt-rotate-y))))
(if s4-1
(set! (-> s4-1 initial-valuef) (y-angle (-> this root)))
)
)
(launch-particles (-> *part-id-table* 196) s5-1)
(let ((s4-2 (get-field-spec-by-id (-> *part-id-table* 195) (sp-field-id spt-rotate-y))))
(if s4-2
(set! (-> s4-2 initial-valuef) (y-angle (-> this root)))
)
)
(launch-particles (-> *part-id-table* 195) s5-1)
)
0
(none)
)
(defmethod spawn-shell-particles ((this gun-blue-shot))
"TODO - confirm"
(rlet ((vf0 :class vf)
(vf4 :class vf)
(vf5 :class vf)
(vf6 :class vf)
)
(init-vf0-vector)
(let ((s3-1 (vector-! (new 'stack-no-clear 'vector) (-> this root trans) (-> this init-pos))))
(draw-beam (-> *part-id-table* 191) (-> this init-pos) s3-1 #t #t)
(draw-beam (-> *part-id-table* 194) (-> this init-pos) (-> this starting-dir) #f #t)
(let ((s5-0 (-> *part-id-table* 206))
(s4-0 (-> *part-id-table* 205))
)
(new 'stack-no-clear 'vector)
(let ((s2-0 (vector-reflect! (new 'stack-no-clear 'vector) s3-1 (-> this collide-normal))))
(vector-normalize! s2-0 1.0)
(get-field-spec-by-id s5-0 (sp-field-id spt-conerot-x))
(get-field-spec-by-id s5-0 (sp-field-id spt-conerot-y))
(get-field-spec-by-id s5-0 (sp-field-id spt-conerot-z))
(let ((a1-7 (new 'stack-no-clear 'matrix))
(s1-0 (new 'stack-no-clear 'vector))
(s3-2 (new 'stack-no-clear 'vector))
)
(vector-cross! (the-as vector (-> a1-7 vector)) *y-vector* s2-0)
(vector-cross! (-> a1-7 vector 1) s2-0 (the-as vector (-> a1-7 vector)))
(set! (-> a1-7 vector 2 quad) (-> s2-0 quad))
(matrix->eul (the-as euler-angles s1-0) a1-7 21)
(vector-negate! s3-2 s1-0)
(let ((a0-14 s3-2))
(let ((v1-16 s3-2))
(let ((a1-10 -3640.889))
(.mov vf6 a1-10)
)
(.lvf vf4 (&-> v1-16 quad))
)
(.add.x.vf vf5 vf0 vf0 :mask #b1000)
(.add.x.vf vf5 vf4 vf6 :mask #b111)
(.svf (&-> a0-14 quad) vf5)
)
(sparticle-set-conerot s5-0 s3-2)
(sparticle-set-conerot s4-0 s3-2)
)
)
)
)
(let ((s5-1 (get-process *default-dead-pool* part-tracker #x4000)))
(when s5-1
(let ((t9-12 (method-of-type part-tracker activate)))
(t9-12
(the-as part-tracker s5-1)
*entity-pool*
(symbol->string (-> part-tracker symbol))
(the-as pointer #x70004000)
)
)
(let ((t9-13 run-function-in-process)
(a0-19 s5-1)
(a1-15 part-tracker-init)
(a2-12 (-> *part-group-id-table* 68))
(a3-3 0)
(t0-2 #f)
(t1-0 #f)
(t2-0 #f)
(t3-0 *launch-matrix*)
)
(set! (-> t3-0 trans quad) (-> this root trans quad))
((the-as (function object object object object object object object object none) t9-13)
a0-19
a1-15
a2-12
a3-3
t0-2
t1-0
t2-0
t3-0
)
)
(-> s5-1 ppointer)
)
)
0
(none)
)
)
(defmethod unknown-particles ((this gun-blue-shot))
"TODO - confirm"
(draw-beam (-> *part-id-table* 191) (-> this init-pos) (-> this init-dir) #f #t)
(draw-beam (-> *part-id-table* 194) (-> this init-pos) (-> this starting-dir) #f #t)
0
(none)
)
;; WARN: Return type mismatch sound-id vs none.
(defmethod play-impact-sound ((this gun-blue-shot) (arg0 projectile-options))
(let ((v1-0 arg0))
(cond
((zero? v1-0)
(sound-play "blue-shot-fire")
)
((= v1-0 (projectile-options lose-altitude))
(sound-play "blue-shot-hit")
)
)
)
(none)
)
(defmethod made-impact? ((this gun-blue-shot))
"TODO - queries the collision cache, return true/false"
(let ((v1-0 (-> this root))
(t1-0 (new 'stack-no-clear 'collide-query))
)
(let ((a1-0 t1-0))
(set! (-> a1-0 radius) (-> v1-0 root-prim prim-core world-sphere w))
(set! (-> a1-0 collide-with) (-> v1-0 root-prim prim-core collide-with))
(set! (-> a1-0 ignore-process0) this)
(set! (-> a1-0 ignore-process1) (ppointer->process (-> this parent)))
(set! (-> a1-0 ignore-pat) (new 'static 'pat-surface :noentity #x1 :nojak #x1 :probe #x1 :noendlessfall #x1))
(set! (-> a1-0 action-mask) (collide-action solid))
)
(fill-and-try-snap-to-surface v1-0 (-> v1-0 transv) -12288.0 12697.6 -2048.0 t1-0)
)
)
(defun gun-blue-shot-move ((arg0 gun-blue-shot))
(projectile-move-fill-line-sphere arg0)
(if (logtest? (-> arg0 root status) (collide-status touch-surface))
(go (method-of-object arg0 impact))
)
0
(none)
)
;; WARN: Return type mismatch int vs collide-status.
(defun cshape-reaction-blue-shot ((arg0 control-info) (arg1 collide-query) (arg2 vector) (arg3 vector))
(vector-reset! arg2)
(let ((a1-1 (new 'stack-no-clear 'vector)))
(vector-float*! a1-1 (-> arg1 move-dist) (-> arg1 best-dist))
(move-by-vector! arg0 a1-1)
)
(set! (-> (the-as gun-blue-shot (-> arg0 process)) collide-normal quad) (-> arg1 best-other-tri normal quad))
(let ((v0-1 4))
(logior! (-> arg0 status) v0-1)
(the-as collide-status v0-1)
)
)
(defmethod init-proj-collision! ((this gun-blue-shot))
"Init the [[projectile]]'s [[collide-shape]]"
(let ((s5-0 (new 'process 'collide-shape-moving this (collide-list-enum hit-by-player))))
(set! (-> s5-0 dynam) (copy *standard-dynamics* 'process))
(set! (-> s5-0 reaction) cshape-reaction-blue-shot)
(set! (-> s5-0 no-reaction)
(the-as (function collide-shape-moving collide-query vector vector object) nothing)
)
(set! (-> s5-0 penetrate-using) (penetrate jak-blue-shot))
(let ((s4-0 (new 'process 'collide-shape-prim-group s5-0 (the-as uint 2) 0)))
(set! (-> s5-0 total-prims) (the-as uint 3))
(set! (-> s4-0 prim-core collide-as) (collide-spec projectile))
(set! (-> s4-0 prim-core collide-with)
(collide-spec backgnd bot crate civilian enemy obstacle vehicle-sphere hit-by-others-list player-list pusher)
)
(set! (-> s4-0 prim-core action) (collide-action solid))
(set-vector! (-> s4-0 local-sphere) 0.0 0.0 0.0 1228.8)
(set! (-> s5-0 root-prim) s4-0)
)
(let ((v1-13 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 0))))
(set! (-> v1-13 prim-core collide-as) (collide-spec projectile))
(set! (-> v1-13 prim-core collide-with) (collide-spec backgnd obstacle pusher))
(set! (-> v1-13 prim-core action) (collide-action solid))
(set-vector! (-> v1-13 local-sphere) 0.0 0.0 0.0 819.2)
)
(let ((v1-15 (new 'process 'collide-shape-prim-sphere s5-0 (the-as uint 0))))
(set! (-> v1-15 prim-core collide-as) (collide-spec projectile))
(set! (-> v1-15 prim-core collide-with)
(collide-spec bot crate civilian enemy vehicle-sphere hit-by-others-list player-list)
)
(set! (-> v1-15 prim-core action) (collide-action solid))
(set-vector! (-> v1-15 local-sphere) 0.0 0.0 0.0 4096.0)
)
(set! (-> s5-0 nav-radius) (* 0.75 (-> s5-0 root-prim local-sphere w)))
(let ((v1-18 (-> s5-0 root-prim)))
(set! (-> s5-0 backup-collide-as) (-> v1-18 prim-core collide-as))
(set! (-> s5-0 backup-collide-with) (-> v1-18 prim-core collide-with))
)
(set! (-> s5-0 max-iteration-count) (the-as uint 1))
(set! (-> s5-0 event-self) 'touched)
(set! (-> this root) s5-0)
)
(set! (-> this root pat-ignore-mask)
(new 'static 'pat-surface :noentity #x1 :nojak #x1 :probe #x1 :noproj #x1 :noendlessfall #x1)
)
0
(none)
)
(defmethod init-proj-settings! ((this gun-blue-shot))
"Init relevant settings for the [[projectile]] such as gravity, speed, timeout, etc"
(with-pp
(cpad-set-buzz! (-> *cpad-list* cpads 0) 1 204 (seconds 0.1))
(set! (-> this init-pos quad) (-> this root trans quad))
(set! (-> this init-dir quad) (-> this starting-dir quad))
(vector-normalize-copy! (-> this root transv) (-> this init-dir) (* 327680.0 (-> pp clock frames-per-second)))
(set! (-> this attack-mode) 'eco-blue)
(set! (-> this max-speed) (* 327680.0 (-> pp clock frames-per-second)))
(set! (-> this timeout) 1)
(set! (-> this move) gun-blue-shot-move)
(vector-reset! (-> this collide-normal))
(set! (-> this damage) (if (logtest? (game-feature gun-upgrade-damage) (-> *game-info* features))
4.0
2.0
)
)
0
(none)
)
)