Newer
Older
naledi / item-classes.lisp
;;;;
;;;; 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 animal (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)
		(last-move :accessor .last-move :initform 0))
	(:default-initargs :destroy-with '(weapon) :movable T))

;;TODO (defclass player (feature)

;; 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)))))