Source:NetHack 3.4.3/src/sounds.c

From NetHackWiki
(Redirected from Source:Ref/dosounds)
Jump to: navigation, search

Below is the full text to src/sounds.c from NetHack 3.4.3. To link to a particular line, write [[sounds.c#line123]], for example.

Top of file

  1. /*	SCCS Id: @(#)sounds.c	3.4	2002/05/06	*/
  2. /*	Copyright (c) 1989 Janet Walz, Mike Threepoint */
  3. /* NetHack may be freely redistributed.  See license for details. */

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. #include "hack.h"
  2. #include "edog.h"
  3. #ifdef USER_SOUNDS
  4. # ifdef USER_SOUNDS_REGEX
  5. #include <regex.h>
  6. # endif
  7. #endif
  8.  
  9. #ifdef OVLB
  10.  
  11. static int FDECL(domonnoise,(struct monst *));
  12. static int NDECL(dochat);
  13.  
  14. #endif /* OVLB */
  15.  
  16. #ifdef OVL0

mon_in_room

  1. static int FDECL(mon_in_room, (struct monst *,int));
  2.  
  3. /* this easily could be a macro, but it might overtax dumb compilers */
  4. static int
  5. mon_in_room(mon, rmtyp)
  6. struct monst *mon;
  7. int rmtyp;
  8. {
  9. int rno = levl[mon->mx][mon->my].roomno;
  10.  
  11. return rooms[rno - ROOMOFFSET].rtype == rmtyp;
  12. }

dosounds

  1. void
  2. dosounds()
  3. {
  4. register struct mkroom *sroom;
  5. register int hallu, vx, vy;
  6. #if defined(AMIGA) && defined(AZTEC_C_WORKAROUND)
  7. int xx;
  8. #endif
  9. struct monst *mtmp;
  10.  
  11. if (!flags.soundok || u.uswallow || Underwater) return;
  12.  
  13. hallu = Hallucination ? 1 : 0;
  14.  
  15. if (level.flags.nfountains && !rn2(400)) {
  16. 	static const char * const fountain_msg[4] = {
  17. 		"bubbling water.",
  18. 		"water falling on coins.",
  19. 		"the splashing of a naiad.",
  20. 		"a soda fountain!",
  21. 	};
  22. 	You_hear(fountain_msg[rn2(3)+hallu]);
  23. }
  24. #ifdef SINK
  25. if (level.flags.nsinks && !rn2(300)) {
  26. 	static const char * const sink_msg[3] = {
  27. 		"a slow drip.",
  28. 		"a gurgling noise.",
  29. 		"dishes being washed!",
  30. 	};
  31. 	You_hear(sink_msg[rn2(2)+hallu]);
  32. }
  33. #endif
  34. if (level.flags.has_court && !rn2(200)) {
  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. 	for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
  42. 	    if (DEADMONSTER(mtmp)) continue;
  43. 	    if ((mtmp->msleeping ||
  44. 			is_lord(mtmp->data) || is_prince(mtmp->data)) &&
  45. 		!is_animal(mtmp->data) &&
  46. 		mon_in_room(mtmp, COURT)) {
  47. 		/* finding one is enough, at least for now */
  48. 		int which = rn2(3)+hallu;
  49.  
  50. 		if (which != 2) You_hear(throne_msg[which]);
  51. 		else		pline(throne_msg[2], uhis());
  52. 		return;
  53. 	    }
  54. 	}
  55. }
  56. if (level.flags.has_swamp && !rn2(200)) {
  57. 	static const char * const swamp_msg[3] = {
  58. 		"hear mosquitoes!",
  59. 		"smell marsh gas!",	/* so it's a smell...*/
  60. 		"hear Donald Duck!",
  61. 	};
  62. 	You(swamp_msg[rn2(2)+hallu]);
  63. 	return;
  64. }
  65. if (level.flags.has_vault && !rn2(200)) {
  66. 	if (!(sroom = search_special(VAULT))) {
  67. 	    /* strange ... */
  68. 	    level.flags.has_vault = 0;
  69. 	    return;
  70. 	}
  71. 	if(gd_sound())
  72. 	    switch (rn2(2)+hallu) {
  73. 		case 1: {
  74. 		    boolean gold_in_vault = FALSE;
  75.  
  76. 		    for (vx = sroom->lx;vx <= sroom->hx; vx++)
  77. 			for (vy = sroom->ly; vy <= sroom->hy; vy++)
  78. 			    if (g_at(vx, vy))
  79. 				gold_in_vault = TRUE;
  80. #if defined(AMIGA) && defined(AZTEC_C_WORKAROUND)
  81. 		    /* Bug in aztec assembler here. Workaround below */
  82. 		    xx = ROOM_INDEX(sroom) + ROOMOFFSET;
  83. 		    xx = (xx != vault_occupied(u.urooms));
  84. 		    if(xx)
  85. #else
  86. 		    if (vault_occupied(u.urooms) !=
  87. 			 (ROOM_INDEX(sroom) + ROOMOFFSET))
  88. #endif /* AZTEC_C_WORKAROUND */
  89. 		    {
  90. 			if (gold_in_vault)
  91. 			    You_hear(!hallu ? "someone counting money." :
  92. 				"the quarterback calling the play.");
  93. 			else
  94. 			    You_hear("someone searching.");
  95. 			break;
  96. 		    }
  97. 		    /* fall into... (yes, even for hallucination) */
  98. 		}
  99. 		case 0:
  100. 		    You_hear("the footsteps of a guard on patrol.");
  101. 		    break;
  102. 		case 2:
  103. 		    You_hear("Ebenezer Scrooge!");
  104. 		    break;
  105. 	    }
  106. 	return;
  107. }
  108. if (level.flags.has_beehive && !rn2(200)) {
  109. 	for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
  110. 	    if (DEADMONSTER(mtmp)) continue;
  111. 	    if ((mtmp->data->mlet == S_ANT && is_flyer(mtmp->data)) &&
  112. 		mon_in_room(mtmp, BEEHIVE)) {
  113. 		switch (rn2(2)+hallu) {
  114. 		    case 0:
  115. 			You_hear("a low buzzing.");
  116. 			break;
  117. 		    case 1:
  118. 			You_hear("an angry drone.");
  119. 			break;
  120. 		    case 2:
  121. 			You_hear("bees in your %sbonnet!",
  122. 			    uarmh ? "" : "(nonexistent) ");
  123. 			break;
  124. 		}
  125. 		return;
  126. 	    }
  127. 	}
  128. }
  129. if (level.flags.has_morgue && !rn2(200)) {
  130. 	for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
  131. 	    if (DEADMONSTER(mtmp)) continue;
  132. 	    if (is_undead(mtmp->data) &&
  133. 		mon_in_room(mtmp, MORGUE)) {
  134. 		switch (rn2(2)+hallu) {
  135. 		    case 0:
  136. 			You("suddenly realize it is unnaturally quiet.");
  137. 			break;
  138. 		    case 1:
  139. 			pline_The("%s on the back of your %s stands up.",
  140. 				body_part(HAIR), body_part(NECK));
  141. 			break;
  142. 		    case 2:
  143. 			pline_The("%s on your %s seems to stand up.",
  144. 				body_part(HAIR), body_part(HEAD));
  145. 			break;
  146. 		}
  147. 		return;
  148. 	    }
  149. 	}
  150. }
  151. if (level.flags.has_barracks && !rn2(200)) {
  152. 	static const char * const barracks_msg[4] = {
  153. 		"blades being honed.",
  154. 		"loud snoring.",
  155. 		"dice being thrown.",
  156. 		"General MacArthur!",
  157. 	};
  158. 	int count = 0;
  159.  
  160. 	for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
  161. 	    if (DEADMONSTER(mtmp)) continue;
  162. 	    if (is_mercenary(mtmp->data) &&
  163. #if 0		/* don't bother excluding these */
  164. 		!strstri(mtmp->data->mname, "watch") &&
  165. 		!strstri(mtmp->data->mname, "guard") &&
  166. #endif
  167. 		mon_in_room(mtmp, BARRACKS) &&
  168. 		/* sleeping implies not-yet-disturbed (usually) */
  169. 		(mtmp->msleeping || ++count > 5)) {
  170. 		You_hear(barracks_msg[rn2(3)+hallu]);
  171. 		return;
  172. 	    }
  173. 	}
  174. }
  175. if (level.flags.has_zoo && !rn2(200)) {
  176. 	static const char * const zoo_msg[3] = {
  177. 		"a sound reminiscent of an elephant stepping on a peanut.",
  178. 		"a sound reminiscent of a seal barking.",
  179. 		"Doctor Doolittle!",
  180. 	};
  181. 	for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
  182. 	    if (DEADMONSTER(mtmp)) continue;
  183. 	    if ((mtmp->msleeping || is_animal(mtmp->data)) &&
  184. 		    mon_in_room(mtmp, ZOO)) {
  185. 		You_hear(zoo_msg[rn2(2)+hallu]);
  186. 		return;
  187. 	    }
  188. 	}
  189. }
  190. if (level.flags.has_shop && !rn2(200)) {
  191. 	if (!(sroom = search_special(ANY_SHOP))) {
  192. 	    /* strange... */
  193. 	    level.flags.has_shop = 0;
  194. 	    return;
  195. 	}
  196. 	if (tended_shop(sroom) &&
  197. 		!index(u.ushops, ROOM_INDEX(sroom) + ROOMOFFSET)) {
  198. 	    static const char * const shop_msg[3] = {
  199. 		    "someone cursing shoplifters.",
  200. 		    "the chime of a cash register.",
  201. 		    "Neiman and Marcus arguing!",
  202. 	    };
  203. 	    You_hear(shop_msg[rn2(2)+hallu]);
  204. 	}
  205. 	return;
  206. }
  207. if (Is_oracle_level(&u.uz) && !rn2(400)) {
  208. 	/* make sure the Oracle is still here */
  209. 	for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)
  210. 	    if (!DEADMONSTER(mtmp) && mtmp->data == &mons[PM_ORACLE])
  211. 		break;
  212. 	/* and don't produce silly effects when she's clearly visible */
  213. 	if (mtmp && (hallu || !canseemon(mtmp))) {
  214. 	    static const char * const ora_msg[5] = {
  215. 		    "a strange wind.",		/* Jupiter at Dodona */
  216. 		    "convulsive ravings.",	/* Apollo at Delphi */
  217. 		    "snoring snakes.",		/* AEsculapius at Epidaurus */
  218. 		    "someone say \"No more woodchucks!\"",
  219. 		    "a loud ZOT!"		/* both rec.humor.oracle */
  220. 	    };
  221. 	    You_hear(ora_msg[rn2(3)+hallu*2]);
  222. 	}
  223. 	return;
  224. }
  225. }
  226.  
  227. #endif /* OVL0 */

