Source:NetHack 5.0.0/src/sounds.c

From NetHackWiki
Jump to navigation Jump to search

Below is the full text to sounds.c from the source code of NetHack 5.0.0. To link to a particular line, write [[Source:NetHack 5.0.0/src/sounds.c#line12]], for example.

The NetHack General Public License applies to screenshots, source code and other content from NetHack.

This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.

1. /* NetHack 5.0	sounds.c	$NHDT-Date: 1736530208 2025/01/10 09:30:08 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.165 $ */
2. /*      Copyright (c) 1989 Janet Walz, Mike Threepoint */
3. /* NetHack may be freely redistributed.  See license for details. */
4. 
5. #include "hack.h"
6. 
7. staticfn boolean throne_mon_sound(struct monst *);
8. staticfn boolean beehive_mon_sound(struct monst *);
9. staticfn boolean morgue_mon_sound(struct monst *);
10. staticfn boolean zoo_mon_sound(struct monst *);
11. staticfn boolean temple_priest_sound(struct monst *);
12. staticfn boolean mon_is_gecko(struct monst *);
13. staticfn int dochat(void);
14. staticfn struct monst *responsive_mon_at(int, int);
15. staticfn int mon_in_room(struct monst *, int);
16. staticfn boolean oracle_sound(struct monst *);
17. 
18. /* this easily could be a macro, but it might overtax dumb compilers */
19. staticfn int
20. mon_in_room(struct monst *mon, int rmtyp)
21. {
22.     int rno = levl[mon->mx][mon->my].roomno;
23.     if (rno >= ROOMOFFSET)
24.         return svr.rooms[rno - ROOMOFFSET].rtype == rmtyp;
25.     return FALSE;
26. }
27. 
28. 
29. staticfn boolean
30. throne_mon_sound(struct monst *mtmp)
31. {
32.     if ((mtmp->msleeping || is_lord(mtmp->data)
33.          || is_prince(mtmp->data)) && !is_animal(mtmp->data)
34.         && mon_in_room(mtmp, COURT)) {
35.         static const char *const throne_msg[4] = {
36.             "the tones of courtly conversation.",
37.             "a sceptre pounded in judgment.",
38.             "Someone shouts \"Off with %s head!\"",
39.             "Queen Beruthiel's cats!",
40.         };
41.         int which = rn2(3) + (Hallucination ? 1 : 0);
42. 
43.         if (which != 2) {
44.             if (which == 0) {
45.                 Soundeffect(se_courtly_conversation, 30);
46.             } else if (which == 1) {
47.                 Soundeffect(se_sceptor_pounding, 100);
48.             }
49.             You_hear1(throne_msg[which]);
50.         } else {
51.             DISABLE_WARNING_FORMAT_NONLITERAL
52.             pline(throne_msg[2], uhis());
53.             RESTORE_WARNING_FORMAT_NONLITERAL
54.         }
55.         return TRUE;
56.     }
57.     return FALSE;
58. }
59. 
60. 
61. staticfn boolean
62. beehive_mon_sound(struct monst *mtmp)
63. {
64.     if ((mtmp->data->mlet == S_ANT && is_flyer(mtmp->data))
65.         && mon_in_room(mtmp, BEEHIVE)) {
66.         int hallu = Hallucination ? 1 : 0;
67. 
68.         switch (rn2(2) + hallu) {
69.         case 0:
70.             Soundeffect(se_low_buzzing, 30);
71.             You_hear("a low buzzing.");
72.             break;
73.         case 1:
74.             Soundeffect(se_angry_drone, 100);
75.             You_hear("an angry drone.");
76.             break;
77.         case 2:
78.             Soundeffect(se_bees, 100);
79.             You_hear("bees in your %sbonnet!",
80.                      uarmh ? "" : "(nonexistent) ");
81.             break;
82.         }
83.         return TRUE;
84.     }
85.     return FALSE;
86. }
87. 
88. staticfn boolean
89. morgue_mon_sound(struct monst *mtmp)
90. {
91.     if ((is_undead(mtmp->data) || is_vampshifter(mtmp))
92.         && mon_in_room(mtmp, MORGUE)) {
93.         int hallu = Hallucination ? 1 : 0;
94.         const char *hair = body_part(HAIR); /* hair/fur/scales */
95. 
96.         switch (rn2(2) + hallu) {
97.         case 0:
98.             You("suddenly realize it is unnaturally quiet.");
99.             break;
100.         case 1:
101.             pline_The("%s on the back of your %s %s up.", hair,
102.                       body_part(NECK), vtense(hair, "stand"));
103.             break;
104.         case 2:
105.             pline_The("%s on your %s %s to stand up.", hair,
106.                       body_part(HEAD), vtense(hair, "seem"));
107.             break;
108.         }
109.         return TRUE;
110.     }
111.     return FALSE;
112. }
113. 
114. staticfn boolean
115. zoo_mon_sound(struct monst *mtmp)
116. {
117.     if ((mtmp->msleeping || is_animal(mtmp->data))
118.         && mon_in_room(mtmp, ZOO)) {
119.         int hallu = Hallucination ? 1 : 0, selection = rn2(2) + hallu;
120.         static const char *const zoo_msg[3] = {
121.             "a sound reminiscent of an elephant stepping on a peanut.",
122.             "a sound reminiscent of a seal barking.", "Doctor Dolittle!",
123.         };
124.         You_hear1(zoo_msg[selection]);
125.         return TRUE;
126.     }
127.     return FALSE;
128. }
129. 
130. staticfn boolean
131. temple_priest_sound(struct monst *mtmp)
132. {
133.     if (mtmp->ispriest && inhistemple(mtmp)
134.         /* priest must be active */
135.         && !helpless(mtmp)
136.         /* hero must be outside this temple */
137.         && temple_occupied(u.urooms) != EPRI(mtmp)->shroom) {
138.         /* Generic temple messages; no attempt to match topic or tone
139.            to the pantheon involved, let alone to the specific deity.
140.            These are assumed to be coming from the attending priest;
141.            asterisk means that the priest must be capable of speech;
142.            pound sign (octathorpe,&c--don't go there) means that the
143.            priest and the altar must not be directly visible (we don't
144.            care if telepathy or extended detection reveals that the
145.            priest is not currently standing on the altar; he's mobile). */
146.         static const char *const temple_msg[] = {
147.             "*someone praising %s.", "*someone beseeching %s.",
148.             "#an animal carcass being offered in sacrifice.",
149.             "*a strident plea for donations.",
150.         };
151.         const char *msg;
152.         int hallu = Hallucination ? 1 : 0;
153.         int trycount = 0,
154.             ax = EPRI(mtmp)->shrpos.x,
155.             ay = EPRI(mtmp)->shrpos.y;
156.         boolean speechless = (mtmp->data->msound <= MS_ANIMAL),
157.             in_sight = canseemon(mtmp) || cansee(ax, ay);
158. 
159.         do {
160.             msg = temple_msg[rn2(SIZE(temple_msg) - 1 + hallu)];
161.             if (strchr(msg, '*') && speechless)
162.                 continue;
163.             if (strchr(msg, '#') && in_sight)
164.                 continue;
165.             break; /* msg is acceptable */
166.         } while (++trycount < 50);
167.         while (!letter(*msg))
168.             ++msg; /* skip control flags */
169.         if (strchr(msg, '%')) {
170.             DISABLE_WARNING_FORMAT_NONLITERAL
171.             You_hear(msg, halu_gname(EPRI(mtmp)->shralign));
172.             RESTORE_WARNING_FORMAT_NONLITERAL
173.         } else
174.             You_hear1(msg);
175.         return TRUE;
176.     }
177.     return FALSE;
178. }
179. 
180. staticfn boolean
181. oracle_sound(struct monst *mtmp)
182. {
183.     if (mtmp->data != &mons[PM_ORACLE])
184.         return FALSE;
185. 
186.     /* and don't produce silly effects when she's clearly visible */
187.     if (Hallucination || !canseemon(mtmp)) {
188.         int hallu = Hallucination ? 1 : 0;
189.         static const char *const ora_msg[5] = {
190.             "a strange wind.",     /* Jupiter at Dodona */
191.             "convulsive ravings.", /* Apollo at Delphi */
192.             "snoring snakes.",     /* AEsculapius at Epidaurus */
193.             "someone say \"No more woodchucks!\"",
194.             "a loud ZOT!" /* both rec.humor.oracle */
195.         };
196.         You_hear1(ora_msg[rn2(3) + hallu * 2]);
197.     }
198.     return TRUE;
199. }
200. 
201. void
202. dosounds(void)
203. {
204.     struct mkroom *sroom;
205.     int hallu, vx, vy;
206.     struct monst *mtmp;
207. 
208.     if (Deaf || !flags.acoustics || u.uswallow || Underwater)
209.         return;
210. 
211.     hallu = Hallucination ? 1 : 0;
212. 
213.     if (svl.level.flags.nfountains && !rn2(400)) {
214.         static const char *const fountain_msg[4] = {
215.             "bubbling water.", "water falling on coins.",
216.             "the splashing of a naiad.", "a soda fountain!",
217.         };
218.         You_hear1(fountain_msg[rn2(3) + hallu]);
219.     }
220.     if (svl.level.flags.nsinks && !rn2(300)) {
221.         static const char *const sink_msg[3] = {
222.             "a slow drip.", "a gurgling noise.", "dishes being washed!",
223.         };
224.         You_hear1(sink_msg[rn2(2) + hallu]);
225.     }
226.     if (svl.level.flags.has_court && !rn2(200)) {
227.         if (get_iter_mons(throne_mon_sound))
228.             return;
229.     }
230.     if (svl.level.flags.has_swamp && !rn2(200)) {
231.         static const char *const swamp_msg[3] = {
232.             "hear mosquitoes!", "smell marsh gas!", /* so it's a smell...*/
233.             "hear Donald Duck!",
234.         };
235.         You1(swamp_msg[rn2(2) + hallu]);
236.         return;
237.     }
238.     if (svl.level.flags.has_vault && !rn2(200)) {
239.         if (!(sroom = search_special(VAULT))) {
240.             /* strange ... */
241.             svl.level.flags.has_vault = 0;
242.             return;
243.         }
244.         if (gd_sound())
245.             switch (rn2(2) + hallu) {
246.             case 1: {
247.                 boolean gold_in_vault = FALSE;
248. 
249.                 for (vx = sroom->lx; vx <= sroom->hx; vx++)
250.                     for (vy = sroom->ly; vy <= sroom->hy; vy++)
251.                         if (g_at(vx, vy))
252.                             gold_in_vault = TRUE;
253.                 if (vault_occupied(u.urooms)
254.                     != (ROOM_INDEX(sroom) + ROOMOFFSET)) {
255.                     if (gold_in_vault) {
256.                         You_hear(!hallu
257.                                      ? "someone counting gold coins."
258.                                      : "the quarterback calling the play.");
259.                     } else {
260.                         Soundeffect(se_someone_searching, 30);
261.                         You_hear("someone searching.");
262.                     }
263.                     break;
264.                 }
265.             }
266.             FALLTHROUGH;
267.                 /*FALLTHRU*/
268.             case 0:
269.                 Soundeffect(se_guards_footsteps, 30);
270.                 You_hear("the footsteps of a guard on patrol.");
271.                 break;
272.             case 2:
273.                 You_hear("Ebenezer Scrooge!");
274.                 break;
275.             }
276.         return;
277.     }
278.     if (svl.level.flags.has_beehive && !rn2(200)) {
279.         if (get_iter_mons(beehive_mon_sound))
280.             return;
281.     }
282.     if (svl.level.flags.has_morgue && !rn2(200)) {
283.         if (get_iter_mons(morgue_mon_sound))
284.             return;
285.     }
286.     if (svl.level.flags.has_barracks && !rn2(200)) {
287.         static const char *const barracks_msg[4] = {
288.             "blades being honed.", "loud snoring.", "dice being thrown.",
289.             "General MacArthur!",
290.         };
291.         int count = 0;
292. 
293.         for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
294.             if (DEADMONSTER(mtmp))
295.                 continue;
296.             if (is_mercenary(mtmp->data)
297. #if 0 /* don't bother excluding these */
298.                 && !strstri(mtmp->data->pmnames[NEUTRAL], "watch")
299.                 && !strstri(mtmp->data->pmnames[NEUTRAL], "guard")
300. #endif
301.                 && mon_in_room(mtmp, BARRACKS)
302.                 /* sleeping implies not-yet-disturbed (usually) */
303.                 && (mtmp->msleeping || ++count > 5)) {
304.                 You_hear1(barracks_msg[rn2(3) + hallu]);
305.                 return;
306.             }
307.         }
308.     }
309.     if (svl.level.flags.has_zoo && !rn2(200)) {
310.         if (get_iter_mons(zoo_mon_sound))
311.             return;
312.     }
313.     if (svl.level.flags.has_shop && !rn2(200)) {
314.         if (!(sroom = search_special(ANY_SHOP))) {
315.             /* strange... */
316.             svl.level.flags.has_shop = 0;
317.             return;
318.         }
319.         if (tended_shop(sroom)
320.             && !strchr(u.ushops, (int) (ROOM_INDEX(sroom) + ROOMOFFSET))) {
321.             static const char *const shop_msg[3] = {
322.                 "someone cursing shoplifters.",
323.                 "the chime of a cash register.", "Neiman and Marcus arguing!",
324.             };
325.             You_hear1(shop_msg[rn2(2) + hallu]);
326.             noisy_shop(sroom);
327.         }
328.         return;
329.     }
330.     if (svl.level.flags.has_temple && !rn2(200)
331.         && !(Is_astralevel(&u.uz) || Is_sanctum(&u.uz))) {
332.         if (get_iter_mons(temple_priest_sound))
333.             return;
334.     }
335.     if (Is_oracle_level(&u.uz) && !rn2(400)) {
336.         if (get_iter_mons(oracle_sound))
337.             return;
338.     }
339. }
340. 
341. static const char *const h_sounds[] = {
342.     "beep",   "boing",   "sing",   "belche", "creak",   "cough",
343.     "rattle", "ululate", "pop",    "jingle", "sniffle", "tinkle",
344.     "eep",    "clatter", "hum",    "sizzle", "twitter", "wheeze",
345.     "rustle", "honk",    "lisp",   "yodel",  "coo",     "burp",
346.     "moo",    "boom",    "murmur", "oink",   "quack",   "rumble",
347.     "twang",  "toot",    "gargle", "hoot",    "warble"
348. };
349. 
350. const char *
351. growl_sound(struct monst *mtmp)
352. {
353.     const char *ret;
354. 
355.     switch (mtmp->data->msound) {
356.     case MS_MEW:
357.     case MS_HISS:
358.         ret = "hiss";
359.         break;
360.     case MS_BARK:
361.     case MS_GROWL:
362.         ret = "growl";
363.         break;
364.     case MS_ROAR:
365.         ret = "roar";
366.         break;
367.     case MS_BELLOW:
368.         ret = "bellow";
369.         break;
370.     case MS_BUZZ:
371.         ret = "buzz";
372.         break;
373.     case MS_SQEEK:
374.         ret = "squeal";
375.         break;
376.     case MS_SQAWK:
377.         ret = "screech";
378.         break;
379.     case MS_NEIGH:
380.         ret = "neigh";
381.         break;
382.     case MS_WAIL:
383.         ret = "wail";
384.         break;
385.     case MS_GROAN:
386.         ret = "groan";
387.         break;
388.     case MS_MOO:
389.         ret = "low";
390.         break;
391.     case MS_SILENT:
392.         ret = "commotion";
393.         break;
394.     default:
395.         ret = "scream";
396.     }
397.     return ret;
398. }
399. 
400. /* the sounds of a seriously abused pet, including player attacking it */
401. void
402. growl(struct monst *mtmp)
403. {
404.     const char *growl_verb = 0;
405. 
406.     if (helpless(mtmp) || mtmp->data->msound == MS_SILENT)
407.         return;
408. 
409.     /* presumably nearness and soundok checks have already been made */
410.     if (Hallucination)
411.         growl_verb = ROLL_FROM(h_sounds);
412.     else
413.         growl_verb = growl_sound(mtmp);
414.     if (growl_verb) {
415.         if (canseemon(mtmp) || !Deaf) {
416.             pline("%s %s!", Monnam(mtmp), vtense((char *) 0, growl_verb));
417.             iflags.last_msg = PLNMSG_GROWL;
418.             if (svc.context.run)
419.                 nomul(0);
420.         }
421.         wake_nearto(mtmp->mx, mtmp->my, mtmp->data->mlevel * 18);
422.     }
423. }
424. 
425. /* the sounds of mistreated pets */
426. void
427. yelp(struct monst *mtmp)
428. {
429.     const char *yelp_verb = 0;
430.     enum sound_effect_entries se = se_yelp;
431. 
432.     if (helpless(mtmp) || !mtmp->data->msound)
433.         return;
434. 
435.     /* presumably nearness and soundok checks have already been made */
436.     if (Hallucination)
437.         yelp_verb = ROLL_FROM(h_sounds);
438.     else
439.         switch (mtmp->data->msound) {
440.         case MS_MEW:
441.             se = se_feline_yelp;
442.             yelp_verb = (!Deaf) ? "yowl" : "arch";
443.             break;
444.         case MS_BARK:
445.         case MS_GROWL:
446.             se = se_canine_yelp;
447.             yelp_verb = (!Deaf) ? "yelp" : "recoil";
448.             break;
449.         case MS_ROAR:
450.             yelp_verb = (!Deaf) ? "snarl" : "bluff";
451.             break;
452.         case MS_SQEEK:
453.             se = se_squeal;
454.             yelp_verb = (!Deaf) ? "squeal" : "quiver";
455.             break;
456.         case MS_SQAWK:
457.             se = se_avian_screak;
458.             yelp_verb = (!Deaf) ? "screak" : "thrash";
459.             break;
460.         case MS_WAIL:
461.             se = se_wail;
462.             yelp_verb = (!Deaf) ? "wail" : "cringe";
463.             break;
464.         }
465.     if (yelp_verb) {
466.         Soundeffect(se, 70);  /* Soundeffect() handles Deaf or not Deaf */
467.         pline("%s %s!", Monnam(mtmp), vtense((char *) 0, yelp_verb));
468.         if (svc.context.run)
469.             nomul(0);
470.         wake_nearto(mtmp->mx, mtmp->my, mtmp->data->mlevel * 12);
471.     }
472. #ifndef SND_LIB_INTEGRATED
473.     nhUse(se);
474. #endif
475. }
476. 
477. /* the sounds of distressed pets */
478. void
479. whimper(struct monst *mtmp)
480. {
481.     const char *whimper_verb = 0;
482.     enum sound_effect_entries se = se_canine_whine;
483.     if (helpless(mtmp) || !mtmp->data->msound)
484.         return;
485. 
486.     /* presumably nearness and soundok checks have already been made */
487.     if (Hallucination)
488.         whimper_verb = ROLL_FROM(h_sounds);
489.     else
490.         switch (mtmp->data->msound) {
491.         case MS_MEW:
492.         case MS_GROWL:
493.             whimper_verb = "whimper";
494.             break;
495.         case MS_BARK:
496.             whimper_verb = "whine";
497.             break;
498.         case MS_SQEEK:
499.             se = se_squeal;
500.             whimper_verb = "squeal";
501.             break;
502.         }
503.     if (whimper_verb) {
504.         if (!Hallucination) {
505.             Soundeffect(se, 50);
506.         }
507.         pline("%s %s.", Monnam(mtmp), vtense((char *) 0, whimper_verb));
508.         if (svc.context.run)
509.             nomul(0);
510.         wake_nearto(mtmp->mx, mtmp->my, mtmp->data->mlevel * 6);
511.     }
512. #ifndef SND_LIB_INTEGRATED
513.     nhUse(se);
514. #endif
515. }
516. 
517. /* pet makes "I'm hungry" noises */
518. void
519. beg(struct monst *mtmp)
520. {
521.     if (helpless(mtmp)
522.         || !(carnivorous(mtmp->data) || herbivorous(mtmp->data)))
523.         return;
524. 
525.     /* presumably nearness and soundok checks have already been made */
526.     if (!is_silent(mtmp->data) && mtmp->data->msound <= MS_ANIMAL) {
527.         (void) domonnoise(mtmp);
528.     } else if (mtmp->data->msound >= MS_HUMANOID) {
529.         if (!canspotmon(mtmp))
530.             map_invisible(mtmp->mx, mtmp->my);
531.         SetVoice(mtmp, 0, 80, 0);
532.         verbalize("I'm hungry.");
533.     } else {
534.         /* this is pretty lame but is better than leaving out the block
535.            of speech types between animal and humanoid; this covers
536.            MS_SILENT too (if caller lets that get this far) since it's
537.            excluded by the first two cases */
538.         if (canspotmon(mtmp))
539.             pline("%s seems famished.", Monnam(mtmp));
540.         /* looking famished will be a good trick for a tame skeleton... */
541.     }
542. }
543. 
544. /* hero has attacked a peaceful monster within 'mon's view */
545. const char *
546. maybe_gasp(struct monst *mon)
547. {
548.     static const char *const Exclam[] = {
549.         "Gasp!", "Uh-oh.", "Oh my!", "What?", "Why?",
550.     };
551.     struct permonst *mptr = mon->data;
552.     int msound = mptr->msound;
553.     boolean dogasp = FALSE;
554. 
555.     /* other roles' guardians and cross-aligned priests don't gasp */
556.     if ((msound == MS_GUARDIAN && mptr != &mons[gu.urole.guardnum])
557.         || (msound == MS_PRIEST && !p_coaligned(mon)))
558.         msound = MS_SILENT;
559.     /* co-aligned angels do gasp */
560.     else if (msound == MS_CUSS && has_emin(mon)
561.            && (p_coaligned(mon) ? !EMIN(mon)->renegade : EMIN(mon)->renegade))
562.         msound = MS_HUMANOID;
563. 
564.     /*
565.      * Only called for humanoids so animal noise handling is ignored.
566.      */
567.     switch (msound) {
568.     case MS_HUMANOID:
569.     case MS_ARREST: /* Kops */
570.     case MS_SOLDIER: /* solider, watchman */
571.     case MS_GUARD: /* vault guard */
572.     case MS_NURSE:
573.     case MS_SEDUCE: /* nymph, succubus/incubus */
574.     case MS_LEADER: /* quest leader */
575.     case MS_GUARDIAN: /* leader's guards */
576.     case MS_SELL: /* shopkeeper */
577.     case MS_ORACLE:
578.     case MS_PRIEST: /* temple priest, roaming aligned priest (not mplayer) */
579.     case MS_BOAST: /* giants */
580.     case MS_IMITATE: /* doppelganger, leocrotta, Aleax */
581.         dogasp = TRUE;
582.         break;
583.     /* issue comprehensible word(s) if hero is similar type of creature */
584.     case MS_ORC: /* used to be synonym for MS_GRUNT */
585.     case MS_GRUNT: /* ogres, trolls, gargoyles, one or two others */
586.     case MS_LAUGH: /* leprechaun, gremlin */
587.     case MS_ROAR: /* dragon, xorn, owlbear */
588.     case MS_BELLOW: /* crocodile */
589.     /* capable of speech but only do so if hero is similar type */
590.     case MS_DJINNI:
591.     case MS_VAMPIRE: /* vampire in its own form */
592.     case MS_WERE: /* lycanthrope in human form */
593.     case MS_SPELL: /* titan, barrow wight, Nazgul, nalfeshnee */
594.         dogasp = (mptr->mlet == gy.youmonst.data->mlet);
595.         break;
596.     /* capable of speech but don't care if you attack peacefuls */
597.     case MS_BRIBE:
598.     case MS_CUSS:
599.     case MS_RIDER:
600.     case MS_NEMESIS:
601.     /* can't speak */
602.     case MS_SILENT:
603.     default:
604.         break;
605.     }
606.     if (dogasp) {
607.         return ROLL_FROM(Exclam); /* [mon->m_id % SIZE(Exclam)]; */
608.     }
609.     return (const char *) 0;
610. }
611. 
612. /* for egg hatching; caller will apply "ing" suffix
613.    [the old message when a carried egg hatches was
614.    "its cries sound like {mommy,daddy}"
615.    regardless of what type of sound--if any--the creature made] */
616. const char *
617. cry_sound(struct monst *mtmp)
618. {
619.     const char *ret = 0;
620.     struct permonst *ptr = mtmp->data;
621. 
622.     /* a relatively small subset of MS_ sound values are used by oviparous
623.        species so we don't try to supply something for every MS_ type */
624.     switch (ptr->msound) {
625.     default:
626.     case MS_SILENT: /* insects, arthropods, worms, sea creatures */
627.         /* "chitter": have silent critters make some noise
628.            or the mommy/daddy gag when hatching doesn't work */
629.         ret = (ptr->mlet == S_EEL) ? "gurgle" : "chitter";
630.         break;
631.     case MS_HISS: /* chickatrice, pyrolisk, snakes */
632.         ret = "hiss";
633.         break;
634.     case MS_ROAR: /* baby dragons; have them growl instead of roar */
635.     case MS_GROWL: /* (none) */
636.         ret = "growl";
637.         break;
638.     case MS_CHIRP: /* adult crocodiles bellow, babies chirp */
639.         ret = "chirp";
640.         break;
641.     case MS_BUZZ: /* killer bees */
642.         ret = "buzz";
643.         break;
644.     case MS_SQAWK: /* ravens */
645.         ret = "screech";
646.         break;
647.     case MS_GRUNT: /* gargoyles */
648.         ret = "grunt";
649.         break;
650.     case MS_MUMBLE: /* naga hatchlingss */
651.         ret = "mumble";
652.         break;
653.     }
654.     return ret;
655. }
656. 
657. /* return True if mon is a gecko or seems to look like one (hallucination) */
658. staticfn boolean
659. mon_is_gecko(struct monst *mon)
660. {
661.     int glyph;
662. 
663.     /* return True if it is actually a gecko */
664.     if (mon->data == &mons[PM_GECKO])
665.         return TRUE;
666.     /* return False if it is a long worm; we might be chatting to its tail
667.        (not strictly needed; long worms are MS_SILENT so won't get here) */
668.     if (mon->data == &mons[PM_LONG_WORM])
669.         return FALSE;
670.     /* result depends upon whether map spot shows a gecko, which will
671.        be due to hallucination or to mimickery since mon isn't one */
672.     glyph = glyph_at(mon->mx, mon->my);
673.     return (boolean) (glyph_to_mon(glyph) == PM_GECKO);
674. }
675. 
676. DISABLE_WARNING_FORMAT_NONLITERAL
677. 
678. int /* check calls to this */
679. domonnoise(struct monst *mtmp)
680. {
681.     char verbuf[BUFSZ];
682.     const char *pline_msg = 0, /* Monnam(mtmp) will be prepended */
683.         *verbl_msg = 0,                 /* verbalize() */
684.         *verbl_msg_mcan = 0;            /* verbalize() if cancelled */
685.     struct permonst *ptr = mtmp->data;
686.     int msound = ptr->msound, gnomeplan = 0;
687. 
688.     /* presumably nearness and sleep checks have already been made */
689.     if (Deaf)
690.         return ECMD_OK;
691.     /* shk_chat can handle nonverbal monsters */
692.     if (is_silent(ptr) && !mtmp->isshk)
693.         return ECMD_OK;
694. 
695.     /* leader might be poly'd; if he can still speak, give leader speech */
696.     if (mtmp->m_id == svq.quest_status.leader_m_id && msound > MS_ANIMAL)
697.         msound = MS_LEADER;
698.     /* make sure it's your role's quest guardian; adjust if not */
699.     else if (msound == MS_GUARDIAN && ptr != &mons[gu.urole.guardnum])
700.         msound = mons[genus(monsndx(ptr), 1)].msound;
701.     /* even polymorphed, shopkeepers retain their minds and capitalist bent */
702.     else if (mtmp->isshk)
703.         msound = MS_SELL;
704.     /* some normally non-speaking types can/will speak if hero is similar */
705.     else if (msound == MS_ORC
706.              && ((same_race(ptr, gy.youmonst.data)        /* current form, */
707.                   || same_race(ptr, &mons[Race_switch])) /* unpoly'd form */
708.                  || Hallucination))
709.         msound = MS_HUMANOID;
710.     else if (msound == MS_MOO && !mtmp->mtame)
711.         msound = MS_BELLOW;
712.     /* silliness; formerly had a slight chance to interfere with shopping */
713.     else if (Hallucination && mon_is_gecko(mtmp))
714.         msound = MS_SELL;
715. 
716.     /* be sure to do this before talking; the monster might teleport away, in
717.      * which case we want to check its pre-teleport position
718.      */
719.     if (!canspotmon(mtmp))
720.         map_invisible(mtmp->mx, mtmp->my);
721. 
722.     switch (msound) {
723.     case MS_ORACLE:
724.         return doconsult(mtmp); /* check this */
725.     case MS_PRIEST:
726.         priest_talk(mtmp);
727.         break;
728.     case MS_LEADER:
729.     case MS_NEMESIS:
730.     case MS_GUARDIAN:
731.         quest_chat(mtmp);
732.         break;
733.     case MS_SELL: /* pitch, pay, total */
734.         if (!Hallucination || is_silent(ptr) || (mtmp->isshk && !rn2(2))) {
735.             shk_chat(mtmp);
736.         } else {
737.             /* approximation of GEICO's advertising slogan (it actually
738.                concludes with "save you 15% or more on car insurance.") */
739.             Sprintf(verbuf, "15 minutes could save you 15 %s.",
740.                     currency(15L)); /* "zorkmids" */
741.             verbl_msg = verbuf;
742.         }
743.         break;
744.     case MS_VAMPIRE: {
745.         /* vampire messages are varied by tameness, peacefulness, and time of
746.            night */
747.         boolean isnight = night();
748.         boolean kindred = (Upolyd && (u.umonnum == PM_VAMPIRE
749.                                       || u.umonnum == PM_VAMPIRE_LEADER));
750.         boolean nightchild = (Upolyd && (u.umonnum == PM_WOLF
751.                                          || u.umonnum == PM_WINTER_WOLF
752.                                          || u.umonnum == PM_WINTER_WOLF_CUB));
753.         const char *racenoun = (flags.female && gu.urace.individual.f)
754.                                ? gu.urace.individual.f
755.                                : (gu.urace.individual.m)
756.                                  ? gu.urace.individual.m
757.                                  : gu.urace.noun;
758. 
759.         if (mtmp->mtame) {
760.             if (kindred) {
761.                 Sprintf(verbuf, "Good %s to you Master%s",
762.                         isnight ? "evening" : "day",
763.                         isnight ? "!" : ".  Why do we not rest?");
764.                 verbl_msg = verbuf;
765.             } else {
766.                 Sprintf(verbuf, "%s%s",
767.                         nightchild ? "Child of the night, " : "",
768.                         midnight()
769.                          ? "I can stand this craving no longer!"
770.                          : isnight
771.                           ? "I beg you, help me satisfy this growing craving!"
772.                           : "I find myself growing a little weary.");
773.                 verbl_msg = verbuf;
774.             }
775.         } else if (mtmp->mpeaceful) {
776.             if (kindred && isnight) {
777.                 Sprintf(verbuf, "Good feeding %s!",
778.                         flags.female ? "sister" : "brother");
779.                 verbl_msg = verbuf;
780.             } else if (nightchild && isnight) {
781.                 Sprintf(verbuf, "How nice to hear you, child of the night!");
782.                 verbl_msg = verbuf;
783.             } else
784.                 verbl_msg = "I only drink... potions.";
785.         } else {
786.             static const char *const vampmsg[] = {
787.                 /* These first two (0 and 1) are specially handled below */
788.                 "I vant to suck your %s!",
789.                 "I vill come after %s without regret!",
790.                 /* other famous vampire quotes can follow here if desired */
791.             };
792.             int vampindex;
793. 
794.             if (kindred) {
795.                 verbl_msg = "This is my hunting ground"
796.                             " that you dare to prowl!";
797.             } else if (gy.youmonst.data == &mons[PM_SILVER_DRAGON]
798.                        || gy.youmonst.data == &mons[PM_BABY_SILVER_DRAGON]) {
799.                 /* Silver dragons are silver in color, not made of silver */
800.                 Sprintf(verbuf,
801.                         "%s!  Your silver sheen"" does not frighten me!",
802.                         (gy.youmonst.data == &mons[PM_SILVER_DRAGON])
803.                             ? "Fool"
804.                             : "Young Fool");
805.                 verbl_msg = verbuf;
806.             } else {
807.                 vampindex = rn2(SIZE(vampmsg));
808.                 if (vampindex == 0) {
809.                     Sprintf(verbuf, vampmsg[vampindex], body_part(BLOOD));
810.                     verbl_msg = verbuf;
811.                 } else if (vampindex == 1) {
812.                     Sprintf(verbuf, vampmsg[vampindex],
813.                             Upolyd ? an(pmname(&mons[u.umonnum],
814.                                                flags.female ? FEMALE : MALE))
815.                                    : an(racenoun));
816.                     verbl_msg = verbuf;
817.                 } else
818.                     verbl_msg = vampmsg[vampindex];
819.             }
820.         }
821.         break;
822.     }
823.     case MS_WERE:
824.         if (flags.moonphase == FULL_MOON && (night() ^ !rn2(13))) {
825.             pline("%s throws back %s head and lets out a blood curdling %s!",
826.                   Monnam(mtmp), mhis(mtmp),
827.                   (ptr == &mons[PM_HUMAN_WERERAT]) ? "shriek" : "howl");
828.             Soundeffect((ptr == &mons[PM_HUMAN_WERERAT]) ? se_scream
829.                                                          : se_canine_howl,
830.                         80);
831.             wake_nearto(mtmp->mx, mtmp->my, 11 * 11);
832.         } else {
833.             pline_msg =
834.                 "whispers inaudibly.  All you can make out is \"moon\".";
835.         }
836.         break;
837.     case MS_BARK:
838.         if (flags.moonphase == FULL_MOON && night()) {
839.             pline_msg = "howls.";
840.         } else if (mtmp->mpeaceful) {
841.             if (mtmp->mtame
842.                 && (mtmp->mconf || mtmp->mflee || mtmp->mtrapped
843.                     || svm.moves > EDOG(mtmp)->hungrytime || mtmp->mtame < 5))
844.                 pline_msg = "whines.";
845.             else if (mtmp->mtame && EDOG(mtmp)->hungrytime > svm.moves + 1000)
846.                 pline_msg = "yips.";
847.             else {
848.                 if (ptr != &mons[PM_DINGO]) /* dingos do not actually bark */
849.                     pline_msg = "barks.";
850.             }
851.         } else {
852.             pline_msg = "growls.";
853.         }
854.         break;
855.     case MS_MEW:
856.         if (mtmp->mtame) {
857.             if (mtmp->mconf || mtmp->mflee || mtmp->mtrapped
858.                 || mtmp->mtame < 5) {
859.                 Soundeffect(se_feline_yowl, 80);
860.                 pline_msg = "yowls.";
861.             } else if (svm.moves > EDOG(mtmp)->hungrytime) {
862.                 Soundeffect(se_feline_meow, 80);
863.                 pline_msg = "meows.";
864.             } else if (EDOG(mtmp)->hungrytime > svm.moves + 1000) {
865.                 Soundeffect(se_feline_purr, 40);
866.                 pline_msg = "purrs.";
867.             } else {
868.                 Soundeffect(se_feline_mew, 60);
869.                 pline_msg = "mews.";
870.             }
871.             break;
872.         }
873.         FALLTHROUGH;
874.         /*FALLTHRU*/
875.     case MS_GROWL:
876.         Soundeffect((mtmp->mpeaceful ? se_snarl : se_growl), 80);
877.         pline_msg = mtmp->mpeaceful ? "snarls." : "growls!";
878.         break;
879.     case MS_ROAR:
880.         Soundeffect((mtmp->mpeaceful ? se_snarl : se_roar), 80);
881.         pline_msg = mtmp->mpeaceful ? "snarls." : "roars!";
882.         break;
883.     case MS_SQEEK:
884.         Soundeffect(se_squeak, 80);
885.         pline_msg = "squeaks.";
886.         break;
887.     case MS_SQAWK:
888.         if (ptr == &mons[PM_RAVEN] && !mtmp->mpeaceful) {
889.             verbl_msg = "Nevermore!";
890.         } else {
891.             Soundeffect(se_squawk, 80);
892.             pline_msg = "squawks.";
893.         }
894.         break;
895.     case MS_HISS:
896.         if (!mtmp->mpeaceful) {
897.             Soundeffect(se_hiss, 80);
898.             pline_msg = "hisses!";
899.         } else {
900.             return ECMD_OK; /* no sound */
901.         }
902.         break;
903.     case MS_BUZZ:
904.         Soundeffect((mtmp->mpeaceful ? se_buzz : se_angry_drone), 80);
905.         pline_msg = mtmp->mpeaceful ? "drones." : "buzzes angrily.";
906.         break;
907.     case MS_GRUNT:
908.         Soundeffect(se_grunt, 60);
909.         pline_msg = "grunts.";
910.         break;
911.     case MS_NEIGH:
912.         if (mtmp->mtame < 5) {
913.             Soundeffect(se_equine_neigh, 60);
914.             pline_msg = "neighs.";
915.         } else if (svm.moves > EDOG(mtmp)->hungrytime) {
916.             Soundeffect(se_equine_whinny, 60);
917.             pline_msg = "whinnies.";
918.         } else {
919.             Soundeffect(se_equine_whicker, 60);
920.             pline_msg = "whickers.";
921.         }
922.         break;
923.     case MS_MOO:
924.         Soundeffect(se_bovine_moo, 80);
925.         pline_msg = "moos.";
926.         break;
927.     case MS_BELLOW:
928.         Soundeffect((ptr->mlet == S_QUADRUPED) ? se_bovine_bellow
929.                                                : se_croc_bellow,
930.                     80);
931.         pline_msg = "bellows!";
932.         break;
933.     case MS_CHIRP:
934.         Soundeffect(se_chirp, 60);
935.         pline_msg = "chirps.";
936.         break;
937.     case MS_WAIL:
938.         Soundeffect(se_sad_wailing, 60);
939.         pline_msg = "wails mournfully.";
940.         break;
941.     case MS_GROAN:
942.         if (!rn2(3)) {
943.             Soundeffect(se_groan, 60);
944.             pline_msg = "groans.";
945.         }
946.         break;
947.     case MS_GURGLE:
948.         Soundeffect(se_gurgle, 60);
949.         pline_msg = "gurgles.";
950.         break;
951.     case MS_BURBLE:
952.         Soundeffect(se_jabberwock_burble, 60);
953.         pline_msg = "burbles.";
954.         break;
955.     case MS_TRUMPET:
956.         Soundeffect(se_elephant_trumpet, 60);
957.         pline_msg = "trumpets!";
958.         wake_nearto(mtmp->mx, mtmp->my, 11 * 11);
959.         break;
960.     case MS_SHRIEK:
961.         Soundeffect(se_shriek, 60);
962.         pline_msg = "shrieks.";
963.         aggravate();
964.         break;
965.     case MS_IMITATE:
966.         pline_msg = "imitates you.";
967.         break;
968.     case MS_BONES:
969.         Soundeffect(se_bone_rattle, 60);
970.         pline("%s rattles noisily.", Monnam(mtmp));
971.         You("freeze for a moment.");
972.         nomul(-2);
973.         gm.multi_reason = "scared by rattling";
974.         gn.nomovemsg = 0;
975.         break;
976.     case MS_LAUGH: {
977.         static const char *const laugh_msg[4] = {
978.             "giggles.", "chuckles.", "snickers.", "laughs.",
979.         };
980.         Soundeffect(se_laughter, 60);
981.         pline_msg = laugh_msg[rn2(4)];
982.         break;
983.     }
984.     case MS_MUMBLE:
985.         pline_msg = "mumbles incomprehensibly.";
986.         break;
987.     case MS_ORC: /* this used to be an alias for grunt, now it is distinct */
988.         Soundeffect(se_orc_grunt, 60);
989.         pline_msg = "grunts.";
990.         break;
991.     case MS_DJINNI:
992.         if (mtmp->mtame) {
993.             verbl_msg = "Sorry, I'm all out of wishes.";
994.         } else if (mtmp->mpeaceful) {
995.             if (ptr == &mons[PM_WATER_DEMON])
996.                 pline_msg = "gurgles.";
997.             else
998.                 verbl_msg = "I'm free!";
999.         } else {
1000.             if (ptr != &mons[PM_PRISONER])
1001.                 verbl_msg = "This will teach you not to disturb me!";
1002.             else /* vague because prisoner might already be out of cell */
1003.                 verbl_msg = "Get me out of here.";
1004.         }
1005.         break;
1006.     case MS_BOAST: /* giants */
1007.         if (!mtmp->mpeaceful) {
1008.             switch (rn2(4)) {
1009.             case 0:
1010.                 pline("%s boasts about %s gem collection.", Monnam(mtmp),
1011.                       mhis(mtmp));
1012.                 break;
1013.             case 1:
1014.                 pline_msg = "complains about a diet of mutton.";
1015.                 break;
1016.             default:
1017.                 pline_msg = "shouts \"Fee Fie Foe Foo!\" and guffaws.";
1018.                 wake_nearto(mtmp->mx, mtmp->my, 7 * 7);
1019.                 break;
1020.             }
1021.             break;
1022.         }
1023.         FALLTHROUGH;
1024.         /*FALLTHRU*/
1025.     case MS_HUMANOID:
1026.         if (!mtmp->mpeaceful) {
1027.             if (In_endgame(&u.uz) && is_mplayer(ptr))
1028.                 mplayer_talk(mtmp);
1029.             else
1030.                 pline_msg = "threatens you.";
1031.             break;
1032.         }
1033.         /* Generic peaceful humanoid behavior. */
1034.         if (mtmp->mflee)
1035.             pline_msg = "wants nothing to do with you.";
1036.         else if (mtmp->mhp < mtmp->mhpmax / 4)
1037.             pline_msg = "moans.";
1038.         else if (mtmp->mconf || mtmp->mstun)
1039.             verbl_msg = !rn2(3) ? "Huh?" : rn2(2) ? "What?" : "Eh?";
1040.         else if (!mtmp->mcansee)
1041.             verbl_msg = "I can't see!";
1042.         else if (mtmp->mtrapped) {
1043.             struct trap *t = t_at(mtmp->mx, mtmp->my);
1044. 
1045.             if (t)
1046.                 t->tseen = 1;
1047.             verbl_msg = "I'm trapped!";
1048.         } else if (mtmp->mhp < mtmp->mhpmax / 2)
1049.             pline_msg = "asks for a potion of healing.";
1050.         else if (mtmp->mtame && !mtmp->isminion
1051.                  && svm.moves > EDOG(mtmp)->hungrytime)
1052.             verbl_msg = "I'm hungry.";
1053.         /* Specific monsters' interests */
1054.         else if (is_elf(ptr))
1055.             pline_msg = "curses orcs.";
1056.         else if (is_dwarf(ptr))
1057.             pline_msg = "talks about mining.";
1058.         else if (likes_magic(ptr))
1059.             pline_msg = "talks about spellcraft.";
1060.         else if (ptr->mlet == S_CENTAUR)
1061.             pline_msg = "discusses hunting.";
1062.         else if (is_gnome(ptr)) {
1063.             if (Hallucination && (gnomeplan = rn2(4)) % 2) {
1064.                 /* skipped for rn2(4) result of 0 or 2;
1065.                    gag from an early episode of South Park called "Gnomes";
1066.                    initially, Tweek (introduced in that episode) is the only
1067.                    one aware of the tiny gnomes after spotting them sneaking
1068.                    about; they are embarked upon a three-step business plan;
1069.                    a diagram of the plan shows:
1070.                                Phase 1         Phase 2      Phase 3
1071.                          Collect underpants       ?          Profit
1072.                    and they never verbalize step 2 so we don't either */
1073.                 verbl_msg = (gnomeplan == 1)
1074.                             ? "Phase one, collect underpants."
1075.                             : "Phase three, profit!";
1076.             } else {
1077.                 verbl_msg = "Many enter the dungeon,"
1078.                             " and few return to the sunlit lands.";
1079.             }
1080.         } else
1081.             switch (monsndx(ptr)) {
1082.             case PM_HOBBIT:
1083.                 /* 5.0: the 'complains' message used to be given if the
1084.                    hobbit's current hit points were at 10 below max or
1085.                    less, but their max is normally less than 10 so it
1086.                    would almost never occur */
1087.                 pline_msg = (mtmp->mhp < mtmp->mhpmax
1088.                              && (mtmp->mhpmax <= 10
1089.                                  || mtmp->mhp <= mtmp->mhpmax - 10))
1090.                             ? "complains about unpleasant dungeon conditions."
1091.                             : "asks you about the One Ring.";
1092.                 break;
1093.             case PM_ARCHEOLOGIST:
1094.                 pline_msg =
1095.                 "describes a recent article in \"Spelunker Today\" magazine.";
1096.                 break;
1097.             case PM_TOURIST:
1098.                 verbl_msg = "Aloha.";
1099.                 break;
1100.             default:
1101.                 pline_msg = "discusses dungeon exploration.";
1102.                 break;
1103.             }
1104.         break;
1105.     case MS_SEDUCE: {
1106.         int swval;
1107. 
1108.         if (SYSOPT_SEDUCE) {
1109.             if (ptr->mlet != S_NYMPH
1110.                 && (could_seduce(mtmp, &gy.youmonst, (struct attack *) 0)
1111.                     == 1)) {
1112.                 (void) doseduce(mtmp);
1113.                 break;
1114.             }
1115.             swval = ((poly_gender() != (int) mtmp->female) ? rn2(3) : 0);
1116.         } else
1117.             swval = ((poly_gender() == 0) ? rn2(3) : 0);
1118.         switch (swval) {
1119.         case 2:
1120.             verbl_msg = "Hello, sailor.";
1121.             break;
1122.         case 1:
1123.             pline_msg = "comes on to you.";
1124.             break;
1125.         default:
1126.             pline_msg = "cajoles you.";
1127.         }
1128.     } break;
1129.     case MS_ARREST:
1130.         if (mtmp->mpeaceful) {
1131.             SetVoice(mtmp, 0, 80, 0);
1132.             verbalize("Just the facts, %s.", flags.female ? "Ma'am" : "Sir");
1133.         } else {
1134.             static const char *const arrest_msg[3] = {
1135.                 "Anything you say can be used against you.",
1136.                 "You're under arrest!", "Stop in the name of the Law!",
1137.             };
1138.             verbl_msg = arrest_msg[rn2(3)];
1139.         }
1140.         break;
1141.     case MS_BRIBE:
1142.         if (mtmp->mpeaceful && !mtmp->mtame) {
1143.             (void) demon_talk(mtmp);
1144.             break;
1145.         }
1146.         FALLTHROUGH;
1147.         /* FALLTHRU */
1148.     case MS_CUSS:
1149.         if (!mtmp->mpeaceful)
1150.             cuss(mtmp);
1151.         else if (is_lminion(mtmp))
1152.             verbl_msg = "It's not too late.";
1153.         else
1154.             verbl_msg = "We're all doomed.";
1155.         break;
1156.     case MS_SPELL:
1157.         /* deliberately vague, since it's not actually casting any spell */
1158.         pline_msg = "seems to mutter a cantrip.";
1159.         break;
1160.     case MS_NURSE:
1161.         verbl_msg_mcan = "I hate this job!";
1162.         if (uwep && (uwep->oclass == WEAPON_CLASS || is_weptool(uwep)))
1163.             verbl_msg = "Put that weapon away before you hurt someone!";
1164.         else if (uarmc || uarm || uarmh || uarms || uarmg || uarmf)
1165.             verbl_msg = Role_if(PM_HEALER)
1166.                             ? "Doc, I can't help you unless you cooperate."
1167.                             : "Please undress so I can examine you.";
1168.         else if (uarmu)
1169.             verbl_msg = "Take off your shirt, please.";
1170.         else
1171.             verbl_msg = "Relax, this won't hurt a bit.";
1172.         break;
1173.     case MS_GUARD:
1174.         if (money_cnt(gi.invent))
1175.             verbl_msg = "Please drop that gold and follow me.";
1176.         else
1177.             verbl_msg = "Please follow me.";
1178.         break;
1179.     case MS_SOLDIER: {
1180.         static const char
1181.             *const soldier_foe_msg[3] = {
1182.                 "Resistance is useless!", "You're dog meat!", "Surrender!",
1183.             },
1184.             *const soldier_pax_msg[3] = {
1185.                 "What lousy pay we're getting here!",
1186.                 "The food's not fit for Orcs!",
1187.                 "My feet hurt, I've been on them all day!",
1188.             };
1189.         verbl_msg = mtmp->mpeaceful ? soldier_pax_msg[rn2(3)]
1190.                                     : soldier_foe_msg[rn2(3)];
1191.         break;
1192.     }
1193.     case MS_RIDER: {
1194.         const char *tribtitle;
1195.         struct obj *book = 0;
1196.         boolean ms_Death = (ptr == &mons[PM_DEATH]);
1197. 
1198.         /* 3.6 tribute */
1199.         if (ms_Death && !svc.context.tribute.Deathnotice
1200.             && (book = u_have_novel()) != 0) {
1201.             if ((tribtitle = noveltitle(&book->novelidx)) != 0) {
1202.                 Sprintf(verbuf, "Ah, so you have a copy of /%s/.", tribtitle);
1203.                 /* no Death featured in these two, so exclude them */
1204.                 if (strcmpi(tribtitle, "Snuff")
1205.                     && strcmpi(tribtitle, "The Wee Free Men"))
1206.                     Strcat(verbuf, "  I may have been misquoted there.");
1207.                 verbl_msg = verbuf;
1208.             }
1209.             svc.context.tribute.Deathnotice = 1;
1210.         } else if (ms_Death && rn2(3) && Death_quote(verbuf, sizeof verbuf)) {
1211.             verbl_msg = verbuf;
1212.         /* end of tribute addition */
1213. 
1214.         } else if (ms_Death && !rn2(10)) {
1215.             pline_msg = "is busy reading a copy of Sandman #8.";
1216.         } else
1217.             verbl_msg = "Who do you think you are, War?";
1218.         break;
1219.     } /* case MS_RIDER */
1220.     } /* switch */
1221. 
1222.     if (pline_msg) {
1223.         pline("%s %s", Monnam(mtmp), pline_msg);
1224.     } else if (mtmp->mcan && verbl_msg_mcan) {
1225.         SetVoice(mtmp, 0, 80, 0);
1226.         verbalize1(verbl_msg_mcan);
1227.     } else if (verbl_msg) {
1228.         /* more 3.6 tribute */
1229.         if (ptr == &mons[PM_DEATH]) {
1230.             /* Death talks in CAPITAL LETTERS
1231.                and without quotation marks */
1232.             char tmpbuf[BUFSZ];
1233.             pline1(ucase(strcpy(tmpbuf, verbl_msg)));
1234.             SetVoice((struct monst *) 0, 0, 80, voice_death);
1235.             sound_speak(tmpbuf);
1236.         } else {
1237.             SetVoice(mtmp, 0, 80, 0);
1238.             verbalize1(verbl_msg);
1239.         }
1240.     }
1241.     return ECMD_TIME;
1242. }
1243. 
1244. RESTORE_WARNING_FORMAT_NONLITERAL
1245. 
1246. /* #chat command */
1247. int
1248. dotalk(void)
1249. {
1250.     int result;
1251. 
1252.     result = dochat();
1253.     return result;
1254. }
1255. 
1256. staticfn int
1257. dochat(void)
1258. {
1259.     struct monst *mtmp;
1260.     int tx, ty;
1261.     struct obj *otmp;
1262. 
1263.     if (is_silent(gy.youmonst.data)) {
1264.         pline("As %s, you cannot speak.",
1265.               an(pmname(gy.youmonst.data, flags.female ? FEMALE : MALE)));
1266.         return ECMD_OK;
1267.     }
1268.     if (Strangled) {
1269.         You_cant("speak.  You're choking!");
1270.         return ECMD_OK;
1271.     }
1272.     if (u.uswallow) {
1273.         pline("They won't hear you out there.");
1274.         return ECMD_OK;
1275.     }
1276.     if (Underwater) {
1277.         Your("speech is unintelligible underwater.");
1278.         return ECMD_OK;
1279.     }
1280.     if (!Deaf && !Blind && (otmp = shop_object(u.ux, u.uy)) != 0) {
1281.         /* standing on something in a shop and chatting causes the shopkeeper
1282.            to describe the price(s).  This can inhibit other chatting inside
1283.            a shop, but that shouldn't matter much.  shop_object() returns an
1284.            object iff inside a shop and the shopkeeper is present and willing
1285.            (not angry) and able (not asleep) to speak and the position
1286.            contains any objects other than just gold.
1287.         */
1288.         price_quote(otmp);
1289.         return ECMD_TIME;
1290.     }
1291. 
1292.     if (!getdir("Talk to whom? (in what direction)")) {
1293.         /* decided not to chat */
1294.         return ECMD_CANCEL;
1295.     }
1296. 
1297.     if (u.usteed && u.dz > 0) {
1298.         if (helpless(u.usteed)) {
1299.             pline("%s seems not to notice you.", Monnam(u.usteed));
1300.             return ECMD_TIME;
1301.         } else
1302.             return domonnoise(u.usteed);
1303.     }
1304. 
1305.     if (u.dz) {
1306.         pline("They won't hear you %s there.", u.dz < 0 ? "up" : "down");
1307.         return ECMD_OK;
1308.     }
1309. 
1310.     if (u.dx == 0 && u.dy == 0) {
1311.         /*
1312.          * Let's not include this.
1313.          * It raises all sorts of questions: can you wear
1314.          * 2 helmets, 2 amulets, 3 pairs of gloves or 6 rings as a marilith,
1315.          * etc...  --KAA
1316.         if (u.umonnum == PM_ETTIN) {
1317.             You("discover that your other head makes boring conversation.");
1318.             return 1;
1319.         }
1320.          */
1321.         pline("Talking to yourself is a bad habit for a dungeoneer.");
1322.         return ECMD_OK;
1323.     }
1324. 
1325.     tx = u.ux + u.dx;
1326.     ty = u.uy + u.dy;
1327. 
1328.     if (!isok(tx, ty))
1329.         return ECMD_OK;
1330. 
1331.     mtmp = m_at(tx, ty);
1332. 
1333.     if (!mtmp || mtmp->mundetected) {
1334.         if ((otmp = vobj_at(tx, ty)) != 0 && otmp->otyp == STATUE) {
1335.             /* Talking to a statue */
1336.             if (!Blind)
1337.                 pline_The("%s seems not to notice you.",
1338.                           /* if hallucinating, you can't tell it's a statue */
1339.                           Hallucination ? rndmonnam((char *) 0) : "statue");
1340.             return ECMD_OK;
1341.         }
1342.         if (!Deaf && (IS_WALL(levl[tx][ty].typ)
1343.                       || levl[tx][ty].typ == SDOOR)) {
1344.             /* Talking to a wall; secret door remains hidden by behaving
1345.                like a wall; IS_WALL() test excludes solid rock even when
1346.                that serves as a wall bordering a corridor */
1347.             if (Blind && !IS_WALL(svl.lastseentyp[tx][ty])) {
1348.                 /* when blind, you can only talk to a wall if it has
1349.                    already been mapped as a wall */
1350.                 ;
1351.             } else if (!Hallucination) {
1352.                 pline("It's like talking to a wall.");
1353.             } else {
1354.                 static const char *const walltalk[] = {
1355.                     "gripes about its job.",
1356.                     "tells you a funny joke!",
1357.                     "insults your heritage!",
1358.                     "chuckles.",
1359.                     "guffaws merrily!",
1360.                     "deprecates your exploration efforts.",
1361.                     "suggests a stint of rehab...",
1362.                     "doesn't seem to be interested.",
1363.                 };
1364.                 int idx = rn2(10);
1365. 
1366.                 if (idx >= SIZE(walltalk))
1367.                     idx = SIZE(walltalk) - 1;
1368.                 pline_The("wall %s", walltalk[idx]);
1369.             }
1370.             return ECMD_OK;
1371.         }
1372.     }
1373. 
1374.     if (!mtmp || mtmp->mundetected
1375.         || M_AP_TYPE(mtmp) == M_AP_FURNITURE
1376.         || M_AP_TYPE(mtmp) == M_AP_OBJECT)
1377.         return ECMD_OK;
1378. 
1379.     /* sleeping monsters won't talk, except priests (who wake up) */
1380.     if (helpless(mtmp) && !mtmp->ispriest) {
1381.         /* If it is unseen, the player can't tell the difference between
1382.            not noticing him and just not existing, so skip the message. */
1383.         if (canspotmon(mtmp))
1384.             pline("%s seems not to notice you.", Monnam(mtmp));
1385.         return ECMD_OK;
1386.     }
1387. 
1388.     /* if this monster is waiting for something, prod it into action */
1389.     mtmp->mstrategy &= ~STRAT_WAITMASK;
1390. 
1391.     if (!Deaf && mtmp->mtame && mtmp->meating) {
1392.         if (!canspotmon(mtmp))
1393.             map_invisible(mtmp->mx, mtmp->my);
1394.         pline("%s is eating noisily.", Monnam(mtmp));
1395.         return ECMD_OK;
1396.     }
1397.     if (Deaf) {
1398.         const char *xresponse = humanoid(gy.youmonst.data)
1399.                     ? "falls on deaf ears"
1400.                     : "is inaudible";
1401. 
1402.         pline("Any response%s%s %s.",
1403.               canspotmon(mtmp) ? " from " : "",
1404.               canspotmon(mtmp) ? mon_nam(mtmp) : "",
1405.               xresponse);
1406.         return ECMD_OK;
1407.     }
1408.     return domonnoise(mtmp);
1409. }
1410. 
1411. /* is there a monster at <x,y> that can see the hero and react? */
1412. staticfn struct monst *
1413. responsive_mon_at(int x, int y)
1414. {
1415.     struct monst *mtmp = isok(x, y) ? m_at(x, y) : 0;
1416. 
1417.     if (mtmp && (helpless(mtmp) /* immobilized monst */
1418.                  || !mtmp->mcansee || !haseyes(mtmp->data) /* blind monst */
1419.                  || (Invis && !perceives(mtmp->data)) /* unseen hero */
1420.                  || (x != mtmp->mx || y != mtmp->my))) /* worm tail */
1421.         mtmp = (struct monst *) 0;
1422.     return mtmp;
1423. }
1424. 
1425. /* player chose 'uarmh' for #tip (pickup.c); visual #chat, sort of... */
1426. int
1427. tiphat(void)
1428. {
1429.     struct monst *mtmp;
1430.     struct obj *otmp;
1431.     int x, y, range, glyph, vismon, unseen, statue, res;
1432. 
1433.     if (!uarmh) /* can't get here from there */
1434.         return 0;
1435. 
1436.     res = uarmh->bknown ? 0 : 1;
1437.     if (cursed(uarmh)) /* "You can't.  It is cursed." */
1438.         return res; /* if learned of curse, use a move */
1439. 
1440.     /* might choose a position, but dealing with direct lines is simpler */
1441.     if (!getdir("At whom? (in what direction)")) /* bail on ESC */
1442.         return res; /* iffy; now know it's not cursed for sure (since we got
1443.                      * past prior test) but might have already known that */
1444.     res = 1; /* physical action is going to take place */
1445. 
1446.     /* most helmets have a short wear/take-off delay and we could set
1447.        'multi' to account for that, but we'll pretend that no extra time
1448.        beyond the current move is necessary */
1449.     You("briefly doff your %s.", helm_simple_name(uarmh));
1450. 
1451.     if (!u.dx && !u.dy) {
1452.         if (u.usteed && u.dz > 0) {
1453.             if (helpless(u.usteed))
1454.                 pline("%s doesn't notice.", Monnam(u.usteed));
1455.             else
1456.                 (void) domonnoise(u.usteed);
1457.         } else if (u.dz) {
1458.             pline("There's no one %s there.", (u.dz < 0) ? "up" : "down");
1459.         } else {
1460.             pline_The("lout here doesn't acknowledge you...");
1461.         }
1462.         return res;
1463.     }
1464. 
1465.     mtmp = (struct monst *) 0;
1466.     vismon = unseen = statue = 0, glyph = GLYPH_MON_OFF;
1467.     x = u.ux, y = u.uy;
1468.     for (range = 1; range <= BOLT_LIM + 1; ++range) {
1469.         x += u.dx, y += u.dy;
1470.         if (!isok(x, y) || (range > 1 && !couldsee(x, y))) {
1471.             /* switch back to coordinates for previous iteration's 'mtmp' */
1472.             x -= u.dx, y -= u.dy;
1473.             break;
1474.         }
1475.         mtmp = m_at(x, y);
1476.         vismon = (mtmp && canseemon(mtmp));
1477.         glyph = glyph_at(x, y);
1478.         unseen = glyph_is_invisible(glyph);
1479.         statue = (glyph_is_statue(glyph) /* mimic or hallucinatory statue */
1480.                   || (!vismon && !unseen && (otmp = vobj_at(x, y)) != 0
1481.                       && otmp->otyp == STATUE)); /* or actual statue */
1482.         if (vismon && (M_AP_TYPE(mtmp) == M_AP_FURNITURE
1483.                        || M_AP_TYPE(mtmp) == M_AP_OBJECT))
1484.             vismon = 0, mtmp = (struct monst *) 0;
1485.         if (vismon || unseen || (statue && Hallucination)
1486.             /* unseen adjacent monster will respond if able */
1487.             || (range == 1 && mtmp && responsive_mon_at(x, y)
1488.                 && !is_silent(mtmp->data))
1489.             /* we check accessible() after m_at() in case there's a
1490.                visible monster phazing through a wall here */
1491.             || !(accessible(x, y) || levl[x][y].typ == IRONBARS))
1492.             break;
1493.     }
1494. 
1495.     if (unseen || (statue && Hallucination)) {
1496.         pline("That %screature is ignoring you!", unseen ? "unseen " : "");
1497.     } else if (!mtmp || !responsive_mon_at(x, y)) {
1498.         if (vismon) /* 'vismon' is only True when 'mtmp' is non-Null */
1499.             pline("%s seems not to notice you.", Monnam(mtmp));
1500.         else
1501.             goto nada;
1502.     } else { /* 'mtmp' is guaranteed to be non-Null if we get here */
1503.         /* if this monster is waiting for something, prod it into action */
1504.         mtmp->mstrategy &= ~STRAT_WAITMASK;
1505. 
1506.         if (vismon && humanoid(mtmp->data) && mtmp->mpeaceful && !Conflict) {
1507.             if ((otmp = which_armor(mtmp, W_ARMH)) == 0) {
1508.                 pline("%s waves.", Monnam(mtmp));
1509.             } else if (otmp->cursed) {
1510.                 pline("%s grasps %s %s but can't remove it.", Monnam(mtmp),
1511.                       mhis(mtmp), helm_simple_name(otmp));
1512.                 otmp->bknown = 1;
1513.             } else {
1514.                 pline("%s tips %s %s in response.", Monnam(mtmp),
1515.                       mhis(mtmp), helm_simple_name(otmp));
1516.             }
1517.         } else if (vismon && humanoid(mtmp->data)) {
1518.             static const char *const reaction[3] = {
1519.                 "curses", "gestures rudely", "gestures offensively",
1520.             };
1521.             int which = !Deaf ? rn2(3) : rn1(2, 1),
1522.                 twice = (Deaf || which > 0 || rn2(3)) ? 0 : rn1(2, 1);
1523. 
1524.             pline("%s %s%s%s at you...", Monnam(mtmp), reaction[which],
1525.                   twice ? " and " : "", twice ? reaction[twice] : "");
1526.         } else if (next2u(x, y) && !Deaf && domonnoise(mtmp)) {
1527.             if (!vismon)
1528.                 map_invisible(x, y);
1529.         } else if (vismon) {
1530.             pline("%s doesn't respond.", Monnam(mtmp));
1531.         } else {
1532.  nada:
1533.             pline("%s", nothing_happens);
1534.         }
1535.     }
1536.     return res;
1537. }
1538. 
1539. #ifdef USER_SOUNDS
1540. 
1541. typedef struct audio_mapping_rec {
1542.     struct nhregex *regex;
1543.     char *filename;
1544.     int volume;
1545.     int idx;
1546.     struct audio_mapping_rec *next;
1547. } audio_mapping;
1548. 
1549. static audio_mapping *soundmap = 0;
1550. static audio_mapping *sound_matches_message(const char *);
1551. 
1552. char *sounddir = 0; /* set in files.c */
1553. 
1554. /* adds a sound file mapping, returns 0 on failure, 1 on success */
1555. int
1556. add_sound_mapping(const char *mapping)
1557. {
1558.     char text[256];
1559.     char filename[256];
1560.     char filespec[256];
1561.     char msgtyp[11];
1562.     int volume, idx = -1;
1563. 
1564.     msgtyp[0] = '\0';
1565.     filename[sizeof filename - 1] = '\0';
1566.     filespec[sizeof filespec - 1] = '\0';
1567.     text[sizeof text - 1] = '\0';
1568.     if (sscanf(mapping, "MESG \"%255[^\"]\"%*[\t ]\"%255[^\"]\" %d %d",
1569.                text, filename, &volume, &idx) == 4
1570.         || sscanf(mapping,
1571.                   "MESG %10[^\"] \"%255[^\"]\"%*[\t ]\"%255[^\"]\" %d %d",
1572.                   msgtyp, text, filename, &volume, &idx) == 5
1573.         || sscanf(mapping,
1574.                   "MESG %10[^\"] \"%255[^\"]\"%*[\t ]\"%255[^\"]\" %d",
1575.                   msgtyp, text, filename, &volume) == 4
1576.         || sscanf(mapping, "MESG \"%255[^\"]\"%*[\t ]\"%255[^\"]\" %d",
1577.                   text, filename, &volume) == 3) {
1578.         audio_mapping *new_map;
1579. 
1580.         if (!sounddir)
1581.             sounddir = dupstr(".");
1582.         if (strlen(sounddir) + 1 + strlen(filename) >= sizeof filespec) {
1583.             raw_print("sound file name too long");
1584.             return 0;
1585.         }
1586.         Snprintf(filespec, sizeof filespec, "%s/%s", sounddir, filename);
1587. 
1588.         if (idx >= 0 || can_read_file(filespec)) {
1589.             new_map = (audio_mapping *) alloc(sizeof *new_map);
1590.             new_map->regex = regex_init();
1591.             new_map->filename = dupstr(filespec);
1592.             new_map->volume = volume;
1593.             new_map->idx = idx;
1594.             new_map->next = soundmap;
1595. 
1596.             if (!regex_compile(text, new_map->regex)) {
1597.                 char errbuf[BUFSZ];
1598.                 char *re_error_desc
1599.                          = regex_error_desc(new_map->regex, errbuf);
1600. 
1601.                 regex_free(new_map->regex);
1602.                 free((genericptr_t) new_map->filename);
1603.                 free((genericptr_t) new_map);
1604.                 raw_print(re_error_desc);
1605.                 return 0;
1606.             } else {
1607.                 if (*msgtyp) {
1608.                     char tmpbuf[BUFSZ];
1609. 
1610.                     Sprintf(tmpbuf, "%.10s \"%.230s\"", msgtyp, text);
1611.                     (void) msgtype_parse_add(tmpbuf);
1612.                 }
1613.                 soundmap = new_map;
1614.             }
1615.         } else {
1616.             Sprintf(text, "cannot read %.243s", filespec);
1617.             raw_print(text);
1618.             return 0;
1619.         }
1620.     } else {
1621.         raw_print("syntax error in SOUND");
1622.         return 0;
1623.     }
1624. 
1625.     return 1;
1626. }
1627. 
1628. staticfn audio_mapping *
1629. sound_matches_message(const char *msg)
1630. {
1631.     audio_mapping *snd = soundmap;
1632. 
1633.     while (snd) {
1634.         if (regex_match(msg, snd->regex))
1635.             return snd;
1636.         snd = snd->next;
1637.     }
1638.     return (audio_mapping *) 0;
1639. }
1640. 
1641. void
1642. play_sound_for_message(const char *msg)
1643. {
1644.     audio_mapping *snd;
1645. 
1646.     /* we do this check here first, in order to completely
1647.      * avoid doing the regex search when there won't be a
1648.      * sound anyway, despite a match.
1649.      */
1650.     if (soundprocs.sound_play_usersound) {
1651.         snd = sound_matches_message(msg);
1652.         if (snd) {
1653.             Play_usersound(snd->filename, snd->volume, snd->idx);
1654.         }
1655.     }
1656. }
1657. 
1658. void
1659. maybe_play_sound(const char *msg)
1660. {
1661.     audio_mapping *snd;
1662. 
1663.     /* we do this check here first, in order to completely
1664.      * avoid doing the regex search when there won't be a
1665.      * sound anyway, despite a match.
1666.      */
1667.     if (soundprocs.sound_play_usersound) {
1668.         snd = sound_matches_message(msg);
1669.         if (snd) {
1670.             Play_usersound(snd->filename, snd->volume, snd->idx);
1671.         }
1672.     }
1673. }
1674. 
1675. void
1676. release_sound_mappings(void)
1677. {
1678.     audio_mapping *nextsound = 0;
1679. 
1680.     while (soundmap) {
1681.         nextsound = soundmap->next;
1682.         regex_free(soundmap->regex);
1683.         free((genericptr_t) soundmap->filename);
1684.         free((genericptr_t) soundmap);
1685.         soundmap = nextsound;
1686.     }
1687. 
1688.     if (sounddir)
1689.         free((genericptr_t) sounddir), sounddir = 0;
1690. }
1691. #endif /* USER_SOUNDS */
1692. 
1693. struct sound_procs soundprocs;
1694. 
1695. #ifdef SND_LIB_PORTAUDIO
1696. extern struct sound_procs portaudio_procs;
1697. #endif
1698. #ifdef SND_LIB_OPENAL
1699. extern struct sound_procs openal_procs;
1700. #endif
1701. #ifdef SND_LIB_SDL_MIXER
1702. extern struct sound_procs sdl_mixer_procs;
1703. #endif
1704. #ifdef SND_LIB_MINIAUDIO
1705. extern struct sound_procs miniaudio_procs;
1706. #endif
1707. #ifdef SND_LIB_FMOD
1708. extern struct sound_procs fmod_procs;
1709. #endif
1710. #ifdef SND_LIB_SOUND_ESCCODES
1711. extern struct sound_procs esccodes_procs;
1712. #endif
1713. #ifdef SND_LIB_VISSOUND
1714. extern struct sound_procs vissound_procs;
1715. #endif
1716. #ifdef SND_LIB_WINDSOUND
1717. extern struct sound_procs windsound_procs;
1718. #endif
1719. #ifdef SND_LIB_MACSOUND
1720. extern struct sound_procs macsound_procs;
1721. #endif
1722. #ifdef SND_LIB_QTSOUND
1723. extern struct sound_procs qtsound_procs;
1724. #endif
1725. 
1726. static struct sound_procs nosound_procs = {
1727.     SOUNDID(nosound),
1728.     0L,
1729.     (void (*)(void)) 0,                           /* init_nhsound   */
1730.     (void (*)(const char *)) 0,                   /* exit_nhsound   */
1731.     (void (*)(schar, schar, int32_t)) 0,          /* achievement    */
1732.     (void (*)(char *, int32_t, int32_t)) 0,       /* sound effect   */
1733.     (void (*)(int32_t, const char *, int32_t)) 0, /* hero_playnotes */
1734.     (void (*)(char *, int32_t, int32_t)) 0,       /* play_usersound */
1735.     (void (*)(int32_t, int32_t, int32_t)) 0,      /* ambience       */
1736.     (void (*)(char *, int32_t, int32_t, int32_t, int32_t)) 0, /* verbal */
1737. };
1738. 
1739. /* The order of these array entries must match the
1740.    order of the enum soundlib_ids in sndprocs.h */
1741. 
1742. static struct sound_choices {
1743.     struct sound_procs *sndprocs;
1744. } soundlib_choices[] = {
1745.     { &nosound_procs },     /* default, built-in */
1746. #ifdef SND_LIB_PORTAUDIO
1747.     { &portaudio_procs },
1748. #endif
1749. #ifdef SND_LIB_OPENAL
1750.     { &openal_procs },
1751. #endif
1752. #ifdef SND_LIB_SDL_MIXER
1753.     { &sdl_mixer_procs },
1754. #endif
1755. #ifdef SND_LIB_MINIAUDIO
1756.     { &miniaudio_procs },
1757. #endif
1758. #ifdef SND_LIB_FMOD
1759.     { &fmod_procs },
1760. #endif
1761. #ifdef SND_LIB_SOUND_ESCCODES
1762.     { &esccodes_procs },
1763. #endif
1764. #ifdef SND_LIB_VISSOUND
1765.     { &vissound_procs },
1766. #endif
1767. #ifdef SND_LIB_WINDSOUND
1768.     { &windsound_procs },
1769. #endif
1770. #ifdef SND_LIB_MACSOUND
1771.     { &macsound_procs },
1772. #endif
1773. #ifdef SND_LIB_QTSOUND
1774.     { &qtsound_procs },
1775. #endif
1776. };
1777. 
1778. void
1779. activate_chosen_soundlib(void)
1780. {
1781.     int idx = gc.chosen_soundlib;
1782. 
1783.     if (!IndexOk(idx, soundlib_choices))
1784.         panic("activate_chosen_soundlib: invalid soundlib (%d)", idx);
1785. 
1786.     if (ga.active_soundlib != soundlib_nosound || idx != soundlib_nosound) {
1787.         if (soundprocs.sound_exit_nhsound)
1788.             (*soundprocs.sound_exit_nhsound)("assigning a new sound library");
1789.     }
1790.     soundprocs = *soundlib_choices[idx].sndprocs;
1791.     if (soundprocs.sound_init_nhsound)
1792.         (*soundprocs.sound_init_nhsound)();
1793.     ga.active_soundlib = soundprocs.soundlib_id;
1794.     gc.chosen_soundlib = ga.active_soundlib;
1795. }
1796. 
1797. void
1798. assign_soundlib(int idx)
1799. {
1800.     if (!IndexOk(idx, soundlib_choices))
1801.         panic("assign_soundlib: invalid soundlib (%d)", idx);
1802. 
1803.     gc.chosen_soundlib
1804.         = (uint32_t) soundlib_choices[idx].sndprocs->soundlib_id;
1805. }
1806. 
1807. #if 0
1808. staticfn void
1809. choose_soundlib(const char *s)
1810. {
1811.     int i;
1812.     char *tmps = 0;
1813. 
1814.     for (i = 1; soundlib_choices[i].sndprocs; i++) {
1815.         if (!strcmpi(s, soundlib_choices[i].sndprocs->soundname)) {
1816.             assign_soundlib(i);
1817.             return;
1818.         }
1819.     }
1820.     assign_soundlib((int) soundlib_nosound);
1821. 
1822.     /* The code below here mimics that in windows.c error handling
1823.        for choosing Window type */
1824. 
1825.     /* 50: arbitrary, no real soundlib names are anywhere near that long;
1826.        used to prevent potential raw_printf() overflow if user supplies a
1827.        very long string (on the order of 1200 chars) on the command line
1828.        (config file options can't get that big; they're truncated at 1023) */
1829. #define SOUNDLIB_NAME_MAXLEN 50
1830.     if (strlen(s) >= SOUNDLIB_NAME_MAXLEN) {
1831.         tmps = (char *) alloc(SOUNDLIB_NAME_MAXLEN);
1832.         (void) strncpy(tmps, s, SOUNDLIB_NAME_MAXLEN - 1);
1833.         tmps[SOUNDLIB_NAME_MAXLEN - 1] = '\0';
1834.         s = tmps;
1835.     }
1836. #undef SOUNDLIB_NAME_MAXLEN
1837. 
1838.     if (!soundlib_choices[1].sndprocs) {
1839.         config_error_add(
1840.                    "Soundlib type %s not recognized.  The only choice is: %s",
1841.                    s, soundlib_choices[0].sndprocs->soundname);
1842.     } else {
1843.         char buf[BUFSZ];
1844.         boolean first = TRUE;
1845. 
1846.         buf[0] = '\0';
1847.         for (i = 0; soundlib_choices[i].sndprocs; i++) {
1848.             Sprintf(eos(buf), "%s%s",
1849.                     first ? "" : ", ",
1850.                     soundlib_choices[i].sndprocs->soundname);
1851.             first = FALSE;
1852.         }
1853.         config_error_add("Soundlib type %s not recognized.  Choices are:  %s",
1854.                          s, buf);
1855.     }
1856.     if (tmps)
1857.         free((genericptr_t) tmps) /*, tmps = 0*/ ;
1858. }
1859. #endif
1860. 
1861. /* copy up to maxlen-1 characters; 'dest' must be able to hold maxlen;
1862.    treat comma as alternate end of 'src' */
1863. void
1864. get_soundlib_name(char *dest, int maxlen)
1865. {
1866.     int count, idx;
1867.     const char *src;
1868. 
1869.     idx = ga.active_soundlib;
1870.     if (!IndexOk(idx, soundlib_choices))
1871.         panic("get_soundlib_name: invalid active_soundlib (%d)", idx);
1872. 
1873.     src = soundlib_choices[idx].sndprocs->soundname;
1874.     for (count = 1; count < maxlen; count++) {
1875.         if (*src == ',' || *src == '\0')
1876.             break; /*exit on \0 terminator*/
1877.         *dest++ = *src++;
1878.     }
1879.     *dest = '\0';
1880. }
1881. 
1882. enum soundlib_ids
1883. soundlib_id_from_opt(char *op)
1884. {
1885.     int idx;
1886.     struct sound_procs *defproc = &nosound_procs,
1887.                        *sp = 0;
1888. 
1889.     for (idx = 0; idx < SIZE(soundlib_choices); ++idx) {
1890.         sp = soundlib_choices[idx].sndprocs;
1891.         if (!strcmp(sp->soundname, op))
1892.             return sp->soundlib_id;
1893.     }
1894.     return defproc->soundlib_id;
1895. }
1896. 
1897. /*
1898.  * The default sound interface
1899.  *
1900.  * 3rd party sound_procs should be placed in ../sound/x
1901.  * and build procedures should reference them there.
1902.  */
1903. 
1904. #if 0
1905. staticfn void nosound_init_nhsound(void);
1906. staticfn void nosound_exit_nhsound(const char *);
1907. staticfn void nosound_suspend_nhsound(const char *);
1908. staticfn void nosound_resume_nhsound(void);
1909. staticfn void nosound_achievement(schar, schar, int32_t);
1910. staticfn void nosound_soundeffect(int32_t, int32_t);
1911. staticfn void nosound_play_usersound(char *, int32_t, int32_t);
1912. staticfn void nosound_ambience(int32_t, int32_t, int32_t);
1913. staticfn void nosound_verbal(char *text, int32_t gender, int32_t tone,
1914.                            int32_t vol, int32_t moreinfo);
1915. 
1916. staticfn void
1917. nosound_init_nhsound(void)
1918. {
1919. }
1920. 
1921. staticfn void
1922. nosound_exit_nhsound(const char *reason)
1923. {
1924. }
1925. 
1926. staticfn void
1927. nosound_achievement(schar ach1, schar ach2, int32_t repeat)
1928. {
1929. }
1930. 
1931. staticfn void
1932. nosound_soundeffect(int32_t seid, int volume)
1933. {
1934. }
1935. 
1936. staticfn void
1937. nosound_hero_playnotes(int32_t instr, const char *notes, int32_t vol)
1938. {
1939. }
1940. 
1941. staticfn void
1942. nosound_play_usersound(char *filename, int volume, int idx)
1943. {
1944. }
1945. 
1946. staticfn void
1947. nosound_ambience(int32_t ambienceid, int32_t ambience_action,
1948.                 int32_t hero_proximity)
1949. {
1950. }
1951. 
1952. staticfn void
1953. nosound_verbal(char *text, int32_t gender, int32_t tone,
1954.                int32_t vol, int32_t moreinfo)
1955. {
1956. }
1957. #endif
1958. 
1959. #ifdef SND_SOUNDEFFECTS_AUTOMAP
1960. 
1961. /* prototype in case a build defines staticfn to nothing */
1962. staticfn void initialize_semap_basenames(void);
1963. 
1964. struct soundeffect_automapping {
1965.     enum sound_effect_entries seid;
1966.     const char *base_filename;
1967. };
1968. 
1969. #define SEFFECTS_AUTOMAP
1970. static const struct soundeffect_automapping
1971.     se_mappings_init[number_of_se_entries] = {
1972.     { se_zero_invalid,                  "" },
1973. #include "seffects.h"
1974. };
1975. #undef SEFFECTS_AUTOMAP
1976. 
1977. static const char *semap_basenames[SIZE(se_mappings_init)];
1978. static boolean basenames_initialized = FALSE;
1979. 
1980. staticfn void
1981. initialize_semap_basenames(void)
1982. {
1983.     int i;
1984. 
1985.     /* to avoid things getting out of sequence; seid an index to the name */
1986.     for (i = 1; i < SIZE(se_mappings_init); ++i) {
1987.         if (se_mappings_init[i].seid > 0
1988.                 && se_mappings_init[i].seid < SIZE(semap_basenames))
1989.             semap_basenames[se_mappings_init[i].seid]
1990.                                 = se_mappings_init[i].base_filename;
1991.     }
1992. }
1993. 
1994. char *
1995. get_sound_effect_filename(
1996.     int32_t seidint,
1997.     char *buf,
1998.     size_t bufsz,
1999.     int32_t approach)
2000. {
2001.     static const char prefix[] = "se_", suffix[] = ".wav";
2002.     size_t consumes = 0, baselen = 0, existinglen = 0;
2003. /*    enum sound_effect_entries seid = (enum sound_effect_entries) seidint; */
2004.     char *ourdir = sounddir;       /* sounddir would get set in files.c */
2005.     char *cp = buf;
2006.     boolean needslash = TRUE;
2007. 
2008.     if (!buf || (!ourdir && approach == sff_default))
2009.         return (char *) 0;
2010. 
2011.     if (!basenames_initialized) {
2012.         initialize_semap_basenames();
2013.         basenames_initialized = TRUE;
2014.     }
2015. 
2016.     if (semap_basenames[seidint])
2017.         baselen = strlen(semap_basenames[seidint]);
2018. 
2019.     consumes = (sizeof prefix - 1) + baselen;
2020.     if (approach == sff_default) {
2021.         consumes += (sizeof suffix - 1) + strlen(ourdir) + 1; /* 1 for '/' */
2022.     } else if (approach == sff_havedir_append_rest) {
2023.         /* consumes += (sizeof suffix - 1); */
2024.         existinglen = strlen(buf);
2025.         if (existinglen > 0) {
2026.             cp = buf + existinglen; /* points at trailing NUL */
2027.             cp--;                   /* points at last character */
2028.             if (*cp == '/' || *cp == '\\')
2029.                 needslash = FALSE;
2030.             cp++;                   /* points back at trailing NUL */
2031.         }
2032.         if (needslash)
2033.             consumes++;  /* for '/' */
2034.         consumes += existinglen;
2035.         consumes += (sizeof suffix - 1);
2036.     }
2037.     consumes += 1; /* for trailing NUL */
2038.     /* existinglen could be >= bufsz if caller didn't initialize buf
2039.      * to properly include a trailing NUL */
2040.     if (baselen <= 0 || consumes > bufsz || existinglen >= bufsz)
2041.         return (char *) 0;
2042. 
2043. #if 0
2044.     if (approach == sff_default) {
2045.         Strcpy(buf, ourdir);
2046.         Strcat(buf, "/");
2047.     } else if (approach == sff_havdir_append_rest) {
2048.         if (needslash)
2049.             Strcat(buf, "/");
2050.     } else if (approach == sff_base_only) {
2051.         buf[0] = '\0';
2052.     } else {
2053.         return (char *) 0;
2054.     }
2055.     Strcat(buf, prefix);
2056.     Strcat(buf, semap_basenames[seidint]);
2057.     if (approach != sff_base_only) {
2058.         Strcat(buf, suffix);
2059.     }
2060. #else
2061.     if (approach == sff_default) {
2062.         Snprintf(buf, bufsz , "%s/%s%s%s", ourdir, prefix,
2063.                  semap_basenames[seidint], suffix);
2064.     } else if (approach == sff_havedir_append_rest) {
2065.         if (needslash) {
2066.             *cp = '/';
2067.             cp++;
2068.             *cp = '\0';
2069.             existinglen++;
2070.         }
2071.         Snprintf(cp, bufsz - (existinglen + 1) , "%s%s%s",
2072.                  prefix, semap_basenames[seidint], suffix);
2073.     } else if (approach == sff_base_only) {
2074.         Snprintf(buf, bufsz, "%s%s", prefix, semap_basenames[seidint]);
2075.     } else {
2076.         return (char *) 0;
2077.     }
2078. #endif
2079.     return buf;
2080. }
2081. #endif  /* SND_SOUNDEFFECTS_AUTOMAP */
2082. 
2083. char *
2084. base_soundname_to_filename(
2085.     char *basename,
2086.     char *buf,
2087.     size_t bufsz,
2088.     int32_t approach)
2089. {
2090.     static const char suffix[] = ".wav";
2091.     size_t consumes = 0, baselen = 0, existinglen = 0;
2092.     char *cp = buf;
2093.     boolean needslash = TRUE;
2094. 
2095.     if (!buf)
2096.         return (char *) 0;
2097. 
2098.     baselen = strlen(basename);
2099.     consumes = baselen;
2100. 
2101.     if (approach == sff_havedir_append_rest) {
2102.         /* consumes += (sizeof suffix - 1); */
2103.         existinglen = strlen(buf);
2104.         if (existinglen > 0) {
2105.             cp = buf + existinglen; /* points at trailing NUL */
2106.             cp--;                   /* points at last character */
2107.             if (*cp == '/' || *cp == '\\')
2108.                 needslash = FALSE;
2109.             cp++;                   /* points back at trailing NUL */
2110.         }
2111.         if (needslash)
2112.             consumes++;  /* for '/' */
2113.         consumes += existinglen;
2114.         consumes += (sizeof suffix - 1);
2115.     }
2116.     consumes += 1; /* for trailing NUL */
2117.     /* existinglen could be >= bufsz if caller didn't initialize buf
2118.      * to properly include a trailing NUL */
2119.     if (!baselen || consumes > bufsz || existinglen >= bufsz)
2120.         return (char *) 0;
2121. 
2122. #if 0
2123.     if (approach == sff_havedir_append_rest) {
2124.         if (needslash)
2125.             Strcat(buf, "/");
2126.     } else if (approach == sff_base_only) {
2127.         buf[0] = '\0';
2128.     } else {
2129.         return (char *) 0;
2130.     }
2131.     Strcat(buf, basename);
2132.     if (approach != sff_base_only) {
2133.         Strcat(buf, suffix);
2134.     }
2135. #else
2136.     if (approach == sff_havedir_append_rest) {
2137.         if (needslash) {
2138.             *cp = '/';
2139.             cp++;
2140.             *cp = '\0';
2141.             existinglen++;
2142.         }
2143.         Snprintf(cp, bufsz - (existinglen + 1) , "%s%s",
2144.                  basename, suffix);
2145.     } else if (approach == sff_base_only) {
2146.         Snprintf(buf, bufsz, "%s", basename);
2147.     } else {
2148.         return (char *) 0;
2149.     }
2150. #endif
2151.     return buf;
2152. }
2153. 
2154. #ifdef SND_SPEECH
2155. #define SPEECHONLY
2156. #else
2157. #define SPEECHONLY UNUSED
2158. #endif
2159. 
2160. void
2161. set_voice(
2162.     struct monst *mtmp SPEECHONLY,
2163.     int32_t tone SPEECHONLY,
2164.     int32_t volume SPEECHONLY,
2165.     int32_t moreinfo SPEECHONLY)
2166. {
2167. #ifdef SND_SPEECH
2168.     int32_t gender = (mtmp && mtmp->female) ? FEMALE : MALE;
2169. 
2170.     if (gv.voice.nameid)
2171.         free((genericptr_t) gv.voice.nameid);
2172.     gv.voice.gender = gender;
2173.     gv.voice.serialno = mtmp ? mtmp->m_id
2174.                              : ((moreinfo & voice_talking_artifact) != 0)  ? 3
2175.                                  : ((moreinfo & voice_deity) != 0) ? 4 : 2;
2176.     gv.voice.tone = tone;
2177.     gv.voice.volume = volume;
2178.     gv.voice.moreinfo = moreinfo;
2179.     gv.voice.nameid = (const char *) 0;
2180.     gp.pline_flags |= PLINE_SPEECH;
2181. #endif
2182. }
2183. 
2184. void
2185. sound_speak(const char *text SPEECHONLY)
2186. {
2187. #ifdef SND_SPEECH
2188.     const char *cp1, *cp2;
2189.     char *cpdst;
2190.     char buf[BUFSZ + BUFSZ];
2191. 
2192.     if (!text || (text && *text == '\0'))
2193.         return;
2194.     if (iflags.voices && soundprocs.sound_verbal
2195.         && (soundprocs.sound_triggers & SOUND_TRIGGER_VERBAL)) {
2196.         cp1 = text;
2197.         cpdst = buf;
2198.         cp2 = c_eos(cp1);
2199.         cp2--;  /* last non-NUL */
2200.         *cpdst = '\0';
2201.         if ((gp.pline_flags & PLINE_VERBALIZE) != 0) {
2202.             if (*cp1 == '"')
2203.                 cp1++;
2204.             if (*cp2 == '"')
2205.                 cp2--;
2206.         }
2207.         /* cp1 -> 1st, cp2 -> last non-nul) */
2208.         if ((unsigned)(cp2 - cp1) < (sizeof buf - 1U)) {
2209.             while (cp1 <= cp2) {
2210.                 *cpdst = *cp1;
2211.                 cp1++;
2212.                 cpdst++;
2213.             }
2214.             *cpdst = '\0';
2215.         }
2216.         (*soundprocs.sound_verbal)(buf, gv.voice.gender, gv.voice.tone,
2217.                                    gv.voice.volume, gv.voice.moreinfo);
2218.     }
2219. #endif
2220. }
2221. 
2222. /*sounds.c*/