diff --git a/TODO b/TODO index 0932d37..4583e01 100644 --- a/TODO +++ b/TODO @@ -8,8 +8,6 @@ GAME -* add animals - * introduce multithreading, update functions * (I am legion...) diff --git a/TODO b/TODO index 0932d37..4583e01 100644 --- a/TODO +++ b/TODO @@ -8,8 +8,6 @@ GAME -* add animals - * introduce multithreading, update functions * (I am legion...) diff --git a/animals.lisp b/animals.lisp index d675bb5..3e0cabd 100644 --- a/animals.lisp +++ b/animals.lisp @@ -8,19 +8,6 @@ ;;;; (c) 2018 Daniel Vedder, MIT license ;;;; -(defmethod random-move ((a animal)) - (do* ((dir (random-elt *directions*) (random-elt *directions*)) - (next-patch (patch-in-dir (.x a) (.y a) dir) - (patch-in-dir (.x a) (.y a) dir)) - (ttl 10 (1- ttl))) - ((zerop ttl) NIL) - (when (and next-patch (null (patch-occupant next-patch))) - (setf (patch-occupant (coord (.x a) (.y a))) NIL) - (setf (.x a) (first (patch-pos next-patch)) - (.y a) (second (patch-pos next-patch))) - (setf (patch-occupant next-patch) a) - (return-from random-move a)))) - ;;XXX bird species? ;;XXX water species? ;;XXX small mammals -> hills diff --git a/TODO b/TODO index 0932d37..4583e01 100644 --- a/TODO +++ b/TODO @@ -8,8 +8,6 @@ GAME -* add animals - * introduce multithreading, update functions * (I am legion...) diff --git a/animals.lisp b/animals.lisp index d675bb5..3e0cabd 100644 --- a/animals.lisp +++ b/animals.lisp @@ -8,19 +8,6 @@ ;;;; (c) 2018 Daniel Vedder, MIT license ;;;; -(defmethod random-move ((a animal)) - (do* ((dir (random-elt *directions*) (random-elt *directions*)) - (next-patch (patch-in-dir (.x a) (.y a) dir) - (patch-in-dir (.x a) (.y a) dir)) - (ttl 10 (1- ttl))) - ((zerop ttl) NIL) - (when (and next-patch (null (patch-occupant next-patch))) - (setf (patch-occupant (coord (.x a) (.y a))) NIL) - (setf (.x a) (first (patch-pos next-patch)) - (.y a) (second (patch-pos next-patch))) - (setf (patch-occupant next-patch) a) - (return-from random-move a)))) - ;;XXX bird species? ;;XXX water species? ;;XXX small mammals -> hills diff --git a/classes.lisp b/classes.lisp deleted file mode 100644 index 1a35ecd..0000000 --- a/classes.lisp +++ /dev/null @@ -1,71 +0,0 @@ -;;;; -;;;; Naledi ya Africa ("Star of Africa") is an ncurses-based survival game -;;;; set in Africa. -;;;; -;;;; This file defines all CLOS classes used in the game. -;;;; -;;;; (c) 2018 Daniel Vedder, MIT license -;;;; - -(defclass item () - ;; The base class of all game items. - ((name :accessor .name :initarg :name :initform "") - (description :accessor .description :initarg :description :initform "") - (weight :accessor .weight :initarg :weight :initform 0) - (movable :reader movablep :initarg :movable :initform T))) - -(defclass destructable (item) - ;; An item that can be destroyed - ((destroy-with :reader destructors :initarg :destroy-with :initform NIL) - (drops :reader drops :initarg :drops :initform '()))) - -(defclass craftable (item) - ;; An item that can be crafted from other items or resources - ((requires-tool :reader requires-tool :initarg :requires-tool :initform '()) - (craft-with :reader craft-with :initarg :craft-with :initform '()))) - -(defclass feature (destructable) - ;; A landscape feature such as a rock, a tree, or an animal. - ((symbol-char :reader .char :initarg :char :initform NIL) - (symbol-color :reader .color :initarg :color :initform NIL) - (x-pos :accessor .x :initarg :x :initform 0) - (y-pos :accessor .y :initarg :y :initform 0)) - (:default-initargs :movable NIL)) - -(defclass resource (item) - ;; A resource that can be gathered and used to craft items. - ((burning-product :reader .burning-product :initarg :burning-product))) - -(defclass tool (craftable) - ;; A tool or weapon that can be crafted and used in-game. - ((level :reader .level :initarg :level :initform 0) - ;;TODO the type needs some thought (add/change to efficiency?) - (type :reader .type :initarg :type :initform NIL) ;e.g. 'weapon, 'wood - (condition :accessor .condition :initarg :condition :initform 100))) - -(defclass container (craftable feature) - ;; An item that can store other items (and perhaps manipulate them) - ((contains :accessor .contains :initform '()) - (max-weight :reader .max-weight :initarg :max-weight :initform -1) - (capacity :reader .capacity :initarg :capacity :initform 0))) - -(defclass species (feature) - ;; An animal species - (;; species properties - (strength :accessor .strength :initarg :strength :initform 1) - (max-health :accessor .max-health :initarg :max-health :initform 1) - (aggression :accessor .aggression :initarg :aggression :initform 0) - (group-size :reader .group-size :initarg :group-size :initform 1) - (habitat :reader .habitat :initarg :habitat :initform '()) - ;; individual properties - (id :reader .id :initarg :id :initform -1) - (health :reader .health :initarg :health :initform 1)) - (:default-initargs :destroy-with '(weapon) :movable T)) - - -;; Create a new class for each item type -(defmacro new-item (superclass name &body body) - `(defclass ,name (,superclass) () - (:default-initargs ,@body - :name (string-downcase (to-string ',name))))) - diff --git a/TODO b/TODO index 0932d37..4583e01 100644 --- a/TODO +++ b/TODO @@ -8,8 +8,6 @@ GAME -* add animals - * introduce multithreading, update functions * (I am legion...) diff --git a/animals.lisp b/animals.lisp index d675bb5..3e0cabd 100644 --- a/animals.lisp +++ b/animals.lisp @@ -8,19 +8,6 @@ ;;;; (c) 2018 Daniel Vedder, MIT license ;;;; -(defmethod random-move ((a animal)) - (do* ((dir (random-elt *directions*) (random-elt *directions*)) - (next-patch (patch-in-dir (.x a) (.y a) dir) - (patch-in-dir (.x a) (.y a) dir)) - (ttl 10 (1- ttl))) - ((zerop ttl) NIL) - (when (and next-patch (null (patch-occupant next-patch))) - (setf (patch-occupant (coord (.x a) (.y a))) NIL) - (setf (.x a) (first (patch-pos next-patch)) - (.y a) (second (patch-pos next-patch))) - (setf (patch-occupant next-patch) a) - (return-from random-move a)))) - ;;XXX bird species? ;;XXX water species? ;;XXX small mammals -> hills diff --git a/classes.lisp b/classes.lisp deleted file mode 100644 index 1a35ecd..0000000 --- a/classes.lisp +++ /dev/null @@ -1,71 +0,0 @@ -;;;; -;;;; Naledi ya Africa ("Star of Africa") is an ncurses-based survival game -;;;; set in Africa. -;;;; -;;;; This file defines all CLOS classes used in the game. -;;;; -;;;; (c) 2018 Daniel Vedder, MIT license -;;;; - -(defclass item () - ;; The base class of all game items. - ((name :accessor .name :initarg :name :initform "") - (description :accessor .description :initarg :description :initform "") - (weight :accessor .weight :initarg :weight :initform 0) - (movable :reader movablep :initarg :movable :initform T))) - -(defclass destructable (item) - ;; An item that can be destroyed - ((destroy-with :reader destructors :initarg :destroy-with :initform NIL) - (drops :reader drops :initarg :drops :initform '()))) - -(defclass craftable (item) - ;; An item that can be crafted from other items or resources - ((requires-tool :reader requires-tool :initarg :requires-tool :initform '()) - (craft-with :reader craft-with :initarg :craft-with :initform '()))) - -(defclass feature (destructable) - ;; A landscape feature such as a rock, a tree, or an animal. - ((symbol-char :reader .char :initarg :char :initform NIL) - (symbol-color :reader .color :initarg :color :initform NIL) - (x-pos :accessor .x :initarg :x :initform 0) - (y-pos :accessor .y :initarg :y :initform 0)) - (:default-initargs :movable NIL)) - -(defclass resource (item) - ;; A resource that can be gathered and used to craft items. - ((burning-product :reader .burning-product :initarg :burning-product))) - -(defclass tool (craftable) - ;; A tool or weapon that can be crafted and used in-game. - ((level :reader .level :initarg :level :initform 0) - ;;TODO the type needs some thought (add/change to efficiency?) - (type :reader .type :initarg :type :initform NIL) ;e.g. 'weapon, 'wood - (condition :accessor .condition :initarg :condition :initform 100))) - -(defclass container (craftable feature) - ;; An item that can store other items (and perhaps manipulate them) - ((contains :accessor .contains :initform '()) - (max-weight :reader .max-weight :initarg :max-weight :initform -1) - (capacity :reader .capacity :initarg :capacity :initform 0))) - -(defclass species (feature) - ;; An animal species - (;; species properties - (strength :accessor .strength :initarg :strength :initform 1) - (max-health :accessor .max-health :initarg :max-health :initform 1) - (aggression :accessor .aggression :initarg :aggression :initform 0) - (group-size :reader .group-size :initarg :group-size :initform 1) - (habitat :reader .habitat :initarg :habitat :initform '()) - ;; individual properties - (id :reader .id :initarg :id :initform -1) - (health :reader .health :initarg :health :initform 1)) - (:default-initargs :destroy-with '(weapon) :movable T)) - - -;; Create a new class for each item type -(defmacro new-item (superclass name &body body) - `(defclass ,name (,superclass) () - (:default-initargs ,@body - :name (string-downcase (to-string ',name))))) - diff --git a/data.lisp b/data.lisp index d411280..55a60d7 100644 --- a/data.lisp +++ b/data.lisp @@ -50,29 +50,3 @@ (make-biome :name ,(symbol-to-string name) ,@body))) - -;;; ANIMALS -;; XXX Do I even need this code? - -(let ((max-id 0) (animals NIL)) - (defun add-animal (species position) - "Create a new animal of the given species" - (let ((a (make-instance '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" - ;;XXX Can't we just do this with `remove-if'? - (do ((al animals (cdr al))) - ((null al)) - (when (= (.id (car al)) id) - (setf (cdr al) (cddr al)))))) diff --git a/TODO b/TODO index 0932d37..4583e01 100644 --- a/TODO +++ b/TODO @@ -8,8 +8,6 @@ GAME -* add animals - * introduce multithreading, update functions * (I am legion...) diff --git a/animals.lisp b/animals.lisp index d675bb5..3e0cabd 100644 --- a/animals.lisp +++ b/animals.lisp @@ -8,19 +8,6 @@ ;;;; (c) 2018 Daniel Vedder, MIT license ;;;; -(defmethod random-move ((a animal)) - (do* ((dir (random-elt *directions*) (random-elt *directions*)) - (next-patch (patch-in-dir (.x a) (.y a) dir) - (patch-in-dir (.x a) (.y a) dir)) - (ttl 10 (1- ttl))) - ((zerop ttl) NIL) - (when (and next-patch (null (patch-occupant next-patch))) - (setf (patch-occupant (coord (.x a) (.y a))) NIL) - (setf (.x a) (first (patch-pos next-patch)) - (.y a) (second (patch-pos next-patch))) - (setf (patch-occupant next-patch) a) - (return-from random-move a)))) - ;;XXX bird species? ;;XXX water species? ;;XXX small mammals -> hills diff --git a/classes.lisp b/classes.lisp deleted file mode 100644 index 1a35ecd..0000000 --- a/classes.lisp +++ /dev/null @@ -1,71 +0,0 @@ -;;;; -;;;; Naledi ya Africa ("Star of Africa") is an ncurses-based survival game -;;;; set in Africa. -;;;; -;;;; This file defines all CLOS classes used in the game. -;;;; -;;;; (c) 2018 Daniel Vedder, MIT license -;;;; - -(defclass item () - ;; The base class of all game items. - ((name :accessor .name :initarg :name :initform "") - (description :accessor .description :initarg :description :initform "") - (weight :accessor .weight :initarg :weight :initform 0) - (movable :reader movablep :initarg :movable :initform T))) - -(defclass destructable (item) - ;; An item that can be destroyed - ((destroy-with :reader destructors :initarg :destroy-with :initform NIL) - (drops :reader drops :initarg :drops :initform '()))) - -(defclass craftable (item) - ;; An item that can be crafted from other items or resources - ((requires-tool :reader requires-tool :initarg :requires-tool :initform '()) - (craft-with :reader craft-with :initarg :craft-with :initform '()))) - -(defclass feature (destructable) - ;; A landscape feature such as a rock, a tree, or an animal. - ((symbol-char :reader .char :initarg :char :initform NIL) - (symbol-color :reader .color :initarg :color :initform NIL) - (x-pos :accessor .x :initarg :x :initform 0) - (y-pos :accessor .y :initarg :y :initform 0)) - (:default-initargs :movable NIL)) - -(defclass resource (item) - ;; A resource that can be gathered and used to craft items. - ((burning-product :reader .burning-product :initarg :burning-product))) - -(defclass tool (craftable) - ;; A tool or weapon that can be crafted and used in-game. - ((level :reader .level :initarg :level :initform 0) - ;;TODO the type needs some thought (add/change to efficiency?) - (type :reader .type :initarg :type :initform NIL) ;e.g. 'weapon, 'wood - (condition :accessor .condition :initarg :condition :initform 100))) - -(defclass container (craftable feature) - ;; An item that can store other items (and perhaps manipulate them) - ((contains :accessor .contains :initform '()) - (max-weight :reader .max-weight :initarg :max-weight :initform -1) - (capacity :reader .capacity :initarg :capacity :initform 0))) - -(defclass species (feature) - ;; An animal species - (;; species properties - (strength :accessor .strength :initarg :strength :initform 1) - (max-health :accessor .max-health :initarg :max-health :initform 1) - (aggression :accessor .aggression :initarg :aggression :initform 0) - (group-size :reader .group-size :initarg :group-size :initform 1) - (habitat :reader .habitat :initarg :habitat :initform '()) - ;; individual properties - (id :reader .id :initarg :id :initform -1) - (health :reader .health :initarg :health :initform 1)) - (:default-initargs :destroy-with '(weapon) :movable T)) - - -;; Create a new class for each item type -(defmacro new-item (superclass name &body body) - `(defclass ,name (,superclass) () - (:default-initargs ,@body - :name (string-downcase (to-string ',name))))) - diff --git a/data.lisp b/data.lisp index d411280..55a60d7 100644 --- a/data.lisp +++ b/data.lisp @@ -50,29 +50,3 @@ (make-biome :name ,(symbol-to-string name) ,@body))) - -;;; ANIMALS -;; XXX Do I even need this code? - -(let ((max-id 0) (animals NIL)) - (defun add-animal (species position) - "Create a new animal of the given species" - (let ((a (make-instance '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" - ;;XXX Can't we just do this with `remove-if'? - (do ((al animals (cdr al))) - ((null al)) - (when (= (.id (car al)) id) - (setf (cdr al) (cddr al)))))) diff --git a/item-classes.lisp b/item-classes.lisp new file mode 100644 index 0000000..1286189 --- /dev/null +++ b/item-classes.lisp @@ -0,0 +1,71 @@ +;;;; +;;;; Naledi ya Africa ("Star of Africa") is an ncurses-based survival game +;;;; set in Africa. +;;;; +;;;; This file defines all CLOS classes used in the game. +;;;; +;;;; (c) 2018 Daniel Vedder, MIT license +;;;; + +(defclass item () + ;; The base class of all game items. + ((name :accessor .name :initarg :name :initform "") + (description :accessor .description :initarg :description :initform "") + (weight :accessor .weight :initarg :weight :initform 0) + (movable :reader movablep :initarg :movable :initform T))) + +(defclass destructable (item) + ;; An item that can be destroyed + ((destroy-with :reader .destructors :initarg :destroy-with :initform NIL) + (health :accessor .health :initarg :health :initform 1) + (drops :reader .drops :initarg :drops :initform '()))) + +(defclass craftable (item) + ;; An item that can be crafted from other items or resources + ((requires-tool :reader requires-tool :initarg :requires-tool :initform '()) + (craft-with :reader craft-with :initarg :craft-with :initform '()))) + +(defclass feature (destructable) + ;; A landscape feature such as a rock, a tree, or an animal. + ((symbol-char :reader .char :initarg :char :initform NIL) + (symbol-color :reader .color :initarg :color :initform NIL) + (x-pos :accessor .x :initarg :x :initform 0) + (y-pos :accessor .y :initarg :y :initform 0)) + (:default-initargs :movable NIL)) + +(defclass resource (item) + ;; A resource that can be gathered and used to craft items. + ((burning-product :reader .burning-product :initarg :burning-product))) + +(defclass tool (craftable) + ;; A tool or weapon that can be crafted and used in-game. + ((level :reader .level :initarg :level :initform 0) + ;;TODO the type needs some thought (add/change to efficiency?) + (type :reader .type :initarg :type :initform NIL) ;e.g. 'weapon, 'wood + (condition :accessor .condition :initarg :condition :initform 100))) + +(defclass container (craftable feature) + ;; An item that can store other items (and perhaps manipulate them) + ((contains :accessor .contains :initform '()) + (max-weight :reader .max-weight :initarg :max-weight :initform -1) + (capacity :reader .capacity :initarg :capacity :initform 0))) + +(defclass species (feature) + ;; An animal species + (;; species properties + (strength :accessor .strength :initarg :strength :initform 1) + (max-health :accessor .max-health :initarg :max-health :initform 1) + (aggression :accessor .aggression :initarg :aggression :initform 0) + (group-size :reader .group-size :initarg :group-size :initform 1) + (habitat :reader .habitat :initarg :habitat :initform '()) + ;; individual properties + (id :reader .id :initarg :id :initform -1) + (:default-initargs :destroy-with '(weapon) :movable T)) + + +;; Create a new class for each item type +(defmacro new-item (superclass name &body body) + `(defclass ,name (,superclass) () + (:default-initargs ,@body + :name (string-downcase (to-string ',name))))) + diff --git a/TODO b/TODO index 0932d37..4583e01 100644 --- a/TODO +++ b/TODO @@ -8,8 +8,6 @@ GAME -* add animals - * introduce multithreading, update functions * (I am legion...) diff --git a/animals.lisp b/animals.lisp index d675bb5..3e0cabd 100644 --- a/animals.lisp +++ b/animals.lisp @@ -8,19 +8,6 @@ ;;;; (c) 2018 Daniel Vedder, MIT license ;;;; -(defmethod random-move ((a animal)) - (do* ((dir (random-elt *directions*) (random-elt *directions*)) - (next-patch (patch-in-dir (.x a) (.y a) dir) - (patch-in-dir (.x a) (.y a) dir)) - (ttl 10 (1- ttl))) - ((zerop ttl) NIL) - (when (and next-patch (null (patch-occupant next-patch))) - (setf (patch-occupant (coord (.x a) (.y a))) NIL) - (setf (.x a) (first (patch-pos next-patch)) - (.y a) (second (patch-pos next-patch))) - (setf (patch-occupant next-patch) a) - (return-from random-move a)))) - ;;XXX bird species? ;;XXX water species? ;;XXX small mammals -> hills diff --git a/classes.lisp b/classes.lisp deleted file mode 100644 index 1a35ecd..0000000 --- a/classes.lisp +++ /dev/null @@ -1,71 +0,0 @@ -;;;; -;;;; Naledi ya Africa ("Star of Africa") is an ncurses-based survival game -;;;; set in Africa. -;;;; -;;;; This file defines all CLOS classes used in the game. -;;;; -;;;; (c) 2018 Daniel Vedder, MIT license -;;;; - -(defclass item () - ;; The base class of all game items. - ((name :accessor .name :initarg :name :initform "") - (description :accessor .description :initarg :description :initform "") - (weight :accessor .weight :initarg :weight :initform 0) - (movable :reader movablep :initarg :movable :initform T))) - -(defclass destructable (item) - ;; An item that can be destroyed - ((destroy-with :reader destructors :initarg :destroy-with :initform NIL) - (drops :reader drops :initarg :drops :initform '()))) - -(defclass craftable (item) - ;; An item that can be crafted from other items or resources - ((requires-tool :reader requires-tool :initarg :requires-tool :initform '()) - (craft-with :reader craft-with :initarg :craft-with :initform '()))) - -(defclass feature (destructable) - ;; A landscape feature such as a rock, a tree, or an animal. - ((symbol-char :reader .char :initarg :char :initform NIL) - (symbol-color :reader .color :initarg :color :initform NIL) - (x-pos :accessor .x :initarg :x :initform 0) - (y-pos :accessor .y :initarg :y :initform 0)) - (:default-initargs :movable NIL)) - -(defclass resource (item) - ;; A resource that can be gathered and used to craft items. - ((burning-product :reader .burning-product :initarg :burning-product))) - -(defclass tool (craftable) - ;; A tool or weapon that can be crafted and used in-game. - ((level :reader .level :initarg :level :initform 0) - ;;TODO the type needs some thought (add/change to efficiency?) - (type :reader .type :initarg :type :initform NIL) ;e.g. 'weapon, 'wood - (condition :accessor .condition :initarg :condition :initform 100))) - -(defclass container (craftable feature) - ;; An item that can store other items (and perhaps manipulate them) - ((contains :accessor .contains :initform '()) - (max-weight :reader .max-weight :initarg :max-weight :initform -1) - (capacity :reader .capacity :initarg :capacity :initform 0))) - -(defclass species (feature) - ;; An animal species - (;; species properties - (strength :accessor .strength :initarg :strength :initform 1) - (max-health :accessor .max-health :initarg :max-health :initform 1) - (aggression :accessor .aggression :initarg :aggression :initform 0) - (group-size :reader .group-size :initarg :group-size :initform 1) - (habitat :reader .habitat :initarg :habitat :initform '()) - ;; individual properties - (id :reader .id :initarg :id :initform -1) - (health :reader .health :initarg :health :initform 1)) - (:default-initargs :destroy-with '(weapon) :movable T)) - - -;; Create a new class for each item type -(defmacro new-item (superclass name &body body) - `(defclass ,name (,superclass) () - (:default-initargs ,@body - :name (string-downcase (to-string ',name))))) - diff --git a/data.lisp b/data.lisp index d411280..55a60d7 100644 --- a/data.lisp +++ b/data.lisp @@ -50,29 +50,3 @@ (make-biome :name ,(symbol-to-string name) ,@body))) - -;;; ANIMALS -;; XXX Do I even need this code? - -(let ((max-id 0) (animals NIL)) - (defun add-animal (species position) - "Create a new animal of the given species" - (let ((a (make-instance '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" - ;;XXX Can't we just do this with `remove-if'? - (do ((al animals (cdr al))) - ((null al)) - (when (= (.id (car al)) id) - (setf (cdr al) (cddr al)))))) diff --git a/item-classes.lisp b/item-classes.lisp new file mode 100644 index 0000000..1286189 --- /dev/null +++ b/item-classes.lisp @@ -0,0 +1,71 @@ +;;;; +;;;; Naledi ya Africa ("Star of Africa") is an ncurses-based survival game +;;;; set in Africa. +;;;; +;;;; This file defines all CLOS classes used in the game. +;;;; +;;;; (c) 2018 Daniel Vedder, MIT license +;;;; + +(defclass item () + ;; The base class of all game items. + ((name :accessor .name :initarg :name :initform "") + (description :accessor .description :initarg :description :initform "") + (weight :accessor .weight :initarg :weight :initform 0) + (movable :reader movablep :initarg :movable :initform T))) + +(defclass destructable (item) + ;; An item that can be destroyed + ((destroy-with :reader .destructors :initarg :destroy-with :initform NIL) + (health :accessor .health :initarg :health :initform 1) + (drops :reader .drops :initarg :drops :initform '()))) + +(defclass craftable (item) + ;; An item that can be crafted from other items or resources + ((requires-tool :reader requires-tool :initarg :requires-tool :initform '()) + (craft-with :reader craft-with :initarg :craft-with :initform '()))) + +(defclass feature (destructable) + ;; A landscape feature such as a rock, a tree, or an animal. + ((symbol-char :reader .char :initarg :char :initform NIL) + (symbol-color :reader .color :initarg :color :initform NIL) + (x-pos :accessor .x :initarg :x :initform 0) + (y-pos :accessor .y :initarg :y :initform 0)) + (:default-initargs :movable NIL)) + +(defclass resource (item) + ;; A resource that can be gathered and used to craft items. + ((burning-product :reader .burning-product :initarg :burning-product))) + +(defclass tool (craftable) + ;; A tool or weapon that can be crafted and used in-game. + ((level :reader .level :initarg :level :initform 0) + ;;TODO the type needs some thought (add/change to efficiency?) + (type :reader .type :initarg :type :initform NIL) ;e.g. 'weapon, 'wood + (condition :accessor .condition :initarg :condition :initform 100))) + +(defclass container (craftable feature) + ;; An item that can store other items (and perhaps manipulate them) + ((contains :accessor .contains :initform '()) + (max-weight :reader .max-weight :initarg :max-weight :initform -1) + (capacity :reader .capacity :initarg :capacity :initform 0))) + +(defclass species (feature) + ;; An animal species + (;; species properties + (strength :accessor .strength :initarg :strength :initform 1) + (max-health :accessor .max-health :initarg :max-health :initform 1) + (aggression :accessor .aggression :initarg :aggression :initform 0) + (group-size :reader .group-size :initarg :group-size :initform 1) + (habitat :reader .habitat :initarg :habitat :initform '()) + ;; individual properties + (id :reader .id :initarg :id :initform -1) + (:default-initargs :destroy-with '(weapon) :movable T)) + + +;; Create a new class for each item type +(defmacro new-item (superclass name &body body) + `(defclass ,name (,superclass) () + (:default-initargs ,@body + :name (string-downcase (to-string ',name))))) + diff --git a/item-methods.lisp b/item-methods.lisp new file mode 100644 index 0000000..9440b90 --- /dev/null +++ b/item-methods.lisp @@ -0,0 +1,44 @@ +;;;; +;;;; Naledi ya Africa ("Star of Africa") is an ncurses-based survival game +;;;; set in Africa. +;;;; +;;;; This file defines all CLOS methods used in the game for the different +;;;; item classes. +;;;; +;;;; (c) 2018 Daniel Vedder, MIT license +;;;; + +;; Default `update' and `action' methods are NOP +(defmethod update ((i item))) +(defmethod action ((i item))) + +(defmethod attack ((d destructable) (tl tool)) + "Attack a destructable item with a tool or weapon" + ;;Returns either the damaged item or the items it drops when destroyed + (if (member (class-of tl) (.destructors d)) + (if (>= 0 (decf (.health d) (random (* 10 (.level tl))))) + (.drops d) d) + (progn (notify "You cannot attack ~A with ~A." + (leading-vowl (.name d)) (leading-vowel (.name tl))) + NIL))) + +(defmethod update ((a animal)) + (random-move a)) + +(defmethod random-move ((a animal)) + "Move in a random direction within the species' habitat niche" + (do* ((dir (random-elt *directions*) (random-elt *directions*)) + (next-patch (patch-in-dir (.x a) (.y a) dir) + (patch-in-dir (.x a) (.y a) dir)) + (ttl 10 (1- ttl))) + ((zerop ttl) NIL) + (when (and next-patch (null (patch-occupant next-patch)) + (member (read-from-string + (biome-name (patch-biome next-patch))) + (.habitat a))) + (setf (patch-occupant (coord (.x a) (.y a))) NIL) + (setf (.x a) (first (patch-pos next-patch)) + (.y a) (second (patch-pos next-patch))) + (setf (patch-occupant next-patch) a) + (return-from random-move a)))) +