growl_sound

  1. #ifdef OVLB
  2.  
  3. static const char * const h_sounds[] = {
  4. "beep", "boing", "sing", "belche", "creak", "cough", "rattle",
  5. "ululate", "pop", "jingle", "sniffle", "tinkle", "eep"
  6. };
  7.  
  8. const char *
  9. growl_sound(mtmp)
  10. register struct monst *mtmp;
  11. {
  12. 	const char *ret;
  13.  
  14. 	switch (mtmp->data->msound) {
  15. 	case MS_MEW:
  16. 	case MS_HISS:
  17. 	    ret = "hiss";
  18. 	    break;
  19. 	case MS_BARK:
  20. 	case MS_GROWL:
  21. 	    ret = "growl";
  22. 	    break;
  23. 	case MS_ROAR:
  24. 	    ret = "roar";
  25. 	    break;
  26. 	case MS_BUZZ:
  27. 	    ret = "buzz";
  28. 	    break;
  29. 	case MS_SQEEK:
  30. 	    ret = "squeal";
  31. 	    break;
  32. 	case MS_SQAWK:
  33. 	    ret = "screech";
  34. 	    break;
  35. 	case MS_NEIGH:
  36. 	    ret = "neigh";
  37. 	    break;
  38. 	case MS_WAIL:
  39. 	    ret = "wail";
  40. 	    break;
  41. 	case MS_SILENT:
  42. 		ret = "commotion";
  43. 		break;
  44. 	default:
  45. 		ret = "scream";
  46. 	}
  47. 	return ret;
  48. }

