A bunch of stuff so you can set your own username
[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 systems actors)
24              (8sync agenda)
25              (oop goops)
26              (ice-9 format)
27              (rx irregex))
28
29
30 \f
31 ;;; Utilities, useful or otherwise
32 ;;; ==============================
33
34 (set! *random-state* (random-state-from-platform))
35
36 (define (random-choice lst)
37   (list-ref lst (random (length lst))))
38
39 ;; list of lists, lol.
40 (define-syntax-rule (lol (list-contents ...) ...)
41   (list (list list-contents ...) ...))
42
43 \f
44 ;;; Some simple object types.
45 ;;; =========================
46
47 (define readable-commands
48   (list
49    (direct-command "read" 'cmd-read)))
50 (define readable-actions
51   (build-actions
52    (cmd-read (wrap-apply readable-cmd-read))))
53
54 (define-class <readable> (<gameobj>)
55   (read-text #:init-value "All it says is: \"Blah blah blah.\""
56              #:init-keyword #:read-text)
57   (commands
58    #:init-value readable-commands)
59   (message-handler
60    #:init-value
61    (simple-dispatcher (append gameobj-actions readable-actions))))
62
63 (define (readable-cmd-read actor message)
64   (<- actor (message-from message) 'tell
65       #:text (string-append (slot-ref actor 'read-text) "\n")))
66
67
68 \f
69 ;;; Lobby
70 ;;; -----
71
72 (define-mhandler (npc-chat-randomly actor message)
73   (define text-to-send
74     (format #f "~a says: \"~a\"\n"
75             (slot-ref actor 'name)
76             (random-choice (slot-ref actor 'catchphrases))))
77   (<- actor (message-from message) 'tell
78       #:text text-to-send))
79
80 (define chat-commands
81   (list
82    (direct-command "chat" 'cmd-chat)))
83 (define chat-actions
84   (build-actions
85    (cmd-chat (wrap-apply npc-chat-randomly))))
86
87 (define hotel-owner-grumps
88   '("Eight sinks!  Eight sinks!  And I couldn't unwind them..."
89     "Don't mind the mess.  I built this place on a dare, you
90 know?"
91     "(*tearfully*) Here, take this parenthesis.  May it serve
92 you well."
93     "I gotta get back to the goblin farm soon..."
94     "Oh, but I was going to make a mansion... a great,
95 beautiful mansion!  Full of ghosts!  Now all I have is this cruddy
96 mo... hotel.  Oh... If only I had more time!"
97     "I told them to paint more of the walls purple.
98 Why didn't they listen?"
99     "Listen to that overhead muzak.  Whoever made that doesn't
100 know how to compose very well!  Have you heard of the bands 'fmt'
101 or 'skribe'?  Now *that's* composition!"))
102
103 (define-class <chatty-npc> (<gameobj>)
104   (catchphrases #:init-value '("Blarga blarga blarga!")
105                 #:init-keyword #:catchphrases)
106   (commands
107    #:init-value chat-commands)
108   (message-handler
109    #:init-value
110    (simple-dispatcher (append gameobj-actions chat-actions))))
111
112 (define random-bricabrac
113   '("a creepy porcelain doll"
114     "assorted 1950s robots"
115     "an exquisite tea set"
116     "an antique mustard pot"
117     "the pickled head of Elvis"
118     "the pickled circuitboard of EVLIS"
119     "a scroll of teletype paper holding the software Four Freedoms"
120     "a telephone shaped like an orange cartoon cat"))
121
122 (define-class <sign-in-form> (<gameobj>)
123   (commands
124    #:init-value
125    (list
126     (indir-as-direct-command "sign" 'cmd-sign-form
127                              '("as"))))
128   (message-handler
129    #:init-value
130    (simple-dispatcher
131     (append
132      (build-actions
133       (cmd-sign-form (wrap-apply sign-cmd-sign-in)))
134      gameobj-actions))))
135
136
137 (define name-sre
138   (sre->irregex '(: alpha (** 1 14 (or alphanum "-" "_")))))
139
140 (define forbidden-words
141   (append article preposition
142           '("and" "or" "but" "admin")))
143
144 (define (valid-name? name)
145   (and (irregex-match name-sre name)
146        (not (member name forbidden-words))))
147
148 (define-mhandler (sign-cmd-sign-in actor message direct-obj indir-obj)
149   (define old-name
150     (message-ref
151      (<-wait actor (message-from message) 'get-name)
152      'val))
153   (define name indir-obj)
154   (if (valid-name? indir-obj)
155       (begin
156         (<-wait actor (message-from message) 'set-name!
157                 #:val name)
158         (<- actor (slot-ref actor 'loc) 'tell-room
159             #:text (format #f "~a signs the form!\n~a is now known as ~a\n"
160                            old-name old-name name)))
161       (<- actor (message-from message) 'tell
162           "Sorry, that's not a valid name.
163 Alphanumerics, _ and - only, 2-15 characters, starts with an alphabetic
164 character.")))
165
166
167 (define lobby
168   (lol
169    ('room:lobby
170     <room> #f
171     #:name "Hotel Lobby"
172     #:desc
173     "  You're in some sort of hotel lobby.  You see a large sign hanging
174 over the desk that says \"Hotel Bricabrac\".  On the desk is a bell
175 that says \"ring for service\".  Terrible music plays from a speaker
176 somewhere overhead.
177   The room is lined with various curio cabinets, filled with all sorts
178 of kitschy junk.  It looks like whoever decorated this place had great
179 ambitions, but actually assembled it all in a hurry and used whatever
180 kind of objects they found lying around.
181   There's a door to the north leading to some kind of hallway."
182     #:exits
183     (list (make <exit>
184             #:name "north"
185             #:to-symbol 'room:grand-hallway)))
186    ;; NPC: hotel owner
187    ('npc:hotel-owner
188     <chatty-npc> 'room:lobby
189     #:name "a frumpy fellow"
190     #:desc "  Whoever this is, they looks totally exhausted.  They're
191 collapsed into the only comfortable looking chair in the room and you
192 don't get the sense that they're likely to move any time soon.
193   You notice they're wearing a sticker badly adhesed to their clothing
194 which says \"Hotel Proprietor\", but they look so disorganized that you
195 think that can't possibly be true... can it?
196   Despite their exhaustion, you sense they'd be happy to chat with you,
197 though the conversation may be a bit one sided."
198     #:goes-by '("frumpy fellow" "fellow"
199                 "Chris Webber"  ; heh, did you rtfc?  or was it so obvious?
200                 "hotel proprietor" "proprietor")
201     #:catchphrases hotel-owner-grumps)
202    ;; NPC: desk clerk (comes when you ring the s)
203    ;;   impatient teenager, only stays around for a few minutes
204    ;;   complaining, then leaves.
205    
206    ;; Object: Sign
207    ('thing:lobby-sign
208     <readable> 'room:lobby
209     #:name "the Hotel Bricabrac sign"
210     #:desc "  It strikes you that there's something funny going on with this sign.
211 Sure enough, if you look at it hard enough, you can tell that someone
212 hastily painted over an existing sign and changed the \"M\" to an \"H\".
213 Classy!"
214     #:read-text "  All it says is \"Hotel Bricabrac\" in smudged, hasty text."
215     #:goes-by '("sign"
216                 "bricabrac sign"
217                 "hotel sign"
218                 "hotel bricabrac sign"
219                 "lobby sign"))
220
221    ;; Object: curio cabinets
222    ('thing:cabinet
223     <gameobj> 'room:lobby
224     #:name "a curio cabinet"
225     #:goes-by '("curio cabinet" "cabinet" "bricabrac cabinet")
226     #:desc (lambda _
227              (format #f "  The curio cabinet is full of all sorts of oddities!
228 Something catches your eye!
229 Ooh, ~a!" (random-choice random-bricabrac))))
230    ('thing:sign-in-form
231     <sign-in-form> 'room:lobby
232     #:name "sign-in form"
233     #:goes-by '("sign-in form" "form" "signin form")
234     #:desc "It looks like you could sign this form and set your name.")
235    ;; Object: desk
236    ;;  - Object: bell
237    ;;  - Object: sign in form
238    ;;  - Object: pamphlet
239    ;; Object: <invisible bell>: reprimands that you want to ring the
240    ;;   bell on the desk
241    )
242   )
243
244
245 \f
246 ;;; Grand hallway
247 ;;; -------------
248
249 (define grand-hallway
250   (lol
251    ('room:grand-hallway
252     <room> #f
253     #:name "Grand Hallway"
254     #:desc "  A majestic red carpet runs down the center of the room.
255 Busts of serious looking people line the walls, but there's no
256 clear indication that they have any logical relation to this place.
257   To the south is the lobby.  All around are various doors, but
258 they're all boarded up.  Guess this is still a work in progress, huh?"
259     #:exits
260     (list (make <exit>
261             #:name "south"
262             #:to-symbol 'room:lobby))
263     )))
264
265 \f
266 ;;; Playroom
267 ;;; --------
268
269 \f
270 ;;; Writing room
271 ;;; ------------
272
273 \f
274 ;;; Armory???
275 ;;; ---------
276
277 ;; ... full of NURPH weapons?
278
279 \f
280 ;;; Smoking parlor
281 ;;; --------------
282
283
284 \f
285 ;;; Ennpie's Sea Lounge
286 ;;; -------------------
287
288 \f
289 ;;; Computer room
290 ;;; -------------
291
292 \f
293 ;;; Game
294 ;;; ----
295
296 (define game-spec
297   (append lobby grand-hallway))
298
299 (define (run-game . args)
300   (run-demo "/tmp/bricabrac-game.db" game-spec 'room:lobby))
301