1 ;;; Mudsync --- Live hackable MUD
2 ;;; Copyright © 2016 Christopher Allan 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/>.
21 (define-module (mudsync container)
23 #:use-module (oop goops)
24 #:use-module (mudsync gameobj)
25 #:use-module (mudsync utils)
26 #:use-module (ice-9 control)
28 cmd-take-from cmd-put-in))
30 (define-actor <container> (<gameobj>)
31 ((cmd-take-from cmd-take-from)
32 (cmd-put-in cmd-put-in))
33 ;; Can be a boolean or a procedure accepting
34 ;; (gameobj whos-acting take-what)
35 (take-from-me? #:init-value #t
36 #:init-keyword #:take-from-me?)
37 ;; Can be a boolean or a procedure accepting
38 ;; (gameobj whos-acting put-what)
39 (put-in-me? #:init-value #t
40 #:init-keyword #:put-in-me?))
42 ;; @@: Moving this to a container subclass/mixin could allow a lot more
43 ;; customization of take out / put in phrases
44 (define* (cmd-take-from gameobj message
45 #:key direct-obj indir-obj preposition
46 (player (message-from message)))
48 (mbody-val (<-wait player 'get-name)))
50 (mbody-val (<-wait player 'get-loc)))
51 (define our-name (slot-ref gameobj 'name))
52 ;; We need to check if we even have such a thing
56 (for-each (lambda (occupant)
57 (define goes-by (mbody-val (<-wait occupant 'goes-by)))
58 (when (ci-member direct-obj goes-by)
60 (gameobj-occupants gameobj))
63 (define (this-thing-name)
64 (mbody-val (<-wait this-thing 'get-name)))
65 (define (should-take-from-me)
67 (slot-ref-maybe-runcheck gameobj 'take-from-me? player this-thing)))
68 (define (default-objection)
69 `("Unfortunately, it doesn't seem like you can take "
70 ,(this-thing-name) " " ,preposition " " ,our-name "."))
72 (define (this-thing-objection)
73 (mbody-receive (_ taken-ok? #:key why-not) ; does the object object to being removed?
74 (<-wait this-thing 'ok-to-be-taken-from? player) ; @@ no need to supply from where
76 ;; Either give the specified reason, or give a boilerplate one
78 (default-objection)))))
80 ;; Unfortunately this does leak information about what is contained
81 ;; by us. Maybe not what's wanted in all circumstances.
84 #:text `("You don't see any such " ,direct-obj " to take "
85 ,preposition " " ,our-name ".")))
86 ;; A particular objection to taking this thing.
87 ;; We should allow customizing the reason here, which could be
88 ;; provided by the 'ok-to-be-taken-from? slot.
89 ((not (should-take-from-me))
91 #:text (default-objection)))
92 ;; the thing we wsant to take itself has objected...
93 ((this-thing-objection) =>
97 ;; looks like we can take it
99 ;; Wait to announce to the player just in case settting the location
100 ;; errors out or something. Maybe it's overthinking things, I dunno.
101 (<-wait this-thing 'set-loc! #:loc player)
103 #:text `("You take " ,(this-thing-name) " from "
105 (<- player-loc 'tell-room
106 #:text `(,player-name " takes " ,(this-thing-name) " from "
110 (define* (cmd-put-in gameobj message
111 #:key direct-obj indir-obj preposition
112 (player (message-from message)))
114 (mbody-val (<-wait player 'get-name)))
116 (mbody-val (<-wait player 'get-loc)))
117 (define our-name (slot-ref gameobj 'name))
118 ;; We need to check if we even have such a thing
122 (for-each (lambda (occupant)
123 (define goes-by (mbody-val (<-wait occupant 'goes-by)))
124 (when (ci-member direct-obj goes-by)
126 (mbody-val (<-wait player 'get-occupants)))
129 (define (this-thing-name)
130 (mbody-val (<-wait this-thing 'get-name)))
131 (define (should-put-in-me)
133 (slot-ref-maybe-runcheck gameobj 'put-in-me? player this-thing)))
134 (define (default-objection)
135 `("As much as you'd like to, it doesn't seem like you can put "
136 ,(this-thing-name) " " ,preposition " " ,our-name "."))
137 (define (this-thing-objection)
138 (mbody-receive (_ put-in-ok? #:key why-not) ; does the object object to being moved?
139 (<-wait this-thing 'ok-to-be-put-in? player (actor-id gameobj))
140 (and (not put-in-ok?)
141 ;; Either give the specified reason, or give a boilerplate one
142 (or why-not (default-objection)))))
144 ;; Is it not there, or maybe we won't allow it to be taken?
147 #:text `("You don't seem to have any such " ,direct-obj " to put "
148 ,preposition " " ,our-name ".")))
150 ((or (not (should-put-in-me)))
152 #:text (default-objection)))
153 ;; the thing we wsant to take itself has objected...
154 ((this-thing-objection) =>
158 ;; looks like we can take it
160 ;; Wait to announce to the player just in case settting the location
161 ;; errors out or something. Maybe it's overthinking things, I dunno.
162 (<-wait this-thing 'set-loc! #:loc (actor-id gameobj))
164 #:text `("You put " ,(this-thing-name) " " ,preposition " "
166 (<- player-loc 'tell-room
167 #:text `(,player-name " puts " ,(this-thing-name) " " ,preposition " "