start of smoking room, and some namespacing
[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 'room:grand-hallway)))
187    ;; NPC: hotel owner
188    ('npc:lobby: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:lobby: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:lobby: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   In the center is a large statue of a bearded man.  You wonder what
259 that's all about?
260   To the south is the lobby.  All around are various doors, but
261 they're all boarded up.  One to the east goes to the smoking parlor,
262 though."
263     #:exits
264     (list (make <exit>
265             #:name "south"
266             #:to 'room:lobby)
267           (make <exit>
268             #:name "east"
269             #:to 'room:smoking-parlor)))
270    ('thing:ignucius-statue
271     <gameobj> 'room:grand-hallway
272     #:name "a statue"
273     #:desc "  The statue is of a serious-looking bearded man with long, flowing hair.
274 The inscription says \"St. Ignucius\".
275   It has a large physical halo.  It doesn't look like it would be hard to remove."
276     #:goes-by '("statue" "st ignucius" "st. ignucius"))))
277
278 \f
279 ;;; Playroom
280 ;;; --------
281
282 \f
283 ;;; Writing room
284 ;;; ------------
285
286 \f
287 ;;; Armory???
288 ;;; ---------
289
290 ;; ... full of NURPH weapons?
291
292 \f
293 ;;; Smoking parlor
294 ;;; --------------
295
296 (define-class <furniture> (<gameobj>)
297   (sit-phrase #:init-keyword #:sit-phrase)
298   (sit-phrase-third-person #:init-keyword #:sit-phrase-third-person)
299   (sit-name #:init-keyword #:sit-name)
300
301   (commands
302    #:init-value
303    (list
304     (direct-command "sit" 'cmd-sit-furniture)))
305   (message-handler
306    #:init-value
307    (simple-dispatcher
308     (append
309      (build-actions
310       (cmd-sit-furniture (wrap-apply furniture-cmd-sit)))
311      gameobj-actions))))
312
313 (define-mhandler (furniture-cmd-sit actor message direct-obj)
314   (define player-name
315     (message-ref
316      (<-wait actor (message-from message) 'get-name)
317      'val))
318   (<- actor (message-from message) 'tell
319       #:text (format #f "You ~a ~a.\n"
320                      (slot-ref actor 'sit-phrase)
321                      (slot-ref actor 'sit-name)))
322   (<- actor (slot-ref actor 'loc) 'tell-room
323       #:text (format #f "~a ~a on ~a.\n"
324                      player-name
325                      (slot-ref actor 'sit-phrase-third-person)
326                      (slot-ref actor 'sit-name))
327       #:exclude (message-from message)))
328
329
330 (define smoking-parlor
331   (lol
332    ('room:smoking-parlor
333     <room> #f
334     #:name "Smoking Parlor"
335     #:desc "  This room looks quite posh.  There are huge comfy seats you can sit in
336 if you like.
337   Strangely, you see a large sign saying \"No Smoking\".  The owners must
338 have installed this place and then changed their mind later.
339   Nonetheless there are some candy cigarettes and cigars you can pick up
340 at the bar.  (editor's note: or will be soon :])"
341     #:exits
342     (list (make <exit>
343             #:name "west"
344             #:to 'room:grand-hallway)))
345    ('thing:smoking-room:chair
346     <furniture> 'room:smoking-parlor
347     #:name "a comfy leather chair"
348     #:desc "  That leather chair looks really comfy!"
349     #:goes-by '("leather chair" "comfy leather chair" "chair")
350     #:sit-phrase "sink into"
351     #:sit-phrase-third-person "sinks into"
352     #:sit-name "the comfy leather chair")
353    ('thing:smoking-room:sofa
354     <furniture> 'room:smoking-parlor
355     #:name "a plush leather sofa"
356     #:desc "  That leather chair looks really comfy!"
357     #:goes-by '("leather sofa" "plush leather sofa" "chair"
358                 "leather couch" "plush leather couch" "couch")
359     #:sit-phrase "sprawl out on"
360     #:sit-phrase-third-person "sprawls out on into"
361     #:sit-name "the plush leather couch")
362    ('thing:smoking-room:bar-stool
363     <furniture> 'room:smoking-parlor
364     #:name "a bar stool"
365     #:desc "  Conveniently located near the bar!  Not the most comfortable
366 seat in the room, though."
367     #:goes-by '("stool" "bar stool")
368     #:sit-phrase "hop on"
369     #:sit-phrase-third-person "hops onto"
370     #:sit-name "the bar stool")))
371
372 \f
373 ;;; Ennpie's Sea Lounge
374 ;;; -------------------
375
376 \f
377 ;;; Computer room
378 ;;; -------------
379
380 \f
381 ;;; Game
382 ;;; ----
383
384 (define game-spec
385   (append lobby grand-hallway smoking-parlor))
386
387 ;; TODO: Provide command line args
388 (define (run-game . args)
389   (run-demo game-spec 'room:lobby #:repl-server #t))
390