bd953aa6d6a17d4cf8e447d6bbb16e71ddd19b2b
[mudsync.git] / worlds / bricabrac.scm
1 ;;; Mudsync --- Live hackable MUD
2 ;;; Copyright © 2016 Christopher Allan Webber <cwebber@dustycloud.org>
3 ;;;
4 ;;; This file is part of Mudsync.
5 ;;;
6 ;;; Mudsync is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or
9 ;;; (at your option) any later version.
10 ;;;
11 ;;; Mudsync is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 ;;; General Public License for more details.
15 ;;;
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with Mudsync.  If not, see <http://www.gnu.org/licenses/>.
18
19 ;;; Hotel Bricabrac
20
21 (use-modules (mudsync)
22              (mudsync 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 (string-append (slot-ref actor 'read-text) "\n")))
62
63
64 ;; This one allows you to take from items that are proxied by it
65 (define-actor <proxy-items> (<gameobj>)
66   ((cmd-take-from take-from-proxy))
67   (proxy-items #:init-keyword #:proxy-items))
68
69 (define* (take-from-proxy gameobj message
70                           #:key direct-obj indir-obj preposition
71                           (player (message-from message)))
72   (call/ec
73    (lambda (escape)
74      (for-each
75       (lambda (obj-sym)
76         (define obj-id (dyn-ref gameobj obj-sym))
77         (define goes-by
78           (mbody-val (<-wait obj-id 'goes-by)))
79         (when (ci-member direct-obj goes-by)
80           (<- obj-id 'cmd-take #:direct-obj direct-obj #:player player)
81           (escape #f)))
82       (slot-ref gameobj 'proxy-items))
83
84      (<- player 'tell
85         #:text `("You don't see any such " ,direct-obj " to take "
86                  ,preposition " " ,(slot-ref gameobj 'name) ".")))))
87
88
89 \f
90 ;;; Lobby
91 ;;; -----
92
93 (define (npc-chat-randomly actor message . _)
94   (define text-to-send
95     (format #f "~a says: \"~a\"\n"
96             (slot-ref actor 'name)
97             (random-choice (slot-ref actor 'catchphrases))))
98   (<- (message-from message) 'tell
99       #:text text-to-send))
100
101 (define hotel-owner-grumps
102   '("Eight sinks!  Eight sinks!  And I couldn't unwind them..."
103     "Don't mind the mess.  I built this place on a dare, you
104 know?"
105     "(*tearfully*) Here, take this parenthesis.  May it serve
106 you well."
107     "I gotta get back to the goblin farm soon..."
108     "Oh, but I was going to make a mansion... a great,
109 beautiful mansion!  Full of ghosts!  Now all I have is this cruddy
110 mo... hotel.  Oh... If only I had more time!"
111     "I told them to paint more of the walls purple.
112 Why didn't they listen?"
113     "Listen to that overhead muzak.  Whoever made that doesn't
114 know how to compose very well!  Have you heard of the bands 'fmt'
115 or 'skribe'?  Now *that's* composition!"))
116
117 (define-class <chatty-npc> (<gameobj>)
118   (catchphrases #:init-value '("Blarga blarga blarga!")
119                 #:init-keyword #:catchphrases)
120   (commands
121    #:allocation #:each-subclass
122    #:init-thunk (build-commands
123                  (("chat" "talk") ((direct-command cmd-chat)))))
124   (actions #:allocation #:each-subclass
125            #:init-thunk
126            (build-actions
127             (cmd-chat npc-chat-randomly))))
128
129 (define-class <sign-in-form> (<gameobj>)
130   (commands
131    #:allocation #:each-subclass
132    #:init-thunk (build-commands
133                  ("sign" ((prep-direct-command cmd-sign-form '("as"))))))
134
135   (actions #:allocation #:each-subclass
136            #:init-thunk (build-actions
137                          (cmd-sign-form sign-cmd-sign-in))))
138
139
140 (define name-sre
141   (sre->irregex '(: alpha (** 1 14 (or alphanum "-" "_")))))
142
143 (define forbidden-words
144   (append article preposition
145           '("and" "or" "but" "admin")))
146
147 (define (valid-name? name)
148   (and (irregex-match name-sre name)
149        (not (member name forbidden-words))))
150
151 (define* (sign-cmd-sign-in actor message
152                            #:key direct-obj indir-obj preposition)
153   (define old-name
154     (mbody-val (<-wait (message-from message) 'get-name)))
155   (define name indir-obj)
156   (if (valid-name? indir-obj)
157       (begin
158         (<-wait (message-from message) 'set-name! name)
159         (<- (slot-ref actor 'loc) 'tell-room
160             #:text (format #f "~a signs the form!\n~a is now known as ~a\n"
161                            old-name old-name name)))
162       (<- (message-from message) 'tell
163           #:text "Sorry, that's not a valid name.
164 Alphanumerics, _ and - only, 2-15 characters, starts with an alphabetic
165 character.\n")))
166
167
168 (define-class <summoning-bell> (<gameobj>)
169   (summons #:init-keyword #:summons)
170
171   (commands
172    #:allocation #:each-subclass
173    #:init-thunk (build-commands
174                  ("ring" ((direct-command cmd-ring)))))
175   (actions #:allocation #:each-subclass
176            #:init-thunk (build-actions
177                          (cmd-ring summoning-bell-cmd-ring))))
178
179 (define* (summoning-bell-cmd-ring bell message . _)
180   ;; Call back to actor who invoked this message handler
181   ;; and find out their name.  We'll call *their* get-name message
182   ;; handler... meanwhile, this procedure suspends until we get
183   ;; their response.
184   (define who-rang
185     (mbody-val (<-wait (message-from message) 'get-name)))
186
187   ;; Now we'll invoke the "tell" message handler on the player
188   ;; who rang us, displaying this text on their screen.
189   ;; This one just uses <- instead of <-wait, since we don't
190   ;; care when it's delivered; we're not following up on it.
191   (<- (message-from message) 'tell
192       #:text "*ring ring!*  You ring the bell!\n")
193   ;; We also want everyone else in the room to "hear" the bell,
194   ;; but they get a different message since they aren't the ones
195   ;; ringing it.  Notice here's where we make use of the invoker's
196   ;; name as extracted and assigned to the who-rang variable.
197   ;; Notice how we send this message to our "location", which
198   ;; forwards it to the rest of the occupants in the room.
199   (<- (gameobj-loc bell) 'tell-room
200       #:text
201       (format #f "*ring ring!*  ~a rings the bell!\n"
202               who-rang)
203       #:exclude (message-from message))
204   ;; Now we perform the primary task of the bell, which is to summon
205   ;; the "clerk" character to the room.  (This is configurable,
206   ;; so we dynamically look up their address.)
207   (<- (dyn-ref bell (slot-ref bell 'summons)) 'be-summoned
208       #:who-summoned (message-from message)))
209
210
211 (define prefect-quotes
212   '("I'm a frood who really knows where my towel is!"
213     "On no account allow a Vogon to read poetry at you."
214     "Time is an illusion, lunchtime doubly so!"
215     "How can you have money if none of you produces anything?"
216     "On no account allow Arthur to request tea on this ship."))
217
218 (define-class <cabinet-item> (<gameobj>)
219   (take-me? #:init-value
220             (lambda _
221               (values #f #:why-not
222                       `("Hm, well... the cabinet is locked and the properitor "
223                         "is right over there.")))))
224
225 (define lobby
226   (lol
227    ('lobby
228     <room> #f
229     #:name "Hotel Lobby"
230     #:desc
231     '((p "You're in some sort of hotel lobby.  You see a large sign hanging "
232          "over the desk that says \"Hotel Bricabrac\".  On the desk is a bell "
233          "that says \"'ring bell' for service\".  Terrible music plays from a speaker "
234          "somewhere overhead.  "
235          "The room is lined with various curio cabinets, filled with all sorts "
236          "of kitschy junk.  It looks like whoever decorated this place had great "
237          "ambitions, but actually assembled it all in a hurry and used whatever "
238          "kind of objects they found lying around.")
239       (p "There's a door to the north leading to some kind of hallway."))
240     #:exits
241     (list (make <exit>
242             #:name "north"
243             #:to 'grand-hallway)))
244    ;; NPC: hotel owner
245    ('lobby:hotel-owner
246     <chatty-npc> 'lobby
247     #:name "a frumpy fellow"
248     #:desc
249     '((p "  Whoever this is, they looks totally exhausted.  They're
250 collapsed into the only comfortable looking chair in the room and you
251 don't get the sense that they're likely to move any time soon.
252   You notice they're wearing a sticker badly adhesed to their clothing
253 which says \"Hotel Proprietor\", but they look so disorganized that you
254 think that can't possibly be true... can it?
255   Despite their exhaustion, you sense they'd be happy to chat with you,
256 though the conversation may be a bit one sided."))
257     #:goes-by '("frumpy fellow" "fellow"
258                 "Chris Webber"  ; heh, did you rtfc?  or was it so obvious?
259                 "hotel proprietor" "proprietor")
260     #:catchphrases hotel-owner-grumps)
261    ;; Object: Sign
262    ('lobby:sign
263     <readable> 'lobby
264     #:name "the Hotel Bricabrac sign"
265     #:desc "  It strikes you that there's something funny going on with this sign.
266 Sure enough, if you look at it hard enough, you can tell that someone
267 hastily painted over an existing sign and changed the \"M\" to an \"H\".
268 Classy!"
269     #:read-text "  All it says is \"Hotel Bricabrac\" in smudged, hasty text."
270     #:goes-by '("sign"
271                 "bricabrac sign"
272                 "hotel sign"
273                 "hotel bricabrac sign"
274                 "lobby sign"))
275
276    ('lobby:bell
277     <summoning-bell> 'lobby
278     #:name "a shiny brass bell"
279     #:goes-by '("shiny brass bell" "shiny bell" "brass bell" "bell")
280     #:desc "  A shiny brass bell.  Inscribed on its wooden base is the text
281 \"ring me for service\".  You probably could \"ring the bell\" if you 
282 wanted to."
283     #:summons 'break-room:desk-clerk)
284
285    ('lobby:sign-in-form
286     <sign-in-form> 'lobby
287     #:name "sign-in form"
288     #:goes-by '("sign-in form" "form" "signin form")
289     #:desc "It looks like you could sign this form and set your name.")
290
291    ;; Object: curio cabinets
292    ;; TODO: respond to attempts to open the curio cabinet
293    ('lobby:cabinet
294     <proxy-items> 'lobby
295     #:proxy-items '(lobby:porcelain-doll
296                     lobby:1950s-robots
297                     lobby:tea-set lobby:mustard-pot
298                     lobby:head-of-elvis lobby:circuitboard-of-evlis
299                     lobby:teletype-scroll lobby:orange-cat-phone)
300     #:name "a curio cabinet"
301     #:goes-by '("curio cabinet" "cabinet" "bricabrac cabinet"
302                 "cabinet of curiosities")
303     #:desc (lambda _
304              (format #f "  The curio cabinet is full of all sorts of oddities!
305 Something catches your eye!
306 Ooh, ~a!" (random-choice
307            '("a creepy porcelain doll"
308              "assorted 1950s robots"
309              "an exquisite tea set"
310              "an antique mustard pot"
311              "the pickled head of Elvis"
312              "the pickled circuitboard of EVLIS"
313              "a scroll of teletype paper holding the software Four Freedoms"
314              "a telephone shaped like an orange cartoon cat")))))
315
316    ('lobby:porcelain-doll
317     <cabinet-item> 'lobby
318     #:invisible? #t
319     #:name "a creepy porcelain doll"
320     #:desc "It strikes you that while the doll is technically well crafted,
321 it's also the stuff of nightmares."
322     #:goes-by '("porcelain doll" "doll"))
323    ('lobby:1950s-robots
324     <cabinet-item> 'lobby
325     #:invisible? #t
326     #:name "a set of 1950s robots"
327     #:desc "There's a whole set of these 1950s style robots.
328 They seem to be stamped out of tin, and have various decorations of levers
329 and buttons and springs.  Some of them have wind-up knobs on them."
330     #:goes-by '("robot" "robots" "1950s robot" "1950s robots"))
331    ('lobby:tea-set
332     <cabinet-item> 'lobby
333     #:invisible? #t
334     #:name "a tea set"
335     #:desc "A complete tea set.  Some of the cups are chipped.
336 You can imagine yourself joining a tea party using this set, around a
337 nice table with some doilies, drinking some Earl Grey tea, hot.  Mmmm."
338     #:goes-by '("tea set" "tea"))
339    ('lobby:mustard-pot
340     <cabinet-item> 'lobby
341     #:invisible? #t
342     #:name "a mustard pot"
343     #:desc '((p "It's a mustard pot.  I mean, it's kind of cool, it has a
344 nice design, and it's an antique, but you can't imagine putting something
345 like this in a museum.")
346              (p "Ha... imagine that... a mustard museum."))
347     #:goes-by '("mustard pot" "antique mustard pot" "mustard"))
348    ('lobby:head-of-elvis
349     <cabinet-item> 'lobby
350     #:invisible? #t
351     #:name "the pickled head of Elvis"
352     #:desc '((p "It's a jar full of some briny-looking liquid and...
353 a free floating head.  The head looks an awful lot like Elvis, and
354 definitely not the younger Elvis.  The hair even somehow maintains
355 that signature swoop while suspended in liquid.  But of course it's
356 not Elvis.")
357              (p "Oh, wait, it has a label at the bottom which says:
358 \"This is really the head of Elvis\".  Well... maybe don't believe
359 everything you read."))
360     #:goes-by '("pickled head of elvis" "pickled head of Elvis"
361                 "elvis" "Elvis" "head" "pickled head"))
362    ('lobby:circuitboard-of-evlis
363     <cabinet-item> 'lobby
364     #:invisible? #t
365     #:name "the pickled circuitboard of Evlis"
366     #:desc '((p "It's a circuitboard from a Lisp Machine called EVLIS.
367 This is quite the find, and you bet just about anyone interested in
368 preserving computer history would love to get their hands on this.")
369              (p "Unfortunately, whatever moron did acquire this has
370 no idea what it means to preserve computers, so here it is floating
371 in some kind of briny liquid.  It appears to be heavily corroded.
372 Too bad..."))
373     #:goes-by '("pickled circuitboard of evlis" "pickled circuitboard of Evlis"
374                 "pickled circuitboard of EVLIS"
375                 "evlis" "Evlis" "EVLIS" "circuitboard" "pickled circuitboard"))
376    ('lobby:teletype-scroll
377     <cabinet-item> 'lobby
378     #:invisible? #t
379     #:name "a scroll of teletype"
380     #:desc '((p "This is a scroll of teletype paper.  It's a bit old
381 and yellowed but the type is very legible.  It says:")
382              (br)
383              (i
384               (p (strong "== The four essential freedoms =="))
385               (p "A program is free software if the program's users have
386 the four essential freedoms: ")
387               (ul (li "The freedom to run the program as you wish, for any purpose (freedom 0).")
388                   (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.")
389                   (li "The freedom to redistribute copies so you can help your neighbor (freedom 2).")
390                   (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.")))
391              (p "You get this feeling that ambiguities in the
392 English language surrounding the word 'free' have lead to a lot of terminology debates."))
393     #:goes-by '("scroll of teletype" "scroll of teletype paper" "teletype scroll"
394                 "teletype paper" "scroll" "four freedoms"
395                 "scroll of teletype paper holding the software Four Freedoms"
396                 "scroll of teletype paper holding the software four freedoms"))
397    ('lobby:orange-cat-phone
398     <cabinet-item> 'lobby
399     #:invisible? #t
400     #:name "a telephone shaped like an orange cartoon cat"
401     #:desc "It's made out of a cheap plastic, and it's very orange.
402 It resembles a striped tabby, and it's eyes hold the emotion of
403 a being both sleepy and smarmy.
404 You suspect that someone, somewhere made a ton of cash on items holding
405 this general shape in the 1990s."
406     #:goes-by '("orange cartoon cat phone" "orange cartoon cat telephone"
407                 "orange cat phone" "orange cat telephone"
408                 "cartoon cat phone" "cartoon cat"
409                 "cat phone" "cat telephone" "phone" "telephone"))))
410
411
412 \f
413 ;;; Grand hallway
414 ;;; -------------
415
416 (define-actor <disc-shield> (<gameobj>)
417   ((cmd-take disc-shield-take)))
418
419 (define* (disc-shield-take gameobj message
420                            #:key direct-obj
421                            (player (message-from message)))
422   (create-gameobj <glowing-disc> (gameobj-gm gameobj)
423                   player)  ;; set loc to player to put in player's inventory
424   (<- player 'tell
425       #:text '((p "As you attempt to pull the shield / disk platter
426 from the statue a shining outline appears around it... and a
427 completely separate, glowing copy of the disc materializes into your
428 hands!")))
429   (<- (gameobj-loc gameobj) 'tell-room
430         #:text `(,(mbody-val (<-wait player 'get-name))
431                  " pulls on the shield of the statue, and a glowing "
432                  "copy of it materializes into their hands!")
433         #:exclude player)
434   (<- (gameobj-loc gameobj) 'tell-room
435       #:text
436       '(p "You hear a voice whisper: "
437           (i "\"Share the software... and you'll be free...\""))))
438
439 ;;; This is the disc that gets put in the player's inventory
440 (define-actor <glowing-disc> (<gameobj>)
441   ((cmd-drop glowing-disc-drop-cmd))
442   (initial-props
443    #:allocation #:each-subclass
444    #:init-thunk (build-props
445                  '((hd-platter? . #t))))
446   (name #:allocation #:each-subclass
447         #:init-value "a glowing disc")
448   (desc #:allocation #:each-subclass
449         #:init-value "A brightly glowing disc.  It's shaped like a hard
450 drive platter, not unlike the one from the statue it came from.  It's
451 labeled \"RL02.5\".")
452   (goes-by #:init-value '("glowing disc" "glowing platter"
453                           "glowing disc platter" "glowing disk platter"
454                           "platter" "disc" "disk" "glowing shield")))
455
456 (define* (glowing-disc-drop-cmd gameobj message
457                    #:key direct-obj
458                    (player (message-from message)))
459   (<- player 'tell
460       #:text "You drop the glowing disc, and it shatters into a million pieces!")
461   (<- (mbody-val (<-wait player 'get-loc)) 'tell-room
462       #:text `(,(mbody-val (<-wait player 'get-name))
463                " drops a glowing disc, and it shatters into a million pieces!")
464       #:exclude player)
465   (gameobj-self-destruct gameobj))
466
467 (define grand-hallway
468   (lol
469    ('grand-hallway
470     <room> #f
471     #:name "Grand Hallway"
472     #:desc '((p "  A majestic red carpet runs down the center of the room.
473 Busts of serious looking people line the walls, but there's no
474 clear indication that they have any logical relation to this place.")
475              (p "In the center is a large statue of a woman in a warrior's
476 pose, but something is strange about her weapon and shield.  You wonder what
477 that's all about?")
478              (p "To the south is the lobby.  A door to the east is labeled \"smoking
479 room\", while a door to the west is labeled \"playroom\"."))
480     #:exits
481     (list (make <exit>
482             #:name "south"
483             #:to 'lobby)
484           (make <exit>
485             #:name "west"
486             #:to 'playroom)
487           (make <exit>
488             #:name "east"
489             #:to 'smoking-parlor)))
490    ('grand-hallway:carpet
491     <gameobj> 'grand-hallway
492     #:name "the Grand Hallway carpet"
493     #:desc "It's very red, except in the places where it's very worn."
494     #:invisible? #t
495     #:goes-by '("red carpet" "carpet"))
496    ('grand-hallway:busts
497     <gameobj> 'grand-hallway
498     #:name "the busts of serious people"
499     #:desc "There are about 6 of them in total.  They look distinguished
500 but there's no indication of who they are."
501     #:invisible? #t
502     #:goes-by '("busts" "bust" "busts of serious people" "bust of serious person"))
503    ('grand-hallway:hackthena-statue
504     <proxy-items> 'grand-hallway
505     #:name "the statue of Hackthena"
506     #:desc '((p "The base of the statue says \"Hackthena, guardian of the hacker
507 spirit\".  You've heard of Hackthena... not a goddess, but spiritual protector of
508 all good hacks, and legendary hacker herself.")
509              (p "Hackthena holds the form of a human woman.  She wears flowing
510 robes, has a pear of curly bovine-esque horns protruding from the sides of her
511 head, wears a pair of horn-rimmed glasses, and appears posed as if for battle.
512 But instead of a weapon, she seems to hold some sort of keyboard.  And her
513 shield... well it's round like a shield, but something seems off about it.
514 You'd better take a closer look to be sure."))
515     #:goes-by '("hackthena statue" "hackthena" "statue" "statue of hackthena")
516     #:proxy-items '(grand-hallway:keyboard
517                     grand-hallway:disc-platter
518                     grand-hallway:hackthena-horns))
519    ('grand-hallway:keyboard
520     <gameobj> 'grand-hallway
521     #:name "a Knight Keyboard"
522     #:desc "Whoa, this isn't just any old keyboard, this is a Knight Keyboard!
523 Any space cadet can see that with that kind of layout a hack-and-slayer could
524 thrash out some serious key-chords like there's no tomorrow.  You guess
525 Hackthena must be an emacs user."
526     #:invisible? #t
527     #:take-me? (lambda _
528                  (values #f
529                          #:why-not
530                          `("Are you kidding?  Do you know how hard it is to find "
531                               "a Knight Keyboard?  There's no way she's going "
532                               "to give that up.")))
533     #:goes-by '("knight keyboard" "keyboard"))
534    ('grand-hallway:hackthena-horns
535     <gameobj> 'grand-hallway
536     #:name "Hackthena's horns"
537     #:desc "They're not unlike a Gnu's horns."
538     #:invisible? #t
539     #:take-me? (lambda _
540                  (values #f
541                          #:why-not
542                          `("Are you seriously considering desecrating a statue?")))
543     #:goes-by '("hackthena's horns" "horns" "horns of hacktena"))
544    ('grand-hallway:disc-platter
545     <disc-shield> 'grand-hallway
546     #:name "Hackthena's shield"
547     #:desc "No wonder the \"shield\" looks unusual... it seems to be a hard disk
548 platter!  It has \"RL02.5\" written on it.  It looks kind of loose."
549     #:invisible? #t
550     #:goes-by '("hackthena's shield" "shield" "platter" "hard disk platter"))))
551
552 \f
553 ;;; Playroom
554 ;;; --------
555
556 (define playroom
557   (lol
558    ('playroom
559     <room> #f
560     #:name "The Playroom"
561     #:desc '(p ("  There are toys scattered everywhere here.  It's really unclear
562 if this room is intended for children or child-like adults.")
563                ("  There are doors to both the east and the west."))
564     #:exits
565     (list (make <exit>
566             #:name "east"
567             #:to 'grand-hallway)
568           (make <exit>
569             #:name "west"
570             #:to 'computer-room)))
571    ('playroom:cubey
572     <gameobj> 'playroom
573     #:name "Cubey"
574     #:take-me? #t
575     #:desc "  It's a little foam cube with googly eyes on it.  So cute!")
576    ('playroom:cuddles-plushie
577     <gameobj> 'playroom
578     #:name "a Cuddles plushie"
579     #:goes-by '("plushie" "cuddles plushie" "cuddles")
580     #:take-me? #t
581     #:desc "  A warm and fuzzy cuddles plushie!  It's a cuddlefish!")
582
583    ('playroom:toy-chest
584     <container> 'playroom
585     #:name "a toy chest"
586     #:goes-by '("toy chest" "chest")
587     #:desc (lambda (toy-chest whos-looking)
588              (let ((contents (gameobj-occupants toy-chest)))
589                `((p "A brightly painted wooden chest.  The word \"TOYS\" is "
590                     "engraved on it.")
591                  (p "Inside you see:"
592                     ,(if (eq? contents '())
593                          " nothing!  It's empty!"
594                          `(ul ,(map (lambda (occupant)
595                                       `(li ,(mbody-val
596                                              (<-wait occupant 'get-name))))
597                                     (gameobj-occupants toy-chest))))))))
598     #:take-from-me? #t
599     #:put-in-me? #t)
600
601    ;; Things inside the toy chest
602    ('playroom:toy-chest:rubber-duck
603     <gameobj> 'playroom:toy-chest
604     #:name "a rubber duck"
605     #:goes-by '("rubber duck" "duck")
606     #:take-me? #t
607     #:desc "It's a yellow rubber duck with a bright orange beak.")))
608
609
610 \f
611 ;;; Writing room
612 ;;; ------------
613
614 \f
615 ;;; Armory???
616 ;;; ---------
617
618 ;; ... full of NURPH weapons?
619
620 \f
621 ;;; Smoking parlor
622 ;;; --------------
623
624 (define-class <furniture> (<gameobj>)
625   (sit-phrase #:init-keyword #:sit-phrase)
626   (sit-phrase-third-person #:init-keyword #:sit-phrase-third-person)
627   (sit-name #:init-keyword #:sit-name)
628
629   (commands
630    #:allocation #:each-subclass
631    #:init-thunk (build-commands
632                  ("sit" ((direct-command cmd-sit-furniture)))))
633   (actions #:allocation #:each-subclass
634            #:init-thunk (build-actions
635                          (cmd-sit-furniture furniture-cmd-sit))))
636
637 (define* (furniture-cmd-sit actor message #:key direct-obj)
638   (define player-name
639     (mbody-val (<-wait (message-from message) 'get-name)))
640   (<- (message-from message) 'tell
641       #:text (format #f "You ~a ~a.\n"
642                      (slot-ref actor 'sit-phrase)
643                      (slot-ref actor 'sit-name)))
644   (<- (slot-ref actor 'loc) 'tell-room
645       #:text (format #f "~a ~a on ~a.\n"
646                      player-name
647                      (slot-ref actor 'sit-phrase-third-person)
648                      (slot-ref actor 'sit-name))
649       #:exclude (message-from message)))
650
651
652 (define smoking-parlor
653   (lol
654    ('smoking-parlor
655     <room> #f
656     #:name "Smoking Parlor"
657     #:desc
658     '((p "This room looks quite posh.  There are huge comfy seats you can sit in
659 if you like. Strangely, you see a large sign saying \"No Smoking\".  The owners must
660 have installed this place and then changed their mind later.")
661       (p "There's a door to the west leading back to the grand hallway, and
662 a nondescript steel door to the south, leading apparently outside."))
663     #:exits
664     (list (make <exit>
665             #:name "west"
666             #:to 'grand-hallway)
667           (make <exit>
668             #:name "south"
669             #:to 'break-room)))
670    ('smoking-parlor:chair
671     <furniture> 'smoking-parlor
672     #:name "a comfy leather chair"
673     #:desc "  That leather chair looks really comfy!"
674     #:goes-by '("leather chair" "comfy leather chair" "chair")
675     #:sit-phrase "sink into"
676     #:sit-phrase-third-person "sinks into"
677     #:sit-name "the comfy leather chair")
678    ('smoking-parlor:sofa
679     <furniture> 'smoking-parlor
680     #:name "a plush leather sofa"
681     #:desc "  That leather chair looks really comfy!"
682     #:goes-by '("leather sofa" "plush leather sofa" "sofa"
683                 "leather couch" "plush leather couch" "couch")
684     #:sit-phrase "sprawl out on"
685     #:sit-phrase-third-person "sprawls out on into"
686     #:sit-name "the plush leather couch")
687    ('smoking-parlor:bar-stool
688     <furniture> 'smoking-parlor
689     #:name "a bar stool"
690     #:desc "  Conveniently located near the bar!  Not the most comfortable
691 seat in the room, though."
692     #:goes-by '("stool" "bar stool" "seat")
693     #:sit-phrase "hop on"
694     #:sit-phrase-third-person "hops onto"
695     #:sit-name "the bar stool")
696    ('ford-prefect
697     <chatty-npc> 'smoking-parlor
698     #:name "Ford Prefect"
699     #:desc "Just some guy, you know?"
700     #:goes-by '("Ford Prefect" "ford prefect"
701                 "frood" "prefect" "ford")
702     #:catchphrases prefect-quotes)
703
704    ('smoking-parlor:no-smoking-sign
705     <gameobj> 'smoking-parlor
706     #:invisible? #t
707     #:name "No Smoking Sign"
708     #:desc "This sign says \"No Smoking\" in big, red letters.
709 It has some bits of bubble gum stuck to it... yuck."
710     #:goes-by '("no smoking sign" "sign"))
711
712    ;; TODO: Cigar dispenser
713    ))
714
715 \f
716
717 ;;; Breakroom
718 ;;; ---------
719
720 (define-class <desk-clerk> (<gameobj>)
721   ;; The desk clerk has three states:
722   ;;  - on-duty: Arrived, and waiting for instructions (and losing patience
723   ;;    gradually)
724   ;;  - slacking: In the break room, probably smoking a cigarette
725   ;;    or checking text messages
726   (state #:init-value 'slacking)
727   (commands #:allocation #:each-subclass
728             #:init-thunk
729             (build-commands
730              (("talk" "chat") ((direct-command cmd-chat)))
731              ("ask" ((direct-command cmd-ask-incomplete)
732                      (prep-direct-command cmd-ask-about)))
733              ("dismiss" ((direct-command cmd-dismiss)))))
734   (patience #:init-value 0)
735   (actions #:allocation #:each-subclass
736            #:init-thunk (build-actions
737                          (init clerk-act-init)
738                          (cmd-chat clerk-cmd-chat)
739                          (cmd-ask-incomplete clerk-cmd-ask-incomplete)
740                          (cmd-ask-about clerk-cmd-ask)
741                          (cmd-dismiss clerk-cmd-dismiss)
742                          (update-loop clerk-act-update-loop)
743                          (be-summoned clerk-act-be-summoned))))
744
745 (define (clerk-act-init clerk message . _)
746   ;; call the gameobj main init method
747   (gameobj-act-init clerk message)
748   ;; start our main loop
749   (<- (actor-id clerk) 'update-loop))
750
751 (define clerk-help-topics
752   '(("changing name" .
753      "Changing your name is easy!  We have a clipboard here at the desk
754 where you can make yourself known to other participants in the hotel
755 if you sign it.  Try 'sign form as <your-name>', replacing
756 <your-name>, obviously!")
757     ("common commands" .
758      "Here are some useful commands you might like to try: chat,
759 go, take, drop, say...")
760     ("hotel" .
761      "We hope you enjoy your stay at Hotel Bricabrac.  As you may see,
762 our hotel emphasizes interesting experiences over rest and lodging.
763 The origins of the hotel are... unclear... and it has recently come
764 under new... 'management'.  But at Hotel Bricabrac we believe these
765 aspects make the hotel into a fun and unique experience!  Please,
766 feel free to walk around and explore.")))
767
768
769 (define clerk-knows-about
770   "'ask clerk about changing name', 'ask clerk about common commands', and 'ask clerk about the hotel'")
771
772 (define clerk-general-helpful-line
773   (string-append
774    "The clerk says, \"If you need help with anything, feel free to ask me about it.
775 For example, 'ask clerk about changing name'. You can ask me about the following:
776 " clerk-knows-about ".\"\n"))
777
778 (define clerk-slacking-complaints
779   '("The pay here is absolutely lousy."
780     "The owner here has no idea what they're doing."
781     "Some times you just gotta step away, you know?"
782     "You as exhausted as I am?"
783     "Yeah well, this is just temporary.  I'm studying to be a high
784 energy particle physicist.  But ya gotta pay the bills, especially
785 with tuition at where it is..."))
786
787 (define* (clerk-cmd-chat clerk message #:key direct-obj)
788   (match (slot-ref clerk 'state)
789     ('on-duty
790      (<- (message-from message) 'tell
791          #:text clerk-general-helpful-line))
792     ('slacking
793      (<- (message-from message) 'tell
794          #:text
795          (string-append
796           "The clerk says, \""
797           (random-choice clerk-slacking-complaints)
798           "\"\n")))))
799
800 (define (clerk-cmd-ask-incomplete clerk message . _)
801   (<- (message-from message) 'tell
802       #:text "The clerk says, \"Ask about what?\"\n"))
803
804 (define clerk-doesnt-know-text
805   "The clerk apologizes and says she doesn't know about that topic.\n")
806
807 (define* (clerk-cmd-ask clerk message #:key indir-obj
808                         #:allow-other-keys)
809   (match (slot-ref clerk 'state)
810     ('on-duty
811      (match (assoc indir-obj clerk-help-topics)
812        ((_ . info)
813            (<- (message-from message) 'tell
814                #:text
815                (string-append "The clerk clears her throat and says:\n  \""
816                               info
817                               "\"\n")))
818        (#f
819         (<- (message-from message) 'tell
820             #:text clerk-doesnt-know-text))))
821     ('slacking
822      (<- (message-from message) 'tell
823          #:text "The clerk says, \"Sorry, I'm on my break.\"\n"))))
824
825 (define* (clerk-act-be-summoned clerk message #:key who-summoned)
826   (match (slot-ref clerk 'state)
827     ('on-duty
828      (<- who-summoned 'tell
829          #:text
830          "The clerk tells you as politely as she can that she's already here,
831 so there's no need to ring the bell.\n"))
832     ('slacking
833      (<- (gameobj-loc clerk) 'tell-room
834          #:text
835          "The clerk's ears perk up, she stamps out a cigarette, and she
836 runs out of the room!\n")
837      (gameobj-set-loc! clerk (dyn-ref clerk 'lobby))
838      (slot-set! clerk 'patience 8)
839      (slot-set! clerk 'state 'on-duty)
840      (<- (gameobj-loc clerk) 'tell-room
841          #:text
842          (string-append
843           "  Suddenly, a uniformed woman rushes into the room!  She's wearing a
844 badge that says \"Desk Clerk\".
845   \"Hello, yes,\" she says between breaths, \"welcome to Hotel Bricabrac!
846 We look forward to your stay.  If you'd like help getting acclimated,
847 feel free to ask me.  For example, 'ask clerk about changing name'.
848 You can ask me about the following:
849 " clerk-knows-about ".\"\n")))))
850
851 (define* (clerk-cmd-dismiss clerk message . _)
852   (define player-name
853     (mbody-val (<-wait (message-from message) 'get-name)))
854   (match (slot-ref clerk 'state)
855     ('on-duty
856      (<- (gameobj-loc clerk) 'tell-room
857          #:text
858          (format #f "\"Thanks ~a!\" says the clerk. \"I have somewhere I need to be.\"
859 The clerk leaves the room in a hurry.\n"
860                  player-name)
861          #:exclude (actor-id clerk))
862      (gameobj-set-loc! clerk (dyn-ref clerk 'break-room))
863      (slot-set! clerk 'state 'slacking)
864      (<- (gameobj-loc clerk) 'tell-room
865          #:text clerk-return-to-slacking-text
866          #:exclude (actor-id clerk)))
867     ('slacking
868      (<- (message-from message) 'tell
869          #:text "The clerk sternly asks you to not be so dismissive.\n"))))
870
871 (define clerk-slacking-texts
872   '("The clerk takes a long drag on her cigarette.\n"
873     "The clerk scrolls through text messages on her phone.\n"
874     "The clerk coughs a few times.\n"
875     "The clerk checks her watch and justifies a few more minutes outside.\n"
876     "The clerk fumbles around for a lighter.\n"
877     "The clerk sighs deeply and exhaustedly.\n"
878     "The clerk fumbles around for a cigarette.\n"))
879
880 (define clerk-working-impatience-texts
881   '("The clerk hums something, but you're not sure what it is."
882     "The clerk attempts to change the overhead music, but the dial seems broken."
883     "The clerk clicks around on the desk computer."
884     "The clerk scribbles an equation on a memo pad, then crosses it out."
885     "The clerk mutters something about the proprietor having no idea how to run a hotel."
886     "The clerk thumbs through a printout of some physics paper."))
887
888 (define clerk-slack-excuse-text
889   "The desk clerk excuses herself, but says you are welcome to ring the bell
890 if you need further help.")
891
892 (define clerk-return-to-slacking-text
893   "The desk clerk enters and slams the door behind her.\n")
894
895
896 (define (clerk-act-update-loop clerk message)
897   (define (tell-room text)
898     (<- (gameobj-loc clerk) 'tell-room
899         #:text text
900         #:exclude (actor-id clerk)))
901   (define (loop-if-not-destructed)
902     (if (not (slot-ref clerk 'destructed))
903         ;; This iterates by "recursing" on itself by calling itself
904         ;; (as the message handler) again.  It used to be that we had to do
905         ;; this, because there was a bug where a loop which yielded like this
906         ;; would keep growing the stack due to some parameter goofiness.
907         ;; That's no longer true, but there's an added advantage to this
908         ;; route: it's much more live hackable.  If we change the definition
909         ;; of this method, the character will act differently on the next
910         ;; "tick" of the loop.
911         (<- (actor-id clerk) 'update-loop)))
912   (match (slot-ref clerk 'state)
913     ('slacking
914      (tell-room (random-choice clerk-slacking-texts))
915      (8sleep (+ (random 20) 15))
916      (loop-if-not-destructed))
917     ('on-duty
918      (if (> (slot-ref clerk 'patience) 0)
919          ;; Keep working but lose patience gradually
920          (begin
921            (tell-room (random-choice clerk-working-impatience-texts))
922            (slot-set! clerk 'patience (- (slot-ref clerk 'patience)
923                                          (+ (random 2) 1)))
924            (8sleep (+ (random 60) 40))
925            (loop-if-not-destructed))
926          ;; Back to slacking
927          (begin
928            (tell-room clerk-slack-excuse-text)
929            ;; back bto the break room
930            (gameobj-set-loc! clerk (dyn-ref clerk 'break-room))
931            (tell-room clerk-return-to-slacking-text)
932            ;; annnnnd back to slacking
933            (slot-set! clerk 'state 'slacking)
934            (8sleep (+ (random 30) 15))
935            (loop-if-not-destructed))))))
936
937
938 (define break-room
939   (lol
940    ('break-room
941     <room> #f
942     #:name "Employee Break Room"
943     #:desc "  This is less a room and more of an outdoor wire cage.  You get
944 a bit of a view of the brick exterior of the building, and a crisp wind blows,
945 whistling, through the openings of the fenced area.  Partly smoked cigarettes
946 and various other debris cover the floor.
947   Through the wires you can see... well... hm.  It looks oddly like
948 the scenery tapers off nothingness.  But that can't be right, can it?"
949     #:exits
950     (list (make <exit>
951             #:name "north"
952             #:to 'smoking-parlor)))
953    ('break-room:desk-clerk
954     <desk-clerk> 'break-room
955     #:name "the hotel desk clerk"
956     #:desc "  The hotel clerk is wearing a neatly pressed uniform bearing the
957 hotel insignia.  She appears to be rather exhausted."
958     #:goes-by '("hotel desk clerk" "clerk" "desk clerk"))
959    ('break-room:void
960     <gameobj> 'break-room
961     #:invisible? #t
962     #:name "The Void"
963     #:desc "As you stare into the void, the void stares back into you."
964     #:goes-by '("void" "abyss" "nothingness" "scenery"))
965    ('break-room:fence
966     <gameobj> 'break-room
967     #:invisible? #t
968     #:name "break room cage"
969     #:desc "It's a mostly-cubical wire mesh surrounding the break area.
970 You can see through the gaps, but they're too small to put more than a
971 couple of fingers through.  There appears to be some wear and tear to
972 the paint, but the wires themselves seem to be unusually sturdy."
973     #:goes-by '("fence" "cage" "wire cage"))))
974
975
976 \f
977 ;;; Ennpie's Sea Lounge
978 ;;; -------------------
979
980 \f
981 ;;; Computer room
982 ;;; -------------
983
984 ;; Our computer and hard drive are based off the PDP-11 and the RL01 /
985 ;; RL02 disk drives.  However we increment both by .5 (a true heresy)
986 ;; to distinguish both from the real thing.
987
988 (define-actor <hard-drive> (<gameobj>)
989   ((cmd-put-in hard-drive-insert)
990    (cmd-push-button hard-drive-push-button)
991    (get-state hard-drive-act-get-state))
992   (commands #:allocation #:each-subclass
993             #:init-thunk (build-commands
994                           ("insert" ((prep-indir-command cmd-put-in
995                                                          '("in" "inside" "into"))))
996                           (("press" "push") ((prep-indir-command cmd-push-button)))))
997   ;; the state moves from: empty -> with-disc -> loading -> ready
998   (state #:init-value 'empty
999          #:accessor .state))
1000
1001 (define (hard-drive-act-get-state hard-drive message)
1002   (<-reply message (.state hard-drive)))
1003
1004 (define* (hard-drive-desc hard-drive #:optional whos-looking)
1005   `((p "The hard drive is labeled \"RL02.5\".  It's a little under a meter tall.")
1006     (p "There is a slot where a disk platter could be inserted, "
1007        ,(if (eq? (.state hard-drive) 'empty)
1008             "which is currently empty"
1009             "which contains a glowing platter")
1010        ". There is a LOAD button "
1011        ,(if (member (.state hard-drive) '(empty with-disc))
1012             "which is glowing"
1013             "which is pressed in and unlit")
1014        ". There is a READY indicator "
1015        ,(if (eq? (.state hard-drive) 'ready)
1016             "which is glowing."
1017             "which is unlit.")
1018        ,(if (member (.state hard-drive) '(loading ready))
1019             "  The machine emits a gentle whirring noise."
1020             ""))))
1021
1022 (define* (hard-drive-push-button gameobj message
1023                                  #:key direct-obj indir-obj preposition
1024                                  (player (message-from message)))
1025   (define (tell-room text)
1026     (<- (gameobj-loc gameobj) 'tell-room
1027         #:text text))
1028   (define (tell-room-excluding-player text)
1029     (<- (gameobj-loc gameobj) 'tell-room
1030         #:text text
1031         #:exclude player))
1032   (cond
1033    ((ci-member direct-obj '("button" "load button" "load"))
1034     (tell-room-excluding-player
1035      `(,(mbody-val (<-wait player 'get-name))
1036        " presses the button on the hard disk."))
1037     (<- player 'tell
1038         #:text "You press the button on the hard disk.")
1039
1040     (case (.state gameobj)
1041       ((empty)
1042        ;; I have no idea what this drive did when you didn't have a platter
1043        ;; in it and pressed load, but I know there was a FAULT button.
1044        (tell-room "You hear some movement inside the hard drive...")
1045        (8sleep 1.5)
1046        (tell-room
1047         '("... but then the FAULT button blinks a couple times. "
1048           "What could be missing?")))
1049       ((with-disc)
1050        (set! (.state gameobj) 'loading)
1051        (tell-room "The hard disk begins to spin up!")
1052        (8sleep 2)
1053        (set! (.state gameobj) 'ready)
1054        (tell-room "The READY light turns on!"))
1055       ((loading ready)
1056        (<- 'tell player
1057            #:text '("Pressing the button does nothing right now, "
1058                     "but it does feel satisfying.")))))
1059    (else
1060     (<- player 'tell
1061         #:text '("How could you think of pressing anything else "
1062                  "but that tantalizing button right in front of you?")))))
1063
1064 (define* (hard-drive-insert gameobj message
1065                             #:key direct-obj indir-obj preposition
1066                             (player (message-from message)))
1067   (define our-name (slot-ref gameobj 'name))
1068   (define this-thing
1069     (call/ec
1070      (lambda (return)
1071        (for-each (lambda (occupant)
1072                    (define goes-by (mbody-val (<-wait occupant 'goes-by)))
1073                    (when (ci-member direct-obj goes-by)
1074                      (return occupant)))
1075                  (mbody-val (<-wait player 'get-occupants)))
1076        ;; nothing found
1077        #f)))
1078   (cond
1079    ((not this-thing)
1080     (<- player 'tell
1081         #:text `("You don't seem to have any such " ,direct-obj " to put "
1082                  ,preposition " " ,our-name ".")))
1083    ((not (mbody-val (<-wait this-thing 'get-prop 'hd-platter?)))
1084     (<- player 'tell
1085         #:text `("It wouldn't make sense to put "
1086                  ,(mbody-val (<-wait this-thing 'get-name))
1087                  " " ,preposition " " ,our-name ".")))
1088    ((not (eq? (.state gameobj) 'empty))
1089     (<- player 'tell
1090         #:text "The disk drive already has a platter in it."))
1091    (else
1092     (set! (.state gameobj) 'with-disc)
1093     (<- player 'tell
1094         #:text '((p "You insert the glowing disc into the drive.")
1095                  (p "The LOAD button begins to glow."))))))
1096
1097 (define computer-room
1098   (lol
1099    ('computer-room
1100     <room> #f
1101     #:name "Computer Room"
1102     #:desc '((p "A sizable computer cabinet covers a good portion of the left
1103 wall.  It emits a pleasant hum which covers the room like a warm blanket.
1104 Connected to a computer is a large hard drive.")
1105              (p "On the floor is a large steel panel.  It is closed, but it has
1106 hinges which suggest it could be opened."))
1107     #:exits
1108     (list (make <exit>
1109             #:name "east"
1110             #:to 'playroom)))
1111    ('computer-room:hard-drive
1112     <hard-drive> 'computer-room
1113     #:name "a hard drive"
1114     #:desc (wrap-apply hard-drive-desc)
1115     #:goes-by '("hard drive" "drive" "hard disk"))))
1116
1117
1118 \f
1119 ;;; Game
1120 ;;; ----
1121
1122 (define (game-spec)
1123   (append lobby grand-hallway smoking-parlor
1124           playroom break-room computer-room))
1125
1126 ;; TODO: Provide command line args
1127 (define (run-game . args)
1128   (run-demo (game-spec) 'lobby #:repl-server #t))
1129