X-Git-Url: https://jxself.org/git/?p=mudsync.git;a=blobdiff_plain;f=mudsync%2Fgame-master.scm;fp=mudsync%2Fgame-master.scm;h=f82ec37cda6379e496be673b5b25e0e9c96773e3;hp=6a06cb7bf1af4de62be822c901c8283568cc26ab;hb=36042544b6defa138f348f093f895722a472e1ba;hpb=0580e6a2294089a142923e4fba9b345d7442af79 diff --git a/mudsync/game-master.scm b/mudsync/game-master.scm index 6a06cb7..f82ec37 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 '()) @@ -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