;; 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
#: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))
(<- 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)
(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