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.
;; 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)
(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
(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)