more basic gameobj and player stuff
[mudsync.git] / mudsync.scm
index cdc03fd3d408f7dc1dc2e164adbba1e46b50fea2..7219c37e947883daa75f9baa711b6395affc5394 100644 (file)
@@ -377,9 +377,35 @@ 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 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
+  (commands #:init-value #f)
+  ;; 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
@@ -426,8 +452,7 @@ with an anonymous persona"
                    #:val (slot-ref actor slot))))
 
 
-(define-class <room> (<game-actor>)
-  (name #:init-keyword #:name)
+(define-class <room> (<gameobj>)
   (desc #:init-value ""
                #:init-keyword #:desc)
   ;; Uses a hash table like a set (values ignored)
@@ -461,7 +486,7 @@ 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))
@@ -473,15 +498,16 @@ claim to point to."
 ;;; Players
 ;;; =======
 
-(define-class <player> (<game-actor>)
+(define-class <player> (<gameobj>)
   (username #:init-keyword #:username
             #:accessor player-username)
-  ;; location id
-  (loc #:init-value #f
-       #:accessor player-loc)
   ;; Connection id
   (client #:accessor player-client)
 
+  (self-commands
+   #:init-value #f  ; TODO: Set me to a reasonable default
+   #:accessor player-self-commands)
+
   (message-handler
    #:init-value
    (make-action-dispatch
@@ -491,9 +517,9 @@ claim to point to."
 ;;; player message handlers
 
 (define-mhandler (player-set-loc! player message id)
-  (format #t "DEBUG: Location set to ~s for player ~s"
+  (format #t "DEBUG: Location set to ~s for player ~s\n"
           id (actor-id-actor player))
-  (set! (player-loc player) id))
+  (set! (gameobj-loc player) id))
 
 (define-mhandler (player-init! player message)
   (player-look-around player))
@@ -503,16 +529,16 @@ claim to point to."
 (define (player-look-around player)
   (define room-name
     (message-ref
-     (<-wait player (player-loc player) 'get-name)
+     (<-wait player (gameobj-loc player) 'get-name)
      'val))
   (define room-desc
     (message-ref
-     (<-wait player (player-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