diff --git a/terranostra.lisp b/terranostra.lisp index d6a1353..a194b61 100644 --- a/terranostra.lisp +++ b/terranostra.lisp @@ -11,7 +11,7 @@ (defstruct patch (pos '(0 0)) ;position - (alt 0) ;altitude + (alt 50) ;altitude (streams-in NIL) (streams-out NIL)) @@ -28,6 +28,33 @@ (unless (or (< x 0) (< y 0) (> x (length world)) (> y (length world))) (nth x (nth y world)))) +(defun dir2patch (herex herey therex therey) + "Calculate the direction to a patch" + (cond ((> herex therex) + (cond ((> herey therey) 'SE) + ((< herey therey) 'NE) + (T 'E))) + ((< herex therex) + (cond ((> herey therey) 'SW) + ((< herey therey) 'NW) + (T 'W))) + (T (cond ((> herey therey) 'S) + ((< herey therey) 'N) + (T NIL))))) + +(defun patchindir (x y dir &optional (world *world*)) + "Return the patch in the given direction" + (cond ((eq dir 'N) (coord x (1- y) world)) + ((eq dir 'NE) (coord (1+ x) (1- y) world)) + ((eq dir 'E) (coord (1+ x) y world)) + ((eq dir 'SE) (coord (1+ x) (1+ y) world)) + ((eq dir 'S) (coord x (1+ y) world)) + ((eq dir 'SW) (coord (1- x) (1+ y) world)) + ((eq dir 'W) (coord (1- x) y world)) + ((eq dir 'NW) (coord (1- x) (1- y) world)) + ((null dir) (coord x y world)) + (T (error "~&Invalid direction ~S")))) + (defun save-topography (file-name &optional (world *world*)) "Save the world topography as a csv file" (with-open-file (tf file-name :direction :output) @@ -41,8 +68,34 @@ (defun create-mountains (world &optional (montaneity 2)) "Create mountains and hills. Montaneity determines their number and height." - ) + (do ((n 0 (1+ n)) (npeaks (random (* (/ montaneity 100) + (* (length world) + (length (first world))))))) + ((= n npeaks) world) + (setf world (create-peak (random (first world)) (random (length world)) + (random (* montaneity 100)) world)))) + +(defun create-peak (x y height world) + "Create a mountain peak at the specified location" + (let ((base-height (patch-alt (make-patch)))) + ;;TODO + )) (defun create-valleys (world &optional (aqueousness 5)) "Create valleys through streams. Aqueousness determines their number." + (do ((n 0 (1+ n)) (nstreams (random (* (/ aqueousness 100) + (* (length world) + (length (first world))))))) + ((= n nstreams) world) + (setf world (create-stream (random (first world)) + (random (length world)) world)))) + +(defun create-stream (x y world) + "Create a stream, starting at x/y" + ;;TODO + (flet ((lowest-neighbour ()))) ) + + +;; Initialize the random state (which would otherwise not be very random...) +(setf *random-state* (make-random-state t))