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)
23 (8sync systems actors)
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 readable-actions
59 (cmd-read (wrap-apply readable-cmd-read))))
61 (define readable-actions*
62 (append readable-actions
65 (define-class <readable> (<thing>)
66 (read-text #:init-value "All it says is: \"Blah blah blah.\""
67 #:init-keyword #:read-text)
69 #:init-value readable-commands*)
72 (simple-dispatcher readable-actions*)))
74 (define (readable-cmd-read actor message)
75 (<- actor (message-from message) 'tell
76 #:text (string-append (slot-ref actor 'read-text) "\n")))
83 (define-mhandler (npc-chat-randomly actor message)
85 (format #f "~a says: \"~a\"\n"
86 (slot-ref actor 'name)
87 (random-choice (slot-ref actor 'catchphrases))))
88 (<- actor (message-from message) 'tell
93 (direct-command "chat" 'cmd-chat)
94 (direct-command "talk" 'cmd-chat)))
97 (cmd-chat (wrap-apply npc-chat-randomly))))
99 (define hotel-owner-grumps
100 '("Eight sinks! Eight sinks! And I couldn't unwind them..."
101 "Don't mind the mess. I built this place on a dare, you
103 "(*tearfully*) Here, take this parenthesis. May it serve
105 "I gotta get back to the goblin farm soon..."
106 "Oh, but I was going to make a mansion... a great,
107 beautiful mansion! Full of ghosts! Now all I have is this cruddy
108 mo... hotel. Oh... If only I had more time!"
109 "I told them to paint more of the walls purple.
110 Why didn't they listen?"
111 "Listen to that overhead muzak. Whoever made that doesn't
112 know how to compose very well! Have you heard of the bands 'fmt'
113 or 'skribe'? Now *that's* composition!"))
115 (define-class <chatty-npc> (<gameobj>)
116 (catchphrases #:init-value '("Blarga blarga blarga!")
117 #:init-keyword #:catchphrases)
119 #:init-value chat-commands)
122 (simple-dispatcher (append gameobj-actions chat-actions))))
124 (define random-bricabrac
125 '("a creepy porcelain doll"
126 "assorted 1950s robots"
127 "an exquisite tea set"
128 "an antique mustard pot"
129 "the pickled head of Elvis"
130 "the pickled circuitboard of EVLIS"
131 "a scroll of teletype paper holding the software Four Freedoms"
132 "a telephone shaped like an orange cartoon cat"))
134 (define-class <sign-in-form> (<gameobj>)
138 (prep-direct-command "sign" 'cmd-sign-form
145 (cmd-sign-form (wrap-apply sign-cmd-sign-in)))
150 (sre->irregex '(: alpha (** 1 14 (or alphanum "-" "_")))))
152 (define forbidden-words
153 (append article preposition
154 '("and" "or" "but" "admin")))
156 (define (valid-name? name)
157 (and (irregex-match name-sre name)
158 (not (member name forbidden-words))))
160 (define-mhandler (sign-cmd-sign-in actor message direct-obj indir-obj)
163 (<-wait actor (message-from message) 'get-name)
165 (define name indir-obj)
166 (if (valid-name? indir-obj)
168 (<-wait actor (message-from message) 'set-name!
170 (<- actor (slot-ref actor 'loc) 'tell-room
171 #:text (format #f "~a signs the form!\n~a is now known as ~a\n"
172 old-name old-name name)))
173 (<- actor (message-from message) 'tell
174 #:text "Sorry, that's not a valid name.
175 Alphanumerics, _ and - only, 2-15 characters, starts with an alphabetic
179 (define summoning-bell-commands
181 (direct-command "ring" 'cmd-ring)))
182 (define summoning-bell-commands*
183 (append summoning-bell-commands
186 (define summoning-bell-actions
188 (cmd-ring (wrap-apply summoning-bell-cmd-ring))))
189 (define summoning-bell-actions*
190 (append summoning-bell-actions
193 (define-class <summoning-bell> (<thing>)
194 (summons #:init-keyword #:summons)
197 #:init-value summoning-bell-commands*)
200 (simple-dispatcher summoning-bell-actions*)))
202 (define-mhandler (summoning-bell-cmd-ring bell message)
205 (<-wait bell (message-from message) 'get-name)
207 (<- bell (message-from message) 'tell
208 #:text "*ring ring!* You ring the bell!\n")
209 (<- bell (gameobj-loc bell) 'tell-room
211 (format #f "*ring ring!* ~a rings the bell!\n"
213 #:exclude (message-from message))
215 (<- bell (dyn-ref bell (slot-ref bell 'summons)) 'be-summoned))
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)
253 ;; NPC: desk clerk (comes when you ring the s)
254 ;; impatient teenager, only stays around for a few minutes
255 ;; complaining, then leaves.
259 <readable> 'room:lobby
260 #:name "the Hotel Bricabrac sign"
261 #:desc " It strikes you that there's something funny going on with this sign.
262 Sure enough, if you look at it hard enough, you can tell that someone
263 hastily painted over an existing sign and changed the \"M\" to an \"H\".
265 #:read-text " All it says is \"Hotel Bricabrac\" in smudged, hasty text."
269 "hotel bricabrac sign"
273 <summoning-bell> 'room:lobby
274 #:name "a shiny brass bell"
275 #:goes-by '("shiny brass bell" "shiny bell" "brass bell" "bell")
276 #:desc " A shiny brass bell. Inscribed on its wooden base is the text
277 \"ring me for service\". You probably could \"ring the bell\" if you
279 #:summons 'npc:break-room:desk-clerk)
281 ;; Object: curio cabinets
282 ('thing:lobby:cabinet
283 <gameobj> 'room:lobby
284 #:name "a curio cabinet"
285 #:goes-by '("curio cabinet" "cabinet" "bricabrac cabinet")
287 (format #f " The curio cabinet is full of all sorts of oddities!
288 Something catches your eye!
289 Ooh, ~a!" (random-choice random-bricabrac))))
290 ('thing:lobby:sign-in-form
291 <sign-in-form> 'room:lobby
292 #:name "sign-in form"
293 #:goes-by '("sign-in form" "form" "signin form")
294 #:desc "It looks like you could sign this form and set your name.")
297 ;; - Object: sign in form
298 ;; - Object: pamphlet
299 ;; Object: <invisible bell>: reprimands that you want to ring the
309 (define grand-hallway
313 #:name "Grand Hallway"
314 #:desc " A majestic red carpet runs down the center of the room.
315 Busts of serious looking people line the walls, but there's no
316 clear indication that they have any logical relation to this place.
317 In the center is a large statue of a bearded man. You wonder what
319 To the south is the lobby. A door to the east is labeled \"smoking
320 room\", while a door to the west is labeled \"playroom\"."
330 #:to 'room:smoking-parlor)))
331 ('thing:ignucius-statue
332 <gameobj> 'room:grand-hallway
334 #:desc " The statue is of a serious-looking bearded man with long, flowing hair.
335 The inscription says \"St. Ignucius\".
336 It has a large physical halo. It doesn't look like it would be hard to remove."
337 #:goes-by '("statue" "st ignucius" "st. ignucius"))))
347 #:name "The Playroom"
348 #:desc " There are toys scattered everywhere here. It's really unclear
349 if this room is intended for children or child-like adults."
353 #:to 'room:grand-hallway)))
354 ('thing:playroom:cubey
355 <thing> 'room:playroom
358 #:desc " It's a little foam cube with googly eyes on it. So cute!")))
369 ;; ... full of NURPH weapons?
375 (define-class <furniture> (<gameobj>)
376 (sit-phrase #:init-keyword #:sit-phrase)
377 (sit-phrase-third-person #:init-keyword #:sit-phrase-third-person)
378 (sit-name #:init-keyword #:sit-name)
383 (direct-command "sit" 'cmd-sit-furniture)))
389 (cmd-sit-furniture (wrap-apply furniture-cmd-sit)))
392 (define-mhandler (furniture-cmd-sit actor message direct-obj)
395 (<-wait actor (message-from message) 'get-name)
397 (<- actor (message-from message) 'tell
398 #:text (format #f "You ~a ~a.\n"
399 (slot-ref actor 'sit-phrase)
400 (slot-ref actor 'sit-name)))
401 (<- actor (slot-ref actor 'loc) 'tell-room
402 #:text (format #f "~a ~a on ~a.\n"
404 (slot-ref actor 'sit-phrase-third-person)
405 (slot-ref actor 'sit-name))
406 #:exclude (message-from message)))
409 (define smoking-parlor
411 ('room:smoking-parlor
413 #:name "Smoking Parlor"
414 #:desc " This room looks quite posh. There are huge comfy seats you can sit in
416 Strangely, you see a large sign saying \"No Smoking\". The owners must
417 have installed this place and then changed their mind later.
418 There's a door to the west leading back to the grand hallway, and
419 a nondescript steel door to the south, leading apparently outside."
423 #:to 'room:grand-hallway)
426 #:to 'room:break-room)))
427 ('thing:smoking-room:chair
428 <furniture> 'room:smoking-parlor
429 #:name "a comfy leather chair"
430 #:desc " That leather chair looks really comfy!"
431 #:goes-by '("leather chair" "comfy leather chair" "chair")
432 #:sit-phrase "sink into"
433 #:sit-phrase-third-person "sinks into"
434 #:sit-name "the comfy leather chair")
435 ('thing:smoking-room:sofa
436 <furniture> 'room:smoking-parlor
437 #:name "a plush leather sofa"
438 #:desc " That leather chair looks really comfy!"
439 #:goes-by '("leather sofa" "plush leather sofa" "sofa"
440 "leather couch" "plush leather couch" "couch")
441 #:sit-phrase "sprawl out on"
442 #:sit-phrase-third-person "sprawls out on into"
443 #:sit-name "the plush leather couch")
444 ('thing:smoking-room:bar-stool
445 <furniture> 'room:smoking-parlor
447 #:desc " Conveniently located near the bar! Not the most comfortable
448 seat in the room, though."
449 #:goes-by '("stool" "bar stool" "seat")
450 #:sit-phrase "hop on"
451 #:sit-phrase-third-person "hops onto"
452 #:sit-name "the bar stool")
454 ;; TODO: Cigar dispenser
463 (define clerk-commands
465 (direct-command "talk" 'cmd-chat)
466 (direct-command "chat" 'cmd-chat)
467 (direct-command "ask" 'cmd-ask-incomplete)
468 (prep-direct-command "ask" 'cmd-ask-about)))
469 (define clerk-commands*
470 (append clerk-commands thing-commands*))
472 (define clerk-actions
474 (init (wrap-apply clerk-act-init))
475 (cmd-chat (wrap-apply clerk-cmd-chat))
476 (cmd-ask-incomplete (wrap-apply clerk-cmd-ask-incomplete))
477 (cmd-ask-about (wrap-apply clerk-cmd-ask))
478 (update-loop (wrap-apply clerk-act-update-loop))
479 (be-summoned (wrap-apply clerk-act-be-summoned))))
480 (define clerk-actions* (append clerk-actions
483 (define-class <desk-clerk> (<thing>)
484 ;; The desk clerk has three states:
485 ;; - on-duty: Arrived, and waiting for instructions (and losing patience
487 ;; - slacking: In the break room, probably smoking a cigarette
488 ;; or checking text messages
489 (state #:init-value 'slacking)
490 (commands #:init-value clerk-commands*)
491 (patience #:init-value 0)
494 (simple-dispatcher clerk-actions*)))
496 (define-mhandler (clerk-act-init clerk message)
497 ;; call the gameobj main init method
498 (gameobj-act-init clerk message)
499 ;; start our main loop
500 (<- clerk (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-mhandler (clerk-cmd-chat clerk message)
539 (match (slot-ref clerk 'state)
541 (<- clerk (message-from message) 'tell
542 #:text clerk-general-helpful-line))
544 (<- clerk (message-from message) 'tell
548 (random-choice clerk-slacking-complaints)
551 (define-mhandler (clerk-cmd-ask-incomplete clerk message)
552 (<- clerk (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-mhandler (clerk-cmd-ask clerk message indir-obj)
559 (match (slot-ref clerk 'state)
561 (match (assoc (pk 'indir indir-obj) clerk-help-topics)
563 (<- clerk (message-from message) 'tell
565 (string-append "The clerk clears her throat and says:\n \""
569 (<- clerk (message-from message) 'tell
570 #:text clerk-doesnt-know-text))))
572 (<- clerk (message-from message) 'tell
573 #:text "The clerk says, \"Sorry, I'm on my break.\"\n"))))
575 (define-mhandler (clerk-act-be-summoned clerk message)
576 (match (slot-ref clerk 'state)
578 (<- clerk (message-from message) 'tell
580 "The clerk tells you as politely as she can that she's already here,
581 so there's no need to ring the bell.\n"))
583 (<- clerk (gameobj-loc clerk) 'tell-room
585 "The clerk's ears perk up, she stamps out a cigarette, and she
586 runs out of the room!\n")
587 (gameobj-set-loc! clerk (dyn-ref clerk 'room:lobby))
588 (slot-set! clerk 'patience 8)
589 (slot-set! clerk 'state 'on-duty)
590 (<- clerk (gameobj-loc clerk) 'tell-room
593 " Suddenly, a uniformed woman rushes into the room! She's wearing a
594 badge that says \"Desk Clerk\".
595 \"Hello, yes,\" she says between breaths, \"welcome to Hotel Bricabrac!
596 We look forward to your stay. If you'd like help getting acclimated,
597 feel free to ask me. For example, 'ask clerk about changing name'.
598 You can ask me about the following:
599 " clerk-knows-about ".\"\n")))))
601 (define clerk-slacking-texts
602 '("The clerk takes a long drag on her cigarette.\n"
603 "The clerk scrolls through text messages on her phone.\n"
604 "The clerk coughs a few times.\n"
605 "The clerk checks her watch and justifies a few more minutes outside.\n"
606 "The clerk fumbles around for a lighter.\n"
607 "The clerk sighs deeply and exhaustedly.\n"
608 "The clerk fumbles around for a cigarette.\n"))
610 (define clerk-working-impatience-texts
611 '("The clerk struggles to retain an interested and polite smile.\n"
612 "The clerk checks the time on her phone.\n"
613 "The clerk taps her foot.\n"
614 "The clerk takes a deep breath.\n"
616 "The clerk drums her nails on the counter.\n"
617 "The clerk clicks around on the desk computer.\n"))
619 (define clerk-slack-excuse-text
620 "The desk clerk excuses herself, claiming she has important things to
623 (define clerk-return-to-slacking-text
624 "The desk clerk enters and slams the door behind her.\n")
626 (define-mhandler (clerk-act-update-loop clerk message)
627 (define (tell-room text)
628 (<- clerk (gameobj-loc clerk) 'tell-room
630 (define (loop return)
631 (define (stop-if-destructed)
632 (if (slot-ref clerk 'destructed)
634 (match (slot-ref clerk 'state)
636 (tell-room (random-choice clerk-slacking-texts))
637 (8sleep (+ (random 10) 10))
641 (if (> (slot-ref clerk 'patience) 0)
642 ;; Keep working but lose patience gradually
644 (tell-room (random-choice clerk-working-impatience-texts))
645 (slot-set! clerk 'patience (- (slot-ref clerk 'patience)
647 (8sleep (+ (random 25) 20))
652 (tell-room clerk-slack-excuse-text)
653 ;; back bto the break room
654 (gameobj-set-loc! clerk (pk 'break-room (dyn-ref clerk 'room:break-room)))
655 (tell-room clerk-return-to-slacking-text)
656 ;; annnnnd back to slacking
657 (slot-set! clerk 'state 'slacking)
658 (8sleep (+ (random 30) 15))
667 #:name "Employee Break Room"
668 #:desc " This is less a room and more of an outdoor wire cage. You get
669 a bit of a view of the brick exterior of the building, and a crisp wind blows,
670 whistling, through the openings of the fenced area. Partly smoked cigarettes
671 and various other debris cover the floor.
672 Through the wires you can see... well... hm. It looks oddly like
673 the scenery tapers off nothingness. But that can't be right, can it?"
677 #:to 'room:smoking-parlor))
679 ('npc:break-room:desk-clerk
680 <desk-clerk> 'room:break-room
681 #:name "the hotel desk clerk"
682 #:desc " The hotel clerk is wearing a neatly pressed uniform bearing the
683 hotel insignia. She looks like she'd much rather be somewhere else."
684 #:goes-by '("hotel desk clerk" "clerk" "desk clerk"))))
688 ;;; Ennpie's Sea Lounge
689 ;;; -------------------
700 (append lobby grand-hallway smoking-parlor
701 playroom break-room))
703 ;; TODO: Provide command line args
704 (define (run-game . args)
705 (run-demo game-spec 'room:lobby #:repl-server #t))