Newer
Older
naledi / animals.lisp
;;;;
;;;; Terra Nostra is a Minecraft-like survival game for the commandline.
;;;;
;;;; This file defines animal and species structs and the various species
;;;; found in-game.
;;;; 
;;;; (c) 2018 Daniel Vedder, MIT license
;;;;


;;; ANIMAL & SPECIES STRUCTS & FUNCTIONS

(defvar *animals* NIL)

(defstruct animal
	(id 0)
	(pos '(0 0))
	(health 0)
	(species NIL))

;;TODO predatory species

(defstruct species
	(name "")
	(strength 0)
	(max-health 0)
	(aggression 0) ;attack probability %
	(group-size 1) ;maximum group size
	(habitat '()) ;preferred biomes
	(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)
		(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-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 (species-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"
	: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