X-Git-Url: https://jxself.org/git/?p=mudsync.git;a=blobdiff_plain;f=mudsync%2Froom.scm;h=c4305233672755dad1f35c50057de342ec40ae33;hp=10932c9314fa3ff9e3b2bb7285e57ac6e562ddee;hb=095dde9158621c8bb3d690feaa0d525a76342eb9;hpb=4d1280ec16d7645817bf741cde658e358de66327 diff --git a/mudsync/room.scm b/mudsync/room.scm index 10932c9..c430523 100644 --- a/mudsync/room.scm +++ b/mudsync/room.scm @@ -35,10 +35,7 @@ ;;; ===== (define-class () - ;; Used for wiring - (to-symbol #:init-keyword #:to-symbol) - ;; The actual address we use - (to-address #:init-keyword #:address) + (to #:init-keyword #:to) ;; Name of the room (@@: Should this be names?) (name #:getter exit-name #:init-keyword #:name) @@ -72,21 +69,22 @@ (empty-command "look" 'cmd-look-room) (empty-command "go" 'cmd-go-where) (loose-direct-command "go" 'cmd-go) - ;; (greedy-command "say" 'cmd-say) - )) + (greedy-command "say" 'cmd-say) + (greedy-command "emote" 'cmd-emote))) (define room-actions (build-actions - ;; desc == description - (init (wrap-apply room-init)) - (wire-exits! (wrap-apply room-wire-exits!)) (cmd-go (wrap-apply room-cmd-go)) (cmd-go-where (wrap-apply room-cmd-go-where)) + (announce-entrance (wrap-apply room-announce-entrance)) (look-room (wrap-apply room-look-room)) + (tell-room (wrap-apply room-act-tell-room)) ;; in this case the command is the same version as the normal ;; look-room version (cmd-look-room (wrap-apply room-look-room)) - (cmd-look-at (wrap-apply room-look-at)))) + (cmd-look-at (wrap-apply room-look-at)) + (cmd-say (wrap-apply room-cmd-say)) + (cmd-emote (wrap-apply room-cmd-emote)))) (define room-actions* (append room-actions gameobj-actions)) @@ -109,37 +107,34 @@ ;; @@: Can remove this indirection once things settle #:init-value (wrap-apply room-action-dispatch))) -(define (room-init room message) - (room-wire-exits! room)) - -(define (room-wire-exits! room) - "Actually hook up the rooms' exit addresses to the rooms they -claim to point to." - (for-each - (lambda (exit) - (define new-exit - (message-ref - (<-wait room (gameobj-gm room) 'lookup-special - #:symbol (slot-ref exit 'to-symbol)) - 'room-id)) - - (slot-set! exit 'to-address new-exit)) - - (room-exits room))) - (define-mhandler (room-cmd-go room message direct-obj) (define exit (find (lambda (exit) (equal? (exit-name exit) direct-obj)) (room-exits room))) + (define to-address (if exit + ;; Get the exit, but resolve it dynamically + ;; in case it's a special + (dyn-ref room (slot-ref exit 'to)) + #f)) + (define player-name + (message-ref (<-wait room (message-from message) + 'get-name) 'val)) (cond (exit ;; Set the player's new location (<-wait room (message-from message) 'set-loc! - #:loc (slot-ref exit 'to-address)) + #:loc to-address) + ;; Tell everyone else the person walked away + (room-tell-room + room + (format #f "~a wanders ~a.\n" + player-name direct-obj)) + (<- room to-address 'announce-entrance + #:who-entered (message-from message)) ;; Have the new room update the player to the new location - (<- room (slot-ref exit 'to-address) 'look-room + (<- room to-address 'look-room #:to-id (message-from message))) (else (<- room (message-from message) 'tell @@ -227,7 +222,6 @@ claim to point to." (define goes-by (message-ref (<-wait room occupant 'goes-by) 'goes-by #f)) - (display "here!\n") (if (member called-this goes-by) (return occupant))) (hash-map->list (lambda (key val) key) @@ -235,7 +229,7 @@ claim to point to." #f))) (define %formless-desc - "You don't see anything special about it.") + "You don't see anything special.") (define-mhandler (room-look-at room message direct-obj) "Look at a specific object in the room." @@ -257,3 +251,52 @@ claim to point to." (else (<- room (message-from message) 'tell #:text "You don't see that here, so you can't look at it.\n")))) + + +(define* (room-tell-room room text #:key exclude wait) + (define who-to-tell (gameobj-occupants room #:exclude exclude)) + (for-each + (lambda (tell-me) + ;; @@: Does anything really care? + (define deliver-method + (if wait + <-wait + <-)) + (deliver-method room tell-me 'tell + #:text text)) + who-to-tell)) + +(define-mhandler (room-act-tell-room room message text) + "Tell the room some messages." + (define exclude (message-ref message 'exclude #f)) + (define wait-delivery (message-ref message 'wait #f)) + (room-tell-room room text + #:exclude exclude + #:wait wait-delivery)) + +(define-mhandler (room-cmd-say room message phrase) + "Command: Say something to room participants." + (define player-name + (message-ref (<-wait room (message-from message) + 'get-name) 'val)) + (define message-to-send + (format #f "~a says: ~a\n" player-name phrase)) + (room-tell-room room message-to-send)) + +(define-mhandler (room-cmd-emote room message phrase) + "Command: Say something to room participants." + (define player-name + (message-ref (<-wait room (message-from message) + 'get-name) 'val)) + (define message-to-send + (format #f "* ~a ~a\n" player-name phrase)) + (room-tell-room room message-to-send)) + +(define-mhandler (room-announce-entrance room message who-entered) + (define player-name + (message-ref (<-wait room who-entered 'get-name) + 'val)) + (define message-to-send + (format #f "~a enters the room.\n" player-name)) + (room-tell-room room message-to-send + #:exclude who-entered))