From 049e859dacc9e40ee0eac5b4b457f68b36270ab2 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sat, 25 May 2024 13:51:23 -0400 Subject: [PATCH] Allow block to be pushed onto tile with gate that is being switched on/off. --- modules/game/actors.scm | 44 ++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/modules/game/actors.scm b/modules/game/actors.scm index cb8d061..3bcd614 100644 --- a/modules/game/actors.scm +++ b/modules/game/actors.scm @@ -128,6 +128,8 @@ (('post-tick grid-info) #f) (('enter obj grid-info) #f) (('exit obj grid-info) #f) + (('activate grid-info) #f) + (('deactivate grid-info) #f) (('wire-state grid-info from from-x from-y) (match type ((or 'copper 'electron-head 'electron-tail) @@ -228,14 +230,14 @@ (('describe) `(switched-emitter ,position ,(wire-state))) (('collide other offset grid-info) #f))) -(define (first-non-player-occupant grid-info x y) +(define (non-player-occupants grid-info x y) (let lp ((objs ($ grid-info 'occupants x y))) (match objs - (() #f) + (() '()) ((obj . rest) (if (eq? ($ obj 'type) 'player) (lp rest) - obj))))) + (cons obj (lp rest))))))) (define (^floor-switch bcom x y target-x target-y) (define position (vector x y 0)) @@ -250,22 +252,20 @@ (('exit obj grid-info) (when (= (length ($ grid-info 'occupants x y)) 1) ($ on? #f) - (match (first-non-player-occupant grid-info target-x target-y) - (#f (pk "no switch target!")) - (target - ($ grid-info 'append-event `(floor-switch-off ,x ,y)) - ($ target 'deactivate grid-info))))) + (for-each (lambda (obj) + ($ grid-info 'append-event `(floor-switch-off ,x ,y)) + ($ obj 'deactivate grid-info)) + (non-player-occupants grid-info target-x target-y)))) (('wire-state grid-info from from-x from-y) #f) (('update-wire-state grid-info neighbor-grid) #f) (('alive?) #t) (('describe) `(floor-switch ,position ,($ on?))) (('collide other offset grid-info) ($ on? #t) - (match (first-non-player-occupant grid-info target-x target-y) - (#f (pk "no switch target!")) - (target - ($ grid-info 'append-event `(floor-switch-on ,x ,y)) - ($ target 'activate grid-info)))))) + (for-each (lambda (obj) + ($ grid-info 'append-event `(floor-switch-on ,x ,y)) + ($ obj 'activate grid-info)) + (non-player-occupants grid-info target-x target-y))))) (define (^electric-switch bcom x y target-x target-y) (define position (vector x y 0)) @@ -285,19 +285,17 @@ ($ timer t) (when (= t 0) ($ on? #f) - (match (first-non-player-occupant grid-info target-x target-y) - (#f (pk "no switch target!")) - (target - ($ grid-info 'append-event `(electric-switch-off ,x ,y)) - ($ target 'deactivate grid-info))))) + (for-each (lambda (obj) + ($ grid-info 'append-event `(electic-switch-off ,x ,y)) + ($ obj 'deactivate grid-info)) + (non-player-occupants grid-info target-x target-y)))) (when (>= (electron-head-count neighbor-grid) 1) ($ on? #t) ($ timer 2) - (match (first-non-player-occupant grid-info target-x target-y) - (#f (pk "no switch target!")) - (target - ($ grid-info 'append-event `(electric-switch-on ,x ,y)) - ($ target 'activate grid-info)))))) + (for-each (lambda (obj) + ($ grid-info 'append-event `(electic-switch-on ,x ,y)) + ($ obj 'activate grid-info)) + (non-player-occupants grid-info target-x target-y))))) (('alive?) #t) (('describe) `(electric-switch ,position ,($ on?))) (('collide other offset grid-info) #f)))