diff --git a/animals.lisp b/animals.lisp index 2f02144..da62e2e 100644 --- a/animals.lisp +++ b/animals.lisp @@ -7,7 +7,13 @@ ;;;; (c) 2018 Daniel Vedder, MIT license ;;;; + +;;; ANIMAL & SPECIES STRUCTS & FUNCTIONS + +(defvar *animals* NIL) + (defstruct animal + (id 0) (pos '(0 0)) (health 0) (species NIL)) @@ -21,7 +27,8 @@ (aggression 0) ;attack probability % (group-size 1) ;maximum group size (habitat '()) ;preferred biomes - (corpse-items '())) + (corpse-items '()) ;items dropped on death + (update-fn #'(lambda (id) NIL))) ; takes animal ID as argument (let ((species-list NIL)) (defun register-species (symbol-name species-object) @@ -31,30 +38,48 @@ (defun get-species (symbol-name) (cassoc symbol-name species-list))) -(register-species 'deer - (make-species :name "deer" - :strength 3 :max-health 10 :aggression 0 - :group-size 10 - :habitat '(forest grassland) - :corpse-items NIL)) ;TODO +(defmacro new-species (name &body body) + `(register-species name + (make-species ,@body))) -(register-species 'boar - (make-species :name "boar" - :strength 7 :max-health 15 :aggression 5 - :group-size 5 - :habitat '(forest) - :corpse-items NIL)) ;TODO +(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 (species-max-health species)))) + (incf max-id) + (setf *animals* (append *animals* a))))) -(register-species 'wolf - (make-species :name "wolf" - :strength 10 :max-health 20 :aggression 20 - :group-size 6 - :habitat '(grassland) - :corpse-items 'NIL)) ;TODO +;;; SPECIES DEFINITIONS -(register-species 'bear - (make-species :name "bear" - :strength 20 :max-health 30 :aggression 20 - :group-size 1 - :habitat '(forest) - :corpse-items 'NIL)) ;TODO +;;XXX Change to African species? +;;TODO bird species + +(new-species 'deer + :name "deer" + :strength 3 :max-health 10 :aggression 0 + :group-size 10 + :habitat '(forest grassland) + :corpse-items NIL) ;TODO + +(new-species 'boar + :name "boar" + :strength 7 :max-health 15 :aggression 5 + :group-size 5 + :habitat '(forest) + :corpse-items NIL) ;TODO + +(new-species 'wolf + :name "wolf" + :strength 10 :max-health 20 :aggression 20 + :group-size 6 + :habitat '(grassland) + :corpse-items NIL) ;TODO + +(new-species 'bear + :name "bear" + :strength 20 :max-health 30 :aggression 20 + :group-size 1 + :habitat '(forest) + :corpse-items NIL) ;TODO diff --git a/animals.lisp b/animals.lisp index 2f02144..da62e2e 100644 --- a/animals.lisp +++ b/animals.lisp @@ -7,7 +7,13 @@ ;;;; (c) 2018 Daniel Vedder, MIT license ;;;; + +;;; ANIMAL & SPECIES STRUCTS & FUNCTIONS + +(defvar *animals* NIL) + (defstruct animal + (id 0) (pos '(0 0)) (health 0) (species NIL)) @@ -21,7 +27,8 @@ (aggression 0) ;attack probability % (group-size 1) ;maximum group size (habitat '()) ;preferred biomes - (corpse-items '())) + (corpse-items '()) ;items dropped on death + (update-fn #'(lambda (id) NIL))) ; takes animal ID as argument (let ((species-list NIL)) (defun register-species (symbol-name species-object) @@ -31,30 +38,48 @@ (defun get-species (symbol-name) (cassoc symbol-name species-list))) -(register-species 'deer - (make-species :name "deer" - :strength 3 :max-health 10 :aggression 0 - :group-size 10 - :habitat '(forest grassland) - :corpse-items NIL)) ;TODO +(defmacro new-species (name &body body) + `(register-species name + (make-species ,@body))) -(register-species 'boar - (make-species :name "boar" - :strength 7 :max-health 15 :aggression 5 - :group-size 5 - :habitat '(forest) - :corpse-items NIL)) ;TODO +(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 (species-max-health species)))) + (incf max-id) + (setf *animals* (append *animals* a))))) -(register-species 'wolf - (make-species :name "wolf" - :strength 10 :max-health 20 :aggression 20 - :group-size 6 - :habitat '(grassland) - :corpse-items 'NIL)) ;TODO +;;; SPECIES DEFINITIONS -(register-species 'bear - (make-species :name "bear" - :strength 20 :max-health 30 :aggression 20 - :group-size 1 - :habitat '(forest) - :corpse-items 'NIL)) ;TODO +;;XXX Change to African species? +;;TODO bird species + +(new-species 'deer + :name "deer" + :strength 3 :max-health 10 :aggression 0 + :group-size 10 + :habitat '(forest grassland) + :corpse-items NIL) ;TODO + +(new-species 'boar + :name "boar" + :strength 7 :max-health 15 :aggression 5 + :group-size 5 + :habitat '(forest) + :corpse-items NIL) ;TODO + +(new-species 'wolf + :name "wolf" + :strength 10 :max-health 20 :aggression 20 + :group-size 6 + :habitat '(grassland) + :corpse-items NIL) ;TODO + +(new-species 'bear + :name "bear" + :strength 20 :max-health 30 :aggression 20 + :group-size 1 + :habitat '(forest) + :corpse-items NIL) ;TODO diff --git a/biome.lisp b/biome.lisp index ac533c3..648452e 100644 --- a/biome.lisp +++ b/biome.lisp @@ -23,16 +23,20 @@ (defun get-biome (symbol-name) (cassoc symbol-name biome-list))) +(defmacro new-biome (name &body body) + `(register-biome ,name + (make-biome ,@body))) + ;; 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)) +(new-biome 'grassland + :name "grassland" :char #\i + :init-items NIL ;TODO + :update-fn #'update-grasslands) ;; Forest biome @@ -40,10 +44,10 @@ ;;TODO ) -(register-biome 'forest - (make-biome :name "forest" :char #\Y - :init-items NIL ;TODO - :update-fn #'update-forest)) +(new-biome 'forest + :name "forest" :char #\Y + :init-items NIL ;TODO + :update-fn #'update-forest) ;; Stream biome @@ -51,7 +55,7 @@ ;;TODO ) -(register-biome 'stream - (make-biome :name "stream" :char #\~ - :init-items NIL ;TODO - :update-fn #'update-stream)) +(new-biome 'stream + :name "stream" :char #\~ + :init-items NIL ;TODO + :update-fn #'update-stream) diff --git a/animals.lisp b/animals.lisp index 2f02144..da62e2e 100644 --- a/animals.lisp +++ b/animals.lisp @@ -7,7 +7,13 @@ ;;;; (c) 2018 Daniel Vedder, MIT license ;;;; + +;;; ANIMAL & SPECIES STRUCTS & FUNCTIONS + +(defvar *animals* NIL) + (defstruct animal + (id 0) (pos '(0 0)) (health 0) (species NIL)) @@ -21,7 +27,8 @@ (aggression 0) ;attack probability % (group-size 1) ;maximum group size (habitat '()) ;preferred biomes - (corpse-items '())) + (corpse-items '()) ;items dropped on death + (update-fn #'(lambda (id) NIL))) ; takes animal ID as argument (let ((species-list NIL)) (defun register-species (symbol-name species-object) @@ -31,30 +38,48 @@ (defun get-species (symbol-name) (cassoc symbol-name species-list))) -(register-species 'deer - (make-species :name "deer" - :strength 3 :max-health 10 :aggression 0 - :group-size 10 - :habitat '(forest grassland) - :corpse-items NIL)) ;TODO +(defmacro new-species (name &body body) + `(register-species name + (make-species ,@body))) -(register-species 'boar - (make-species :name "boar" - :strength 7 :max-health 15 :aggression 5 - :group-size 5 - :habitat '(forest) - :corpse-items NIL)) ;TODO +(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 (species-max-health species)))) + (incf max-id) + (setf *animals* (append *animals* a))))) -(register-species 'wolf - (make-species :name "wolf" - :strength 10 :max-health 20 :aggression 20 - :group-size 6 - :habitat '(grassland) - :corpse-items 'NIL)) ;TODO +;;; SPECIES DEFINITIONS -(register-species 'bear - (make-species :name "bear" - :strength 20 :max-health 30 :aggression 20 - :group-size 1 - :habitat '(forest) - :corpse-items 'NIL)) ;TODO +;;XXX Change to African species? +;;TODO bird species + +(new-species 'deer + :name "deer" + :strength 3 :max-health 10 :aggression 0 + :group-size 10 + :habitat '(forest grassland) + :corpse-items NIL) ;TODO + +(new-species 'boar + :name "boar" + :strength 7 :max-health 15 :aggression 5 + :group-size 5 + :habitat '(forest) + :corpse-items NIL) ;TODO + +(new-species 'wolf + :name "wolf" + :strength 10 :max-health 20 :aggression 20 + :group-size 6 + :habitat '(grassland) + :corpse-items NIL) ;TODO + +(new-species 'bear + :name "bear" + :strength 20 :max-health 30 :aggression 20 + :group-size 1 + :habitat '(forest) + :corpse-items NIL) ;TODO diff --git a/biome.lisp b/biome.lisp index ac533c3..648452e 100644 --- a/biome.lisp +++ b/biome.lisp @@ -23,16 +23,20 @@ (defun get-biome (symbol-name) (cassoc symbol-name biome-list))) +(defmacro new-biome (name &body body) + `(register-biome ,name + (make-biome ,@body))) + ;; 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)) +(new-biome 'grassland + :name "grassland" :char #\i + :init-items NIL ;TODO + :update-fn #'update-grasslands) ;; Forest biome @@ -40,10 +44,10 @@ ;;TODO ) -(register-biome 'forest - (make-biome :name "forest" :char #\Y - :init-items NIL ;TODO - :update-fn #'update-forest)) +(new-biome 'forest + :name "forest" :char #\Y + :init-items NIL ;TODO + :update-fn #'update-forest) ;; Stream biome @@ -51,7 +55,7 @@ ;;TODO ) -(register-biome 'stream - (make-biome :name "stream" :char #\~ - :init-items NIL ;TODO - :update-fn #'update-stream)) +(new-biome 'stream + :name "stream" :char #\~ + :init-items NIL ;TODO + :update-fn #'update-stream) diff --git a/items.lisp b/items.lisp index f22b891..f220c83 100644 --- a/items.lisp +++ b/items.lisp @@ -26,55 +26,59 @@ (defun get-item (symbol-name) (copy-item (get-item-type symbol-name)))) +(defmacro new-item (name &body body) + `(register-item ,name + (make-item ,@body))) + ;;; RESOURCE ITEMS -(register-item 'wood - (make-item :name "wood" :weight 1 - :description "A block of wood, just right for working with")) +(new-item 'wood + :name "wood" :weight 1 + :description "A block of wood, just right for working with") -(register-item 'stone - (make-item :name "stone" :weight 2 - :description "A fist-sized stone. What are you going to do with it?")) +(new-item 'stone + :name "stone" :weight 2 + :description "A fist-sized stone. What are you going to do with it?") -(register-item 'iron - (make-item :name "iron" :weight 3 - :description "An iron ingot, ready for further crafting.")) +(new-item 'iron + :name "iron" :weight 3 + :description "An iron ingot, ready for further crafting.") ;;; NATURE ITEMS -(register-item 'oak - (make-item :name "oak" - :description "An old, majestic oak, gnarled with age." - :destroy-with '(stone-axe iron-axe) - :drops '(wood) :movable NIL :weight 2000)) +(new-item 'oak + :name "oak" + :description "An old, majestic oak, gnarled with age." + :destroy-with '(stone-axe iron-axe) + :drops '(wood) :movable NIL :weight 2000) -(register-item 'rock - (make-item :name "rock" - :description "A huge lump of grey basalt, sticking out of the ground." - :destroy-with '(stone-pickaxe iron-pickaxe) - :drops '(stone) :movable NIL :weight 5000)) +(new-item 'rock + :name "rock" + :description "A huge lump of grey basalt, sticking out of the ground." + :destroy-with '(stone-pickaxe iron-pickaxe) + :drops '(stone) :movable NIL :weight 5000) ;;; TOOL ITEMS ;;TODO Faustkeil? -(register-item 'stone-axe - (make-item :name "stone axe" - :description "An axe, crudely but effectively fashioned out of stone." - :weight 2 :craft-with '(stone wood))) +(new-item 'stone-axe + :name "stone axe" + :description "An axe, crudely but effectively fashioned out of stone." + :weight 2 :craft-with '(stone wood)) -(register-item 'iron-axe - (make-item :name "iron axe" - :description "A finely honed iron axe, just right for chopping wood." - :weight 3 :craft-with '(iron wood))) +(new-item 'iron-axe + :name "iron axe" + :description "A finely honed iron axe, just right for chopping wood." + :weight 3 :craft-with '(iron wood)) -(register-item 'stone-pickaxe - (make-item :name "stone pickaxe" - :description "A pickaxe, somewhat helplessly made from stone." - :weight 3 :craft-with '(stone wood))) +(new-item 'stone-pickaxe + :name "stone pickaxe" + :description "A pickaxe, somewhat helplessly made from stone." + :weight 3 :craft-with '(stone wood)) -(register-item 'iron-pickaxe - (make-item :name "iron pickaxe" - :description "A solid iron pickaxe. Prepare to split rock!" - :weight 4 :craft-with '(iron wood))) +(new-item 'iron-pickaxe + :name "iron pickaxe" + :description "A solid iron pickaxe. Prepare to split rock!" + :weight 4 :craft-with '(iron wood))