#: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>
gameobj-loc
gameobj-gm
+ gameobj-act-init
gameobj-set-loc!
gameobj-occupants
gameobj-actions
;;; 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*))
(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)
"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))