Add the glowing disc
[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   (pk 'hi)
423   (create-gameobj <glowing-disc> (gameobj-gm gameobj)
424                   player)  ;; set loc to player to put in player's inventory
425   (<- player 'tell
426       #:text '((p "As you attempt to pull the shield / disk platter
427 from the statue, there is a bright glow...  and a completely separate,
428 glowing copy of the disc materializes into your hands!")
429                (p "You hear a voice whispering in your ear: "
430                   (i "\"Share the software... and you'll be free...\"")))))
431
432 ;;; This is the disc that gets put in the player's inventory
433 (define-actor <glowing-disc> (<gameobj>)
434   ((cmd-drop glowing-disc-drop-cmd))
435   (initial-props
436    #:allocation #:each-subclass
437    #:init-thunk (build-props
438                  '((hd-platter? . #t))))
439   (name #:allocation #:each-subclass
440         #:init-value "a glowing disc")
441   (desc #:allocation #:each-subclass
442         #:init-value "A brightly glowing disc.  It's shaped like a hard
443 drive platter, not unlike the one from the statue it came from.  It's
444 labeled \"RL02.5\".")
445   (goes-by #:init-value '("glowing disc" "glowing platter"
446                           "glowing disc platter" "glowing disk platter"
447                           "platter" "disc" "disk" "glowing shield")))
448
449 (define* (glowing-disc-drop-cmd gameobj message
450                    #:key direct-obj
451                    (player (message-from message)))
452   (<- player 'tell
453       #:text "You drop the glowing disc, and it shatters into a million
454 pieces!")
455   (gameobj-self-destruct gameobj))
456
457 (define grand-hallway
458   (lol
459    ('grand-hallway
460     <room> #f
461     #:name "Grand Hallway"
462     #:desc '((p "  A majestic red carpet runs down the center of the room.
463 Busts of serious looking people line the walls, but there's no
464 clear indication that they have any logical relation to this place.")
465              (p "In the center is a large statue of a woman in a warrior's
466 pose, but something is strange about her weapon and shield.  You wonder what
467 that's all about?")
468              (p "To the south is the lobby.  A door to the east is labeled \"smoking
469 room\", while a door to the west is labeled \"playroom\"."))
470     #:exits
471     (list (make <exit>
472             #:name "south"
473             #:to 'lobby)
474           (make <exit>
475             #:name "west"
476             #:to 'playroom)
477           (make <exit>
478             #:name "east"
479             #:to 'smoking-parlor)))
480    ('grand-hallway:carpet
481     <gameobj> 'grand-hallway
482     #:name "the Grand Hallway carpet"
483     #:desc "It's very red, except in the places where it's very worn."
484     #:invisible? #t
485     #:goes-by '("red carpet" "carpet"))
486    ('grand-hallway:busts
487     <gameobj> 'grand-hallway
488     #:name "the busts of serious people"
489     #:desc "There are about 6 of them in total.  They look distinguished
490 but there's no indication of who they are."
491     #:invisible? #t
492     #:goes-by '("busts" "bust" "busts of serious people" "bust of serious person"))
493    ('grand-hallway:hackthena-statue
494     <proxy-items> 'grand-hallway
495     #:name "the statue of Hackthena"
496     #:desc '((p "The base of the statue says \"Hackthena, guardian of the hacker
497 spirit\".  You've heard of Hackthena... not a goddess, but spiritual protector of
498 all good hacks, and legendary hacker herself.")
499              (p "Hackthena holds the form of a human woman.  She wears flowing
500 robes, has a pear of curly bovine-esque horns protruding from the sides of her
501 head, wears a pair of horn-rimmed glasses, and appears posed as if for battle.
502 But instead of a weapon, she seems to hold some sort of keyboard.  And her
503 shield... well it's round like a shield, but something seems off about it.
504 You'd better take a closer look to be sure."))
505     #:goes-by '("hackthena statue" "hackthena" "statue" "statue of hackthena")
506     #:proxy-items '(grand-hallway:keyboard
507                     grand-hallway:disc-platter
508                     grand-hallway:hackthena-horns))
509    ('grand-hallway:keyboard
510     <gameobj> 'grand-hallway
511     #:name "a Knight Keyboard"
512     #:desc "Whoa, this isn't just any old keyboard, this is a Knight Keyboard!
513 Any space cadet can see that with that kind of layout a hack-and-slayer could
514 thrash out some serious key-chords like there's no tomorrow.  You guess
515 Hackthena must be an emacs user."
516     #:invisible? #t
517     #:take-me? (lambda _
518                  (values #f
519                          #:why-not
520                          `("Are you kidding?  Do you know how hard it is to find "
521                               "a Knight Keyboard?  There's no way she's going "
522                               "to give that up.")))
523     #:goes-by '("knight keyboard" "keyboard"))
524    ('grand-hallway:hackthena-horns
525     <gameobj> 'grand-hallway
526     #:name "Hackthena's horns"
527     #:desc "They're not unlike a Gnu's horns."
528     #:invisible? #t
529     #:take-me? (lambda _
530                  (values #f
531                          #:why-not
532                          `("Are you seriously considering desecrating a statue?")))
533     #:goes-by '("hackthena's horns" "horns" "horns of hacktena"))
534    ('grand-hallway:disc-platter
535     <disc-shield> 'grand-hallway
536     #:name "a hard disc platter"
537     #:desc "This isn't a shield after all, it seems to be a hard disc
538 platter!  It looks kind of loose..."
539     #:invisible? #t
540     #:goes-by '("hard disc platter" "disc platter" "disc"
541                 "hard disk platter" "disk platter"
542                 "shield" "platter"))))
543
544 \f
545 ;;; Playroom
546 ;;; --------
547
548 (define playroom
549   (lol
550    ('playroom
551     <room> #f
552     #:name "The Playroom"
553     #:desc '(p ("  There are toys scattered everywhere here.  It's really unclear
554 if this room is intended for children or child-like adults.")
555                ("  There are doors to both the east and the west."))
556     #:exits
557     (list (make <exit>
558             #:name "east"
559             #:to 'grand-hallway)
560           (make <exit>
561             #:name "west"
562             #:to 'computer-room)))
563    ('playroom:cubey
564     <gameobj> 'playroom
565     #:name "Cubey"
566     #:take-me? #t
567     #:desc "  It's a little foam cube with googly eyes on it.  So cute!")
568    ('playroom:cuddles-plushie
569     <gameobj> 'playroom
570     #:name "a Cuddles plushie"
571     #:goes-by '("plushie" "cuddles plushie" "cuddles")
572     #:take-me? #t
573     #:desc "  A warm and fuzzy cuddles plushie!  It's a cuddlefish!")
574
575    ('playroom:toy-chest
576     <container> 'playroom
577     #:name "a toy chest"
578     #:goes-by '("toy chest" "chest")
579     #:desc (lambda (toy-chest whos-looking)
580              (let ((contents (gameobj-occupants toy-chest)))
581                `((p "A brightly painted wooden chest.  The word \"TOYS\" is "
582                     "engraved on it.")
583                  (p "Inside you see:"
584                     ,(if (eq? contents '())
585                          " nothing!  It's empty!"
586                          `(ul ,(map (lambda (occupant)
587                                       `(li ,(mbody-val
588                                              (<-wait occupant 'get-name))))
589                                     (gameobj-occupants toy-chest))))))))
590     #:take-from-me? #t
591     #:put-in-me? #t)
592
593    ;; Things inside the toy chest
594    ('playroom:toy-chest:rubber-duck
595     <gameobj> 'playroom:toy-chest
596     #:name "a rubber duck"
597     #:goes-by '("rubber duck" "duck")
598     #:take-me? #t
599     #:desc "It's a yellow rubber duck with a bright orange beak.")))
600
601
602 \f
603 ;;; Writing room
604 ;;; ------------
605
606 \f
607 ;;; Armory???
608 ;;; ---------
609
610 ;; ... full of NURPH weapons?
611
612 \f
613 ;;; Smoking parlor
614 ;;; --------------
615
616 (define-class <furniture> (<gameobj>)
617   (sit-phrase #:init-keyword #:sit-phrase)
618   (sit-phrase-third-person #:init-keyword #:sit-phrase-third-person)
619   (sit-name #:init-keyword #:sit-name)
620
621   (commands
622    #:allocation #:each-subclass
623    #:init-thunk (build-commands
624                  ("sit" ((direct-command cmd-sit-furniture)))))
625   (actions #:allocation #:each-subclass
626            #:init-thunk (build-actions
627                          (cmd-sit-furniture furniture-cmd-sit))))
628
629 (define* (furniture-cmd-sit actor message #:key direct-obj)
630   (define player-name
631     (mbody-val (<-wait (message-from message) 'get-name)))
632   (<- (message-from message) 'tell
633       #:text (format #f "You ~a ~a.\n"
634                      (slot-ref actor 'sit-phrase)
635                      (slot-ref actor 'sit-name)))
636   (<- (slot-ref actor 'loc) 'tell-room
637       #:text (format #f "~a ~a on ~a.\n"
638                      player-name
639                      (slot-ref actor 'sit-phrase-third-person)
640                      (slot-ref actor 'sit-name))
641       #:exclude (message-from message)))
642
643
644 (define smoking-parlor
645   (lol
646    ('smoking-parlor
647     <room> #f
648     #:name "Smoking Parlor"
649     #:desc
650     '((p "This room looks quite posh.  There are huge comfy seats you can sit in
651 if you like. Strangely, you see a large sign saying \"No Smoking\".  The owners must
652 have installed this place and then changed their mind later.")
653       (p "There's a door to the west leading back to the grand hallway, and
654 a nondescript steel door to the south, leading apparently outside."))
655     #:exits
656     (list (make <exit>
657             #:name "west"
658             #:to 'grand-hallway)
659           (make <exit>
660             #:name "south"
661             #:to 'break-room)))
662    ('smoking-parlor:chair
663     <furniture> 'smoking-parlor
664     #:name "a comfy leather chair"
665     #:desc "  That leather chair looks really comfy!"
666     #:goes-by '("leather chair" "comfy leather chair" "chair")
667     #:sit-phrase "sink into"
668     #:sit-phrase-third-person "sinks into"
669     #:sit-name "the comfy leather chair")
670    ('smoking-parlor:sofa
671     <furniture> 'smoking-parlor
672     #:name "a plush leather sofa"
673     #:desc "  That leather chair looks really comfy!"
674     #:goes-by '("leather sofa" "plush leather sofa" "sofa"
675                 "leather couch" "plush leather couch" "couch")
676     #:sit-phrase "sprawl out on"
677     #:sit-phrase-third-person "sprawls out on into"
678     #:sit-name "the plush leather couch")
679    ('smoking-parlor:bar-stool
680     <furniture> 'smoking-parlor
681     #:name "a bar stool"
682     #:desc "  Conveniently located near the bar!  Not the most comfortable
683 seat in the room, though."
684     #:goes-by '("stool" "bar stool" "seat")
685     #:sit-phrase "hop on"
686     #:sit-phrase-third-person "hops onto"
687     #:sit-name "the bar stool")
688    ('ford-prefect
689     <chatty-npc> 'smoking-parlor
690     #:name "Ford Prefect"
691     #:desc "Just some guy, you know?"
692     #:goes-by '("Ford Prefect" "ford prefect"
693                 "frood" "prefect" "ford")
694     #:catchphrases prefect-quotes)
695
696    ('smoking-parlor:no-smoking-sign
697     <gameobj> 'smoking-parlor
698     #:invisible? #t
699     #:name "No Smoking Sign"
700     #:desc "This sign says \"No Smoking\" in big, red letters.
701 It has some bits of bubble gum stuck to it... yuck."
702     #:goes-by '("no smoking sign" "sign"))
703
704    ;; TODO: Cigar dispenser
705    ))
706
707 \f
708
709 ;;; Breakroom
710 ;;; ---------
711
712 (define-class <desk-clerk> (<gameobj>)
713   ;; The desk clerk has three states:
714   ;;  - on-duty: Arrived, and waiting for instructions (and losing patience
715   ;;    gradually)
716   ;;  - slacking: In the break room, probably smoking a cigarette
717   ;;    or checking text messages
718   (state #:init-value 'slacking)
719   (commands #:allocation #:each-subclass
720             #:init-thunk
721             (build-commands
722              (("talk" "chat") ((direct-command cmd-chat)))
723              ("ask" ((direct-command cmd-ask-incomplete)
724                      (prep-direct-command cmd-ask-about)))
725              ("dismiss" ((direct-command cmd-dismiss)))))
726   (patience #:init-value 0)
727   (actions #:allocation #:each-subclass
728            #:init-thunk (build-actions
729                          (init clerk-act-init)
730                          (cmd-chat clerk-cmd-chat)
731                          (cmd-ask-incomplete clerk-cmd-ask-incomplete)
732                          (cmd-ask-about clerk-cmd-ask)
733                          (cmd-dismiss clerk-cmd-dismiss)
734                          (update-loop clerk-act-update-loop)
735                          (be-summoned clerk-act-be-summoned))))
736
737 (define (clerk-act-init clerk message . _)
738   ;; call the gameobj main init method
739   (gameobj-act-init clerk message)
740   ;; start our main loop
741   (<- (actor-id clerk) 'update-loop))
742
743 (define clerk-help-topics
744   '(("changing name" .
745      "Changing your name is easy!  We have a clipboard here at the desk
746 where you can make yourself known to other participants in the hotel
747 if you sign it.  Try 'sign form as <your-name>', replacing
748 <your-name>, obviously!")
749     ("common commands" .
750      "Here are some useful commands you might like to try: chat,
751 go, take, drop, say...")
752     ("hotel" .
753      "We hope you enjoy your stay at Hotel Bricabrac.  As you may see,
754 our hotel emphasizes interesting experiences over rest and lodging.
755 The origins of the hotel are... unclear... and it has recently come
756 under new... 'management'.  But at Hotel Bricabrac we believe these
757 aspects make the hotel into a fun and unique experience!  Please,
758 feel free to walk around and explore.")))
759
760
761 (define clerk-knows-about
762   "'ask clerk about changing name', 'ask clerk about common commands', and 'ask clerk about the hotel'")
763
764 (define clerk-general-helpful-line
765   (string-append
766    "The clerk says, \"If you need help with anything, feel free to ask me about it.
767 For example, 'ask clerk about changing name'. You can ask me about the following:
768 " clerk-knows-about ".\"\n"))
769
770 (define clerk-slacking-complaints
771   '("The pay here is absolutely lousy."
772     "The owner here has no idea what they're doing."
773     "Some times you just gotta step away, you know?"
774     "You as exhausted as I am?"
775     "Yeah well, this is just temporary.  I'm studying to be a high
776 energy particle physicist.  But ya gotta pay the bills, especially
777 with tuition at where it is..."))
778
779 (define* (clerk-cmd-chat clerk message #:key direct-obj)
780   (match (slot-ref clerk 'state)
781     ('on-duty
782      (<- (message-from message) 'tell
783          #:text clerk-general-helpful-line))
784     ('slacking
785      (<- (message-from message) 'tell
786          #:text
787          (string-append
788           "The clerk says, \""
789           (random-choice clerk-slacking-complaints)
790           "\"\n")))))
791
792 (define (clerk-cmd-ask-incomplete clerk message . _)
793   (<- (message-from message) 'tell
794       #:text "The clerk says, \"Ask about what?\"\n"))
795
796 (define clerk-doesnt-know-text
797   "The clerk apologizes and says she doesn't know about that topic.\n")
798
799 (define* (clerk-cmd-ask clerk message #:key indir-obj
800                         #:allow-other-keys)
801   (match (slot-ref clerk 'state)
802     ('on-duty
803      (match (assoc (pk 'indir indir-obj) clerk-help-topics)
804        ((_ . info)
805            (<- (message-from message) 'tell
806                #:text
807                (string-append "The clerk clears her throat and says:\n  \""
808                               info
809                               "\"\n")))
810        (#f
811         (<- (message-from message) 'tell
812             #:text clerk-doesnt-know-text))))
813     ('slacking
814      (<- (message-from message) 'tell
815          #:text "The clerk says, \"Sorry, I'm on my break.\"\n"))))
816
817 (define* (clerk-act-be-summoned clerk message #:key who-summoned)
818   (match (slot-ref clerk 'state)
819     ('on-duty
820      (<- who-summoned 'tell
821          #:text
822          "The clerk tells you as politely as she can that she's already here,
823 so there's no need to ring the bell.\n"))
824     ('slacking
825      (<- (gameobj-loc clerk) 'tell-room
826          #:text
827          "The clerk's ears perk up, she stamps out a cigarette, and she
828 runs out of the room!\n")
829      (gameobj-set-loc! clerk (dyn-ref clerk 'lobby))
830      (slot-set! clerk 'patience 8)
831      (slot-set! clerk 'state 'on-duty)
832      (<- (gameobj-loc clerk) 'tell-room
833          #:text
834          (string-append
835           "  Suddenly, a uniformed woman rushes into the room!  She's wearing a
836 badge that says \"Desk Clerk\".
837   \"Hello, yes,\" she says between breaths, \"welcome to Hotel Bricabrac!
838 We look forward to your stay.  If you'd like help getting acclimated,
839 feel free to ask me.  For example, 'ask clerk about changing name'.
840 You can ask me about the following:
841 " clerk-knows-about ".\"\n")))))
842
843 (define* (clerk-cmd-dismiss clerk message . _)
844   (define player-name
845     (mbody-val (<-wait (message-from message) 'get-name)))
846   (match (slot-ref clerk 'state)
847     ('on-duty
848      (<- (gameobj-loc clerk) 'tell-room
849          #:text
850          (format #f "\"Thanks ~a!\" says the clerk. \"I have somewhere I need to be.\"
851 The clerk leaves the room in a hurry.\n"
852                  player-name)
853          #:exclude (actor-id clerk))
854      (gameobj-set-loc! clerk (dyn-ref clerk 'break-room))
855      (slot-set! clerk 'state 'slacking)
856      (<- (gameobj-loc clerk) 'tell-room
857          #:text clerk-return-to-slacking-text
858          #:exclude (actor-id clerk)))
859     ('slacking
860      (<- (message-from message) 'tell
861          #:text "The clerk sternly asks you to not be so dismissive.\n"))))
862
863 (define clerk-slacking-texts
864   '("The clerk takes a long drag on her cigarette.\n"
865     "The clerk scrolls through text messages on her phone.\n"
866     "The clerk coughs a few times.\n"
867     "The clerk checks her watch and justifies a few more minutes outside.\n"
868     "The clerk fumbles around for a lighter.\n"
869     "The clerk sighs deeply and exhaustedly.\n"
870     "The clerk fumbles around for a cigarette.\n"))
871
872 (define clerk-working-impatience-texts
873   '("The clerk hums something, but you're not sure what it is."
874     "The clerk attempts to change the overhead music, but the dial seems broken."
875     "The clerk clicks around on the desk computer."
876     "The clerk scribbles an equation on a memo pad, then crosses it out."
877     "The clerk mutters something about the proprietor having no idea how to run a hotel."
878     "The clerk thumbs through a printout of some physics paper."))
879
880 (define clerk-slack-excuse-text
881   "The desk clerk excuses herself, but says you are welcome to ring the bell
882 if you need further help.")
883
884 (define clerk-return-to-slacking-text
885   "The desk clerk enters and slams the door behind her.\n")
886
887
888 (define (clerk-act-update-loop clerk message)
889   (define (tell-room text)
890     (<- (gameobj-loc clerk) 'tell-room
891         #:text text
892         #:exclude (actor-id clerk)))
893   (define (loop-if-not-destructed)
894     (if (not (slot-ref clerk 'destructed))
895         ;; This iterates by "recursing" on itself by calling itself
896         ;; (as the message handler) again.  It used to be that we had to do
897         ;; this, because there was a bug where a loop which yielded like this
898         ;; would keep growing the stack due to some parameter goofiness.
899         ;; That's no longer true, but there's an added advantage to this
900         ;; route: it's much more live hackable.  If we change the definition
901         ;; of this method, the character will act differently on the next
902         ;; "tick" of the loop.
903         (<- (actor-id clerk) 'update-loop)))
904   (match (slot-ref clerk 'state)
905     ('slacking
906      (tell-room (random-choice clerk-slacking-texts))
907      (8sleep (+ (random 20) 15))
908      (loop-if-not-destructed))
909     ('on-duty
910      (if (> (slot-ref clerk 'patience) 0)
911          ;; Keep working but lose patience gradually
912          (begin
913            (tell-room (random-choice clerk-working-impatience-texts))
914            (slot-set! clerk 'patience (- (slot-ref clerk 'patience)
915                                          (+ (random 2) 1)))
916            (8sleep (+ (random 60) 40))
917            (loop-if-not-destructed))
918          ;; Back to slacking
919          (begin
920            (tell-room clerk-slack-excuse-text)
921            ;; back bto the break room
922            (gameobj-set-loc! clerk (pk 'break-room (dyn-ref clerk 'break-room)))
923            (tell-room clerk-return-to-slacking-text)
924            ;; annnnnd back to slacking
925            (slot-set! clerk 'state 'slacking)
926            (8sleep (+ (random 30) 15))
927            (loop-if-not-destructed))))))
928
929
930 (define break-room
931   (lol
932    ('break-room
933     <room> #f
934     #:name "Employee Break Room"
935     #:desc "  This is less a room and more of an outdoor wire cage.  You get
936 a bit of a view of the brick exterior of the building, and a crisp wind blows,
937 whistling, through the openings of the fenced area.  Partly smoked cigarettes
938 and various other debris cover the floor.
939   Through the wires you can see... well... hm.  It looks oddly like
940 the scenery tapers off nothingness.  But that can't be right, can it?"
941     #:exits
942     (list (make <exit>
943             #:name "north"
944             #:to 'smoking-parlor)))
945    ('break-room:desk-clerk
946     <desk-clerk> 'break-room
947     #:name "the hotel desk clerk"
948     #:desc "  The hotel clerk is wearing a neatly pressed uniform bearing the
949 hotel insignia.  She appears to be rather exhausted."
950     #:goes-by '("hotel desk clerk" "clerk" "desk clerk"))
951    ('break-room:void
952     <gameobj> 'break-room
953     #:invisible? #t
954     #:name "The Void"
955     #:desc "As you stare into the void, the void stares back into you."
956     #:goes-by '("void" "abyss" "nothingness" "scenery"))
957    ('break-room:fence
958     <gameobj> 'break-room
959     #:invisible? #t
960     #:name "break room cage"
961     #:desc "It's a mostly-cubical wire mesh surrounding the break area.
962 You can see through the gaps, but they're too small to put more than a
963 couple of fingers through.  There appears to be some wear and tear to
964 the paint, but the wires themselves seem to be unusually sturdy."
965     #:goes-by '("fence" "cage" "wire cage"))))
966
967
968 \f
969 ;;; Ennpie's Sea Lounge
970 ;;; -------------------
971
972 \f
973 ;;; Computer room
974 ;;; -------------
975
976 ;; Our computer and hard drive are based off the PDP-11 and the RL01 /
977 ;; RL02 disk drives.  However we increment both by .5 (a true heresy)
978 ;; to distinguish both from the real thing.
979
980 (define-actor <hard-drive> (<gameobj>)
981   ()
982   ;; the state moves from: empty -> with-disc -> loading -> ready
983   (state #:init-value 'empty
984          #:accessor .state))
985
986 (define* (hard-drive-desc hard-drive #:optional whos-looking)
987   `((p "The hard drive is labeled \"RL02.5\".  It's a little under a meter tall.")
988     (p "There is a slot where a disk platter could be inserted, "
989        ,(if (eq? (.state hard-drive) 'empty)
990             "which is currently empty"
991             "which contains a glowing platter")
992        ". There is a LOAD button "
993        ,(if (member (.state hard-drive) '(empty with-disc))
994             "which is glowing"
995             "which is pressed in and unlit")
996        ". There is a READY indicator "
997        ,(if (eq? (.state hard-drive) 'ready)
998             "which is glowing.  The machine emits a gentle whirring noise."
999             "which is unlit."))))
1000
1001 (define computer-room
1002   (lol
1003    ('computer-room
1004     <room> #f
1005     #:name "Computer Room"
1006     #:desc '((p "A sizable computer cabinet covers a good portion of the left
1007 wall.  It emits a pleasant hum which covers the room like a warm blanket.
1008 Connected to a computer is a large hard drive.")
1009              (p "On the floor is a large steel panel.  It is closed, but it has
1010 hinges which suggest it could be opened."))
1011     #:exits
1012     (list (make <exit>
1013             #:name "east"
1014             #:to 'playroom)))
1015    ('computer-room:hard-drive
1016     <hard-drive> 'computer-room
1017     #:name "a hard drive"
1018     #:desc (wrap-apply hard-drive-desc)
1019     #:goes-by '("hard drive" "drive" "hard disk"))))
1020
1021
1022 \f
1023 ;;; Game
1024 ;;; ----
1025
1026 (define (game-spec)
1027   (append lobby grand-hallway smoking-parlor
1028           playroom break-room computer-room))
1029
1030 ;; TODO: Provide command line args
1031 (define (run-game . args)
1032   (run-demo (game-spec) 'lobby #:repl-server #t))
1033