X-Git-Url: https://jxself.org/git/?p=mudsync.git;a=blobdiff_plain;f=mudsync%2Fgameobj.scm;h=6a5e369cb1c5b0fabac887eeacaad4d06dae777b;hp=2c3970613d0867ae298fc817cafbfc44d83ba861;hb=060a48dce227e8c53e007941cc673b494ca36024;hpb=136ce3b725c83af0b7e8be632e943de6b07b65c5 diff --git a/mudsync/gameobj.scm b/mudsync/gameobj.scm index 2c39706..6a5e369 100644 --- a/mudsync/gameobj.scm +++ b/mudsync/gameobj.scm @@ -29,8 +29,23 @@ gameobj-loc gameobj-gm gameobj-name - gameobj-name-f)) + gameobj-name-f + gameobj-actions)) + +;;; Gameobj +;;; ======= + + +;;; Actions supported by all gameobj +(define gameobj-actions + (build-actions + (get-commands (wrap-apply gameobj-get-commands)) + (get-container-commands (wrap-apply gameobj-get-container-commands)) + (get-children (wrap-apply gameobj-get-children)) + (add-occupant! (wrap-apply gameobj-add-child!)) + (remove-occupant! (wrap-apply gameobj-remove-child!)) + (set-loc! (wrap-apply gameobj-set-loc!)))) ;;; *all* game components that talk to players should somehow ;;; derive from this class. @@ -40,6 +55,11 @@ ;; location id (loc #:init-value #f #:accessor gameobj-loc) + + ;; Uses a hash table like a set (values ignored) + (occupants #:init-thunk make-hash-table + #:accessor gameobj-occupants) + ;; game master id (gm #:init-keyword #:gm #:getter gameobj-gm) @@ -47,6 +67,9 @@ (name #:init-keyword #:name #:accessor gameobj-name) + (desc #:init-value "" + #:init-keyword #:desc) + ;; how to print our name (name-f #:init-keyword #:name-f #:getter gameobj-name-f @@ -60,7 +83,33 @@ (commands #:init-value '()) ;; Commands we can handle by being something's container - (contain-commands #:init-value '())) + (container-commands #:init-value '()) + (message-handler + #:init-value + (simple-dispatcher gameobj-actions))) + + +;;; gameobj message handlers +;;; ======================== + +(define-mhandler (gameobj-get-commands actor message verb) + (<-reply actor message #:commands (slot-ref actor 'commands))) + +(define-mhandler (gameobj-get-container-commands actor message verb) + (<-reply actor message #:commands (slot-ref actor 'container-commands))) + +(define-mhandler (gameobj-get-children actor message) + (define children + (hash-map->list (lambda (key val) key) + (gameobj-children actor))) + + (<-reply actor message + #:children children)) + +(define-mhandler (gameobj-set-loc! player message id) + (format #t "DEBUG: Location set to ~s for player ~s\n" + id (actor-id-actor player)) + (set! (gameobj-loc player) id)) (define (gameobj-simple-name-f gameobj)