Browse Source

Add find-arc and find-circle for eventual vision

Lily Carpenter 9 years ago
parent
commit
8ee6b41a22
1 changed files with 29 additions and 0 deletions
  1. 29 0
      src/crypts-and-corpses.lisp

+ 29 - 0
src/crypts-and-corpses.lisp

@@ -279,6 +279,35 @@
279 279
       ((eq :not-found (gethash right mobiles :not-found)) right)
280 280
       ((eq :not-found (gethash down mobiles :not-found)) down))))
281 281
 
282
+(defun find-arc (x y x0 y0 map)
283
+  (labels ((calc-location-map (x y) (calc-location x y map)))
284
+    (let ((coords (list (list (+ x x0) (+ y y0))
285
+                        (list (+ y x0) (+ x y0))
286
+                        (list (- x0 x) (+ y y0))
287
+                        (list (- x0 y) (+ x y0))
288
+                        (list (- x0 x) (- y0 y))
289
+                        (list (- x0 y) (- y0 x))
290
+                        (list (+ x x0) (- y0 y))
291
+                        (list (+ y x0) (- y0 x)))))
292
+      (loop for i in coords collect (apply #'calc-location-map i)))))
293
+
294
+
295
+
296
+(defun find-circle (location radius map)
297
+  (multiple-value-bind (x0 y0) (calc-coord location map)
298
+    (let ((cur-radius radius)
299
+          (y 0)
300
+          (decision-over-2 (- 1 radius)))
301
+      (loop while (<= y cur-radius)
302
+            as coords = (find-arc cur-radius y x0 y0 map) do
303
+              (incf y)
304
+              (if (<= decision-over-2 0)
305
+                  (incf decision-over-2 (1+ (* 2 y)))
306
+                  (progn
307
+                    (decf cur-radius)
308
+                    (incf decision-over-2 (1+ (* 2 (- y cur-radius))))))
309
+            collect coords))))
310
+
282 311
 (defun fill-map-from-crawler (dungeon map player)
283 312
   (with-slots ((width crawler:width) (height crawler:height)) dungeon
284 313
     (dotimes (x width)