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 gameobj)
21 #:use-module (8sync systems actors)
22 #:use-module (8sync agenda)
23 #:use-module (oop goops)
30 (define-class <exit> ()
32 (to-symbol #:accessor exit-to-symbol
33 #:init-keyword #:to-symbol)
34 ;; The actual address we use
35 (to-address #:accessor exit-to-address
36 #:init-keyword #:address)
37 ;; Name of the room (@@: Should this be names?)
38 (name #:accessor exit-name
39 #:init-keyword #:name)
40 (desc #:accessor exit-desc
41 #:init-keyword #:desc)
43 ;; *Note*: These two methods have an extra layer of indirection, but
44 ;; it's for a good reason.
45 (visible-check #:init-value (const #t)
46 #:init-keyword #:visible-check)
47 ;; By default all exits can be traversed
48 (traverse-check #:init-value (const #t)
49 #:init-keyword #:traverse-check))
51 (define* (exit-can-traverse? exit actor
52 #:optional (target-actor (actor-id actor)))
53 ((slot-ref exit 'traverse-check) exit actor target-actor))
55 (define* (exit-is-visible? exit actor
56 #:optional (target-actor (actor-id actor)))
57 ((slot-ref exit 'traverse-check) exit actor target-actor))
60 ;; Kind of a useful utility, maybe?
61 (define (simple-slot-getter slot)
62 (lambda (actor message)
63 (reply-message actor message
64 #:val (slot-ref actor slot))))
66 (define always (const #t))
69 (define full-command list)
71 ;; TODO: fill these in
72 (define cmatch-just-verb #f)
73 (define cmatch-direct-verb #f)
74 (define cmatch-direct-obj #f)
76 (define %room-contain-commands
78 (full-command "look" cmatch-just-verb always 'look-room)
79 (full-command "look" cmatch-direct-obj always 'look-member)
80 (full-command "go" cmatch-just-verb always 'go-where)
81 (full-command "go" cmatch-direct-obj always 'go-exit)))
83 ;; TODO: Subclass from container?
84 (define-class <room> (<gameobj>)
86 #:init-keyword #:desc)
87 ;; TODO: Switch this to be loc based
88 ;; Uses a hash table like a set (values ignored)
89 (occupants #:init-thunk make-hash-table)
91 (exits #:init-value '()
93 ;; @@: Maybe eventually <room> will inherit from some more general
97 #:init-value %room-contain-commands)
100 #:allocation #:each-subclass
102 (make-action-dispatch
103 ;; desc == description
105 (simple-slot-getter 'desc))
107 (simple-slot-getter 'name))
108 ((register-occupant! actor message who)
109 "Register an actor as being a occupant of this room"
110 (hash-set! (slot-ref actor 'occupants) who #t))
111 ((evict-occupant! actor message who)
112 "De-register an occupant removed from the room"
113 (hash-remove! (slot-ref actor 'occupants) who))
114 (wire-exits! (wrap-apply room-wire-exits!)))))
116 (define (room-wire-exits! room message)
117 "Actually hook up the rooms' exit addresses to the rooms they
122 (<-wait room (gameobj-gm room) 'lookup-room
123 #:symbol (exit-to-symbol exit)))
125 (set! (exit-to-address exit) new-exit))