diff --git a/biome.lisp b/biome.lisp new file mode 100644 index 0000000..ac533c3 --- /dev/null +++ b/biome.lisp @@ -0,0 +1,57 @@ +;;;; +;;;; Terra Nostra is a Minecraft-like survival game for the commandline. +;;;; +;;;; Biomes are habitat types, that provide default functions for patches. +;;;; This file defines the biome struct and the inbuilt biomes. +;;;; +;;;; (c) 2018 Daniel Vedder, MIT license +;;;; + +;; Biome struct and register + +(defstruct biome + (name "") + (char #\.) ;map display character + (init-items '()) ;initial items for patches with this biome + (update-fn #'(lambda (patch-pos) NIL))) ;needs a patch position argument + + +(let ((biome-list NIL)) + (defun register-biome (symbol-name biome-object) + (setf biome-list (cons (list symbol-name biome-object) biome-list))) + + (defun get-biome (symbol-name) + (cassoc symbol-name biome-list))) + +;; Grasslands biome + +(defun update-grasslands (patch-pos) + ;;TODO + ) + +(register-biome 'grassland + (make-biome :name "grassland" :char #\i + :init-items NIL ;TODO + :update-fn #'update-grasslands)) + +;; Forest biome + +(defun update-forest (patch-pos) + ;;TODO + ) + +(register-biome 'forest + (make-biome :name "forest" :char #\Y + :init-items NIL ;TODO + :update-fn #'update-forest)) + +;; Stream biome + +(defun update-stream (patch-pos) + ;;TODO + ) + +(register-biome 'stream + (make-biome :name "stream" :char #\~ + :init-items NIL ;TODO + :update-fn #'update-stream)) diff --git a/biome.lisp b/biome.lisp new file mode 100644 index 0000000..ac533c3 --- /dev/null +++ b/biome.lisp @@ -0,0 +1,57 @@ +;;;; +;;;; Terra Nostra is a Minecraft-like survival game for the commandline. +;;;; +;;;; Biomes are habitat types, that provide default functions for patches. +;;;; This file defines the biome struct and the inbuilt biomes. +;;;; +;;;; (c) 2018 Daniel Vedder, MIT license +;;;; + +;; Biome struct and register + +(defstruct biome + (name "") + (char #\.) ;map display character + (init-items '()) ;initial items for patches with this biome + (update-fn #'(lambda (patch-pos) NIL))) ;needs a patch position argument + + +(let ((biome-list NIL)) + (defun register-biome (symbol-name biome-object) + (setf biome-list (cons (list symbol-name biome-object) biome-list))) + + (defun get-biome (symbol-name) + (cassoc symbol-name biome-list))) + +;; Grasslands biome + +(defun update-grasslands (patch-pos) + ;;TODO + ) + +(register-biome 'grassland + (make-biome :name "grassland" :char #\i + :init-items NIL ;TODO + :update-fn #'update-grasslands)) + +;; Forest biome + +(defun update-forest (patch-pos) + ;;TODO + ) + +(register-biome 'forest + (make-biome :name "forest" :char #\Y + :init-items NIL ;TODO + :update-fn #'update-forest)) + +;; Stream biome + +(defun update-stream (patch-pos) + ;;TODO + ) + +(register-biome 'stream + (make-biome :name "stream" :char #\~ + :init-items NIL ;TODO + :update-fn #'update-stream)) diff --git a/terranostra.lisp b/terranostra.lisp index ea7b4f9..1377574 100644 --- a/terranostra.lisp +++ b/terranostra.lisp @@ -2,17 +2,18 @@ ;;;; ;;;; Terra Nostra is a Minecraft-like survival game for the commandline. ;;;; -;;;; (c) 2018 Daniel Vedder +;;;; (c) 2018 Daniel Vedder, MIT license ;;;; -;;(load "util.lisp") ;; I want to avoid using this if possible +(load "util.lisp") ;; I want to avoid using this if possible +(load "biome.lisp") (defvar *world* NIL) (defconstant *directions* '(N NE E SE S SW W NW)) (defstruct patch (pos '(0 0)) ;position - (char #\.)) + (biome (make-biome))) (defun init-matrix (size) @@ -81,12 +82,14 @@ ((= x (length world)) (format tf "~&~A~%" xstr)) ;;TODO (setf xstr (concatenate 'string xstr (unless (= x 0) ",") - (format NIL "~S" (patch-char (nth x row))))))))) + (format NIL "~S" + (biome-char (patch-biome (nth x row)))))))))) (defun create-world (size name &optional (world *world*)) (setf world NIL) (setf world (init-matrix size)) + ;;TODO (save-topography name world)) ;; Initialize the random state (which would otherwise not be very random...)