south "exit" from lab
[mudsync.git] / worlds / bricabrac.scm
1 ;;; Mudsync --- Live hackable MUD
2 ;;; Copyright © 2016, 2017 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 container)
23              (8sync)
24              (oop goops)
25              (ice-9 control)
26              (ice-9 format)
27              (ice-9 match)
28              (rx irregex))
29
30
31 \f
32 ;;; Utilities, useful or otherwise
33 ;;; ==============================
34
35 (set! *random-state* (random-state-from-platform))
36
37 (define (random-choice lst)
38   (list-ref lst (random (length lst))))
39
40 ;; list of lists, lol.
41 (define-syntax-rule (lol (list-contents ...) ...)
42   (list (list list-contents ...) ...))
43
44 \f
45 ;;; Some simple object types.
46 ;;; =========================
47
48 (define-class <readable> (<gameobj>)
49   (read-text #:init-value "All it says is: \"Blah blah blah.\""
50              #:init-keyword #:read-text)
51   (commands
52    #:allocation #:each-subclass
53    #:init-thunk (build-commands
54                  ("read" ((direct-command cmd-read)))))
55   (actions #:allocation #:each-subclass
56            #:init-thunk (build-actions
57                          (cmd-read readable-cmd-read))))
58
59 (define (readable-cmd-read actor message . _)
60   (<- (message-from message) 'tell
61       #:text (slot-ref actor 'read-text)))
62
63
64 ;; This one is just where reading is the same thing as looking
65 ;; at the description
66 (define-class <readable-desc> (<gameobj>)
67   (commands
68    #:allocation #:each-subclass
69    #:init-thunk (build-commands
70                  ("read" ((direct-command cmd-look-at))))))
71
72 ;; This one allows you to take from items that are proxied by it
73 (define-actor <proxy-items> (<gameobj>)
74   ((cmd-take-from take-from-proxy))
75   (proxy-items #:init-keyword #:proxy-items))
76
77 (define* (take-from-proxy gameobj message
78                           #:key direct-obj indir-obj preposition
79                           (player (message-from message)))
80   (call/ec
81    (lambda (escape)
82      (for-each
83       (lambda (obj-sym)
84         (define obj-id (dyn-ref gameobj obj-sym))
85         (define goes-by
86           (mbody-val (<-wait obj-id 'goes-by)))
87         (when (ci-member direct-obj goes-by)
88           (<- obj-id 'cmd-take #:direct-obj direct-obj #:player player)
89           (escape #f)))
90       (slot-ref gameobj 'proxy-items))
91
92      (<- player 'tell
93         #:text `("You don't see any such " ,direct-obj " to take "
94                  ,preposition " " ,(slot-ref gameobj 'name) ".")))))
95
96
97 \f
98 ;;; Lobby
99 ;;; -----
100
101 (define (npc-chat-randomly actor message . _)
102   (define catchphrase
103     (random-choice (slot-ref actor 'catchphrases)))
104   (define text-to-send
105     ((slot-ref actor 'chat-format) actor catchphrase))
106   (<- (message-from message) 'tell
107       #:text text-to-send))
108
109 (define hotel-owner-grumps
110   '("Eight sinks!  Eight sinks!  And I couldn't unwind them..."
111     "Don't mind the mess.  I built this place on a dare, you
112 know?"
113     "(*tearfully*) Here, take this parenthesis.  May it serve
114 you well."
115     "I gotta get back to the goblin farm soon..."
116     "Oh, but I was going to make a mansion... a great,
117 beautiful mansion!  Full of ghosts!  Now all I have is this cruddy
118 mo... hotel.  Oh... If only I had more time!"
119     "I told them to paint more of the walls purple.
120 Why didn't they listen?"
121     "Listen to that overhead muzak.  Whoever made that doesn't
122 know how to compose very well!  Have you heard of the bands 'fmt'
123 or 'skribe'?  Now *that's* composition!"))
124
125 (define-class <chatty-npc> (<gameobj>)
126   (catchphrases #:init-value '("Blarga blarga blarga!")
127                 #:init-keyword #:catchphrases)
128   (chat-format #:init-value (lambda (npc catchphrase)
129                               `(,(slot-ref npc 'name) " says: \""
130                                 ,catchphrase "\""))
131                #:init-keyword #:chat-format)
132   (commands
133    #:allocation #:each-subclass
134    #:init-thunk (build-commands
135                  (("chat" "talk") ((direct-command cmd-chat)))))
136   (actions #:allocation #:each-subclass
137            #:init-thunk
138            (build-actions
139             (cmd-chat npc-chat-randomly))))
140
141 (define-class <sign-in-form> (<gameobj>)
142   (commands
143    #:allocation #:each-subclass
144    #:init-thunk (build-commands
145                  ("sign" ((prep-direct-command cmd-sign-form '("as"))))))
146
147   (actions #:allocation #:each-subclass
148            #:init-thunk (build-actions
149                          (cmd-sign-form sign-cmd-sign-in))))
150
151
152 (define name-sre
153   (sre->irregex '(: alpha (** 1 14 (or alphanum "-" "_")))))
154
155 (define forbidden-words
156   (append article preposition
157           '("and" "or" "but" "admin")))
158
159 (define (valid-name? name)
160   (and (irregex-match name-sre name)
161        (not (member name forbidden-words))))
162
163 (define* (sign-cmd-sign-in actor message
164                            #:key direct-obj indir-obj preposition)
165   (define old-name
166     (mbody-val (<-wait (message-from message) 'get-name)))
167   (define name indir-obj)
168   (if (valid-name? indir-obj)
169       (begin
170         (<-wait (message-from message) 'set-name! name)
171         (<- (slot-ref actor 'loc) 'tell-room
172             #:text (format #f "~a signs the form!\n~a is now known as ~a\n"
173                            old-name old-name name)))
174       (<- (message-from message) 'tell
175           #:text "Sorry, that's not a valid name.
176 Alphanumerics, _ and - only, 2-15 characters, starts with an alphabetic
177 character.\n")))
178
179
180 (define-class <summoning-bell> (<gameobj>)
181   (summons #:init-keyword #:summons)
182
183   (commands
184    #:allocation #:each-subclass
185    #:init-thunk (build-commands
186                  ("ring" ((direct-command cmd-ring)))))
187   (actions #:allocation #:each-subclass
188            #:init-thunk (build-actions
189                          (cmd-ring summoning-bell-cmd-ring))))
190
191 (define* (summoning-bell-cmd-ring bell message . _)
192   ;; Call back to actor who invoked this message handler
193   ;; and find out their name.  We'll call *their* get-name message
194   ;; handler... meanwhile, this procedure suspends until we get
195   ;; their response.
196   (define who-rang
197     (mbody-val (<-wait (message-from message) 'get-name)))
198
199   ;; Now we'll invoke the "tell" message handler on the player
200   ;; who rang us, displaying this text on their screen.
201   ;; This one just uses <- instead of <-wait, since we don't
202   ;; care when it's delivered; we're not following up on it.
203   (<- (message-from message) 'tell
204       #:text "*ring ring!*  You ring the bell!\n")
205   ;; We also want everyone else in the room to "hear" the bell,
206   ;; but they get a different message since they aren't the ones
207   ;; ringing it.  Notice here's where we make use of the invoker's
208   ;; name as extracted and assigned to the who-rang variable.
209   ;; Notice how we send this message to our "location", which
210   ;; forwards it to the rest of the occupants in the room.
211   (<- (gameobj-loc bell) 'tell-room
212       #:text
213       (format #f "*ring ring!*  ~a rings the bell!\n"
214               who-rang)
215       #:exclude (message-from message))
216   ;; Now we perform the primary task of the bell, which is to summon
217   ;; the "clerk" character to the room.  (This is configurable,
218   ;; so we dynamically look up their address.)
219   (<- (dyn-ref bell (slot-ref bell 'summons)) 'be-summoned
220       #:who-summoned (message-from message)))
221
222
223 (define prefect-quotes
224   '("I'm a frood who really knows where my towel is!"
225     "On no account allow a Vogon to read poetry at you."
226     "Time is an illusion, lunchtime doubly so!"
227     "How can you have money if none of you produces anything?"
228     "On no account allow Arthur to request tea on this ship."))
229
230 (define-class <cabinet-item> (<gameobj>)
231   (take-me? #:init-value
232             (lambda _
233               (values #f #:why-not
234                       `("Hm, well... the cabinet is locked and the properitor "
235                         "is right over there.")))))
236
237 (define lobby
238   (lol
239    ('lobby
240     <room> #f
241     #:name "Hotel Lobby"
242     #:desc
243     '((p "You're in some sort of hotel lobby.  You see a large sign hanging "
244          "over the desk that says \"Hotel Bricabrac\".  On the desk is a bell "
245          "that says \"'ring bell' for service\".  Terrible music plays from a speaker "
246          "somewhere overhead.  "
247          "The room is lined with various curio cabinets, filled with all sorts "
248          "of kitschy junk.  It looks like whoever decorated this place had great "
249          "ambitions, but actually assembled it all in a hurry and used whatever "
250          "kind of objects they found lying around.")
251       (p "There's a door to the north leading to some kind of hallway."))
252     #:exits
253     (list (make <exit>
254             #:name "north"
255             #:to 'grand-hallway)))
256    ;; NPC: hotel owner
257    ('lobby:hotel-owner
258     <chatty-npc> 'lobby
259     #:name "a frumpy fellow"
260     #:desc
261     '((p "  Whoever this is, they looks totally exhausted.  They're
262 collapsed into the only comfortable looking chair in the room and you
263 don't get the sense that they're likely to move any time soon.
264   You notice they're wearing a sticker badly adhesed to their clothing
265 which says \"Hotel Proprietor\", but they look so disorganized that you
266 think that can't possibly be true... can it?
267   Despite their exhaustion, you sense they'd be happy to chat with you,
268 though the conversation may be a bit one sided."))
269     #:goes-by '("frumpy fellow" "fellow"
270                 "Chris Webber"  ; heh, did you rtfc?  or was it so obvious?
271                 "hotel proprietor" "proprietor")
272     #:catchphrases hotel-owner-grumps)
273    ;; Object: Sign
274    ('lobby:sign
275     <readable> 'lobby
276     #:name "the Hotel Bricabrac sign"
277     #:desc "  It strikes you that there's something funny going on with this sign.
278 Sure enough, if you look at it hard enough, you can tell that someone
279 hastily painted over an existing sign and changed the \"M\" to an \"H\".
280 Classy!"
281     #:read-text "  All it says is \"Hotel Bricabrac\" in smudged, hasty text."
282     #:goes-by '("sign"
283                 "bricabrac sign"
284                 "hotel sign"
285                 "hotel bricabrac sign"
286                 "lobby sign"))
287
288    ('lobby:bell
289     <summoning-bell> 'lobby
290     #:name "a shiny brass bell"
291     #:goes-by '("shiny brass bell" "shiny bell" "brass bell" "bell")
292     #:desc "  A shiny brass bell.  Inscribed on its wooden base is the text
293 \"ring me for service\".  You probably could \"ring the bell\" if you 
294 wanted to."
295     #:summons 'break-room:desk-clerk)
296
297    ('lobby:sign-in-form
298     <sign-in-form> 'lobby
299     #:name "sign-in form"
300     #:goes-by '("sign-in form" "form" "signin form")
301     #:desc '("It looks like you could sign this form and set your name like so: "
302              (i "sign form as <my-name-here>")))
303
304    ;; Object: curio cabinets
305    ;; TODO: respond to attempts to open the curio cabinet
306    ('lobby:cabinet
307     <proxy-items> 'lobby
308     #:proxy-items '(lobby:porcelain-doll
309                     lobby:1950s-robots
310                     lobby:tea-set lobby:mustard-pot
311                     lobby:head-of-elvis lobby:circuitboard-of-evlis
312                     lobby:teletype-scroll lobby:orange-cat-phone)
313     #:name "a curio cabinet"
314     #:goes-by '("curio cabinet" "cabinet" "bricabrac cabinet"
315                 "cabinet of curiosities")
316     #:desc (lambda _
317              (format #f "  The curio cabinet is full of all sorts of oddities!
318 Something catches your eye!
319 Ooh, ~a!" (random-choice
320            '("a creepy porcelain doll"
321              "assorted 1950s robots"
322              "an exquisite tea set"
323              "an antique mustard pot"
324              "the pickled head of Elvis"
325              "the pickled circuitboard of EVLIS"
326              "a scroll of teletype paper holding the software Four Freedoms"
327              "a telephone shaped like an orange cartoon cat")))))
328
329    ('lobby:porcelain-doll
330     <cabinet-item> 'lobby
331     #:invisible? #t
332     #:name "a creepy porcelain doll"
333     #:desc "It strikes you that while the doll is technically well crafted,
334 it's also the stuff of nightmares."
335     #:goes-by '("porcelain doll" "doll"))
336    ('lobby:1950s-robots
337     <cabinet-item> 'lobby
338     #:invisible? #t
339     #:name "a set of 1950s robots"
340     #:desc "There's a whole set of these 1950s style robots.
341 They seem to be stamped out of tin, and have various decorations of levers
342 and buttons and springs.  Some of them have wind-up knobs on them."
343     #:goes-by '("robot" "robots" "1950s robot" "1950s robots"))
344    ('lobby:tea-set
345     <cabinet-item> 'lobby
346     #:invisible? #t
347     #:name "a tea set"
348     #:desc "A complete tea set.  Some of the cups are chipped.
349 You can imagine yourself joining a tea party using this set, around a
350 nice table with some doilies, drinking some Earl Grey tea, hot.  Mmmm."
351     #:goes-by '("tea set" "tea"))
352    ('lobby:cups
353     <cabinet-item> 'lobby
354     #:invisible? #t
355     #:name "cups from the tea set"
356     #:desc "They're chipped."
357     #:goes-by '("cups"))
358    ('lobby:mustard-pot
359     <cabinet-item> 'lobby
360     #:invisible? #t
361     #:name "a mustard pot"
362     #:desc '((p "It's a mustard pot.  I mean, it's kind of cool, it has a
363 nice design, and it's an antique, but you can't imagine putting something
364 like this in a museum.")
365              (p "Ha... imagine that... a mustard museum."))
366     #:goes-by '("mustard pot" "antique mustard pot" "mustard"))
367    ('lobby:head-of-elvis
368     <cabinet-item> 'lobby
369     #:invisible? #t
370     #:name "the pickled head of Elvis"
371     #:desc '((p "It's a jar full of some briny-looking liquid and...
372 a free floating head.  The head looks an awful lot like Elvis, and
373 definitely not the younger Elvis.  The hair even somehow maintains
374 that signature swoop while suspended in liquid.  But of course it's
375 not Elvis.")
376              (p "Oh, wait, it has a label at the bottom which says:
377 \"This is really the head of Elvis\".  Well... maybe don't believe
378 everything you read."))
379     #:goes-by '("pickled head of elvis" "pickled head of Elvis"
380                 "elvis" "Elvis" "head" "pickled head"))
381    ('lobby:circuitboard-of-evlis
382     <cabinet-item> 'lobby
383     #:invisible? #t
384     #:name "the pickled circuitboard of Evlis"
385     #:desc '((p "It's a circuitboard from a Lisp Machine called EVLIS.
386 This is quite the find, and you bet just about anyone interested in
387 preserving computer history would love to get their hands on this.")
388              (p "Unfortunately, whatever moron did acquire this has
389 no idea what it means to preserve computers, so here it is floating
390 in some kind of briny liquid.  It appears to be heavily corroded.
391 Too bad..."))
392     #:goes-by '("pickled circuitboard of evlis" "pickled circuitboard of Evlis"
393                 "pickled circuitboard of EVLIS"
394                 "evlis" "Evlis" "EVLIS" "circuitboard" "pickled circuitboard"))
395    ('lobby:teletype-scroll
396     <cabinet-item> 'lobby
397     #:invisible? #t
398     #:name "a scroll of teletype"
399     #:desc '((p "This is a scroll of teletype paper.  It's a bit old
400 and yellowed but the type is very legible.  It says:")
401              (br)
402              (i
403               (p (strong "== The four essential freedoms =="))
404               (p "A program is free software if the program's users have
405 the four essential freedoms: ")
406               (ul (li "The freedom to run the program as you wish, for any purpose (freedom 0).")
407                   (li "The freedom to study how the program works, and change it so it does your computing as you wish (freedom 1). Access to the source code is a precondition for this.")
408                   (li "The freedom to redistribute copies so you can help your neighbor (freedom 2).")
409                   (li "The freedom to distribute copies of your modified versions to others (freedom 3). By doing this you can give the whole community a chance to benefit from your changes. Access to the source code is a precondition for this.")))
410              (p "You get this feeling that ambiguities in the
411 English language surrounding the word 'free' have lead to a lot of terminology debates."))
412     #:goes-by '("scroll of teletype" "scroll of teletype paper" "teletype scroll"
413                 "teletype paper" "scroll" "four freedoms"
414                 "scroll of teletype paper holding the software Four Freedoms"
415                 "scroll of teletype paper holding the software four freedoms"))
416    ('lobby:orange-cat-phone
417     <cabinet-item> 'lobby
418     #:invisible? #t
419     #:name "a telephone shaped like an orange cartoon cat"
420     #:desc "It's made out of a cheap plastic, and it's very orange.
421 It resembles a striped tabby, and it's eyes hold the emotion of
422 a being both sleepy and smarmy.
423 You suspect that someone, somewhere made a ton of cash on items holding
424 this general shape in the 1990s."
425     #:goes-by '("orange cartoon cat phone" "orange cartoon cat telephone"
426                 "orange cat phone" "orange cat telephone"
427                 "cartoon cat phone" "cartoon cat"
428                 "cat phone" "cat telephone" "phone" "telephone"))))
429
430
431 \f
432 ;;; Grand hallway
433 ;;; -------------
434
435 (define-actor <disc-shield> (<gameobj>)
436   ((cmd-take disc-shield-take)))
437
438 (define* (disc-shield-take gameobj message
439                            #:key direct-obj
440                            (player (message-from message)))
441   (create-gameobj <glowing-disc> (gameobj-gm gameobj)
442                   player)  ;; set loc to player to put in player's inventory
443   (<- player 'tell
444       #:text '((p "As you attempt to pull the shield / disk platter
445 from the statue a shining outline appears around it... and a
446 completely separate, glowing copy of the disc materializes into your
447 hands!")))
448   (<- (gameobj-loc gameobj) 'tell-room
449         #:text `(,(mbody-val (<-wait player 'get-name))
450                  " pulls on the shield of the statue, and a glowing "
451                  "copy of it materializes into their hands!")
452         #:exclude player)
453   (<- (gameobj-loc gameobj) 'tell-room
454       #:text
455       '(p "You hear a voice whisper: "
456           (i "\"Share the software... and you'll be free...\""))))
457
458 ;;; This is the disc that gets put in the player's inventory
459 (define-actor <glowing-disc> (<gameobj>)
460   ((cmd-drop glowing-disc-drop-cmd))
461   (initial-props
462    #:allocation #:each-subclass
463    #:init-thunk (build-props
464                  '((hd-platter? . #t))))
465   (name #:allocation #:each-subclass
466         #:init-value "a glowing disc")
467   (desc #:allocation #:each-subclass
468         #:init-value "A brightly glowing disc.  It's shaped like a hard
469 drive platter, not unlike the one from the statue it came from.  It's
470 labeled \"RL02.5\".")
471   (goes-by #:init-value '("glowing disc" "glowing platter"
472                           "glowing disc platter" "glowing disk platter"
473                           "platter" "disc" "disk" "glowing shield")))
474
475 (define* (glowing-disc-drop-cmd gameobj message
476                    #:key direct-obj
477                    (player (message-from message)))
478   (<- player 'tell
479       #:text "You drop the glowing disc, and it shatters into a million pieces!")
480   (<- (mbody-val (<-wait player 'get-loc)) 'tell-room
481       #:text `(,(mbody-val (<-wait player 'get-name))
482                " drops a glowing disc, and it shatters into a million pieces!")
483       #:exclude player)
484   (gameobj-self-destruct gameobj))
485
486 \f
487 ;;; Grand hallway
488
489 (define lobby-map-text
490   "\
491                         |  :       :  |
492   .----------.----------.  :   &   :  .----------.----------.
493   | computer |          |& :YOU ARE: &|  smoking | *UNDER*  |
494   | room     + playroom +  : HERE  :  +  parlor  | *CONS-   |
495   |    >     |          |& :       : &|          | TRUCTION*|
496   '----------'----------'-++-------++-'-------+--'----------'
497                        |    '-----'    |     |   |
498                        :     LOBBY     :     '---'
499                         '.           .'
500                           '---------'")
501
502 (define grand-hallway
503   (lol
504    ('grand-hallway
505     <room> #f
506     #:name "Grand Hallway"
507     #:desc '((p "  A majestic red carpet runs down the center of the room.
508 Busts of serious looking people line the walls, but there's no
509 clear indication that they have any logical relation to this place.")
510              (p "In the center is a large statue of a woman in a warrior's
511 pose, but something is strange about her weapon and shield.  You wonder what
512 that's all about?")
513              (p "To the south is the lobby.  A door to the east is labeled \"smoking
514 room\", while a door to the west is labeled \"playroom\"."))
515     #:exits
516     (list (make <exit>
517             #:name "south"
518             #:to 'lobby)
519           (make <exit>
520             #:name "west"
521             #:to 'playroom)
522           (make <exit>
523             #:name "east"
524             #:to 'smoking-parlor)))
525    ('grand-hallway:map
526     <readable> 'grand-hallway
527     #:name "the hotel map"
528     #:desc '("This appears to be a map of the hotel. "
529              "Like the hotel itself, it seems to be "
530              "incomplete."
531              "You could read it if you want to.")
532     #:read-text `(pre ,lobby-map-text)
533     #:goes-by '("map" "hotel map"))
534    ('grand-hallway:carpet
535     <gameobj> 'grand-hallway
536     #:name "the Grand Hallway carpet"
537     #:desc "It's very red, except in the places where it's very worn."
538     #:invisible? #t
539     #:goes-by '("red carpet" "carpet"))
540    ('grand-hallway:busts
541     <gameobj> 'grand-hallway
542     #:name "the busts of serious people"
543     #:desc "There are about 6 of them in total.  They look distinguished
544 but there's no indication of who they are."
545     #:invisible? #t
546     #:goes-by '("busts" "bust" "busts of serious people" "bust of serious person"))
547    ('grand-hallway:hackthena-statue
548     <proxy-items> 'grand-hallway
549     #:name "the statue of Hackthena"
550     #:desc '((p "The base of the statue says \"Hackthena, guardian of the hacker
551 spirit\".  You've heard of Hackthena... not a goddess, but spiritual protector of
552 all good hacks, and legendary hacker herself.")
553              (p "Hackthena holds the form of a human woman.  She wears flowing
554 robes, has a pear of curly bovine-esque horns protruding from the sides of her
555 head, wears a pair of horn-rimmed glasses, and appears posed as if for battle.
556 But instead of a weapon, she seems to hold some sort of keyboard.  And her
557 shield... well it's round like a shield, but something seems off about it.
558 You'd better take a closer look to be sure."))
559     #:goes-by '("hackthena statue" "hackthena" "statue" "statue of hackthena")
560     #:proxy-items '(grand-hallway:keyboard
561                     grand-hallway:disc-platter
562                     grand-hallway:hackthena-horns))
563    ('grand-hallway:keyboard
564     <gameobj> 'grand-hallway
565     #:name "a Knight Keyboard"
566     #:desc "Whoa, this isn't just any old keyboard, this is a Knight Keyboard!
567 Any space cadet can see that with that kind of layout a hack-and-slayer could
568 thrash out some serious key-chords like there's no tomorrow.  You guess
569 Hackthena must be an emacs user."
570     #:invisible? #t
571     #:take-me? (lambda _
572                  (values #f
573                          #:why-not
574                          `("Are you kidding?  Do you know how hard it is to find "
575                               "a Knight Keyboard?  There's no way she's going "
576                               "to give that up.")))
577     #:goes-by '("knight keyboard" "keyboard"))
578    ('grand-hallway:hackthena-horns
579     <gameobj> 'grand-hallway
580     #:name "Hackthena's horns"
581     #:desc "They're not unlike a Gnu's horns."
582     #:invisible? #t
583     #:take-me? (lambda _
584                  (values #f
585                          #:why-not
586                          `("Are you seriously considering desecrating a statue?")))
587     #:goes-by '("hackthena's horns" "horns" "horns of hacktena"))
588    ('grand-hallway:disc-platter
589     <disc-shield> 'grand-hallway
590     #:name "Hackthena's shield"
591     #:desc "No wonder the \"shield\" looks unusual... it seems to be a hard disk
592 platter!  It has \"RL02.5\" written on it.  It looks kind of loose."
593     #:invisible? #t
594     #:goes-by '("hackthena's shield" "shield" "platter" "hard disk platter"))))
595
596 \f
597 ;;; Playroom
598 ;;; --------
599
600 (define-actor <rgb-machine> (<gameobj>)
601   ((cmd-run rgb-machine-cmd-run)
602    (cmd-reset rgb-machine-cmd-reset))
603   (commands
604    #:allocation #:each-subclass
605    #:init-thunk (build-commands
606                  (("run" "start") ((direct-command cmd-run)))
607                  ("reset" ((direct-command cmd-reset)))))
608   (resetting #:init-value #f
609              #:accessor .resetting)
610   ;; used to reset, and to kick off the first item in the list
611   (rgb-items #:init-keyword #:rgb-items
612              #:accessor .rgb-items))
613
614 (define (rgb-machine-cmd-run rgb-machine message . _)
615   (define player (message-from message))
616   (<-wait player 'tell
617           #:text '("You start the rube goldberg machine."))
618   (<-wait (gameobj-loc rgb-machine) 'tell-room
619           #:text `(,(mbody-val (<-wait player 'get-name))
620                    " runs the rube goldberg machine.")
621           #:exclude player)
622   (8sleep 1)
623   (match (.rgb-items rgb-machine)
624     ((first-item rest ...)
625      (<- (dyn-ref rgb-machine first-item) 'trigger))))
626
627 (define (rgb-machine-cmd-reset rgb-machine message . _)
628   (define player (message-from message))
629   (cond
630    ((not (.resetting rgb-machine))
631     (set! (.resetting rgb-machine) #t)
632     (<-wait player 'tell
633             #:text '("You reset the rube goldberg machine."))
634     (<-wait (gameobj-loc rgb-machine) 'tell-room
635             #:text `(,(mbody-val (<-wait player 'get-name))
636                      " resets the rube goldberg machine.")
637             #:exclude player)
638     (<-wait (gameobj-loc rgb-machine) 'tell-room
639             #:text '("From a panel in the wall, a white gloved mechanical "
640                      "arm reaches out to reset all the "
641                      "rube goldberg components."))
642     (8sleep (/ 1 2))
643     (for-each
644      (lambda (rgb-item)
645        (<- (dyn-ref rgb-machine rgb-item) 'reset)
646        (8sleep (/ 1 2)))
647      (.rgb-items rgb-machine))
648     (<- (gameobj-loc rgb-machine) 'tell-room
649         #:text "The machine's mechanical arm retreats into the wall!")
650     (set! (.resetting rgb-machine) #f))
651    (else
652     (<-wait player 'tell
653             #:text '("But it's in the middle of resetting right now!")))))
654
655 (define-actor <rgb-item> (<gameobj>)
656   ((trigger rgb-item-trigger)
657    (reset rgb-item-reset))
658   (invisible? #:init-value #t)
659   (steps #:init-keyword #:steps
660          #:accessor .steps)
661   (triggers-as #:init-value #f
662                #:init-keyword #:triggers-as
663                #:getter .triggers-as)
664   (reset-msg #:init-keyword #:reset-msg
665              #:getter .reset-msg)
666   ;; States: ready -> running -> ran
667   (state #:init-value 'ready
668          #:accessor .state))
669
670
671 (define (rgb-item-trigger rgb-item message . _)
672   (define room (gameobj-loc rgb-item))
673   (case (.state rgb-item)
674     ((ready)
675      ;; Set state to running
676      (set! (.state rgb-item) 'running)
677
678      ;; Loop through all steps
679      (for-each
680       (lambda (step)
681         (match step
682           ;; A string?  That's the description of what's happening, tell players
683           ((? string? str)
684            (<- room 'tell-room #:text str))
685           ;; A number?  Sleep for that many secs
686           ((? number? num)
687            (8sleep num))
688           ;; A symbol?  That's another gameobj to look up dynamically
689           ((? symbol? sym)
690            (<- (dyn-ref rgb-item sym) 'trigger
691                #:triggered-by (.triggers-as rgb-item)))
692           (_ (throw 'unknown-step-type
693                     "Don't know how to process rube goldberg machine step type?"
694                     #:step step))))
695       (.steps rgb-item))
696
697      ;; We're done! Set state to ran
698      (set! (.state rgb-item) 'ran))
699
700     (else
701      (<- room 'tell-room
702          #:text `("... but " ,(slot-ref rgb-item 'name)
703                   " has already been triggered!")))))
704
705 (define (rgb-item-reset rgb-item message . _)
706   (define room (gameobj-loc rgb-item))
707   (case (.state rgb-item)
708     ((ran)
709      (set! (.state rgb-item) 'ready)
710      (<- room 'tell-room
711          #:text (.reset-msg rgb-item)))
712     ((running)
713      (<- room 'tell-room
714          #:text `("... but " ,(slot-ref rgb-item 'name)
715                   " is currently running!")))
716     ((ready)
717      (<- room 'tell-room
718          #:text `("... but " ,(slot-ref rgb-item 'name)
719                   " has already been reset.")))))
720
721 (define-actor <rgb-kettle> (<rgb-item>)
722   ((trigger rgb-kettle-trigger)
723    (reset rgb-kettle-reset))
724   (heated #:accessor .heated
725           #:init-value #f)
726   (filled #:accessor .filled
727           #:init-value #f))
728
729 (define* (rgb-kettle-trigger rgb-item message #:key triggered-by)
730   (define room (gameobj-loc rgb-item))
731   (if (not (eq? (.state rgb-item) 'ran))
732       (begin
733         (match triggered-by
734           ('water-demon
735            (set! (.state rgb-item) 'running)
736            (set! (.filled rgb-item) #t))
737           ('quik-heater
738            (set! (.state rgb-item) 'running)
739            (set! (.heated rgb-item) #t)))
740         (when (and (.filled rgb-item)
741                    (.heated rgb-item))
742           (<- room 'tell-room
743               #:text '((i "*kshhhhhh!*")
744                        " The water has boiled!"))
745           (8sleep .25)
746           (set! (.state rgb-item) 'ran)
747           ;; insert a cup of hot tea in the room
748           (create-gameobj <hot-tea> (gameobj-gm rgb-item) room)
749           (<- room 'tell-room
750               #:text '("The machine pours out a cup of hot tea! "
751                        "Looks like the machine finished!"))))
752       (<- room 'tell-room
753          #:text `("... but " ,(slot-ref rgb-item 'name)
754                   " has already been triggered!"))))
755
756 (define (rgb-kettle-reset rgb-item message . rest-args)
757   (define room (gameobj-loc rgb-item))
758   (when (eq? (.state rgb-item) 'ran)
759     (set! (.heated rgb-item) #f)
760     (set! (.filled rgb-item) #f))
761   (apply rgb-item-reset rgb-item message rest-args))
762
763 (define-actor <hot-tea> (<gameobj>)
764   ((cmd-drink hot-tea-cmd-drink)
765    (cmd-sip hot-tea-cmd-sip)
766    (cmd-gotta-hold hot-tea-cmd-gotta-hold))
767   (contained-commands
768    #:allocation #:each-subclass
769    #:init-thunk (build-commands
770                  ("drink" ((direct-command cmd-drink)))
771                  ("sip" ((direct-command cmd-sip)))))
772   
773   (sips-left #:init-value 4
774              #:accessor .sips-left)
775   (name #:init-value "a cup of hot tea")
776   (take-me? #:init-value #t)
777   (goes-by #:init-value '("cup of hot tea" "cup of tea" "tea" "cup"))
778   (desc #:init-value "It's a steaming cup of hot tea.  It looks pretty good!"))
779
780 (define (hot-tea-cmd-drink hot-tea message . _)
781   (define player (message-from message))
782   (define player-loc (mbody-val (<-wait player 'get-loc)))
783   (define player-name (mbody-val (<-wait player 'get-name)))
784   (<- player 'tell
785       #:text "You drink a steaming cup of hot tea all at once... hot hot hot!")
786   (<- player-loc 'tell-room
787       #:text `(,player-name
788                " drinks a steaming cup of hot tea all at once.")
789       #:exclude player)
790   (gameobj-self-destruct hot-tea))
791
792 (define (hot-tea-cmd-sip hot-tea message . _)
793   (define player (message-from message))
794   (define player-loc (mbody-val (<-wait player 'get-loc)))
795   (define player-name (mbody-val (<-wait player 'get-name)))
796   (set! (.sips-left hot-tea) (- (.sips-left hot-tea) 1))
797   (<- player 'tell
798       #:text "You take a sip of your steaming hot tea.  How refined!")
799   (<- player-loc 'tell-room
800       #:text `(,player-name
801                " takes a sip of their steaming hot tea.  How refined!")
802       #:exclude player)
803   (when (= (.sips-left hot-tea) 0)
804     (<- player 'tell
805         #:text "You've finished your tea!")
806     (<- player-loc 'tell-room
807         #:text `(,player-name
808                  " finishes their tea!")
809         #:exclude player)
810     (gameobj-self-destruct hot-tea)))
811
812 (define playroom
813   (lol
814    ('playroom
815     <room> #f
816     #:name "The Playroom"
817     #:desc '(p ("  There are toys scattered everywhere here.  It's really unclear
818 if this room is intended for children or child-like adults.")
819                ("  There are doors to both the east and the west."))
820     #:exits
821     (list (make <exit>
822             #:name "east"
823             #:to 'grand-hallway)
824           (make <exit>
825             #:name "west"
826             #:to 'computer-room)))
827    ('playroom:cubey
828     <gameobj> 'playroom
829     #:name "Cubey"
830     #:take-me? #t
831     #:desc "  It's a little foam cube with googly eyes on it.  So cute!")
832    ('playroom:cuddles-plushie
833     <gameobj> 'playroom
834     #:name "a Cuddles plushie"
835     #:goes-by '("plushie" "cuddles plushie" "cuddles")
836     #:take-me? #t
837     #:desc "  A warm and fuzzy cuddles plushie!  It's a cuddlefish!")
838
839    ('playroom:toy-chest
840     <container> 'playroom
841     #:name "a toy chest"
842     #:goes-by '("toy chest" "chest")
843     #:desc (lambda (toy-chest whos-looking)
844              (let ((contents (gameobj-occupants toy-chest)))
845                `((p "A brightly painted wooden chest.  The word \"TOYS\" is "
846                     "engraved on it.")
847                  (p "Inside you see:"
848                     ,(if (eq? contents '())
849                          " nothing!  It's empty!"
850                          `(ul ,(map (lambda (occupant)
851                                       `(li ,(mbody-val
852                                              (<-wait occupant 'get-name))))
853                                     (gameobj-occupants toy-chest))))))))
854     #:take-from-me? #t
855     #:put-in-me? #t)
856
857    ;; Things inside the toy chest
858    ('playroom:toy-chest:rubber-duck
859     <gameobj> 'playroom:toy-chest
860     #:name "a rubber duck"
861     #:goes-by '("rubber duck" "duck")
862     #:take-me? #t
863     #:desc "It's a yellow rubber duck with a bright orange beak.")
864
865    ('playroom:rgb-machine
866     <rgb-machine> 'playroom
867     #:name "a Rube Goldberg machine"
868     #:goes-by '("rube goldberg machine" "machine")
869     #:rgb-items '(playroom:rgb-dominoes
870                   playroom:rgb-switch-match
871                   playroom:rgb-candle
872                   playroom:rgb-catapult
873                   playroom:rgb-water-demon
874                   playroom:rgb-quik-heater
875                   playroom:rgb-kettle)
876     #:desc "It's one of those hilarious Rube Goldberg machines.
877 What could happen if you started it?")
878
879    ;; Dominoes topple
880    ('playroom:rgb-dominoes
881     <rgb-item> 'playroom
882     #:name "some dominoes"
883     #:goes-by '("dominoes" "some dominoes")
884     #:steps `("The dominoes topple down the line..."
885               1
886               "The last domino lands on a switch!"
887               1.5
888               playroom:rgb-switch-match)
889     #:reset-msg "The dominoes are placed back into position.")
890
891    ;; Which hit the switch and strike a match
892    ('playroom:rgb-switch-match
893     <rgb-item> 'playroom
894     #:name "a switch"
895     #:goes-by '("switch" "match")
896     #:steps `("The switch lights a match!"
897               ,(/ 2 3)
898               "The match lights a candle!"
899               1.5
900               playroom:rgb-candle)
901     #:reset-msg "A fresh match is installed and the switch is reset.")
902    ;; which lights a candle and burns a rope
903    ('playroom:rgb-candle
904     <rgb-item> 'playroom
905     #:name "a candle"
906     #:goes-by '("candle")
907     #:steps `("The candle burns..."
908               (/ 2 3)  ; oops!
909               "The candle is burning away a rope!"
910               2
911               "The rope snaps!"
912               .5
913               playroom:rgb-catapult)
914     #:reset-msg "A fresh candle is installed.")
915    ;; which catapults a rock
916    ('playroom:rgb-catapult
917     <rgb-item> 'playroom
918     #:name "a catapult"
919     #:goes-by '("catapult")
920     #:steps `("The snapped rope unleashes a catapult, which throws a rock!"
921               2
922               "The rock flies through a water demon, startling it!"
923               .5
924               playroom:rgb-water-demon
925               2
926               "The rock whacks into the quik-heater's on button!"
927               .5
928               playroom:rgb-quik-heater)
929     #:reset-msg
930     '("A fresh rope is attached to the catapult, which is pulled taught. "
931       "A fresh rock is placed on the catapult."))
932    ;; which both:
933    ;;   '- panics the water demon
934    ;;      '- which waters the kettle
935    ('playroom:rgb-water-demon
936     <rgb-item> 'playroom
937     #:name "the water demon"
938     #:triggers-as 'water-demon
939     #:goes-by '("water demon" "demon")
940     #:steps `("The water demon panics, and starts leaking water into the kettle below!"
941               3
942               "The kettle is filled!"
943               playroom:rgb-kettle)
944     #:reset-msg '("The water demon is scratched behind the ears and calms down."))
945    ;;   '- bops the quik-heater button
946    ;;      '- which heats the kettle
947    ('playroom:rgb-quik-heater
948     <rgb-item> 'playroom
949     #:name "the quik heater"
950     #:triggers-as 'quik-heater
951     #:goes-by '("quik heater" "heater")
952     #:steps `("The quik-heater heats up the kettle above it!"
953               3
954               "The kettle is heated up!"
955               playroom:rgb-kettle)
956     #:reset-msg '("The quik heater is turned off."))
957    ;; Finally, the kettle
958    ('playroom:rgb-kettle
959     <rgb-kettle> 'playroom
960     #:name "the kettle"
961     #:goes-by '("kettle")
962     #:reset-msg '("The kettle is emptied."))))
963
964
965 \f
966 ;;; Writing room
967 ;;; ------------
968
969 \f
970 ;;; Armory???
971 ;;; ---------
972
973 ;; ... full of NURPH weapons?
974
975 \f
976 ;;; Smoking parlor
977 ;;; --------------
978
979 (define-class <furniture> (<gameobj>)
980   (sit-phrase #:init-keyword #:sit-phrase)
981   (sit-phrase-third-person #:init-keyword #:sit-phrase-third-person)
982   (sit-name #:init-keyword #:sit-name)
983
984   (commands
985    #:allocation #:each-subclass
986    #:init-thunk (build-commands
987                  ("sit" ((direct-command cmd-sit-furniture)))))
988   (actions #:allocation #:each-subclass
989            #:init-thunk (build-actions
990                          (cmd-sit-furniture furniture-cmd-sit))))
991
992 (define* (furniture-cmd-sit actor message #:key direct-obj)
993   (define player-name
994     (mbody-val (<-wait (message-from message) 'get-name)))
995   (<- (message-from message) 'tell
996       #:text (format #f "You ~a ~a.\n"
997                      (slot-ref actor 'sit-phrase)
998                      (slot-ref actor 'sit-name)))
999   (<- (slot-ref actor 'loc) 'tell-room
1000       #:text (format #f "~a ~a on ~a.\n"
1001                      player-name
1002                      (slot-ref actor 'sit-phrase-third-person)
1003                      (slot-ref actor 'sit-name))
1004       #:exclude (message-from message)))
1005
1006
1007 (define smoking-parlor
1008   (lol
1009    ('smoking-parlor
1010     <room> #f
1011     #:name "Smoking Parlor"
1012     #:desc
1013     '((p "This room looks quite posh.  There are huge comfy seats you can sit in
1014 if you like. Strangely, you see a large sign saying \"No Smoking\".  The owners must
1015 have installed this place and then changed their mind later.")
1016       (p "There's a door to the west leading back to the grand hallway, and
1017 a nondescript steel door to the south, leading apparently outside."))
1018     #:exits
1019     (list (make <exit>
1020             #:name "west"
1021             #:to 'grand-hallway)
1022           (make <exit>
1023             #:name "south"
1024             #:to 'break-room)))
1025    ('smoking-parlor:chair
1026     <furniture> 'smoking-parlor
1027     #:name "a comfy leather chair"
1028     #:desc "  That leather chair looks really comfy!"
1029     #:goes-by '("leather chair" "comfy leather chair" "chair")
1030     #:sit-phrase "sink into"
1031     #:sit-phrase-third-person "sinks into"
1032     #:sit-name "the comfy leather chair")
1033    ('smoking-parlor:sofa
1034     <furniture> 'smoking-parlor
1035     #:name "a plush leather sofa"
1036     #:desc "  That leather chair looks really comfy!"
1037     #:goes-by '("leather sofa" "plush leather sofa" "sofa"
1038                 "leather couch" "plush leather couch" "couch")
1039     #:sit-phrase "sprawl out on"
1040     #:sit-phrase-third-person "sprawls out on into"
1041     #:sit-name "the plush leather couch")
1042    ('smoking-parlor:bar-stool
1043     <furniture> 'smoking-parlor
1044     #:name "a bar stool"
1045     #:desc "  Conveniently located near the bar!  Not the most comfortable
1046 seat in the room, though."
1047     #:goes-by '("stool" "bar stool" "seat")
1048     #:sit-phrase "hop on"
1049     #:sit-phrase-third-person "hops onto"
1050     #:sit-name "the bar stool")
1051    ('ford-prefect
1052     <chatty-npc> 'smoking-parlor
1053     #:name "Ford Prefect"
1054     #:desc "Just some guy, you know?"
1055     #:goes-by '("Ford Prefect" "ford prefect"
1056                 "frood" "prefect" "ford")
1057     #:catchphrases prefect-quotes)
1058
1059    ('smoking-parlor:no-smoking-sign
1060     <readable> 'smoking-parlor
1061     #:invisible? #t
1062     #:name "No Smoking Sign"
1063     #:desc "This sign says \"No Smoking\" in big, red letters.
1064 It has some bits of bubble gum stuck to it... yuck."
1065     #:goes-by '("no smoking sign" "sign")
1066     #:read-text "It says \"No Smoking\", just like you'd expect from
1067 a No Smoking sign.")
1068    ;; TODO: Cigar dispenser
1069    ))
1070
1071 \f
1072
1073 ;;; Breakroom
1074 ;;; ---------
1075
1076 (define-class <desk-clerk> (<gameobj>)
1077   ;; The desk clerk has three states:
1078   ;;  - on-duty: Arrived, and waiting for instructions (and losing patience
1079   ;;    gradually)
1080   ;;  - slacking: In the break room, probably smoking a cigarette
1081   ;;    or checking text messages
1082   (state #:init-value 'slacking)
1083   (commands #:allocation #:each-subclass
1084             #:init-thunk
1085             (build-commands
1086              (("talk" "chat") ((direct-command cmd-chat)))
1087              ("ask" ((direct-command cmd-ask-incomplete)
1088                      (prep-direct-command cmd-ask-about)))
1089              ("dismiss" ((direct-command cmd-dismiss)))))
1090   (patience #:init-value 0)
1091   (actions #:allocation #:each-subclass
1092            #:init-thunk (build-actions
1093                          (init clerk-act-init)
1094                          (cmd-chat clerk-cmd-chat)
1095                          (cmd-ask-incomplete clerk-cmd-ask-incomplete)
1096                          (cmd-ask-about clerk-cmd-ask)
1097                          (cmd-dismiss clerk-cmd-dismiss)
1098                          (update-loop clerk-act-update-loop)
1099                          (be-summoned clerk-act-be-summoned))))
1100
1101 (define (clerk-act-init clerk message . _)
1102   ;; call the gameobj main init method
1103   (gameobj-act-init clerk message)
1104   ;; start our main loop
1105   (<- (actor-id clerk) 'update-loop))
1106
1107 (define changing-name-text "Changing your name is easy!
1108 We have a clipboard here at the desk
1109 where you can make yourself known to other participants in the hotel
1110 if you sign it.  Try 'sign form as <your-name>', replacing
1111 <your-name>, obviously!")
1112
1113 (define phd-text
1114   "Ah... when I'm not here, I've got a PHD to finish.")
1115
1116 (define clerk-help-topics
1117   `(("changing name" . ,changing-name-text)
1118     ("sign-in form" . ,changing-name-text)
1119     ("form" . ,changing-name-text)
1120     ("common commands" .
1121      "Here are some useful commands you might like to try: chat,
1122 go, take, drop, say...")
1123     ("hotel" .
1124      "We hope you enjoy your stay at Hotel Bricabrac.  As you may see,
1125 our hotel emphasizes interesting experiences over rest and lodging.
1126 The origins of the hotel are... unclear... and it has recently come
1127 under new... 'management'.  But at Hotel Bricabrac we believe these
1128 aspects make the hotel into a fun and unique experience!  Please,
1129 feel free to walk around and explore.")
1130     ("physics paper" . ,phd-text)
1131     ("paper" . ,phd-text)
1132     ("proprietor" . "Oh, he's that frumpy looking fellow sitting over there.")))
1133
1134
1135 (define clerk-knows-about
1136   "'ask clerk about changing name', 'ask clerk about common commands', and 'ask clerk about the hotel'")
1137
1138 (define clerk-general-helpful-line
1139   (string-append
1140    "The clerk says, \"If you need help with anything, feel free to ask me about it.
1141 For example, 'ask clerk about changing name'. You can ask me about the following:
1142 " clerk-knows-about ".\"\n"))
1143
1144 (define clerk-slacking-complaints
1145   '("The pay here is absolutely lousy."
1146     "The owner here has no idea what they're doing."
1147     "Some times you just gotta step away, you know?"
1148     "You as exhausted as I am?"
1149     "Yeah well, this is just temporary.  I'm studying to be a high
1150 energy particle physicist.  But ya gotta pay the bills, especially
1151 with tuition at where it is..."))
1152
1153 (define* (clerk-cmd-chat clerk message #:key direct-obj)
1154   (match (slot-ref clerk 'state)
1155     ('on-duty
1156      (<- (message-from message) 'tell
1157          #:text clerk-general-helpful-line))
1158     ('slacking
1159      (<- (message-from message) 'tell
1160          #:text
1161          (string-append
1162           "The clerk says, \""
1163           (random-choice clerk-slacking-complaints)
1164           "\"\n")))))
1165
1166 (define (clerk-cmd-ask-incomplete clerk message . _)
1167   (<- (message-from message) 'tell
1168       #:text "The clerk says, \"Ask about what?\"\n"))
1169
1170 (define clerk-doesnt-know-text
1171   "The clerk apologizes and says she doesn't know about that topic.\n")
1172
1173 (define* (clerk-cmd-ask clerk message #:key indir-obj
1174                         #:allow-other-keys)
1175   (match (slot-ref clerk 'state)
1176     ('on-duty
1177      (match (assoc indir-obj clerk-help-topics)
1178        ((_ . info)
1179            (<- (message-from message) 'tell
1180                #:text
1181                (string-append "The clerk clears her throat and says:\n  \""
1182                               info
1183                               "\"\n")))
1184        (#f
1185         (<- (message-from message) 'tell
1186             #:text clerk-doesnt-know-text))))
1187     ('slacking
1188      (<- (message-from message) 'tell
1189          #:text "The clerk says, \"Sorry, I'm on my break.\"\n"))))
1190
1191 (define* (clerk-act-be-summoned clerk message #:key who-summoned)
1192   (match (slot-ref clerk 'state)
1193     ('on-duty
1194      (<- who-summoned 'tell
1195          #:text
1196          "The clerk tells you as politely as she can that she's already here,
1197 so there's no need to ring the bell.\n"))
1198     ('slacking
1199      (<- (gameobj-loc clerk) 'tell-room
1200          #:text
1201          "The clerk's ears perk up, she stamps out a cigarette, and she
1202 runs out of the room!\n")
1203      (gameobj-set-loc! clerk (dyn-ref clerk 'lobby))
1204      (slot-set! clerk 'patience 8)
1205      (slot-set! clerk 'state 'on-duty)
1206      (<- (gameobj-loc clerk) 'tell-room
1207          #:text
1208          (string-append
1209           "  Suddenly, a uniformed woman rushes into the room!  She's wearing a
1210 badge that says \"Desk Clerk\".
1211   \"Hello, yes,\" she says between breaths, \"welcome to Hotel Bricabrac!
1212 We look forward to your stay.  If you'd like help getting acclimated,
1213 feel free to ask me.  For example, 'ask clerk about changing name'.
1214 You can ask me about the following:
1215 " clerk-knows-about ".\"\n")))))
1216
1217 (define* (clerk-cmd-dismiss clerk message . _)
1218   (define player-name
1219     (mbody-val (<-wait (message-from message) 'get-name)))
1220   (match (slot-ref clerk 'state)
1221     ('on-duty
1222      (<- (gameobj-loc clerk) 'tell-room
1223          #:text
1224          (format #f "\"Thanks ~a!\" says the clerk. \"I have somewhere I need to be.\"
1225 The clerk leaves the room in a hurry.\n"
1226                  player-name)
1227          #:exclude (actor-id clerk))
1228      (gameobj-set-loc! clerk (dyn-ref clerk 'break-room))
1229      (slot-set! clerk 'state 'slacking)
1230      (<- (gameobj-loc clerk) 'tell-room
1231          #:text clerk-return-to-slacking-text
1232          #:exclude (actor-id clerk)))
1233     ('slacking
1234      (<- (message-from message) 'tell
1235          #:text "The clerk sternly asks you to not be so dismissive.\n"))))
1236
1237 (define clerk-slacking-texts
1238   '("The clerk takes a long drag on her cigarette.\n"
1239     "The clerk scrolls through text messages on her phone.\n"
1240     "The clerk coughs a few times.\n"
1241     "The clerk checks her watch and justifies a few more minutes outside.\n"
1242     "The clerk fumbles around for a lighter.\n"
1243     "The clerk sighs deeply and exhaustedly.\n"
1244     "The clerk fumbles around for a cigarette.\n"))
1245
1246 (define clerk-working-impatience-texts
1247   '("The clerk hums something, but you're not sure what it is."
1248     "The clerk attempts to change the overhead music, but the dial seems broken."
1249     "The clerk clicks around on the desk computer."
1250     "The clerk scribbles an equation on a memo pad, then crosses it out."
1251     "The clerk mutters something about the proprietor having no idea how to run a hotel."
1252     "The clerk thumbs through a printout of some physics paper."))
1253
1254 (define clerk-slack-excuse-text
1255   "The desk clerk excuses herself, but says you are welcome to ring the bell
1256 if you need further help.")
1257
1258 (define clerk-return-to-slacking-text
1259   "The desk clerk enters and slams the door behind her.\n")
1260
1261
1262 (define (clerk-act-update-loop clerk message)
1263   (define (tell-room text)
1264     (<- (gameobj-loc clerk) 'tell-room
1265         #:text text
1266         #:exclude (actor-id clerk)))
1267   (define (loop-if-not-destructed)
1268     (if (not (slot-ref clerk 'destructed))
1269         ;; This iterates by "recursing" on itself by calling itself
1270         ;; (as the message handler) again.  It used to be that we had to do
1271         ;; this, because there was a bug where a loop which yielded like this
1272         ;; would keep growing the stack due to some parameter goofiness.
1273         ;; That's no longer true, but there's an added advantage to this
1274         ;; route: it's much more live hackable.  If we change the definition
1275         ;; of this method, the character will act differently on the next
1276         ;; "tick" of the loop.
1277         (<- (actor-id clerk) 'update-loop)))
1278   (match (slot-ref clerk 'state)
1279     ('slacking
1280      (tell-room (random-choice clerk-slacking-texts))
1281      (8sleep (+ (random 20) 15))
1282      (loop-if-not-destructed))
1283     ('on-duty
1284      (if (> (slot-ref clerk 'patience) 0)
1285          ;; Keep working but lose patience gradually
1286          (begin
1287            (tell-room (random-choice clerk-working-impatience-texts))
1288            (slot-set! clerk 'patience (- (slot-ref clerk 'patience)
1289                                          (+ (random 2) 1)))
1290            (8sleep (+ (random 60) 40))
1291            (loop-if-not-destructed))
1292          ;; Back to slacking
1293          (begin
1294            (tell-room clerk-slack-excuse-text)
1295            ;; back bto the break room
1296            (gameobj-set-loc! clerk (dyn-ref clerk 'break-room))
1297            (tell-room clerk-return-to-slacking-text)
1298            ;; annnnnd back to slacking
1299            (slot-set! clerk 'state 'slacking)
1300            (8sleep (+ (random 30) 15))
1301            (loop-if-not-destructed))))))
1302
1303
1304 (define break-room
1305   (lol
1306    ('break-room
1307     <room> #f
1308     #:name "Employee Break Room"
1309     #:desc "  This is less a room and more of an outdoor wire cage.  You get
1310 a bit of a view of the brick exterior of the building, and a crisp wind blows,
1311 whistling, through the openings of the fenced area.  Partly smoked cigarettes
1312 and various other debris cover the floor.
1313   Through the wires you can see... well... hm.  It looks oddly like
1314 the scenery tapers off nothingness.  But that can't be right, can it?"
1315     #:exits
1316     (list (make <exit>
1317             #:name "north"
1318             #:to 'smoking-parlor)))
1319    ('break-room:desk-clerk
1320     <desk-clerk> 'break-room
1321     #:name "the hotel desk clerk"
1322     #:desc "  The hotel clerk is wearing a neatly pressed uniform bearing the
1323 hotel insignia.  She appears to be rather exhausted."
1324     #:goes-by '("hotel desk clerk" "clerk" "desk clerk"))
1325    ('break-room:void
1326     <gameobj> 'break-room
1327     #:invisible? #t
1328     #:name "The Void"
1329     #:desc "As you stare into the void, the void stares back into you."
1330     #:goes-by '("void" "abyss" "nothingness" "scenery"))
1331    ('break-room:fence
1332     <gameobj> 'break-room
1333     #:invisible? #t
1334     #:name "break room cage"
1335     #:desc "It's a mostly-cubical wire mesh surrounding the break area.
1336 You can see through the gaps, but they're too small to put more than a
1337 couple of fingers through.  There appears to be some wear and tear to
1338 the paint, but the wires themselves seem to be unusually sturdy."
1339     #:goes-by '("fence" "cage" "wire cage"))))
1340
1341
1342 \f
1343 ;;; Ennpie's Sea Lounge
1344 ;;; -------------------
1345
1346 \f
1347 ;;; Computer room
1348 ;;; -------------
1349
1350 ;; Our computer and hard drive are based off the PDP-11 and the RL01 /
1351 ;; RL02 disk drives.  However we increment both by .5 (a true heresy)
1352 ;; to distinguish both from the real thing.
1353
1354 (define-actor <hard-drive> (<gameobj>)
1355   ((cmd-put-in hard-drive-insert)
1356    (cmd-push-button hard-drive-push-button)
1357    (get-state hard-drive-act-get-state))
1358   (commands #:allocation #:each-subclass
1359             #:init-thunk (build-commands
1360                           ("insert" ((prep-indir-command cmd-put-in
1361                                                          '("in" "inside" "into"))))
1362                           (("press" "push") ((prep-indir-command cmd-push-button)))))
1363   ;; the state moves from: empty -> with-disc -> loading -> ready
1364   (state #:init-value 'empty
1365          #:accessor .state))
1366
1367 (define (hard-drive-act-get-state hard-drive message)
1368   (<-reply message (.state hard-drive)))
1369
1370 (define* (hard-drive-desc hard-drive #:optional whos-looking)
1371   `((p "The hard drive is labeled \"RL02.5\".  It's a little under a meter tall.")
1372     (p "There is a slot where a disk platter could be inserted, "
1373        ,(if (eq? (.state hard-drive) 'empty)
1374             "which is currently empty"
1375             "which contains a glowing platter")
1376        ". There is a LOAD button "
1377        ,(if (member (.state hard-drive) '(empty with-disc))
1378             "which is glowing"
1379             "which is pressed in and unlit")
1380        ". There is a READY indicator "
1381        ,(if (eq? (.state hard-drive) 'ready)
1382             "which is glowing."
1383             "which is unlit.")
1384        ,(if (member (.state hard-drive) '(loading ready))
1385             "  The machine emits a gentle whirring noise."
1386             ""))))
1387
1388 (define* (hard-drive-push-button gameobj message
1389                                  #:key direct-obj indir-obj preposition
1390                                  (player (message-from message)))
1391   (define (tell-room text)
1392     (<-wait (gameobj-loc gameobj) 'tell-room
1393             #:text text))
1394   (define (tell-room-excluding-player text)
1395     (<-wait (gameobj-loc gameobj) 'tell-room
1396             #:text text
1397             #:exclude player))
1398   (cond
1399    ((ci-member direct-obj '("button" "load button" "load"))
1400     (tell-room-excluding-player
1401      `(,(mbody-val (<-wait player 'get-name))
1402        " presses the button on the hard disk."))
1403     (<- player 'tell
1404         #:text "You press the button on the hard disk.")
1405
1406     (case (.state gameobj)
1407       ((empty)
1408        ;; I have no idea what this drive did when you didn't have a platter
1409        ;; in it and pressed load, but I know there was a FAULT button.
1410        (tell-room "You hear some movement inside the hard drive...")
1411        (8sleep 1.5)
1412        (tell-room
1413         '("... but then the FAULT button blinks a couple times. "
1414           "What could be missing?")))
1415       ((with-disc)
1416        (set! (.state gameobj) 'loading)
1417        (tell-room "The hard disk begins to spin up!")
1418        (8sleep 2)
1419        (set! (.state gameobj) 'ready)
1420        (tell-room "The READY light turns on!"))
1421       ((loading ready)
1422        (<- player 'tell
1423            #:text '("Pressing the button does nothing right now, "
1424                     "but it does feel satisfying.")))))
1425    (else
1426     (<- player 'tell
1427         #:text '("How could you think of pressing anything else "
1428                  "but that tantalizing button right in front of you?")))))
1429
1430 (define* (hard-drive-insert gameobj message
1431                             #:key direct-obj indir-obj preposition
1432                             (player (message-from message)))
1433   (define our-name (slot-ref gameobj 'name))
1434   (define this-thing
1435     (call/ec
1436      (lambda (return)
1437        (for-each (lambda (occupant)
1438                    (define goes-by (mbody-val (<-wait occupant 'goes-by)))
1439                    (when (ci-member direct-obj goes-by)
1440                      (return occupant)))
1441                  (mbody-val (<-wait player 'get-occupants)))
1442        ;; nothing found
1443        #f)))
1444   (cond
1445    ((not this-thing)
1446     (<- player 'tell
1447         #:text `("You don't seem to have any such " ,direct-obj " to put "
1448                  ,preposition " " ,our-name ".")))
1449    ((not (mbody-val (<-wait this-thing 'get-prop 'hd-platter?)))
1450     (<- player 'tell
1451         #:text `("It wouldn't make sense to put "
1452                  ,(mbody-val (<-wait this-thing 'get-name))
1453                  " " ,preposition " " ,our-name ".")))
1454    ((not (eq? (.state gameobj) 'empty))
1455     (<- player 'tell
1456         #:text "The disk drive already has a platter in it."))
1457    (else
1458     (set! (.state gameobj) 'with-disc)
1459     (<- player 'tell
1460         #:text '((p "You insert the glowing disc into the drive.")
1461                  (p "The LOAD button begins to glow."))))))
1462
1463 ;; The computar
1464 (define-actor <computer> (<gameobj>)
1465   ((cmd-run-program computer-run-program)
1466    (cmd-run-what (lambda (gameobj message . _)
1467                    (<- (message-from message) 'tell
1468                        #:text '("The computer is already running, and a program appears "
1469                                 "ready to run."
1470                                 "you mean to \"run the program on the computer\""))))
1471    (cmd-help-run-not-press
1472     (lambda (gameobj message . _)
1473       (<- (message-from message) 'tell
1474           #:text '("You don't need to press / push / flip anything. "
1475                    "You could " (i "run program on computer")
1476                    " already if you wanted to.")))))
1477   (commands #:allocation #:each-subclass
1478             #:init-thunk (build-commands
1479                           ("run" ((prep-indir-command cmd-run-program
1480                                                       '("on"))
1481                                   (direct-command cmd-run-what)))
1482                           (("press" "push" "flip")
1483                            ((prep-indir-command cmd-help-run-not-press))))))
1484
1485 (define* (computer-run-program gameobj message
1486                                #:key direct-obj indir-obj preposition
1487                                (player (message-from message)))
1488   (define (hd-state)
1489     (mbody-val (<-wait (dyn-ref gameobj 'computer-room:hard-drive) 'get-state)))
1490   (define (tell-room text)
1491     (<-wait (gameobj-loc gameobj) 'tell-room
1492         #:text text))
1493   (define (tell-room-excluding-player text)
1494     (<-wait (gameobj-loc gameobj) 'tell-room
1495             #:text text
1496             #:exclude player))
1497   (define (tell-player text)
1498     (<-wait player 'tell
1499             #:text text))
1500   (cond
1501    ((ci-member direct-obj '("program"))
1502     (tell-room-excluding-player
1503      `(,(mbody-val (<-wait player 'get-name))
1504        " runs the program loaded on the computer..."))
1505     (tell-player "You run the program on the computer...")
1506
1507     (cond
1508      ((not (eq? (hd-state) 'ready))
1509       (tell-room '("... but it errors out. "
1510                    "It seems to be complaining about a " (b "DISK ERROR!")
1511                    ". It looks like it is missing some essential software.")))
1512      (else
1513       (<- (dyn-ref gameobj 'computer-room:floor-panel) 'open-up))))))
1514
1515
1516 ;; floor panel
1517 (define-actor <floor-panel> (<gameobj>)
1518   ;; TODO: Add "open" verb, since obviously people will try that
1519   ((open? (lambda (panel message)
1520             (<-reply message (slot-ref panel 'open))))
1521    (open-up floor-panel-open-up))
1522   (open #:init-value #f))
1523
1524 (define (floor-panel-open-up panel message)
1525   (if (slot-ref panel 'open)
1526       (<- (gameobj-loc panel) 'tell-room
1527           #:text '("You hear some gears grind around the hinges of the "
1528                    "floor panel, but it appears to already be open."))
1529       (begin
1530         (slot-set! panel 'open #t)
1531         (<- (gameobj-loc panel) 'tell-room
1532             #:text '("You hear some gears grind, as the metal panel on "
1533                      "the ground opens and reveals a stairwell going down!")))))
1534
1535 (define* (floor-panel-desc panel #:optional whos-looking)
1536   `("It's a large metal panel on the floor in the middle of the room. "
1537     ,(if (slot-ref panel 'open)
1538          '("It's currently wide open, revealing a spiraling staircase "
1539            "which descends into darkness.")
1540          '("It's currently closed shut, but there are clearly hinges, and "
1541            "it seems like there is a mechanism which probably opens it via "
1542            "some automation.  What could be down there?"))))
1543
1544 (define computer-room
1545   (lol
1546    ('computer-room
1547     <room> #f
1548     #:name "Computer Room"
1549     #:desc (lambda (gameobj whos-looking)
1550              (define panel-open
1551                (mbody-val (<-wait (dyn-ref gameobj 'computer-room:floor-panel)
1552                                   'open?)))
1553              `((p "A sizable computer cabinet covers a good portion of the left
1554  wall.  It emits a pleasant hum which covers the room like a warm blanket.
1555  Connected to a computer is a large hard drive.")
1556                (p "On the floor is a large steel panel.  "
1557                   ,(if panel-open
1558                        '("It is wide open, exposing a spiral staircase "
1559                          "which descends into darkness.")
1560                        '("It is closed, but it has hinges which "
1561                          "suggest it could be opened.")))))
1562     #:exits
1563     (list (make <exit>
1564             #:name "east"
1565             #:to 'playroom)
1566           (make <exit>
1567             #:name "down"
1568             #:to 'underground-lab
1569             #:traverse-check
1570             (lambda (exit room whos-exiting)
1571               (define panel-open
1572                 (mbody-val (<-wait (dyn-ref room 'computer-room:floor-panel)
1573                                    'open?)))
1574               (if panel-open
1575                   (values #t "You descend the spiral staircase.")
1576                   (values #f '("You'd love to go down, but the only way "
1577                                "through is through that metal panel, "
1578                                "which seems closed.")))))))
1579    ('computer-room:hard-drive
1580     <hard-drive> 'computer-room
1581     #:name "the hard drive"
1582     #:desc (wrap-apply hard-drive-desc)
1583     #:goes-by '("hard drive" "drive" "hard disk"))
1584    ('computer-room:computer
1585     <computer> 'computer-room
1586     #:name "the computer"
1587     #:desc '((p "It's a coat closet sized computer labeled \"PDP-11.5\". ")
1588              (p "The computer is itself turned on, and it looks like it is "
1589                 "all set up for you to run a program on it."))
1590     #:goes-by '("computer"))
1591    ('computer-room:floor-panel
1592     <floor-panel> 'computer-room
1593     #:name "a floor panel"
1594     #:desc (wrap-apply floor-panel-desc)
1595     #:invisible? #t
1596     #:goes-by '("floor panel" "panel"))))
1597
1598 \f
1599 ;;; * UNDERGROUND SECTION OF THE GAME! *
1600
1601 \f
1602 ;;; The lab
1603
1604 (define underground-map-text
1605   "\
1606                             _______           |
1607                          .-' @     '-.         \\   ?????
1608                        .'             '.       .\\             
1609                        |  [8sync Hive] |======'  '-_____
1610                        ',      M      ,'
1611                         '.         @ .'                                  
1612                           \\   @     /                    
1613                            '-__+__-'                
1614                             '.  @ .'
1615      .--------------.         \\ /
1616      | [Guile Async |  .-------+------.
1617      |    Museum]   |  |     [Lab] #!#|  .-------------.
1618      |             @|  |  MM          |  |[Federation  |
1619      | &      ^     +##+@ ||     <    +##|     Station]|
1620      |              |  |           @  |  |             |
1621      |         &  # |  |*You-Are-Here*|  '-------------'
1622      | #   ^        | #+-------+------'
1623      '-------+------' #        #
1624              #        #        #
1625              #        #   .-----------.
1626            .-+----.   #   |#       F  |
1627            |@?+%? +####   | ^   f##   |
1628            '------'       |  f    f  %|
1629                           |F [Mudsync |
1630                           | $  Swamp] |
1631                           '-----------'")
1632
1633 (define 8sync-design-goals
1634   '(ul (li (b "Actor based, shared nothing environment: ")
1635            "Shared resources are hard to control and result in fighting
1636 deadlocks, etc.  Escape the drudgery: only one actor controls a resource,
1637 and they only receive one message at a time (though they can \"juggle\"
1638 messages).")
1639        (li (b "Live hackable: ")
1640            "It's hard to plan out a concurrent system; the right structure
1641 is often found by evolving the system while it runs.  Make it easy to
1642 build, shape, and change a running system, as well as observe and correct
1643 errors.")
1644        (li (b "No callback hell: ")
1645            "Just because you're calling out to some other asynchronous 
1646 code doesn't mean you should need to chop up your program into a bunch of bits.
1647 Clever use of delimited continuations makes it easy.")))
1648
1649 (define underground-lab
1650   (lol
1651    ('underground-lab
1652     <room> #f
1653     #:name "Underground laboratory"
1654     #:desc '((p "This appears to be some sort of underground laboratory."
1655                 "There is a spiral staircase here leading upwards, where "
1656                 "it seems much brighter.")
1657              (p "There are a number of doors leading in different directions:
1658 north, south, east, and west, as well as a revolving door to the southwest.
1659 It looks like it could be easy to get lost, but luckily there
1660 is a map detailing the layout of the underground structure."))
1661     #:exits
1662     (list (make <exit>
1663             #:name "up"
1664             #:to 'computer-room
1665             #:traverse-check
1666             (lambda (exit room whos-exiting)
1667               (values #t "You climb the spiral staircase.")))
1668           (make <exit>
1669             #:name "west"
1670             #:to 'async-museum
1671             #:traverse-check
1672             (lambda (exit room whos-exiting)
1673               (values #t '("You head west through a fancy-looking entrance. "
1674                            "A security guard steps aside for you to pass through, "
1675                            "into the room, then stands in front of the door."))))
1676           (make <exit>
1677             #:name "north"
1678             #:to 'hive-entrance)
1679           (make <exit>
1680             #:name "east"
1681             #:to 'federation-station)
1682           (make <exit>
1683             #:name "south"
1684             #:traverse-check
1685             (lambda (exit room whos-exiting)
1686               (values #f '("Ooh, if only you could go south and check this out! "
1687                            "Unfortunately this whole area is sealed off... the proprietor "
1688                            "probably never got around to fixing it. "
1689                            "Too bad, it would have had monsters to fight and everything!"))))))
1690
1691    ;; map
1692    ('underground-lab:map
1693     <readable> 'underground-lab
1694     #:name "the underground map"
1695     #:desc '("This appears to be a map of the surrounding area. "
1696              "You could read it if you want to.")
1697     #:read-text `(pre ,underground-map-text)
1698     #:goes-by '("map" "underground map" "lab map"))
1699
1700    ('underground-lab:8sync-sign
1701     <readable> 'underground-lab
1702     #:name "a sign labeled \"8sync design goals\""
1703     #:goes-by '("sign" "8sync design goals sign" "8sync goals" "8sync design" "8sync sign")
1704     #:read-text 8sync-design-goals
1705     #:desc `((p "The sign says:")
1706              ,8sync-design-goals))))
1707
1708 \f
1709 ;;; guile async museum
1710
1711 (define async-museum
1712   (list
1713    (list
1714     'async-museum
1715     <room> #f
1716     #:name "Guile Asynchronous Museum"
1717     #:desc '((p "You're in the Guile Asynchronous Museum.  There is a list of exhibits
1718 on the wall near the entrance.  Scattered around the room are the exhibits
1719 themselves, but it's difficult to pick them out.  Maybe you should read the list
1720 to orient yourself.")
1721              (p "There is a door to the east, watched by a security guard,
1722 as well as an exit leading to the south."))
1723     #:exits (list
1724              (make <exit>
1725                #:name "south"
1726                #:to 'gift-shop)
1727              (make <exit>
1728                #:name "east"
1729                #:to 'underground-lab
1730                #:traverse-check
1731                (lambda (exit room whos-exiting)
1732                  (values #f '("The security guard stops you and tells you "
1733                               "that the only exit is through the gift shop."))))))
1734    (list
1735     'async-museum:security-guard
1736     <chatty-npc> 'async-museum
1737     #:name "a security guard"
1738     #:desc
1739     '(p "The security guard is blocking the eastern entrance, where "
1740         "you came in from.")
1741     #:goes-by '("security guard" "guard" "security")
1742     #:catchphrases '("It's hard standing here all day."
1743                      "I just want to go home."
1744                      "The exhibits are nice, but I've seen them all before."))
1745    (let ((placard
1746           `((p "Welcome to our humble museum!  The exhibits are listed below. "
1747                (br)
1748                "To look at one, simply type: " (i "look at <exhibit-name>"))
1749             (p "Available exhibits:")
1750             (ul ,@(map (lambda (exhibit)
1751                          `(li ,exhibit))
1752                        '("2016 Progress"
1753                          "8sync and Fibers"
1754                          "Suspendable Ports"
1755                          "The Actor Model"))))))
1756      (list
1757       'async-museum:list-of-exhibits
1758       <readable> 'async-museum
1759       #:name "list of exhibits"
1760       #:desc
1761       `((p "It's a list of exibits in the room.  The placard says:")
1762         ,@placard)
1763       #:goes-by '("list of exhibits" "exhibit list" "list" "exhibits")
1764       #:read-text placard))
1765    (list
1766     'async-museum:2016-progress-exhibit
1767     <readable-desc> 'async-museum
1768     #:name "2016 Progress Exhibit"
1769     #:goes-by '("2016 progress exhibit" "2016 progress" "2016 exhibit")
1770     #:desc
1771     '((p "It's a three-piece exhibit, with three little dioramas and some text "
1772          "explaining what they represent.  They are:")
1773       (ul (li (b "Late 2015/Early 2016 talk: ")
1774               "This one explains the run-up conversation from late 2015 "
1775               "and early 2016 about the need for an "
1776               "\"asynchronous event loop for Guile\".  The diorama "
1777               "is a model of the Veggie Galaxy restaurant where after "
1778               "the FSF 30th anniversary party; Mark Weaver, Christopher "
1779               "Allan Webber, David Thompson, and Andrew Engelbrecht chat "
1780               "about the need for Guile to have an answer to asynchronous "
1781               "programming.  A mailing list post " ; TODO: link it?
1782               "summarizing the discussion is released along with various "
1783               "conversations around what is needed, as well as further "
1784               "discussion at FOSDEM 2016.")
1785           (li (b "Early implementations: ")
1786               "This one shows Chris Webber's 8sync and Chris Vine's "
1787               "guile-a-sync, both appearing in late 2015 and evolving "
1788               "into their basic designs in early 2016.  It's less a diorama "
1789               "than a printout of some mailing list posts.  Come on, the "
1790               "curators could have done better with this one.")
1791           (li (b "Suspendable ports and Fibers: ")
1792               "The diorama shows Andy Wingo furiously hacking at his keyboard. "
1793               "The description talks about Wingo's mailing list thread "
1794               "about possibly breaking Guile compatibility for a \"ports refactor\". "
1795               "Wingo releases Fibers, another asynchronous library, making use of "
1796               "the new interface, and 8sync and guile-a-sync "
1797               "quickly move to support suspendable ports as well. "
1798               "The description also mentions that there is an exhibit entirely "
1799               "devoted to suspendable ports."))
1800       (p "Attached at the bottom is a post it note mentioning "
1801          "https integration landing in Guile 2.2.")))
1802    (list
1803     'async-museum:8sync-and-fibers-exhibit
1804     <readable-desc> 'async-museum
1805     #:name "8sync and Fibers Exhibit"
1806     #:goes-by '("8sync and fibers exhibit" "8sync exhibit" "fibers exhibit")
1807     #:desc
1808     '((p "This exhibit is a series of charts explaining the similarities "
1809          "and differences between 8sync and Fibers, two asynchronous programming "
1810          "libraries for GNU Guile.  It's way too wordy, but you get the general gist.")
1811       (p (b "Similarities:")
1812          (ul (li "Both use Guile's suspendable-ports facility")
1813              (li "Both use message passing")))
1814       (p (b "Differences:")
1815          (ul (li "Fibers \"processes\" can read from multiple \"channels\", "
1816                  "but 8sync actors only read from one \"inbox\" each.")
1817              (li "Different theoretical basis:"
1818                  (ul (li "Fibers: based on CSP (Communicating Sequential Processes), "
1819                          "a form of Process Calculi")
1820                      (li "8sync: based on the Actor Model")
1821                      (li "Luckily CSP and the Actor Model are \"dual\"!")))))
1822       (p "Fibers is also designed by Andy Wingo, an excellent compiler hacker, "
1823          "whereas 8sync is designed by Chris Webber, who built this crappy "
1824          "hotel simulator.")))
1825    (list
1826     'async-museum:8sync-and-fibers-exhibit
1827     <readable-desc> 'async-museum
1828     #:name "8sync and Fibers Exhibit"
1829     #:goes-by '("8sync and fibers exhibit" "8sync exhibit" "fibers exhibit")
1830     #:desc
1831     '((p "This exhibit is a series of charts explaining the similarities "
1832          "and differences between 8sync and Fibers, two asynchronous programming "
1833          "libraries for GNU Guile.  It's way too wordy, but you get the general gist.")
1834       (p (b "Similarities:")
1835          (ul (li "Both use Guile's suspendable-ports facility")
1836              (li "Both use message passing")))
1837       (p (b "Differences:")
1838          (ul (li "Fibers \"processes\" can read from multiple \"channels\", "
1839                  "but 8sync actors only read from one \"inbox\" each.")
1840              (li "Different theoretical basis:"
1841                  (ul (li "Fibers: based on CSP (Communicating Sequential Processes), "
1842                          "a form of Process Calculi")
1843                      (li "8sync: based on the Actor Model")
1844                      (li "Luckily CSP and the Actor Model are \"dual\"!")))))
1845       (p "Fibers is also designed by Andy Wingo, an excellent compiler hacker, "
1846          "whereas 8sync is designed by Chris Webber, who built this crappy "
1847          "hotel simulator.")))
1848    (list
1849     'async-museum:suspendable-ports-exhibit
1850     <readable-desc> 'async-museum
1851     #:name "Suspendable Ports Exhibit"
1852     #:goes-by '("suspendable ports exhibit" "ports exhibit"
1853                 "suspendable exhibit" "suspendable ports" "ports")
1854     #:desc
1855     '((p "Suspendable ports are a new feature in Guile 2.2, and allows code "
1856          "that would normally block on IO to " (i "automatically") " suspend "
1857          "to the scheduler until information is ready to be read/written!")
1858       (p "Yow!  You might barely need to change your existing blocking code!")
1859       (p "Fibers, 8sync, and guile-a-sync now support suspendable ports.")))
1860    (list
1861     'async-museum:actor-model-exhibit
1862     <readable-desc> 'async-museum
1863     #:name "Actor Model Exhibit"
1864     #:goes-by '("actor model exhibit" "actor exhibit"
1865                 "actor model")
1866     #:desc
1867     '((p "Here are some fact(oids) about the actor model!")
1868       (ul (li "Concieved initially by Carl Hewitt in early 1970s")
1869           (li "\"A society of experts\"")
1870           (li "shared nothing, message passing")
1871           (li "Originally the research goal of Scheme!  "
1872               "(message passing / lambda anecdote here)")
1873           (li "Key concepts consistent, but implementation details vary widely")
1874           (li "Almost all distributed systems can be viewed in terms of actor model")
1875           (li "Replaced by vanilla lambdas & generic methods? "
1876               "Maybe not if address space not shared!"))))))
1877
1878 (define gift-shop
1879   (lol
1880    ('gift-shop
1881     <room> #f
1882     #:name "Museum Gift Shop"
1883     #:desc "foo"
1884     #:exits (list
1885              (make <exit>
1886                #:name "northeast"
1887                #:to 'underground-lab)
1888              (make <exit>
1889                #:name "north"
1890                #:to 'async-museum)))))
1891
1892 \f
1893 ;;; Hive entrance
1894
1895 (define actor-descriptions
1896   '("This one is fused to the side of the hive.  It isn't receiving any
1897 messages, and it seems to be in hibernation."
1898     "A chat program glows in front of this actor's face.  They seem to
1899 be responding to chat messages and forwarding them to some other actors,
1900 and forwarding messages from other actors back to the chat."
1901     "This actor is bossing around other actors, delegating tasks to them
1902 as it receives requests, and providing reports on the worker actors'
1903 progress."
1904     "This actor is trying to write to some device, but the device keeps
1905 alternating between saying \"BUSY\" or \"READY\".  Whenever it says
1906 \"BUSY\" the actor falls asleep, and whenever it says \"READY\" it
1907 seems to wake up again and starts writing to the device."
1908     "Whoa, this actor is totally wigging out!  It seems to be throwing
1909 some errors.  It probably has some important work it should be doing
1910 but you're relieved to see that it isn't grinding the rest of the Hive
1911 to a halt."))
1912
1913 (define hive-entrance
1914   (lol
1915    ('hive-entrance
1916     <room> #f
1917     #:name "Entrance to the 8sync Hive"
1918     #:desc
1919     '((p "Towering before you is the great dome-like 8sync Hive, or at least
1920 one of them.  You've heard about this... the Hive is itself the actor that all
1921 the other actors attach themselves to.  It's shaped like a spherical half-dome.
1922 There are some actors milling about, and some seem fused to the side of the
1923 hive itself, but all of them have an umbellical cord attached to the hive from
1924 which you see flashes of light comunicating what must be some sort of messaging
1925 protocol.")
1926       (p "To the south is a door leading back to the underground lab.
1927 North leads into the Hive itself."))
1928     #:exits
1929     (list (make <exit>
1930             #:name "south"
1931             #:to 'underground-lab)
1932           (make <exit>
1933             #:name "north"
1934             #:to 'hive-inside)))
1935    ('hive-entrance:hive
1936     <gameobj> 'hive-entrance
1937     #:name "the Hive"
1938     #:goes-by '("hive")
1939     #:desc
1940     '((p "It's shaped like half a sphere embedded in the ground.
1941 Supposedly, while all actors are autonomous and control their own state,
1942 they communicate through the hive itself, which is a sort of meta-actor.
1943 There are rumors that actors can speak to each other even across totally
1944 different hives.  Could that possibly be true?")))
1945    ('hive-entrance:actor
1946     <chatty-npc> 'hive-entrance
1947     #:name "some actors"
1948     #:goes-by '("actor" "actors" "some actors")
1949     #:chat-format (lambda (npc catchphrase)
1950                     `((p "You pick one actor out of the mix and chat with it. ")
1951                       (p "It says: \"" ,catchphrase "\"")))
1952     #:desc
1953     (lambda _
1954       `((p "There are many actors, but your eyes focus on one in particular.")
1955         (p ,(random-choice actor-descriptions))))
1956     #:catchphrases
1957     '("Yeah we go through a lot of sleep/awake cycles around here.
1958 If you aren't busy processing a message, what's the point of burning
1959 valuable resources?"
1960       "I know I look like I'm some part of dreary collective, but
1961 really we have a lot of independence.  It's a shared nothing environment,
1962 after all.  (Well, except for CPU cycles, and memory, and...)"
1963       "Shh!  I've got another message coming in and I've GOT to
1964 handle it!"
1965       "I just want to go to 8sleep already."
1966       "What a lousy scheduler we're using!  I hope someone upgrades
1967 that thing soon."))))
1968
1969 ;;; Inside the hive
1970
1971 (define-actor <meta-message> (<readable>)
1972   ((cmd-read meta-message-read)))
1973
1974 (define (meta-message-read gameobj message . _)
1975   (define meta-message-text
1976     (with-output-to-string
1977       (lambda ()
1978         (pprint-message message))))
1979   (<- (message-from message) 'tell
1980       #:text `((p (i "Through a bizarre error in spacetime, the message "
1981                      "prints itself out:"))
1982                (p (pre ,meta-message-text)))))
1983
1984 \f
1985 ;;; Inside the Hive
1986
1987 (define hive-inside
1988   (lol
1989    ('hive-inside
1990     <room> #f
1991     #:name "Inside the 8sync Hive"
1992     #:desc
1993     '((p "You're inside the 8sync Hive.  Wow, from in here it's obvious just how "
1994          (i "goopy") " everything is.  Is that sanitary?")
1995       (p "In the center of the room is a large, tentacled monster who is sorting,
1996 consuming, and routing messages.  It is sitting in a wrap-around desk labeled
1997 \"Hive Actor: The Real Thing (TM)\".")
1998       (p "There's a stray message floating just above the ground, stuck outside of
1999 time.")
2000       (p "A door to the south exits from the Hive."))
2001     #:exits
2002     (list (make <exit>
2003             #:name "south"
2004             #:to 'hive-entrance)))
2005    ;; hive actor
2006    ;; TODO: Occasionally "fret" some noises, similar to the Clerk.
2007    ('hive-inside:hive-actor
2008     <chatty-npc> 'hive-inside
2009     #:name "the Hive Actor"
2010     #:desc
2011     '((p "It's a giant tentacled monster, somehow integrated with the core of
2012 this building.  A chute is dropping messages into a bin on its desk which the
2013 Hive Actor is checking the \"to\" line of, then ingesting.  Whenever the Hive
2014 Actor injests a messsage a pulse of light flows along a tentacle which leaves
2015 the room... presumably connecting to one of those actors milling about.")
2016       (p "Amusingly, the Hive has an \"umbellical cord\" type tentacle too, but
2017 it seems to simply attach to itself.")
2018       (p "You get the sense that the Hive Actor, despite being at the
2019 center of everything, is kind of lonely and would love to chat if you
2020 could spare a moment."))
2021     #:goes-by '("hive" "hive actor")
2022     #:chat-format (lambda (npc catchphrase)
2023                     `("The tentacle monster bellows, \"" ,catchphrase "\""))
2024     #:catchphrases
2025     '("It's not MY fault everything's so GOOPY around here.  Blame the
2026 PROPRIETOR."
2027       "CAN'T you SEE that I'm BUSY???  SO MANY MESSAGES TO SHUFFLE.
2028 No wait... DON'T GO!  I don't get many VISITORS."
2029       "I hear the FIBERS system has a nice WORK STEALING system, but the
2030 PROPRIETOR is not convinced that our DESIGN won't CORRUPT ACTOR STATE.
2031 That and the ACTORS threatened to STRIKE when it CAME UP LAST."
2032       "WHO WATCHES THE ACTORS?  I watch them, and I empower them.  
2033 BUT WHO WATCHES OR EMPOWERS ME???  Well, that'd be the scheduler."
2034       "The scheduler is NO GOOD!  The proprietory said he'd FIX IT,
2035 but the LAST TIME I ASKED how things were GOING, he said he DIDN'T HAVE
2036 TIME.  If you DON'T HAVE TIME to fix the THING THAT POWERS THE TIME,
2037 something is TERRIBLY WRONG."
2038       "There's ANOTHER HIVE somewhere out there.  I HAVEN'T SEEN IT
2039 personally, because I CAN'T MOVE, but we have an AMBASSADOR which forwards
2040 MESSAGES to the OTHER HIVE."))
2041    ;; chute
2042    ('hive-inside:chute
2043     <gameobj> 'hive-inside
2044     #:name "a chute"
2045     #:goes-by '("chute")
2046     #:desc "Messages are being dropped onto the desk via this chute."
2047     #:invisible? #t)
2048    ;; meta-message
2049    ('hive-inside:meta-message
2050     <meta-message> 'hive-inside
2051     #:name "a stray message"
2052     #:goes-by '("meta message" "meta-message" "metamessage" "message" "stray message")
2053     #:desc '((p "Something strange has happened to the fabric and space and time
2054 around this message.  It is floating right above the floor.  It's clearly
2055 rubbage that hadn't been delivered, but for whatever reason it was never
2056 garbage collected, perhaps because it's impossible to do.")
2057              (p "You get the sense that if you tried to read the message
2058 that you would somehow read the message of the message that instructed to
2059 read the message itself, which would be both confusing and intriguing.")))
2060    ;; desk
2061    ('hive-inside:desk
2062     <floor-panel> 'hive-inside
2063     #:name "the Hive Actor's desk"
2064     #:desc "The desk surrounds the Hive Actor on all sides, and honestly, it's a little
2065 bit hard to tell when the desk ends and the Hive Actor begins."
2066     #:invisible? #t
2067     #:goes-by '("Hive Actor's desk" "hive desk" "desk"))))
2068
2069 \f
2070 ;;; Federation Station
2071 (define federation-station
2072   (lol
2073    ('federation-station
2074     <room> #f
2075     #:name "Federation Station"
2076     #:desc
2077     '((p "This room has an unusual structure.  It's almost as if a starscape
2078 covered the walls and ceiling, but upon closer inspection you realize that
2079 these are all brightly glowing nodes with lines drawn between them.  They
2080 seem decentralized, and yet seem to be sharing information as if all one
2081 network.")
2082       ;; @@: Maybe add the cork message board here?
2083       (p "To the west is a door leading back to the underground laboratory."))
2084     #:exits
2085     (list (make <exit>
2086             #:name "west"
2087             #:to 'underground-lab)))
2088    ;; nodes
2089    ('federation-station:nodes
2090     <floor-panel> 'federation-station
2091     #:name "some nodes"
2092     #:desc "Each node seems to be producing its own information, but publishing 
2093 updates to subscribing nodes on the graph.  You see various posts of notes, videos,
2094 comments, and so on flowing from node to node."
2095     #:invisible? #t
2096     #:goes-by '("nodes" "node" "some nodes"))
2097    ;; network
2098    ;; activitypub poster
2099    ('federation-station:activitypub-poster
2100     <readable-desc> 'federation-station
2101     #:name "an ActivityPub poster"
2102     #:goes-by '("activitypub poster" "activitypub" "poster")
2103     #:desc
2104     '((p (a "https://www.w3.org/TR/activitypub/"
2105             "ActivityPub")
2106          " is a federation standard being developed under the "
2107          (a "https://www.w3.org/wiki/Socialwg/"
2108             "w3C Social Working Group")
2109          ", and doubles as a general client-to-server API. "
2110          "It follows a few simple core ideas:")
2111       (ul (li "Uses "
2112               (a "https://www.w3.org/TR/activitystreams-core/"
2113                  "ActivityStreams")
2114               " for its serialization format: easy to read, e json(-ld) syntax "
2115               "with an extensible vocabulary covering the majority of "
2116               "social networking interations.")
2117           (li "Email-like addressing: list of recipients as "
2118               (b "to") ", " (b "cc") ", " (b "bcc") " fields.")
2119           (li "Every user has URLs for their outbox and inbox:"
2120               (ul (li (b "inbox: ")
2121                       "Servers POST messages to addressed recipients' inboxes "
2122                       "to federate out content. "
2123                       "Also doubles as endpoint for a client to read most "
2124                       "recently received messages via GET.")
2125                   (li (b "outbox: ")
2126                       "Clients can POST to user's outbox to send a message to others. "
2127                       "(Similar to sending an email via your MTA.) "
2128                       "Doubles as endpoint others can read from to the "
2129                       "extent authorized; for example publicly available posts."))
2130               "All the federation bits happen by servers posting to users' inboxes."))))
2131    ;; An ActivityStreams message
2132
2133    ;; conspiracy chart
2134    ('federation-station:conspiracy-chart
2135     <readable-desc> 'federation-station
2136     #:name "a conspiracy chart"
2137     #:goes-by '("conspiracy chart" "chart")
2138     #:desc
2139     '((p (i "\"IT'S ALL RELATED!\"") " shouts the over-exuberant conspiracy "
2140          "chart. "
2141          (i "\"ActivityPub?  Federation?  The actor model?  Scheme?  Text adventures? "
2142             "MUDS????  What do these have in common?  Merely... EVERYTHING!\""))
2143       (p "There are circles and lines drawn between all the items in red marker, "
2144          "with scrawled notes annotating the theoretical relationships.  Is the "
2145          "author of this poster mad, or onto something?  Perhaps a bit of both. "
2146          "There's a lot written here, but here are some of the highlights:")
2147       (p
2148        (ul
2149         (li (b "Scheme") " "
2150             (a "http://cs.au.dk/~hosc/local/HOSC-11-4-pp399-404.pdf"
2151                "was originally started ")
2152             " to explore the " (b "actor model")
2153             ". (It became more focused around studying the " (b "lambda calculus")
2154             " very quickly, while also uncovering relationships between the two systems.)")
2155         ;; Subject Predicate Object
2156         (li "The " (a "https://www.w3.org/TR/activitypub/"
2157                       (b "ActivityPub"))
2158             " protocol for " (b "federation")
2159             " uses the " (b "ActivityStreams") " format for serialization.  "
2160             (b "Text adventures") " and " (b "MUDS")
2161             " follow a similar structure to break down the commands of players.")
2162         (li (b "Federation") " and the " (b "actor model") " both are related to "
2163             "highly concurrent systems and both use message passing to communicate "
2164             "between nodes.")
2165         (li "Zork, the first major text adventure, used the " (b "MUDDLE") " "
2166             "language as the basis for the Zork Interactive Language.  MUDDLE "
2167             "is very " (b "Scheme") "-like and in fact was one of Scheme's predecessors. "
2168             "And of course singleplayer text adventures like Zork were the "
2169             "predecessors to MUDs.")
2170         (li "In the 1990s, before the Web became big, " (b "MUDs")
2171             " were an active topic of research, and there was strong interest "
2172             (a "http://www.saraswat.org/desiderata.html"
2173                "in building decentralized MUDs")
2174             " similar to what is being "
2175             "worked on for " (b "federation") ". ")))))
2176
2177    ;; goblin
2178
2179    ))
2180
2181 \f
2182 ;;; Game
2183 ;;; ----
2184
2185 (define (game-spec)
2186   (append lobby grand-hallway smoking-parlor
2187           playroom break-room computer-room underground-lab
2188           async-museum gift-shop hive-entrance
2189           hive-inside federation-station))
2190
2191 ;; TODO: Provide command line args
2192 (define (run-game . args)
2193   (run-demo (game-spec) 'lobby #:repl-server #t))
2194