# HG changeset patch # User Steve Losh # Date 1470668427 0 # Node ID 62acd4bfdc0f02b601e9b996e82f201cd32f0b8b # Parent 0f17d55b8f34a1c53fcb53b979655171aebe296b Add the colossus and clean up the inspection a bit diff -r 0f17d55b8f34 -r 62acd4bfdc0f silt.lisp --- a/silt.lisp Mon Aug 08 14:31:14 2016 +0000 +++ b/silt.lisp Mon Aug 08 15:00:27 2016 +0000 @@ -59,9 +59,9 @@ (+color-black-white+ charms/ll:COLOR_BLACK charms/ll:COLOR_WHITE) (+color-black-yellow+ charms/ll:COLOR_BLACK charms/ll:COLOR_YELLOW) - (+color-white-blue+ charms/ll:COLOR_WHITE charms/ll:COLOR_BLUE)) + (+color-white-blue+ charms/ll:COLOR_WHITE charms/ll:COLOR_BLUE) - + (+color-white-red+ charms/ll:COLOR_WHITE charms/ll:COLOR_RED)) (defmacro with-color (color &body body) (once-only (color) @@ -261,6 +261,9 @@ (setf *timing* (cons 0 0))) +(defmacro modf (place n) + `(zap% ,place #'mod % ,n)) + ;;;; Terrain Generation ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun average4 (a b c d) @@ -760,6 +763,7 @@ (defun creature-mutate (c) (let ((v (random 1.0))) + (declare (ignore v)) (cond (t (setf (visible/glyph c) (random-elt #("@" "$" "?" "!" "&" "+"))))))) @@ -852,6 +856,19 @@ (define-entity fountain (coords visible sentient flavor inspectable) (recent :initform (make-ticklist) :accessor fountain-recent)) +(define-entity colossus (coords visible sentient flavor inspectable) + (counter :initform 1 :accessor colossus-counter) + (next :initform 1000 :accessor colossus-next)) + + +(defun colossus-act (c) + (with-slots (counter next) c + (incf counter) + (modf counter next) + (when (zerop counter) + (setf next (random-range 1000 4000)) + (coords-move-entity c (1+ (coords/x c)) (coords/y c)) + (log-message "The colossus takes a step.")))) (defun monolith-act (m) (when (zerop *population*) @@ -865,7 +882,6 @@ "The monolith flashes brightly and ~A appears in front of it!" <>))))))) - (defun fountain-act (f) (zapf (fountain-recent f) #'ticklist-tick) (iterate @@ -896,12 +912,24 @@ :visible/glyph "ƒ" :visible/color +color-white-blue+ :sentient/function 'fountain-act - :inspectable/slots '(fountain-recent) + :inspectable/slots '(recent) :flavor/text '("A marble fountain burbles peacefully here."))) +(defun make-colossus () + (create-entity 'colossus + :coords/x 10 + :coords/y 0 + :visible/glyph "@" + :visible/color +color-white-red+ + :sentient/function 'colossus-act + :inspectable/slots '(counter next) + :flavor/text + '("A massive granite statue of an alien being."))) + (defun generate-mysteries () + (make-colossus) (make-fountain) (make-monolith)) @@ -1044,9 +1072,15 @@ (when (typep entity 'inspectable) (appending - (indent (iterate - (for slot :in (inspectable/slots entity)) - (collect (format nil "~A ~A" slot (funcall slot entity))))) + (indent + (iterate + (with slots = (inspectable/slots entity)) + (with width = (apply #'max + (mapcar (compose #'length #'symbol-name) + slots))) + (for slot :in slots) + (collect (format nil "~vA ~A" + width slot (slot-value entity slot))))) :into text)) (collecting "" :into text))