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