See objects in the same room as you
authorChristopher Allan Webber <cwebber@dustycloud.org>
Thu, 5 May 2016 19:35:45 +0000 (14:35 -0500)
committerChristopher Allan Webber <cwebber@dustycloud.org>
Thu, 5 May 2016 19:35:45 +0000 (14:35 -0500)
mudsync/game-master.scm
mudsync/gameobj.scm
mudsync/room.scm

index aab0b7a856820a1a6a18071b361d421b73518cc6..34476b0077a892aaa553813e73df8d30f6676d3c 100644 (file)
@@ -190,7 +190,7 @@ with an anonymous persona"
              ;; create and register the player
              (player
               (create-actor* gm (@@ (mudsync player) <player>) "player"
-                             #:username guest-name
+                             #:name guest-name
                              #:gm (actor-id gm)
                              #:client client-id)))
         (display "Are we broke yet?\n")
index 1d120072380ad17d49b276c016beba8a729ace47..827876955432036712c4f8bae655f89573e66ee6 100644 (file)
@@ -52,7 +52,8 @@
    (set-loc! (wrap-apply gameobj-set-loc!))
    (get-name (wrap-apply gameobj-get-name))
    (get-desc (wrap-apply gameobj-get-desc))
-   (goes-by (wrap-apply gameobj-goes-by))))
+   (goes-by (wrap-apply gameobj-goes-by))
+   (visible-name (wrap-apply gameobj-visible-name))))
 
 ;;; *all* game components that talk to players should somehow
 ;;; derive from this class.
   (container-commands #:init-value '())
   (message-handler
    #:init-value
-   (simple-dispatcher gameobj-actions)))
+   (simple-dispatcher gameobj-actions))
+
+  ;; Most objects are generally visible by default
+  (generally-visible #:init-value #t)
+  ;; @@: Would be preferable to be using generic methods for this...
+  ;;   Hopefully we can port this to Guile 2.2 soon...
+  (visible-to-player?
+   #:init-value (wrap-apply gameobj-visible-to-player?)))
 
 
 ;;; gameobj message handlers
 (define (gameobj-simple-name-f gameobj)
   "Simplest version: return ourselves for our name."
   (gameobj-name gameobj))
+
+(define (gameobj-visible-to-player? gameobj whos-looking)
+  "Check to see whether we're visible to the player or not.
+By default, this is whether or not the generally-visible flag is set."
+  (slot-ref gameobj 'generally-visible))
+
+(define-mhandler (gameobj-visible-name actor message whos-looking)
+  ;; Are we visible?
+  (define we-are-visible
+    ((slot-ref actor 'visible-to-player?) actor whos-looking))
+
+  (define name-to-return
+    (if we-are-visible
+        ;; Return our name
+        (match (slot-ref actor 'name)
+          ((? procedure? name-proc)
+           (name-proc actor whos-looking))
+          ((? string? name)
+           name)
+          (#f #f))
+        #f))
+  (<-reply actor message #:text name-to-return))
index aee0636ab4c817c6e9c985d18c6bee1ef2b888e9..efc2a380e9b2ea13436c1207cd51737b7cdd6ace 100644 (file)
@@ -147,14 +147,63 @@ claim to point to."
 
 ;;; look commands
 
+(define (list-words-as-string words)
+  "A little utility for listing a bunch of words in an English-style list"
+  ;; TODO: This could be made faster by traversing the O(n)
+  ;;   list once, not twice
+  (let ((word-length (length words)))
+    (cond 
+     ((eqv? word-length 0) "")
+     ((eqv? word-length 1) (car words))
+     (else
+      ;; TODO: and this is NOT efficient
+      (string-append
+       (string-join
+        (drop-right words 1)
+        ", ")
+       " and "
+       (last words))))))
+
 (define (room-player-looks-around room player-id)
   "Handle looking around the room"
+  ;; Get the room text
   (define room-text
     (format #f "**~a**\n~a\n"
             (slot-ref room 'name)
             (slot-ref room 'desc)))
+
+  ;; Get a list of other things the player would see in the room
+  (define occupant-names-all
+    (map
+     (lambda (occupant)
+       (message-ref
+        (<-wait room occupant 'visible-name
+                #:whos-looking player-id)
+        'text))
+     (remove
+      (lambda (x) (equal? x player-id))
+      (hash-map->list (lambda (x _) x)
+                      (slot-ref room 'occupants)))))
+
+  ;; Strip out the #f responses (these aren't listed because they lack a name
+  ;; or they aren't "obviously visible" to the player)
+  (define occupant-names-filtered
+    (filter identity occupant-names-all))
+
+  (define occupant-names-string
+    (if (eq? occupant-names-filtered '())
+        #f
+        (format #f "You see here: ~a.\n"
+                (list-words-as-string occupant-names-filtered))))
+
+  (define final-text
+    (if occupant-names-string
+        (string-append room-text occupant-names-string)
+        room-text))
+  
   (<- room player-id 'tell
-      #:text room-text))
+      #:text final-text))
+
 
 (define-mhandler (room-look-room room message)
   "Command: Player asks to look around the room"