growl

  1. /* the sounds of a seriously abused pet, including player attacking it */
  2. void
  3. growl(mtmp)
  4. register struct monst *mtmp;
  5. {
  6. register const char *growl_verb = 0;
  7.  
  8. if (mtmp->msleeping || !mtmp->mcanmove || !mtmp->data->msound)
  9. 	return;
  10.  
  11. /* presumably nearness and soundok checks have already been made */
  12. if (Hallucination)
  13. 	growl_verb = h_sounds[rn2(SIZE(h_sounds))];
  14. else
  15. 	growl_verb = growl_sound(mtmp);
  16. if (growl_verb) {
  17. 	pline("%s %s!", Monnam(mtmp), vtense((char *)0, growl_verb));
  18. 	if(flags.run) nomul(0);
  19. 	wake_nearto(mtmp->mx, mtmp->my, mtmp->data->mlevel * 18);
  20. }
  21. }

yelp

  1. /* the sounds of mistreated pets */
  2. void
  3. yelp(mtmp)
  4. register struct monst *mtmp;
  5. {
  6. register const char *yelp_verb = 0;
  7.  
  8. if (mtmp->msleeping || !mtmp->mcanmove || !mtmp->data->msound)
  9. 	return;
  10.  
  11. /* presumably nearness and soundok checks have already been made */
  12. if (Hallucination)
  13. 	yelp_verb = h_sounds[rn2(SIZE(h_sounds))];
  14. else switch (mtmp->data->msound) {
  15. 	case MS_MEW:
  16. 	    yelp_verb = "yowl";
  17. 	    break;
  18. 	case MS_BARK:
  19. 	case MS_GROWL:
  20. 	    yelp_verb = "yelp";
  21. 	    break;
  22. 	case MS_ROAR:
  23. 	    yelp_verb = "snarl";
  24. 	    break;
  25. 	case MS_SQEEK:
  26. 	    yelp_verb = "squeal";
  27. 	    break;
  28. 	case MS_SQAWK:
  29. 	    yelp_verb = "screak";
  30. 	    break;
  31. 	case MS_WAIL:
  32. 	    yelp_verb = "wail";
  33. 	    break;
  34. }
  35. if (yelp_verb) {
  36. 	pline("%s %s!", Monnam(mtmp), vtense((char *)0, yelp_verb));
  37. 	if(flags.run) nomul(0);
  38. 	wake_nearto(mtmp->mx, mtmp->my, mtmp->data->mlevel * 12);
  39. }
  40. }

whimper

  1. /* the sounds of distressed pets */
  2. void
  3. whimper(mtmp)
  4. register struct monst *mtmp;
  5. {
  6. register const char *whimper_verb = 0;
  7.  
  8. if (mtmp->msleeping || !mtmp->mcanmove || !mtmp->data->msound)
  9. 	return;
  10.  
  11. /* presumably nearness and soundok checks have already been made */
  12. if (Hallucination)
  13. 	whimper_verb = h_sounds[rn2(SIZE(h_sounds))];
  14. else switch (mtmp->data->msound) {
  15. 	case MS_MEW:
  16. 	case MS_GROWL:
  17. 	    whimper_verb = "whimper";
  18. 	    break;
  19. 	case MS_BARK:
  20. 	    whimper_verb = "whine";
  21. 	    break;
  22. 	case MS_SQEEK:
  23. 	    whimper_verb = "squeal";
  24. 	    break;
  25. }
  26. if (whimper_verb) {
  27. 	pline("%s %s.", Monnam(mtmp), vtense((char *)0, whimper_verb));
  28. 	if(flags.run) nomul(0);
  29. 	wake_nearto(mtmp->mx, mtmp->my, mtmp->data->mlevel * 6);
  30. }
  31. }

