X-Git-Url: https://jxself.org/git/?p=mudsync.git;a=blobdiff_plain;f=mudsync%2Fgameobj.scm;h=00858522281f2bc5257b6b13e51fe2c14aad469c;hp=32506803cfa43bbf71cd764caf3a458122e76de4;hb=4d4af0656b0402e630eea9393420197152945e5b;hpb=aca41e2e3c5ed026c2672e3ac4ac364bbdef19c7 diff --git a/mudsync/gameobj.scm b/mudsync/gameobj.scm index 3250680..0085852 100644 --- a/mudsync/gameobj.scm +++ b/mudsync/gameobj.scm @@ -21,8 +21,9 @@ (define-module (mudsync gameobj) #:use-module (mudsync command) - #:use-module (8sync systems actors) + #:use-module (8sync actors) #:use-module (8sync agenda) + #:use-module (8sync rmeta-slot) #:use-module (srfi srfi-1) #:use-module (ice-9 format) #:use-module (ice-9 match) @@ -35,7 +36,6 @@ gameobj-act-init gameobj-set-loc! gameobj-occupants - gameobj-actions gameobj-self-destruct slot-ref-maybe-runcheck @@ -47,30 +47,6 @@ ;;; ======= -;;; Actions supported by all gameobj -(define gameobj-actions - (build-actions - (init (wrap-apply gameobj-act-init)) - ;; Commands for co-occupants - (get-commands (wrap-apply gameobj-get-commands)) - ;; Commands for participants in a room - (get-container-commands (wrap-apply gameobj-get-container-commands)) - ;; Commands for inventory items, etc (occupants of the gameobj commanding) - (get-contained-commands (wrap-apply gameobj-get-contained-commands)) - (get-occupants (wrap-apply gameobj-get-occupants)) - (add-occupant! (wrap-apply gameobj-add-occupant!)) - (remove-occupant! (wrap-apply gameobj-remove-occupant!)) - (get-loc (wrap-apply gameobj-act-get-loc)) - (set-loc! (wrap-apply gameobj-act-set-loc!)) - (get-name (wrap-apply gameobj-get-name)) - (set-name! (wrap-apply gameobj-act-set-name!)) - (get-desc (wrap-apply gameobj-get-desc)) - (goes-by (wrap-apply gameobj-act-goes-by)) - (visible-name (wrap-apply gameobj-visible-name)) - (self-destruct (wrap-apply gameobj-act-self-destruct)) - (tell (wrap-apply gameobj-tell-no-op)) - (assist-replace (wrap-apply gameobj-act-assist-replace)))) - ;;; *all* game components that talk to players should somehow ;;; derive from this class. ;;; And all of them need a GM! @@ -96,17 +72,16 @@ #:init-keyword #:desc) ;; Commands we can handle - (commands #:init-value '()) + (commands #:allocation #:each-subclass + #:init-thunk (build-commands)) ;; Commands we can handle by being something's container - (container-commands #:init-value '()) + (container-commands #:allocation #:each-subclass + #:init-thunk (build-commands)) ;; Commands we can handle by being contained by something else - (contained-commands #:init-value '()) - - (message-handler - #:init-value - (simple-dispatcher gameobj-actions)) + (contained-commands #:allocation #:each-subclass + #:init-thunk (build-commands)) ;; Most objects are generally visible by default (generally-visible #:init-value #t @@ -118,7 +93,32 @@ ;; Set this on self-destruct ;; (checked by some "long running" game routines) - (destructed #:init-value #f)) + (destructed #:init-value #f) + + (actions #:allocation #:each-subclass + ;;; Actions supported by all gameobj + #:init-thunk + (build-actions + (init gameobj-act-init) + ;; Commands for co-occupants + (get-commands gameobj-get-commands) + ;; Commands for participants in a room + (get-container-commands gameobj-get-container-commands) + ;; Commands for inventory items, etc (occupants of the gameobj commanding) + (get-contained-commands gameobj-get-contained-commands) + (get-occupants gameobj-get-occupants) + (add-occupant! gameobj-add-occupant!) + (remove-occupant! gameobj-remove-occupant!) + (get-loc gameobj-act-get-loc) + (set-loc! gameobj-act-set-loc!) + (get-name gameobj-get-name) + (set-name! gameobj-act-set-name!) + (get-desc gameobj-get-desc) + (goes-by gameobj-act-goes-by) + (visible-name gameobj-visible-name) + (self-destruct gameobj-act-self-destruct) + (tell gameobj-tell-no-op) + (assist-replace gameobj-act-assist-replace)))) ;;; gameobj message handlers @@ -127,7 +127,7 @@ ;; Kind of a useful utility, maybe? (define (simple-slot-getter slot) (lambda (actor message) - (<-reply actor message (slot-ref actor slot)))) + (<-reply message (slot-ref actor slot)))) (define (gameobj-replace-step-occupants actor occupants) ;; Snarf all the occupants! @@ -135,7 +135,7 @@ (when occupants (for-each (lambda (occupant) - (<-wait actor occupant 'set-loc! + (<-wait occupant 'set-loc! #:loc (actor-id actor))) occupants))) @@ -144,8 +144,8 @@ (define (run-replacement actor replaces replace-steps) (when replaces - (msg-receive (_ #:key occupants) - (<-wait actor replaces 'assist-replace) + (mbody-receive (_ #:key occupants) + (<-wait replaces 'assist-replace) (for-each (lambda (replace-step) (replace-step actor occupants)) @@ -169,8 +169,7 @@ Assists in its replacement of occupants if necessary and nothing else." (define (gameobj-act-goes-by actor message) "Reply to a message requesting what we go by." - (<-reply actor message - #:goes-by (gameobj-goes-by actor))) + (<-reply message #:goes-by (gameobj-goes-by actor))) (define (val-or-run val-or-proc) "Evaluate if a procedure, or just return otherwise" @@ -178,36 +177,30 @@ Assists in its replacement of occupants if necessary and nothing else." (val-or-proc) val-or-proc)) -(define (filter-commands commands verb) - (filter - (lambda (cmd) - (equal? (command-verbs cmd) - verb)) - commands)) +(define (get-candidate-commands actor rmeta-sym verb) + (class-rmeta-ref (class-of actor) rmeta-sym verb + #:dflt '())) (define* (gameobj-get-commands actor message #:key verb) "Get commands a co-occupant of the room might execute for VERB" - (define filtered-commands - (filter-commands (val-or-run (slot-ref actor 'commands)) - verb)) - (<-reply actor message - #:commands filtered-commands + (define candidate-commands + (get-candidate-commands actor 'commands verb)) + (<-reply message + #:commands candidate-commands #:goes-by (gameobj-goes-by actor))) (define* (gameobj-get-container-commands actor message #:key verb) "Get commands as the container / room of message's sender" - (define filtered-commands - (filter-commands (val-or-run (slot-ref actor 'container-commands)) - verb)) - (<-reply actor message #:commands filtered-commands)) + (define candidate-commands + (get-candidate-commands actor 'container-commands verb)) + (<-reply message #:commands candidate-commands)) (define* (gameobj-get-contained-commands actor message #:key verb) "Get commands as being contained (eg inventory) of commanding gameobj" - (define filtered-commands - (filter-commands (val-or-run (slot-ref actor 'contained-commands)) - verb)) - (<-reply actor message - #:commands filtered-commands + (define candidate-commands + (get-candidate-commands actor 'contained-commands verb)) + (<-reply message + #:commands candidate-commands #:goes-by (gameobj-goes-by actor))) (define* (gameobj-add-occupant! actor message #:key who) @@ -230,7 +223,7 @@ Assists in its replacement of occupants if necessary and nothing else." ;; A list of addresses... since our address object is (annoyingly) ;; currently a simple cons cell... ((exclude-1 ... exclude-rest) - (pk 'failboat (member occupant (pk 'exclude-lst exclude)))) + (member occupant exclude)) ;; Must be an individual address! (_ (equal? occupant exclude)))) (if exclude-it? @@ -244,11 +237,10 @@ Assists in its replacement of occupants if necessary and nothing else." (define occupants (gameobj-occupants actor #:exclude exclude)) - (<-reply actor message - #:occupants occupants)) + (<-reply message #:occupants occupants)) (define (gameobj-act-get-loc actor message) - (<-reply actor message (slot-ref actor 'loc))) + (<-reply message (slot-ref actor 'loc))) (define (gameobj-set-loc! gameobj loc) "Set the location of this object." @@ -260,9 +252,9 @@ Assists in its replacement of occupants if necessary and nothing else." (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))) + (<-wait old-loc 'remove-occupant! #:who (actor-id gameobj))) (if loc - (<-wait gameobj loc 'add-occupant! #:who (actor-id gameobj))))) + (<-wait loc 'add-occupant! #:who (actor-id gameobj))))) ;; @@: Should it really be #:id ? Maybe #:loc-id or #:loc? (define* (gameobj-act-set-loc! actor message #:key loc) @@ -288,7 +280,7 @@ and whos-asking, and see if we should just return it or run it." ((? procedure? desc-proc) (desc-proc actor whos-looking)) (desc desc))) - (<-reply actor message desc-text)) + (<-reply message desc-text)) (define (gameobj-visible-to-player? gameobj whos-looking) "Check to see whether we're visible to the player or not. @@ -310,7 +302,7 @@ By default, this is whether or not the generally-visible flag is set." name) (#f #f)) #f)) - (<-reply actor message #:text name-to-return)) + (<-reply message #:text name-to-return)) (define (gameobj-self-destruct gameobj) "General gameobj self destruction routine" @@ -320,7 +312,7 @@ By default, this is whether or not the generally-visible flag is set." ;; Boom! (self-destruct gameobj)) -(define (gameobj-act-self-destruct gameobj message) +(define* (gameobj-act-self-destruct gameobj message #:key why) "Action routine for self destruction" (gameobj-self-destruct gameobj)) @@ -342,7 +334,7 @@ By default, this is whether or not the generally-visible flag is set." ;; But that's life in a live hacked game! (define (gameobj-act-assist-replace actor message) "Vanilla method for assisting in self-replacement for live hacking" - (apply <-reply actor message + (apply <-reply message (gameobj-replace-data* actor))) @@ -354,8 +346,8 @@ By default, this is whether or not the generally-visible flag is set." (match special-symbol ;; if it's a symbol, look it up dynamically ((? symbol? _) - (msg-val (<-wait gameobj (slot-ref gameobj 'gm) 'lookup-special - #:symbol special-symbol))) + (mbody-val (<-wait (slot-ref gameobj 'gm) 'lookup-special + #:symbol special-symbol))) ;; if it's false, return nothing (#f #f) ;; otherwise it's probably an address, return it as-is