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 (define-module (mudsync room)
20 #:use-module (mudsync command)
21 #:use-module (mudsync gameobj)
22 #:use-module (8sync systems actors)
23 #:use-module (8sync agenda)
24 #:use-module (oop goops)
25 #:use-module (srfi srfi-1)
36 (define-class <exit> ()
38 (to-symbol #:init-keyword #:to-symbol)
39 ;; The actual address we use
40 (to-address #:init-keyword #:address)
41 ;; Name of the room (@@: Should this be names?)
42 (name #:getter exit-name
43 #:init-keyword #:name)
44 (desc #:init-keyword #:desc
47 ;; *Note*: These two methods have an extra layer of indirection, but
48 ;; it's for a good reason.
49 (visible-check #:init-value (const #t)
50 #:init-keyword #:visible-check)
51 ;; By default all exits can be traversed
52 (traverse-check #:init-value (const #t)
53 #:init-keyword #:traverse-check))
55 (define* (exit-can-traverse? exit actor
56 #:optional (target-actor (actor-id actor)))
57 ((slot-ref exit 'traverse-check) exit actor target-actor))
59 (define* (exit-is-visible? exit actor
60 #:optional (target-actor (actor-id actor)))
61 ((slot-ref exit 'traverse-check) exit actor target-actor))
68 (define %room-contain-commands
70 (loose-direct-command "look" 'cmd-look-at)
71 (empty-command "look" 'cmd-look-room)
72 (empty-command "go" 'cmd-go-where)
73 (loose-direct-command "go" 'cmd-go)))
77 ;; desc == description
78 (wire-exits! (wrap-apply room-wire-exits!))
79 (cmd-go (wrap-apply room-cmd-go))
80 (cmd-go-where (wrap-apply room-cmd-go-where))
81 (cmd-look-room (wrap-apply room-cmd-look-room))))
84 (append room-actions gameobj-actions))
86 (define room-action-dispatch
87 (simple-dispatcher room-actions*))
89 ;; TODO: Subclass from container?
90 (define-class <room> (<gameobj>)
92 (exits #:init-value '()
93 #:init-keyword #:exits
97 #:init-value (wrap %room-contain-commands))
100 #:allocation #:each-subclass
101 ;; @@: Can remove this indirection once things settle
102 #:init-value (wrap-apply room-action-dispatch)))
105 (define (room-wire-exits! room message)
106 "Actually hook up the rooms' exit addresses to the rooms they
112 (<-wait room (gameobj-gm room) 'lookup-room
113 #:symbol (slot-ref exit 'to-symbol))
116 (slot-set! exit 'to-address new-exit))
120 (define-mhandler (room-cmd-go room message direct-obj)
124 (equal? (exit-name exit) direct-obj))
128 (<-wait room (message-from message) 'set-loc!
129 #:loc (slot-ref exit 'to-address))
130 (<- room (message-from message) 'look-room))
132 (<- room (message-from message) 'tell
133 #:text "I don't know where that is?\n"))))
135 (define-mhandler (room-cmd-go-where room message)
136 (<- room (message-from message) 'tell
137 #:text "Go where?\n"))
139 (define-mhandler (room-cmd-look-room room message)
140 (<- room (message-from message) 'look-room))