beg

  1. /* pet makes "I'm hungry" noises */
  2. void
  3. beg(mtmp)
  4. register struct monst *mtmp;
  5. {
  6. if (mtmp->msleeping || !mtmp->mcanmove ||
  7. 	    !(carnivorous(mtmp->data) || herbivorous(mtmp->data)))
  8. 	return;
  9.  
  10. /* presumably nearness and soundok checks have already been made */
  11. if (!is_silent(mtmp->data) && mtmp->data->msound <= MS_ANIMAL)
  12. 	(void) domonnoise(mtmp);
  13. else if (mtmp->data->msound >= MS_HUMANOID) {
  14. 	if (!canspotmon(mtmp))
  15. 	    map_invisible(mtmp->mx, mtmp->my);
  16. 	verbalize("I'm hungry.");
  17. }
  18. }

domonnoise

  1. static int
  2. domonnoise(mtmp)
  3. register struct monst *mtmp;
  4. {
  5. register const char *pline_msg = 0,	/* Monnam(mtmp) will be prepended */
  6. 			*verbl_msg = 0;	/* verbalize() */
  7. struct permonst *ptr = mtmp->data;
  8. char verbuf[BUFSZ];
  9.  
  10. /* presumably nearness and sleep checks have already been made */
  11. if (!flags.soundok) return(0);
  12. if (is_silent(ptr)) return(0);
  13.  
  14. /* Make sure its your role's quest quardian; adjust if not */
  15. if (ptr->msound == MS_GUARDIAN && ptr != &mons[urole.guardnum]) {
  16. 	int mndx = monsndx(ptr);
  17. 	ptr = &mons[genus(mndx,1)];
  18. }
  19.  
  20. /* be sure to do this before talking; the monster might teleport away, in
  21. * which case we want to check its pre-teleport position
  22. */
  23. if (!canspotmon(mtmp))
  24. 	map_invisible(mtmp->mx, mtmp->my);
  25.  
  26. switch (ptr->msound) {
  27. 	case MS_ORACLE:
  28. 	    return doconsult(mtmp);
  29. 	case MS_PRIEST:
  30. 	    priest_talk(mtmp);
  31. 	    break;
  32. 	case MS_LEADER:
  33. 	case MS_NEMESIS:
  34. 	case MS_GUARDIAN:
  35. 	    quest_chat(mtmp);
  36. 	    break;
  37. 	case MS_SELL: /* pitch, pay, total */
  38. 	    shk_chat(mtmp);
  39. 	    break;
  40. 	case MS_VAMPIRE:
  41. 	    {
  42. 	    /* vampire messages are varied by tameness, peacefulness, and time of night */
  43. 		boolean isnight = night();
  44. 		boolean kindred =    (Upolyd && (u.umonnum == PM_VAMPIRE ||
  45. 				       u.umonnum == PM_VAMPIRE_LORD));
  46. 		boolean nightchild = (Upolyd && (u.umonnum == PM_WOLF ||
  47. 				       u.umonnum == PM_WINTER_WOLF ||
  48. 	    			       u.umonnum == PM_WINTER_WOLF_CUB));
  49. 		const char *racenoun = (flags.female && urace.individual.f) ?
  50. 					urace.individual.f : (urace.individual.m) ?
  51. 					urace.individual.m : urace.noun;
  52.  
  53. 		if (mtmp->mtame) {
  54. 			if (kindred) {
  55. 				Sprintf(verbuf, "Good %s to you Master%s",
  56. 					isnight ? "evening" : "day",
  57. 					isnight ? "!" : ".  Why do we not rest?");
  58. 				verbl_msg = verbuf;
  59. 		    	} else {
  60. 		    	    Sprintf(verbuf,"%s%s",
  61. 				nightchild ? "Child of the night, " : "",
  62. 				midnight() ?
  63. 					"I can stand this craving no longer!" :
  64. 				isnight ?
  65. 					"I beg you, help me satisfy this growing craving!" :
  66. 					"I find myself growing a little weary.");
  67. 				verbl_msg = verbuf;
  68. 			}
  69. 		} else if (mtmp->mpeaceful) {
  70. 			if (kindred && isnight) {
  71. 				Sprintf(verbuf, "Good feeding %s!",
  72. 	    				flags.female ? "sister" : "brother");
  73. 				verbl_msg = verbuf;
  74. 			} else if (nightchild && isnight) {
  75. 				Sprintf(verbuf,
  76. 				    "How nice to hear you, child of the night!");
  77. 				verbl_msg = verbuf;
  78. 	    		} else
  79. 		    		verbl_msg = "I only drink... potions.";
  80. 	        } else {
  81. 			int vampindex;
  82. 	    		static const char * const vampmsg[] = {
  83. 			       /* These first two (0 and 1) are specially handled below */
  84. 	    			"I vant to suck your %s!",
  85. 	    			"I vill come after %s without regret!",
  86. 		    	       /* other famous vampire quotes can follow here if desired */
  87. 	    		};
  88. 			if (kindred)
  89. 			    verbl_msg = "This is my hunting ground that you dare to prowl!";
  90. 			else if (youmonst.data == &mons[PM_SILVER_DRAGON] ||
  91. 				 youmonst.data == &mons[PM_BABY_SILVER_DRAGON]) {
  92. 			    /* Silver dragons are silver in color, not made of silver */
  93. 			    Sprintf(verbuf, "%s! Your silver sheen does not frighten me!",
  94. 					youmonst.data == &mons[PM_SILVER_DRAGON] ?
  95. 					"Fool" : "Young Fool");
  96. 			    verbl_msg = verbuf; 
  97. 			} else {
  98. 			    vampindex = rn2(SIZE(vampmsg));
  99. 			    if (vampindex == 0) {
  100. 				Sprintf(verbuf, vampmsg[vampindex], body_part(BLOOD));
  101. 	    			verbl_msg = verbuf;
  102. 			    } else if (vampindex == 1) {
  103. 				Sprintf(verbuf, vampmsg[vampindex],
  104. 					Upolyd ? an(mons[u.umonnum].mname) : an(racenoun));
  105. 	    			verbl_msg = verbuf;
  106. 		    	    } else
  107. 			    	verbl_msg = vampmsg[vampindex];
  108. 			}
  109. 	        }
  110. 	    }
  111. 	    break;
  112. 	case MS_WERE:
  113. 	    if (flags.moonphase == FULL_MOON && (night() ^ !rn2(13))) {
  114. 		pline("%s throws back %s head and lets out a blood curdling %s!",
  115. 		      Monnam(mtmp), mhis(mtmp),
  116. 		      ptr == &mons[PM_HUMAN_WERERAT] ? "shriek" : "howl");
  117. 		wake_nearto(mtmp->mx, mtmp->my, 11*11);
  118. 	    } else
  119. 		pline_msg =
  120. 		     "whispers inaudibly.  All you can make out is \"moon\".";
  121. 	    break;
  122. 	case MS_BARK:
  123. 	    if (flags.moonphase == FULL_MOON && night()) {
  124. 		pline_msg = "howls.";
  125. 	    } else if (mtmp->mpeaceful) {
  126. 		if (mtmp->mtame &&
  127. 			(mtmp->mconf || mtmp->mflee || mtmp->mtrapped ||
  128. 			 moves > EDOG(mtmp)->hungrytime || mtmp->mtame < 5))
  129. 		    pline_msg = "whines.";
  130. 		else if (mtmp->mtame && EDOG(mtmp)->hungrytime > moves + 1000)
  131. 		    pline_msg = "yips.";
  132. 		else {
  133. 		    if (mtmp->data != &mons[PM_DINGO])	/* dingos do not actually bark */
  134. 			    pline_msg = "barks.";
  135. 		}
  136. 	    } else {
  137. 		pline_msg = "growls.";
  138. 	    }
  139. 	    break;
  140. 	case MS_MEW:
  141. 	    if (mtmp->mtame) {
  142. 		if (mtmp->mconf || mtmp->mflee || mtmp->mtrapped ||
  143. 			mtmp->mtame < 5)
  144. 		    pline_msg = "yowls.";
  145. 		else if (moves > EDOG(mtmp)->hungrytime)
  146. 		    pline_msg = "meows.";
  147. 		else if (EDOG(mtmp)->hungrytime > moves + 1000)
  148. 		    pline_msg = "purrs.";
  149. 		else
  150. 		    pline_msg = "mews.";
  151. 		break;
  152. 	    } /* else FALLTHRU */
  153. 	case MS_GROWL:
  154. 	    pline_msg = mtmp->mpeaceful ? "snarls." : "growls!";
  155. 	    break;
  156. 	case MS_ROAR:
  157. 	    pline_msg = mtmp->mpeaceful ? "snarls." : "roars!";
  158. 	    break;
  159. 	case MS_SQEEK:
  160. 	    pline_msg = "squeaks.";
  161. 	    break;
  162. 	case MS_SQAWK:
  163. 	    if (ptr == &mons[PM_RAVEN] && !mtmp->mpeaceful)
  164. 	    	verbl_msg = "Nevermore!";
  165. 	    else
  166. 	    	pline_msg = "squawks.";
  167. 	    break;
  168. 	case MS_HISS:
  169. 	    if (!mtmp->mpeaceful)
  170. 		pline_msg = "hisses!";
  171. 	    else return 0;	/* no sound */
  172. 	    break;
  173. 	case MS_BUZZ:
  174. 	    pline_msg = mtmp->mpeaceful ? "drones." : "buzzes angrily.";
  175. 	    break;
  176. 	case MS_GRUNT:
  177. 	    pline_msg = "grunts.";
  178. 	    break;
  179. 	case MS_NEIGH:
  180. 	    if (mtmp->mtame < 5)
  181. 		pline_msg = "neighs.";
  182. 	    else if (moves > EDOG(mtmp)->hungrytime)
  183. 		pline_msg = "whinnies.";
  184. 	    else
  185. 		pline_msg = "whickers.";
  186. 	    break;
  187. 	case MS_WAIL:
  188. 	    pline_msg = "wails mournfully.";
  189. 	    break;
  190. 	case MS_GURGLE:
  191. 	    pline_msg = "gurgles.";
  192. 	    break;
  193. 	case MS_BURBLE:
  194. 	    pline_msg = "burbles.";
  195. 	    break;
  196. 	case MS_SHRIEK:
  197. 	    pline_msg = "shrieks.";
  198. 	    aggravate();
  199. 	    break;
  200. 	case MS_IMITATE:
  201. 	    pline_msg = "imitates you.";
  202. 	    break;
  203. 	case MS_BONES:
  204. 	    pline("%s rattles noisily.", Monnam(mtmp));
  205. 	    You("freeze for a moment.");
  206. 	    nomul(-2);
  207. 	    break;
  208. 	case MS_LAUGH:
  209. 	    {
  210. 		static const char * const laugh_msg[4] = {
  211. 		    "giggles.", "chuckles.", "snickers.", "laughs.",
  212. 		};
  213. 		pline_msg = laugh_msg[rn2(4)];
  214. 	    }
  215. 	    break;
  216. 	case MS_MUMBLE:
  217. 	    pline_msg = "mumbles incomprehensibly.";
  218. 	    break;
  219. 	case MS_DJINNI:
  220. 	    if (mtmp->mtame) {
  221. 		verbl_msg = "Sorry, I'm all out of wishes.";
  222. 	    } else if (mtmp->mpeaceful) {
  223. 		if (ptr == &mons[PM_WATER_DEMON])
  224. 		    pline_msg = "gurgles.";
  225. 		else
  226. 		    verbl_msg = "I'm free!";
  227. 	    } else verbl_msg = "This will teach you not to disturb me!";
  228. 	    break;
  229. 	case MS_BOAST:	/* giants */
  230. 	    if (!mtmp->mpeaceful) {
  231. 		switch (rn2(4)) {
  232. 		case 0: pline("%s boasts about %s gem collection.",
  233. 			      Monnam(mtmp), mhis(mtmp));
  234. 			break;
  235. 		case 1: pline_msg = "complains about a diet of mutton.";
  236. 			break;
  237. 	       default: pline_msg = "shouts \"Fee Fie Foe Foo!\" and guffaws.";
  238. 			wake_nearto(mtmp->mx, mtmp->my, 7*7);
  239. 			break;
  240. 		}
  241. 		break;
  242. 	    }
  243. 	    /* else FALLTHRU */
  244. 	case MS_HUMANOID:
  245. 	    if (!mtmp->mpeaceful) {
  246. 		if (In_endgame(&u.uz) && is_mplayer(ptr)) {
  247. 		    mplayer_talk(mtmp);
  248. 		    break;
  249. 		} else return 0;	/* no sound */
  250. 	    }
  251. 	    /* Generic peaceful humanoid behaviour. */
  252. 	    if (mtmp->mflee)
  253. 		pline_msg = "wants nothing to do with you.";
  254. 	    else if (mtmp->mhp < mtmp->mhpmax/4)
  255. 		pline_msg = "moans.";
  256. 	    else if (mtmp->mconf || mtmp->mstun)
  257. 		verbl_msg = !rn2(3) ? "Huh?" : rn2(2) ? "What?" : "Eh?";
  258. 	    else if (!mtmp->mcansee)
  259. 		verbl_msg = "I can't see!";
  260. 	    else if (mtmp->mtrapped) {
  261. 		struct trap *t = t_at(mtmp->mx, mtmp->my);
  262.  
  263. 		if (t) t->tseen = 1;
  264. 		verbl_msg = "I'm trapped!";
  265. 	    } else if (mtmp->mhp < mtmp->mhpmax/2)
  266. 		pline_msg = "asks for a potion of healing.";
  267. 	    else if (mtmp->mtame && !mtmp->isminion &&
  268. 						moves > EDOG(mtmp)->hungrytime)
  269. 		verbl_msg = "I'm hungry.";
  270. 	    /* Specific monsters' interests */
  271. 	    else if (is_elf(ptr))
  272. 		pline_msg = "curses orcs.";
  273. 	    else if (is_dwarf(ptr))
  274. 		pline_msg = "talks about mining.";
  275. 	    else if (likes_magic(ptr))
  276. 		pline_msg = "talks about spellcraft.";
  277. 	    else if (ptr->mlet == S_CENTAUR)
  278. 		pline_msg = "discusses hunting.";
  279. 	    else switch (monsndx(ptr)) {
  280. 		case PM_HOBBIT:
  281. 		    pline_msg = (mtmp->mhpmax - mtmp->mhp >= 10) ?
  282. 				"complains about unpleasant dungeon conditions."
  283. 				: "asks you about the One Ring.";
  284. 		    break;
  285. 		case PM_ARCHEOLOGIST:
  286. pline_msg = "describes a recent article in \"Spelunker Today\" magazine.";
  287. 		    break;
  288. #ifdef TOURIST
  289. 		case PM_TOURIST:
  290. 		    verbl_msg = "Aloha.";
  291. 		    break;
  292. #endif
  293. 		default:
  294. 		    pline_msg = "discusses dungeon exploration.";
  295. 		    break;
  296. 	    }
  297. 	    break;
  298. 	case MS_SEDUCE:
  299. #ifdef SEDUCE
  300. 	    if (ptr->mlet != S_NYMPH &&
  301. 		could_seduce(mtmp, &youmonst, (struct attack *)0) == 1) {
  302. 			(void) doseduce(mtmp);
  303. 			break;
  304. 	    }
  305. 	    switch ((poly_gender() != (int) mtmp->female) ? rn2(3) : 0)
  306. #else
  307. 	    switch ((poly_gender() == 0) ? rn2(3) : 0)
  308. #endif
  309. 	    {
  310. 		case 2:
  311. 			verbl_msg = "Hello, sailor.";
  312. 			break;
  313. 		case 1:
  314. 			pline_msg = "comes on to you.";
  315. 			break;
  316. 		default:
  317. 			pline_msg = "cajoles you.";
  318. 	    }
  319. 	    break;
  320. #ifdef KOPS
  321. 	case MS_ARREST:
  322. 	    if (mtmp->mpeaceful)
  323. 		verbalize("Just the facts, %s.",
  324. 		      flags.female ? "Ma'am" : "Sir");
  325. 	    else {
  326. 		static const char * const arrest_msg[3] = {
  327. 		    "Anything you say can be used against you.",
  328. 		    "You're under arrest!",
  329. 		    "Stop in the name of the Law!",
  330. 		};
  331. 		verbl_msg = arrest_msg[rn2(3)];
  332. 	    }
  333. 	    break;
  334. #endif
  335. 	case MS_BRIBE:
  336. 	    if (mtmp->mpeaceful && !mtmp->mtame) {
  337. 		(void) demon_talk(mtmp);
  338. 		break;
  339. 	    }
  340. 	    /* fall through */
  341. 	case MS_CUSS:
  342. 	    if (!mtmp->mpeaceful)
  343. 		cuss(mtmp);
  344. 	    break;
  345. 	case MS_SPELL:
  346. 	    /* deliberately vague, since it's not actually casting any spell */
  347. 	    pline_msg = "seems to mutter a cantrip.";
  348. 	    break;
  349. 	case MS_NURSE:
  350. 	    if (uwep && (uwep->oclass == WEAPON_CLASS || is_weptool(uwep)))
  351. 		verbl_msg = "Put that weapon away before you hurt someone!";
  352. 	    else if (uarmc || uarm || uarmh || uarms || uarmg || uarmf)
  353. 		verbl_msg = Role_if(PM_HEALER) ?
  354. 			  "Doc, I can't help you unless you cooperate." :
  355. 			  "Please undress so I can examine you.";
  356. #ifdef TOURIST
  357. 	    else if (uarmu)
  358. 		verbl_msg = "Take off your shirt, please.";
  359. #endif
  360. 	    else verbl_msg = "Relax, this won't hurt a bit.";
  361. 	    break;
  362. 	case MS_GUARD:
  363. #ifndef GOLDOBJ
  364. 	    if (u.ugold)
  365. #else
  366. 	    if (money_cnt(invent))
  367. #endif
  368. 		verbl_msg = "Please drop that gold and follow me.";
  369. 	    else
  370. 		verbl_msg = "Please follow me.";
  371. 	    break;
  372. 	case MS_SOLDIER:
  373. 	    {
  374. 		static const char * const soldier_foe_msg[3] = {
  375. 		    "Resistance is useless!",
  376. 		    "You're dog meat!",
  377. 		    "Surrender!",
  378. 		},		  * const soldier_pax_msg[3] = {
  379. 		    "What lousy pay we're getting here!",
  380. 		    "The food's not fit for Orcs!",
  381. 		    "My feet hurt, I've been on them all day!",
  382. 		};
  383. 		verbl_msg = mtmp->mpeaceful ? soldier_pax_msg[rn2(3)]
  384. 					    : soldier_foe_msg[rn2(3)];
  385. 	    }
  386. 	    break;
  387. 	case MS_RIDER:
  388. 	    if (ptr == &mons[PM_DEATH] && !rn2(10))
  389. 		pline_msg = "is busy reading a copy of Sandman #8.";
  390. 	    else verbl_msg = "Who do you think you are, War?";
  391. 	    break;
  392. }
  393.  
  394. if (pline_msg) pline("%s %s", Monnam(mtmp), pline_msg);
  395. else if (verbl_msg) verbalize(verbl_msg);
  396. return(1);
  397. }

