diff --git a/terranostra.lisp b/terranostra.lisp index cfc8ab3..0e647bb 100644 --- a/terranostra.lisp +++ b/terranostra.lisp @@ -110,8 +110,30 @@ (defun create-stream (x y world) "Create a stream, starting at x/y" - ;;TODO - ) + (let ((dir NIL) (min 10000) (nextpatch NIL)) + ;;XXX min=1000 is is a hack to get a hypothetical maximum altitude + ;;Figure out the lowest neighbouring patch + (dolist (d *directions*) + (let ((np (patchindir x y d))) + (when (and np (< (patch-alt np) min)) + (setf min (patch-alt np)) + (setf dir d nextpatch np)))) + (unless (and dir nextpatch) (return-from create-stream world)) + ;;Set streams-in and streams-out + (setf (patch-streams-out (coord x y)) + (append (patch-streams-out (coord x y)) (list dir))) + (setf (patch-streams-in nextpatch) + (append (patch-streams-out nextpatch) + (list (opposite-dir dir)))) + ;;Erode this patch + (setf (patch-alt (coord x y)) + (- (patch-alt (coord x y)) + (random (round (/ (patch-alt (coord x y)) 10))))) + ;;Continue forming the stream + ;;FIXME causes an endless loop -> lowest neighbour becomes this patch + (create-stream (first (patch-pos nextpatch)) + (second (patch-pos nextpatch)) world))) + ;; Initialize the random state (which would otherwise not be very random...) (setf *random-state* (make-random-state t))