X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;ds=sidebyside;f=mudsync%2Fgameobj.scm;h=55b76bbb15dc959139a5b388fd5d6d37a83136e9;hb=6732328d0efb666ae0dfaf8d85d29ca96d978cf1;hp=65ddc296262c7d2a767e53db858330170d4aed3d;hpb=dc03715be3fb99a68618c9aea2bd1e35fae8548c;p=mudsync.git diff --git a/mudsync/gameobj.scm b/mudsync/gameobj.scm index 65ddc29..55b76bb 100644 --- a/mudsync/gameobj.scm +++ b/mudsync/gameobj.scm @@ -21,6 +21,7 @@ (define-module (mudsync gameobj) #:use-module (mudsync command) + #:use-module (mudsync utils) #:use-module (8sync actors) #:use-module (8sync agenda) #:use-module (8sync rmeta-slot) @@ -211,7 +212,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 message #:goes-by (gameobj-goes-by actor))) + (<-reply message (gameobj-goes-by actor))) (define (val-or-run val-or-proc) "Evaluate if a procedure, or just return otherwise" @@ -379,12 +380,20 @@ By default, this is whether or not the generally-visible flag is set." (gameobj-replace-data* gameobj))) (define (gameobj-ok-to-be-taken-from gameobj message whos-acting) - (<-reply message (slot-ref-maybe-runcheck gameobj 'take-me? - whos-acting #:from #t))) + (call-with-values (lambda () + (slot-ref-maybe-runcheck gameobj 'take-me? + whos-acting #:from #t)) + ;; This allows this to reply with #:why-not if appropriate + (lambda args + (apply <-reply message args)))) (define (gameobj-ok-to-be-put-in gameobj message whos-acting where) - (<-reply message (slot-ref-maybe-runcheck gameobj 'drop-me? - whos-acting where))) + (call-with-values (lambda () + (slot-ref-maybe-runcheck gameobj 'drop-me? + whos-acting where)) + ;; This allows this to reply with #:why-not if appropriate + (lambda args + (apply <-reply message args)))) ;;; Utilities every gameobj has @@ -407,8 +416,9 @@ By default, this is whether or not the generally-visible flag is set." ;;; Basic actions ;;; ------------- -(define* (cmd-take gameobj message #:key direct-obj) - (define player (message-from message)) +(define* (cmd-take gameobj message + #:key direct-obj + (player (message-from message))) (define player-name (mbody-val (<-wait player 'get-name))) (define player-loc @@ -418,25 +428,28 @@ By default, this is whether or not the generally-visible flag is set." (slot-ref-maybe-runcheck gameobj 'take-me? player)) ;; @@: Is there any reason to allow the room to object in the way ;; that there is for dropping? It doesn't seem like it. - ;; TODO: Allow gameobj to customize - (if self-should-take - ;; Set the location to whoever's picking us up - (begin - (gameobj-set-loc! gameobj player) - (<- player 'tell - #:text (format #f "You pick up ~a.\n" - our-name)) - (<- player-loc 'tell-room - #:text (format #f "~a picks up ~a.\n" - player-name - our-name) - #:exclude player)) - (<- player 'tell - #:text (format #f "It doesn't seem like you can take ~a.\n" - our-name)))) - -(define* (cmd-drop gameobj message #:key direct-obj) - (define player (message-from message)) + (call-with-values (lambda () + (slot-ref-maybe-runcheck gameobj 'take-me? player)) + (lambda* (self-should-take #:key (why-not + `("It doesn't seem like you can take " + ,our-name "."))) + (if self-should-take + ;; Set the location to whoever's picking us up + (begin + (gameobj-set-loc! gameobj player) + (<- player 'tell + #:text (format #f "You pick up ~a.\n" + our-name)) + (<- player-loc 'tell-room + #:text (format #f "~a picks up ~a.\n" + player-name + our-name) + #:exclude player)) + (<- player 'tell #:text why-not))))) + +(define* (cmd-drop gameobj message + #:key direct-obj + (player (message-from message))) (define player-name (mbody-val (<-wait player 'get-name))) (define player-loc @@ -481,8 +494,8 @@ By default, this is whether or not the generally-visible flag is set." ;; @@: Moving this to a container subclass/mixin could allow a lot more ;; customization of take out / put in phrases (define* (cmd-take-from gameobj message - #:key direct-obj indir-obj preposition) - (define player (message-from message)) + #:key direct-obj indir-obj preposition + (player (message-from message))) (define player-name (mbody-val (<-wait player 'get-name))) (define player-loc @@ -493,10 +506,9 @@ By default, this is whether or not the generally-visible flag is set." (call/ec (lambda (return) (for-each (lambda (occupant) - (mbody-receive (_ #:key goes-by) - (<-wait occupant 'goes-by) - (when (member direct-obj goes-by) - (return occupant)))) + (define goes-by (mbody-val (<-wait occupant 'goes-by))) + (when (ci-member direct-obj goes-by) + (return occupant))) (gameobj-occupants gameobj)) ;; nothing found #f))) @@ -507,7 +519,7 @@ By default, this is whether or not the generally-visible flag is set." (slot-ref-maybe-runcheck gameobj 'take-from-me? player this-thing))) (define (default-objection) `("Unfortunately, it doesn't seem like you can take " - (this-thing-name) " " preposition " " our-name ".")) + ,(this-thing-name) " " ,preposition " " ,our-name ".")) (define (this-thing-objection) (mbody-receive (_ taken-ok? #:key why-not) ; does the object object to being removed? @@ -524,7 +536,6 @@ By default, this is whether or not the generally-visible flag is set." (<- player 'tell #:text `("It's not really clear how to take something " ,preposition " " ,our-name "."))) - ;; Unfortunately this does leak information about what is contained ;; by us. Maybe not what's wanted in all circumstances. ((not this-thing) @@ -556,8 +567,8 @@ By default, this is whether or not the generally-visible flag is set." #:exclude player)))) (define* (cmd-put-in gameobj message - #:key direct-obj indir-obj preposition) - (define player (message-from message)) + #:key direct-obj indir-obj preposition + (player (message-from message))) (define player-name (mbody-val (<-wait player 'get-name))) (define player-loc @@ -568,10 +579,9 @@ By default, this is whether or not the generally-visible flag is set." (call/ec (lambda (return) (for-each (lambda (occupant) - (mbody-receive (_ #:key goes-by) - (<-wait occupant 'goes-by) - (when (member direct-obj goes-by) - (return occupant)))) + (define goes-by (mbody-val (<-wait occupant 'goes-by))) + (when (ci-member direct-obj goes-by) + (return occupant))) (mbody-val (<-wait player 'get-occupants))) ;; nothing found #f))) @@ -592,17 +602,17 @@ By default, this is whether or not the generally-visible flag is set." (cond ;; Is it not there, or maybe we won't allow it to be taken? ((not this-thing) - (<- (message-from message) 'tell + (<- player 'tell #:text `("You don't seem to have any such " ,direct-obj " to put " ,preposition " " ,our-name "."))) ((or (not (should-put-in-me))) - (<- (message-from message) 'tell + (<- player 'tell #:text (default-objection))) ;; the thing we wsant to take itself has objected... ((this-thing-objection) => (lambda (objection) - (<- (message-from message) 'tell + (<- player 'tell #:text objection))) ;; looks like we can take it (else