diff --git a/decompiler/config/all-types.gc b/decompiler/config/all-types.gc index 0ad6e20c0d..427e59c72a 100644 --- a/decompiler/config/all-types.gc +++ b/decompiler/config/all-types.gc @@ -34988,6 +34988,10 @@ (:methods (TODO-RENAME-20 (_type_) symbol 20) ) + (:states + cave-trap-idle + cave-trap-give-up + cave-trap-active) ) (deftype spider-vent (process-drawable) @@ -34997,6 +35001,8 @@ :size-assert #xb8 :heap-base #x50 :flag-assert #x14005000b8 + (:states + spider-vent-idle) ) (deftype spawn-baby-spider-best (structure) @@ -35020,13 +35026,6 @@ (define-extern cave-trap-default-event-handler (function process int symbol event-message-block object :behavior cave-trap)) -;; - Unknowns - -(define-extern cave-trap-idle (state cave-trap)) ;; unknown type -(define-extern cave-trap-give-up (state cave-trap)) ;; unknown type -(define-extern cave-trap-active (state cave-trap)) ;; unknown type -(define-extern spider-vent-idle (state spider-vent)) ;; unknown type - ;; ---------------------- ;; File - spider-egg diff --git a/decompiler/config/jak1_ntsc_black_label/stack_structures.jsonc b/decompiler/config/jak1_ntsc_black_label/stack_structures.jsonc index 8f353d83e2..f8415dcad8 100644 --- a/decompiler/config/jak1_ntsc_black_label/stack_structures.jsonc +++ b/decompiler/config/jak1_ntsc_black_label/stack_structures.jsonc @@ -2838,9 +2838,9 @@ [16, "spawn-baby-spider-work"], [80, "vector"], [96, "event-message-block"], - [176, "vector"], + [176, "sphere"], [192, "vector"], - [208, "vector"] + [208, "baby-spider-spawn-params"] ], "(trans cave-trap-idle)": [[16, "event-message-block"]], diff --git a/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc b/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc index b5fa35f227..9084f44a8e 100644 --- a/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc +++ b/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc @@ -3185,7 +3185,8 @@ [77, "s2", "process-drawable"], [95, "s2", "process-drawable"], [181, "s3", "process-drawable"], - [221, "s3", "process-drawable"] + [221, "s3", "process-drawable"], + [230, "v1", "baby-spider"] ], "(method 7 cave-trap)": [ diff --git a/goal_src/levels/robocave/cave-trap.gc b/goal_src/levels/robocave/cave-trap.gc index 451e5f1c66..96afc62b2e 100644 --- a/goal_src/levels/robocave/cave-trap.gc +++ b/goal_src/levels/robocave/cave-trap.gc @@ -5,3 +5,353 @@ ;; name in dgo: cave-trap ;; dgos: L1, ROB +(declare-type spider-egg process-drawable) + +;; DECOMP BEGINS + +(deftype cave-trap (process-drawable) + ((root-override collide-shape :offset 112) + (spider-count int32 :offset-assert 176) + (alt-actors (array entity-actor) :offset-assert 180) + (spawn-delay uint64 :offset-assert 184) + (last-spawn-time uint64 :offset-assert 192) + (debug-targ-pos vector :inline :offset-assert 208) + ) + :heap-base #x70 + :method-count-assert 21 + :size-assert #xe0 + :flag-assert #x15007000e0 + (:methods + (TODO-RENAME-20 (_type_) symbol 20) + ) + (:states + cave-trap-active + cave-trap-give-up + cave-trap-idle + ) + ) + + +(deftype spider-vent (process-drawable) + ((last-spawn-time uint64 :offset-assert 176) + ) + :heap-base #x50 + :method-count-assert 20 + :size-assert #xb8 + :flag-assert #x14005000b8 + (:states + spider-vent-idle + ) + ) + + +(defstate spider-vent-idle (spider-vent) + :event + (behavior ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block)) + (local-vars (v0-0 object)) + (case arg2 + (('can-spawn?) + (return (>= (- (-> *display* base-frame-counter) (the-as int (-> self last-spawn-time))) 300)) + v0-0 + ) + (('notify-spawned) + (set! v0-0 (-> *display* base-frame-counter)) + (set! (-> self last-spawn-time) (the-as uint v0-0)) + v0-0 + ) + ) + ) + :code + (behavior () (logior! (-> self mask) (process-mask sleep-code)) (suspend) 0 (none)) + ) + +(defmethod init-from-entity! spider-vent ((obj spider-vent) (arg0 entity-actor)) + (set! (-> obj last-spawn-time) (the-as uint 0)) + (set! (-> obj root) (new 'process 'trsqv)) + (process-drawable-from-entity! obj arg0) + (go spider-vent-idle) + (none) + ) + +(defbehavior cave-trap-default-event-handler cave-trap ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block)) + (case arg2 + (('untrigger) + (when (= (-> arg0 type) baby-spider) + (let ((v0-0 (the-as object (max 0 (+ (-> self spider-count) -1))))) + (set! (-> self spider-count) (the-as int v0-0)) + v0-0 + ) + ) + ) + (('notify) + (if (and (= (-> arg0 type) spider-egg) (= (-> self next-state name) 'cave-trap-idle)) + (go cave-trap-active) + ) + ) + ) + ) + +(deftype spawn-baby-spider-best (structure) + ((index int32 :offset-assert 0) + (dist float :offset-assert 4) + ) + :method-count-assert 9 + :size-assert #x8 + :flag-assert #x900000008 + ) + + +(deftype spawn-baby-spider-work (structure) + ((best spawn-baby-spider-best 4 :inline :offset-assert 0) + ) + :method-count-assert 9 + :size-assert #x40 + :flag-assert #x900000040 + ) + + +(defmethod TODO-RENAME-20 cave-trap ((obj cave-trap)) + (with-pp + (set! (-> obj last-spawn-time) (the-as uint (-> *display* base-frame-counter))) + (set! (-> obj spawn-delay) (the-as uint (rand-vu-int-range 30 150))) + (let ((s5-0 (new 'stack-no-clear 'spawn-baby-spider-work))) + (let ((s4-0 (new 'stack-no-clear 'vector))) + (dotimes (v1-2 4) + (set! (-> s5-0 best v1-2 index) -1) + ) + (set! (-> s4-0 quad) (-> (matrix-local->world #f #f) vector 2 quad)) + (set! (-> s4-0 y) 0.0) + (vector-normalize! s4-0 102400.0) + (vector+! s4-0 s4-0 (camera-pos)) + (set! (-> s4-0 y) (-> (target-pos 0) y)) + (dotimes (s3-2 (-> obj alt-actors length)) + (let* ((v1-10 (-> obj alt-actors s3-2)) + (s1-0 (if v1-10 + (-> v1-10 extra process) + ) + ) + (s2-2 (if (and (nonzero? s1-0) (type-type? (-> s1-0 type) process-drawable)) + s1-0 + ) + ) + ) + (when s2-2 + (let ((a1-6 (new 'stack-no-clear 'event-message-block))) + (set! (-> a1-6 from) pp) + (set! (-> a1-6 num-params) 0) + (set! (-> a1-6 message) 'can-spawn?) + (when (send-event-function s2-2 a1-6) + (let ((f30-0 (vector-vector-distance s4-0 (-> (the-as process-drawable s2-2) root trans))) + (a0-12 (new 'stack-no-clear 'sphere)) + ) + (let ((v1-16 (-> s5-0 best 3))) + (when (or (< (-> v1-16 index) 0) (< f30-0 (-> v1-16 dist))) + (set! (-> v1-16 index) s3-2) + (set! (-> v1-16 dist) f30-0) + ) + ) + (set! (-> a0-12 quad) (-> (the-as process-drawable s2-2) root trans quad)) + (set! (-> a0-12 w) 4096.0) + (when (sphere-in-view-frustum? a0-12) + (let ((v1-18 (-> s5-0 best 2))) + (when (or (< (-> v1-18 index) 0) (< f30-0 (-> v1-18 dist))) + (set! (-> v1-18 index) s3-2) + (set! (-> v1-18 dist) f30-0) + ) + ) + (when (>= 40960.0 f30-0) + (let ((v1-19 (-> s5-0 best 1))) + (when (or (< (-> v1-19 index) 0) (< f30-0 (-> v1-19 dist))) + (set! (-> v1-19 index) s3-2) + (set! (-> v1-19 dist) f30-0) + ) + ) + (when (= (-> s2-2 type) spider-egg) + (let ((v1-21 (-> s5-0 best))) + (when (or (< (-> v1-21 0 index) 0) (< f30-0 (-> v1-21 0 dist))) + (set! (-> v1-21 0 index) s3-2) + (set! (-> v1-21 0 dist) f30-0) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + (dotimes (s4-1 4) + (let ((v1-29 (-> s5-0 best s4-1 index))) + (when (>= v1-29 0) + (let* ((v1-32 (-> obj alt-actors v1-29)) + (s2-3 (if v1-32 + (-> v1-32 extra process) + ) + ) + (s3-3 (if (and (nonzero? s2-3) (type-type? (-> s2-3 type) process-drawable)) + s2-3 + ) + ) + (s2-4 (new 'stack-no-clear 'vector)) + (s1-1 (new 'stack-no-clear 'baby-spider-spawn-params)) + ) + (vector-! s2-4 (target-pos 0) (-> (the-as process-drawable s3-3) root trans)) + (vector-normalize! s2-4 1.0) + (init! s1-1 (= (-> s3-3 type) spider-egg) #t #t #t 7 1 'untrigger) + (let* ((s0-2 (get-process *default-dead-pool* baby-spider #x4000)) + (v1-40 (when s0-2 + (let ((t9-14 (method-of-type baby-spider activate))) + (t9-14 (the-as baby-spider s0-2) obj 'baby-spider (the-as pointer #x70004000)) + ) + (run-now-in-process + s0-2 + baby-spider-init-by-other + obj + (-> (the-as process-drawable s3-3) root trans) + s2-4 + s1-1 + ) + (-> s0-2 ppointer) + ) + ) + ) + (when v1-40 + (set! (-> (the-as baby-spider (-> v1-40 0)) die-if-not-visible?) #t) + (+! (-> obj spider-count) 1) + (send-event s3-3 'notify-spawned) + (return #f) + ) + ) + ) + ) + ) + ) + ) + #f + ) + ) + +(defstate cave-trap-idle (cave-trap) + :event + cave-trap-default-event-handler + :trans + (behavior () + (when *target* + (let* ((gp-0 (target-pos 0)) + (f0-0 (vector-vector-xz-distance (-> self root-override trans) (target-pos 0))) + (f1-1 (- (-> gp-0 y) (-> self root-override trans y))) + ) + (when (and (>= 61440.0 f1-1) (>= f1-1 -16384.0)) + (when (>= 274432.0 f0-0) + (when (or (>= 188416.0 f0-0) (send-event *target* 'query 'powerup 1)) + (level-hint-spawn + (game-text-id cave-trap-nest-hint) + "sksp0341" + (the-as entity #f) + *entity-pool* + (game-task none) + ) + (close-specific-task! (game-task cave-spider-tunnel) (task-status need-hint)) + (go cave-trap-active) + ) + ) + ) + ) + ) + (none) + ) + :code + (behavior () (logior! (-> self mask) (process-mask sleep-code)) (suspend) 0 (none)) + ) + +(defstate cave-trap-active (cave-trap) + :event + cave-trap-default-event-handler + :enter + (behavior () (set! (-> self spawn-delay) (the-as uint 150)) (none)) + :trans + (behavior () + (cond + (*target* + (let* ((gp-0 (target-pos 0)) + (f0-0 (vector-vector-xz-distance (-> self root-override trans) (target-pos 0))) + (f1-1 (- (-> gp-0 y) (-> self root-override trans y))) + ) + (if (or (< 73728.0 f1-1) (< f1-1 -24576.0) (< 368640.0 f0-0)) + (go cave-trap-give-up) + ) + ) + (if (and + (< (-> self spider-count) 8) + (>= (- (-> *display* base-frame-counter) (the-as int (-> self last-spawn-time))) + (the-as int (-> self spawn-delay)) + ) + ) + (TODO-RENAME-20 self) + ) + ) + (else + (go cave-trap-give-up) + ) + ) + 0 + (none) + ) + :code + (behavior () (logior! (-> self mask) (process-mask sleep-code)) (suspend) 0 (none)) + ) + +(defstate cave-trap-give-up (cave-trap) + :event + cave-trap-default-event-handler + :code + (behavior () (suspend) (go cave-trap-idle) (none)) + ) + +(defmethod relocate cave-trap ((obj cave-trap) (arg0 int)) + (if (nonzero? (-> obj alt-actors)) + (&+! (-> obj alt-actors) arg0) + ) + (the-as + cave-trap + ((the-as (function process-drawable int process-drawable) (find-parent-method cave-trap 7)) obj arg0) + ) + ) + +(defmethod init-from-entity! cave-trap ((obj cave-trap) (arg0 entity-actor)) + (set! (-> obj spider-count) 0) + (set! (-> obj spawn-delay) (the-as uint 0)) + (set! (-> obj last-spawn-time) (the-as uint 0)) + (let ((s4-0 (new 'process 'collide-shape obj (collide-list-enum hit-by-player)))) + (let ((s3-0 (new 'process 'collide-shape-prim-sphere s4-0 (the-as uint 0)))) + (set! (-> s3-0 prim-core offense) 0) + (set-vector! (-> s3-0 local-sphere) 0.0 0.0 0.0 4096.0) + (set-root-prim! s4-0 s3-0) + ) + (set! (-> s4-0 nav-radius) (* 0.75 (-> s4-0 root-prim local-sphere w))) + (backup-collide-with-as s4-0) + (set! (-> obj root-override) s4-0) + ) + (process-drawable-from-entity! obj arg0) + (set! (-> obj nav) (new 'process 'nav-control (-> obj root-override) 16 40960.0)) + (logior! (-> obj nav flags) (nav-control-flags display-marks bit3 bit5 bit6 bit7)) + (set! (-> obj nav nearest-y-threshold) 409600.0) + (set! (-> obj root-override nav-flags) (logand -2 (-> obj root-override nav-flags))) + (set! (-> obj path) (new 'process 'path-control obj 'path 0.0)) + (logior! (-> obj path flags) (path-control-flag display draw-line draw-point draw-text)) + (let ((s4-1 (entity-actor-count arg0 'alt-actor))) + (set! (-> obj alt-actors) (the-as (array entity-actor) (new 'process 'boxed-array entity-actor s4-1))) + (dotimes (s3-1 s4-1) + (set! (-> obj alt-actors s3-1) (entity-actor-lookup arg0 'alt-actor s3-1)) + ) + ) + (go cave-trap-idle) + (none) + ) + + + + diff --git a/test/decompiler/reference/levels/robocave/cave-trap_REF.gc b/test/decompiler/reference/levels/robocave/cave-trap_REF.gc new file mode 100644 index 0000000000..e1b16366b2 --- /dev/null +++ b/test/decompiler/reference/levels/robocave/cave-trap_REF.gc @@ -0,0 +1,395 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition of type cave-trap +(deftype cave-trap (process-drawable) + ((root-override collide-shape :offset 112) + (spider-count int32 :offset-assert 176) + (alt-actors (array entity-actor) :offset-assert 180) + (spawn-delay uint64 :offset-assert 184) + (last-spawn-time uint64 :offset-assert 192) + (debug-targ-pos vector :inline :offset-assert 208) + ) + :heap-base #x70 + :method-count-assert 21 + :size-assert #xe0 + :flag-assert #x15007000e0 + (:methods + (TODO-RENAME-20 (_type_) symbol 20) + ) + (:states + cave-trap-active + cave-trap-give-up + cave-trap-idle + ) + ) + +;; definition for method 3 of type cave-trap +(defmethod inspect cave-trap ((obj cave-trap)) + (let ((t9-0 (method-of-type process-drawable inspect))) + (t9-0 obj) + ) + (format #t "~T~Tspider-count: ~D~%" (-> obj spider-count)) + (format #t "~T~Talt-actors: ~A~%" (-> obj alt-actors)) + (format #t "~T~Tspawn-delay: ~D~%" (-> obj spawn-delay)) + (format #t "~T~Tlast-spawn-time: ~D~%" (-> obj last-spawn-time)) + (format #t "~T~Tdebug-targ-pos: #~%" (-> obj debug-targ-pos)) + obj + ) + +;; definition of type spider-vent +(deftype spider-vent (process-drawable) + ((last-spawn-time uint64 :offset-assert 176) + ) + :heap-base #x50 + :method-count-assert 20 + :size-assert #xb8 + :flag-assert #x14005000b8 + (:states + spider-vent-idle + ) + ) + +;; definition for method 3 of type spider-vent +(defmethod inspect spider-vent ((obj spider-vent)) + (let ((t9-0 (method-of-type process-drawable inspect))) + (t9-0 obj) + ) + (format #t "~T~Tlast-spawn-time: ~D~%" (-> obj last-spawn-time)) + obj + ) + +;; failed to figure out what this is: +(defstate spider-vent-idle (spider-vent) + :event + (behavior ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block)) + (local-vars (v0-0 object)) + (case arg2 + (('can-spawn?) + (return (>= (- (-> *display* base-frame-counter) (the-as int (-> self last-spawn-time))) 300)) + v0-0 + ) + (('notify-spawned) + (set! v0-0 (-> *display* base-frame-counter)) + (set! (-> self last-spawn-time) (the-as uint v0-0)) + v0-0 + ) + ) + ) + :code + (behavior () (logior! (-> self mask) (process-mask sleep-code)) (suspend) 0 (none)) + ) + +;; definition for method 11 of type spider-vent +;; INFO: Return type mismatch object vs none. +(defmethod init-from-entity! spider-vent ((obj spider-vent) (arg0 entity-actor)) + (set! (-> obj last-spawn-time) (the-as uint 0)) + (set! (-> obj root) (new 'process 'trsqv)) + (process-drawable-from-entity! obj arg0) + (go spider-vent-idle) + (none) + ) + +;; definition for function cave-trap-default-event-handler +(defbehavior cave-trap-default-event-handler cave-trap ((arg0 process) (arg1 int) (arg2 symbol) (arg3 event-message-block)) + (case arg2 + (('untrigger) + (when (= (-> arg0 type) baby-spider) + (let ((v0-0 (the-as object (max 0 (+ (-> self spider-count) -1))))) + (set! (-> self spider-count) (the-as int v0-0)) + v0-0 + ) + ) + ) + (('notify) + (if (and (= (-> arg0 type) spider-egg) (= (-> self next-state name) 'cave-trap-idle)) + (go cave-trap-active) + ) + ) + ) + ) + +;; definition of type spawn-baby-spider-best +(deftype spawn-baby-spider-best (structure) + ((index int32 :offset-assert 0) + (dist float :offset-assert 4) + ) + :method-count-assert 9 + :size-assert #x8 + :flag-assert #x900000008 + ) + +;; definition for method 3 of type spawn-baby-spider-best +(defmethod inspect spawn-baby-spider-best ((obj spawn-baby-spider-best)) + (format #t "[~8x] ~A~%" obj 'spawn-baby-spider-best) + (format #t "~Tindex: ~D~%" (-> obj index)) + (format #t "~Tdist: ~f~%" (-> obj dist)) + obj + ) + +;; definition of type spawn-baby-spider-work +(deftype spawn-baby-spider-work (structure) + ((best spawn-baby-spider-best 4 :inline :offset-assert 0) + ) + :method-count-assert 9 + :size-assert #x40 + :flag-assert #x900000040 + ) + +;; definition for method 3 of type spawn-baby-spider-work +(defmethod inspect spawn-baby-spider-work ((obj spawn-baby-spider-work)) + (format #t "[~8x] ~A~%" obj 'spawn-baby-spider-work) + (format #t "~Tbest[4] @ #x~X~%" (-> obj best)) + obj + ) + +;; definition for method 20 of type cave-trap +;; Used lq/sq +(defmethod TODO-RENAME-20 cave-trap ((obj cave-trap)) + (with-pp + (set! (-> obj last-spawn-time) (the-as uint (-> *display* base-frame-counter))) + (set! (-> obj spawn-delay) (the-as uint (rand-vu-int-range 30 150))) + (let ((s5-0 (new 'stack-no-clear 'spawn-baby-spider-work))) + (let ((s4-0 (new 'stack-no-clear 'vector))) + (dotimes (v1-2 4) + (set! (-> s5-0 best v1-2 index) -1) + ) + (set! (-> s4-0 quad) (-> (matrix-local->world #f #f) vector 2 quad)) + (set! (-> s4-0 y) 0.0) + (vector-normalize! s4-0 102400.0) + (vector+! s4-0 s4-0 (camera-pos)) + (set! (-> s4-0 y) (-> (target-pos 0) y)) + (dotimes (s3-2 (-> obj alt-actors length)) + (let* ((v1-10 (-> obj alt-actors s3-2)) + (s1-0 (if v1-10 + (-> v1-10 extra process) + ) + ) + (s2-2 (if (and (nonzero? s1-0) (type-type? (-> s1-0 type) process-drawable)) + s1-0 + ) + ) + ) + (when s2-2 + (let ((a1-6 (new 'stack-no-clear 'event-message-block))) + (set! (-> a1-6 from) pp) + (set! (-> a1-6 num-params) 0) + (set! (-> a1-6 message) 'can-spawn?) + (when (send-event-function s2-2 a1-6) + (let ((f30-0 (vector-vector-distance s4-0 (-> (the-as process-drawable s2-2) root trans))) + (a0-12 (new 'stack-no-clear 'sphere)) + ) + (let ((v1-16 (-> s5-0 best 3))) + (when (or (< (-> v1-16 index) 0) (< f30-0 (-> v1-16 dist))) + (set! (-> v1-16 index) s3-2) + (set! (-> v1-16 dist) f30-0) + ) + ) + (set! (-> a0-12 quad) (-> (the-as process-drawable s2-2) root trans quad)) + (set! (-> a0-12 w) 4096.0) + (when (sphere-in-view-frustum? a0-12) + (let ((v1-18 (-> s5-0 best 2))) + (when (or (< (-> v1-18 index) 0) (< f30-0 (-> v1-18 dist))) + (set! (-> v1-18 index) s3-2) + (set! (-> v1-18 dist) f30-0) + ) + ) + (when (>= 40960.0 f30-0) + (let ((v1-19 (-> s5-0 best 1))) + (when (or (< (-> v1-19 index) 0) (< f30-0 (-> v1-19 dist))) + (set! (-> v1-19 index) s3-2) + (set! (-> v1-19 dist) f30-0) + ) + ) + (when (= (-> s2-2 type) spider-egg) + (let ((v1-21 (-> s5-0 best))) + (when (or (< (-> v1-21 0 index) 0) (< f30-0 (-> v1-21 0 dist))) + (set! (-> v1-21 0 index) s3-2) + (set! (-> v1-21 0 dist) f30-0) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + (dotimes (s4-1 4) + (let ((v1-29 (-> s5-0 best s4-1 index))) + (when (>= v1-29 0) + (let* ((v1-32 (-> obj alt-actors v1-29)) + (s2-3 (if v1-32 + (-> v1-32 extra process) + ) + ) + (s3-3 (if (and (nonzero? s2-3) (type-type? (-> s2-3 type) process-drawable)) + s2-3 + ) + ) + (s2-4 (new 'stack-no-clear 'vector)) + (s1-1 (new 'stack-no-clear 'baby-spider-spawn-params)) + ) + (vector-! s2-4 (target-pos 0) (-> (the-as process-drawable s3-3) root trans)) + (vector-normalize! s2-4 1.0) + (init! s1-1 (= (-> s3-3 type) spider-egg) #t #t #t 7 1 'untrigger) + (let* ((s0-2 (get-process *default-dead-pool* baby-spider #x4000)) + (v1-40 (when s0-2 + (let ((t9-14 (method-of-type baby-spider activate))) + (t9-14 (the-as baby-spider s0-2) obj 'baby-spider (the-as pointer #x70004000)) + ) + (run-now-in-process + s0-2 + baby-spider-init-by-other + obj + (-> (the-as process-drawable s3-3) root trans) + s2-4 + s1-1 + ) + (-> s0-2 ppointer) + ) + ) + ) + (when v1-40 + (set! (-> (the-as baby-spider (-> v1-40 0)) die-if-not-visible?) #t) + (+! (-> obj spider-count) 1) + (send-event s3-3 'notify-spawned) + (return #f) + ) + ) + ) + ) + ) + ) + ) + #f + ) + ) + +;; failed to figure out what this is: +(defstate cave-trap-idle (cave-trap) + :event + cave-trap-default-event-handler + :trans + (behavior () + (when *target* + (let* ((gp-0 (target-pos 0)) + (f0-0 (vector-vector-xz-distance (-> self root-override trans) (target-pos 0))) + (f1-1 (- (-> gp-0 y) (-> self root-override trans y))) + ) + (when (and (>= 61440.0 f1-1) (>= f1-1 -16384.0)) + (when (>= 274432.0 f0-0) + (when (or (>= 188416.0 f0-0) (send-event *target* 'query 'powerup 1)) + (level-hint-spawn + (game-text-id cave-trap-nest-hint) + "sksp0341" + (the-as entity #f) + *entity-pool* + (game-task none) + ) + (close-specific-task! (game-task cave-spider-tunnel) (task-status need-hint)) + (go cave-trap-active) + ) + ) + ) + ) + ) + (none) + ) + :code + (behavior () (logior! (-> self mask) (process-mask sleep-code)) (suspend) 0 (none)) + ) + +;; failed to figure out what this is: +(defstate cave-trap-active (cave-trap) + :event + cave-trap-default-event-handler + :enter + (behavior () (set! (-> self spawn-delay) (the-as uint 150)) (none)) + :trans + (behavior () + (cond + (*target* + (let* ((gp-0 (target-pos 0)) + (f0-0 (vector-vector-xz-distance (-> self root-override trans) (target-pos 0))) + (f1-1 (- (-> gp-0 y) (-> self root-override trans y))) + ) + (if (or (< 73728.0 f1-1) (< f1-1 -24576.0) (< 368640.0 f0-0)) + (go cave-trap-give-up) + ) + ) + (if (and + (< (-> self spider-count) 8) + (>= (- (-> *display* base-frame-counter) (the-as int (-> self last-spawn-time))) + (the-as int (-> self spawn-delay)) + ) + ) + (TODO-RENAME-20 self) + ) + ) + (else + (go cave-trap-give-up) + ) + ) + 0 + (none) + ) + :code + (behavior () (logior! (-> self mask) (process-mask sleep-code)) (suspend) 0 (none)) + ) + +;; failed to figure out what this is: +(defstate cave-trap-give-up (cave-trap) + :event + cave-trap-default-event-handler + :code + (behavior () (suspend) (go cave-trap-idle) (none)) + ) + +;; definition for method 7 of type cave-trap +;; INFO: Return type mismatch process-drawable vs cave-trap. +(defmethod relocate cave-trap ((obj cave-trap) (arg0 int)) + (if (nonzero? (-> obj alt-actors)) + (&+! (-> obj alt-actors) arg0) + ) + (the-as + cave-trap + ((the-as (function process-drawable int process-drawable) (find-parent-method cave-trap 7)) obj arg0) + ) + ) + +;; definition for method 11 of type cave-trap +;; INFO: Return type mismatch object vs none. +(defmethod init-from-entity! cave-trap ((obj cave-trap) (arg0 entity-actor)) + (set! (-> obj spider-count) 0) + (set! (-> obj spawn-delay) (the-as uint 0)) + (set! (-> obj last-spawn-time) (the-as uint 0)) + (let ((s4-0 (new 'process 'collide-shape obj (collide-list-enum hit-by-player)))) + (let ((s3-0 (new 'process 'collide-shape-prim-sphere s4-0 (the-as uint 0)))) + (set! (-> s3-0 prim-core offense) 0) + (set-vector! (-> s3-0 local-sphere) 0.0 0.0 0.0 4096.0) + (set-root-prim! s4-0 s3-0) + ) + (set! (-> s4-0 nav-radius) (* 0.75 (-> s4-0 root-prim local-sphere w))) + (backup-collide-with-as s4-0) + (set! (-> obj root-override) s4-0) + ) + (process-drawable-from-entity! obj arg0) + (set! (-> obj nav) (new 'process 'nav-control (-> obj root-override) 16 40960.0)) + (logior! (-> obj nav flags) (nav-control-flags display-marks bit3 bit5 bit6 bit7)) + (set! (-> obj nav nearest-y-threshold) 409600.0) + (set! (-> obj root-override nav-flags) (logand -2 (-> obj root-override nav-flags))) + (set! (-> obj path) (new 'process 'path-control obj 'path 0.0)) + (logior! (-> obj path flags) (path-control-flag display draw-line draw-point draw-text)) + (let ((s4-1 (entity-actor-count arg0 'alt-actor))) + (set! (-> obj alt-actors) (the-as (array entity-actor) (new 'process 'boxed-array entity-actor s4-1))) + (dotimes (s3-1 s4-1) + (set! (-> obj alt-actors s3-1) (entity-actor-lookup arg0 'alt-actor s3-1)) + ) + ) + (go cave-trap-idle) + (none) + )