51549873151ea6567620c52fe1c058e454b830fd
[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 actors)
24              (8sync agenda)
25              (oop goops)
26              (ice-9 control)
27              (ice-9 format)
28              (ice-9 match)
29              (rx irregex))
30
31
32 \f
33 ;;; Utilities, useful or otherwise
34 ;;; ==============================
35
36 (set! *random-state* (random-state-from-platform))
37
38 (define (random-choice lst)
39   (list-ref lst (random (length lst))))
40
41 ;; list of lists, lol.
42 (define-syntax-rule (lol (list-contents ...) ...)
43   (list (list list-contents ...) ...))
44
45 \f
46 ;;; Some simple object types.
47 ;;; =========================
48
49 (define-class <readable> (<gameobj>)
50   (read-text #:init-value "All it says is: \"Blah blah blah.\""
51              #:init-keyword #:read-text)
52   (commands
53    #:allocation #:each-subclass
54    #:init-thunk (build-commands
55                  ("read" ((direct-command cmd-read)))))
56   (actions #:allocation #:each-subclass
57            #:init-thunk (build-actions
58                          (cmd-read readable-cmd-read))))
59
60 (define (readable-cmd-read actor message)
61   (<- (message-from message) 'tell
62       #:text (string-append (slot-ref actor 'read-text) "\n")))
63
64
65 ;; This one allows you to take from 
66
67 (define-actor <proxy-items> (<gameobj>)
68   ((cmd-take-from take-from-proxy))
69   (proxy-items #:init-keyword #:proxy-items))
70
71 (define* (take-from-proxy gameobj message
72                           #:key direct-obj indir-obj preposition
73                           (player (message-from message)))
74   (call/ec
75    (lambda (escape)
76      (for-each
77       (lambda (obj-sym)
78         (define obj-id (dyn-ref gameobj obj-sym))
79         (define goes-by
80           (mbody-val (<-wait obj-id 'goes-by)))
81         (when (ci-member direct-obj goes-by)
82           (<- obj-id 'cmd-take #:direct-obj direct-obj #:player player)
83           (escape)))
84       (slot-ref gameobj 'proxy-items))
85
86      (<- player 'tell
87         #:text `("You don't see any such " ,direct-obj " to take "
88                  ,preposition " " ,(slot-ref gameobj 'name) ".")))))
89
90
91 \f
92 ;;; Lobby
93 ;;; -----
94
95 (define (npc-chat-randomly actor message . _)
96   (define text-to-send
97     (format #f "~a says: \"~a\"\n"
98             (slot-ref actor 'name)
99             (random-choice (slot-ref actor 'catchphrases))))
100   (<- (message-from message) 'tell
101       #:text text-to-send))
102
103 (define hotel-owner-grumps
104   '("Eight sinks!  Eight sinks!  And I couldn't unwind them..."
105     "Don't mind the mess.  I built this place on a dare, you
106 know?"
107     "(*tearfully*) Here, take this parenthesis.  May it serve
108 you well."
109     "I gotta get back to the goblin farm soon..."
110     "Oh, but I was going to make a mansion... a great,
111 beautiful mansion!  Full of ghosts!  Now all I have is this cruddy
112 mo... hotel.  Oh... If only I had more time!"
113     "I told them to paint more of the walls purple.
114 Why didn't they listen?"
115     "Listen to that overhead muzak.  Whoever made that doesn't
116 know how to compose very well!  Have you heard of the bands 'fmt'
117 or 'skribe'?  Now *that's* composition!"))
118
119 (define-class <chatty-npc> (<gameobj>)
120   (catchphrases #:init-value '("Blarga blarga blarga!")
121                 #:init-keyword #:catchphrases)
122   (commands
123    #:allocation #:each-subclass
124    #:init-thunk (build-commands
125                  (("chat" "talk") ((direct-command cmd-chat)))))
126   (actions #:allocation #:each-subclass
127            #:init-thunk
128            (build-actions
129             (cmd-chat npc-chat-randomly))))
130
131 (define-class <sign-in-form> (<gameobj>)
132   (commands
133    #:allocation #:each-subclass
134    #:init-thunk (build-commands
135                  ("sign" ((prep-direct-command cmd-sign-form '("as"))))))
136   (actions #:allocation #:each-subclass
137            #:init-thunk (build-actions
138                          (cmd-sign-form sign-cmd-sign-in))))
139
140
141 (define name-sre
142   (sre->irregex '(: alpha (** 1 14 (or alphanum "-" "_")))))
143
144 (define forbidden-words
145   (append article preposition
146           '("and" "or" "but" "admin")))
147
148 (define (valid-name? name)
149   (and (irregex-match name-sre name)
150        (not (member name forbidden-words))))
151
152 (define* (sign-cmd-sign-in actor message
153                            #:key direct-obj indir-obj preposition)
154   (define old-name
155     (mbody-val (<-wait (message-from message) 'get-name)))
156   (define name indir-obj)
157   (if (valid-name? indir-obj)
158       (begin
159         (<-wait (message-from message) 'set-name! name)
160         (<- (slot-ref actor 'loc) 'tell-room
161             #:text (format #f "~a signs the form!\n~a is now known as ~a\n"
162                            old-name old-name name)))
163       (<- (message-from message) 'tell
164           #:text "Sorry, that's not a valid name.
165 Alphanumerics, _ and - only, 2-15 characters, starts with an alphabetic
166 character.\n")))
167
168
169 (define-class <summoning-bell> (<gameobj>)
170   (summons #:init-keyword #:summons)
171
172   (commands
173    #:allocation #:each-subclass
174    #:init-thunk (build-commands
175                  ("ring" ((direct-command cmd-ring)))))
176   (actions #:allocation #:each-subclass
177            #:init-thunk (build-actions
178                          (cmd-ring summoning-bell-cmd-ring))))
179
180 (define* (summoning-bell-cmd-ring bell message . _)
181   ;; Call back to actor who invoked this message handler
182   ;; and find out their name.  We'll call *their* get-name message
183   ;; handler... meanwhile, this procedure suspends until we get
184   ;; their response.
185   (define who-rang
186     (mbody-val (<-wait (message-from message) 'get-name)))
187
188   ;; Now we'll invoke the "tell" message handler on the player
189   ;; who rang us, displaying this text on their screen.
190   ;; This one just uses <- instead of <-wait, since we don't
191   ;; care when it's delivered; we're not following up on it.
192   (<- (message-from message) 'tell
193       #:text "*ring ring!*  You ring the bell!\n")
194   ;; We also want everyone else in the room to "hear" the bell,
195   ;; but they get a different message since they aren't the ones
196   ;; ringing it.  Notice here's where we make use of the invoker's
197   ;; name as extracted and assigned to the who-rang variable.
198   ;; Notice how we send this message to our "location", which
199   ;; forwards it to the rest of the occupants in the room.
200   (<- (gameobj-loc bell) 'tell-room
201       #:text
202       (format #f "*ring ring!*  ~a rings the bell!\n"
203               who-rang)
204       #:exclude (message-from message))
205   ;; Now we perform the primary task of the bell, which is to summon
206   ;; the "clerk" character to the room.  (This is configurable,
207   ;; so we dynamically look up their address.)
208   (<- (dyn-ref bell (slot-ref bell 'summons)) 'be-summoned
209       #:who-summoned (message-from message)))
210
211
212 (define prefect-quotes
213   '("I'm a frood who really knows where my towel is!"
214     "On no account allow a Vogon to read poetry at you."
215     "Time is an illusion, lunchtime doubly so!"
216     "How can you have money if none of you produces anything?"
217     "On no account allow Arthur to request tea on this ship."))
218
219 (define-class <cabinet-item> (<gameobj>)
220   (take-me? #:init-value
221             (lambda _
222               (values #f #:why-not
223                       `("Hm, well... the cabinet is locked and the properitor "
224                         "is right over there.")))))
225
226 (define lobby
227   (lol
228    ('lobby
229     <room> #f
230     #:name "Hotel Lobby"
231     #:desc
232     '((p "You're in some sort of hotel lobby.  You see a large sign hanging "
233          "over the desk that says \"Hotel Bricabrac\".  On the desk is a bell "
234          "that says \"'ring bell' for service\".  Terrible music plays from a speaker "
235          "somewhere overhead.  "
236          "The room is lined with various curio cabinets, filled with all sorts "
237          "of kitschy junk.  It looks like whoever decorated this place had great "
238          "ambitions, but actually assembled it all in a hurry and used whatever "
239          "kind of objects they found lying around.")
240       (p "There's a door to the north leading to some kind of hallway."))
241     #:exits
242     (list (make <exit>
243             #:name "north"
244             #:to 'grand-hallway)))
245    ;; NPC: hotel owner
246    ('lobby:hotel-owner
247     <chatty-npc> 'lobby
248     #:name "a frumpy fellow"
249     #:desc
250     '((p "  Whoever this is, they looks totally exhausted.  They're
251 collapsed into the only comfortable looking chair in the room and you
252 don't get the sense that they're likely to move any time soon.
253   You notice they're wearing a sticker badly adhesed to their clothing
254 which says \"Hotel Proprietor\", but they look so disorganized that you
255 think that can't possibly be true... can it?
256   Despite their exhaustion, you sense they'd be happy to chat with you,
257 though the conversation may be a bit one sided."))
258     #:goes-by '("frumpy fellow" "fellow"
259                 "Chris Webber"  ; heh, did you rtfc?  or was it so obvious?
260                 "hotel proprietor" "proprietor")
261     #:catchphrases hotel-owner-grumps)
262    ;; Object: Sign
263    ('lobby:sign
264     <readable> 'lobby
265     #:name "the Hotel Bricabrac sign"
266     #:desc "  It strikes you that there's something funny going on with this sign.
267 Sure enough, if you look at it hard enough, you can tell that someone
268 hastily painted over an existing sign and changed the \"M\" to an \"H\".
269 Classy!"
270     #:read-text "  All it says is \"Hotel Bricabrac\" in smudged, hasty text."
271     #:goes-by '("sign"
272                 "bricabrac sign"
273                 "hotel sign"
274                 "hotel bricabrac sign"
275                 "lobby sign"))
276
277    ('lobby:bell
278     <summoning-bell> 'lobby
279     #:name "a shiny brass bell"
280     #:goes-by '("shiny brass bell" "shiny bell" "brass bell" "bell")
281     #:desc "  A shiny brass bell.  Inscribed on its wooden base is the text
282 \"ring me for service\".  You probably could \"ring the bell\" if you 
283 wanted to."
284     #:summons 'break-desk-clerk)
285
286    ('lobby:sign-in-form
287     <sign-in-form> 'lobby
288     #:name "sign-in form"
289     #:goes-by '("sign-in form" "form" "signin form")
290     #:desc "It looks like you could sign this form and set your name.")
291
292    ;; Object: curio cabinets
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 grand-hallway
417   (lol
418    ('grand-hallway
419     <room> #f
420     #:name "Grand Hallway"
421     #:desc '((p "  A majestic red carpet runs down the center of the room.
422 Busts of serious looking people line the walls, but there's no
423 clear indication that they have any logical relation to this place.")
424              (p "In the center is a large statue of a woman in a warrior's
425 pose, but something is strange about her weapon and shield.  You wonder what
426 that's all about?")
427              (p "To the south is the lobby.  A door to the east is labeled \"smoking
428 room\", while a door to the west is labeled \"playroom\"."))
429     #:exits
430     (list (make <exit>
431             #:name "south"
432             #:to 'lobby)
433           (make <exit>
434             #:name "west"
435             #:to 'playroom)
436           (make <exit>
437             #:name "east"
438             #:to 'smoking-parlor)))
439    ('grand-hallway:carpet
440     <gameobj> 'grand-hallway
441     #:name "the Grand Hallway carpet"
442     #:desc "It's very red, except in the places where it's very worn."
443     #:invisible? #t
444     #:goes-by '("red carpet" "carpet"))
445    ('grand-hallway:busts
446     <gameobj> 'grand-hallway
447     #:name "the busts of serious people"
448     #:desc "There are about 6 of them in total.  They look distinguished
449 but there's no indication of who they are."
450     #:invisible? #t
451     #:goes-by '("busts" "bust" "busts of serious people" "bust of serious person"))
452    ('grand-hallway:hackthena-statue
453     <proxy-items> 'grand-hallway
454     #:name "the statue of Hackthena"
455     #:desc '((p "The base of the statue says \"Hackthena, guardian of the hacker
456 spirit\".  You've heard of Hackthena... not a goddess, but spiritual protector of
457 all good hacks, and legendary hacker herself.")
458              (p "Hackthena holds the form of a human woman.  She wears flowing
459 robes, has a pear of curly bovine-esque horns protruding from the sides of her
460 head, wears a pair of horn-rimmed glasses, and appears posed as if for battle.
461 But instead of a weapon, she seems to hold some sort of keyboard.  And her
462 shield... well it's round like a shield, but something seems off about it.
463 You'd better take a closer look to be sure."))
464     #:goes-by '("hackthena statue" "hackthena" "statue" "statue of hackthena")
465     #:proxy-items '(grand-hallway:keyboard
466                     grand-hallway:disc-platter
467                     grand-hallway:hackthena-horns))
468    ('grand-hallway:keyboard
469     <gameobj> 'grand-hallway
470     #:name "a Knight Keyboard"
471     #:desc "Whoa, this isn't just any old keyboard, this is a Knight Keyboard!
472 Any space cadet can see that with that kind of layout a hack-and-slayer could
473 thrash out some serious key-chords like there's no tomorrow.  You guess
474 Hackthena must be an emacs user."
475     #:invisible? #t
476     #:take-me? (lambda _
477                  (values #f
478                          #:why-not
479                          `("Are you kidding?  Do you know how hard it is to find "
480                               "a Knight Keyboard?  There's no way she's going "
481                               "to give that up.")))
482     #:goes-by '("knight keyboard" "keyboard"))
483    ('grand-hallway:hackthena-horns
484     <gameobj> 'grand-hallway
485     #:name "Hackthena's horns"
486     #:desc "They're not unlike a Gnu's horns."
487     #:invisible? #t
488     #:take-me? (lambda _
489                  (values #f
490                          #:why-not
491                          `("Are you seriously considering desecrating a statue?")))
492     #:goes-by '("hackthena's horns" "horns" "horns of hacktena"))
493    ('grand-hallway:disc-platter
494     <gameobj> 'grand-hallway
495     #:name "a hard disc platter"
496     #:desc "This isn't a shield after all, it seems to be a hard disc
497 platter!  It looks kind of loose..."
498     #:invisible? #t
499     #:goes-by '("hard disc platter" "disc platter" "disc" "shield" "platter"))))
500
501 \f
502 ;;; Playroom
503 ;;; --------
504
505 (define playroom
506   (lol
507    ('playroom
508     <room> #f
509     #:name "The Playroom"
510     #:desc "  There are toys scattered everywhere here.  It's really unclear
511 if this room is intended for children or child-like adults."
512     #:exits
513     (list (make <exit>
514             #:name "east"
515             #:to 'grand-hallway)))
516    ('playroom:cubey
517     <gameobj> 'playroom
518     #:name "Cubey"
519     #:take-me? #t
520     #:desc "  It's a little foam cube with googly eyes on it.  So cute!")
521    ('playroom:cuddles-plushie
522     <gameobj> 'playroom
523     #:name "a Cuddles plushie"
524     #:goes-by '("plushie" "cuddles plushie" "cuddles")
525     #:take-me? #t
526     #:desc "  A warm and fuzzy cuddles plushie!  It's a cuddlefish!")
527
528    ('playroom:toy-chest
529     <container> 'playroom
530     #:name "a toy chest"
531     #:goes-by '("toy chest" "chest")
532     #:desc (lambda (toy-chest whos-looking)
533              (let ((contents (gameobj-occupants toy-chest)))
534                `((p "A brightly painted wooden chest.  The word \"TOYS\" is "
535                     "engraved on it.")
536                  (p "Inside you see:"
537                     ,(if (eq? contents '())
538                          " nothing!  It's empty!"
539                          `(ul ,(map (lambda (occupant)
540                                       `(li ,(mbody-val
541                                              (<-wait occupant 'get-name))))
542                                     (gameobj-occupants toy-chest))))))))
543     #:take-from-me? #t
544     #:put-in-me? #t)
545
546    ;; Things inside the toy chest
547    ('playroom:toy-chest:rubber-duck
548     <gameobj> 'playroom:toy-chest
549     #:name "a rubber duck"
550     #:goes-by '("rubber duck" "duck")
551     #:take-me? #t
552     #:desc "It's a yellow rubber duck with a bright orange beak.")))
553
554
555 \f
556 ;;; Writing room
557 ;;; ------------
558
559 \f
560 ;;; Armory???
561 ;;; ---------
562
563 ;; ... full of NURPH weapons?
564
565 \f
566 ;;; Smoking parlor
567 ;;; --------------
568
569 (define-class <furniture> (<gameobj>)
570   (sit-phrase #:init-keyword #:sit-phrase)
571   (sit-phrase-third-person #:init-keyword #:sit-phrase-third-person)
572   (sit-name #:init-keyword #:sit-name)
573
574   (commands
575    #:allocation #:each-subclass
576    #:init-thunk (build-commands
577                  ("sit" ((direct-command cmd-sit-furniture)))))
578   (actions #:allocation #:each-subclass
579            #:init-thunk (build-actions
580                          (cmd-sit-furniture furniture-cmd-sit))))
581
582 (define* (furniture-cmd-sit actor message #:key direct-obj)
583   (define player-name
584     (mbody-val (<-wait (message-from message) 'get-name)))
585   (<- (message-from message) 'tell
586       #:text (format #f "You ~a ~a.\n"
587                      (slot-ref actor 'sit-phrase)
588                      (slot-ref actor 'sit-name)))
589   (<- (slot-ref actor 'loc) 'tell-room
590       #:text (format #f "~a ~a on ~a.\n"
591                      player-name
592                      (slot-ref actor 'sit-phrase-third-person)
593                      (slot-ref actor 'sit-name))
594       #:exclude (message-from message)))
595
596
597 (define smoking-parlor
598   (lol
599    ('smoking-parlor
600     <room> #f
601     #:name "Smoking Parlor"
602     #:desc
603     '((p "This room looks quite posh.  There are huge comfy seats you can sit in
604 if you like. Strangely, you see a large sign saying \"No Smoking\".  The owners must
605 have installed this place and then changed their mind later.")
606       (p "There's a door to the west leading back to the grand hallway, and
607 a nondescript steel door to the south, leading apparently outside."))
608     #:exits
609     (list (make <exit>
610             #:name "west"
611             #:to 'grand-hallway)
612           (make <exit>
613             #:name "south"
614             #:to 'break-room)))
615    ('smoking-parlor:chair
616     <furniture> 'smoking-parlor
617     #:name "a comfy leather chair"
618     #:desc "  That leather chair looks really comfy!"
619     #:goes-by '("leather chair" "comfy leather chair" "chair")
620     #:sit-phrase "sink into"
621     #:sit-phrase-third-person "sinks into"
622     #:sit-name "the comfy leather chair")
623    ('smoking-parlor:sofa
624     <furniture> 'smoking-parlor
625     #:name "a plush leather sofa"
626     #:desc "  That leather chair looks really comfy!"
627     #:goes-by '("leather sofa" "plush leather sofa" "sofa"
628                 "leather couch" "plush leather couch" "couch")
629     #:sit-phrase "sprawl out on"
630     #:sit-phrase-third-person "sprawls out on into"
631     #:sit-name "the plush leather couch")
632    ('smoking-parlor:bar-stool
633     <furniture> 'smoking-parlor
634     #:name "a bar stool"
635     #:desc "  Conveniently located near the bar!  Not the most comfortable
636 seat in the room, though."
637     #:goes-by '("stool" "bar stool" "seat")
638     #:sit-phrase "hop on"
639     #:sit-phrase-third-person "hops onto"
640     #:sit-name "the bar stool")
641    ('ford-prefect
642     <chatty-npc> 'smoking-parlor
643     #:name "Ford Prefect"
644     #:desc "Just some guy, you know?"
645     #:goes-by '("Ford Prefect" "ford prefect"
646                 "frood" "prefect" "ford")
647     #:catchphrases prefect-quotes)
648
649    ('smoking-parlor:no-smoking-sign
650     <gameobj> 'smoking-parlor
651     #:invisible? #t
652     #:name "No Smoking Sign"
653     #:desc "This sign says \"No Smoking\" in big, red letters.
654 It has some bits of bubble gum stuck to it... yuck."
655     #:goes-by '("no smoking sign" "sign"))
656
657    ;; TODO: Cigar dispenser
658    ))
659
660 \f
661
662 ;;; Breakroom
663 ;;; ---------
664
665 (define-class <desk-clerk> (<gameobj>)
666   ;; The desk clerk has three states:
667   ;;  - on-duty: Arrived, and waiting for instructions (and losing patience
668   ;;    gradually)
669   ;;  - slacking: In the break room, probably smoking a cigarette
670   ;;    or checking text messages
671   (state #:init-value 'slacking)
672   (commands #:allocation #:each-subclass
673             #:init-thunk
674             (build-commands
675              (("talk" "chat") ((direct-command cmd-chat)))
676              ("ask" ((direct-command cmd-ask-incomplete)
677                      (prep-direct-command cmd-ask-about)))
678              ("dismiss" ((direct-command cmd-dismiss)))))
679   (patience #:init-value 0)
680   (actions #:allocation #:each-subclass
681            #:init-thunk (build-actions
682                          (init clerk-act-init)
683                          (cmd-chat clerk-cmd-chat)
684                          (cmd-ask-incomplete clerk-cmd-ask-incomplete)
685                          (cmd-ask-about clerk-cmd-ask)
686                          (cmd-dismiss clerk-cmd-dismiss)
687                          (update-loop clerk-act-update-loop)
688                          (be-summoned clerk-act-be-summoned))))
689
690 (define (clerk-act-init clerk message . _)
691   ;; call the gameobj main init method
692   (gameobj-act-init clerk message)
693   ;; start our main loop
694   (<- (actor-id clerk) 'update-loop))
695
696 (define clerk-help-topics
697   '(("changing name" .
698      "Changing your name is easy!  We have a clipboard here at the desk
699 where you can make yourself known to other participants in the hotel
700 if you sign it.  Try 'sign form as <your-name>', replacing
701 <your-name>, obviously!")
702     ("common commands" .
703      "Here are some useful commands you might like to try: chat,
704 go, take, drop, say...")
705     ("hotel" .
706      "We hope you enjoy your stay at Hotel Bricabrac.  As you may see,
707 our hotel emphasizes interesting experiences over rest and lodging.
708 The origins of the hotel are... unclear... and it has recently come
709 under new... 'management'.  But at Hotel Bricabrac we believe these
710 aspects make the hotel into a fun and unique experience!  Please,
711 feel free to walk around and explore.")))
712
713
714 (define clerk-knows-about
715   "'ask clerk about changing name', 'ask clerk about common commands', and 'ask clerk about the hotel'")
716
717 (define clerk-general-helpful-line
718   (string-append
719    "The clerk says, \"If you need help with anything, feel free to ask me about it.
720 For example, 'ask clerk about changing name'. You can ask me about the following:
721 " clerk-knows-about ".\"\n"))
722
723 (define clerk-slacking-complaints
724   '("The pay here is absolutely lousy."
725     "The owner here has no idea what they're doing."
726     "Some times you just gotta step away, you know?"
727     "You as exhausted as I am?"
728     "Yeah well, this is just temporary.  I'm studying to be a high
729 energy particle physicist.  But ya gotta pay the bills, especially
730 with tuition at where it is..."))
731
732 (define* (clerk-cmd-chat clerk message #:key direct-obj)
733   (match (slot-ref clerk 'state)
734     ('on-duty
735      (<- (message-from message) 'tell
736          #:text clerk-general-helpful-line))
737     ('slacking
738      (<- (message-from message) 'tell
739          #:text
740          (string-append
741           "The clerk says, \""
742           (random-choice clerk-slacking-complaints)
743           "\"\n")))))
744
745 (define (clerk-cmd-ask-incomplete clerk message . _)
746   (<- (message-from message) 'tell
747       #:text "The clerk says, \"Ask about what?\"\n"))
748
749 (define clerk-doesnt-know-text
750   "The clerk apologizes and says she doesn't know about that topic.\n")
751
752 (define* (clerk-cmd-ask clerk message #:key indir-obj
753                         #:allow-other-keys)
754   (match (slot-ref clerk 'state)
755     ('on-duty
756      (match (assoc (pk 'indir indir-obj) clerk-help-topics)
757        ((_ . info)
758            (<- (message-from message) 'tell
759                #:text
760                (string-append "The clerk clears her throat and says:\n  \""
761                               info
762                               "\"\n")))
763        (#f
764         (<- (message-from message) 'tell
765             #:text clerk-doesnt-know-text))))
766     ('slacking
767      (<- (message-from message) 'tell
768          #:text "The clerk says, \"Sorry, I'm on my break.\"\n"))))
769
770 (define* (clerk-act-be-summoned clerk message #:key who-summoned)
771   (match (slot-ref clerk 'state)
772     ('on-duty
773      (<- who-summoned 'tell
774          #:text
775          "The clerk tells you as politely as she can that she's already here,
776 so there's no need to ring the bell.\n"))
777     ('slacking
778      (<- (gameobj-loc clerk) 'tell-room
779          #:text
780          "The clerk's ears perk up, she stamps out a cigarette, and she
781 runs out of the room!\n")
782      (gameobj-set-loc! clerk (dyn-ref clerk 'lobby))
783      (slot-set! clerk 'patience 8)
784      (slot-set! clerk 'state 'on-duty)
785      (<- (gameobj-loc clerk) 'tell-room
786          #:text
787          (string-append
788           "  Suddenly, a uniformed woman rushes into the room!  She's wearing a
789 badge that says \"Desk Clerk\".
790   \"Hello, yes,\" she says between breaths, \"welcome to Hotel Bricabrac!
791 We look forward to your stay.  If you'd like help getting acclimated,
792 feel free to ask me.  For example, 'ask clerk about changing name'.
793 You can ask me about the following:
794 " clerk-knows-about ".\"\n")))))
795
796 (define* (clerk-cmd-dismiss clerk message . _)
797   (define player-name
798     (mbody-val (<-wait (message-from message) 'get-name)))
799   (match (slot-ref clerk 'state)
800     ('on-duty
801      (<- (gameobj-loc clerk) 'tell-room
802          #:text
803          (format #f "\"Thanks ~a!\" says the clerk. \"I have somewhere I need to be.\"
804 The clerk leaves the room in a hurry.\n"
805                  player-name)
806          #:exclude (actor-id clerk))
807      (gameobj-set-loc! clerk (dyn-ref clerk 'break-room))
808      (slot-set! clerk 'state 'slacking)
809      (<- (gameobj-loc clerk) 'tell-room
810          #:text clerk-return-to-slacking-text
811          #:exclude (actor-id clerk)))
812     ('slacking
813      (<- (message-from message) 'tell
814          #:text "The clerk sternly asks you to not be so dismissive.\n"))))
815
816 (define clerk-slacking-texts
817   '("The clerk takes a long drag on her cigarette.\n"
818     "The clerk scrolls through text messages on her phone.\n"
819     "The clerk coughs a few times.\n"
820     "The clerk checks her watch and justifies a few more minutes outside.\n"
821     "The clerk fumbles around for a lighter.\n"
822     "The clerk sighs deeply and exhaustedly.\n"
823     "The clerk fumbles around for a cigarette.\n"))
824
825 (define clerk-working-impatience-texts
826   '("The clerk hums something, but you're not sure what it is."
827     "The clerk attempts to change the overhead music, but the dial seems broken."
828     "The clerk clicks around on the desk computer."
829     "The clerk scribbles an equation on a memo pad, then crosses it out."
830     "The clerk mutters something about the proprietor having no idea how to run a hotel."
831     "The clerk thumbs through a printout of some physics paper."))
832
833 (define clerk-slack-excuse-text
834   "The desk clerk excuses herself, but says you are welcome to ring the bell
835 if you need further help.")
836
837 (define clerk-return-to-slacking-text
838   "The desk clerk enters and slams the door behind her.\n")
839
840
841 (define (clerk-act-update-loop clerk message)
842   (define (tell-room text)
843     (<- (gameobj-loc clerk) 'tell-room
844         #:text text
845         #:exclude (actor-id clerk)))
846   (define (loop-if-not-destructed)
847     (if (not (slot-ref clerk 'destructed))
848         ;; This iterates by "recursing" on itself by calling itself
849         ;; (as the message handler) again.  It used to be that we had to do
850         ;; this, because there was a bug where a loop which yielded like this
851         ;; would keep growing the stack due to some parameter goofiness.
852         ;; That's no longer true, but there's an added advantage to this
853         ;; route: it's much more live hackable.  If we change the definition
854         ;; of this method, the character will act differently on the next
855         ;; "tick" of the loop.
856         (<- (actor-id clerk) 'update-loop)))
857   (match (slot-ref clerk 'state)
858     ('slacking
859      (tell-room (random-choice clerk-slacking-texts))
860      (8sleep (+ (random 20) 15))
861      (loop-if-not-destructed))
862     ('on-duty
863      (if (> (slot-ref clerk 'patience) 0)
864          ;; Keep working but lose patience gradually
865          (begin
866            (tell-room (random-choice clerk-working-impatience-texts))
867            (slot-set! clerk 'patience (- (slot-ref clerk 'patience)
868                                          (+ (random 2) 1)))
869            (8sleep (+ (random 60) 40))
870            (loop-if-not-destructed))
871          ;; Back to slacking
872          (begin
873            (tell-room clerk-slack-excuse-text)
874            ;; back bto the break room
875            (gameobj-set-loc! clerk (pk 'break-room (dyn-ref clerk 'break-room)))
876            (tell-room clerk-return-to-slacking-text)
877            ;; annnnnd back to slacking
878            (slot-set! clerk 'state 'slacking)
879            (8sleep (+ (random 30) 15))
880            (loop-if-not-destructed))))))
881
882
883 (define break-room
884   (lol
885    ('break-room
886     <room> #f
887     #:name "Employee Break Room"
888     #:desc "  This is less a room and more of an outdoor wire cage.  You get
889 a bit of a view of the brick exterior of the building, and a crisp wind blows,
890 whistling, through the openings of the fenced area.  Partly smoked cigarettes
891 and various other debris cover the floor.
892   Through the wires you can see... well... hm.  It looks oddly like
893 the scenery tapers off nothingness.  But that can't be right, can it?"
894     #:exits
895     (list (make <exit>
896             #:name "north"
897             #:to 'smoking-parlor)))
898    ('break-room:desk-clerk
899     <desk-clerk> 'break-room
900     #:name "the hotel desk clerk"
901     #:desc "  The hotel clerk is wearing a neatly pressed uniform bearing the
902 hotel insignia.  She appears to be rather exhausted."
903     #:goes-by '("hotel desk clerk" "clerk" "desk clerk"))
904    ('break-room:void
905     <gameobj> 'break-room
906     #:invisible? #t
907     #:name "The Void"
908     #:desc "As you stare into the void, the void stares back into you."
909     #:goes-by '("void" "abyss" "nothingness" "scenery"))
910    ('break-room:fence
911     <gameobj> 'break-room
912     #:invisible? #t
913     #:name "break room cage"
914     #:desc "It's a mostly-cubical wire mesh surrounding the break area.
915 You can see through the gaps, but they're too small to put more than a
916 couple of fingers through.  There appears to be some wear and tear to
917 the paint, but the wires themselves seem to be unusually sturdy."
918     #:goes-by '("fence" "cage" "wire cage"))))
919
920
921 \f
922 ;;; Ennpie's Sea Lounge
923 ;;; -------------------
924
925 \f
926 ;;; Computer room
927 ;;; -------------
928
929 \f
930 ;;; Game
931 ;;; ----
932
933 (define (game-spec)
934   (append lobby grand-hallway smoking-parlor
935           playroom break-room))
936
937 ;; TODO: Provide command line args
938 (define (run-game . args)
939   (run-demo (game-spec) 'lobby #:repl-server #t))
940