X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=iflib.lisp;h=0684f32c18e601843949eae2649459ac8d84539c;hb=1f02beed487906a8be49f59dff91d16e7e5fd775;hp=8ed948098176870efde758fdbc3d4333005477c7;hpb=4b3d4fbf3031334896e98a3da1dbc8820abb0c17;p=lifp.git diff --git a/iflib.lisp b/iflib.lisp index 8ed9480..0684f32 100644 --- a/iflib.lisp +++ b/iflib.lisp @@ -37,10 +37,11 @@ :reset-scope :look :words2dic-first :disambig :normal-token-scope :input-quit-loop :quit-game :prompt :prompt-read :input-loop-step :go-to-room :property :init :test-seq - :heldp :the-name :each-turn + :heldp :the-name :each-turn :daemon :time-left :time-out + :start-daemon :stop-daemon :start-timer :stop-timer :supporter :animate :scenery :afterlife :print-gamestate :end-game - :repl-mode :compile-lib + :repl-mode :compile-lib :free-symbol ) (:shadow :room)) @@ -82,6 +83,12 @@ (declare-predicate add-to-scope add-to-outscope found-in seen-from) + +;;Library file names +(defvar *library-file-if* "if.fas") +(defvar *library-file-iflib* "if.fas") +(defvar *library-file-verbs* "if.fas") + ;;SECTION 2: Library-defined classes and objects (ifclass container () (capacity integer) (has :container)) @@ -256,7 +263,7 @@ (defun print-property (obj property) "Print a property of object" (multiple-value-bind (value printp) (read-property obj property) - (if (and (stringp value) (not printp)) (sprint value) value))) + (if (and (stringp value) (not printp)) (progn (sprint value) t) printp))) (defgeneric print-name (obj &key article capital) (:documentation "Returns a string containing the name of object")) @@ -507,11 +514,33 @@ (supply turn-passing (&optional time) (reset-scope) (incf *turns* time) - (loop for x in *outscope* + (loop for x in *allobjects* + if (and (has x :daemon) (provides x 'daemon)) + do (read-property- :execute x 'daemon) + if (and (has x :timer) (provides x 'time-left) + (provides x 'time-out)) + do (if (zerop (slot-value x 'time-left)) + (read-property- :execute x 'time-out) + (decf (slot-value x 'time-left)))) + (loop for x in *outscope* if (provides x 'each-turn) - do (read-property-execute (slot-value x 'each-turn))) + do (read-property- :execute x 'each-turn)) (call-next-method)) +(defun start-daemon (obj) + (give obj :daemon)) + +(defun stop-daemon (obj) + (give obj :~daemon)) + +(defun start-timer (obj time) + (assert (provides obj 'time-left)) + (setf (slot-value obj 'time-left) time) + (give obj :timer)) + +(defun stop-timer (obj) + (give obj :~timer)) + (defgeneric before-special-rule (location) (:documentation "Runs on location before other before effects are runned") (:method (location) (declare (ignore location)) nil)) @@ -611,19 +640,19 @@ (defun lib (file dir) "Reloads the IF library" (format t "[DIRECTORY: ~a]~%" dir) - (print-message "Loading if.fas...") - (load (merge-pathnames dir "if.fas")) - (print-message "Loading iflib.fas...") - (load (merge-pathnames dir "iflib.fas")) - (print-message "Loading verbs.fas...") - (load (merge-pathnames dir "verbs.fas")) + (print-message "Loading if-basic-lib...") + (load (merge-pathnames dir *library-file-if*)) + (print-message "Loading if-lib...") + (load (merge-pathnames dir *library-file-iflib*)) + (print-message "Loading verbs...") + (load (merge-pathnames dir *library-file-verbs*)) (print-message "Loading game module...") (load file) (print-message "Module is successfully loaded.")) -(defun test-seq (&optional (rm nil)) +(defun test-seq (&optional (rm *repl-mode*)) "Test sequence emulating interactive fiction interpreter" - (load-cfg "iflib.cfg") + ;;(load-cfg "iflib.cfg") (setf *score* 0 *turns* 0 *gamestate* 0) @@ -640,8 +669,9 @@ (defun interactive-start () "Function intended to be used by user" (load-cfg "iflib.cfg") - (run-console #'seq #'lib :interactive t) - (when *hard-quit* (quit-lisp))) + (unless *repl-mode* + (run-console #'seq #'lib :interactive t) + (when *hard-quit* (quit-lisp)))) ;;SECTION 9: Other stuff @@ -651,7 +681,13 @@ `(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))) + (:shadowing-import-from :verb-lib :listen :fill))) + +(defmacro free-symbol (id) + "Frees a symbol from current package using shadow" + `(eval-when (:compile-toplevel :load-toplevel :execute) + (shadow ,id))) + (defun repl-mode (&optional (mode :unspecified)) "Flip the using of REPL for input and output (as opposed to