;;; The SIM-OBJECT class that gives the basic state and functionality ;;; for all objects that populate the world (including the agent's body). (defstruct (sim-object (:print-function print-sim-object)) "A sim-object is anything that occupies space. Some objects are 'alive'." (name "?") ; Used to print the object on the map (alive? nil) ; Is the object alive? (loc (@ 1 1)) ; The square that the object is in (bump nil) ; Has the object bumped into something? (size 0.5) ; Size of object as proportion of loc (color 'black) ; Some objects have a color (shape 'rectangle) ; Some objects have a shape (sound nil) ; Some objects create a sound (contents '()) ; Some objects contain others (max-contents 0) ; How much (total size) can fit inside? (container nil) ; The object's current container in the simulation (heading (@ 1 0)) ; Direction object is facing as unit vector (grabable? T) ) (defun print-sim-object (object stream depth) "Show an object's name, and if it is alive, the direction it faces." (declare (ignore depth)) (let ((name (or (sim-object-name object) (type-of object)))) (if (sim-object-alive? object) (format stream "~A~A" name (heading->string (sim-object-heading object))) (format stream "~A" name)))) ;;;***************************************************************** ;;; Here are some common objects in the grid world: (defstruct (obstacle (:include sim-object (name "#") (container NIL) (grabable? NIL)))) (defstruct (wall (:include obstacle))) (defstruct (agent-body (:include sim-object (name "A") (grabable? NIL) (alive? T))))