diff --git a/animals.lisp b/animals.lisp index 09ac297..3f5634c 100644 --- a/animals.lisp +++ b/animals.lisp @@ -8,58 +8,28 @@ ;;;; (c) 2018 Daniel Vedder, MIT license ;;;; +;;TODO Change to African species +;;XXX bird species? -(defvar *animals* NIL) - -(let ((species-list NIL)) - (defun register-species (symbol-name species-object) - (setf species-list - (cons (list symbol-name species-object) species-list))) - - (defun get-species (symbol-name) - (cassoc symbol-name species-list))) - -(defmacro new-species (name &body body) - `(register-species ,name - (make-instance 'species ,@body))) - -(let ((max-id 0)) - (defun add-animal (species position) - "Create a new animal of the given species" - (let ((a (make-animal :id max-id - :pos position :species species - :health (.max-health species)))) - (incf max-id) - (setf *animals* (append *animals* a))))) - -;;; SPECIES DEFINITIONS - -;;XXX Change to African species? -;;TODO bird species - -(new-species 'deer - :name "deer" +(new-species deer :strength 3 :max-health 10 :aggression 0 :group-size 10 :habitat '(forest grassland) :drops NIL) ;TODO -(new-species 'boar - :name "boar" +(new-species boar :strength 7 :max-health 15 :aggression 5 :group-size 5 :habitat '(forest) :drops NIL) ;TODO -(new-species 'wolf - :name "wolf" +(new-species wolf :strength 10 :max-health 20 :aggression 20 :group-size 6 :habitat '(grassland) :drops NIL) ;TODO -(new-species 'bear - :name "bear" +(new-species bear :strength 20 :max-health 30 :aggression 20 :group-size 1 :habitat '(forest) diff --git a/animals.lisp b/animals.lisp index 09ac297..3f5634c 100644 --- a/animals.lisp +++ b/animals.lisp @@ -8,58 +8,28 @@ ;;;; (c) 2018 Daniel Vedder, MIT license ;;;; +;;TODO Change to African species +;;XXX bird species? -(defvar *animals* NIL) - -(let ((species-list NIL)) - (defun register-species (symbol-name species-object) - (setf species-list - (cons (list symbol-name species-object) species-list))) - - (defun get-species (symbol-name) - (cassoc symbol-name species-list))) - -(defmacro new-species (name &body body) - `(register-species ,name - (make-instance 'species ,@body))) - -(let ((max-id 0)) - (defun add-animal (species position) - "Create a new animal of the given species" - (let ((a (make-animal :id max-id - :pos position :species species - :health (.max-health species)))) - (incf max-id) - (setf *animals* (append *animals* a))))) - -;;; SPECIES DEFINITIONS - -;;XXX Change to African species? -;;TODO bird species - -(new-species 'deer - :name "deer" +(new-species deer :strength 3 :max-health 10 :aggression 0 :group-size 10 :habitat '(forest grassland) :drops NIL) ;TODO -(new-species 'boar - :name "boar" +(new-species boar :strength 7 :max-health 15 :aggression 5 :group-size 5 :habitat '(forest) :drops NIL) ;TODO -(new-species 'wolf - :name "wolf" +(new-species wolf :strength 10 :max-health 20 :aggression 20 :group-size 6 :habitat '(grassland) :drops NIL) ;TODO -(new-species 'bear - :name "bear" +(new-species bear :strength 20 :max-health 30 :aggression 20 :group-size 1 :habitat '(forest) diff --git a/biomes.lisp b/biomes.lisp index a723d8d..88d76c0 100644 --- a/biomes.lisp +++ b/biomes.lisp @@ -3,39 +3,11 @@ ;;;; set in Africa. ;;;; ;;;; Biomes are habitat types, that provide default functions for patches. -;;;; This file defines the biome struct and the inbuilt biomes. +;;;; This file holds the biome definitions. ;;;; ;;;; (c) 2018 Daniel Vedder, MIT license ;;;; -;; Biome struct and register - -(defstruct biome - (name "") - (ground "") - (features '()) ;an alist of possible features and their 1/p probabilities - (char #\.) ;default map display character - (col ':white)) ;default map display colour - -(let ((biome-list NIL)) - (defun register-biome (symbol-name biome-object) - (setf biome-list (cons (list symbol-name biome-object) biome-list))) - - (defun available-biomes () - (keys biome-list)) - - (defun get-biome (symbol-name) - (cassoc symbol-name biome-list))) - -(defmacro new-biome (name &body body) - `(register-biome ',name - (make-biome - :name ,(symbol-to-string name) - ,@body))) - - -;; Biome definitions - (new-biome grassland :ground "tall elephant grass" :char #\; :col ':yellow diff --git a/animals.lisp b/animals.lisp index 09ac297..3f5634c 100644 --- a/animals.lisp +++ b/animals.lisp @@ -8,58 +8,28 @@ ;;;; (c) 2018 Daniel Vedder, MIT license ;;;; +;;TODO Change to African species +;;XXX bird species? -(defvar *animals* NIL) - -(let ((species-list NIL)) - (defun register-species (symbol-name species-object) - (setf species-list - (cons (list symbol-name species-object) species-list))) - - (defun get-species (symbol-name) - (cassoc symbol-name species-list))) - -(defmacro new-species (name &body body) - `(register-species ,name - (make-instance 'species ,@body))) - -(let ((max-id 0)) - (defun add-animal (species position) - "Create a new animal of the given species" - (let ((a (make-animal :id max-id - :pos position :species species - :health (.max-health species)))) - (incf max-id) - (setf *animals* (append *animals* a))))) - -;;; SPECIES DEFINITIONS - -;;XXX Change to African species? -;;TODO bird species - -(new-species 'deer - :name "deer" +(new-species deer :strength 3 :max-health 10 :aggression 0 :group-size 10 :habitat '(forest grassland) :drops NIL) ;TODO -(new-species 'boar - :name "boar" +(new-species boar :strength 7 :max-health 15 :aggression 5 :group-size 5 :habitat '(forest) :drops NIL) ;TODO -(new-species 'wolf - :name "wolf" +(new-species wolf :strength 10 :max-health 20 :aggression 20 :group-size 6 :habitat '(grassland) :drops NIL) ;TODO -(new-species 'bear - :name "bear" +(new-species bear :strength 20 :max-health 30 :aggression 20 :group-size 1 :habitat '(forest) diff --git a/biomes.lisp b/biomes.lisp index a723d8d..88d76c0 100644 --- a/biomes.lisp +++ b/biomes.lisp @@ -3,39 +3,11 @@ ;;;; set in Africa. ;;;; ;;;; Biomes are habitat types, that provide default functions for patches. -;;;; This file defines the biome struct and the inbuilt biomes. +;;;; This file holds the biome definitions. ;;;; ;;;; (c) 2018 Daniel Vedder, MIT license ;;;; -;; Biome struct and register - -(defstruct biome - (name "") - (ground "") - (features '()) ;an alist of possible features and their 1/p probabilities - (char #\.) ;default map display character - (col ':white)) ;default map display colour - -(let ((biome-list NIL)) - (defun register-biome (symbol-name biome-object) - (setf biome-list (cons (list symbol-name biome-object) biome-list))) - - (defun available-biomes () - (keys biome-list)) - - (defun get-biome (symbol-name) - (cassoc symbol-name biome-list))) - -(defmacro new-biome (name &body body) - `(register-biome ',name - (make-biome - :name ,(symbol-to-string name) - ,@body))) - - -;; Biome definitions - (new-biome grassland :ground "tall elephant grass" :char #\; :col ':yellow diff --git a/classes.lisp b/classes.lisp index d559409..d30eb90 100644 --- a/classes.lisp +++ b/classes.lisp @@ -7,6 +7,7 @@ ;;;; (c) 2018 Daniel Vedder, MIT license ;;;; + (defclass item () ;; The base class of all game items. ((name :accessor .name :initarg :name :initform "") diff --git a/animals.lisp b/animals.lisp index 09ac297..3f5634c 100644 --- a/animals.lisp +++ b/animals.lisp @@ -8,58 +8,28 @@ ;;;; (c) 2018 Daniel Vedder, MIT license ;;;; +;;TODO Change to African species +;;XXX bird species? -(defvar *animals* NIL) - -(let ((species-list NIL)) - (defun register-species (symbol-name species-object) - (setf species-list - (cons (list symbol-name species-object) species-list))) - - (defun get-species (symbol-name) - (cassoc symbol-name species-list))) - -(defmacro new-species (name &body body) - `(register-species ,name - (make-instance 'species ,@body))) - -(let ((max-id 0)) - (defun add-animal (species position) - "Create a new animal of the given species" - (let ((a (make-animal :id max-id - :pos position :species species - :health (.max-health species)))) - (incf max-id) - (setf *animals* (append *animals* a))))) - -;;; SPECIES DEFINITIONS - -;;XXX Change to African species? -;;TODO bird species - -(new-species 'deer - :name "deer" +(new-species deer :strength 3 :max-health 10 :aggression 0 :group-size 10 :habitat '(forest grassland) :drops NIL) ;TODO -(new-species 'boar - :name "boar" +(new-species boar :strength 7 :max-health 15 :aggression 5 :group-size 5 :habitat '(forest) :drops NIL) ;TODO -(new-species 'wolf - :name "wolf" +(new-species wolf :strength 10 :max-health 20 :aggression 20 :group-size 6 :habitat '(grassland) :drops NIL) ;TODO -(new-species 'bear - :name "bear" +(new-species bear :strength 20 :max-health 30 :aggression 20 :group-size 1 :habitat '(forest) diff --git a/biomes.lisp b/biomes.lisp index a723d8d..88d76c0 100644 --- a/biomes.lisp +++ b/biomes.lisp @@ -3,39 +3,11 @@ ;;;; set in Africa. ;;;; ;;;; Biomes are habitat types, that provide default functions for patches. -;;;; This file defines the biome struct and the inbuilt biomes. +;;;; This file holds the biome definitions. ;;;; ;;;; (c) 2018 Daniel Vedder, MIT license ;;;; -;; Biome struct and register - -(defstruct biome - (name "") - (ground "") - (features '()) ;an alist of possible features and their 1/p probabilities - (char #\.) ;default map display character - (col ':white)) ;default map display colour - -(let ((biome-list NIL)) - (defun register-biome (symbol-name biome-object) - (setf biome-list (cons (list symbol-name biome-object) biome-list))) - - (defun available-biomes () - (keys biome-list)) - - (defun get-biome (symbol-name) - (cassoc symbol-name biome-list))) - -(defmacro new-biome (name &body body) - `(register-biome ',name - (make-biome - :name ,(symbol-to-string name) - ,@body))) - - -;; Biome definitions - (new-biome grassland :ground "tall elephant grass" :char #\; :col ':yellow diff --git a/classes.lisp b/classes.lisp index d559409..d30eb90 100644 --- a/classes.lisp +++ b/classes.lisp @@ -7,6 +7,7 @@ ;;;; (c) 2018 Daniel Vedder, MIT license ;;;; + (defclass item () ;; The base class of all game items. ((name :accessor .name :initarg :name :initform "") diff --git a/data.lisp b/data.lisp new file mode 100644 index 0000000..23d9e39 --- /dev/null +++ b/data.lisp @@ -0,0 +1,107 @@ +;;;; +;;;; Naledi ya Africa ("Star of Africa") is a rogue-like survival game +;;;; set in Africa. +;;;; +;;;; This file stores all game data. +;;;; +;;;; (c) 2018 Daniel Vedder, MIT license +;;;; + +;;; PATCHES + +(let ((world NIL)) + (defun set-world (w) (setf world w)) + + (defun world-size () (length world)) + + (defun save-topography (file-name) ;XXX (re)move this? + "Save the world topography as a text file" + (debugging "~&Saving world to file ~A" file-name) ;debug + (with-open-file (tf file-name :direction :output) + (dolist (row world) + (format stream "~&~A~%" + (string-from-list + (mapcar #'(lambda (p) + (biome-char (patch-biome p))) + row) ""))))) + + (defun coord (x y) + "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))))) + +;;; BIOMES + +(let ((biome-list NIL)) + (defun register-biome (symbol-name biome-object) + (setf biome-list (cons (list symbol-name biome-object) biome-list))) + + (defun available-biomes () + (keys biome-list)) + + (defun get-biome (symbol-name) + (cassoc symbol-name biome-list))) + +(defmacro new-biome (name &body body) + `(register-biome ',name + (make-biome + :name ,(symbol-to-string name) + ,@body))) + +;;; ITEMS + +(let ((item-list NIL)) + (defun register-item (symbol-name item-object) + (setf item-list + (cons (list symbol-name item-object) item-list))) + + (defun get-item-type (symbol-name) + (cassoc symbol-name item-list)) + + (defun get-item (symbol-name) + ;;FIXME copy-item doesn't work with CLOS + (copy-item (get-item-type symbol-name)))) + +(defmacro new-item (type name &body body) + `(register-item ',name + (make-instance ',type + :name ,(symbol-to-string name) + ,@body))) + +;;; ANIMALS & SPECIES + +(let ((species-list NIL)) + (defun register-species (symbol-name species-object) + (setf species-list + (cons (list symbol-name species-object) species-list))) + + (defun get-species (symbol-name) + (cassoc symbol-name species-list))) + +(defmacro new-species (name &body body) + `(register-species ',name + (make-instance 'species + :name ,(symbol-to-string name) + ,@body))) + +(let ((max-id 0) (animals NIL)) + (defun add-animal (species position) + "Create a new animal of the given species" + (let ((a (make-animal :id max-id + :pos position :species species + :health (.max-health species)))) + (incf max-id) + (setf animals (append animals a)))) + + (defun get-animal (id) + "Return the animal with this ID number" + (dolist (a animals) + (when (= (.id a) id) + (return-from get-animal a)))) + + (defun remove-animal (id) + "Remove the animal with this ID from the game" + (do ((al animals (cdr al))) + ((null al)) + (when (= (.id (car al)) id) + (setf (cdr al) (cddr al)))))) diff --git a/animals.lisp b/animals.lisp index 09ac297..3f5634c 100644 --- a/animals.lisp +++ b/animals.lisp @@ -8,58 +8,28 @@ ;;;; (c) 2018 Daniel Vedder, MIT license ;;;; +;;TODO Change to African species +;;XXX bird species? -(defvar *animals* NIL) - -(let ((species-list NIL)) - (defun register-species (symbol-name species-object) - (setf species-list - (cons (list symbol-name species-object) species-list))) - - (defun get-species (symbol-name) - (cassoc symbol-name species-list))) - -(defmacro new-species (name &body body) - `(register-species ,name - (make-instance 'species ,@body))) - -(let ((max-id 0)) - (defun add-animal (species position) - "Create a new animal of the given species" - (let ((a (make-animal :id max-id - :pos position :species species - :health (.max-health species)))) - (incf max-id) - (setf *animals* (append *animals* a))))) - -;;; SPECIES DEFINITIONS - -;;XXX Change to African species? -;;TODO bird species - -(new-species 'deer - :name "deer" +(new-species deer :strength 3 :max-health 10 :aggression 0 :group-size 10 :habitat '(forest grassland) :drops NIL) ;TODO -(new-species 'boar - :name "boar" +(new-species boar :strength 7 :max-health 15 :aggression 5 :group-size 5 :habitat '(forest) :drops NIL) ;TODO -(new-species 'wolf - :name "wolf" +(new-species wolf :strength 10 :max-health 20 :aggression 20 :group-size 6 :habitat '(grassland) :drops NIL) ;TODO -(new-species 'bear - :name "bear" +(new-species bear :strength 20 :max-health 30 :aggression 20 :group-size 1 :habitat '(forest) diff --git a/biomes.lisp b/biomes.lisp index a723d8d..88d76c0 100644 --- a/biomes.lisp +++ b/biomes.lisp @@ -3,39 +3,11 @@ ;;;; set in Africa. ;;;; ;;;; Biomes are habitat types, that provide default functions for patches. -;;;; This file defines the biome struct and the inbuilt biomes. +;;;; This file holds the biome definitions. ;;;; ;;;; (c) 2018 Daniel Vedder, MIT license ;;;; -;; Biome struct and register - -(defstruct biome - (name "") - (ground "") - (features '()) ;an alist of possible features and their 1/p probabilities - (char #\.) ;default map display character - (col ':white)) ;default map display colour - -(let ((biome-list NIL)) - (defun register-biome (symbol-name biome-object) - (setf biome-list (cons (list symbol-name biome-object) biome-list))) - - (defun available-biomes () - (keys biome-list)) - - (defun get-biome (symbol-name) - (cassoc symbol-name biome-list))) - -(defmacro new-biome (name &body body) - `(register-biome ',name - (make-biome - :name ,(symbol-to-string name) - ,@body))) - - -;; Biome definitions - (new-biome grassland :ground "tall elephant grass" :char #\; :col ':yellow diff --git a/classes.lisp b/classes.lisp index d559409..d30eb90 100644 --- a/classes.lisp +++ b/classes.lisp @@ -7,6 +7,7 @@ ;;;; (c) 2018 Daniel Vedder, MIT license ;;;; + (defclass item () ;; The base class of all game items. ((name :accessor .name :initarg :name :initform "") diff --git a/data.lisp b/data.lisp new file mode 100644 index 0000000..23d9e39 --- /dev/null +++ b/data.lisp @@ -0,0 +1,107 @@ +;;;; +;;;; Naledi ya Africa ("Star of Africa") is a rogue-like survival game +;;;; set in Africa. +;;;; +;;;; This file stores all game data. +;;;; +;;;; (c) 2018 Daniel Vedder, MIT license +;;;; + +;;; PATCHES + +(let ((world NIL)) + (defun set-world (w) (setf world w)) + + (defun world-size () (length world)) + + (defun save-topography (file-name) ;XXX (re)move this? + "Save the world topography as a text file" + (debugging "~&Saving world to file ~A" file-name) ;debug + (with-open-file (tf file-name :direction :output) + (dolist (row world) + (format stream "~&~A~%" + (string-from-list + (mapcar #'(lambda (p) + (biome-char (patch-biome p))) + row) ""))))) + + (defun coord (x y) + "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))))) + +;;; BIOMES + +(let ((biome-list NIL)) + (defun register-biome (symbol-name biome-object) + (setf biome-list (cons (list symbol-name biome-object) biome-list))) + + (defun available-biomes () + (keys biome-list)) + + (defun get-biome (symbol-name) + (cassoc symbol-name biome-list))) + +(defmacro new-biome (name &body body) + `(register-biome ',name + (make-biome + :name ,(symbol-to-string name) + ,@body))) + +;;; ITEMS + +(let ((item-list NIL)) + (defun register-item (symbol-name item-object) + (setf item-list + (cons (list symbol-name item-object) item-list))) + + (defun get-item-type (symbol-name) + (cassoc symbol-name item-list)) + + (defun get-item (symbol-name) + ;;FIXME copy-item doesn't work with CLOS + (copy-item (get-item-type symbol-name)))) + +(defmacro new-item (type name &body body) + `(register-item ',name + (make-instance ',type + :name ,(symbol-to-string name) + ,@body))) + +;;; ANIMALS & SPECIES + +(let ((species-list NIL)) + (defun register-species (symbol-name species-object) + (setf species-list + (cons (list symbol-name species-object) species-list))) + + (defun get-species (symbol-name) + (cassoc symbol-name species-list))) + +(defmacro new-species (name &body body) + `(register-species ',name + (make-instance 'species + :name ,(symbol-to-string name) + ,@body))) + +(let ((max-id 0) (animals NIL)) + (defun add-animal (species position) + "Create a new animal of the given species" + (let ((a (make-animal :id max-id + :pos position :species species + :health (.max-health species)))) + (incf max-id) + (setf animals (append animals a)))) + + (defun get-animal (id) + "Return the animal with this ID number" + (dolist (a animals) + (when (= (.id a) id) + (return-from get-animal a)))) + + (defun remove-animal (id) + "Remove the animal with this ID from the game" + (do ((al animals (cdr al))) + ((null al)) + (when (= (.id (car al)) id) + (setf (cdr al) (cddr al)))))) diff --git a/items.lisp b/items.lisp index 70e8acb..6957112 100644 --- a/items.lisp +++ b/items.lisp @@ -7,24 +7,6 @@ ;;;; (c) 2018 Daniel Vedder, MIT license ;;;; -(let ((item-list NIL)) - (defun register-item (symbol-name item-object) - (setf item-list - (cons (list symbol-name item-object) item-list))) - - (defun get-item-type (symbol-name) - (cassoc symbol-name item-list)) - - (defun get-item (symbol-name) - ;;FIXME copy-item doesn't work with CLOS - (copy-item (get-item-type symbol-name)))) - -(defmacro new-item (type name &body body) - `(register-item ',name - (make-instance ',type - :name ,(symbol-to-string name) - ,@body))) - ;;; RESOURCE ITEMS diff --git a/animals.lisp b/animals.lisp index 09ac297..3f5634c 100644 --- a/animals.lisp +++ b/animals.lisp @@ -8,58 +8,28 @@ ;;;; (c) 2018 Daniel Vedder, MIT license ;;;; +;;TODO Change to African species +;;XXX bird species? -(defvar *animals* NIL) - -(let ((species-list NIL)) - (defun register-species (symbol-name species-object) - (setf species-list - (cons (list symbol-name species-object) species-list))) - - (defun get-species (symbol-name) - (cassoc symbol-name species-list))) - -(defmacro new-species (name &body body) - `(register-species ,name - (make-instance 'species ,@body))) - -(let ((max-id 0)) - (defun add-animal (species position) - "Create a new animal of the given species" - (let ((a (make-animal :id max-id - :pos position :species species - :health (.max-health species)))) - (incf max-id) - (setf *animals* (append *animals* a))))) - -;;; SPECIES DEFINITIONS - -;;XXX Change to African species? -;;TODO bird species - -(new-species 'deer - :name "deer" +(new-species deer :strength 3 :max-health 10 :aggression 0 :group-size 10 :habitat '(forest grassland) :drops NIL) ;TODO -(new-species 'boar - :name "boar" +(new-species boar :strength 7 :max-health 15 :aggression 5 :group-size 5 :habitat '(forest) :drops NIL) ;TODO -(new-species 'wolf - :name "wolf" +(new-species wolf :strength 10 :max-health 20 :aggression 20 :group-size 6 :habitat '(grassland) :drops NIL) ;TODO -(new-species 'bear - :name "bear" +(new-species bear :strength 20 :max-health 30 :aggression 20 :group-size 1 :habitat '(forest) diff --git a/biomes.lisp b/biomes.lisp index a723d8d..88d76c0 100644 --- a/biomes.lisp +++ b/biomes.lisp @@ -3,39 +3,11 @@ ;;;; set in Africa. ;;;; ;;;; Biomes are habitat types, that provide default functions for patches. -;;;; This file defines the biome struct and the inbuilt biomes. +;;;; This file holds the biome definitions. ;;;; ;;;; (c) 2018 Daniel Vedder, MIT license ;;;; -;; Biome struct and register - -(defstruct biome - (name "") - (ground "") - (features '()) ;an alist of possible features and their 1/p probabilities - (char #\.) ;default map display character - (col ':white)) ;default map display colour - -(let ((biome-list NIL)) - (defun register-biome (symbol-name biome-object) - (setf biome-list (cons (list symbol-name biome-object) biome-list))) - - (defun available-biomes () - (keys biome-list)) - - (defun get-biome (symbol-name) - (cassoc symbol-name biome-list))) - -(defmacro new-biome (name &body body) - `(register-biome ',name - (make-biome - :name ,(symbol-to-string name) - ,@body))) - - -;; Biome definitions - (new-biome grassland :ground "tall elephant grass" :char #\; :col ':yellow diff --git a/classes.lisp b/classes.lisp index d559409..d30eb90 100644 --- a/classes.lisp +++ b/classes.lisp @@ -7,6 +7,7 @@ ;;;; (c) 2018 Daniel Vedder, MIT license ;;;; + (defclass item () ;; The base class of all game items. ((name :accessor .name :initarg :name :initform "") diff --git a/data.lisp b/data.lisp new file mode 100644 index 0000000..23d9e39 --- /dev/null +++ b/data.lisp @@ -0,0 +1,107 @@ +;;;; +;;;; Naledi ya Africa ("Star of Africa") is a rogue-like survival game +;;;; set in Africa. +;;;; +;;;; This file stores all game data. +;;;; +;;;; (c) 2018 Daniel Vedder, MIT license +;;;; + +;;; PATCHES + +(let ((world NIL)) + (defun set-world (w) (setf world w)) + + (defun world-size () (length world)) + + (defun save-topography (file-name) ;XXX (re)move this? + "Save the world topography as a text file" + (debugging "~&Saving world to file ~A" file-name) ;debug + (with-open-file (tf file-name :direction :output) + (dolist (row world) + (format stream "~&~A~%" + (string-from-list + (mapcar #'(lambda (p) + (biome-char (patch-biome p))) + row) ""))))) + + (defun coord (x y) + "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))))) + +;;; BIOMES + +(let ((biome-list NIL)) + (defun register-biome (symbol-name biome-object) + (setf biome-list (cons (list symbol-name biome-object) biome-list))) + + (defun available-biomes () + (keys biome-list)) + + (defun get-biome (symbol-name) + (cassoc symbol-name biome-list))) + +(defmacro new-biome (name &body body) + `(register-biome ',name + (make-biome + :name ,(symbol-to-string name) + ,@body))) + +;;; ITEMS + +(let ((item-list NIL)) + (defun register-item (symbol-name item-object) + (setf item-list + (cons (list symbol-name item-object) item-list))) + + (defun get-item-type (symbol-name) + (cassoc symbol-name item-list)) + + (defun get-item (symbol-name) + ;;FIXME copy-item doesn't work with CLOS + (copy-item (get-item-type symbol-name)))) + +(defmacro new-item (type name &body body) + `(register-item ',name + (make-instance ',type + :name ,(symbol-to-string name) + ,@body))) + +;;; ANIMALS & SPECIES + +(let ((species-list NIL)) + (defun register-species (symbol-name species-object) + (setf species-list + (cons (list symbol-name species-object) species-list))) + + (defun get-species (symbol-name) + (cassoc symbol-name species-list))) + +(defmacro new-species (name &body body) + `(register-species ',name + (make-instance 'species + :name ,(symbol-to-string name) + ,@body))) + +(let ((max-id 0) (animals NIL)) + (defun add-animal (species position) + "Create a new animal of the given species" + (let ((a (make-animal :id max-id + :pos position :species species + :health (.max-health species)))) + (incf max-id) + (setf animals (append animals a)))) + + (defun get-animal (id) + "Return the animal with this ID number" + (dolist (a animals) + (when (= (.id a) id) + (return-from get-animal a)))) + + (defun remove-animal (id) + "Remove the animal with this ID from the game" + (do ((al animals (cdr al))) + ((null al)) + (when (= (.id (car al)) id) + (setf (cdr al) (cddr al)))))) diff --git a/items.lisp b/items.lisp index 70e8acb..6957112 100644 --- a/items.lisp +++ b/items.lisp @@ -7,24 +7,6 @@ ;;;; (c) 2018 Daniel Vedder, MIT license ;;;; -(let ((item-list NIL)) - (defun register-item (symbol-name item-object) - (setf item-list - (cons (list symbol-name item-object) item-list))) - - (defun get-item-type (symbol-name) - (cassoc symbol-name item-list)) - - (defun get-item (symbol-name) - ;;FIXME copy-item doesn't work with CLOS - (copy-item (get-item-type symbol-name)))) - -(defmacro new-item (type name &body body) - `(register-item ',name - (make-instance ',type - :name ,(symbol-to-string name) - ,@body))) - ;;; RESOURCE ITEMS diff --git a/naledi.lisp b/naledi.lisp index f7319f2..81b2d0a 100644 --- a/naledi.lisp +++ b/naledi.lisp @@ -15,10 +15,11 @@ (load "util.lisp") (load "classes.lisp") +(load "data.lisp") +(load "world.lisp") (load "items.lisp") (load "biomes.lisp") (load "animals.lisp") -(load "world.lisp") (defun user-interface () @@ -105,6 +106,7 @@ (defun draw-place-panel (win me) "Draw a panel with information about the player's current location." + (debugging "~&~S" me) (let* ((p (coord (first me) (second me))) (descr (describe-patch p))) (clear win) (box win) @@ -153,5 +155,5 @@ ;; Initialize the random state (which would otherwise not be very random...) (setf *random-state* (make-random-state t)) -(setf *world* (create-world 500)) +(create-world 100) (user-interface) diff --git a/animals.lisp b/animals.lisp index 09ac297..3f5634c 100644 --- a/animals.lisp +++ b/animals.lisp @@ -8,58 +8,28 @@ ;;;; (c) 2018 Daniel Vedder, MIT license ;;;; +;;TODO Change to African species +;;XXX bird species? -(defvar *animals* NIL) - -(let ((species-list NIL)) - (defun register-species (symbol-name species-object) - (setf species-list - (cons (list symbol-name species-object) species-list))) - - (defun get-species (symbol-name) - (cassoc symbol-name species-list))) - -(defmacro new-species (name &body body) - `(register-species ,name - (make-instance 'species ,@body))) - -(let ((max-id 0)) - (defun add-animal (species position) - "Create a new animal of the given species" - (let ((a (make-animal :id max-id - :pos position :species species - :health (.max-health species)))) - (incf max-id) - (setf *animals* (append *animals* a))))) - -;;; SPECIES DEFINITIONS - -;;XXX Change to African species? -;;TODO bird species - -(new-species 'deer - :name "deer" +(new-species deer :strength 3 :max-health 10 :aggression 0 :group-size 10 :habitat '(forest grassland) :drops NIL) ;TODO -(new-species 'boar - :name "boar" +(new-species boar :strength 7 :max-health 15 :aggression 5 :group-size 5 :habitat '(forest) :drops NIL) ;TODO -(new-species 'wolf - :name "wolf" +(new-species wolf :strength 10 :max-health 20 :aggression 20 :group-size 6 :habitat '(grassland) :drops NIL) ;TODO -(new-species 'bear - :name "bear" +(new-species bear :strength 20 :max-health 30 :aggression 20 :group-size 1 :habitat '(forest) diff --git a/biomes.lisp b/biomes.lisp index a723d8d..88d76c0 100644 --- a/biomes.lisp +++ b/biomes.lisp @@ -3,39 +3,11 @@ ;;;; set in Africa. ;;;; ;;;; Biomes are habitat types, that provide default functions for patches. -;;;; This file defines the biome struct and the inbuilt biomes. +;;;; This file holds the biome definitions. ;;;; ;;;; (c) 2018 Daniel Vedder, MIT license ;;;; -;; Biome struct and register - -(defstruct biome - (name "") - (ground "") - (features '()) ;an alist of possible features and their 1/p probabilities - (char #\.) ;default map display character - (col ':white)) ;default map display colour - -(let ((biome-list NIL)) - (defun register-biome (symbol-name biome-object) - (setf biome-list (cons (list symbol-name biome-object) biome-list))) - - (defun available-biomes () - (keys biome-list)) - - (defun get-biome (symbol-name) - (cassoc symbol-name biome-list))) - -(defmacro new-biome (name &body body) - `(register-biome ',name - (make-biome - :name ,(symbol-to-string name) - ,@body))) - - -;; Biome definitions - (new-biome grassland :ground "tall elephant grass" :char #\; :col ':yellow diff --git a/classes.lisp b/classes.lisp index d559409..d30eb90 100644 --- a/classes.lisp +++ b/classes.lisp @@ -7,6 +7,7 @@ ;;;; (c) 2018 Daniel Vedder, MIT license ;;;; + (defclass item () ;; The base class of all game items. ((name :accessor .name :initarg :name :initform "") diff --git a/data.lisp b/data.lisp new file mode 100644 index 0000000..23d9e39 --- /dev/null +++ b/data.lisp @@ -0,0 +1,107 @@ +;;;; +;;;; Naledi ya Africa ("Star of Africa") is a rogue-like survival game +;;;; set in Africa. +;;;; +;;;; This file stores all game data. +;;;; +;;;; (c) 2018 Daniel Vedder, MIT license +;;;; + +;;; PATCHES + +(let ((world NIL)) + (defun set-world (w) (setf world w)) + + (defun world-size () (length world)) + + (defun save-topography (file-name) ;XXX (re)move this? + "Save the world topography as a text file" + (debugging "~&Saving world to file ~A" file-name) ;debug + (with-open-file (tf file-name :direction :output) + (dolist (row world) + (format stream "~&~A~%" + (string-from-list + (mapcar #'(lambda (p) + (biome-char (patch-biome p))) + row) ""))))) + + (defun coord (x y) + "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))))) + +;;; BIOMES + +(let ((biome-list NIL)) + (defun register-biome (symbol-name biome-object) + (setf biome-list (cons (list symbol-name biome-object) biome-list))) + + (defun available-biomes () + (keys biome-list)) + + (defun get-biome (symbol-name) + (cassoc symbol-name biome-list))) + +(defmacro new-biome (name &body body) + `(register-biome ',name + (make-biome + :name ,(symbol-to-string name) + ,@body))) + +;;; ITEMS + +(let ((item-list NIL)) + (defun register-item (symbol-name item-object) + (setf item-list + (cons (list symbol-name item-object) item-list))) + + (defun get-item-type (symbol-name) + (cassoc symbol-name item-list)) + + (defun get-item (symbol-name) + ;;FIXME copy-item doesn't work with CLOS + (copy-item (get-item-type symbol-name)))) + +(defmacro new-item (type name &body body) + `(register-item ',name + (make-instance ',type + :name ,(symbol-to-string name) + ,@body))) + +;;; ANIMALS & SPECIES + +(let ((species-list NIL)) + (defun register-species (symbol-name species-object) + (setf species-list + (cons (list symbol-name species-object) species-list))) + + (defun get-species (symbol-name) + (cassoc symbol-name species-list))) + +(defmacro new-species (name &body body) + `(register-species ',name + (make-instance 'species + :name ,(symbol-to-string name) + ,@body))) + +(let ((max-id 0) (animals NIL)) + (defun add-animal (species position) + "Create a new animal of the given species" + (let ((a (make-animal :id max-id + :pos position :species species + :health (.max-health species)))) + (incf max-id) + (setf animals (append animals a)))) + + (defun get-animal (id) + "Return the animal with this ID number" + (dolist (a animals) + (when (= (.id a) id) + (return-from get-animal a)))) + + (defun remove-animal (id) + "Remove the animal with this ID from the game" + (do ((al animals (cdr al))) + ((null al)) + (when (= (.id (car al)) id) + (setf (cdr al) (cddr al)))))) diff --git a/items.lisp b/items.lisp index 70e8acb..6957112 100644 --- a/items.lisp +++ b/items.lisp @@ -7,24 +7,6 @@ ;;;; (c) 2018 Daniel Vedder, MIT license ;;;; -(let ((item-list NIL)) - (defun register-item (symbol-name item-object) - (setf item-list - (cons (list symbol-name item-object) item-list))) - - (defun get-item-type (symbol-name) - (cassoc symbol-name item-list)) - - (defun get-item (symbol-name) - ;;FIXME copy-item doesn't work with CLOS - (copy-item (get-item-type symbol-name)))) - -(defmacro new-item (type name &body body) - `(register-item ',name - (make-instance ',type - :name ,(symbol-to-string name) - ,@body))) - ;;; RESOURCE ITEMS diff --git a/naledi.lisp b/naledi.lisp index f7319f2..81b2d0a 100644 --- a/naledi.lisp +++ b/naledi.lisp @@ -15,10 +15,11 @@ (load "util.lisp") (load "classes.lisp") +(load "data.lisp") +(load "world.lisp") (load "items.lisp") (load "biomes.lisp") (load "animals.lisp") -(load "world.lisp") (defun user-interface () @@ -105,6 +106,7 @@ (defun draw-place-panel (win me) "Draw a panel with information about the player's current location." + (debugging "~&~S" me) (let* ((p (coord (first me) (second me))) (descr (describe-patch p))) (clear win) (box win) @@ -153,5 +155,5 @@ ;; Initialize the random state (which would otherwise not be very random...) (setf *random-state* (make-random-state t)) -(setf *world* (create-world 500)) +(create-world 100) (user-interface) diff --git a/util.lisp b/util.lisp index c50e0ce..d6d034c 100644 --- a/util.lisp +++ b/util.lisp @@ -96,6 +96,10 @@ (if (null assoc-list) NIL (cons (car (car assoc-list)) (keys (cdr assoc-list))))) +(defun build-symbol (&rest components) + "Concatenate the passed components into a single symbol" + (read-from-string (string-from-list components :sep ""))) + (defun symbol-to-string (sym) "Convert a symbol to a string, exchanging dashes for spaces" (string-from-list diff --git a/animals.lisp b/animals.lisp index 09ac297..3f5634c 100644 --- a/animals.lisp +++ b/animals.lisp @@ -8,58 +8,28 @@ ;;;; (c) 2018 Daniel Vedder, MIT license ;;;; +;;TODO Change to African species +;;XXX bird species? -(defvar *animals* NIL) - -(let ((species-list NIL)) - (defun register-species (symbol-name species-object) - (setf species-list - (cons (list symbol-name species-object) species-list))) - - (defun get-species (symbol-name) - (cassoc symbol-name species-list))) - -(defmacro new-species (name &body body) - `(register-species ,name - (make-instance 'species ,@body))) - -(let ((max-id 0)) - (defun add-animal (species position) - "Create a new animal of the given species" - (let ((a (make-animal :id max-id - :pos position :species species - :health (.max-health species)))) - (incf max-id) - (setf *animals* (append *animals* a))))) - -;;; SPECIES DEFINITIONS - -;;XXX Change to African species? -;;TODO bird species - -(new-species 'deer - :name "deer" +(new-species deer :strength 3 :max-health 10 :aggression 0 :group-size 10 :habitat '(forest grassland) :drops NIL) ;TODO -(new-species 'boar - :name "boar" +(new-species boar :strength 7 :max-health 15 :aggression 5 :group-size 5 :habitat '(forest) :drops NIL) ;TODO -(new-species 'wolf - :name "wolf" +(new-species wolf :strength 10 :max-health 20 :aggression 20 :group-size 6 :habitat '(grassland) :drops NIL) ;TODO -(new-species 'bear - :name "bear" +(new-species bear :strength 20 :max-health 30 :aggression 20 :group-size 1 :habitat '(forest) diff --git a/biomes.lisp b/biomes.lisp index a723d8d..88d76c0 100644 --- a/biomes.lisp +++ b/biomes.lisp @@ -3,39 +3,11 @@ ;;;; set in Africa. ;;;; ;;;; Biomes are habitat types, that provide default functions for patches. -;;;; This file defines the biome struct and the inbuilt biomes. +;;;; This file holds the biome definitions. ;;;; ;;;; (c) 2018 Daniel Vedder, MIT license ;;;; -;; Biome struct and register - -(defstruct biome - (name "") - (ground "") - (features '()) ;an alist of possible features and their 1/p probabilities - (char #\.) ;default map display character - (col ':white)) ;default map display colour - -(let ((biome-list NIL)) - (defun register-biome (symbol-name biome-object) - (setf biome-list (cons (list symbol-name biome-object) biome-list))) - - (defun available-biomes () - (keys biome-list)) - - (defun get-biome (symbol-name) - (cassoc symbol-name biome-list))) - -(defmacro new-biome (name &body body) - `(register-biome ',name - (make-biome - :name ,(symbol-to-string name) - ,@body))) - - -;; Biome definitions - (new-biome grassland :ground "tall elephant grass" :char #\; :col ':yellow diff --git a/classes.lisp b/classes.lisp index d559409..d30eb90 100644 --- a/classes.lisp +++ b/classes.lisp @@ -7,6 +7,7 @@ ;;;; (c) 2018 Daniel Vedder, MIT license ;;;; + (defclass item () ;; The base class of all game items. ((name :accessor .name :initarg :name :initform "") diff --git a/data.lisp b/data.lisp new file mode 100644 index 0000000..23d9e39 --- /dev/null +++ b/data.lisp @@ -0,0 +1,107 @@ +;;;; +;;;; Naledi ya Africa ("Star of Africa") is a rogue-like survival game +;;;; set in Africa. +;;;; +;;;; This file stores all game data. +;;;; +;;;; (c) 2018 Daniel Vedder, MIT license +;;;; + +;;; PATCHES + +(let ((world NIL)) + (defun set-world (w) (setf world w)) + + (defun world-size () (length world)) + + (defun save-topography (file-name) ;XXX (re)move this? + "Save the world topography as a text file" + (debugging "~&Saving world to file ~A" file-name) ;debug + (with-open-file (tf file-name :direction :output) + (dolist (row world) + (format stream "~&~A~%" + (string-from-list + (mapcar #'(lambda (p) + (biome-char (patch-biome p))) + row) ""))))) + + (defun coord (x y) + "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))))) + +;;; BIOMES + +(let ((biome-list NIL)) + (defun register-biome (symbol-name biome-object) + (setf biome-list (cons (list symbol-name biome-object) biome-list))) + + (defun available-biomes () + (keys biome-list)) + + (defun get-biome (symbol-name) + (cassoc symbol-name biome-list))) + +(defmacro new-biome (name &body body) + `(register-biome ',name + (make-biome + :name ,(symbol-to-string name) + ,@body))) + +;;; ITEMS + +(let ((item-list NIL)) + (defun register-item (symbol-name item-object) + (setf item-list + (cons (list symbol-name item-object) item-list))) + + (defun get-item-type (symbol-name) + (cassoc symbol-name item-list)) + + (defun get-item (symbol-name) + ;;FIXME copy-item doesn't work with CLOS + (copy-item (get-item-type symbol-name)))) + +(defmacro new-item (type name &body body) + `(register-item ',name + (make-instance ',type + :name ,(symbol-to-string name) + ,@body))) + +;;; ANIMALS & SPECIES + +(let ((species-list NIL)) + (defun register-species (symbol-name species-object) + (setf species-list + (cons (list symbol-name species-object) species-list))) + + (defun get-species (symbol-name) + (cassoc symbol-name species-list))) + +(defmacro new-species (name &body body) + `(register-species ',name + (make-instance 'species + :name ,(symbol-to-string name) + ,@body))) + +(let ((max-id 0) (animals NIL)) + (defun add-animal (species position) + "Create a new animal of the given species" + (let ((a (make-animal :id max-id + :pos position :species species + :health (.max-health species)))) + (incf max-id) + (setf animals (append animals a)))) + + (defun get-animal (id) + "Return the animal with this ID number" + (dolist (a animals) + (when (= (.id a) id) + (return-from get-animal a)))) + + (defun remove-animal (id) + "Remove the animal with this ID from the game" + (do ((al animals (cdr al))) + ((null al)) + (when (= (.id (car al)) id) + (setf (cdr al) (cddr al)))))) diff --git a/items.lisp b/items.lisp index 70e8acb..6957112 100644 --- a/items.lisp +++ b/items.lisp @@ -7,24 +7,6 @@ ;;;; (c) 2018 Daniel Vedder, MIT license ;;;; -(let ((item-list NIL)) - (defun register-item (symbol-name item-object) - (setf item-list - (cons (list symbol-name item-object) item-list))) - - (defun get-item-type (symbol-name) - (cassoc symbol-name item-list)) - - (defun get-item (symbol-name) - ;;FIXME copy-item doesn't work with CLOS - (copy-item (get-item-type symbol-name)))) - -(defmacro new-item (type name &body body) - `(register-item ',name - (make-instance ',type - :name ,(symbol-to-string name) - ,@body))) - ;;; RESOURCE ITEMS diff --git a/naledi.lisp b/naledi.lisp index f7319f2..81b2d0a 100644 --- a/naledi.lisp +++ b/naledi.lisp @@ -15,10 +15,11 @@ (load "util.lisp") (load "classes.lisp") +(load "data.lisp") +(load "world.lisp") (load "items.lisp") (load "biomes.lisp") (load "animals.lisp") -(load "world.lisp") (defun user-interface () @@ -105,6 +106,7 @@ (defun draw-place-panel (win me) "Draw a panel with information about the player's current location." + (debugging "~&~S" me) (let* ((p (coord (first me) (second me))) (descr (describe-patch p))) (clear win) (box win) @@ -153,5 +155,5 @@ ;; Initialize the random state (which would otherwise not be very random...) (setf *random-state* (make-random-state t)) -(setf *world* (create-world 500)) +(create-world 100) (user-interface) diff --git a/util.lisp b/util.lisp index c50e0ce..d6d034c 100644 --- a/util.lisp +++ b/util.lisp @@ -96,6 +96,10 @@ (if (null assoc-list) NIL (cons (car (car assoc-list)) (keys (cdr assoc-list))))) +(defun build-symbol (&rest components) + "Concatenate the passed components into a single symbol" + (read-from-string (string-from-list components :sep ""))) + (defun symbol-to-string (sym) "Convert a symbol to a string, exchanging dashes for spaces" (string-from-list diff --git a/world.lisp b/world.lisp index b591133..d46cdb6 100644 --- a/world.lisp +++ b/world.lisp @@ -7,7 +7,6 @@ ;;;; (c) 2018 Daniel Vedder, MIT license ;;;; -(defparameter *world* NIL) (defconstant *directions* '(N NE E SE S SW W NW)) (defstruct patch @@ -16,6 +15,14 @@ (items '()) (occupant NIL)) +(defstruct biome + (name "") + (ground "") + (features '()) ;an alist of possible features and their 1/p probabilities + (char #\.) ;default map display character + (col ':white)) ;default map display colour + + ;; MATRIX FUNCTIONS (defun init-matrix (size) @@ -28,11 +35,6 @@ (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 distance (x1 y1 x2 y2 &optional (pythag NIL)) "Find the distance between two sets of coordinates" (if pythag (round (sqrt (+ (expt (- x1 x2) 2) (expt (- y1 y2) 2)))) @@ -96,34 +98,15 @@ ((null dir) (list x y)) (T (error "~&Invalid direction ~S")))) -(defun patchindir (x y dir &optional (world *world*)) +(defun patchindir (x y dir) "Return the patch in the given direction" (let* ((coords (coordsindir x y dir)) (nextx (first coords)) (nexty (second coords))) - (coord nextx nexty world))) + (coord nextx nexty))) -(defun neighbour (p dir &optional (world *world*)) +(defun neighbour (p dir) "Return the neighbouring patch in this direction" - (patchindir (first (patch-pos p)) (second (patch-pos p)) dir world)) - - -;; TOPOGRAPHY FUNCTIONS - -;;XXX Do I still need these? - -(defun print-topography (&optional (stream T) (world *world*)) - "Print a text representation of the world and each patch's biome" - (dolist (row world) - (format stream "~&~A~%" - (string-from-list - (mapcar #'(lambda (p) (biome-char (patch-biome p))) row) - "")))) - -(defun save-topography (file-name &optional (world *world*)) - "Save the world topography as a text file" - (debugging "~&Saving world to file ~A" file-name) ;debug - (with-open-file (tf file-name :direction :output) - (print-topography tf))) + (patchindir (first (patch-pos p)) (second (patch-pos p)) dir)) ;; WORLD CREATION FUNCTIONS @@ -135,36 +118,36 @@ (when (chancep (second f)) (return-from get-patch-feature (get-item-type (first f))))))) -(defun generate-biomes (size-factor world) +(defun generate-biomes (size-factor) ;;XXX The maps this produces don't look quite as expected, but for ;; current purposes they are good enough (debugging "~&Generating biomes") ;debug - (let* ((world-size (length world)) (seeds NIL) - (nseeds (round (/ world-size size-factor))) + (let* ((wsize (world-size)) (seeds NIL) + (nseeds (round (/ wsize size-factor))) (biomes (remove-first-if #'(lambda (e) (eq e 'stream)) (available-biomes)))) ;;Initialize a set of biome 'seed' coordinates (dotimes (n nseeds) (setf seeds - (cons (list (random world-size) - (random world-size) + (cons (list (random wsize) + (random wsize) (random-elt biomes)) seeds))) (debugging "~&~S" seeds) ;;For each patch, calculate the closest seed and set to that biome - (dotimes (x world-size) - (dotimes (y world-size) - (let ((p (coord x y world)) + (dotimes (x wsize) + (dotimes (y wsize) + (let ((p (coord x y)) (b (third (closest-coords (list x y) seeds T)))) (setf (patch-biome p) (get-biome b)) (setf (patch-occupant p) (get-patch-feature p))))))) -(defun generate-stream (x0 y0 world) +(defun generate-stream (x0 y0) (debugging "~&Generating a stream, starting at ~S/~S" x0 y0) ;debug (do* ((dir (random-elt *directions*) (if (probabilityp 75) dir (next-dir dir (random-elt '(T NIL))))) - (patch (coord x0 y0 world) (neighbour patch dir world))) + (patch (coord x0 y0) (neighbour patch dir))) ((or (null patch) (eq (patch-biome patch) (get-biome 'stream)))) (setf (patch-biome patch) (get-biome 'stream)) (setf (patch-occupant patch) NIL))) @@ -172,14 +155,13 @@ ;;TODO create animal herds (defun create-world (size) - (let ((world (init-matrix size))) - ;;XXX magic numbers - (generate-biomes 10 world) - (dotimes (s (round (/ (expt size 2) 2000))) - (generate-stream (random size) (random size) world)) - world)) + (set-world (init-matrix size)) + ;;XXX magic numbers + (generate-biomes 10) + (dotimes (s (round (/ (expt size 2) 2000))) + (generate-stream (random size) (random size)))) -(defun describe-patch (p) +(defun describe-patch (p) ;;FIXME needs a line width parameter "Return a list of lines describing this patch." (list (string-upcase (biome-name (patch-biome p))) "" (format NIL "~A / ~A" (first (patch-pos p)) (second (patch-pos p))) ""