lock,unlock
Wed Jul 5 02:23:31 PDT 2006 grue@mail.ru
* lock,unlock
diff -rN -u old-lifp/iflib.lisp new-lifp/iflib.lisp
--- old-lifp/iflib.lisp 2014-07-12 00:57:46.000000000 -0700
+++ new-lifp/iflib.lisp 2014-07-12 00:57:46.000000000 -0700
@@ -81,8 +81,8 @@
(defparameter *player* nil
"Current player object (will be initialised later)")
-(declare-predicate add-to-scope add-to-outscope found-in seen-from)
-
+(declare-predicate add-to-scope add-to-outscope found-in seen-from
+ with-keys)
;;Library file names
(defvar *library-file-if* "if.fas")
diff -rN -u old-lifp/verbs.lisp new-lifp/verbs.lisp
--- old-lifp/verbs.lisp 2014-07-12 00:57:46.000000000 -0700
+++ new-lifp/verbs.lisp 2014-07-12 00:57:46.000000000 -0700
@@ -17,7 +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 :open :close)
+ :fill :empty :extract :let-go :open :close
+ :lock :unlock :open-unlock)
(:shadow :listen :fill :open :close)
(:shadowing-import-from :if-lib :room))
@@ -433,10 +434,11 @@
(run-action-after host))
(defaction open (obj)
- "You cannot open this")
+ "You cannot open this.")
(defmethod open ((obj container))
- (unless (has obj :container) (return-from open (call-next-method)))
+ (unless (and (has obj :container) (has obj :openable))
+ (return-from open (call-next-method)))
(if (has obj :closed)
(if (hasnt obj :locked)
(progn
@@ -446,11 +448,65 @@
"It's locked.")
(format nil "~a is already open." (the-name obj))))
+(defaction close (obj)
+ "You cannot close this.")
+
(defmethod close ((obj container))
- (unless (has obj :container) (return-from closed (call-next-method)))
+ (unless (and (has obj :container) (has obj :openable))
+ (return-from close (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))))
+
+(defaction lock (obj key)
+ "Not lockable.")
+
+(defmethod lock ((obj container) (key item))
+ (unless (and (has obj :container)
+ (has obj :openable)
+ (has obj :lockable))
+ (return-from lock (call-next-method)))
+ (if (has obj :locked)
+ (format nil "~a is already locked." (the-name obj))
+ (if (hasnt obj :closed)
+ (format nil "~a is not closed." (the-name obj))
+ (if (with-keys obj key)
+ (progn
+ (give obj :locked)
+ (when (run-action-after obj)
+ (format nil "You lock ~a." (the-name obj))))
+ (format nil "You cannot lock ~a with ~a."
+ (the-name obj) (the-name key))))))
+
+(defaction unlock (obj key)
+ "There is nothing to unlock.")
+
+(defmethod unlock ((obj container) (key item))
+ (unless (and (has obj :container)
+ (has obj :openable)
+ (has obj :lockable))
+ (return-from unlock (call-next-method)))
+ (if (hasnt obj :locked)
+ (format nil "~a is already unlocked." (the-name obj))
+ (if (hasnt obj :closed)
+ (format nil "~a is not closed." (the-name obj))
+ (if (with-keys obj key)
+ (progn
+ (give obj :~locked)
+ (when (run-action-after obj)
+ (format nil "You unlock ~a." (the-name obj))))
+ (format nil "You cannot unlock ~a with ~a."
+ (the-name obj) (the-name key))))))
+
+(defaction open-unlock (obj key)
+ "You cannot open this.")
+
+(defmethod open-unlock ((obj container) (key item))
+ (unless (and (has obj :container)
+ (has obj :openable))
+ (return-from open-unlock (call-next-method)))
+ (and (run-action 'unlock *args*)
+ (run-action 'open obj)))