remove room: and npc: and thing: prefixes
[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 parser)
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 \f
66 ;;; Lobby
67 ;;; -----
68
69 (define (npc-chat-randomly actor message . _)
70   (define text-to-send
71     (format #f "~a says: \"~a\"\n"
72             (slot-ref actor 'name)
73             (random-choice (slot-ref actor 'catchphrases))))
74   (<- (message-from message) 'tell
75       #:text text-to-send))
76
77 (define hotel-owner-grumps
78   '("Eight sinks!  Eight sinks!  And I couldn't unwind them..."
79     "Don't mind the mess.  I built this place on a dare, you
80 know?"
81     "(*tearfully*) Here, take this parenthesis.  May it serve
82 you well."
83     "I gotta get back to the goblin farm soon..."
84     "Oh, but I was going to make a mansion... a great,
85 beautiful mansion!  Full of ghosts!  Now all I have is this cruddy
86 mo... hotel.  Oh... If only I had more time!"
87     "I told them to paint more of the walls purple.
88 Why didn't they listen?"
89     "Listen to that overhead muzak.  Whoever made that doesn't
90 know how to compose very well!  Have you heard of the bands 'fmt'
91 or 'skribe'?  Now *that's* composition!"))
92
93 (define-class <chatty-npc> (<gameobj>)
94   (catchphrases #:init-value '("Blarga blarga blarga!")
95                 #:init-keyword #:catchphrases)
96   (commands
97    #:allocation #:each-subclass
98    #:init-thunk (build-commands
99                  (("chat" "talk") ((direct-command cmd-chat)))))
100   (actions #:allocation #:each-subclass
101            #:init-thunk
102            (build-actions
103             (cmd-chat npc-chat-randomly))))
104
105 (define-class <sign-in-form> (<gameobj>)
106   (commands
107    #:allocation #:each-subclass
108    #:init-thunk (build-commands
109                  ("sign" ((prep-direct-command cmd-sign-form '("as"))))))
110   (actions #:allocation #:each-subclass
111            #:init-thunk (build-actions
112                          (cmd-sign-form sign-cmd-sign-in))))
113
114
115 (define name-sre
116   (sre->irregex '(: alpha (** 1 14 (or alphanum "-" "_")))))
117
118 (define forbidden-words
119   (append article preposition
120           '("and" "or" "but" "admin")))
121
122 (define (valid-name? name)
123   (and (irregex-match name-sre name)
124        (not (member name forbidden-words))))
125
126 (define* (sign-cmd-sign-in actor message
127                            #:key direct-obj indir-obj preposition)
128   (define old-name
129     (mbody-val (<-wait (message-from message) 'get-name)))
130   (define name indir-obj)
131   (if (valid-name? indir-obj)
132       (begin
133         (<-wait (message-from message) 'set-name! name)
134         (<- (slot-ref actor 'loc) 'tell-room
135             #:text (format #f "~a signs the form!\n~a is now known as ~a\n"
136                            old-name old-name name)))
137       (<- (message-from message) 'tell
138           #:text "Sorry, that's not a valid name.
139 Alphanumerics, _ and - only, 2-15 characters, starts with an alphabetic
140 character.\n")))
141
142
143 (define-class <summoning-bell> (<gameobj>)
144   (summons #:init-keyword #:summons)
145
146   (commands
147    #:allocation #:each-subclass
148    #:init-thunk (build-commands
149                  ("ring" ((direct-command cmd-ring)))))
150   (actions #:allocation #:each-subclass
151            #:init-thunk (build-actions
152                          (cmd-ring summoning-bell-cmd-ring))))
153
154 (define* (summoning-bell-cmd-ring bell message . _)
155   ;; Call back to actor who invoked this message handler
156   ;; and find out their name.  We'll call *their* get-name message
157   ;; handler... meanwhile, this procedure suspends until we get
158   ;; their response.
159   (define who-rang
160     (mbody-val (<-wait (message-from message) 'get-name)))
161
162   ;; Now we'll invoke the "tell" message handler on the player
163   ;; who rang us, displaying this text on their screen.
164   ;; This one just uses <- instead of <-wait, since we don't
165   ;; care when it's delivered; we're not following up on it.
166   (<- (message-from message) 'tell
167       #:text "*ring ring!*  You ring the bell!\n")
168   ;; We also want everyone else in the room to "hear" the bell,
169   ;; but they get a different message since they aren't the ones
170   ;; ringing it.  Notice here's where we make use of the invoker's
171   ;; name as extracted and assigned to the who-rang variable.
172   ;; Notice how we send this message to our "location", which
173   ;; forwards it to the rest of the occupants in the room.
174   (<- (gameobj-loc bell) 'tell-room
175       #:text
176       (format #f "*ring ring!*  ~a rings the bell!\n"
177               who-rang)
178       #:exclude (message-from message))
179   ;; Now we perform the primary task of the bell, which is to summon
180   ;; the "clerk" character to the room.  (This is configurable,
181   ;; so we dynamically look up their address.)
182   (<- (dyn-ref bell (slot-ref bell 'summons)) 'be-summoned
183       #:who-summoned (message-from message)))
184
185
186 (define prefect-quotes
187   '("I'm a frood who really knows where my towel is!"
188     "On no account allow a Vogon to read poetry at you."
189     "Time is an illusion, lunchtime doubly so!"
190     "How can you have money if none of you produces anything?"
191     "On no account allow Arthur to request tea on this ship."))
192
193 (define lobby
194   (lol
195    ('lobby
196     <room> #f
197     #:name "Hotel Lobby"
198     #:desc
199     '((p "You're in some sort of hotel lobby.  You see a large sign hanging "
200          "over the desk that says \"Hotel Bricabrac\".  On the desk is a bell "
201          "that says \"'ring bell' for service\".  Terrible music plays from a speaker "
202          "somewhere overhead.  "
203          "The room is lined with various curio cabinets, filled with all sorts "
204          "of kitschy junk.  It looks like whoever decorated this place had great "
205          "ambitions, but actually assembled it all in a hurry and used whatever "
206          "kind of objects they found lying around.")
207       (p "There's a door to the north leading to some kind of hallway."))
208     #:exits
209     (list (make <exit>
210             #:name "north"
211             #:to 'grand-hallway)))
212    ;; NPC: hotel owner
213    ('lobby:hotel-owner
214     <chatty-npc> 'lobby
215     #:name "a frumpy fellow"
216     #:desc
217     '((p "  Whoever this is, they looks totally exhausted.  They're
218 collapsed into the only comfortable looking chair in the room and you
219 don't get the sense that they're likely to move any time soon.
220   You notice they're wearing a sticker badly adhesed to their clothing
221 which says \"Hotel Proprietor\", but they look so disorganized that you
222 think that can't possibly be true... can it?
223   Despite their exhaustion, you sense they'd be happy to chat with you,
224 though the conversation may be a bit one sided."))
225     #:goes-by '("frumpy fellow" "fellow"
226                 "Chris Webber"  ; heh, did you rtfc?  or was it so obvious?
227                 "hotel proprietor" "proprietor")
228     #:catchphrases hotel-owner-grumps)
229    ;; Object: Sign
230    ('lobby:sign
231     <readable> 'lobby
232     #:name "the Hotel Bricabrac sign"
233     #:desc "  It strikes you that there's something funny going on with this sign.
234 Sure enough, if you look at it hard enough, you can tell that someone
235 hastily painted over an existing sign and changed the \"M\" to an \"H\".
236 Classy!"
237     #:read-text "  All it says is \"Hotel Bricabrac\" in smudged, hasty text."
238     #:goes-by '("sign"
239                 "bricabrac sign"
240                 "hotel sign"
241                 "hotel bricabrac sign"
242                 "lobby sign"))
243
244    ('lobby:bell
245     <summoning-bell> 'lobby
246     #:name "a shiny brass bell"
247     #:goes-by '("shiny brass bell" "shiny bell" "brass bell" "bell")
248     #:desc "  A shiny brass bell.  Inscribed on its wooden base is the text
249 \"ring me for service\".  You probably could \"ring the bell\" if you 
250 wanted to."
251     #:summons 'break-desk-clerk)
252
253    ;; Object: curio cabinets
254    ('lobby:cabinet
255     <gameobj> 'lobby
256     #:name "a curio cabinet"
257     #:goes-by '("curio cabinet" "cabinet" "bricabrac cabinet"
258                 "cabinet of curiosities")
259     #:desc (lambda _
260              (format #f "  The curio cabinet is full of all sorts of oddities!
261 Something catches your eye!
262 Ooh, ~a!" (random-choice
263            '("a creepy porcelain doll"
264              "assorted 1950s robots"
265              "an exquisite tea set"
266              "an antique mustard pot"
267              "the pickled head of Elvis"
268              "the pickled circuitboard of EVLIS"
269              "a scroll of teletype paper holding the software Four Freedoms"
270              "a telephone shaped like an orange cartoon cat")))))
271    ('lobby:sign-in-form
272     <sign-in-form> 'lobby
273     #:name "sign-in form"
274     #:goes-by '("sign-in form" "form" "signin form")
275     #:desc "It looks like you could sign this form and set your name.")
276
277    ('lobby:porcelain-doll
278     <gameobj> 'lobby
279     #:invisible? #t
280     #:name "a creepy porcelain doll"
281     #:desc "It strikes you that while the doll is technically well crafted,
282 it's also the stuff of nightmares."
283     #:goes-by '("porcelain doll" "doll"))
284    ('lobby:1950s-robots
285     <gameobj> 'lobby
286     #:invisible? #t
287     #:name "a set of 1950s robots"
288     #:desc "There's a whole set of these 1950s style robots.
289 They seem to be stamped out of tin, and have various decorations of levers
290 and buttons and springs.  Some of them have wind-up knobs on them."
291     #:goes-by '("robot" "robots" "1950s robot" "1950s robots"))
292    ('lobby:tea-set
293     <gameobj> 'lobby
294     #:invisible? #t
295     #:name "a tea set"
296     #:desc "A complete tea set.  Some of the cups are chipped.
297 You can imagine yourself joining a tea party using this set, around a
298 nice table with some doilies, drinking some Earl Grey tea, hot.  Mmmm."
299     #:goes-by '("tea set" "tea"))
300    ('lobby:mustard-pot
301     <gameobj> 'lobby
302     #:invisible? #t
303     #:name "a mustard pot"
304     #:desc '((p "It's a mustard pot.  I mean, it's kind of cool, it has a
305 nice design, and it's an antique, but you can't imagine putting something
306 like this in a museum.")
307              (p "Ha... imagine that... a mustard museum."))
308     #:goes-by '("mustard pot" "antique mustard pot" "mustard"))
309    ('lobby:head-of-elvis
310     <gameobj> 'lobby
311     #:invisible? #t
312     #:name "the pickled head of Elvis"
313     #:desc '((p "It's a jar full of some briny-looking liquid and...
314 a free floating head.  The head looks an awful lot like Elvis, and
315 definitely not the younger Elvis.  The hair even somehow maintains
316 that signature swoop while suspended in liquid.  But of course it's
317 not Elvis.")
318              (p "Oh, wait, it has a label at the bottom which says:
319 \"This is really the head of Elvis\".  Well... maybe don't believe
320 everything you read."))
321     #:goes-by '("pickled head of elvis" "pickled head of Elvis"
322                 "elvis" "Elvis" "head" "pickled head"))
323    ('lobby:circuitboard-of-evlis
324     <gameobj> 'lobby
325     #:invisible? #t
326     #:name "the pickled circuitboard of Evlis"
327     #:desc '((p "It's a circuitboard from a Lisp Machine called EVLIS.
328 This is quite the find, and you bet just about anyone interested in
329 preserving computer history would love to get their hands on this.")
330              (p "Unfortunately, whatever moron did acquire this has
331 no idea what it means to preserve computers, so here it is floating
332 in some kind of briny liquid.  It appears to be heavily corroded.
333 Too bad..."))
334     #:goes-by '("pickled circuitboard of evlis" "pickled circuitboard of Evlis"
335                 "pickled circuitboard of EVLIS"
336                 "evlis" "Evlis" "EVLIS" "circuitboard" "pickled circuitboard"))
337    ('lobby:teletype-scroll
338     <gameobj> 'lobby
339     #:invisible? #t
340     #:name "a scroll of teletype"
341     #:desc '((p "This is a scroll of teletype paper.  It's a bit old
342 and yellowed but the type is very legible.  It says:")
343              (br)
344              (i
345               (p (strong "== The four essential freedoms =="))
346               (p "A program is free software if the program's users have
347 the four essential freedoms: ")
348               (ul (li "The freedom to run the program as you wish, for any purpose (freedom 0).")
349                   (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.")
350                   (li "The freedom to redistribute copies so you can help your neighbor (freedom 2).")
351                   (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.")))
352              (p "You get this feeling that ambiguities in the
353 English language surrounding the word 'free' have lead to a lot of terminology debates."))
354     #:goes-by '("scroll of teletype" "scroll of teletype paper" "teletype scroll"
355                 "teletype paper" "scroll" "four freedoms"
356                 "scroll of teletype paper holding the software Four Freedoms"
357                 "scroll of teletype paper holding the software four freedoms"))
358    ('lobby:orange-cat-phone
359     <gameobj> 'lobby
360     #:invisible? #t
361     #:name "a telephone shaped like an orange cartoon cat"
362     #:desc "It's made out of a cheap plastic, and it's very orange.
363 It resembles a striped tabby, and it's eyes hold the emotion of
364 a being both sleepy and smarmy.
365 You suspect that someone, somewhere made a ton of cash on items holding
366 this general shape in the 1990s."
367     #:goes-by '("orange cartoon cat phone" "orange cartoon cat telephone"
368                 "orange cat phone" "orange cat telephone"
369                 "cartoon cat phone" "cartoon cat"
370                 "cat phone" "cat telephone" "phone" "telephone"))))
371
372
373 \f
374 ;;; Grand hallway
375 ;;; -------------
376
377 (define grand-hallway
378   (lol
379    ('grand-hallway
380     <room> #f
381     #:name "Grand Hallway"
382     #:desc '((p "  A majestic red carpet runs down the center of the room.
383 Busts of serious looking people line the walls, but there's no
384 clear indication that they have any logical relation to this place.")
385              (p "In the center is a large statue of a woman in a warrior's
386 pose, but something is strange about her weapon and shield.  You wonder what
387 that's all about?")
388              (p "To the south is the lobby.  A door to the east is labeled \"smoking
389 room\", while a door to the west is labeled \"playroom\"."))
390     #:exits
391     (list (make <exit>
392             #:name "south"
393             #:to 'lobby)
394           (make <exit>
395             #:name "west"
396             #:to 'playroom)
397           (make <exit>
398             #:name "east"
399             #:to 'smoking-parlor)))
400    ('grand-hallway:hackthena-statue
401     <gameobj> 'grand-hallway
402     #:name "a statue"
403     #:desc '((p "The base of the statue says \"Hackthena, guardian of the hacker
404 spirit\".  You've heard of Hackthena... not a goddess, but spiritual protector of
405 all good hacks, and legendary hacker herself.")
406              (p "Hackthena holds the form of a human woman.  She wears flowing
407 robes, has a pear of curly bovine-esque horns protruding from the sides of her
408 head, wears a pair of horn-rimmed glasses, and appears posed as if for battle.
409 But instead of a weapon, she seems to hold some sort of keyboard.  And her
410 shield... well it's round like a shield, but something seems off about it.
411 You'd better take a closer look to be sure."))
412     #:goes-by '("hackthena statue" "hackthena" "statue"))
413    ))
414
415 \f
416 ;;; Playroom
417 ;;; --------
418
419 (define playroom
420   (lol
421    ('playroom
422     <room> #f
423     #:name "The Playroom"
424     #:desc "  There are toys scattered everywhere here.  It's really unclear
425 if this room is intended for children or child-like adults."
426     #:exits
427     (list (make <exit>
428             #:name "east"
429             #:to 'grand-hallway)))
430    ('playroom:cubey
431     <gameobj> 'playroom
432     #:name "cubey"
433     #:take-me? #t
434     #:desc "  It's a little foam cube with googly eyes on it.  So cute!")
435    ('playroom:cuddles-plushie
436     <gameobj> 'playroom
437     #:name "a cuddles plushie"
438     #:goes-by '("plushie" "cuddles plushie" "cuddles")
439     #:take-me? #t
440     #:desc "  A warm and fuzzy cuddles plushie!  It's a cuddlefish!")
441
442    ('playroom:toy-chest
443     <gameobj> 'playroom
444     #:name "a toy chest"
445     #:goes-by '("toy chest" "chest")
446     #:desc (lambda (toy-chest whos-looking)
447              (let ((contents (gameobj-occupants toy-chest)))
448                `((p "A brightly painted wooden chest.  The word \"TOYS\" is "
449                     "engraved on it.")
450                  (p "Inside you see:"
451                     ,(if (eq? (pk 'contents contents) '())
452                          " nothing!  It's empty!"
453                          `(ul ,(map (lambda (occupant)
454                                       `(li ,(mbody-val
455                                              (<-wait occupant 'get-name))))
456                                     (gameobj-occupants toy-chest))))))))
457     #:take-from-me? #t
458     #:put-in-me? #t)
459
460    ;; Things inside the toy chest
461    ('playroom:toy-chest:rubber-duck
462     <gameobj> 'playroom:toy-chest
463     #:name "a rubber duck"
464     #:goes-by '("rubber duck" "duck")
465     #:take-me? #t
466     #:desc "It's a yellow rubber duck with a bright orange beak.")))
467
468
469 \f
470 ;;; Writing room
471 ;;; ------------
472
473 \f
474 ;;; Armory???
475 ;;; ---------
476
477 ;; ... full of NURPH weapons?
478
479 \f
480 ;;; Smoking parlor
481 ;;; --------------
482
483 (define-class <furniture> (<gameobj>)
484   (sit-phrase #:init-keyword #:sit-phrase)
485   (sit-phrase-third-person #:init-keyword #:sit-phrase-third-person)
486   (sit-name #:init-keyword #:sit-name)
487
488   (commands
489    #:allocation #:each-subclass
490    #:init-thunk (build-commands
491                  ("sit" ((direct-command cmd-sit-furniture)))))
492   (actions #:allocation #:each-subclass
493            #:init-thunk (build-actions
494                          (cmd-sit-furniture furniture-cmd-sit))))
495
496 (define* (furniture-cmd-sit actor message #:key direct-obj)
497   (define player-name
498     (mbody-val (<-wait (message-from message) 'get-name)))
499   (<- (message-from message) 'tell
500       #:text (format #f "You ~a ~a.\n"
501                      (slot-ref actor 'sit-phrase)
502                      (slot-ref actor 'sit-name)))
503   (<- (slot-ref actor 'loc) 'tell-room
504       #:text (format #f "~a ~a on ~a.\n"
505                      player-name
506                      (slot-ref actor 'sit-phrase-third-person)
507                      (slot-ref actor 'sit-name))
508       #:exclude (message-from message)))
509
510
511 (define smoking-parlor
512   (lol
513    ('smoking-parlor
514     <room> #f
515     #:name "Smoking Parlor"
516     #:desc
517     '((p "This room looks quite posh.  There are huge comfy seats you can sit in
518 if you like. Strangely, you see a large sign saying \"No Smoking\".  The owners must
519 have installed this place and then changed their mind later.")
520       (p "There's a door to the west leading back to the grand hallway, and
521 a nondescript steel door to the south, leading apparently outside."))
522     #:exits
523     (list (make <exit>
524             #:name "west"
525             #:to 'grand-hallway)
526           (make <exit>
527             #:name "south"
528             #:to 'break-room)))
529    ('smoking-parlor:chair
530     <furniture> 'smoking-parlor
531     #:name "a comfy leather chair"
532     #:desc "  That leather chair looks really comfy!"
533     #:goes-by '("leather chair" "comfy leather chair" "chair")
534     #:sit-phrase "sink into"
535     #:sit-phrase-third-person "sinks into"
536     #:sit-name "the comfy leather chair")
537    ('smoking-parlor:sofa
538     <furniture> 'smoking-parlor
539     #:name "a plush leather sofa"
540     #:desc "  That leather chair looks really comfy!"
541     #:goes-by '("leather sofa" "plush leather sofa" "sofa"
542                 "leather couch" "plush leather couch" "couch")
543     #:sit-phrase "sprawl out on"
544     #:sit-phrase-third-person "sprawls out on into"
545     #:sit-name "the plush leather couch")
546    ('smoking-parlor:bar-stool
547     <furniture> 'smoking-parlor
548     #:name "a bar stool"
549     #:desc "  Conveniently located near the bar!  Not the most comfortable
550 seat in the room, though."
551     #:goes-by '("stool" "bar stool" "seat")
552     #:sit-phrase "hop on"
553     #:sit-phrase-third-person "hops onto"
554     #:sit-name "the bar stool")
555    ('ford-prefect
556     <chatty-npc> 'smoking-parlor
557     #:name "Ford Prefect"
558     #:desc "Just some guy, you know?"
559     #:goes-by '("Ford Prefect" "ford prefect"
560                 "frood" "prefect" "ford")
561     #:catchphrases prefect-quotes)
562
563    ('smoking-parlor:no-smoking-sign
564     <gameobj> 'smoking-parlor
565     #:invisible? #t
566     #:name "No Smoking Sign"
567     #:desc "This sign says \"No Smoking\" in big, red letters.
568 It has some bits of bubble gum stuck to it... yuck."
569     #:goes-by '("no smoking sign" "sign"))
570
571    ;; TODO: Cigar dispenser
572    ))
573
574 \f
575
576 ;;; Breakroom
577 ;;; ---------
578
579 (define-class <desk-clerk> (<gameobj>)
580   ;; The desk clerk has three states:
581   ;;  - on-duty: Arrived, and waiting for instructions (and losing patience
582   ;;    gradually)
583   ;;  - slacking: In the break room, probably smoking a cigarette
584   ;;    or checking text messages
585   (state #:init-value 'slacking)
586   (commands #:allocation #:each-subclass
587             #:init-thunk
588             (build-commands
589              (("talk" "chat") ((direct-command cmd-chat)))
590              ("ask" ((direct-command cmd-ask-incomplete)
591                      (prep-direct-command cmd-ask-about)))
592              ("dismiss" ((direct-command cmd-dismiss)))))
593   (patience #:init-value 0)
594   (actions #:allocation #:each-subclass
595            #:init-thunk (build-actions
596                          (init clerk-act-init)
597                          (cmd-chat clerk-cmd-chat)
598                          (cmd-ask-incomplete clerk-cmd-ask-incomplete)
599                          (cmd-ask-about clerk-cmd-ask)
600                          (cmd-dismiss clerk-cmd-dismiss)
601                          (update-loop clerk-act-update-loop)
602                          (be-summoned clerk-act-be-summoned))))
603
604 (define (clerk-act-init clerk message . _)
605   ;; call the gameobj main init method
606   (gameobj-act-init clerk message)
607   ;; start our main loop
608   (<- (actor-id clerk) 'update-loop))
609
610 (define clerk-help-topics
611   '(("changing name" .
612      "Changing your name is easy!  We have a clipboard here at the desk
613 where you can make yourself known to other participants in the hotel
614 if you sign it.  Try 'sign form as <your-name>', replacing
615 <your-name>, obviously!")
616     ("common commands" .
617      "Here are some useful commands you might like to try: chat,
618 go, take, drop, say...")
619     ("hotel" .
620      "We hope you enjoy your stay at Hotel Bricabrac.  As you may see,
621 our hotel emphasizes interesting experiences over rest and lodging.
622 The origins of the hotel are... unclear... and it has recently come
623 under new... 'management'.  But at Hotel Bricabrac we believe these
624 aspects make the hotel into a fun and unique experience!  Please,
625 feel free to walk around and explore.")))
626
627
628 (define clerk-knows-about
629   "'ask clerk about changing name', 'ask clerk about common commands', and 'ask clerk about the hotel'")
630
631 (define clerk-general-helpful-line
632   (string-append
633    "The clerk says, \"If you need help with anything, feel free to ask me about it.
634 For example, 'ask clerk about changing name'. You can ask me about the following:
635 " clerk-knows-about ".\"\n"))
636
637 (define clerk-slacking-complaints
638   '("The pay here is absolutely lousy."
639     "The owner here has no idea what they're doing."
640     "Some times you just gotta step away, you know?"
641     "You as exhausted as I am?"
642     "Yeah well, this is just temporary.  I'm studying to be a high
643 energy particle physicist.  But ya gotta pay the bills, especially
644 with tuition at where it is..."))
645
646 (define* (clerk-cmd-chat clerk message #:key direct-obj)
647   (match (slot-ref clerk 'state)
648     ('on-duty
649      (<- (message-from message) 'tell
650          #:text clerk-general-helpful-line))
651     ('slacking
652      (<- (message-from message) 'tell
653          #:text
654          (string-append
655           "The clerk says, \""
656           (random-choice clerk-slacking-complaints)
657           "\"\n")))))
658
659 (define (clerk-cmd-ask-incomplete clerk message . _)
660   (<- (message-from message) 'tell
661       #:text "The clerk says, \"Ask about what?\"\n"))
662
663 (define clerk-doesnt-know-text
664   "The clerk apologizes and says she doesn't know about that topic.\n")
665
666 (define* (clerk-cmd-ask clerk message #:key indir-obj
667                         #:allow-other-keys)
668   (match (slot-ref clerk 'state)
669     ('on-duty
670      (match (assoc (pk 'indir indir-obj) clerk-help-topics)
671        ((_ . info)
672            (<- (message-from message) 'tell
673                #:text
674                (string-append "The clerk clears her throat and says:\n  \""
675                               info
676                               "\"\n")))
677        (#f
678         (<- (message-from message) 'tell
679             #:text clerk-doesnt-know-text))))
680     ('slacking
681      (<- (message-from message) 'tell
682          #:text "The clerk says, \"Sorry, I'm on my break.\"\n"))))
683
684 (define* (clerk-act-be-summoned clerk message #:key who-summoned)
685   (match (slot-ref clerk 'state)
686     ('on-duty
687      (<- who-summoned 'tell
688          #:text
689          "The clerk tells you as politely as she can that she's already here,
690 so there's no need to ring the bell.\n"))
691     ('slacking
692      (<- (gameobj-loc clerk) 'tell-room
693          #:text
694          "The clerk's ears perk up, she stamps out a cigarette, and she
695 runs out of the room!\n")
696      (gameobj-set-loc! clerk (dyn-ref clerk 'lobby))
697      (slot-set! clerk 'patience 8)
698      (slot-set! clerk 'state 'on-duty)
699      (<- (gameobj-loc clerk) 'tell-room
700          #:text
701          (string-append
702           "  Suddenly, a uniformed woman rushes into the room!  She's wearing a
703 badge that says \"Desk Clerk\".
704   \"Hello, yes,\" she says between breaths, \"welcome to Hotel Bricabrac!
705 We look forward to your stay.  If you'd like help getting acclimated,
706 feel free to ask me.  For example, 'ask clerk about changing name'.
707 You can ask me about the following:
708 " clerk-knows-about ".\"\n")))))
709
710 (define* (clerk-cmd-dismiss clerk message . _)
711   (define player-name
712     (mbody-val (<-wait (message-from message) 'get-name)))
713   (match (slot-ref clerk 'state)
714     ('on-duty
715      (<- (gameobj-loc clerk) 'tell-room
716          #:text
717          (format #f "\"Thanks ~a!\" says the clerk. \"I have somewhere I need to be.\"
718 The clerk leaves the room in a hurry.\n"
719                  player-name)
720          #:exclude (actor-id clerk))
721      (gameobj-set-loc! clerk (dyn-ref clerk 'break-room))
722      (slot-set! clerk 'state 'slacking)
723      (<- (gameobj-loc clerk) 'tell-room
724          #:text clerk-return-to-slacking-text
725          #:exclude (actor-id clerk)))
726     ('slacking
727      (<- (message-from message) 'tell
728          #:text "The clerk sternly asks you to not be so dismissive.\n"))))
729
730 (define clerk-slacking-texts
731   '("The clerk takes a long drag on her cigarette.\n"
732     "The clerk scrolls through text messages on her phone.\n"
733     "The clerk coughs a few times.\n"
734     "The clerk checks her watch and justifies a few more minutes outside.\n"
735     "The clerk fumbles around for a lighter.\n"
736     "The clerk sighs deeply and exhaustedly.\n"
737     "The clerk fumbles around for a cigarette.\n"))
738
739 (define clerk-working-impatience-texts
740   '("The clerk hums something, but you're not sure what it is."
741     "The clerk attempts to change the overhead music, but the dial seems broken."
742     "The clerk clicks around on the desk computer."
743     "The clerk scribbles an equation on a memo pad, then crosses it out."
744     "The clerk mutters something about the proprietor having no idea how to run a hotel."
745     "The clerk thumbs through a printout of some physics paper."))
746
747 (define clerk-slack-excuse-text
748   "The desk clerk excuses herself, but says you are welcome to ring the bell
749 if you need further help.")
750
751 (define clerk-return-to-slacking-text
752   "The desk clerk enters and slams the door behind her.\n")
753
754
755 (define (clerk-act-update-loop clerk message)
756   (define (tell-room text)
757     (<- (gameobj-loc clerk) 'tell-room
758         #:text text
759         #:exclude (actor-id clerk)))
760   (define (loop-if-not-destructed)
761     (if (not (slot-ref clerk 'destructed))
762         ;; This iterates by "recursing" on itself by calling itself
763         ;; (as the message handler) again.  It used to be that we had to do
764         ;; this, because there was a bug where a loop which yielded like this
765         ;; would keep growing the stack due to some parameter goofiness.
766         ;; That's no longer true, but there's an added advantage to this
767         ;; route: it's much more live hackable.  If we change the definition
768         ;; of this method, the character will act differently on the next
769         ;; "tick" of the loop.
770         (<- (actor-id clerk) 'update-loop)))
771   (match (slot-ref clerk 'state)
772     ('slacking
773      (tell-room (random-choice clerk-slacking-texts))
774      (8sleep (+ (random 20) 15))
775      (loop-if-not-destructed))
776     ('on-duty
777      (if (> (slot-ref clerk 'patience) 0)
778          ;; Keep working but lose patience gradually
779          (begin
780            (tell-room (random-choice clerk-working-impatience-texts))
781            (slot-set! clerk 'patience (- (slot-ref clerk 'patience)
782                                          (+ (random 2) 1)))
783            (8sleep (+ (random 60) 40))
784            (loop-if-not-destructed))
785          ;; Back to slacking
786          (begin
787            (tell-room clerk-slack-excuse-text)
788            ;; back bto the break room
789            (gameobj-set-loc! clerk (pk 'break-room (dyn-ref clerk 'break-room)))
790            (tell-room clerk-return-to-slacking-text)
791            ;; annnnnd back to slacking
792            (slot-set! clerk 'state 'slacking)
793            (8sleep (+ (random 30) 15))
794            (loop-if-not-destructed))))))
795
796
797 (define break-room
798   (lol
799    ('break-room
800     <room> #f
801     #:name "Employee Break Room"
802     #:desc "  This is less a room and more of an outdoor wire cage.  You get
803 a bit of a view of the brick exterior of the building, and a crisp wind blows,
804 whistling, through the openings of the fenced area.  Partly smoked cigarettes
805 and various other debris cover the floor.
806   Through the wires you can see... well... hm.  It looks oddly like
807 the scenery tapers off nothingness.  But that can't be right, can it?"
808     #:exits
809     (list (make <exit>
810             #:name "north"
811             #:to 'smoking-parlor)))
812    ('break-room:desk-clerk
813     <desk-clerk> 'break-room
814     #:name "the hotel desk clerk"
815     #:desc "  The hotel clerk is wearing a neatly pressed uniform bearing the
816 hotel insignia.  She appears to be rather exhausted."
817     #:goes-by '("hotel desk clerk" "clerk" "desk clerk"))
818    ('break-room:void
819     <gameobj> 'break-room
820     #:invisible? #t
821     #:name "The Void"
822     #:desc "As you stare into the void, the void stares back into you."
823     #:goes-by '("void" "abyss" "nothingness" "scenery"))
824    ('break-room:fence
825     <gameobj> 'break-room
826     #:invisible? #t
827     #:name "break room cage"
828     #:desc "It's a mostly-cubical wire mesh surrounding the break area.
829 You can see through the gaps, but they're too small to put more than a
830 couple of fingers through.  There appears to be some wear and tear to
831 the paint, but the wires themselves seem to be unusually sturdy."
832     #:goes-by '("fence" "cage" "wire cage"))))
833
834
835 \f
836 ;;; Ennpie's Sea Lounge
837 ;;; -------------------
838
839 \f
840 ;;; Computer room
841 ;;; -------------
842
843 \f
844 ;;; Game
845 ;;; ----
846
847 (define (game-spec)
848   (append lobby grand-hallway smoking-parlor
849           playroom break-room))
850
851 ;; TODO: Provide command line args
852 (define (run-game . args)
853   (run-demo (game-spec) 'lobby #:repl-server #t))
854