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 " 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 for service\". Terrible music plays from a speaker
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 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"
241 #:desc " Whoever this is, they looks totally exhausted. They're
242 collapsed into the only comfortable looking chair in the room and you
243 don't get the sense that they're likely to move any time soon.
244 You notice they're wearing a sticker badly adhesed to their clothing
245 which says \"Hotel Proprietor\", but they look so disorganized that you
246 think that can't possibly be true... can it?
247 Despite their exhaustion, you sense they'd be happy to chat with you,
248 though the conversation may be a bit one sided."
249 #:goes-by '("frumpy fellow" "fellow"
250 "Chris Webber" ; heh, did you rtfc? or was it so obvious?
251 "hotel proprietor" "proprietor")
252 #:catchphrases hotel-owner-grumps)
255 <readable> 'room:lobby
256 #:name "the Hotel Bricabrac sign"
257 #:desc " It strikes you that there's something funny going on with this sign.
258 Sure enough, if you look at it hard enough, you can tell that someone
259 hastily painted over an existing sign and changed the \"M\" to an \"H\".
261 #:read-text " All it says is \"Hotel Bricabrac\" in smudged, hasty text."
265 "hotel bricabrac sign"
269 <summoning-bell> 'room:lobby
270 #:name "a shiny brass bell"
271 #:goes-by '("shiny brass bell" "shiny bell" "brass bell" "bell")
272 #:desc " A shiny brass bell. Inscribed on its wooden base is the text
273 \"ring me for service\". You probably could \"ring the bell\" if you
275 #:summons 'npc:break-room:desk-clerk)
277 ;; Object: curio cabinets
278 ('thing:lobby:cabinet
279 <gameobj> 'room:lobby
280 #:name "a curio cabinet"
281 #:goes-by '("curio cabinet" "cabinet" "bricabrac cabinet")
283 (format #f " The curio cabinet is full of all sorts of oddities!
284 Something catches your eye!
285 Ooh, ~a!" (random-choice random-bricabrac))))
286 ('thing:lobby:sign-in-form
287 <sign-in-form> 'room:lobby
288 #:name "sign-in form"
289 #:goes-by '("sign-in form" "form" "signin form")
290 #:desc "It looks like you could sign this form and set your name.")
293 ;; - Object: sign in form
294 ;; - Object: pamphlet
295 ;; Object: <invisible bell>: reprimands that you want to ring the
305 (define grand-hallway
309 #:name "Grand Hallway"
310 #:desc " A majestic red carpet runs down the center of the room.
311 Busts of serious looking people line the walls, but there's no
312 clear indication that they have any logical relation to this place.
313 In the center is a large statue of a bearded man. You wonder what
315 To the south is the lobby. A door to the east is labeled \"smoking
316 room\", while a door to the west is labeled \"playroom\"."
326 #:to 'room:smoking-parlor)))
327 ('thing:ignucius-statue
328 <gameobj> 'room:grand-hallway
330 #:desc " The statue is of a serious-looking bearded man with long, flowing hair.
331 The inscription says \"St. Ignucius\".
332 It has a large physical halo. Removing it is tempting, but it looks pretty
334 #:goes-by '("statue" "st ignucius" "st. ignucius"))))
344 #:name "The Playroom"
345 #:desc " There are toys scattered everywhere here. It's really unclear
346 if this room is intended for children or child-like adults."
350 #:to 'room:grand-hallway)))
351 ('thing:playroom:cubey
352 <thing> 'room:playroom
355 #:desc " It's a little foam cube with googly eyes on it. So cute!")
356 ('thing:cuddles-plushie
357 <thing> 'room:playroom
358 #:name "a cuddles plushie"
359 #:goes-by '("plushie" "cuddles plushie" "cuddles")
361 #:desc " A warm and fuzzy cuddles plushie! It's a cuddlefish!")))
372 ;; ... full of NURPH weapons?
378 (define-class <furniture> (<gameobj>)
379 (sit-phrase #:init-keyword #:sit-phrase)
380 (sit-phrase-third-person #:init-keyword #:sit-phrase-third-person)
381 (sit-name #:init-keyword #:sit-name)
386 (direct-command "sit" 'cmd-sit-furniture)))
387 (actions #:allocation #:each-subclass
388 #:init-value (build-actions
389 (cmd-sit-furniture furniture-cmd-sit))))
391 (define* (furniture-cmd-sit actor message #:key direct-obj)
393 (mbody-val (<-wait (message-from message) 'get-name)))
394 (<- (message-from message) 'tell
395 #:text (format #f "You ~a ~a.\n"
396 (slot-ref actor 'sit-phrase)
397 (slot-ref actor 'sit-name)))
398 (<- (slot-ref actor 'loc) 'tell-room
399 #:text (format #f "~a ~a on ~a.\n"
401 (slot-ref actor 'sit-phrase-third-person)
402 (slot-ref actor 'sit-name))
403 #:exclude (message-from message)))
406 (define smoking-parlor
408 ('room:smoking-parlor
410 #:name "Smoking Parlor"
411 #:desc " This room looks quite posh. There are huge comfy seats you can sit in
413 Strangely, you see a large sign saying \"No Smoking\". The owners must
414 have installed this place and then changed their mind later.
415 There's a door to the west leading back to the grand hallway, and
416 a nondescript steel door to the south, leading apparently outside."
420 #:to 'room:grand-hallway)
423 #:to 'room:break-room)))
424 ('thing:smoking-room:chair
425 <furniture> 'room:smoking-parlor
426 #:name "a comfy leather chair"
427 #:desc " That leather chair looks really comfy!"
428 #:goes-by '("leather chair" "comfy leather chair" "chair")
429 #:sit-phrase "sink into"
430 #:sit-phrase-third-person "sinks into"
431 #:sit-name "the comfy leather chair")
432 ('thing:smoking-room:sofa
433 <furniture> 'room:smoking-parlor
434 #:name "a plush leather sofa"
435 #:desc " That leather chair looks really comfy!"
436 #:goes-by '("leather sofa" "plush leather sofa" "sofa"
437 "leather couch" "plush leather couch" "couch")
438 #:sit-phrase "sprawl out on"
439 #:sit-phrase-third-person "sprawls out on into"
440 #:sit-name "the plush leather couch")
441 ('thing:smoking-room:bar-stool
442 <furniture> 'room:smoking-parlor
444 #:desc " Conveniently located near the bar! Not the most comfortable
445 seat in the room, though."
446 #:goes-by '("stool" "bar stool" "seat")
447 #:sit-phrase "hop on"
448 #:sit-phrase-third-person "hops onto"
449 #:sit-name "the bar stool")
451 <chatty-npc> 'room:smoking-parlor
452 #:name "Ford Prefect"
453 #:desc "Just some guy, you know?"
454 #:goes-by '("Ford Prefect" "ford prefect"
455 "frood" "prefect" "ford")
456 #:catchphrases prefect-quotes)
458 ;; TODO: Cigar dispenser
467 (define clerk-commands
469 (direct-command "talk" 'cmd-chat)
470 (direct-command "chat" 'cmd-chat)
471 (direct-command "ask" 'cmd-ask-incomplete)
472 (prep-direct-command "ask" 'cmd-ask-about)
473 (direct-command "dismiss" 'cmd-dismiss)))
474 (define clerk-commands*
475 (append clerk-commands thing-commands*))
477 (define-class <desk-clerk> (<thing>)
478 ;; The desk clerk has three states:
479 ;; - on-duty: Arrived, and waiting for instructions (and losing patience
481 ;; - slacking: In the break room, probably smoking a cigarette
482 ;; or checking text messages
483 (state #:init-value 'slacking)
484 (commands #:init-value clerk-commands*)
485 (patience #:init-value 0)
486 (actions #:allocation #:each-subclass
487 #:init-value (build-actions
488 (init clerk-act-init)
489 (cmd-chat clerk-cmd-chat)
490 (cmd-ask-incomplete clerk-cmd-ask-incomplete)
491 (cmd-ask-about clerk-cmd-ask)
492 (cmd-dismiss clerk-cmd-dismiss)
493 (update-loop clerk-act-update-loop)
494 (be-summoned clerk-act-be-summoned))))
496 (define (clerk-act-init clerk message)
497 ;; call the gameobj main init method
498 (gameobj-act-init clerk message)
499 ;; start our main loop
500 (<- (actor-id clerk) 'update-loop))
502 (define clerk-help-topics
504 "Changing your name is easy! We have a clipboard here at the desk
505 where you can make yourself known to other participants in the hotel
506 if you sign it. Try 'sign form as <your-name>', replacing
507 <your-name>, obviously!")
509 "Here are some useful commands you might like to try: chat,
510 go, take, drop, say...")
512 "We hope you enjoy your stay at Hotel Bricabrac. As you may see,
513 our hotel emphasizes interesting experiences over rest and lodging.
514 The origins of the hotel are... unclear... and it has recently come
515 under new... 'management'. But at Hotel Bricabrac we believe these
516 aspects make the hotel into a fun and unique experience! Please,
517 feel free to walk around and explore.")))
520 (define clerk-knows-about
521 "'changing name', 'common commands', and 'about the hotel'")
523 (define clerk-general-helpful-line
525 "The clerk says, \"If you need help with anything, feel free to ask me about it.
526 For example, 'ask clerk about changing name'. You can ask me about the following:
527 " clerk-knows-about ".\"\n"))
529 (define clerk-slacking-complaints
530 '("The pay here is absolutely lousy."
531 "The owner here has no idea what they're doing."
532 "Some times you just gotta step away, you know?"
533 "You as exhausted as I am?"
534 "Yeah well, this is just temporary. I'm studying to be a high
535 energy particle physicist. But ya gotta pay the bills, especially
536 with tuition at where it is..."))
538 (define* (clerk-cmd-chat clerk message #:key direct-obj)
539 (match (slot-ref clerk 'state)
541 (<- (message-from message) 'tell
542 #:text clerk-general-helpful-line))
544 (<- (message-from message) 'tell
548 (random-choice clerk-slacking-complaints)
551 (define (clerk-cmd-ask-incomplete clerk message)
552 (<- (message-from message) 'tell
553 #:text "The clerk says, \"Ask about what?\"\n"))
555 (define clerk-doesnt-know-text
556 "The clerk apologizes and says she doesn't know about that topic.\n")
558 (define* (clerk-cmd-ask clerk message #:key indir-obj
560 (match (slot-ref clerk 'state)
562 (match (assoc (pk 'indir indir-obj) clerk-help-topics)
564 (<- (message-from message) 'tell
566 (string-append "The clerk clears her throat and says:\n \""
570 (<- (message-from message) 'tell
571 #:text clerk-doesnt-know-text))))
573 (<- (message-from message) 'tell
574 #:text "The clerk says, \"Sorry, I'm on my break.\"\n"))))
576 (define* (clerk-act-be-summoned clerk message #:key who-summoned)
577 (match (slot-ref clerk 'state)
579 (<- who-summoned 'tell
581 "The clerk tells you as politely as she can that she's already here,
582 so there's no need to ring the bell.\n"))
584 (<- (gameobj-loc clerk) 'tell-room
586 "The clerk's ears perk up, she stamps out a cigarette, and she
587 runs out of the room!\n")
588 (gameobj-set-loc! clerk (dyn-ref clerk 'room:lobby))
589 (slot-set! clerk 'patience 8)
590 (slot-set! clerk 'state 'on-duty)
591 (<- (gameobj-loc clerk) 'tell-room
594 " Suddenly, a uniformed woman rushes into the room! She's wearing a
595 badge that says \"Desk Clerk\".
596 \"Hello, yes,\" she says between breaths, \"welcome to Hotel Bricabrac!
597 We look forward to your stay. If you'd like help getting acclimated,
598 feel free to ask me. For example, 'ask clerk about changing name'.
599 You can ask me about the following:
600 " clerk-knows-about ".\"\n")))))
602 (define* (clerk-cmd-dismiss clerk message . _)
604 (mbody-val (<-wait (message-from message) 'get-name)))
605 (match (slot-ref clerk 'state)
607 (<- (gameobj-loc clerk) 'tell-room
609 (format #f "\"Thanks ~a!\" says the clerk. \"I have somewhere I need to be.\"
610 The clerk leaves the room in a hurry.\n"
612 #:exclude (actor-id clerk))
613 (gameobj-set-loc! clerk (dyn-ref clerk 'room:break-room))
614 (slot-set! clerk 'state 'slacking)
615 (<- (gameobj-loc clerk) 'tell-room
616 #:text clerk-return-to-slacking-text
617 #:exclude (actor-id clerk)))
619 (<- (message-from message) 'tell
620 #:text "The clerk sternly asks you to not be so dismissive.\n"))))
622 (define clerk-slacking-texts
623 '("The clerk takes a long drag on her cigarette.\n"
624 "The clerk scrolls through text messages on her phone.\n"
625 "The clerk coughs a few times.\n"
626 "The clerk checks her watch and justifies a few more minutes outside.\n"
627 "The clerk fumbles around for a lighter.\n"
628 "The clerk sighs deeply and exhaustedly.\n"
629 "The clerk fumbles around for a cigarette.\n"))
631 (define clerk-working-impatience-texts
632 '("The clerk struggles to retain an interested and polite smile.\n"
633 "The clerk checks the time on her phone.\n"
634 "The clerk taps her foot.\n"
635 "The clerk takes a deep breath.\n"
637 "The clerk drums her nails on the counter.\n"
638 "The clerk clicks around on the desk computer.\n"))
640 (define clerk-slack-excuse-text
641 "The desk clerk excuses herself, claiming she has important things to
644 (define clerk-return-to-slacking-text
645 "The desk clerk enters and slams the door behind her.\n")
648 (define (clerk-act-update-loop clerk message)
649 (define (tell-room text)
650 (<- (gameobj-loc clerk) 'tell-room
652 #:exclude (actor-id clerk)))
653 (define (loop-if-not-destructed)
654 (if (not (slot-ref clerk 'destructed))
655 ;; This iterates by "recursing" on itself by calling itself
656 ;; (as the message handler) again. It used to be that we had to do
657 ;; this, because there was a bug where a loop which yielded like this
658 ;; would keep growing the stack due to some parameter goofiness.
659 ;; That's no longer true, but there's an added advantage to this
660 ;; route: it's much more live hackable. If we change the definition
661 ;; of this method, the character will act differently on the next
662 ;; "tick" of the loop.
663 (<- (actor-id clerk) 'update-loop)))
664 (match (slot-ref clerk 'state)
666 (tell-room (random-choice clerk-slacking-texts))
667 (8sleep (+ (random 10) 10))
668 (loop-if-not-destructed))
670 (if (> (slot-ref clerk 'patience) 0)
671 ;; Keep working but lose patience gradually
673 (tell-room (random-choice clerk-working-impatience-texts))
674 (slot-set! clerk 'patience (- (slot-ref clerk 'patience)
676 (8sleep (+ (random 25) 20))
677 (loop-if-not-destructed))
680 (tell-room clerk-slack-excuse-text)
681 ;; back bto the break room
682 (gameobj-set-loc! clerk (pk 'break-room (dyn-ref clerk 'room:break-room)))
683 (tell-room clerk-return-to-slacking-text)
684 ;; annnnnd back to slacking
685 (slot-set! clerk 'state 'slacking)
686 (8sleep (+ (random 30) 15))
687 (loop-if-not-destructed))))))
694 #:name "Employee Break Room"
695 #:desc " This is less a room and more of an outdoor wire cage. You get
696 a bit of a view of the brick exterior of the building, and a crisp wind blows,
697 whistling, through the openings of the fenced area. Partly smoked cigarettes
698 and various other debris cover the floor.
699 Through the wires you can see... well... hm. It looks oddly like
700 the scenery tapers off nothingness. But that can't be right, can it?"
704 #:to 'room:smoking-parlor))
706 ('npc:break-room:desk-clerk
707 <desk-clerk> 'room:break-room
708 #:name "the hotel desk clerk"
709 #:desc " The hotel clerk is wearing a neatly pressed uniform bearing the
710 hotel insignia. She looks like she'd much rather be somewhere else."
711 #:goes-by '("hotel desk clerk" "clerk" "desk clerk"))))
715 ;;; Ennpie's Sea Lounge
716 ;;; -------------------
727 (append lobby grand-hallway smoking-parlor
728 playroom break-room))
730 ;; TODO: Provide command line args
731 (define (run-game . args)
732 (run-demo game-spec 'room:lobby #:repl-server #t))