adding and dropping things works
[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
51 (define readable-commands*
52   (append readable-commands
53           thing-commands))
54
55 (define readable-actions
56   (build-actions
57    (cmd-read (wrap-apply readable-cmd-read))))
58
59 (define readable-actions*
60   (append readable-actions
61           thing-actions*))
62
63 (define-class <readable> (<thing>)
64   (read-text #:init-value "All it says is: \"Blah blah blah.\""
65              #:init-keyword #:read-text)
66   (commands
67    #:init-value readable-commands*)
68   (message-handler
69    #:init-value
70    (simple-dispatcher readable-actions*)))
71
72 (define (readable-cmd-read actor message)
73   (<- actor (message-from message) 'tell
74       #:text (string-append (slot-ref actor 'read-text) "\n")))
75
76
77 \f
78 ;;; Lobby
79 ;;; -----
80
81 (define-mhandler (npc-chat-randomly actor message)
82   (define text-to-send
83     (format #f "~a says: \"~a\"\n"
84             (slot-ref actor 'name)
85             (random-choice (slot-ref actor 'catchphrases))))
86   (<- actor (message-from message) 'tell
87       #:text text-to-send))
88
89 (define chat-commands
90   (list
91    (direct-command "chat" 'cmd-chat)
92    (direct-command "talk" 'cmd-chat)))
93 (define chat-actions
94   (build-actions
95    (cmd-chat (wrap-apply npc-chat-randomly))))
96
97 (define hotel-owner-grumps
98   '("Eight sinks!  Eight sinks!  And I couldn't unwind them..."
99     "Don't mind the mess.  I built this place on a dare, you
100 know?"
101     "(*tearfully*) Here, take this parenthesis.  May it serve
102 you well."
103     "I gotta get back to the goblin farm soon..."
104     "Oh, but I was going to make a mansion... a great,
105 beautiful mansion!  Full of ghosts!  Now all I have is this cruddy
106 mo... hotel.  Oh... If only I had more time!"
107     "I told them to paint more of the walls purple.
108 Why didn't they listen?"
109     "Listen to that overhead muzak.  Whoever made that doesn't
110 know how to compose very well!  Have you heard of the bands 'fmt'
111 or 'skribe'?  Now *that's* composition!"))
112
113 (define-class <chatty-npc> (<gameobj>)
114   (catchphrases #:init-value '("Blarga blarga blarga!")
115                 #:init-keyword #:catchphrases)
116   (commands
117    #:init-value chat-commands)
118   (message-handler
119    #:init-value
120    (simple-dispatcher (append gameobj-actions chat-actions))))
121
122 (define random-bricabrac
123   '("a creepy porcelain doll"
124     "assorted 1950s robots"
125     "an exquisite tea set"
126     "an antique mustard pot"
127     "the pickled head of Elvis"
128     "the pickled circuitboard of EVLIS"
129     "a scroll of teletype paper holding the software Four Freedoms"
130     "a telephone shaped like an orange cartoon cat"))
131
132 (define-class <sign-in-form> (<gameobj>)
133   (commands
134    #:init-value
135    (list
136     (indir-as-direct-command "sign" 'cmd-sign-form
137                              '("as"))))
138   (message-handler
139    #:init-value
140    (simple-dispatcher
141     (append
142      (build-actions
143       (cmd-sign-form (wrap-apply sign-cmd-sign-in)))
144      gameobj-actions))))
145
146
147 (define name-sre
148   (sre->irregex '(: alpha (** 1 14 (or alphanum "-" "_")))))
149
150 (define forbidden-words
151   (append article preposition
152           '("and" "or" "but" "admin")))
153
154 (define (valid-name? name)
155   (and (irregex-match name-sre name)
156        (not (member name forbidden-words))))
157
158 (define-mhandler (sign-cmd-sign-in actor message direct-obj indir-obj)
159   (define old-name
160     (message-ref
161      (<-wait actor (message-from message) 'get-name)
162      'val))
163   (define name indir-obj)
164   (if (valid-name? indir-obj)
165       (begin
166         (<-wait actor (message-from message) 'set-name!
167                 #:val name)
168         (<- actor (slot-ref actor 'loc) 'tell-room
169             #:text (format #f "~a signs the form!\n~a is now known as ~a\n"
170                            old-name old-name name)))
171       (<- actor (message-from message) 'tell
172           #:text "Sorry, that's not a valid name.
173 Alphanumerics, _ and - only, 2-15 characters, starts with an alphabetic
174 character.\n")))
175
176
177 (define lobby
178   (lol
179    ('room:lobby
180     <room> #f
181     #:name "Hotel Lobby"
182     #:desc
183     "  You're in some sort of hotel lobby.  You see a large sign hanging
184 over the desk that says \"Hotel Bricabrac\".  On the desk is a bell
185 that says \"ring for service\".  Terrible music plays from a speaker
186 somewhere overhead.
187   The room is lined with various curio cabinets, filled with all sorts
188 of kitschy junk.  It looks like whoever decorated this place had great
189 ambitions, but actually assembled it all in a hurry and used whatever
190 kind of objects they found lying around.
191   There's a door to the north leading to some kind of hallway."
192     #:exits
193     (list (make <exit>
194             #:name "north"
195             #:to 'room:grand-hallway)))
196    ;; NPC: hotel owner
197    ('npc:lobby:hotel-owner
198     <chatty-npc> 'room:lobby
199     #:name "a frumpy fellow"
200     #:desc "  Whoever this is, they looks totally exhausted.  They're
201 collapsed into the only comfortable looking chair in the room and you
202 don't get the sense that they're likely to move any time soon.
203   You notice they're wearing a sticker badly adhesed to their clothing
204 which says \"Hotel Proprietor\", but they look so disorganized that you
205 think that can't possibly be true... can it?
206   Despite their exhaustion, you sense they'd be happy to chat with you,
207 though the conversation may be a bit one sided."
208     #:goes-by '("frumpy fellow" "fellow"
209                 "Chris Webber"  ; heh, did you rtfc?  or was it so obvious?
210                 "hotel proprietor" "proprietor")
211     #:catchphrases hotel-owner-grumps)
212    ;; NPC: desk clerk (comes when you ring the s)
213    ;;   impatient teenager, only stays around for a few minutes
214    ;;   complaining, then leaves.
215    
216    ;; Object: Sign
217    ('thing:lobby:sign
218     <readable> 'room:lobby
219     #:name "the Hotel Bricabrac sign"
220     #:desc "  It strikes you that there's something funny going on with this sign.
221 Sure enough, if you look at it hard enough, you can tell that someone
222 hastily painted over an existing sign and changed the \"M\" to an \"H\".
223 Classy!"
224     #:read-text "  All it says is \"Hotel Bricabrac\" in smudged, hasty text."
225     #:goes-by '("sign"
226                 "bricabrac sign"
227                 "hotel sign"
228                 "hotel bricabrac sign"
229                 "lobby sign"))
230
231    ;; Object: curio cabinets
232    ('thing:lobby:cabinet
233     <gameobj> 'room:lobby
234     #:name "a curio cabinet"
235     #:goes-by '("curio cabinet" "cabinet" "bricabrac cabinet")
236     #:desc (lambda _
237              (format #f "  The curio cabinet is full of all sorts of oddities!
238 Something catches your eye!
239 Ooh, ~a!" (random-choice random-bricabrac))))
240    ('thing:lobby:sign-in-form
241     <sign-in-form> 'room:lobby
242     #:name "sign-in form"
243     #:goes-by '("sign-in form" "form" "signin form")
244     #:desc "It looks like you could sign this form and set your name.")
245    ;; Object: desk
246    ;;  - Object: bell
247    ;;  - Object: sign in form
248    ;;  - Object: pamphlet
249    ;; Object: <invisible bell>: reprimands that you want to ring the
250    ;;   bell on the desk
251    )
252   )
253
254
255 \f
256 ;;; Grand hallway
257 ;;; -------------
258
259 (define grand-hallway
260   (lol
261    ('room:grand-hallway
262     <room> #f
263     #:name "Grand Hallway"
264     #:desc "  A majestic red carpet runs down the center of the room.
265 Busts of serious looking people line the walls, but there's no
266 clear indication that they have any logical relation to this place.
267   In the center is a large statue of a bearded man.  You wonder what
268 that's all about?
269   To the south is the lobby.  A door to the east is labeled \"smoking
270 room\", while a door to the west is labeled \"playroom\"."
271     #:exits
272     (list (make <exit>
273             #:name "south"
274             #:to 'room:lobby)
275           (make <exit>
276             #:name "west"
277             #:to 'room:playroom)
278           (make <exit>
279             #:name "east"
280             #:to 'room:smoking-parlor)))
281    ('thing:ignucius-statue
282     <gameobj> 'room:grand-hallway
283     #:name "a statue"
284     #:desc "  The statue is of a serious-looking bearded man with long, flowing hair.
285 The inscription says \"St. Ignucius\".
286   It has a large physical halo.  It doesn't look like it would be hard to remove."
287     #:goes-by '("statue" "st ignucius" "st. ignucius"))))
288
289 \f
290 ;;; Playroom
291 ;;; --------
292
293 (define playroom
294   (lol
295    ('room:playroom
296     <room> #f
297     #:name "The Playroom"
298     #:desc "  There are toys scattered everywhere here.  It's really unclear
299 if this room is intended for children or child-like adults."
300     #:exits
301     (list (make <exit>
302             #:name "east"
303             #:to 'room:grand-hallway)))
304    ('thing:playroom:cubey
305     <thing> 'room:playroom
306     #:name "cubey"
307     #:takeable #t
308     #:desc "  It's a little foam cube with googly eyes on it.  So cute!")))
309
310
311 \f
312 ;;; Writing room
313 ;;; ------------
314
315 \f
316 ;;; Armory???
317 ;;; ---------
318
319 ;; ... full of NURPH weapons?
320
321 \f
322 ;;; Smoking parlor
323 ;;; --------------
324
325 (define-class <furniture> (<gameobj>)
326   (sit-phrase #:init-keyword #:sit-phrase)
327   (sit-phrase-third-person #:init-keyword #:sit-phrase-third-person)
328   (sit-name #:init-keyword #:sit-name)
329
330   (commands
331    #:init-value
332    (list
333     (direct-command "sit" 'cmd-sit-furniture)))
334   (message-handler
335    #:init-value
336    (simple-dispatcher
337     (append
338      (build-actions
339       (cmd-sit-furniture (wrap-apply furniture-cmd-sit)))
340      gameobj-actions))))
341
342 (define-mhandler (furniture-cmd-sit actor message direct-obj)
343   (define player-name
344     (message-ref
345      (<-wait actor (message-from message) 'get-name)
346      'val))
347   (<- actor (message-from message) 'tell
348       #:text (format #f "You ~a ~a.\n"
349                      (slot-ref actor 'sit-phrase)
350                      (slot-ref actor 'sit-name)))
351   (<- actor (slot-ref actor 'loc) 'tell-room
352       #:text (format #f "~a ~a on ~a.\n"
353                      player-name
354                      (slot-ref actor 'sit-phrase-third-person)
355                      (slot-ref actor 'sit-name))
356       #:exclude (message-from message)))
357
358
359 (define smoking-parlor
360   (lol
361    ('room:smoking-parlor
362     <room> #f
363     #:name "Smoking Parlor"
364     #:desc "  This room looks quite posh.  There are huge comfy seats you can sit in
365 if you like.
366   Strangely, you see a large sign saying \"No Smoking\".  The owners must
367 have installed this place and then changed their mind later.
368   Nonetheless there are some candy cigarettes and cigars you can pick up
369 at the bar.  (editor's note: or will be soon :])"
370     #:exits
371     (list (make <exit>
372             #:name "west"
373             #:to 'room:grand-hallway)))
374    ('thing:smoking-room:chair
375     <furniture> 'room:smoking-parlor
376     #:name "a comfy leather chair"
377     #:desc "  That leather chair looks really comfy!"
378     #:goes-by '("leather chair" "comfy leather chair" "chair")
379     #:sit-phrase "sink into"
380     #:sit-phrase-third-person "sinks into"
381     #:sit-name "the comfy leather chair")
382    ('thing:smoking-room:sofa
383     <furniture> 'room:smoking-parlor
384     #:name "a plush leather sofa"
385     #:desc "  That leather chair looks really comfy!"
386     #:goes-by '("leather sofa" "plush leather sofa" "sofa"
387                 "leather couch" "plush leather couch" "couch")
388     #:sit-phrase "sprawl out on"
389     #:sit-phrase-third-person "sprawls out on into"
390     #:sit-name "the plush leather couch")
391    ('thing:smoking-room:bar-stool
392     <furniture> 'room:smoking-parlor
393     #:name "a bar stool"
394     #:desc "  Conveniently located near the bar!  Not the most comfortable
395 seat in the room, though."
396     #:goes-by '("stool" "bar stool")
397     #:sit-phrase "hop on"
398     #:sit-phrase-third-person "hops onto"
399     #:sit-name "the bar stool")
400
401    ;; TODO: Cigar dispenser
402
403    ))
404
405 \f
406 ;;; Ennpie's Sea Lounge
407 ;;; -------------------
408
409 \f
410 ;;; Computer room
411 ;;; -------------
412
413 \f
414 ;;; Game
415 ;;; ----
416
417 (define game-spec
418   (append lobby grand-hallway smoking-parlor
419           playroom))
420
421 ;; TODO: Provide command line args
422 (define (run-game . args)
423   (run-demo game-spec 'room:lobby #:repl-server #t))
424