Files
jak-project/goal_src/jak2/levels/city/package/delivery-task.gc
T
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

527 lines
19 KiB
Common Lisp

;;-*-Lisp-*-
(in-package goal)
;; name: delivery-task.gc
;; name in dgo: delivery-task
;; dgos: LPACKAGE
;; DECOMP BEGINS
(defskelgroup skel-krew-package krew-package krew-package-lod0-jg krew-package-idle-ja
((krew-package-lod0-mg (meters 20)) (krew-package-lod1-mg (meters 40)) (krew-package-lod2-mg (meters 999999)))
:bounds (static-spherem 0 0 0 3.6)
)
(deftype krew-package (process-drawable)
((attach-object handle)
(scale float)
)
(:state-methods
idle
die
)
(:methods
(krew-package-method-22 (_type_) none)
(krew-package-method-23 (_type_) none)
)
)
(defmethod krew-package-method-22 ((this krew-package))
(set! (-> this root) (new 'process 'trsqv))
0
(none)
)
(defmethod krew-package-method-23 ((this krew-package))
(with-pp
(set! (-> pp level) (level-get *level* 'lpackage))
(initialize-skeleton
this
(the-as skeleton-group (art-group-get-by-name *level* "skel-krew-package" (the-as (pointer uint32) #f)))
(the-as pair 0)
)
(set! (-> this scale) 1.0)
(set! (-> this draw lod-set lod 0 dist) 81920.0)
(set! (-> this draw lod-set lod 1 dist) 204800.0)
(set! (-> this draw lod-set lod 1 dist) 327680.0)
(logior! (-> this skel status) (joint-control-status sync-math))
0
(none)
)
)
(defstate idle (krew-package)
:virtual #t
:code sleep-code
:post (behavior ()
(let ((gp-0 (handle->process (-> self attach-object))))
(cond
(gp-0
(when (focus-test? (the-as process-focusable gp-0) dead)
(seek! (-> self scale) 0.0 (* 0.5 (seconds-per-frame)))
(if (= (-> self scale) 0.0)
(go-virtual die)
)
)
(set! (-> self draw color-mult quad) (-> (the-as process-focusable gp-0) draw color-mult quad))
(set! (-> self root trans quad) (-> (the-as process-focusable gp-0) root trans quad))
(quaternion-copy! (-> self root quat) (-> (the-as process-focusable gp-0) root quat))
)
(else
)
)
)
(let ((f0-5 (-> self scale)))
(set-vector! (-> self root scale) f0-5 f0-5 f0-5 1.0)
)
(ja-post)
)
)
(defstate die (krew-package)
:virtual #t
:code (behavior ()
(cleanup-for-death self)
)
)
;; WARN: Return type mismatch entity-perm-status vs none.
(defmethod init-from-entity! ((this krew-package) (arg0 entity-actor))
"Typically the method that does the initial setup on the process, potentially using the [[entity-actor]] provided as part of that.
This commonly includes things such as:
- stack size
- collision information
- loading the skeleton group / bones
- sounds"
(process-entity-status! this (entity-perm-status dead) #t)
(none)
)
;; WARN: Return type mismatch object vs none.
(defbehavior krew-package-init-by-other krew-package ((arg0 process-drawable))
(stack-size-set! (-> self main-thread) 16)
(logior! (-> self mask) (process-mask platform))
(logclear! (-> self mask) (process-mask actor-pause movie))
(krew-package-method-22 self)
(set! (-> self attach-object) (process->handle arg0))
(set! (-> self root trans quad) (-> arg0 root trans quad))
(quaternion-copy! (-> self root quat) (-> arg0 root quat))
(krew-package-method-23 self)
(go-virtual idle)
(none)
)
;; WARN: Return type mismatch (pointer process) vs (pointer krew-package).
(defun krew-package-spawn ((arg0 process) (arg1 process))
(process-spawn krew-package arg1 :to arg0)
)
(set-subtask-hook!
*game-info*
(game-task-node city-krew-delivery-delivery)
TASK_MANAGER_INIT_HOOK
(lambda :behavior task-manager
()
(while (!= (level-status *level* 'ctysluma) 'active)
(suspend)
)
(let ((v1-3 (entity-by-name "parking-spot-8")))
(if v1-3
(logior! (-> v1-3 extra perm status) (entity-perm-status bit-9))
)
)
(set! (-> self end-pos quad) (-> (new 'static 'vector :x -282624.0 :y 45056.0 :z 5464064.0 :w 1.0) quad))
(set-setting! 'minimap 'clear 0.0 (minimap-flag task-graph))
(let ((gp-1 *traffic-manager*))
(let ((s5-0 (new 'stack 'traffic-object-spawn-params)))
(set! (-> s5-0 position quad) (-> (new 'static 'vector :x 4698112.0 :y 45875.2 :z 81920.0 :w 1.0) quad))
(quaternion-axis-angle! (-> s5-0 rotation) 0.0 1.0 0.0 32768.0)
(set! (-> s5-0 object-type) (traffic-type bikea))
(set! (-> s5-0 behavior) (the-as uint 0))
(set! (-> s5-0 id) (the-as uint 0))
(set! (-> s5-0 proc) #f)
(send-event gp-1 'spawn-object s5-0)
(when (-> s5-0 proc)
(set! (-> self slave 0) (process->handle (-> s5-0 proc)))
(let ((v1-20 (-> s5-0 proc)))
(set! (-> (the-as vehicle v1-20) damage-factor) 2.0)
)
(let ((v1-22 (krew-package-spawn (-> s5-0 proc) (-> s5-0 proc))))
(if v1-22
(set! (-> self slave 1) (process->handle (-> v1-22 0)))
)
)
)
(let ((s4-0 (new 'stack-no-clear 'task-arrow-params)))
(set! (-> s4-0 pos quad) (-> s5-0 position quad))
(quaternion-identity! (-> s4-0 quat))
(set! (-> s4-0 flags) (task-arrow-flags task-arrow-flag-03))
(set! (-> s4-0 map-icon) (the-as uint 15))
(label cfg-21)
(let ((a0-30 (task-arrow-spawn s4-0 self)))
(when (not a0-30)
(format #t "waiting for task-arrow~%")
(suspend)
(goto cfg-21)
)
(set! (-> self arrow) (process->handle a0-30))
)
)
)
(send-event gp-1 'set-target-level 1.0)
(send-event gp-1 'set-guard-target-count-range 4 0 1)
(send-event gp-1 'set-guard-target-count-range 5 0 0)
)
(set! (-> self sub-state) (the-as uint -1))
(set! (-> self data-int8 0) 0)
(set! (-> self data-int8 1) 0)
0
(none)
)
)
(set-subtask-hook!
*game-info*
(game-task-node city-krew-delivery-delivery)
TASK_MANAGER_CLEANUP_HOOK
(lambda :behavior task-manager () (send-event *traffic-manager* 'restore-default-settings) (none))
)
(defun delivery-task-setup-ambush-1 ()
(format #t "delivery-task-setup-ambush-1~%")
(let ((gp-0
(new 'static 'city-ambush-info
:count 10
:array (new 'static 'inline-array city-ambush-spot 10
(new 'static 'city-ambush-spot
:pos (new 'static 'vector :x 4501504.0 :y 32768.0 :z 2297856.0 :w 1.0)
:obj-type #x6
)
(new 'static 'city-ambush-spot
:pos (new 'static 'vector :x 4501504.0 :y 32768.0 :z 2322432.0 :w 1.0)
:obj-type #x6
)
(new 'static 'city-ambush-spot
:pos (new 'static 'vector :x 4501504.0 :y 32768.0 :z 2347008.0 :w 1.0)
:obj-type #x6
)
(new 'static 'city-ambush-spot
:pos (new 'static 'vector :x 4501504.0 :y 32768.0 :z 2371584.0 :w 1.0)
:obj-type #x6
)
(new 'static 'city-ambush-spot
:pos (new 'static 'vector :x 4501504.0 :y 32768.0 :z 2396160.0 :w 1.0)
:obj-type #x6
)
(new 'static 'city-ambush-spot
:pos (new 'static 'vector :x 4513792.0 :y 69632.0 :z 2306048.0 :w 1.0)
:obj-type #x13
)
(new 'static 'city-ambush-spot
:pos (new 'static 'vector :x 4513792.0 :y 69632.0 :z 2387968.0 :w 1.0)
:obj-type #x13
)
(new 'static 'city-ambush-spot
:pos (new 'static 'vector :x 4464640.0 :y 69632.0 :z 2285568.0 :w 1.0)
:obj-type #x12
)
(new 'static 'city-ambush-spot
:pos (new 'static 'vector :x 4464640.0 :y 69632.0 :z 2347008.0 :w 1.0)
:obj-type #x12
)
(new 'static 'city-ambush-spot
:pos (new 'static 'vector :x 4464640.0 :y 69632.0 :z 2408448.0 :w 1.0)
:obj-type #x12
)
)
)
)
(s5-0 (new 'stack-no-clear 'traffic-object-spawn-params))
)
(set! (-> s5-0 object-type) (traffic-type crimson-guard-1))
(set! (-> s5-0 behavior) (the-as uint 9))
(set! (-> s5-0 id) (the-as uint 0))
(set! (-> s5-0 nav-mesh) #f)
(set! (-> s5-0 nav-branch) #f)
(set! (-> s5-0 proc) #f)
(set! (-> s5-0 handle) (process->handle *target*))
(set! (-> s5-0 user-data) (the-as uint 0))
(set! (-> s5-0 flags) (traffic-spawn-flags trsflags-01))
(set! (-> s5-0 guard-type) (the-as uint 1))
(vector-reset! (-> s5-0 velocity))
(forward-up-nopitch->quaternion
(-> s5-0 rotation)
(new 'static 'vector :x -1.0 :w 1.0)
(new 'static 'vector :y 1.0 :w 1.0)
)
(city-ambush-info-method-9 gp-0 s5-0)
)
(none)
)
(defun delivery-task-setup-ambush-2 ()
(format #t "delivery-task-setup-ambush-2~%")
(let ((gp-0
(new 'static 'city-ambush-info
:count 10
:array (new 'static 'inline-array city-ambush-spot 10
(new 'static 'city-ambush-spot
:pos (new 'static 'vector :x 3325952.0 :y 32768.0 :z 4689920.0 :w 1.0)
:obj-type #x6
)
(new 'static 'city-ambush-spot
:pos (new 'static 'vector :x 3342336.0 :y 32768.0 :z 4689920.0 :w 1.0)
:obj-type #x6
)
(new 'static 'city-ambush-spot
:pos (new 'static 'vector :x 3358720.0 :y 32768.0 :z 4689920.0 :w 1.0)
:obj-type #x6
)
(new 'static 'city-ambush-spot
:pos (new 'static 'vector :x 3375104.0 :y 32768.0 :z 4689920.0 :w 1.0)
:obj-type #x6
)
(new 'static 'city-ambush-spot
:pos (new 'static 'vector :x 3391488.0 :y 32768.0 :z 4689920.0 :w 1.0)
:obj-type #x6
)
(new 'static 'city-ambush-spot
:pos (new 'static 'vector :x 3338240.0 :y 69632.0 :z 4689920.0 :w 1.0)
:obj-type #x13
)
(new 'static 'city-ambush-spot
:pos (new 'static 'vector :x 3383296.0 :y 69632.0 :z 4689920.0 :w 1.0)
:obj-type #x13
)
(new 'static 'city-ambush-spot
:pos (new 'static 'vector :x 3338240.0 :y 45056.0 :z 4722688.0 :w 1.0)
:obj-type #x12
)
(new 'static 'city-ambush-spot
:pos (new 'static 'vector :x 3358720.0 :y 45056.0 :z 4722688.0 :w 1.0)
:obj-type #x12
)
(new 'static 'city-ambush-spot
:pos (new 'static 'vector :x 3379200.0 :y 45056.0 :z 4722688.0 :w 1.0)
:obj-type #x12
)
)
)
)
(s5-0 (new 'stack-no-clear 'traffic-object-spawn-params))
)
(set! (-> s5-0 object-type) (traffic-type crimson-guard-1))
(set! (-> s5-0 behavior) (the-as uint 9))
(set! (-> s5-0 id) (the-as uint 0))
(set! (-> s5-0 nav-mesh) #f)
(set! (-> s5-0 nav-branch) #f)
(set! (-> s5-0 proc) #f)
(set! (-> s5-0 handle) (process->handle *target*))
(set! (-> s5-0 user-data) (the-as uint 0))
(set! (-> s5-0 flags) (traffic-spawn-flags trsflags-01))
(set! (-> s5-0 guard-type) (the-as uint 1))
(vector-reset! (-> s5-0 velocity))
(forward-up-nopitch->quaternion
(-> s5-0 rotation)
(new 'static 'vector :x -1.0 :w 1.0)
(new 'static 'vector :y 1.0 :w 1.0)
)
(city-ambush-info-method-9 gp-0 s5-0)
)
(none)
)
(set-subtask-hook!
*game-info*
(game-task-node city-krew-delivery-delivery)
TASK_MANAGER_UPDATE_HOOK
(lambda :behavior task-manager
()
(local-vars (a0-32 float))
(rlet ((acc :class vf)
(vf0 :class vf)
(vf1 :class vf)
(vf2 :class vf)
)
(init-vf0-vector)
(let ((gp-0 (handle->process (-> self slave 0))))
(cond
((and gp-0 (not (logtest? (-> (the-as process-focusable gp-0) focus-status) (focus-status dead))))
(cond
((zero? (-> self data-int8 0))
(when (= (level-status *level* 'ctyindb) 'active)
(set! (-> self data-int8 0) 1)
(delivery-task-setup-ambush-1)
)
)
(else
(when (!= (level-status *level* 'ctyindb) 'active)
(set! (-> self data-int8 0) 0)
0
)
)
)
(cond
((zero? (-> self data-int8 1))
(when (= (level-status *level* 'ctyinda) 'active)
(set! (-> self data-int8 1) 1)
(delivery-task-setup-ambush-2)
)
)
(else
(when (!= (level-status *level* 'ctyinda) 'active)
(set! (-> self data-int8 1) 0)
0
)
)
)
(let ((f0-0 (vector-vector-distance-squared (-> (the-as process-drawable gp-0) root trans) (target-pos 0)))
(f1-0 12288.0)
)
(cond
((and (< f0-0 (* f1-0 f1-0)) *target* (focus-test? *target* pilot))
(when (nonzero? (-> self sub-state))
(send-event (handle->process (-> self arrow)) 'set-position (-> self end-pos))
(send-event (handle->process (-> self arrow)) 'modify-flags 1 0)
(send-event (handle->process (-> self arrow)) 'map-icon 8)
(set! (-> self sub-state) (the-as uint 0))
0
)
)
(else
(let* ((v1-59 (new 'stack-no-clear 'inline-array 'vector 1))
(f0-1 409.6)
(f0-3 (* f0-1 f0-1))
)
(.lvf vf1 (&-> (-> (the-as process-drawable gp-0) root transv) quad))
(.add.w.vf vf2 vf0 vf0 :mask #b1)
(.mul.vf vf1 vf1 vf1)
(.mul.x.vf acc vf2 vf1 :mask #b1)
(.add.mul.y.vf acc vf2 vf1 acc :mask #b1)
(.add.mul.z.vf vf1 vf2 vf1 acc :mask #b1)
(.mov a0-32 vf1)
(when (>= f0-3 a0-32)
(set! (-> v1-59 0 quad) (-> (the-as process-drawable gp-0) root trans quad))
(+! (-> v1-59 0 y) -14336.0)
(send-event (handle->process (-> self arrow)) 'set-position (-> v1-59 0))
)
)
(when (!= (-> self sub-state) 1)
(send-event (handle->process (-> self arrow)) 'modify-flags 0 1)
(send-event (handle->process (-> self arrow)) 'map-icon 15)
(set! (-> self sub-state) (the-as uint 1))
)
)
)
)
(let ((f30-0 49152.0)
(f0-6 (vector-vector-distance-squared (-> (the-as process-drawable gp-0) root trans) (-> self end-pos)))
)
(if (>= (* f30-0 f30-0) f0-6)
(go-virtual complete)
)
)
)
(else
(go-virtual fail)
)
)
)
(none)
)
)
)
(set-subtask-hook!
*game-info*
(game-task-node city-krew-delivery-delivery)
TASK_MANAGER_CODE_HOOK
(lambda :behavior task-manager
()
(let ((gp-0 (new 'static 'vector :x 4501504.0 :y 73728.0 :z 2338816.0 :w 204800.0))
(s5-0 #f)
)
(while (not s5-0)
(let ((v1-1 (handle->process (-> self slave 0))))
(when v1-1
(let ((f0-0 (vector-vector-distance-squared (-> (the-as process-drawable v1-1) root trans) gp-0))
(f1-0 (-> gp-0 w))
)
(set! s5-0 (< f0-0 (* f1-0 f1-0)))
)
)
)
(suspend)
)
)
(send-event *traffic-manager* 'set-guard-target-count-range 0 0 0)
(send-event *traffic-manager* 'set-guard-target-count-range 1 4 4)
(send-event *traffic-manager* 'set-guard-target-count-range 2 0 0)
(send-event *traffic-manager* 'set-guard-target-count-range 4 0 10)
(send-event *traffic-manager* 'set-guard-target-count-range 5 0 10)
(send-event *traffic-manager* 'set-alert-level 3)
(send-event *traffic-manager* 'set-alert-duration (seconds 36000))
(speech-table-set! *speech-control* (speech-type speech-type-7) (new 'static 'speech-type-info
:channel #x1
:priority -2
:min-delay (seconds 2)
:max-delay (seconds 4)
:list (new 'static 'boxed-array :type string
"kg243a"
"kg241a"
"kg242a"
"kg244a"
"kg245a"
"kg246a"
"kg247a"
"kg248a"
"kg249a"
"kg250a"
"kg251a"
"kg252a"
)
)
)
(talker-spawn-func (-> *talker-speech* 49) *entity-pool* (target-pos 0) (the-as region #f))
(let ((gp-2 (new 'static 'vector :x 3358720.0 :y 32768.0 :z 4689920.0 :w 204800.0))
(s5-2 #f)
)
(while (not s5-2)
(let ((v1-48 (handle->process (-> self slave 0))))
(when v1-48
(let ((f0-1 (vector-vector-distance-squared (-> (the-as process-drawable v1-48) root trans) gp-2))
(f1-3 (-> gp-2 w))
)
(set! s5-2 (< f0-1 (* f1-3 f1-3)))
)
)
)
(suspend)
)
)
(talker-spawn-func (-> *talker-speech* 50) *entity-pool* (target-pos 0) (the-as region #f))
(none)
)
)
(set-subtask-hook!
*game-info*
(game-task-node city-krew-delivery-delivery)
TASK_MANAGER_COMPLETE_HOOK
(lambda :behavior task-manager
()
(send-event *traffic-manager* 'decrease-alert-level 0)
(send-event *traffic-manager* 'set-alert-duration (seconds 30))
(if (and *target* (focus-test? *target* pilot))
(send-event *target* 'change-mode 'normal)
)
(set-setting! 'pilot #f 0.0 0)
(set-time! (-> self state-time))
(while (not (time-elapsed? (-> self state-time) (seconds 2)))
(suspend)
)
(none)
)
)