From: grue Date: Sun, 2 Jul 2006 16:57:03 +0000 (+0000) Subject: open,close X-Git-Url: https://jxself.org/git/?p=lifp.git;a=commitdiff_plain;h=e4d49c347b683ad27be42750e0d9117384fb6c23 open,close darcs-hash:426a8ec95463a391f93a39cc9400474b189da409 --- diff --git a/iflib.lisp b/iflib.lisp index 1193606..853d89d 100644 --- a/iflib.lisp +++ b/iflib.lisp @@ -79,7 +79,7 @@ "Turns passed since beginning of the game") (defparameter *player* nil - "Current player object (will be initialised later") + "Current player object (will be initialised later)") (declare-predicate add-to-scope add-to-outscope found-in seen-from) @@ -681,7 +681,7 @@ `(defpackage ,name (:use :common-lisp :if-basic-lib :if-lib :verb-lib ,@other-packages) (:shadowing-import-from :if-lib :room) - (:shadowing-import-from :verb-lib :listen :fill))) + (:shadowing-import-from :verb-lib :listen :fill :open :close))) (defmacro free-symbol (id) "Frees a symbol from current package using shadow" diff --git a/verbs.lisp b/verbs.lisp index 0adf53c..d10da4d 100644 --- a/verbs.lisp +++ b/verbs.lisp @@ -17,8 +17,8 @@ :take :put-in :put-on :drop :receive :wear :strip :enter :climb :drink :eat :rub :turn :switch-on :switch-off - :fill :empty :extract :let-go) - (:shadow :listen :fill) + :fill :empty :extract :let-go :open :close) + (:shadow :listen :fill :open :close) (:shadowing-import-from :if-lib :room)) (in-package :verb-lib) @@ -174,7 +174,21 @@ (verb "empty" '(:noun -> empty)) +(verb "open" + '(:noun -> open) + '(:noun "with" :held -> unlock-open)) +(verb "close" '(:noun -> close)) +(verb "shut" + '(:noun -> close) + '("off" :noun -> switch-off) + '(:noun "off" -> switch-off)) + +(verb "lock" + '(:noun "with" :held -> lock)) +(verb "unlock" + '(:noun "with" :held -> unlock)) + (defaction attack (obj) "Violence is not the answer.") @@ -338,7 +352,7 @@ "This action achieves nothing.") (defaction turn (what) - "That's fixed in place") + "That's fixed in place.") (defmethod turn ((item item)) (if (has item :item) @@ -417,3 +431,26 @@ (defmethod let-go ((host container) (item item)) (move item (parent host)) (run-action-after host)) + +(defaction open (obj) + "You cannot open this") + +(defmethod open ((obj container)) + (unless (has obj :container) (return-from open (call-next-method))) + (if (has obj :closed) + (if (hasnt obj :locked) + (progn + (give obj :~closed) + (when (run-action-after obj) + (format nil "You open ~a." (the-name obj)))) + "It's locked.") + (format nil "~a is already open." (the-name obj)))) + +(defmethod close ((obj container)) + (unless (has obj :container) (return-from closed (call-next-method))) + (if (hasnt obj :closed) + (progn + (give obj :closed) + (when (run-action-after obj) + (format nil "You close ~a." (the-name obj)))) + (format nil "~a is already closed." (the-name obj))))