dotalk

  1. int
  2. dotalk()
  3. {
  4. int result;
  5. boolean save_soundok = flags.soundok;
  6. flags.soundok = 1;	/* always allow sounds while chatting */
  7. result = dochat();
  8. flags.soundok = save_soundok;
  9. return result;
  10. }

dochat

  1. static int
  2. dochat()
  3. {
  4. register struct monst *mtmp;
  5. register int tx,ty;
  6. struct obj *otmp;
  7.  
  8. if (is_silent(youmonst.data)) {
  9. 	pline("As %s, you cannot speak.", an(youmonst.data->mname));
  10. 	return(0);
  11. }
  12. if (Strangled) {
  13. 	You_cant("speak.  You're choking!");
  14. 	return(0);
  15. }
  16. if (u.uswallow) {
  17. 	pline("They won't hear you out there.");
  18. 	return(0);
  19. }
  20. if (Underwater) {
  21. 	Your("speech is unintelligible underwater.");
  22. 	return(0);
  23. }
  24.  
  25. if (!Blind && (otmp = shop_object(u.ux, u.uy)) != (struct obj *)0) {
  26. 	/* standing on something in a shop and chatting causes the shopkeeper
  27. 	   to describe the price(s).  This can inhibit other chatting inside
  28. 	   a shop, but that shouldn't matter much.  shop_object() returns an
  29. 	   object iff inside a shop and the shopkeeper is present and willing
  30. 	   (not angry) and able (not asleep) to speak and the position contains
  31. 	   any objects other than just gold.
  32. 	*/
  33. 	price_quote(otmp);
  34. 	return(1);
  35. }
  36.  
  37. if (!getdir("Talk to whom? (in what direction)")) {
  38. 	/* decided not to chat */
  39. 	return(0);
  40. }
  41.  
  42. #ifdef STEED
  43. if (u.usteed && u.dz > 0)
  44. 	return (domonnoise(u.usteed));
  45. #endif
  46. if (u.dz) {
  47. 	pline("They won't hear you %s there.", u.dz < 0 ? "up" : "down");
  48. 	return(0);
  49. }
  50.  
  51. if (u.dx == 0 && u.dy == 0) {
  52. /*
  53. * Let's not include this.  It raises all sorts of questions: can you wear
  54. * 2 helmets, 2 amulets, 3 pairs of gloves or 6 rings as a marilith,
  55. * etc...  --KAA
  56. 	if (u.umonnum == PM_ETTIN) {
  57. 	    You("discover that your other head makes boring conversation.");
  58. 	    return(1);
  59. 	}
  60. */
  61. 	pline("Talking to yourself is a bad habit for a dungeoneer.");
  62. 	return(0);
  63. }
  64.  
  65. tx = u.ux+u.dx; ty = u.uy+u.dy;
  66. mtmp = m_at(tx, ty);
  67.  
  68. if (!mtmp || mtmp->mundetected ||
  69. 		mtmp->m_ap_type == M_AP_FURNITURE ||
  70. 		mtmp->m_ap_type == M_AP_OBJECT)
  71. 	return(0);
  72.  
  73. /* sleeping monsters won't talk, except priests (who wake up) */
  74. if ((!mtmp->mcanmove || mtmp->msleeping) && !mtmp->ispriest) {
  75. 	/* If it is unseen, the player can't tell the difference between
  76. 	   not noticing him and just not existing, so skip the message. */
  77. 	if (canspotmon(mtmp))
  78. 	    pline("%s seems not to notice you.", Monnam(mtmp));
  79. 	return(0);
  80. }
  81.  
  82. /* if this monster is waiting for something, prod it into action */
  83. mtmp->mstrategy &= ~STRAT_WAITMASK;
  84.  
  85. if (mtmp->mtame && mtmp->meating) {
  86. 	if (!canspotmon(mtmp))
  87. 	    map_invisible(mtmp->mx, mtmp->my);
  88. 	pline("%s is eating noisily.", Monnam(mtmp));
  89. 	return (0);
  90. }
  91.  
  92. return domonnoise(mtmp);
  93. }
  1. #ifdef USER_SOUNDS
  2.  
  3. extern void FDECL(play_usersound, (const char*, int));
  4.  
  5. typedef struct audio_mapping_rec {
  6. #ifdef USER_SOUNDS_REGEX
  7. 	struct re_pattern_buffer regex;
  8. #else
  9. 	char *pattern;
  10. #endif
  11. 	char *filename;
  12. 	int volume;
  13. 	struct audio_mapping_rec *next;
  14. } audio_mapping;
  15.  
  16. static audio_mapping *soundmap = 0;
  17.  
  18. char* sounddir = ".";

