refactoring commands slots
[mudsync.git] / mudsync.scm
index 05276a7987c186422a010d60f7ea6e9bfa9c4e85..35cc0befcf641f3da7b286e831656d6e98d7ed71 100644 (file)
@@ -377,13 +377,37 @@ with an anonymous persona"
 ;;; derive from this class.
 ;;; And all of them need a GM!
 
-(define-class <game-actor> (<actor>)
+(define-class <gameobj> (<actor>)
   ;; location id
   (loc #:init-value #f
-       #:accessor game-actor-loc)
+       #:accessor gameobj-loc)
   ;; game master id
   (gm #:init-keyword #:gm
-      #:getter game-actor-gm))
+      #:getter gameobj-gm)
+  ;; a name to be known by
+  (name #:init-keyword #:name
+        #:accessor gameobj-name)
+
+  ;; how to print our name
+  (name-f #:init-keyword #:name-f
+          #:getter gameobj-name-f
+          #:init-value gameobj-simple-name-f)
+
+  ;; Name aliases
+  (aliases #:init-keyword #:aliases
+           #:init-value '())
+
+  ;; Commands we can handle
+  (dirobj-commands #:init-value '())
+  (indirobj-commands #:init-value '())
+
+  ;; Commands we can handle by being something's container
+  (contain-commands #:init-value #f))
+
+
+(define (gameobj-simple-name-f gameobj)
+  "Simplest version: return ourselves for our name."
+  (gameobj-name gameobj))
 
 
 \f
@@ -430,10 +454,11 @@ with an anonymous persona"
                    #:val (slot-ref actor slot))))
 
 
-(define-class <room> (<game-actor>)
-  (name #:init-keyword #:name)
+;; TODO: Subclass from container?
+(define-class <room> (<gameobj>)
   (desc #:init-value ""
                #:init-keyword #:desc)
+  ;; TODO: Switch this to be loc based
   ;; Uses a hash table like a set (values ignored)
   (occupants #:init-thunk make-hash-table)
   ;; A list of <exit>
@@ -442,6 +467,9 @@ with an anonymous persona"
   ;; @@: Maybe eventually <room> will inherit from some more general
   ;;  game object class
 
+  (contain-commands
+   #:init-value %room-contain-commands)
+
   (message-handler
    #:allocation #:each-subclass
    #:init-value
@@ -459,13 +487,23 @@ with an anonymous persona"
      (hash-remove! (slot-ref actor 'occupants) who))
     (wire-exits! (wrap-apply room-wire-exits!)))))
 
+(define always (const #t))
+
+(define %room-contain-commands
+  (list
+   (full-command "look" cmatch-just-verb always 'look-room)
+   (full-command "look" cmatch-direct-obj always 'look-member)
+   (full-command "go" cmathc-just-verb always 'go-where)
+   (full-command "go" cmatch-direct-obj always 'go-exit)))
+
+
 (define (room-wire-exits! room message)
   "Actually hook up the rooms' exit addresses to the rooms they
 claim to point to."
   (for-each
    (lambda (exit)
      (define new-exit
-       (<-wait room (game-actor-gm room) 'lookup-room
+       (<-wait room (gameobj-gm room) 'lookup-room
                #:symbol (exit-to-symbol exit)))
 
      (set! (exit-to-address exit) new-exit))
@@ -477,12 +515,16 @@ claim to point to."
 ;;; Players
 ;;; =======
 
-(define-class <player> (<game-actor>)
+(define-class <player> (<gameobj>)
   (username #:init-keyword #:username
             #:accessor player-username)
   ;; Connection id
   (client #:accessor player-client)
 
+  (self-commands
+   #:init-value '()
+   #:accessor player-self-commands)
+
   (message-handler
    #:init-value
    (make-action-dispatch
@@ -494,7 +536,7 @@ claim to point to."
 (define-mhandler (player-set-loc! player message id)
   (format #t "DEBUG: Location set to ~s for player ~s\n"
           id (actor-id-actor player))
-  (set! (game-actor-loc player) id))
+  (set! (gameobj-loc player) id))
 
 (define-mhandler (player-init! player message)
   (player-look-around player))
@@ -504,16 +546,16 @@ claim to point to."
 (define (player-look-around player)
   (define room-name
     (message-ref
-     (<-wait player (game-actor-loc player) 'get-name)
+     (<-wait player (gameobj-loc player) 'get-name)
      'val))
   (define room-desc
     (message-ref
-     (<-wait player (game-actor-loc player) 'get-desc)
+     (<-wait player (gameobj-loc player) 'get-desc)
      'val))
   (define message-text
     (format #f "**~a**\n~a\n" room-name room-desc))
 
-  (<- player (game-actor-gm player) 'write-home #:text message-text))
+  (<- player (gameobj-gm player) 'write-home #:text message-text))
 
 \f
 ;;; Debugging stuff