more dynamic dispatch of commands
authorChristopher Allan Webber <cwebber@dustycloud.org>
Wed, 4 May 2016 18:57:42 +0000 (13:57 -0500)
committerChristopher Allan Webber <cwebber@dustycloud.org>
Wed, 4 May 2016 18:57:42 +0000 (13:57 -0500)
mudsync/gameobj.scm
mudsync/room.scm

index 37f8bfefa8d07ebb85be81a9e17705089703f2b8..921850eef534cde51c23a18a1d9be3a7d91d493c 100644 (file)
@@ -24,6 +24,7 @@
   #:use-module (8sync systems actors)
   #:use-module (8sync agenda)
   #:use-module (srfi srfi-1)
   #:use-module (8sync systems actors)
   #:use-module (8sync agenda)
   #:use-module (srfi srfi-1)
+  #:use-module (ice-9 match)
   #:use-module (oop goops)
   #:export (<gameobj>
             gameobj-simple-name-f
   #:use-module (oop goops)
   #:export (<gameobj>
             gameobj-simple-name-f
     (reply-message actor message
                    #:val (slot-ref actor slot))))
 
     (reply-message actor message
                    #:val (slot-ref actor slot))))
 
+(define (val-or-run val-or-proc)
+  "Evaluate if a procedure, or just return otherwise"
+  (if (procedure? val-or-proc)
+      (val-or-proc)
+      val-or-proc))
+
 (define (filter-commands commands verb)
   (filter
    (lambda (cmd)
 (define (filter-commands commands verb)
   (filter
    (lambda (cmd)
 
 (define-mhandler (gameobj-get-commands actor message verb)
   (define filtered-commands
 
 (define-mhandler (gameobj-get-commands actor message verb)
   (define filtered-commands
-    (filter-commands (slot-ref actor 'commands)
+    (filter-commands (val-or-run (slot-ref actor 'commands))
                      verb))
   (<-reply actor message #:commands filtered-commands))
 
 (define-mhandler (gameobj-get-container-commands actor message verb)
   (define filtered-commands
                      verb))
   (<-reply actor message #:commands filtered-commands))
 
 (define-mhandler (gameobj-get-container-commands actor message verb)
   (define filtered-commands
-    (filter-commands (slot-ref actor 'container-commands)
+    (filter-commands (val-or-run (slot-ref actor 'container-commands))
                      verb))
   (<-reply actor message #:commands filtered-commands))
 
                      verb))
   (<-reply actor message #:commands filtered-commands))
 
index ddf74301056ebae2fa6aeaeb114d8a506f2e3840..b2d23e652a5f654cca29dc06b1e2b0007b87984c 100644 (file)
   (list
    (loose-direct-command "look" 'cmd-look-at)
    (empty-command "look" 'cmd-look-room)
   (list
    (loose-direct-command "look" 'cmd-look-at)
    (empty-command "look" 'cmd-look-room)
+   (empty-command "go" 'cmd-go-where)
    (loose-direct-command "go" 'cmd-go)))
 
    (loose-direct-command "go" 'cmd-go)))
 
+(define room-actions
+  (build-actions
+   ;; desc == description
+   (wire-exits! (wrap-apply room-wire-exits!))
+   (cmd-go (wrap-apply room-cmd-go))
+   (cmd-go-where (wrap-apply room-cmd-go-where))
+   (cmd-look-room (wrap-apply room-cmd-look-room))))
+
+(define room-actions*
+  (append room-actions gameobj-actions))
+
+(define room-action-dispatch
+  (simple-dispatcher room-actions*))
+
 ;; TODO: Subclass from container?
 (define-class <room> (<gameobj>)
   ;; A list of <exit>
 ;; TODO: Subclass from container?
 (define-class <room> (<gameobj>)
   ;; A list of <exit>
@@ -79,7 +94,7 @@
          #:getter room-exits)
 
   (container-commands
          #:getter room-exits)
 
   (container-commands
-   #:init-value %room-contain-commands)
+   #:init-value (wrap %room-contain-commands))
 
   (message-handler
    #:allocation #:each-subclass
 
   (message-handler
    #:allocation #:each-subclass
    #:init-value (wrap-apply room-action-dispatch)))
 
 
    #:init-value (wrap-apply room-action-dispatch)))
 
 
-(define room-actions
-  (build-actions
-   ;; desc == description
-   (wire-exits! (wrap-apply room-wire-exits!))
-   (cmd-go (wrap-apply room-cmd-go))
-   (cmd-look-room (wrap-apply room-cmd-look-room))))
-
-(define room-actions*
-  (append room-actions gameobj-actions))
-
-(define room-action-dispatch
-  (simple-dispatcher room-actions*))
-
-
 (define (room-wire-exits! room message)
   "Actually hook up the rooms' exit addresses to the rooms they
 claim to point to."
 (define (room-wire-exits! room message)
   "Actually hook up the rooms' exit addresses to the rooms they
 claim to point to."
@@ -131,5 +132,9 @@ claim to point to."
     (<- room (message-from message) 'tell
         #:text "I don't know where that is?\n"))))
 
     (<- room (message-from message) 'tell
         #:text "I don't know where that is?\n"))))
 
+(define-mhandler (room-cmd-go-where room message)
+  (<- room (message-from message) 'tell
+      #:text "Go where?\n"))
+
 (define-mhandler (room-cmd-look-room room message)
   (<- room (message-from message) 'look-room))
 (define-mhandler (room-cmd-look-room room message)
   (<- room (message-from message) 'look-room))