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/>.
21 (use-modules (mudsync)
33 ;;; Utilities, useful or otherwise
34 ;;; ==============================
36 (set! *random-state* (random-state-from-platform))
38 (define (random-choice lst)
39 (list-ref lst (random (length lst))))
41 ;; list of lists, lol.
42 (define-syntax-rule (lol (list-contents ...) ...)
43 (list (list list-contents ...) ...))
46 ;;; Some simple object types.
47 ;;; =========================
49 (define readable-commands
51 (direct-command "read" 'cmd-read)))
53 (define readable-commands*
54 (append readable-commands
57 (define-class <readable> (<thing>)
58 (read-text #:init-value "All it says is: \"Blah blah blah.\""
59 #:init-keyword #:read-text)
61 #:init-value readable-commands*)
62 (actions #:allocation #:each-subclass
63 #:init-value (build-actions
64 (cmd-read readable-cmd-read))))
66 (define (readable-cmd-read actor message)
67 (<- (message-from message) 'tell
68 #:text (string-append (slot-ref actor 'read-text) "\n")))
75 (define (npc-chat-randomly actor message . _)
77 (format #f "~a says: \"~a\"\n"
78 (slot-ref actor 'name)
79 (random-choice (slot-ref actor 'catchphrases))))
80 (<- (message-from message) 'tell
85 (direct-command "chat" 'cmd-chat)
86 (direct-command "talk" 'cmd-chat)))
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
92 "(*tearfully*) Here, take this parenthesis. May it serve
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!"))
104 (define-class <chatty-npc> (<gameobj>)
105 (catchphrases #:init-value '("Blarga blarga blarga!")
106 #:init-keyword #:catchphrases)
108 #:init-value chat-commands)
109 (actions #:allocation #:each-subclass
112 (cmd-chat npc-chat-randomly))))
114 (define random-bricabrac
115 '("a creepy porcelain doll"
116 "assorted 1950s robots"
117 "an exquisite tea set"
118 "an antique mustard pot"
119 "the pickled head of Elvis"
120 "the pickled circuitboard of EVLIS"
121 "a scroll of teletype paper holding the software Four Freedoms"
122 "a telephone shaped like an orange cartoon cat"))
124 (define-class <sign-in-form> (<gameobj>)
128 (prep-direct-command "sign" 'cmd-sign-form
130 (actions #:allocation #:each-subclass
131 #:init-value (build-actions
132 (cmd-sign-form sign-cmd-sign-in))))
136 (sre->irregex '(: alpha (** 1 14 (or alphanum "-" "_")))))
138 (define forbidden-words
139 (append article preposition
140 '("and" "or" "but" "admin")))
142 (define (valid-name? name)
143 (and (irregex-match name-sre name)
144 (not (member name forbidden-words))))
146 (define* (sign-cmd-sign-in actor message
147 #:key direct-obj indir-obj preposition)
149 (mbody-val (<-wait (message-from message) 'get-name)))
150 (define name indir-obj)
151 (if (valid-name? indir-obj)
153 (<-wait (message-from message) 'set-name! name)
154 (<- (slot-ref actor 'loc) 'tell-room
155 #:text (format #f "~a signs the form!\n~a is now known as ~a\n"
156 old-name old-name name)))
157 (<- (message-from message) 'tell
158 #:text "Sorry, that's not a valid name.
159 Alphanumerics, _ and - only, 2-15 characters, starts with an alphabetic
163 (define summoning-bell-commands
165 (direct-command "ring" 'cmd-ring)))
166 (define summoning-bell-commands*
167 (append summoning-bell-commands
170 (define-class <summoning-bell> (<thing>)
171 (summons #:init-keyword #:summons)
174 #:init-value summoning-bell-commands*)
175 (actions #:allocation #:each-subclass
176 #:init-value (build-actions
177 (cmd-ring summoning-bell-cmd-ring))))
179 (define* (summoning-bell-cmd-ring bell message . _)
180 ;; Call back to actor who invoked this message handler
181 ;; and find out their name. We'll call *their* get-name message
182 ;; handler... meanwhile, this procedure suspends until we get
185 (mbody-val (<-wait (message-from message) 'get-name)))
187 ;; Now we'll invoke the "tell" message handler on the player
188 ;; who rang us, displaying this text on their screen.
189 ;; This one just uses <- instead of <-wait, since we don't
190 ;; care when it's delivered; we're not following up on it.
191 (<- (message-from message) 'tell
192 #:text "*ring ring!* You ring the bell!\n")
193 ;; We also want everyone else in the room to "hear" the bell,
194 ;; but they get a different message since they aren't the ones
195 ;; ringing it. Notice here's where we make use of the invoker's
196 ;; name as extracted and assigned to the who-rang variable.
197 ;; Notice how we send this message to our "location", which
198 ;; forwards it to the rest of the occupants in the room.
199 (<- (gameobj-loc bell) 'tell-room
201 (format #f "*ring ring!* ~a rings the bell!\n"
203 #:exclude (message-from message))
204 ;; Now we perform the primary task of the bell, which is to summon
205 ;; the "clerk" character to the room. (This is configurable,
206 ;; so we dynamically look up their address.)
207 (<- (dyn-ref bell (slot-ref bell 'summons)) 'be-summoned
208 #:who-summoned (message-from message)))
211 (define prefect-quotes
212 '("I'm a frood who really knows where my towel is!"
213 "On no account allow a Vogon to read poetry at you."
214 "Time is an illusion, lunchtime doubly so!"
215 "How can you have money if none of you produces anything?"
216 "On no account allow Arthur to request tea on this ship."))
224 '((p "You're in some sort of hotel lobby. You see a large sign hanging "
225 "over the desk that says \"Hotel Bricabrac\". On the desk is a bell "
226 "that says \"'ring bell' for service\". Terrible music plays from a speaker "
227 "somewhere overhead. "
228 "The room is lined with various curio cabinets, filled with all sorts "
229 "of kitschy junk. It looks like whoever decorated this place had great "
230 "ambitions, but actually assembled it all in a hurry and used whatever "
231 "kind of objects they found lying around.")
232 (p "There's a door to the north leading to some kind of hallway."))
236 #:to 'room:grand-hallway)))
238 ('npc:lobby:hotel-owner
239 <chatty-npc> 'room:lobby
240 #:name "a frumpy fellow"
242 '((p " Whoever this is, they looks totally exhausted. They're
243 collapsed into the only comfortable looking chair in the room and you
244 don't get the sense that they're likely to move any time soon.
245 You notice they're wearing a sticker badly adhesed to their clothing
246 which says \"Hotel Proprietor\", but they look so disorganized that you
247 think that can't possibly be true... can it?
248 Despite their exhaustion, you sense they'd be happy to chat with you,
249 though the conversation may be a bit one sided."))
250 #:goes-by '("frumpy fellow" "fellow"
251 "Chris Webber" ; heh, did you rtfc? or was it so obvious?
252 "hotel proprietor" "proprietor")
253 #:catchphrases hotel-owner-grumps)
256 <readable> 'room:lobby
257 #:name "the Hotel Bricabrac sign"
258 #:desc " It strikes you that there's something funny going on with this sign.
259 Sure enough, if you look at it hard enough, you can tell that someone
260 hastily painted over an existing sign and changed the \"M\" to an \"H\".
262 #:read-text " All it says is \"Hotel Bricabrac\" in smudged, hasty text."
266 "hotel bricabrac sign"
270 <summoning-bell> 'room:lobby
271 #:name "a shiny brass bell"
272 #:goes-by '("shiny brass bell" "shiny bell" "brass bell" "bell")
273 #:desc " A shiny brass bell. Inscribed on its wooden base is the text
274 \"ring me for service\". You probably could \"ring the bell\" if you
276 #:summons 'npc:break-room:desk-clerk)
278 ;; Object: curio cabinets
279 ('thing:lobby:cabinet
280 <gameobj> 'room:lobby
281 #:name "a curio cabinet"
282 #:goes-by '("curio cabinet" "cabinet" "bricabrac cabinet")
284 (format #f " The curio cabinet is full of all sorts of oddities!
285 Something catches your eye!
286 Ooh, ~a!" (random-choice random-bricabrac))))
287 ('thing:lobby:sign-in-form
288 <sign-in-form> 'room:lobby
289 #:name "sign-in form"
290 #:goes-by '("sign-in form" "form" "signin form")
291 #:desc "It looks like you could sign this form and set your name.")
294 ;; - Object: sign in form
295 ;; - Object: pamphlet
296 ;; Object: <invisible bell>: reprimands that you want to ring the
306 (define grand-hallway
310 #:name "Grand Hallway"
311 #:desc " A majestic red carpet runs down the center of the room.
312 Busts of serious looking people line the walls, but there's no
313 clear indication that they have any logical relation to this place.
314 In the center is a large statue of a bearded man. You wonder what
316 To the south is the lobby. A door to the east is labeled \"smoking
317 room\", while a door to the west is labeled \"playroom\"."
327 #:to 'room:smoking-parlor)))
328 ('thing:ignucius-statue
329 <gameobj> 'room:grand-hallway
331 #:desc " The statue is of a serious-looking bearded man with long, flowing hair.
332 The inscription says \"St. Ignucius\".
333 It has a large physical halo. Removing it is tempting, but it looks pretty
335 #:goes-by '("statue" "st ignucius" "st. ignucius"))))
345 #:name "The Playroom"
346 #:desc " There are toys scattered everywhere here. It's really unclear
347 if this room is intended for children or child-like adults."
351 #:to 'room:grand-hallway)))
352 ('thing:playroom:cubey
353 <thing> 'room:playroom
356 #:desc " It's a little foam cube with googly eyes on it. So cute!")
357 ('thing:cuddles-plushie
358 <thing> 'room:playroom
359 #:name "a cuddles plushie"
360 #:goes-by '("plushie" "cuddles plushie" "cuddles")
362 #:desc " A warm and fuzzy cuddles plushie! It's a cuddlefish!")))
373 ;; ... full of NURPH weapons?
379 (define-class <furniture> (<gameobj>)
380 (sit-phrase #:init-keyword #:sit-phrase)
381 (sit-phrase-third-person #:init-keyword #:sit-phrase-third-person)
382 (sit-name #:init-keyword #:sit-name)
387 (direct-command "sit" 'cmd-sit-furniture)))
388 (actions #:allocation #:each-subclass
389 #:init-value (build-actions
390 (cmd-sit-furniture furniture-cmd-sit))))
392 (define* (furniture-cmd-sit actor message #:key direct-obj)
394 (mbody-val (<-wait (message-from message) 'get-name)))
395 (<- (message-from message) 'tell
396 #:text (format #f "You ~a ~a.\n"
397 (slot-ref actor 'sit-phrase)
398 (slot-ref actor 'sit-name)))
399 (<- (slot-ref actor 'loc) 'tell-room
400 #:text (format #f "~a ~a on ~a.\n"
402 (slot-ref actor 'sit-phrase-third-person)
403 (slot-ref actor 'sit-name))
404 #:exclude (message-from message)))
407 (define smoking-parlor
409 ('room:smoking-parlor
411 #:name "Smoking Parlor"
413 '((p "This room looks quite posh. There are huge comfy seats you can sit in
414 if you like. Strangely, you see a large sign saying \"No Smoking\". The owners must
415 have installed this place and then changed their mind later.")
416 (p "There's a door to the west leading back to the grand hallway, and
417 a nondescript steel door to the south, leading apparently outside."))
421 #:to 'room:grand-hallway)
424 #:to 'room:break-room)))
425 ('thing:smoking-parlor:chair
426 <furniture> 'room:smoking-parlor
427 #:name "a comfy leather chair"
428 #:desc " That leather chair looks really comfy!"
429 #:goes-by '("leather chair" "comfy leather chair" "chair")
430 #:sit-phrase "sink into"
431 #:sit-phrase-third-person "sinks into"
432 #:sit-name "the comfy leather chair")
433 ('thing:smoking-parlor:sofa
434 <furniture> 'room:smoking-parlor
435 #:name "a plush leather sofa"
436 #:desc " That leather chair looks really comfy!"
437 #:goes-by '("leather sofa" "plush leather sofa" "sofa"
438 "leather couch" "plush leather couch" "couch")
439 #:sit-phrase "sprawl out on"
440 #:sit-phrase-third-person "sprawls out on into"
441 #:sit-name "the plush leather couch")
442 ('thing:smoking-parlor:bar-stool
443 <furniture> 'room:smoking-parlor
445 #:desc " Conveniently located near the bar! Not the most comfortable
446 seat in the room, though."
447 #:goes-by '("stool" "bar stool" "seat")
448 #:sit-phrase "hop on"
449 #:sit-phrase-third-person "hops onto"
450 #:sit-name "the bar stool")
452 <chatty-npc> 'room:smoking-parlor
453 #:name "Ford Prefect"
454 #:desc "Just some guy, you know?"
455 #:goes-by '("Ford Prefect" "ford prefect"
456 "frood" "prefect" "ford")
457 #:catchphrases prefect-quotes)
459 ('thing:smoking-parlor:no-smoking-sign
460 <thing> 'room:smoking-parlor
461 #:generally-visible #f
462 #:name "No Smoking Sign"
463 #:desc "This sign says \"No Smoking\" in big, red letters.
464 It has some bits of bubble gum stuck to it... yuck."
465 #:goes-by '("no smoking sign" "sign"))
467 ;; TODO: Cigar dispenser
475 (define clerk-commands
477 (direct-command "talk" 'cmd-chat)
478 (direct-command "chat" 'cmd-chat)
479 (direct-command "ask" 'cmd-ask-incomplete)
480 (prep-direct-command "ask" 'cmd-ask-about)
481 (direct-command "dismiss" 'cmd-dismiss)))
482 (define clerk-commands*
483 (append clerk-commands thing-commands*))
485 (define-class <desk-clerk> (<thing>)
486 ;; The desk clerk has three states:
487 ;; - on-duty: Arrived, and waiting for instructions (and losing patience
489 ;; - slacking: In the break room, probably smoking a cigarette
490 ;; or checking text messages
491 (state #:init-value 'slacking)
492 (commands #:init-value clerk-commands*)
493 (patience #:init-value 0)
494 (actions #:allocation #:each-subclass
495 #:init-value (build-actions
496 (init clerk-act-init)
497 (cmd-chat clerk-cmd-chat)
498 (cmd-ask-incomplete clerk-cmd-ask-incomplete)
499 (cmd-ask-about clerk-cmd-ask)
500 (cmd-dismiss clerk-cmd-dismiss)
501 (update-loop clerk-act-update-loop)
502 (be-summoned clerk-act-be-summoned))))
504 (define (clerk-act-init clerk message)
505 ;; call the gameobj main init method
506 (gameobj-act-init clerk message)
507 ;; start our main loop
508 (<- (actor-id clerk) 'update-loop))
510 (define clerk-help-topics
512 "Changing your name is easy! We have a clipboard here at the desk
513 where you can make yourself known to other participants in the hotel
514 if you sign it. Try 'sign form as <your-name>', replacing
515 <your-name>, obviously!")
517 "Here are some useful commands you might like to try: chat,
518 go, take, drop, say...")
520 "We hope you enjoy your stay at Hotel Bricabrac. As you may see,
521 our hotel emphasizes interesting experiences over rest and lodging.
522 The origins of the hotel are... unclear... and it has recently come
523 under new... 'management'. But at Hotel Bricabrac we believe these
524 aspects make the hotel into a fun and unique experience! Please,
525 feel free to walk around and explore.")))
528 (define clerk-knows-about
529 "'ask clerk about changing name', 'ask clerk about common commands', and 'ask clerk about the hotel'")
531 (define clerk-general-helpful-line
533 "The clerk says, \"If you need help with anything, feel free to ask me about it.
534 For example, 'ask clerk about changing name'. You can ask me about the following:
535 " clerk-knows-about ".\"\n"))
537 (define clerk-slacking-complaints
538 '("The pay here is absolutely lousy."
539 "The owner here has no idea what they're doing."
540 "Some times you just gotta step away, you know?"
541 "You as exhausted as I am?"
542 "Yeah well, this is just temporary. I'm studying to be a high
543 energy particle physicist. But ya gotta pay the bills, especially
544 with tuition at where it is..."))
546 (define* (clerk-cmd-chat clerk message #:key direct-obj)
547 (match (slot-ref clerk 'state)
549 (<- (message-from message) 'tell
550 #:text clerk-general-helpful-line))
552 (<- (message-from message) 'tell
556 (random-choice clerk-slacking-complaints)
559 (define (clerk-cmd-ask-incomplete clerk message . _)
560 (<- (message-from message) 'tell
561 #:text "The clerk says, \"Ask about what?\"\n"))
563 (define clerk-doesnt-know-text
564 "The clerk apologizes and says she doesn't know about that topic.\n")
566 (define* (clerk-cmd-ask clerk message #:key indir-obj
568 (match (slot-ref clerk 'state)
570 (match (assoc (pk 'indir indir-obj) clerk-help-topics)
572 (<- (message-from message) 'tell
574 (string-append "The clerk clears her throat and says:\n \""
578 (<- (message-from message) 'tell
579 #:text clerk-doesnt-know-text))))
581 (<- (message-from message) 'tell
582 #:text "The clerk says, \"Sorry, I'm on my break.\"\n"))))
584 (define* (clerk-act-be-summoned clerk message #:key who-summoned)
585 (match (slot-ref clerk 'state)
587 (<- who-summoned 'tell
589 "The clerk tells you as politely as she can that she's already here,
590 so there's no need to ring the bell.\n"))
592 (<- (gameobj-loc clerk) 'tell-room
594 "The clerk's ears perk up, she stamps out a cigarette, and she
595 runs out of the room!\n")
596 (gameobj-set-loc! clerk (dyn-ref clerk 'room:lobby))
597 (slot-set! clerk 'patience 8)
598 (slot-set! clerk 'state 'on-duty)
599 (<- (gameobj-loc clerk) 'tell-room
602 " Suddenly, a uniformed woman rushes into the room! She's wearing a
603 badge that says \"Desk Clerk\".
604 \"Hello, yes,\" she says between breaths, \"welcome to Hotel Bricabrac!
605 We look forward to your stay. If you'd like help getting acclimated,
606 feel free to ask me. For example, 'ask clerk about changing name'.
607 You can ask me about the following:
608 " clerk-knows-about ".\"\n")))))
610 (define* (clerk-cmd-dismiss clerk message . _)
612 (mbody-val (<-wait (message-from message) 'get-name)))
613 (match (slot-ref clerk 'state)
615 (<- (gameobj-loc clerk) 'tell-room
617 (format #f "\"Thanks ~a!\" says the clerk. \"I have somewhere I need to be.\"
618 The clerk leaves the room in a hurry.\n"
620 #:exclude (actor-id clerk))
621 (gameobj-set-loc! clerk (dyn-ref clerk 'room:break-room))
622 (slot-set! clerk 'state 'slacking)
623 (<- (gameobj-loc clerk) 'tell-room
624 #:text clerk-return-to-slacking-text
625 #:exclude (actor-id clerk)))
627 (<- (message-from message) 'tell
628 #:text "The clerk sternly asks you to not be so dismissive.\n"))))
630 (define clerk-slacking-texts
631 '("The clerk takes a long drag on her cigarette.\n"
632 "The clerk scrolls through text messages on her phone.\n"
633 "The clerk coughs a few times.\n"
634 "The clerk checks her watch and justifies a few more minutes outside.\n"
635 "The clerk fumbles around for a lighter.\n"
636 "The clerk sighs deeply and exhaustedly.\n"
637 "The clerk fumbles around for a cigarette.\n"))
639 (define clerk-working-impatience-texts
640 '("The clerk struggles to retain an interested and polite smile.\n"
641 "The clerk checks the time on her phone.\n"
642 "The clerk taps her foot.\n"
643 "The clerk takes a deep breath.\n"
645 "The clerk drums her nails on the counter.\n"
646 "The clerk clicks around on the desk computer.\n"
647 "The clerk thumbs through a printout of some physics paper.\n"
648 "The clerk mutters that her dissertation isn't going to write itself.\n"))
650 (define clerk-slack-excuse-text
651 "The desk clerk excuses herself, claiming she has important things to
654 (define clerk-return-to-slacking-text
655 "The desk clerk enters and slams the door behind her.\n")
658 (define (clerk-act-update-loop clerk message)
659 (define (tell-room text)
660 (<- (gameobj-loc clerk) 'tell-room
662 #:exclude (actor-id clerk)))
663 (define (loop-if-not-destructed)
664 (if (not (slot-ref clerk 'destructed))
665 ;; This iterates by "recursing" on itself by calling itself
666 ;; (as the message handler) again. It used to be that we had to do
667 ;; this, because there was a bug where a loop which yielded like this
668 ;; would keep growing the stack due to some parameter goofiness.
669 ;; That's no longer true, but there's an added advantage to this
670 ;; route: it's much more live hackable. If we change the definition
671 ;; of this method, the character will act differently on the next
672 ;; "tick" of the loop.
673 (<- (actor-id clerk) 'update-loop)))
674 (match (slot-ref clerk 'state)
676 (tell-room (random-choice clerk-slacking-texts))
677 (8sleep (+ (random 10) 10))
678 (loop-if-not-destructed))
680 (if (> (slot-ref clerk 'patience) 0)
681 ;; Keep working but lose patience gradually
683 (tell-room (random-choice clerk-working-impatience-texts))
684 (slot-set! clerk 'patience (- (slot-ref clerk 'patience)
686 (8sleep (+ (random 25) 20))
687 (loop-if-not-destructed))
690 (tell-room clerk-slack-excuse-text)
691 ;; back bto the break room
692 (gameobj-set-loc! clerk (pk 'break-room (dyn-ref clerk 'room:break-room)))
693 (tell-room clerk-return-to-slacking-text)
694 ;; annnnnd back to slacking
695 (slot-set! clerk 'state 'slacking)
696 (8sleep (+ (random 30) 15))
697 (loop-if-not-destructed))))))
704 #:name "Employee Break Room"
705 #:desc " This is less a room and more of an outdoor wire cage. You get
706 a bit of a view of the brick exterior of the building, and a crisp wind blows,
707 whistling, through the openings of the fenced area. Partly smoked cigarettes
708 and various other debris cover the floor.
709 Through the wires you can see... well... hm. It looks oddly like
710 the scenery tapers off nothingness. But that can't be right, can it?"
714 #:to 'room:smoking-parlor))
716 ('npc:break-room:desk-clerk
717 <desk-clerk> 'room:break-room
718 #:name "the hotel desk clerk"
719 #:desc " The hotel clerk is wearing a neatly pressed uniform bearing the
720 hotel insignia. She looks like she'd much rather be somewhere else."
721 #:goes-by '("hotel desk clerk" "clerk" "desk clerk"))))
725 ;;; Ennpie's Sea Lounge
726 ;;; -------------------
737 (append lobby grand-hallway smoking-parlor
738 playroom break-room))
740 ;; TODO: Provide command line args
741 (define (run-game . args)
742 (run-demo (game-spec) 'room:lobby #:repl-server #t))