bricabrac.scm 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  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. ;;; Hotel Bricabrac
  19. (use-modules (mudsync)
  20. (mudsync parser)
  21. (8sync actors)
  22. (8sync agenda)
  23. (oop goops)
  24. (ice-9 control)
  25. (ice-9 format)
  26. (ice-9 match)
  27. (rx irregex))
  28. ;;; Utilities, useful or otherwise
  29. ;;; ==============================
  30. (set! *random-state* (random-state-from-platform))
  31. (define (random-choice lst)
  32. (list-ref lst (random (length lst))))
  33. ;; list of lists, lol.
  34. (define-syntax-rule (lol (list-contents ...) ...)
  35. (list (list list-contents ...) ...))
  36. ;;; Some simple object types.
  37. ;;; =========================
  38. (define readable-commands
  39. (list
  40. (direct-command "read" 'cmd-read)))
  41. (define readable-commands*
  42. (append readable-commands
  43. thing-commands))
  44. (define-class <readable> (<thing>)
  45. (read-text #:init-value "All it says is: \"Blah blah blah.\""
  46. #:init-keyword #:read-text)
  47. (commands
  48. #:init-value readable-commands*)
  49. (actions #:allocation #:each-subclass
  50. #:init-value (build-actions
  51. (cmd-read readable-cmd-read))))
  52. (define (readable-cmd-read actor message)
  53. (<- (message-from message) 'tell
  54. #:text (string-append (slot-ref actor 'read-text) "\n")))
  55. ;;; Lobby
  56. ;;; -----
  57. (define (npc-chat-randomly actor message . _)
  58. (define text-to-send
  59. (format #f "~a says: \"~a\"\n"
  60. (slot-ref actor 'name)
  61. (random-choice (slot-ref actor 'catchphrases))))
  62. (<- (message-from message) 'tell
  63. #:text text-to-send))
  64. (define chat-commands
  65. (list
  66. (direct-command "chat" 'cmd-chat)
  67. (direct-command "talk" 'cmd-chat)))
  68. (define hotel-owner-grumps
  69. '("Eight sinks! Eight sinks! And I couldn't unwind them..."
  70. "Don't mind the mess. I built this place on a dare, you
  71. know?"
  72. "(*tearfully*) Here, take this parenthesis. May it serve
  73. you well."
  74. "I gotta get back to the goblin farm soon..."
  75. "Oh, but I was going to make a mansion... a great,
  76. beautiful mansion! Full of ghosts! Now all I have is this cruddy
  77. mo... hotel. Oh... If only I had more time!"
  78. "I told them to paint more of the walls purple.
  79. Why didn't they listen?"
  80. "Listen to that overhead muzak. Whoever made that doesn't
  81. know how to compose very well! Have you heard of the bands 'fmt'
  82. or 'skribe'? Now *that's* composition!"))
  83. (define-class <chatty-npc> (<gameobj>)
  84. (catchphrases #:init-value '("Blarga blarga blarga!")
  85. #:init-keyword #:catchphrases)
  86. (commands
  87. #:init-value chat-commands)
  88. (actions #:allocation #:each-subclass
  89. #:init-value
  90. (build-actions
  91. (cmd-chat npc-chat-randomly))))
  92. (define random-bricabrac
  93. '("a creepy porcelain doll"
  94. "assorted 1950s robots"
  95. "an exquisite tea set"
  96. "an antique mustard pot"
  97. "the pickled head of Elvis"
  98. "the pickled circuitboard of EVLIS"
  99. "a scroll of teletype paper holding the software Four Freedoms"
  100. "a telephone shaped like an orange cartoon cat"))
  101. (define-class <sign-in-form> (<gameobj>)
  102. (commands
  103. #:init-value
  104. (list
  105. (prep-direct-command "sign" 'cmd-sign-form
  106. '("as"))))
  107. (actions #:allocation #:each-subclass
  108. #:init-value (build-actions
  109. (cmd-sign-form sign-cmd-sign-in))))
  110. (define name-sre
  111. (sre->irregex '(: alpha (** 1 14 (or alphanum "-" "_")))))
  112. (define forbidden-words
  113. (append article preposition
  114. '("and" "or" "but" "admin")))
  115. (define (valid-name? name)
  116. (and (irregex-match name-sre name)
  117. (not (member name forbidden-words))))
  118. (define* (sign-cmd-sign-in actor message
  119. #:key direct-obj indir-obj preposition)
  120. (define old-name
  121. (mbody-val (<-wait (message-from message) 'get-name)))
  122. (define name indir-obj)
  123. (if (valid-name? indir-obj)
  124. (begin
  125. (<-wait (message-from message) 'set-name! name)
  126. (<- (slot-ref actor 'loc) 'tell-room
  127. #:text (format #f "~a signs the form!\n~a is now known as ~a\n"
  128. old-name old-name name)))
  129. (<- (message-from message) 'tell
  130. #:text "Sorry, that's not a valid name.
  131. Alphanumerics, _ and - only, 2-15 characters, starts with an alphabetic
  132. character.\n")))
  133. (define summoning-bell-commands
  134. (list
  135. (direct-command "ring" 'cmd-ring)))
  136. (define summoning-bell-commands*
  137. (append summoning-bell-commands
  138. thing-commands*))
  139. (define-class <summoning-bell> (<thing>)
  140. (summons #:init-keyword #:summons)
  141. (commands
  142. #:init-value summoning-bell-commands*)
  143. (actions #:allocation #:each-subclass
  144. #:init-value (build-actions
  145. (cmd-ring summoning-bell-cmd-ring))))
  146. (define* (summoning-bell-cmd-ring bell message . _)
  147. ;; Call back to actor who invoked this message handler
  148. ;; and find out their name. We'll call *their* get-name message
  149. ;; handler... meanwhile, this procedure suspends until we get
  150. ;; their response.
  151. (define who-rang
  152. (mbody-val (<-wait (message-from message) 'get-name)))
  153. ;; Now we'll invoke the "tell" message handler on the player
  154. ;; who rang us, displaying this text on their screen.
  155. ;; This one just uses <- instead of <-wait, since we don't
  156. ;; care when it's delivered; we're not following up on it.
  157. (<- (message-from message) 'tell
  158. #:text "*ring ring!* You ring the bell!\n")
  159. ;; We also want everyone else in the room to "hear" the bell,
  160. ;; but they get a different message since they aren't the ones
  161. ;; ringing it. Notice here's where we make use of the invoker's
  162. ;; name as extracted and assigned to the who-rang variable.
  163. ;; Notice how we send this message to our "location", which
  164. ;; forwards it to the rest of the occupants in the room.
  165. (<- (gameobj-loc bell) 'tell-room
  166. #:text
  167. (format #f "*ring ring!* ~a rings the bell!\n"
  168. who-rang)
  169. #:exclude (message-from message))
  170. ;; Now we perform the primary task of the bell, which is to summon
  171. ;; the "clerk" character to the room. (This is configurable,
  172. ;; so we dynamically look up their address.)
  173. (<- (dyn-ref bell (slot-ref bell 'summons)) 'be-summoned
  174. #:who-summoned (message-from message)))
  175. (define prefect-quotes
  176. '("I'm a frood who really knows where my towel is!"
  177. "On no account allow a Vogon to read poetry at you."
  178. "Time is an illusion, lunchtime doubly so!"
  179. "How can you have money if none of you produces anything?"
  180. "On no account allow Arthur to request tea on this ship."))
  181. (define lobby
  182. (lol
  183. ('room:lobby
  184. <room> #f
  185. #:name "Hotel Lobby"
  186. #:desc
  187. " You're in some sort of hotel lobby. You see a large sign hanging
  188. over the desk that says \"Hotel Bricabrac\". On the desk is a bell
  189. that says \"'ring bell' for service\". Terrible music plays from a speaker
  190. somewhere overhead.
  191. The room is lined with various curio cabinets, filled with all sorts
  192. of kitschy junk. It looks like whoever decorated this place had great
  193. ambitions, but actually assembled it all in a hurry and used whatever
  194. kind of objects they found lying around.
  195. There's a door to the north leading to some kind of hallway."
  196. #:exits
  197. (list (make <exit>
  198. #:name "north"
  199. #:to 'room:grand-hallway)))
  200. ;; NPC: hotel owner
  201. ('npc:lobby:hotel-owner
  202. <chatty-npc> 'room:lobby
  203. #:name "a frumpy fellow"
  204. #:desc " Whoever this is, they looks totally exhausted. They're
  205. collapsed into the only comfortable looking chair in the room and you
  206. don't get the sense that they're likely to move any time soon.
  207. You notice they're wearing a sticker badly adhesed to their clothing
  208. which says \"Hotel Proprietor\", but they look so disorganized that you
  209. think that can't possibly be true... can it?
  210. Despite their exhaustion, you sense they'd be happy to chat with you,
  211. though the conversation may be a bit one sided."
  212. #:goes-by '("frumpy fellow" "fellow"
  213. "Chris Webber" ; heh, did you rtfc? or was it so obvious?
  214. "hotel proprietor" "proprietor")
  215. #:catchphrases hotel-owner-grumps)
  216. ;; Object: Sign
  217. ('thing:lobby:sign
  218. <readable> 'room:lobby
  219. #:name "the Hotel Bricabrac sign"
  220. #:desc " It strikes you that there's something funny going on with this sign.
  221. Sure enough, if you look at it hard enough, you can tell that someone
  222. hastily painted over an existing sign and changed the \"M\" to an \"H\".
  223. Classy!"
  224. #:read-text " All it says is \"Hotel Bricabrac\" in smudged, hasty text."
  225. #:goes-by '("sign"
  226. "bricabrac sign"
  227. "hotel sign"
  228. "hotel bricabrac sign"
  229. "lobby sign"))
  230. ('thing:lobby:bell
  231. <summoning-bell> 'room:lobby
  232. #:name "a shiny brass bell"
  233. #:goes-by '("shiny brass bell" "shiny bell" "brass bell" "bell")
  234. #:desc " A shiny brass bell. Inscribed on its wooden base is the text
  235. \"ring me for service\". You probably could \"ring the bell\" if you
  236. wanted to."
  237. #:summons 'npc:break-room:desk-clerk)
  238. ;; Object: curio cabinets
  239. ('thing:lobby:cabinet
  240. <gameobj> 'room:lobby
  241. #:name "a curio cabinet"
  242. #:goes-by '("curio cabinet" "cabinet" "bricabrac cabinet")
  243. #:desc (lambda _
  244. (format #f " The curio cabinet is full of all sorts of oddities!
  245. Something catches your eye!
  246. Ooh, ~a!" (random-choice random-bricabrac))))
  247. ('thing:lobby:sign-in-form
  248. <sign-in-form> 'room:lobby
  249. #:name "sign-in form"
  250. #:goes-by '("sign-in form" "form" "signin form")
  251. #:desc "It looks like you could sign this form and set your name.")
  252. ;; Object: desk
  253. ;; - Object: bell
  254. ;; - Object: sign in form
  255. ;; - Object: pamphlet
  256. ;; Object: <invisible bell>: reprimands that you want to ring the
  257. ;; bell on the desk
  258. )
  259. )
  260. ;;; Grand hallway
  261. ;;; -------------
  262. (define grand-hallway
  263. (lol
  264. ('room:grand-hallway
  265. <room> #f
  266. #:name "Grand Hallway"
  267. #:desc " A majestic red carpet runs down the center of the room.
  268. Busts of serious looking people line the walls, but there's no
  269. clear indication that they have any logical relation to this place.
  270. In the center is a large statue of a bearded man. You wonder what
  271. that's all about?
  272. To the south is the lobby. A door to the east is labeled \"smoking
  273. room\", while a door to the west is labeled \"playroom\"."
  274. #:exits
  275. (list (make <exit>
  276. #:name "south"
  277. #:to 'room:lobby)
  278. (make <exit>
  279. #:name "west"
  280. #:to 'room:playroom)
  281. (make <exit>
  282. #:name "east"
  283. #:to 'room:smoking-parlor)))
  284. ('thing:ignucius-statue
  285. <gameobj> 'room:grand-hallway
  286. #:name "a statue"
  287. #:desc " The statue is of a serious-looking bearded man with long, flowing hair.
  288. The inscription says \"St. Ignucius\".
  289. It has a large physical halo. Removing it is tempting, but it looks pretty
  290. well fastened."
  291. #:goes-by '("statue" "st ignucius" "st. ignucius"))))
  292. ;;; Playroom
  293. ;;; --------
  294. (define playroom
  295. (lol
  296. ('room:playroom
  297. <room> #f
  298. #:name "The Playroom"
  299. #:desc " There are toys scattered everywhere here. It's really unclear
  300. if this room is intended for children or child-like adults."
  301. #:exits
  302. (list (make <exit>
  303. #:name "east"
  304. #:to 'room:grand-hallway)))
  305. ('thing:playroom:cubey
  306. <thing> 'room:playroom
  307. #:name "cubey"
  308. #:takeable #t
  309. #:desc " It's a little foam cube with googly eyes on it. So cute!")
  310. ('thing:cuddles-plushie
  311. <thing> 'room:playroom
  312. #:name "a cuddles plushie"
  313. #:goes-by '("plushie" "cuddles plushie" "cuddles")
  314. #:takeable #t
  315. #:desc " A warm and fuzzy cuddles plushie! It's a cuddlefish!")))
  316. ;;; Writing room
  317. ;;; ------------
  318. ;;; Armory???
  319. ;;; ---------
  320. ;; ... full of NURPH weapons?
  321. ;;; Smoking parlor
  322. ;;; --------------
  323. (define-class <furniture> (<gameobj>)
  324. (sit-phrase #:init-keyword #:sit-phrase)
  325. (sit-phrase-third-person #:init-keyword #:sit-phrase-third-person)
  326. (sit-name #:init-keyword #:sit-name)
  327. (commands
  328. #:init-value
  329. (list
  330. (direct-command "sit" 'cmd-sit-furniture)))
  331. (actions #:allocation #:each-subclass
  332. #:init-value (build-actions
  333. (cmd-sit-furniture furniture-cmd-sit))))
  334. (define* (furniture-cmd-sit actor message #:key direct-obj)
  335. (define player-name
  336. (mbody-val (<-wait (message-from message) 'get-name)))
  337. (<- (message-from message) 'tell
  338. #:text (format #f "You ~a ~a.\n"
  339. (slot-ref actor 'sit-phrase)
  340. (slot-ref actor 'sit-name)))
  341. (<- (slot-ref actor 'loc) 'tell-room
  342. #:text (format #f "~a ~a on ~a.\n"
  343. player-name
  344. (slot-ref actor 'sit-phrase-third-person)
  345. (slot-ref actor 'sit-name))
  346. #:exclude (message-from message)))
  347. (define smoking-parlor
  348. (lol
  349. ('room:smoking-parlor
  350. <room> #f
  351. #:name "Smoking Parlor"
  352. #:desc " This room looks quite posh. There are huge comfy seats you can sit in
  353. if you like.
  354. Strangely, you see a large sign saying \"No Smoking\". The owners must
  355. have installed this place and then changed their mind later.
  356. There's a door to the west leading back to the grand hallway, and
  357. a nondescript steel door to the south, leading apparently outside."
  358. #:exits
  359. (list (make <exit>
  360. #:name "west"
  361. #:to 'room:grand-hallway)
  362. (make <exit>
  363. #:name "south"
  364. #:to 'room:break-room)))
  365. ('thing:smoking-room:chair
  366. <furniture> 'room:smoking-parlor
  367. #:name "a comfy leather chair"
  368. #:desc " That leather chair looks really comfy!"
  369. #:goes-by '("leather chair" "comfy leather chair" "chair")
  370. #:sit-phrase "sink into"
  371. #:sit-phrase-third-person "sinks into"
  372. #:sit-name "the comfy leather chair")
  373. ('thing:smoking-room:sofa
  374. <furniture> 'room:smoking-parlor
  375. #:name "a plush leather sofa"
  376. #:desc " That leather chair looks really comfy!"
  377. #:goes-by '("leather sofa" "plush leather sofa" "sofa"
  378. "leather couch" "plush leather couch" "couch")
  379. #:sit-phrase "sprawl out on"
  380. #:sit-phrase-third-person "sprawls out on into"
  381. #:sit-name "the plush leather couch")
  382. ('thing:smoking-room:bar-stool
  383. <furniture> 'room:smoking-parlor
  384. #:name "a bar stool"
  385. #:desc " Conveniently located near the bar! Not the most comfortable
  386. seat in the room, though."
  387. #:goes-by '("stool" "bar stool" "seat")
  388. #:sit-phrase "hop on"
  389. #:sit-phrase-third-person "hops onto"
  390. #:sit-name "the bar stool")
  391. ('npc:ford-prefect
  392. <chatty-npc> 'room:smoking-parlor
  393. #:name "Ford Prefect"
  394. #:desc "Just some guy, you know?"
  395. #:goes-by '("Ford Prefect" "ford prefect"
  396. "frood" "prefect" "ford")
  397. #:catchphrases prefect-quotes)
  398. ;; TODO: Cigar dispenser
  399. ))
  400. ;;; Breakroom
  401. ;;; ---------
  402. (define clerk-commands
  403. (list
  404. (direct-command "talk" 'cmd-chat)
  405. (direct-command "chat" 'cmd-chat)
  406. (direct-command "ask" 'cmd-ask-incomplete)
  407. (prep-direct-command "ask" 'cmd-ask-about)
  408. (direct-command "dismiss" 'cmd-dismiss)))
  409. (define clerk-commands*
  410. (append clerk-commands thing-commands*))
  411. (define-class <desk-clerk> (<thing>)
  412. ;; The desk clerk has three states:
  413. ;; - on-duty: Arrived, and waiting for instructions (and losing patience
  414. ;; gradually)
  415. ;; - slacking: In the break room, probably smoking a cigarette
  416. ;; or checking text messages
  417. (state #:init-value 'slacking)
  418. (commands #:init-value clerk-commands*)
  419. (patience #:init-value 0)
  420. (actions #:allocation #:each-subclass
  421. #:init-value (build-actions
  422. (init clerk-act-init)
  423. (cmd-chat clerk-cmd-chat)
  424. (cmd-ask-incomplete clerk-cmd-ask-incomplete)
  425. (cmd-ask-about clerk-cmd-ask)
  426. (cmd-dismiss clerk-cmd-dismiss)
  427. (update-loop clerk-act-update-loop)
  428. (be-summoned clerk-act-be-summoned))))
  429. (define (clerk-act-init clerk message)
  430. ;; call the gameobj main init method
  431. (gameobj-act-init clerk message)
  432. ;; start our main loop
  433. (<- (actor-id clerk) 'update-loop))
  434. (define clerk-help-topics
  435. '(("changing name" .
  436. "Changing your name is easy! We have a clipboard here at the desk
  437. where you can make yourself known to other participants in the hotel
  438. if you sign it. Try 'sign form as <your-name>', replacing
  439. <your-name>, obviously!")
  440. ("common commands" .
  441. "Here are some useful commands you might like to try: chat,
  442. go, take, drop, say...")
  443. ("hotel" .
  444. "We hope you enjoy your stay at Hotel Bricabrac. As you may see,
  445. our hotel emphasizes interesting experiences over rest and lodging.
  446. The origins of the hotel are... unclear... and it has recently come
  447. under new... 'management'. But at Hotel Bricabrac we believe these
  448. aspects make the hotel into a fun and unique experience! Please,
  449. feel free to walk around and explore.")))
  450. (define clerk-knows-about
  451. "'changing name', 'common commands', and 'about the hotel'")
  452. (define clerk-general-helpful-line
  453. (string-append
  454. "The clerk says, \"If you need help with anything, feel free to ask me about it.
  455. For example, 'ask clerk about changing name'. You can ask me about the following:
  456. " clerk-knows-about ".\"\n"))
  457. (define clerk-slacking-complaints
  458. '("The pay here is absolutely lousy."
  459. "The owner here has no idea what they're doing."
  460. "Some times you just gotta step away, you know?"
  461. "You as exhausted as I am?"
  462. "Yeah well, this is just temporary. I'm studying to be a high
  463. energy particle physicist. But ya gotta pay the bills, especially
  464. with tuition at where it is..."))
  465. (define* (clerk-cmd-chat clerk message #:key direct-obj)
  466. (match (slot-ref clerk 'state)
  467. ('on-duty
  468. (<- (message-from message) 'tell
  469. #:text clerk-general-helpful-line))
  470. ('slacking
  471. (<- (message-from message) 'tell
  472. #:text
  473. (string-append
  474. "The clerk says, \""
  475. (random-choice clerk-slacking-complaints)
  476. "\"\n")))))
  477. (define (clerk-cmd-ask-incomplete clerk message)
  478. (<- (message-from message) 'tell
  479. #:text "The clerk says, \"Ask about what?\"\n"))
  480. (define clerk-doesnt-know-text
  481. "The clerk apologizes and says she doesn't know about that topic.\n")
  482. (define* (clerk-cmd-ask clerk message #:key indir-obj
  483. #:allow-other-keys)
  484. (match (slot-ref clerk 'state)
  485. ('on-duty
  486. (match (assoc (pk 'indir indir-obj) clerk-help-topics)
  487. ((_ . info)
  488. (<- (message-from message) 'tell
  489. #:text
  490. (string-append "The clerk clears her throat and says:\n \""
  491. info
  492. "\"\n")))
  493. (#f
  494. (<- (message-from message) 'tell
  495. #:text clerk-doesnt-know-text))))
  496. ('slacking
  497. (<- (message-from message) 'tell
  498. #:text "The clerk says, \"Sorry, I'm on my break.\"\n"))))
  499. (define* (clerk-act-be-summoned clerk message #:key who-summoned)
  500. (match (slot-ref clerk 'state)
  501. ('on-duty
  502. (<- who-summoned 'tell
  503. #:text
  504. "The clerk tells you as politely as she can that she's already here,
  505. so there's no need to ring the bell.\n"))
  506. ('slacking
  507. (<- (gameobj-loc clerk) 'tell-room
  508. #:text
  509. "The clerk's ears perk up, she stamps out a cigarette, and she
  510. runs out of the room!\n")
  511. (gameobj-set-loc! clerk (dyn-ref clerk 'room:lobby))
  512. (slot-set! clerk 'patience 8)
  513. (slot-set! clerk 'state 'on-duty)
  514. (<- (gameobj-loc clerk) 'tell-room
  515. #:text
  516. (string-append
  517. " Suddenly, a uniformed woman rushes into the room! She's wearing a
  518. badge that says \"Desk Clerk\".
  519. \"Hello, yes,\" she says between breaths, \"welcome to Hotel Bricabrac!
  520. We look forward to your stay. If you'd like help getting acclimated,
  521. feel free to ask me. For example, 'ask clerk about changing name'.
  522. You can ask me about the following:
  523. " clerk-knows-about ".\"\n")))))
  524. (define* (clerk-cmd-dismiss clerk message . _)
  525. (define player-name
  526. (mbody-val (<-wait (message-from message) 'get-name)))
  527. (match (slot-ref clerk 'state)
  528. ('on-duty
  529. (<- (gameobj-loc clerk) 'tell-room
  530. #:text
  531. (format #f "\"Thanks ~a!\" says the clerk. \"I have somewhere I need to be.\"
  532. The clerk leaves the room in a hurry.\n"
  533. player-name)
  534. #:exclude (actor-id clerk))
  535. (gameobj-set-loc! clerk (dyn-ref clerk 'room:break-room))
  536. (slot-set! clerk 'state 'slacking)
  537. (<- (gameobj-loc clerk) 'tell-room
  538. #:text clerk-return-to-slacking-text
  539. #:exclude (actor-id clerk)))
  540. ('slacking
  541. (<- (message-from message) 'tell
  542. #:text "The clerk sternly asks you to not be so dismissive.\n"))))
  543. (define clerk-slacking-texts
  544. '("The clerk takes a long drag on her cigarette.\n"
  545. "The clerk scrolls through text messages on her phone.\n"
  546. "The clerk coughs a few times.\n"
  547. "The clerk checks her watch and justifies a few more minutes outside.\n"
  548. "The clerk fumbles around for a lighter.\n"
  549. "The clerk sighs deeply and exhaustedly.\n"
  550. "The clerk fumbles around for a cigarette.\n"))
  551. (define clerk-working-impatience-texts
  552. '("The clerk struggles to retain an interested and polite smile.\n"
  553. "The clerk checks the time on her phone.\n"
  554. "The clerk taps her foot.\n"
  555. "The clerk takes a deep breath.\n"
  556. "The clerk yawns.\n"
  557. "The clerk drums her nails on the counter.\n"
  558. "The clerk clicks around on the desk computer.\n"
  559. "The clerk thumbs through a printout of some physics paper.\n"
  560. "The clerk mutters that her dissertation isn't going to write itself.\n"))
  561. (define clerk-slack-excuse-text
  562. "The desk clerk excuses herself, claiming she has important things to
  563. attend to.\n")
  564. (define clerk-return-to-slacking-text
  565. "The desk clerk enters and slams the door behind her.\n")
  566. (define (clerk-act-update-loop clerk message)
  567. (define (tell-room text)
  568. (<- (gameobj-loc clerk) 'tell-room
  569. #:text text
  570. #:exclude (actor-id clerk)))
  571. (define (loop-if-not-destructed)
  572. (if (not (slot-ref clerk 'destructed))
  573. ;; This iterates by "recursing" on itself by calling itself
  574. ;; (as the message handler) again. It used to be that we had to do
  575. ;; this, because there was a bug where a loop which yielded like this
  576. ;; would keep growing the stack due to some parameter goofiness.
  577. ;; That's no longer true, but there's an added advantage to this
  578. ;; route: it's much more live hackable. If we change the definition
  579. ;; of this method, the character will act differently on the next
  580. ;; "tick" of the loop.
  581. (<- (actor-id clerk) 'update-loop)))
  582. (match (slot-ref clerk 'state)
  583. ('slacking
  584. (tell-room (random-choice clerk-slacking-texts))
  585. (8sleep (+ (random 10) 10))
  586. (loop-if-not-destructed))
  587. ('on-duty
  588. (if (> (slot-ref clerk 'patience) 0)
  589. ;; Keep working but lose patience gradually
  590. (begin
  591. (tell-room (random-choice clerk-working-impatience-texts))
  592. (slot-set! clerk 'patience (- (slot-ref clerk 'patience)
  593. (+ (random 2) 1)))
  594. (8sleep (+ (random 25) 20))
  595. (loop-if-not-destructed))
  596. ;; Back to slacking
  597. (begin
  598. (tell-room clerk-slack-excuse-text)
  599. ;; back bto the break room
  600. (gameobj-set-loc! clerk (pk 'break-room (dyn-ref clerk 'room:break-room)))
  601. (tell-room clerk-return-to-slacking-text)
  602. ;; annnnnd back to slacking
  603. (slot-set! clerk 'state 'slacking)
  604. (8sleep (+ (random 30) 15))
  605. (loop-if-not-destructed))))))
  606. (define break-room
  607. (lol
  608. ('room:break-room
  609. <room> #f
  610. #:name "Employee Break Room"
  611. #:desc " This is less a room and more of an outdoor wire cage. You get
  612. a bit of a view of the brick exterior of the building, and a crisp wind blows,
  613. whistling, through the openings of the fenced area. Partly smoked cigarettes
  614. and various other debris cover the floor.
  615. Through the wires you can see... well... hm. It looks oddly like
  616. the scenery tapers off nothingness. But that can't be right, can it?"
  617. #:exits
  618. (list (make <exit>
  619. #:name "north"
  620. #:to 'room:smoking-parlor))
  621. )
  622. ('npc:break-room:desk-clerk
  623. <desk-clerk> 'room:break-room
  624. #:name "the hotel desk clerk"
  625. #:desc " The hotel clerk is wearing a neatly pressed uniform bearing the
  626. hotel insignia. She looks like she'd much rather be somewhere else."
  627. #:goes-by '("hotel desk clerk" "clerk" "desk clerk"))))
  628. ;;; Ennpie's Sea Lounge
  629. ;;; -------------------
  630. ;;; Computer room
  631. ;;; -------------
  632. ;;; Game
  633. ;;; ----
  634. (define game-spec
  635. (append lobby grand-hallway smoking-parlor
  636. playroom break-room))
  637. ;; TODO: Provide command line args
  638. (define (run-game . args)
  639. (run-demo game-spec 'room:lobby #:repl-server #t))