X-Git-Url: https://jxself.org/git/?p=mudsync.git;a=blobdiff_plain;f=mudsync%2Fgame-master.scm;h=8bc239bdb9bebedf6eebbe047879f8e495b218ab;hp=6a06cb7bf1af4de62be822c901c8283568cc26ab;hb=31d4d0fb22546efe897756ad00699d44907c7737;hpb=0580e6a2294089a142923e4fba9b345d7442af79 diff --git a/mudsync/game-master.scm b/mudsync/game-master.scm index 6a06cb7..8bc239b 100644 --- a/mudsync/game-master.scm +++ b/mudsync/game-master.scm @@ -22,6 +22,7 @@ #:use-module (8sync agenda) #:use-module (oop goops) #:use-module (ice-9 match) + #:use-module (srfi srfi-26) #:export ( make-default-room-conn-handler)) @@ -75,6 +76,8 @@ ;; Set up the network (gm-setup-network gm)) + +;; @@: If you change this code, update gm-inject-special! if appropriate. (define (gm-init-game-spec gm game-spec) "Initialize the prebuilt special objects" (define set-locs '()) @@ -148,7 +151,7 @@ (define-mhandler (gm-lookup-special actor message symbol) (<-reply actor message - #:room-id (hash-ref (slot-ref actor 'special-dir) symbol))) + #:val (hash-ref (slot-ref actor 'special-dir) symbol))) (define-mhandler (gm-write-home actor message text) (define client-id (hash-ref (gm-reverse-client-dir actor) @@ -174,8 +177,35 @@ special-symbol gameobj-spec) "Inject, possiibly replacing the original, special symbol using the gameobj-spec." - (pk 'special-symbol special-symbol) - (pk 'gameobj-spec 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)))))) ;;; GM utilities @@ -224,4 +254,3 @@ with an anonymous persona" #:text (format #f "You see ~a materialize out of thin air!\n" guest-name) #:exclude player))))) -