Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defparameter *map* (make-hash-table))
- (define-condition make-error (error)
- ((args :initarg :args :reader make-error-args))
- (:report (lambda (condition stream)
- (format stream "Entry ~a not recognized."
- (make-error-args condition)))))
- (defmacro make-room (name &optional (title nil) &body forms)
- (labels ((is-direction-p (dir)
- (or
- (eq dir 'north)
- (eq dir 'south)
- (eq dir 'west)
- (eq dir 'east)
- (eq dir 'up)
- (eq dir 'down))))
- (let* ((exits nil)
- (funcs nil)
- (room
- (loop for f in forms append
- (let* ((key (car f))
- (rest (cdr f))
- (first (car rest)))
- (cond ((eq key 'loc) `(:loc ',first))
- ((eq key 'desc) `(:desc ',rest))
- ((eq key 'flags) `(:flags ',rest))
- ((eq key 'action) `(:action ,rest))
- ((eq key 'global) `(:global ',rest))
- ((is-direction-p key)
- (cond ((eq (cadr rest) 'if)
- (let* ((sym (gensym))
- (func (caddr rest))
- (else (last rest)))
- (push `(,sym ,func) funcs)
- (push `(list ',key ',first ,sym ',else) exits)))
- (t
- (push `(list ',key ',first) exits)))
- nil)
- (t
- (error 'make-error :args f)))))))
- `(let (,@funcs)
- (setf (gethash ',name *map*) (list :title ,title ,@room :exits (list ,@exits)))))))
- (defun have-boat ()
- (have 'boat))
- (make-room marsh "Marsh"
- (west marsh-wall if #'have-boat "You are stuck")
- (south stone-arch if #'have-boat "You are stuck"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement