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/>.
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 receive-star)
30 #:use-module (mudsync utils)
31 #:use-module (ice-9 control)
33 cmd-take-from cmd-put-in))
35 (define-actor <container> (<gameobj>)
36 ((cmd-take-from cmd-take-from)
37 (cmd-put-in cmd-put-in))
38 ;; Can be a boolean or a procedure accepting
39 ;; (gameobj whos-acting take-what)
40 (take-from-me? #:init-value #t
41 #:init-keyword #:take-from-me?)
42 ;; Can be a boolean or a procedure accepting
43 ;; (gameobj whos-acting put-what)
44 (put-in-me? #:init-value #t
45 #:init-keyword #:put-in-me?))
47 ;; @@: Moving this to a container subclass/mixin could allow a lot more
48 ;; customization of take out / put in phrases
49 (define* (cmd-take-from gameobj message
50 #:key direct-obj indir-obj preposition
51 (player (message-from message)))
53 (<-wait player 'get-name))
55 (<-wait player 'get-loc))
56 (define our-name (slot-ref gameobj 'name))
57 ;; We need to check if we even have such a thing
61 (for-each (lambda (occupant)
62 (define goes-by (<-wait occupant 'goes-by))
63 (when (ci-member direct-obj goes-by)
65 (gameobj-occupants gameobj))
68 (define (this-thing-name)
69 (<-wait this-thing 'get-name))
70 (define (should-take-from-me)
72 (slot-ref-maybe-runcheck gameobj 'take-from-me? player this-thing)))
73 (define (default-objection)
74 `("Unfortunately, it doesn't seem like you can take "
75 ,(this-thing-name) " " ,preposition " " ,our-name "."))
77 (define (this-thing-objection)
78 (receive* (taken-ok? #:key why-not) ; does the object object to being removed?
79 (<-wait this-thing 'ok-to-be-taken-from? player) ; @@ no need to supply from where
81 ;; Either give the specified reason, or give a boilerplate one
83 (default-objection)))))
85 ;; Unfortunately this does leak information about what is contained
86 ;; by us. Maybe not what's wanted in all circumstances.
89 #:text `("You don't see any such " ,direct-obj " to take "
90 ,preposition " " ,our-name ".")))
91 ;; A particular objection to taking this thing.
92 ;; We should allow customizing the reason here, which could be
93 ;; provided by the 'ok-to-be-taken-from? slot.
94 ((not (should-take-from-me))
96 #:text (default-objection)))
97 ;; the thing we wsant to take itself has objected...
98 ((this-thing-objection) =>
102 ;; looks like we can take it
104 ;; Wait to announce to the player just in case settting the location
105 ;; errors out or something. Maybe it's overthinking things, I dunno.
106 (<-wait this-thing 'set-loc! #:loc player)
108 #:text `("You take " ,(this-thing-name) " from "
110 (<- player-loc 'tell-room
111 #:text `(,player-name " takes " ,(this-thing-name) " from "
115 (define* (cmd-put-in gameobj message
116 #:key direct-obj indir-obj preposition
117 (player (message-from message)))
119 (<-wait player 'get-name))
121 (<-wait player 'get-loc))
122 (define our-name (slot-ref gameobj 'name))
123 ;; We need to check if we even have such a thing
127 (for-each (lambda (occupant)
128 (define goes-by (<-wait occupant 'goes-by))
129 (when (ci-member direct-obj goes-by)
131 (<-wait player 'get-occupants))
134 (define (this-thing-name)
135 (<-wait this-thing 'get-name))
136 (define (should-put-in-me)
138 (slot-ref-maybe-runcheck gameobj 'put-in-me? player this-thing)))
139 (define (default-objection)
140 `("As much as you'd like to, it doesn't seem like you can put "
141 ,(this-thing-name) " " ,preposition " " ,our-name "."))
142 (define (this-thing-objection)
143 (receive* (put-in-ok? #:key why-not) ; does the object object to being moved?
144 (<-wait this-thing 'ok-to-be-put-in? player (actor-id gameobj))
145 (and (not put-in-ok?)
146 ;; Either give the specified reason, or give a boilerplate one
147 (or why-not (default-objection)))))
149 ;; Is it not there, or maybe we won't allow it to be taken?
152 #:text `("You don't seem to have any such " ,direct-obj " to put "
153 ,preposition " " ,our-name ".")))
155 ((or (not (should-put-in-me)))
157 #:text (default-objection)))
158 ;; the thing we wsant to take itself has objected...
159 ((this-thing-objection) =>
163 ;; looks like we can take it
165 ;; Wait to announce to the player just in case settting the location
166 ;; errors out or something. Maybe it's overthinking things, I dunno.
167 (<-wait this-thing 'set-loc! #:loc (actor-id gameobj))
169 #:text `("You put " ,(this-thing-name) " " ,preposition " "
171 (<- player-loc 'tell-room
172 #:text `(,player-name " puts " ,(this-thing-name) " " ,preposition " "