diff --git a/animals.lisp b/animals.lisp index 0406c30..d675bb5 100644 --- a/animals.lisp +++ b/animals.lisp @@ -19,7 +19,7 @@ (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)))) + (return-from random-move a)))) ;;XXX bird species? ;;XXX water species? diff --git a/animals.lisp b/animals.lisp index 0406c30..d675bb5 100644 --- a/animals.lisp +++ b/animals.lisp @@ -19,7 +19,7 @@ (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)))) + (return-from random-move a)))) ;;XXX bird species? ;;XXX water species? diff --git a/classes.lisp b/classes.lisp index 5d590b4..1a35ecd 100644 --- a/classes.lisp +++ b/classes.lisp @@ -7,18 +7,12 @@ ;;;; (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) - ;;XXX not sure yet how I'm going to use the actions - (update :accessor .update :initarg :update - :initform #'(lambda () NIL)) - (action :accessor .action :initarg :action - :initform #'(lambda () NIL)))) + (movable :reader movablep :initarg :movable :initform T))) (defclass destructable (item) ;; An item that can be destroyed @@ -35,10 +29,8 @@ ((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) - ;;XXX is there a way of setting a superclass variable for all - ;; subclass instances? - (movable :reader movablep :initarg :movable :initform NIL))) + (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. @@ -59,19 +51,21 @@ (defclass species (feature) ;; An animal species - ((strength :accessor .strength :initarg :strength :initform 1) + (;; 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 '()) - (update :accessor .update :initarg :update :initform #'random-move) - (destroy-with :reader destructors :initarg :destroy-with - :initform '(weapon)))) + ;; individual properties + (id :reader .id :initarg :id :initform -1) + (health :reader .health :initarg :health :initform 1)) + (:default-initargs :destroy-with '(weapon) :movable T)) -(defclass animal (species) - ;; An individual animal - ((id :reader .id :initarg :id :initform -1) - (position :reader .position :initform '(0 0)) - (health :reader .health :initform 1) - (species :reader .species :initform NIL))) +;; 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/animals.lisp b/animals.lisp index 0406c30..d675bb5 100644 --- a/animals.lisp +++ b/animals.lisp @@ -19,7 +19,7 @@ (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)))) + (return-from random-move a)))) ;;XXX bird species? ;;XXX water species? diff --git a/classes.lisp b/classes.lisp index 5d590b4..1a35ecd 100644 --- a/classes.lisp +++ b/classes.lisp @@ -7,18 +7,12 @@ ;;;; (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) - ;;XXX not sure yet how I'm going to use the actions - (update :accessor .update :initarg :update - :initform #'(lambda () NIL)) - (action :accessor .action :initarg :action - :initform #'(lambda () NIL)))) + (movable :reader movablep :initarg :movable :initform T))) (defclass destructable (item) ;; An item that can be destroyed @@ -35,10 +29,8 @@ ((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) - ;;XXX is there a way of setting a superclass variable for all - ;; subclass instances? - (movable :reader movablep :initarg :movable :initform NIL))) + (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. @@ -59,19 +51,21 @@ (defclass species (feature) ;; An animal species - ((strength :accessor .strength :initarg :strength :initform 1) + (;; 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 '()) - (update :accessor .update :initarg :update :initform #'random-move) - (destroy-with :reader destructors :initarg :destroy-with - :initform '(weapon)))) + ;; individual properties + (id :reader .id :initarg :id :initform -1) + (health :reader .health :initarg :health :initform 1)) + (:default-initargs :destroy-with '(weapon) :movable T)) -(defclass animal (species) - ;; An individual animal - ((id :reader .id :initarg :id :initform -1) - (position :reader .position :initform '(0 0)) - (health :reader .health :initform 1) - (species :reader .species :initform NIL))) +;; 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 3cb2630..d411280 100644 --- a/data.lisp +++ b/data.lisp @@ -7,6 +7,9 @@ ;;;; (c) 2018 Daniel Vedder, MIT license ;;;; +;; TODO save and load functions +;; XXX Will probably require `make-load-form-saving-slots' + ;;; PATCHES (let ((world NIL)) @@ -48,27 +51,8 @@ :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 +;;; ANIMALS +;; XXX Do I even need this code? (let ((max-id 0) (animals NIL)) (defun add-animal (species position) diff --git a/animals.lisp b/animals.lisp index 0406c30..d675bb5 100644 --- a/animals.lisp +++ b/animals.lisp @@ -19,7 +19,7 @@ (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)))) + (return-from random-move a)))) ;;XXX bird species? ;;XXX water species? diff --git a/classes.lisp b/classes.lisp index 5d590b4..1a35ecd 100644 --- a/classes.lisp +++ b/classes.lisp @@ -7,18 +7,12 @@ ;;;; (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) - ;;XXX not sure yet how I'm going to use the actions - (update :accessor .update :initarg :update - :initform #'(lambda () NIL)) - (action :accessor .action :initarg :action - :initform #'(lambda () NIL)))) + (movable :reader movablep :initarg :movable :initform T))) (defclass destructable (item) ;; An item that can be destroyed @@ -35,10 +29,8 @@ ((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) - ;;XXX is there a way of setting a superclass variable for all - ;; subclass instances? - (movable :reader movablep :initarg :movable :initform NIL))) + (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. @@ -59,19 +51,21 @@ (defclass species (feature) ;; An animal species - ((strength :accessor .strength :initarg :strength :initform 1) + (;; 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 '()) - (update :accessor .update :initarg :update :initform #'random-move) - (destroy-with :reader destructors :initarg :destroy-with - :initform '(weapon)))) + ;; individual properties + (id :reader .id :initarg :id :initform -1) + (health :reader .health :initarg :health :initform 1)) + (:default-initargs :destroy-with '(weapon) :movable T)) -(defclass animal (species) - ;; An individual animal - ((id :reader .id :initarg :id :initform -1) - (position :reader .position :initform '(0 0)) - (health :reader .health :initform 1) - (species :reader .species :initform NIL))) +;; 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 3cb2630..d411280 100644 --- a/data.lisp +++ b/data.lisp @@ -7,6 +7,9 @@ ;;;; (c) 2018 Daniel Vedder, MIT license ;;;; +;; TODO save and load functions +;; XXX Will probably require `make-load-form-saving-slots' + ;;; PATCHES (let ((world NIL)) @@ -48,27 +51,8 @@ :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 +;;; ANIMALS +;; XXX Do I even need this code? (let ((max-id 0) (animals NIL)) (defun add-animal (species position) diff --git a/naledi.lisp b/naledi.lisp index 7166bf4..1f06386 100644 --- a/naledi.lisp +++ b/naledi.lisp @@ -22,6 +22,8 @@ (load "animals.lisp") (defun start-game () + (setf *random-state* (make-random-state t)) + (create-world 250) (with-screen (scr :input-echoing nil :input-blocking t :enable-colors t :cursor-visibility nil :input-reading :unbuffered) (splash-screen scr) @@ -177,8 +179,4 @@ ;;TODO ) -;; Initialize the random state (which would otherwise not be very random...) -(setf *random-state* (make-random-state t)) - -(create-world 250) (start-game) diff --git a/animals.lisp b/animals.lisp index 0406c30..d675bb5 100644 --- a/animals.lisp +++ b/animals.lisp @@ -19,7 +19,7 @@ (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)))) + (return-from random-move a)))) ;;XXX bird species? ;;XXX water species? diff --git a/classes.lisp b/classes.lisp index 5d590b4..1a35ecd 100644 --- a/classes.lisp +++ b/classes.lisp @@ -7,18 +7,12 @@ ;;;; (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) - ;;XXX not sure yet how I'm going to use the actions - (update :accessor .update :initarg :update - :initform #'(lambda () NIL)) - (action :accessor .action :initarg :action - :initform #'(lambda () NIL)))) + (movable :reader movablep :initarg :movable :initform T))) (defclass destructable (item) ;; An item that can be destroyed @@ -35,10 +29,8 @@ ((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) - ;;XXX is there a way of setting a superclass variable for all - ;; subclass instances? - (movable :reader movablep :initarg :movable :initform NIL))) + (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. @@ -59,19 +51,21 @@ (defclass species (feature) ;; An animal species - ((strength :accessor .strength :initarg :strength :initform 1) + (;; 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 '()) - (update :accessor .update :initarg :update :initform #'random-move) - (destroy-with :reader destructors :initarg :destroy-with - :initform '(weapon)))) + ;; individual properties + (id :reader .id :initarg :id :initform -1) + (health :reader .health :initarg :health :initform 1)) + (:default-initargs :destroy-with '(weapon) :movable T)) -(defclass animal (species) - ;; An individual animal - ((id :reader .id :initarg :id :initform -1) - (position :reader .position :initform '(0 0)) - (health :reader .health :initform 1) - (species :reader .species :initform NIL))) +;; 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 3cb2630..d411280 100644 --- a/data.lisp +++ b/data.lisp @@ -7,6 +7,9 @@ ;;;; (c) 2018 Daniel Vedder, MIT license ;;;; +;; TODO save and load functions +;; XXX Will probably require `make-load-form-saving-slots' + ;;; PATCHES (let ((world NIL)) @@ -48,27 +51,8 @@ :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 +;;; ANIMALS +;; XXX Do I even need this code? (let ((max-id 0) (animals NIL)) (defun add-animal (species position) diff --git a/naledi.lisp b/naledi.lisp index 7166bf4..1f06386 100644 --- a/naledi.lisp +++ b/naledi.lisp @@ -22,6 +22,8 @@ (load "animals.lisp") (defun start-game () + (setf *random-state* (make-random-state t)) + (create-world 250) (with-screen (scr :input-echoing nil :input-blocking t :enable-colors t :cursor-visibility nil :input-reading :unbuffered) (splash-screen scr) @@ -177,8 +179,4 @@ ;;TODO ) -;; Initialize the random state (which would otherwise not be very random...) -(setf *random-state* (make-random-state t)) - -(create-world 250) (start-game) diff --git a/world.lisp b/world.lisp index fca163b..df9744f 100644 --- a/world.lisp +++ b/world.lisp @@ -117,7 +117,7 @@ (dolist (f flist NIL) (when (chancep (second f)) ;;FIXME I need to get an actual item and set its position - (return-from get-patch-feature (get-item-type (first f))))))) + (return-from get-patch-feature (make-instance (first f))))))) (defun generate-biomes (size-factor) ;;XXX The maps this produces don't look quite as expected, but for @@ -171,4 +171,5 @@ (when (patch-items p) ;;FIXME we will be dealing with instances here, not names... (format NIL "The following items are here:~A *~A" #\newline - (string-from-list (patch-items p) (format NIL "~% *")))))) + (string-from-list (mapcar #'.name (patch-items p)) + (format NIL "~% *"))))))