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/>.
19 ;;; Common "things" and stuff you can do with things.
21 (define-module (mudsync thing)
22 #:use-module (mudsync command)
23 #:use-module (mudsync gameobj)
24 #:use-module (8sync actors)
25 #:use-module (8sync agenda)
26 #:use-module (oop goops)
27 #:use-module (ice-9 match)
28 #:use-module (ice-9 format)
31 (define-class <thing> (<gameobj>)
32 ;; Can be a boolean or a procedure accepting two arguments
33 ;; (thing-actor whos-acting)
34 (takeable #:init-value #f
35 #:init-keyword #:takeable)
36 ;; Can be a boolean or a procedure accepting two arguments
37 ;; (thing-actor whos-dropping)
38 (dropable #:init-value #t
39 #:init-keyword #:dropable)
41 #:allocation #:each-subclass
42 #:init-thunk (build-commands
43 ("take" ((direct-command cmd-take)))))
45 #:allocation #:each-subclass
46 #:init-value (build-commands
47 ("drop" ((direct-command cmd-drop)))))
48 (actions #:allocation #:each-subclass
51 (cmd-take thing-cmd-take)
52 (cmd-drop thing-cmd-drop))))
54 (define* (thing-cmd-take thing message #:key direct-obj)
55 (define player (message-from message))
57 (mbody-val (<-wait player 'get-name)))
59 (mbody-val (<-wait player 'get-loc)))
60 (define thing-name (slot-ref thing 'name))
62 (slot-ref-maybe-runcheck thing 'takeable player))
64 ;; Set the location to whoever's picking us up
66 (gameobj-set-loc! thing player)
68 #:text (format #f "You pick up ~a.\n"
70 (<- player-loc 'tell-room
71 #:text (format #f "~a picks up ~a.\n"
76 #:text (format #f "It doesn't seem like you can pick up ~a.\n"
79 (define* (thing-cmd-drop thing message #:key direct-obj)
80 (define player (message-from message))
82 (mbody-val (<-wait player 'get-name)))
84 (mbody-val (<-wait player 'get-loc)))
85 (define thing-name (slot-ref thing 'name))
87 (slot-ref-maybe-runcheck thing 'dropable player))
89 ;; Set the location to whoever's picking us up's location
91 (gameobj-set-loc! thing player-loc)
93 #:text (format #f "You drop ~a.\n"
95 (<- player-loc 'tell-room
96 #:text (format #f "~a drops ~a.\n"
101 #:text (format #f "It doesn't seem like you can drop ~a.\n"