add chat as an alias for talk
[mudsync.git] / worlds / bricabrac.scm
1 ;;; Mudsync --- Live hackable MUD
2 ;;; Copyright © 2016 Christopher Allan Webber <cwebber@dustycloud.org>
3 ;;;
4 ;;; This file is part of Mudsync.
5 ;;;
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.
10 ;;;
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.
15 ;;;
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/>.
18
19 ;;; Hotel Bricabrac
20
21 (use-modules (mudsync)
22              (mudsync parser)
23              (8sync systems actors)
24              (8sync agenda)
25              (oop goops)
26              (ice-9 format)
27              (rx irregex))
28
29
30 \f
31 ;;; Utilities, useful or otherwise
32 ;;; ==============================
33
34 (set! *random-state* (random-state-from-platform))
35
36 (define (random-choice lst)
37   (list-ref lst (random (length lst))))
38
39 ;; list of lists, lol.
40 (define-syntax-rule (lol (list-contents ...) ...)
41   (list (list list-contents ...) ...))
42
43 \f
44 ;;; Some simple object types.
45 ;;; =========================
46
47 (define readable-commands
48   (list
49    (direct-command "read" 'cmd-read)))
50 (define readable-actions
51   (build-actions
52    (cmd-read (wrap-apply readable-cmd-read))))
53
54 (define-class <readable> (<gameobj>)
55   (read-text #:init-value "All it says is: \"Blah blah blah.\""
56              #:init-keyword #:read-text)
57   (commands
58    #:init-value readable-commands)
59   (message-handler
60    #:init-value
61    (simple-dispatcher (append gameobj-actions readable-actions))))
62
63 (define (readable-cmd-read actor message)
64   (<- actor (message-from message) 'tell
65       #:text (string-append (slot-ref actor 'read-text) "\n")))
66
67
68 \f
69 ;;; Lobby
70 ;;; -----
71
72 (define-mhandler (npc-chat-randomly actor message)
73   (define text-to-send
74     (format #f "~a says: \"~a\"\n"
75             (slot-ref actor 'name)
76             (random-choice (slot-ref actor 'catchphrases))))
77   (<- actor (message-from message) 'tell
78       #:text text-to-send))
79
80 (define chat-commands
81   (list
82    (direct-command "chat" 'cmd-chat)
83    (direct-command "talk" 'cmd-chat)))
84 (define chat-actions
85   (build-actions
86    (cmd-chat (wrap-apply npc-chat-randomly))))
87
88 (define hotel-owner-grumps
89   '("Eight sinks!  Eight sinks!  And I couldn't unwind them..."
90     "Don't mind the mess.  I built this place on a dare, you
91 know?"
92     "(*tearfully*) Here, take this parenthesis.  May it serve
93 you well."
94     "I gotta get back to the goblin farm soon..."
95     "Oh, but I was going to make a mansion... a great,
96 beautiful mansion!  Full of ghosts!  Now all I have is this cruddy
97 mo... hotel.  Oh... If only I had more time!"
98     "I told them to paint more of the walls purple.
99 Why didn't they listen?"
100     "Listen to that overhead muzak.  Whoever made that doesn't
101 know how to compose very well!  Have you heard of the bands 'fmt'
102 or 'skribe'?  Now *that's* composition!"))
103
104 (define-class <chatty-npc> (<gameobj>)
105   (catchphrases #:init-value '("Blarga blarga blarga!")
106                 #:init-keyword #:catchphrases)
107   (commands
108    #:init-value chat-commands)
109   (message-handler
110    #:init-value
111    (simple-dispatcher (append gameobj-actions chat-actions))))
112
113 (define random-bricabrac
114   '("a creepy porcelain doll"
115     "assorted 1950s robots"
116     "an exquisite tea set"
117     "an antique mustard pot"
118     "the pickled head of Elvis"
119     "the pickled circuitboard of EVLIS"
120     "a scroll of teletype paper holding the software Four Freedoms"
121     "a telephone shaped like an orange cartoon cat"))
122
123 (define-class <sign-in-form> (<gameobj>)
124   (commands
125    #:init-value
126    (list
127     (indir-as-direct-command "sign" 'cmd-sign-form
128                              '("as"))))
129   (message-handler
130    #:init-value
131    (simple-dispatcher
132     (append
133      (build-actions
134       (cmd-sign-form (wrap-apply sign-cmd-sign-in)))
135      gameobj-actions))))
136
137
138 (define name-sre
139   (sre->irregex '(: alpha (** 1 14 (or alphanum "-" "_")))))
140
141 (define forbidden-words
142   (append article preposition
143           '("and" "or" "but" "admin")))
144
145 (define (valid-name? name)
146   (and (irregex-match name-sre name)
147        (not (member name forbidden-words))))
148
149 (define-mhandler (sign-cmd-sign-in actor message direct-obj indir-obj)
150   (define old-name
151     (message-ref
152      (<-wait actor (message-from message) 'get-name)
153      'val))
154   (define name indir-obj)
155   (if (valid-name? indir-obj)
156       (begin
157         (<-wait actor (message-from message) 'set-name!
158                 #:val name)
159         (<- actor (slot-ref actor 'loc) 'tell-room
160             #:text (format #f "~a signs the form!\n~a is now known as ~a\n"
161                            old-name old-name name)))
162       (<- actor (message-from message) 'tell
163           "Sorry, that's not a valid name.
164 Alphanumerics, _ and - only, 2-15 characters, starts with an alphabetic
165 character.")))
166
167
168 (define lobby
169   (lol
170    ('room:lobby
171     <room> #f
172     #:name "Hotel Lobby"
173     #:desc
174     "  You're in some sort of hotel lobby.  You see a large sign hanging
175 over the desk that says \"Hotel Bricabrac\".  On the desk is a bell
176 that says \"ring for service\".  Terrible music plays from a speaker
177 somewhere overhead.
178   The room is lined with various curio cabinets, filled with all sorts
179 of kitschy junk.  It looks like whoever decorated this place had great
180 ambitions, but actually assembled it all in a hurry and used whatever
181 kind of objects they found lying around.
182   There's a door to the north leading to some kind of hallway."
183     #:exits
184     (list (make <exit>
185             #:name "north"
186             #:to-symbol 'room:grand-hallway)))
187    ;; NPC: hotel owner
188    ('npc:hotel-owner
189     <chatty-npc> 'room:lobby
190     #:name "a frumpy fellow"
191     #:desc "  Whoever this is, they looks totally exhausted.  They're
192 collapsed into the only comfortable looking chair in the room and you
193 don't get the sense that they're likely to move any time soon.
194   You notice they're wearing a sticker badly adhesed to their clothing
195 which says \"Hotel Proprietor\", but they look so disorganized that you
196 think that can't possibly be true... can it?
197   Despite their exhaustion, you sense they'd be happy to chat with you,
198 though the conversation may be a bit one sided."
199     #:goes-by '("frumpy fellow" "fellow"
200                 "Chris Webber"  ; heh, did you rtfc?  or was it so obvious?
201                 "hotel proprietor" "proprietor")
202     #:catchphrases hotel-owner-grumps)
203    ;; NPC: desk clerk (comes when you ring the s)
204    ;;   impatient teenager, only stays around for a few minutes
205    ;;   complaining, then leaves.
206    
207    ;; Object: Sign
208    ('thing:lobby-sign
209     <readable> 'room:lobby
210     #:name "the Hotel Bricabrac sign"
211     #:desc "  It strikes you that there's something funny going on with this sign.
212 Sure enough, if you look at it hard enough, you can tell that someone
213 hastily painted over an existing sign and changed the \"M\" to an \"H\".
214 Classy!"
215     #:read-text "  All it says is \"Hotel Bricabrac\" in smudged, hasty text."
216     #:goes-by '("sign"
217                 "bricabrac sign"
218                 "hotel sign"
219                 "hotel bricabrac sign"
220                 "lobby sign"))
221
222    ;; Object: curio cabinets
223    ('thing:cabinet
224     <gameobj> 'room:lobby
225     #:name "a curio cabinet"
226     #:goes-by '("curio cabinet" "cabinet" "bricabrac cabinet")
227     #:desc (lambda _
228              (format #f "  The curio cabinet is full of all sorts of oddities!
229 Something catches your eye!
230 Ooh, ~a!" (random-choice random-bricabrac))))
231    ('thing:sign-in-form
232     <sign-in-form> 'room:lobby
233     #:name "sign-in form"
234     #:goes-by '("sign-in form" "form" "signin form")
235     #:desc "It looks like you could sign this form and set your name.")
236    ;; Object: desk
237    ;;  - Object: bell
238    ;;  - Object: sign in form
239    ;;  - Object: pamphlet
240    ;; Object: <invisible bell>: reprimands that you want to ring the
241    ;;   bell on the desk
242    )
243   )
244
245
246 \f
247 ;;; Grand hallway
248 ;;; -------------
249
250 (define grand-hallway
251   (lol
252    ('room:grand-hallway
253     <room> #f
254     #:name "Grand Hallway"
255     #:desc "  A majestic red carpet runs down the center of the room.
256 Busts of serious looking people line the walls, but there's no
257 clear indication that they have any logical relation to this place.
258   To the south is the lobby.  All around are various doors, but
259 they're all boarded up.  Guess this is still a work in progress, huh?"
260     #:exits
261     (list (make <exit>
262             #:name "south"
263             #:to-symbol 'room:lobby))
264     )))
265
266 \f
267 ;;; Playroom
268 ;;; --------
269
270 \f
271 ;;; Writing room
272 ;;; ------------
273
274 \f
275 ;;; Armory???
276 ;;; ---------
277
278 ;; ... full of NURPH weapons?
279
280 \f
281 ;;; Smoking parlor
282 ;;; --------------
283
284
285 \f
286 ;;; Ennpie's Sea Lounge
287 ;;; -------------------
288
289 \f
290 ;;; Computer room
291 ;;; -------------
292
293 \f
294 ;;; Game
295 ;;; ----
296
297 (define game-spec
298   (append lobby grand-hallway))
299
300 (define (run-game . args)
301   (run-demo "/tmp/bricabrac-game.db" game-spec 'room:lobby))
302