#!/usr/bin/clisp ;;;; ;;;; Terra Nostra is a Minecraft-like survival game for the commandline. ;;;; ;;;; (c) 2018 Daniel Vedder ;;;; ;;(load "util.lisp") ;; I want to avoid using this if possible (defvar *world* NIL) (defstruct patch (pos '(0 0)) ;position (alt 0) ;altitude (streams-in NIL) (streams-out NIL)) (defun init-matrix (size) "Create a square matrix of empty patches" (do ((y 0 (1+ y)) (world NIL) (row NIL NIL)) ((= y size) world) (dotimes (x size) (setf row (append row (list (make-patch :pos (list x y)))))) (setf world (append world (list row))))) (defun coord (x y &optional (world *world*)) "Return the patch at the given coordinates or NIL if out of bounds" (unless (or (< x 0) (< y 0) (> x (length world)) (> y (length world))) (nth x (nth y world)))) (defun save-topography (file-name &optional (world *world*)) "Save the world topography as a csv file" (with-open-file (tf file-name :direction :output) (dolist (row world) ;; XXX This would be quicker with (string-from-list), but I ;; don't want to use util.lisp just yet (do ((x 0 (1+ x)) (xstr "")) ((= x (length world)) (format tf "~&~S~%" xstr)) (setf xstr (concatenate 'string xstr (unless (= x 0) ",") (format NIL "~S" (patch-alt (nth x row))))))))) (defun create-mountains (world &optional (montaneity 2)) "Create mountains and hills. Montaneity determines their number and height." ) (defun create-valleys (world &optional (aqueousness 5)) "Create valleys through streams. Aqueousness determines their number." )