Allow block to be pushed onto tile with gate that is being switched on/off.

This commit is contained in:
David Thompson 2024-05-25 13:51:23 -04:00
parent 3e79c279a8
commit 049e859dac

View file

@ -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)))