1 ;;; Mudsync --- Live hackable MUD
2 ;;; Copyright © 2016 Christine Lemmer-Webber <cwebber@dustycloud.org>
4 ;;; This file is part of Mudsync.
6 ;;; Mudsync is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or
9 ;;; (at your option) any later version.
11 ;;; Mudsync is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ;;; General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with Mudsync. If not, see <http://www.gnu.org/licenses/>.
22 ;;; While all gameobjs are containers, some gameobjs are more
23 ;;; containers than others.
25 (define-module (mudsync container)
27 #:use-module (oop goops)
28 #:use-module (mudsync gameobj)
29 #:use-module (mudsync utils)
30 #:use-module (ice-9 control)
32 cmd-take-from cmd-put-in))
34 (define-actor <container> (<gameobj>)
35 ((cmd-take-from cmd-take-from)
36 (cmd-put-in cmd-put-in))
37 ;; Can be a boolean or a procedure accepting
38 ;; (gameobj whos-acting take-what)
39 (take-from-me? #:init-value #t
40 #:init-keyword #:take-from-me?)
41 ;; Can be a boolean or a procedure accepting
42 ;; (gameobj whos-acting put-what)
43 (put-in-me? #:init-value #t
44 #:init-keyword #:put-in-me?))
46 ;; @@: Moving this to a container subclass/mixin could allow a lot more
47 ;; customization of take out / put in phrases
48 (define* (cmd-take-from gameobj message
49 #:key direct-obj indir-obj preposition
50 (player (message-from message)))
52 (mbody-val (<-wait player 'get-name)))
54 (mbody-val (<-wait player 'get-loc)))
55 (define our-name (slot-ref gameobj 'name))
56 ;; We need to check if we even have such a thing
60 (for-each (lambda (occupant)
61 (define goes-by (mbody-val (<-wait occupant 'goes-by)))
62 (when (ci-member direct-obj goes-by)
64 (gameobj-occupants gameobj))
67 (define (this-thing-name)
68 (mbody-val (<-wait this-thing 'get-name)))
69 (define (should-take-from-me)
71 (slot-ref-maybe-runcheck gameobj 'take-from-me? player this-thing)))
72 (define (default-objection)
73 `("Unfortunately, it doesn't seem like you can take "
74 ,(this-thing-name) " " ,preposition " " ,our-name "."))
76 (define (this-thing-objection)
77 (mbody-receive (_ taken-ok? #:key why-not) ; does the object object to being removed?
78 (<-wait this-thing 'ok-to-be-taken-from? player) ; @@ no need to supply from where
80 ;; Either give the specified reason, or give a boilerplate one
82 (default-objection)))))
84 ;; Unfortunately this does leak information about what is contained
85 ;; by us. Maybe not what's wanted in all circumstances.
88 #:text `("You don't see any such " ,direct-obj " to take "
89 ,preposition " " ,our-name ".")))
90 ;; A particular objection to taking this thing.
91 ;; We should allow customizing the reason here, which could be
92 ;; provided by the 'ok-to-be-taken-from? slot.
93 ((not (should-take-from-me))
95 #:text (default-objection)))
96 ;; the thing we wsant to take itself has objected...
97 ((this-thing-objection) =>
101 ;; looks like we can take it
103 ;; Wait to announce to the player just in case settting the location
104 ;; errors out or something. Maybe it's overthinking things, I dunno.
105 (<-wait this-thing 'set-loc! #:loc player)
107 #:text `("You take " ,(this-thing-name) " from "
109 (<- player-loc 'tell-room
110 #:text `(,player-name " takes " ,(this-thing-name) " from "
114 (define* (cmd-put-in gameobj message
115 #:key direct-obj indir-obj preposition
116 (player (message-from message)))
118 (mbody-val (<-wait player 'get-name)))
120 (mbody-val (<-wait player 'get-loc)))
121 (define our-name (slot-ref gameobj 'name))
122 ;; We need to check if we even have such a thing
126 (for-each (lambda (occupant)
127 (define goes-by (mbody-val (<-wait occupant 'goes-by)))
128 (when (ci-member direct-obj goes-by)
130 (mbody-val (<-wait player 'get-occupants)))
133 (define (this-thing-name)
134 (mbody-val (<-wait this-thing 'get-name)))
135 (define (should-put-in-me)
137 (slot-ref-maybe-runcheck gameobj 'put-in-me? player this-thing)))
138 (define (default-objection)
139 `("As much as you'd like to, it doesn't seem like you can put "
140 ,(this-thing-name) " " ,preposition " " ,our-name "."))
141 (define (this-thing-objection)
142 (mbody-receive (_ put-in-ok? #:key why-not) ; does the object object to being moved?
143 (<-wait this-thing 'ok-to-be-put-in? player (actor-id gameobj))
144 (and (not put-in-ok?)
145 ;; Either give the specified reason, or give a boilerplate one
146 (or why-not (default-objection)))))
148 ;; Is it not there, or maybe we won't allow it to be taken?
151 #:text `("You don't seem to have any such " ,direct-obj " to put "
152 ,preposition " " ,our-name ".")))
154 ((or (not (should-put-in-me)))
156 #:text (default-objection)))
157 ;; the thing we wsant to take itself has objected...
158 ((this-thing-objection) =>
162 ;; looks like we can take it
164 ;; Wait to announce to the player just in case settting the location
165 ;; errors out or something. Maybe it's overthinking things, I dunno.
166 (<-wait this-thing 'set-loc! #:loc (actor-id gameobj))
168 #:text `("You put " ,(this-thing-name) " " ,preposition " "
170 (<- player-loc 'tell-room
171 #:text `(,player-name " puts " ,(this-thing-name) " " ,preposition " "