Newer
Older
naledi / classes.lisp
;;;;
;;;; Terra Nostra is a Minecraft-like survival game for the commandline.
;;;;
;;;; 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)
		;;XXX not sure yet how I'm going to use the actions
		(action :accessor .action :initarg :action
			:initform #'(lambda () NIL))))

(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)
		;;XXX is there a way of setting a superclass variable for all
		;; subclass instances?
		(movable :reader movablep :initarg :movable :initform 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) ;XXX inherit from `feature' or `destructable'?
	;; An animal species
	((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 '())
		(destroy-with :reader destructors :initarg :destroy-with
			:initform '(weapon))))

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