(defpackage :if-lib\r
(:use :common-lisp :if-basic-lib :if-console)\r
(:export :container :room :item :clothing :capacity\r
- :food :switchable\r
+ :food :switchable :door :predoor\r
:n-to :ne-to :e-to :se-to :s-to :sw-to :w-to :nw-to :in-to :out-to\r
- :u-to :d-to :cant-go\r
+ :u-to :d-to :cant-go :destination\r
:*intscope* :*outscope* :*location* :*trace-light* :*vowels*\r
:*score* :*gamestate* :*turns* :*dark*\r
:add-to-scope :add-to-outscope :found-in :seen-from :with-keys\r
\r
;;SECTION 2: Library-defined classes and objects\r
\r
-(ifclass container () (capacity integer) (has :container))\r
+(ifclass predoor ()) ;;Can potentially be locked... \r
+\r
+(ifclass container (predoor) (capacity integer) (has :container))\r
(ifclass supporter () (capacity integer) (has :supporter))\r
\r
(ifclass room () (description string)\r
(look (look self)))\r
(has :~light))\r
\r
+(ifclass door (predoor scenery) (destination object) (has :door :closed))\r
+\r
+\r
+\r
;;Compass directions\r
(object compass ())\r
(object dir-n () "north" (name "north" "n") compass (property 'n-to))\r
(defpackage :verb-lib\r
(:use :common-lisp :if-lib :if-basic-lib)\r
(:export :attack :take :teleport :examine \r
- :go-to \r
+ :go-to :pass\r
:take :put-in :put-on :drop :receive\r
:wear :strip :enter :climb :drink :eat\r
:rub :turn :switch-on :switch-off\r
\r
(defaction go-to (dir)\r
(let ((destination (read-property *location* (property dir))))\r
- (if destination (go-to-room destination)\r
+ (if destination (exec go-to-dispatch (destination))\r
(if (provides *location* 'cant-go) \r
(read-property *location* 'cant-go)\r
"You can't go here."))))\r
\r
-;; (defaction go-n () (run-action 'go-to dir-n))\r
-;; (defaction go-ne () (run-action 'go-to dir-ne))\r
-;; (defaction go-e () (run-action 'go-to dir-e))\r
-;; (defaction go-se () (run-action 'go-to dir-se))\r
-;; (defaction go-s () (run-action 'go-to dir-s))\r
-;; (defaction go-sw () (run-action 'go-to dir-sw))\r
-;; (defaction go-w () (run-action 'go-to dir-w))\r
-;; (defaction go-nw () (run-action 'go-to dir-nw))\r
-;; (defaction go-u () (run-action 'go-to dir-u))\r
-;; (defaction go-d () (run-action 'go-to dir-d))\r
-;; (defaction go-in () (run-action 'go-to dir-in))\r
-;; (defaction go-out () (run-action 'go-to dir-out))\r
+(defgeneric go-to-dispatch (dest)\r
+ (:documentation "Dispatches between different kinds of goable objects"))\r
+\r
+(defmethod go-to-dispatch ((dest room))\r
+ (go-to-room dest))\r
+\r
+(defmethod go-to-dispatch ((dest door))\r
+ (unless (has dest :door) (return-from go-to-dispatch (call-next-method)))\r
+ (if (has dest :closed) (format nil "~a is closed." (the-name dest))\r
+ (run-action 'pass *args*)))\r
+\r
+(defaction pass (obj)\r
+ "Something's wrong happened.")\r
+\r
+(defmethod pass ((obj door))\r
+ (go-to-dispatch (read-property obj 'destination))\r
+ (run-action-after obj))\r
\r
(defun inventory ()\r
(sprint "You are carrying: ~a." (list-contents *player*))\r
(defaction open (obj)\r
"You cannot open this.")\r
\r
-(defmethod open ((obj container))\r
- (unless (and (has obj :container) (has obj :openable))\r
+(defmethod open ((obj predoor))\r
+ (unless (and (or (has obj :container) (has obj :door)) (has obj :openable))\r
(return-from open (call-next-method))) \r
(if (has obj :closed)\r
(if (hasnt obj :locked)\r
(defaction close (obj)\r
"You cannot close this.")\r
\r
-(defmethod close ((obj container))\r
- (unless (and (has obj :container) (has obj :openable))\r
+(defmethod close ((obj predoor))\r
+ (unless (and (or (has obj :container) (has obj :door)) (has obj :openable))\r
(return-from close (call-next-method)))\r
(if (hasnt obj :closed)\r
(progn \r
(defaction lock (obj key)\r
"Not lockable.")\r
\r
-(defmethod lock ((obj container) (key item))\r
- (unless (and (has obj :container) \r
+(defmethod lock ((obj predoor) (key item))\r
+ (unless (and (or (has obj :container) (has obj :door)) \r
(has obj :openable)\r
(has obj :lockable))\r
(return-from lock (call-next-method)))\r
(defaction unlock (obj key)\r
"There is nothing to unlock.")\r
\r
-(defmethod unlock ((obj container) (key item))\r
- (unless (and (has obj :container) \r
+(defmethod unlock ((obj predoor) (key item))\r
+ (unless (and (or (has obj :container) (has obj :door)) \r
(has obj :openable)\r
(has obj :lockable))\r
(return-from unlock (call-next-method)))\r
(defaction unlock-open (obj key)\r
"You cannot open this.")\r
\r
-(defmethod unlock-open ((obj container) (key item))\r
- (unless (and (has obj :container) \r
+(defmethod unlock-open ((obj predoor) (key item))\r
+ (unless (and (or (has obj :container) (has obj :door)) \r
(has obj :openable))\r
(return-from unlock-open (call-next-method)))\r
(and (run-action 'unlock *args*)\r