Switch inject-special! to do-inject-special!
[mudsync.git] / mudsync / gameobj.scm
index b686e3cbd74a4d2d41825f0f5f5777290b8357f4..9046520bbb9ba7dc396dcfa4bec301117f85f716 100644 (file)
@@ -24,6 +24,7 @@
   #:use-module (8sync systems actors)
   #:use-module (8sync agenda)
   #:use-module (srfi srfi-1)
+  #:use-module (ice-9 format)
   #:use-module (ice-9 match)
   #:use-module (oop goops)
   #:export (<gameobj>
@@ -31,6 +32,7 @@
             gameobj-loc
             gameobj-gm
 
+            gameobj-act-init
             gameobj-set-loc!
             gameobj-occupants
             gameobj-actions
@@ -48,7 +50,7 @@
 ;;; Actions supported by all gameobj
 (define gameobj-actions
   (build-actions
-   (init (wrap-apply gameobj-init))
+   (init (wrap-apply gameobj-act-init))
    ;; Commands for co-occupants
    (get-commands (wrap-apply gameobj-get-commands))
    ;; Commands for participants in a room
   ;; @@: Would be preferable to be using generic methods for this...
   ;;   Hopefully we can port this to Guile 2.2 soon...
   (visible-to-player?
-   #:init-value (wrap-apply gameobj-visible-to-player?)))
+   #:init-value (wrap-apply gameobj-visible-to-player?))
+
+  ;; Set this on self-destruct
+  ;; (checked by some "long running" game routines)
+  (destructed #:init-value #f))
 
 
 ;;; gameobj message handlers
          (replace-step actor replace-reply))
        replace-steps))))
 
-;; @@: This could be kind of a messy way of doing gameobj-init
+;; @@: This could be kind of a messy way of doing gameobj-act-init
 ;;   stuff.  If only we had generic methods :(
-(define-mhandler (gameobj-init actor message)
+(define-mhandler (gameobj-act-init actor message)
   "Your most basic game object init procedure.
 Assists in its replacement of occupants if necessary and nothing else."
   (run-replacement actor message gameobj-replace-steps*))
@@ -256,12 +262,13 @@ Assists in its replacement of occupants if necessary and nothing else."
   (format #t "DEBUG: Location set to ~s for ~s\n"
           loc (actor-id-actor gameobj))
 
-  (slot-set! gameobj 'loc loc)
-  ;; Change registation of where we currently are
-  (if loc
-      (<-wait gameobj loc 'add-occupant! #:who (actor-id gameobj)))
-  (if old-loc
-      (<-wait gameobj old-loc 'remove-occupant! #:who (actor-id gameobj))))
+  (when (not (equal? old-loc loc))
+    (slot-set! gameobj 'loc loc)
+    ;; Change registation of where we currently are
+    (if old-loc
+        (<-wait gameobj old-loc 'remove-occupant! #:who (actor-id gameobj)))
+    (if loc
+        (<-wait gameobj loc 'add-occupant! #:who (actor-id gameobj)))))
 
 ;; @@: Should it really be #:id ?  Maybe #:loc-id or #:loc?
 (define-mhandler (gameobj-act-set-loc! actor message loc)
@@ -315,6 +322,7 @@ By default, this is whether or not the generally-visible flag is set."
   "General gameobj self destruction routine"
   ;; Unregister from being in any particular room
   (gameobj-set-loc! gameobj #f)
+  (slot-set! gameobj 'destructed #t)
   ;; Boom!
   (self-destruct gameobj))