+(define-mhandler (gm-inject-special! gm message
+ special-symbol gameobj-spec)
+ "Inject, possiibly replacing the original, special symbol
+using the gameobj-spec."
+ (define existing-obj
+ (hash-ref (slot-ref gm 'special-dir) special-symbol))
+
+ ;; There's a lot of overlap here with gm-init-game-spec.
+ ;; We could try to union them? It seemed hard last time I looked,
+ ;; because things need to run in a different order.
+ (match gameobj-spec
+ (((? (cut eq? <> special-symbol) symbol) class loc args ...)
+ ;; initialize the special object
+ (let ((special-obj
+ (apply create-actor* gm class
+ ;; set cookie to be the object's symbol
+ (symbol->string symbol)
+ #:gm (actor-id gm)
+ args)))
+ ;; Set the location
+ (<-wait gm special-obj 'set-loc!
+ #:loc (hash-ref (gm-special-dir gm) loc))
+ ;; Initialize the object, and depending on if an object
+ ;; already exists with this info, ask it to coordinate
+ ;; replacing with the existing object.
+ (if existing-obj
+ (<-wait gm special-obj 'init #:replace existing-obj)
+ (<-wait gm special-obj 'init))
+ ;; Register the object
+ (hash-set! (gm-special-dir gm) symbol special-obj)
+ ;; Destroy the original, if it exists.
+ (if existing-obj
+ (<- gm existing-obj 'self-destruct #:why 'replaced))))))
+