adding and dropping things works
authorChristopher Allan Webber <cwebber@dustycloud.org>
Mon, 9 May 2016 15:27:52 +0000 (10:27 -0500)
committerChristopher Allan Webber <cwebber@dustycloud.org>
Mon, 9 May 2016 15:27:52 +0000 (10:27 -0500)
mudsync/player.scm
mudsync/thing.scm
worlds/bricabrac.scm

index d2fc76dd64d1cbb15a4cf079bb3c9de8317761e9..172b81072b4e85e98fcf8536f91be5a9a1dccae3 100644 (file)
 
   ;; Get all the co-occupants' commands
   (define co-occupant-commands
-    ;; TODO: Switch this to a fold.  Ignore a result if it
-    ;;   returns false for in the command response
     (fold
      (lambda (co-occupant prev)
        (let* ((result (<-wait player co-occupant 'get-commands
      (val-or-run
       (slot-ref player 'self-commands))))
 
-  ;; TODO: Append our inventory's relevant command handlers
+  ;; Append our inventory's relevant command handlers
+  (define inv-items
+    (gameobj-occupants player))
+  (define inv-item-commands
+    (fold
+     (lambda (inv-item prev)
+       (let* ((result (<-wait player inv-item
+                              'get-contained-commands
+                              #:verb verb))
+              (commands (message-ref result 'commands))
+              (goes-by (message-ref result 'goes-by)))
+         (append
+          (map (lambda (command)
+                 (list command goes-by inv-item))
+               commands)
+          prev)))
+     '()
+     inv-items))
 
   ;; Now return a big ol sorted list of ((actor-id . command))
   (append
                                player-loc '()) ; room doesn't go by anything
    (sort-commands-multi-actors co-occupant-commands)
    (sort-commands-append-actor our-commands
-                               (actor-id player) '()))) ; nor does player
+                               (actor-id player) '()) ; nor does player
+   (sort-commands-multi-actors inv-item-commands)))
 
 (define (sort-commands-append-actor commands actor-id goes-by)
   (sort-commands-multi-actors
index 341371f7531dbccdd4de448b878524f5224e90da..a3ae6b003e3d706407252ca931e9f1fbd4d50a56 100644 (file)
   #:use-module (ice-9 format)
   #:export (<thing>
             thing-commands
+            thing-commands*
             thing-contained-commands
-            thing-actions))
+            thing-contained-commands*
+            thing-actions
+            thing-actions*))
 
 (define thing-commands
   (list
    (direct-command "take" 'cmd-take)))
 
-;;; Are these kinds of things useful?
-;; ;; Doesn't inherit anything (gameobj has no commands)
-;; ;; so it's an alias.
-;; (define thing-commands* thing-commands)
+;; Doesn't inherit anything (gameobj has no commands)
+;; so it's an alias.
+(define thing-commands* thing-commands)
 
 (define thing-contained-commands
   (list
-   (empty-command "drop" 'cmd-drop)))
+   (direct-command "drop" 'cmd-drop)))
 
-;; ;; Doesn't inherit anything (gameobj has no contained-commands)
-;; ;; so it's an alias.
-;; (define thing-contained-commands* thing-contained-commands)
+;; Doesn't inherit anything (gameobj has no contained-commands)
+;; so it's an alias.
+(define thing-contained-commands* thing-contained-commands)
 
 (define thing-actions
   (build-actions
     (message-ref
      (<-wait thing player 'get-name)
      'val))
+  (define player-loc
+    (message-ref
+     (<-wait thing player 'get-loc)
+     'val))
   (define thing-name (slot-ref thing 'name))
   (define should-take
     (slot-ref-maybe-runcheck thing 'takeable player))
@@ -93,7 +99,7 @@
         (<- thing player 'tell
             #:text (format #f "You pick up ~a.\n"
                            thing-name))
-        (<- thing (gameobj-loc thing) 'tell-room
+        (<- thing player-loc 'tell-room
             #:text (format #f "~a picks up ~a.\n"
                            player-name
                            thing-name)
index 7679735f813317fc4bae729165a36415cc9b583d..6be5b1aab45e05c05dae66478a562fa9cd0c1bc0 100644 (file)
 (define readable-commands
   (list
    (direct-command "read" 'cmd-read)))
+
+(define readable-commands*
+  (append readable-commands
+          thing-commands))
+
 (define readable-actions
   (build-actions
    (cmd-read (wrap-apply readable-cmd-read))))
 
-(define-class <readable> (<gameobj>)
+(define readable-actions*
+  (append readable-actions
+          thing-actions*))
+
+(define-class <readable> (<thing>)
   (read-text #:init-value "All it says is: \"Blah blah blah.\""
              #:init-keyword #:read-text)
   (commands
-   #:init-value readable-commands)
+   #:init-value readable-commands*)
   (message-handler
    #:init-value
-   (simple-dispatcher (append gameobj-actions readable-actions))))
+   (simple-dispatcher readable-actions*)))
 
 (define (readable-cmd-read actor message)
   (<- actor (message-from message) 'tell