;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Questions ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; Globals (define *game* empty) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; Questioning (defclass () (question :type :initarg :question :accessor question) (answer :type :initarg :answer :accessor answer)) (defclass () (questions :type :initarg :questions :accessor questions :initvalue empty)) ;;; Adds this question to the (define (add-question (questioned ) (question )) (set! (questions questioned) (append! (questions questioned) (list question)))) (letrec ((question-action (lambda (plyr inp) (let ((char (nick-find (second inp) (contents (location plyr))))) (cond ((not char) (echos "You look, but you can't find" (second inp))) ((not (instance-of? char )) (echos (name char) "cannot answer your questions")) (else (let* ((charqs (questions char)) (qlist (list (first charqs) (second charqs) (random-elt (tail (tail charqs)))))) (for-each (lambda (n q) (tell plyr (echos-ns "Question " n ":")) (tell plyr (add " " q))) '(1 2 3) (map question qlist)) (let ((selection (no-errors (read-from-string (get-player-input plyr "Which question? "))))) (when (and (integer? selection) (< 0 selection) (> 4 selection)) (tell plyr "") (tell plyr (add " " (answer (list-ref qlist (sub1 selection))))) (tell plyr "") (question-action plyr inp)))))) 0))) (qcommand (make :desc "question Ask the character a question" :specs (list :or (list 'q symbol?) (list 'question symbol?)) :namespace 'context :func question-action))) (defmethod (commands (plyr ) (questioned )) (append (call-next-method) (list qcommand)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; Global game definition for questions (defclass () (murderer :type :accessor murderer :initarg :murderer) (mquestions :type :accessor mquestions :initarg :mquestions) (secondary1 :type :accessor secondary1 :initarg :secondary1) (s1questions :type :accessor s1questions :initarg :s1questions) (secondary2 :type :accessor secondary2 :initarg :secondary2) (s2questions :type :accessor s2questions :initarg :s2questions)) (define (make-a-murder murderer mquestions secondary1 s1questions secondary2 s2questions) (set! *game* (cons (make :murderer murderer :mquestions mquestions :secondary1 secondary1 :s1questions s1questions :secondary2 secondary2 :s2questions s2questions) *game*)))