-
Notifications
You must be signed in to change notification settings - Fork 0
/
water.lisp
32 lines (28 loc) · 1.2 KB
/
water.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
(in-package :lambda-lifter)
(defun water-level (water flooding path)
(+ water (floor (path-length path) flooding)))
(defun under-water-p (objects water-level)
(with-robot-coords (rx ry) objects
(declare (ignore rx))
(>= water-level ry)))
(defun water-update (world objects path metadata)
(if (map-has-flooding-p world objects metadata)
(with-meta-bind (metadata water flooding)
(values world
(let ((prev-underwater (funcall objects :underwater)))
(if (under-water-p objects (water-level water flooding path))
(lambda (type)
(case type
(:underwater (if prev-underwater
(+ prev-underwater 1)
1))
(t (funcall objects type))))
(if prev-underwater
(lambda (type)
(case type
(:underwater nil)
(t (funcall objects type))))
objects)))
path
metadata))
(values world objects path metadata)))