add_sound_mapping

  1. /* adds a sound file mapping, returns 0 on failure, 1 on success */
  2. int
  3. add_sound_mapping(mapping)
  4. const char *mapping;
  5. {
  6. 	char text[256];
  7. 	char filename[256];
  8. 	char filespec[256];
  9. 	int volume;
  10.  
  11. 	if (sscanf(mapping, "MESG \"%255[^\"]\"%*[\t ]\"%255[^\"]\" %d",
  12. 		   text, filename, &volume) == 3) {
  13. 	    const char *err;
  14. 	    audio_mapping *new_map;
  15.  
  16. 	    if (strlen(sounddir) + strlen(filename) > 254) {
  17. 		raw_print("sound file name too long");
  18. 		return 0;
  19. 	    }
  20. 	    Sprintf(filespec, "%s/%s", sounddir, filename);
  21.  
  22. 	    if (can_read_file(filespec)) {
  23. 		new_map = (audio_mapping *)alloc(sizeof(audio_mapping));
  24. #ifdef USER_SOUNDS_REGEX
  25. 		new_map->regex.translate = 0;
  26. 		new_map->regex.fastmap = 0;
  27. 		new_map->regex.buffer = 0;
  28. 		new_map->regex.allocated = 0;
  29. 		new_map->regex.regs_allocated = REGS_FIXED;
  30. #else
  31. 		new_map->pattern = (char *)alloc(strlen(text) + 1);
  32. 		Strcpy(new_map->pattern, text);
  33. #endif
  34. 		new_map->filename = strdup(filespec);
  35. 		new_map->volume = volume;
  36. 		new_map->next = soundmap;
  37.  
  38. #ifdef USER_SOUNDS_REGEX
  39. 		err = re_compile_pattern(text, strlen(text), &new_map->regex);
  40. #else
  41. 		err = 0;
  42. #endif
  43. 		if (err) {
  44. 		    raw_print(err);
  45. 		    free(new_map->filename);
  46. 		    free(new_map);
  47. 		    return 0;
  48. 		} else {
  49. 		    soundmap = new_map;
  50. 		}
  51. 	    } else {
  52. 		Sprintf(text, "cannot read %.243s", filespec);
  53. 		raw_print(text);
  54. 		return 0;
  55. 	    }
  56. 	} else {
  57. 	    raw_print("syntax error in SOUND");
  58. 	    return 0;
  59. 	}
  60.  
  61. 	return 1;
  62. }

play_sound_for_message

  1. void
  2. play_sound_for_message(msg)
  3. const char* msg;
  4. {
  5. 	audio_mapping* cursor = soundmap;
  6.  
  7. 	while (cursor) {
  8. #ifdef USER_SOUNDS_REGEX
  9. 	    if (re_search(&cursor->regex, msg, strlen(msg), 0, 9999, 0) >= 0) {
  10. #else
  11. 	    if (pmatch(cursor->pattern, msg)) {
  12. #endif
  13. 		play_usersound(cursor->filename, cursor->volume);
  14. 	    }
  15. 	    cursor = cursor->next;
  16. 	}
  17. }
  18.  
  19. #endif /* USER_SOUNDS */
  20.  
  21. #endif /* OVLB */
  22.  
  23. /*sounds.c*/