Source:NetHack 3.4.3/src/music.c

From NetHackWiki
Jump to: navigation, search

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

Top of file[edit]

  1. /*	SCCS Id: @(#)music.c	3.4	2003/05/25	*/
  2. /*	Copyright (c) 1989 by Jean-Christophe Collet */
  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. /*
  2. * This file contains the different functions designed to manipulate the
  3. * musical instruments and their various effects.
  4. *
  5. * Actually the list of instruments / effects is :
  6. *
  7. * (wooden) flute	may calm snakes if player has enough dexterity
  8. * magic flute		may put monsters to sleep:  area of effect depends
  9. *			on player level.
  10. * (tooled) horn	Will awaken monsters:  area of effect depends on player
  11. *			level.  May also scare monsters.
  12. * fire horn		Acts like a wand of fire.
  13. * frost horn		Acts like a wand of cold.
  14. * bugle		Will awaken soldiers (if any):  area of effect depends
  15. *			on player level.
  16. * (wooden) harp	May calm nymph if player has enough dexterity.
  17. * magic harp		Charm monsters:  area of effect depends on player
  18. *			level.
  19. * (leather) drum	Will awaken monsters like the horn.
  20. * drum of earthquake	Will initiate an earthquake whose intensity depends
  21. *			on player level.  That is, it creates random pits
  22. *			called here chasms.
  23. */
  1. #include "hack.h"
  2.  
  3. STATIC_DCL void FDECL(awaken_monsters,(int));
  4. STATIC_DCL void FDECL(put_monsters_to_sleep,(int));
  5. STATIC_DCL void FDECL(charm_snakes,(int));
  6. STATIC_DCL void FDECL(calm_nymphs,(int));
  7. STATIC_DCL void FDECL(charm_monsters,(int));
  8. STATIC_DCL void FDECL(do_earthquake,(int));
  9. STATIC_DCL int FDECL(do_improvisation,(struct obj *));
  10.  
  11. #ifdef UNIX386MUSIC
  12. STATIC_DCL int NDECL(atconsole);
  13. STATIC_DCL void FDECL(speaker,(struct obj *,char *));
  14. #endif
  15. #ifdef VPIX_MUSIC
  16. extern int sco_flag_console;	/* will need changing if not _M_UNIX */
  17. STATIC_DCL void NDECL(playinit);
  18. STATIC_DCL void FDECL(playstring, (char *,size_t));
  19. STATIC_DCL void FDECL(speaker,(struct obj *,char *));
  20. #endif
  21. #ifdef PCMUSIC
  22. void FDECL( pc_speaker, ( struct obj *, char * ) );
  23. #endif
  24. #ifdef AMIGA
  25. void FDECL( amii_speaker, ( struct obj *, char *, int ) );
  26. #endif

awaken_monsters[edit]

  1. /*
  2. * Wake every monster in range...
  3. */
  4.  
  5. STATIC_OVL void
  6. awaken_monsters(distance)
  7. int distance;
  8. {
  9. 	register struct monst *mtmp = fmon;
  10. 	register int distm;
  11.  
  12. 	while(mtmp) {
  13. 	    if (!DEADMONSTER(mtmp)) {
  14. 		distm = distu(mtmp->mx, mtmp->my);
  15. 		if (distm < distance) {
  16. 		    mtmp->msleeping = 0;
  17. 		    mtmp->mcanmove = 1;
  18. 		    mtmp->mfrozen = 0;
  19. 		    /* May scare some monsters */
  20. 		    if (distm < distance/3 &&
  21. 			    !resist(mtmp, TOOL_CLASS, 0, NOTELL))
  22. 			monflee(mtmp, 0, FALSE, TRUE);
  23. 		}
  24. 	    }
  25. 	    mtmp = mtmp->nmon;
  26. 	}
  27. }

put_monsters_to_sleep[edit]

  1. /*
  2. * Make monsters fall asleep.  Note that they may resist the spell.
  3. */
  4.  
  5. STATIC_OVL void
  6. put_monsters_to_sleep(distance)
  7. int distance;
  8. {
  9. 	register struct monst *mtmp = fmon;
  10.  
  11. 	while(mtmp) {
  12. 		if (!DEADMONSTER(mtmp) && distu(mtmp->mx, mtmp->my) < distance &&
  13. 			sleep_monst(mtmp, d(10,10), TOOL_CLASS)) {
  14. 		    mtmp->msleeping = 1; /* 10d10 turns + wake_nearby to rouse */
  15. 		    slept_monst(mtmp);
  16. 		}
  17. 		mtmp = mtmp->nmon;
  18. 	}
  19. }

charm_snakes[edit]

  1. /*
  2. * Charm snakes in range.  Note that the snakes are NOT tamed.
  3. */
  4.  
  5. STATIC_OVL void
  6. charm_snakes(distance)
  7. int distance;
  8. {
  9. 	register struct monst *mtmp = fmon;
  10. 	int could_see_mon, was_peaceful;
  11.  
  12. 	while (mtmp) {
  13. 	    if (!DEADMONSTER(mtmp) && mtmp->data->mlet == S_SNAKE && mtmp->mcanmove &&
  14. 		    distu(mtmp->mx, mtmp->my) < distance) {
  15. 		was_peaceful = mtmp->mpeaceful;
  16. 		mtmp->mpeaceful = 1;
  17. 		mtmp->mavenge = 0;
  18. 		could_see_mon = canseemon(mtmp);
  19. 		mtmp->mundetected = 0;
  20. 		newsym(mtmp->mx, mtmp->my);
  21. 		if (canseemon(mtmp)) {
  22. 		    if (!could_see_mon)
  23. 			You("notice %s, swaying with the music.",
  24. 			    a_monnam(mtmp));
  25. 		    else
  26. 			pline("%s freezes, then sways with the music%s.",
  27. 			      Monnam(mtmp),
  28. 			      was_peaceful ? "" : ", and now seems quieter");
  29. 		}
  30. 	    }
  31. 	    mtmp = mtmp->nmon;
  32. 	}
  33. }

calm_nymphs[edit]

  1. /*
  2. * Calm nymphs in range.
  3. */
  4.  
  5. STATIC_OVL void
  6. calm_nymphs(distance)
  7. int distance;
  8. {
  9. 	register struct monst *mtmp = fmon;
  10.  
  11. 	while (mtmp) {
  12. 	    if (!DEADMONSTER(mtmp) && mtmp->data->mlet == S_NYMPH && mtmp->mcanmove &&
  13. 		    distu(mtmp->mx, mtmp->my) < distance) {
  14. 		mtmp->msleeping = 0;
  15. 		mtmp->mpeaceful = 1;
  16. 		mtmp->mavenge = 0;
  17. 		if (canseemon(mtmp))
  18. 		    pline(
  19. 		     "%s listens cheerfully to the music, then seems quieter.",
  20. 			  Monnam(mtmp));
  21. 	    }
  22. 	    mtmp = mtmp->nmon;
  23. 	}
  24. }

awaken_soldiers[edit]

  1. /* Awake only soldiers of the level. */
  2.  
  3. void
  4. awaken_soldiers()
  5. {
  6. 	register struct monst *mtmp = fmon;
  7.  
  8. 	while(mtmp) {
  9. 	    if (!DEADMONSTER(mtmp) &&
  10. 			is_mercenary(mtmp->data) && mtmp->data != &mons[PM_GUARD]) {
  11. 		mtmp->mpeaceful = mtmp->msleeping = mtmp->mfrozen = 0;
  12. 		mtmp->mcanmove = 1;
  13. 		if (canseemon(mtmp))
  14. 		    pline("%s is now ready for battle!", Monnam(mtmp));
  15. 		else
  16. 		    Norep("You hear the rattle of battle gear being readied.");
  17. 	    }
  18. 	    mtmp = mtmp->nmon;
  19. 	}
  20. }

charm_monsters[edit]

  1. /* Charm monsters in range.  Note that they may resist the spell.
  2. * If swallowed, range is reduced to 0.
  3. */
  4.  
  5. STATIC_OVL void
  6. charm_monsters(distance)
  7. int distance;
  8. {
  9. 	struct monst *mtmp, *mtmp2;
  10.  
  11. 	if (u.uswallow) {
  12. 	    if (!resist(u.ustuck, TOOL_CLASS, 0, NOTELL))
  13. 		(void) tamedog(u.ustuck, (struct obj *) 0);
  14. 	} else {
  15. 	    for (mtmp = fmon; mtmp; mtmp = mtmp2) {
  16. 		mtmp2 = mtmp->nmon;
  17. 		if (DEADMONSTER(mtmp)) continue;
  18.  
  19. 		if (distu(mtmp->mx, mtmp->my) <= distance) {
  20. 		    if (!resist(mtmp, TOOL_CLASS, 0, NOTELL))
  21. 			(void) tamedog(mtmp, (struct obj *) 0);
  22. 		}
  23. 	    }
  24. 	}
  25.  
  26. }

do_earthquake[edit]

  1. /* Generate earthquake :-) of desired force.
  2. * That is:  create random chasms (pits).
  3. */
  4.  
  5. STATIC_OVL void
  6. do_earthquake(force)
  7. int force;
  8. {
  9. 	register int x,y;
  10. 	struct monst *mtmp;
  11. 	struct obj *otmp;
  12. 	struct trap *chasm;
  13. 	int start_x, start_y, end_x, end_y;
  14.  
  15. 	start_x = u.ux - (force * 2);
  16. 	start_y = u.uy - (force * 2);
  17. 	end_x = u.ux + (force * 2);
  18. 	end_y = u.uy + (force * 2);
  19. 	if (start_x < 1) start_x = 1;
  20. 	if (start_y < 1) start_y = 1;
  21. 	if (end_x >= COLNO) end_x = COLNO - 1;
  22. 	if (end_y >= ROWNO) end_y = ROWNO - 1;
  23. 	for (x=start_x; x<=end_x; x++) for (y=start_y; y<=end_y; y++) {
  24. 	    if ((mtmp = m_at(x,y)) != 0) {
  25. 		wakeup(mtmp);	/* peaceful monster will become hostile */
  26. 		if (mtmp->mundetected && is_hider(mtmp->data)) {
  27. 		    mtmp->mundetected = 0;
  28. 		    if (cansee(x,y))
  29. 			pline("%s is shaken loose from the ceiling!",
  30. 							    Amonnam(mtmp));
  31. 		    else
  32. 			You_hear("a thumping sound.");
  33. 		    if (x==u.ux && y==u.uy)
  34. 			You("easily dodge the falling %s.",
  35. 							    mon_nam(mtmp));
  36. 		    newsym(x,y);
  37. 		}
  38. 	    }
  39. 	    if (!rn2(14 - force)) switch (levl[x][y].typ) {
  40. 		  case FOUNTAIN : /* Make the fountain disappear */
  41. 			if (cansee(x,y))
  42. 				pline_The("fountain falls into a chasm.");
  43. 			goto do_pit;
  44. #ifdef SINKS
  45. 		  case SINK :
  46. 			if (cansee(x,y))
  47. 				pline_The("kitchen sink falls into a chasm.");
  48. 			goto do_pit;
  49. #endif
  50. 		  case ALTAR :
  51. 			if (Is_astralevel(&u.uz) || Is_sanctum(&u.uz)) break;
  52.  
  53. 			if (cansee(x,y))
  54. 				pline_The("altar falls into a chasm.");
  55. 			goto do_pit;
  56. 		  case GRAVE :
  57. 			if (cansee(x,y))
  58. 				pline_The("headstone topples into a chasm.");
  59. 			goto do_pit;
  60. 		  case THRONE :
  61. 			if (cansee(x,y))
  62. 				pline_The("throne falls into a chasm.");
  63. 			/* Falls into next case */
  64. 		  case ROOM :
  65. 		  case CORR : /* Try to make a pit */
  66. do_pit:		    chasm = maketrap(x,y,PIT);
  67. 		    if (!chasm) break;	/* no pit if portal at that location */
  68. 		    chasm->tseen = 1;
  69.  
  70. 		    levl[x][y].doormask = 0;
  71.  
  72. 		    mtmp = m_at(x,y);
  73.  
  74. 		    if ((otmp = sobj_at(BOULDER, x, y)) != 0) {
  75. 			if (cansee(x, y))
  76. 			   pline("KADOOM! The boulder falls into a chasm%s!",
  77. 			      ((x == u.ux) && (y == u.uy)) ? " below you" : "");
  78. 			if (mtmp)
  79. 				mtmp->mtrapped = 0;
  80. 			obj_extract_self(otmp);
  81. 			(void) flooreffects(otmp, x, y, "");
  82. 			break;
  83. 		    }
  84.  
  85. 		    /* We have to check whether monsters or player
  86. 		       falls in a chasm... */
  87.  
  88. 		    if (mtmp) {
  89. 			if(!is_flyer(mtmp->data) && !is_clinger(mtmp->data)) {
  90. 			    mtmp->mtrapped = 1;
  91. 			    if(cansee(x,y))
  92. 				pline("%s falls into a chasm!", Monnam(mtmp));
  93. 			    else if (flags.soundok && humanoid(mtmp->data))
  94. 				You_hear("a scream!");
  95. 			    mselftouch(mtmp, "Falling, ", TRUE);
  96. 			    if (mtmp->mhp > 0)
  97. 				if ((mtmp->mhp -= rnd(6)) <= 0) {
  98. 				    if(!cansee(x,y))
  99. 					pline("It is destroyed!");
  100. 				    else {
  101. 					You("destroy %s!", mtmp->mtame ?
  102. 					    x_monnam(mtmp, ARTICLE_THE, "poor",
  103. 				mtmp->mnamelth ? SUPPRESS_SADDLE : 0, FALSE):
  104. 					    mon_nam(mtmp));
  105. 				    }
  106. 				    xkilled(mtmp,0);
  107. 				}
  108. 			}
  109. 		    } else if (x == u.ux && y == u.uy) {
  110. 			    if (Levitation || Flying ||
  111. 						is_clinger(youmonst.data)) {
  112. 				    pline("A chasm opens up under you!");
  113. 				    You("don't fall in!");
  114. 			    } else {
  115. 				    You("fall into a chasm!");
  116. 				    u.utrap = rn1(6,2);
  117. 				    u.utraptype = TT_PIT;
  118. 				    losehp(rnd(6),"fell into a chasm",
  119. 					NO_KILLER_PREFIX);
  120. 				    selftouch("Falling, you");
  121. 			    }
  122. 		    } else newsym(x,y);
  123. 		    break;
  124. 		  case DOOR : /* Make the door collapse */
  125. 		    if (levl[x][y].doormask == D_NODOOR) goto do_pit;
  126. 		    if (cansee(x,y))
  127. 			pline_The("door collapses.");
  128. 		    if (*in_rooms(x, y, SHOPBASE))
  129. 			add_damage(x, y, 0L);
  130. 		    levl[x][y].doormask = D_NODOOR;
  131. 		    unblock_point(x,y);
  132. 		    newsym(x,y);
  133. 		    break;
  134. 	    }
  135. 	}
  136. }

do_improvisation[edit]

  1. /*
  2. * The player is trying to extract something from his/her instrument.
  3. */
  4.  
  5. STATIC_OVL int
  6. do_improvisation(instr)
  7. struct obj *instr;
  8. {
  9. 	int damage, do_spec = !Confusion;
  10. #if defined(MAC) || defined(AMIGA) || defined(VPIX_MUSIC) || defined (PCMUSIC)
  11. 	struct obj itmp;
  12.  
  13. 	itmp = *instr;
  14. 	/* if won't yield special effect, make sound of mundane counterpart */
  15. 	if (!do_spec || instr->spe <= 0)
  16. 	    while (objects[itmp.otyp].oc_magic) itmp.otyp -= 1;
  17. # ifdef MAC
  18. 	mac_speaker(&itmp, "C");
  19. # endif
  20. # ifdef AMIGA
  21. 	amii_speaker(&itmp, "Cw", AMII_OKAY_VOLUME);
  22. # endif
  23. # ifdef VPIX_MUSIC
  24. 	if (sco_flag_console)
  25. 	    speaker(&itmp, "C");
  26. # endif
  27. #ifdef PCMUSIC
  28. 	  pc_speaker ( &itmp, "C");
  29. #endif
  30. #endif /* MAC || AMIGA || VPIX_MUSIC || PCMUSIC */
  31.  
  32. 	if (!do_spec)
  33. 	    pline("What you produce is quite far from music...");
  34. 	else
  35. 	    You("start playing %s.", the(xname(instr)));
  36.  
  37. 	switch (instr->otyp) {
  38. 	case MAGIC_FLUTE:		/* Make monster fall asleep */
  39. 	    if (do_spec && instr->spe > 0) {
  40. 		consume_obj_charge(instr, TRUE);
  41.  
  42. 		You("produce soft music.");
  43. 		put_monsters_to_sleep(u.ulevel * 5);
  44. 		exercise(A_DEX, TRUE);
  45. 		break;
  46. 	    } /* else FALLTHRU */
  47. 	case WOODEN_FLUTE:		/* May charm snakes */
  48. 	    do_spec &= (rn2(ACURR(A_DEX)) + u.ulevel > 25);
  49. 	    pline("%s.", Tobjnam(instr, do_spec ? "trill" : "toot"));
  50. 	    if (do_spec) charm_snakes(u.ulevel * 3);
  51. 	    exercise(A_DEX, TRUE);
  52. 	    break;
  53. 	case FROST_HORN:		/* Idem wand of cold */
  54. 	case FIRE_HORN:			/* Idem wand of fire */
  55. 	    if (do_spec && instr->spe > 0) {
  56. 		consume_obj_charge(instr, TRUE);
  57.  
  58. 		if (!getdir((char *)0)) {
  59. 		    pline("%s.", Tobjnam(instr, "vibrate"));
  60. 		    break;
  61. 		} else if (!u.dx && !u.dy && !u.dz) {
  62. 		    if ((damage = zapyourself(instr, TRUE)) != 0) {
  63. 			char buf[BUFSZ];
  64. 			Sprintf(buf, "using a magical horn on %sself", uhim());
  65. 			losehp(damage, buf, KILLED_BY);
  66. 		    }
  67. 		} else {
  68. 		    buzz((instr->otyp == FROST_HORN) ? AD_COLD-1 : AD_FIRE-1,
  69. 			 rn1(6,6), u.ux, u.uy, u.dx, u.dy);
  70. 		}
  71. 		makeknown(instr->otyp);
  72. 		break;
  73. 	    } /* else FALLTHRU */
  74. 	case TOOLED_HORN:		/* Awaken or scare monsters */
  75. 	    You("produce a frightful, grave sound.");
  76. 	    awaken_monsters(u.ulevel * 30);
  77. 	    exercise(A_WIS, FALSE);
  78. 	    break;
  79. 	case BUGLE:			/* Awaken & attract soldiers */
  80. 	    You("extract a loud noise from %s.", the(xname(instr)));
  81. 	    awaken_soldiers();
  82. 	    exercise(A_WIS, FALSE);
  83. 	    break;
  84. 	case MAGIC_HARP:		/* Charm monsters */
  85. 	    if (do_spec && instr->spe > 0) {
  86. 		consume_obj_charge(instr, TRUE);
  87.  
  88. 		pline("%s very attractive music.", Tobjnam(instr, "produce"));
  89. 		charm_monsters((u.ulevel - 1) / 3 + 1);
  90. 		exercise(A_DEX, TRUE);
  91. 		break;
  92. 	    } /* else FALLTHRU */
  93. 	case WOODEN_HARP:		/* May calm Nymph */
  94. 	    do_spec &= (rn2(ACURR(A_DEX)) + u.ulevel > 25);
  95. 	    pline("%s %s.", The(xname(instr)),
  96. 		  do_spec ? "produces a lilting melody" : "twangs");
  97. 	    if (do_spec) calm_nymphs(u.ulevel * 3);
  98. 	    exercise(A_DEX, TRUE);
  99. 	    break;
  100. 	case DRUM_OF_EARTHQUAKE:	/* create several pits */
  101. 	    if (do_spec && instr->spe > 0) {
  102. 		consume_obj_charge(instr, TRUE);
  103.  
  104. 		You("produce a heavy, thunderous rolling!");
  105. 		pline_The("entire dungeon is shaking around you!");
  106. 		do_earthquake((u.ulevel - 1) / 3 + 1);
  107. 		/* shake up monsters in a much larger radius... */
  108. 		awaken_monsters(ROWNO * COLNO);
  109. 		makeknown(DRUM_OF_EARTHQUAKE);
  110. 		break;
  111. 	    } /* else FALLTHRU */
  112. 	case LEATHER_DRUM:		/* Awaken monsters */
  113. 	    You("beat a deafening row!");
  114. 	    awaken_monsters(u.ulevel * 40);
  115. 	    exercise(A_WIS, FALSE);
  116. 	    break;
  117. 	default:
  118. 	    impossible("What a weird instrument (%d)!", instr->otyp);
  119. 	    break;
  120. 	}
  121. 	return 2;		/* That takes time */
  122. }

do_play_instrument[edit]

  1. /*
  2. * So you want music...
  3. */
  4.  
  5. int
  6. do_play_instrument(instr)
  7. struct obj *instr;
  8. {
  9. char buf[BUFSZ], c = 'y';
  10. char *s;
  11. int x,y;
  12. boolean ok;
  13.  
  14. if (Underwater) {
  15. 	You_cant("play music underwater!");
  16. 	return(0);
  17. }
  18. if (instr->otyp != LEATHER_DRUM && instr->otyp != DRUM_OF_EARTHQUAKE) {
  19. 	c = yn("Improvise?");
  20. }
  21. if (c == 'n') {
  22. 	if (u.uevent.uheard_tune == 2 && yn("Play the passtune?") == 'y') {
  23. 	    Strcpy(buf, tune);
  24. 	} else {
  25. 	    getlin("What tune are you playing? [5 notes, A-G]", buf);
  26. 	    (void)mungspaces(buf);
  27. 	    /* convert to uppercase and change any "H" to the expected "B" */
  28. 	    for (s = buf; *s; s++) {
  29. #ifndef AMIGA
  30. 		*s = highc(*s);
  31. #else
  32. 		/* The AMIGA supports two octaves of notes */
  33. 		if (*s == 'h') *s = 'b';
  34. #endif
  35. 		if (*s == 'H') *s = 'B';
  36. 	    }
  37. 	}
  38. 	You("extract a strange sound from %s!", the(xname(instr)));
  39. #ifdef UNIX386MUSIC
  40. 	/* if user is at the console, play through the console speaker */
  41. 	if (atconsole())
  42. 	    speaker(instr, buf);
  43. #endif
  44. #ifdef VPIX_MUSIC
  45. 	if (sco_flag_console)
  46. 	    speaker(instr, buf);
  47. #endif
  48. #ifdef MAC
  49. 	mac_speaker ( instr , buf ) ;
  50. #endif
  51. #ifdef PCMUSIC
  52. 	pc_speaker ( instr, buf );
  53. #endif
  54. #ifdef AMIGA
  55. 	{
  56. 		char nbuf[ 20 ];
  57. 		int i;
  58. 		for( i = 0; buf[i] && i < 5; ++i )
  59. 		{
  60. 			nbuf[ i*2 ] = buf[ i ];
  61. 			nbuf[ (i*2)+1 ] = 'h';
  62. 		}
  63. 		nbuf[ i*2 ] = 0;
  64. 		amii_speaker ( instr , nbuf, AMII_OKAY_VOLUME ) ;
  65. 	}
  66. #endif
  67. 	/* Check if there was the Stronghold drawbridge near
  68. 	 * and if the tune conforms to what we're waiting for.
  69. 	 */
  70. 	if(Is_stronghold(&u.uz)) {
  71. 	    exercise(A_WIS, TRUE);		/* just for trying */
  72. 	    if(!strcmp(buf,tune)) {
  73. 		/* Search for the drawbridge */
  74. 		for(y=u.uy-1; y<=u.uy+1; y++)
  75. 		    for(x=u.ux-1;x<=u.ux+1;x++)
  76. 			if(isok(x,y))
  77. 			if(find_drawbridge(&x,&y)) {
  78. 			    u.uevent.uheard_tune = 2; /* tune now fully known */
  79. 			    if(levl[x][y].typ == DRAWBRIDGE_DOWN)
  80. 				close_drawbridge(x,y);
  81. 			    else
  82. 				open_drawbridge(x,y);
  83. 			    return 0;
  84. 			}
  85. 	    } else if(flags.soundok) {
  86. 		if (u.uevent.uheard_tune < 1) u.uevent.uheard_tune = 1;
  87. 		/* Okay, it wasn't the right tune, but perhaps
  88. 		 * we can give the player some hints like in the
  89. 		 * Mastermind game */
  90. 		ok = FALSE;
  91. 		for(y = u.uy-1; y <= u.uy+1 && !ok; y++)
  92. 		    for(x = u.ux-1; x <= u.ux+1 && !ok; x++)
  93. 			if(isok(x,y))
  94. 			if(IS_DRAWBRIDGE(levl[x][y].typ) ||
  95. 			   is_drawbridge_wall(x,y) >= 0)
  96. 				ok = TRUE;
  97. 		if(ok) { /* There is a drawbridge near */
  98. 		    int tumblers, gears;
  99. 		    boolean matched[5];
  100.  
  101. 		    tumblers = gears = 0;
  102. 		    for(x=0; x < 5; x++)
  103. 			matched[x] = FALSE;
  104.  
  105. 		    for(x=0; x < (int)strlen(buf); x++)
  106. 			if(x < 5) {
  107. 			    if(buf[x] == tune[x]) {
  108. 				gears++;
  109. 				matched[x] = TRUE;
  110. 			    } else
  111. 				for(y=0; y < 5; y++)
  112. 				    if(!matched[y] &&
  113. 				       buf[x] == tune[y] &&
  114. 				       buf[y] != tune[y]) {
  115. 					tumblers++;
  116. 					matched[y] = TRUE;
  117. 					break;
  118. 				    }
  119. 			}
  120. 		    if(tumblers)
  121. 			if(gears)
  122. 			    You_hear("%d tumbler%s click and %d gear%s turn.",
  123. 				tumblers, plur(tumblers), gears, plur(gears));
  124. 			else
  125. 			    You_hear("%d tumbler%s click.",
  126. 				tumblers, plur(tumblers));
  127. 		    else if(gears) {
  128. 			You_hear("%d gear%s turn.", gears, plur(gears));
  129. 			/* could only get `gears == 5' by playing five
  130. 			   correct notes followed by excess; otherwise,
  131. 			   tune would have matched above */
  132. 			if (gears == 5) u.uevent.uheard_tune = 2;
  133. 		    }
  134. 		}
  135. 	    }
  136. 	  }
  137. 	return 1;
  138. } else
  139. 	    return do_improvisation(instr);
  140. }
  141.  
  142. #ifdef UNIX386MUSIC

atconsole[edit]

  1. /*
  2. * Play audible music on the machine's speaker if appropriate.
  3. */
  4.  
  5. STATIC_OVL int
  6. atconsole()
  7. {
  8. /*
  9. * Kluge alert: This code assumes that your [34]86 has no X terminals
  10. * attached and that the console tty type is AT386 (this is always true
  11. * under AT&T UNIX for these boxen). The theory here is that your remote
  12. * ttys will have terminal type `ansi' or something else other than
  13. * `AT386' or `xterm'. We'd like to do better than this, but testing
  14. * to see if we're running on the console physical terminal is quite
  15. * difficult given the presence of virtual consoles and other modern
  16. * UNIX impedimenta...
  17. */
  18. char	*termtype = nh_getenv("TERM");
  19.  
  20. return(!strcmp(termtype, "AT386") || !strcmp(termtype, "xterm"));
  21. }

speaker[edit]

  1. STATIC_OVL void
  2. speaker(instr, buf)
  3. struct obj *instr;
  4. char	*buf;
  5. {
  6. /*
  7. * For this to work, you need to have installed the PD speaker-control
  8. * driver for PC-compatible UNIX boxes that I (esr@snark.thyrsus.com)
  9. * posted to comp.sources.unix in Feb 1990.  A copy should be included
  10. * with your nethack distribution.
  11. */
  12. int	fd;
  13.  
  14. if ((fd = open("/dev/speaker", 1)) != -1)
  15. {
  16. 	/* send a prefix to modify instrumental `timbre' */
  17. 	switch (instr->otyp)
  18. 	{
  19. 	case WOODEN_FLUTE:
  20. 	case MAGIC_FLUTE:
  21. 	    (void) write(fd, ">ol", 1); /* up one octave & lock */
  22. 	    break;
  23. 	case TOOLED_HORN:
  24. 	case FROST_HORN:
  25. 	case FIRE_HORN:
  26. 	    (void) write(fd, "<<ol", 2); /* drop two octaves & lock */
  27. 	    break;
  28. 	case BUGLE:
  29. 	    (void) write(fd, "ol", 2); /* octave lock */
  30. 	    break;
  31. 	case WOODEN_HARP:
  32. 	case MAGIC_HARP:
  33. 	    (void) write(fd, "l8mlol", 4); /* fast, legato, octave lock */
  34. 	    break;
  35. 	}
  36. 	(void) write(fd, buf, strlen(buf));
  37. 	(void) close(fd);
  38. }
  39. }
  40. #endif /* UNIX386MUSIC */
  41.  
  42. #ifdef VPIX_MUSIC
  43.  
  44. # if 0
  45. #include <sys/types.h>
  46. #include <sys/console.h>
  47. #include <sys/vtkd.h>
  48. # else
  49. #define KIOC ('K' << 8)
  50. #define KDMKTONE (KIOC | 8)
  51. # endif
  52.  
  53. #define noDEBUG
  54.  
  55. STATIC_OVL void tone(hz, ticks)
  56. /* emit tone of frequency hz for given number of ticks */
  57. unsigned int hz, ticks;
  58. {
  59. ioctl(0,KDMKTONE,hz|((ticks*10)<<16));
  60. # ifdef DEBUG
  61. printf("TONE: %6d %6d\n",hz,ticks * 10);
  62. # endif
  63. nap(ticks * 10);
  64. }
  65.  
  66. STATIC_OVL void rest(ticks)
  67. /* rest for given number of ticks */
  68. int	ticks;
  69. {
  70. nap(ticks * 10);
  71. # ifdef DEBUG
  72. printf("REST:        %6d\n",ticks * 10);
  73. # endif
  74. }
  75.  
  76.  
  77. #include "interp.c"	/* from snd86unx.shr */
  78.  
  79.  
  80. STATIC_OVL void
  81. speaker(instr, buf)
  82. struct obj *instr;
  83. char	*buf;
  84. {
  85. /* emit a prefix to modify instrumental `timbre' */
  86. playinit();
  87. switch (instr->otyp)
  88. {
  89. 	case WOODEN_FLUTE:
  90. 	case MAGIC_FLUTE:
  91. 	    playstring(">ol", 1); /* up one octave & lock */
  92. 	    break;
  93. 	case TOOLED_HORN:
  94. 	case FROST_HORN:
  95. 	case FIRE_HORN:
  96. 	    playstring("<<ol", 2); /* drop two octaves & lock */
  97. 	    break;
  98. 	case BUGLE:
  99. 	    playstring("ol", 2); /* octave lock */
  100. 	    break;
  101. 	case WOODEN_HARP:
  102. 	case MAGIC_HARP:
  103. 	    playstring("l8mlol", 4); /* fast, legato, octave lock */
  104. 	    break;
  105. }
  106. playstring( buf, strlen(buf));
  107. }
  108.  
  109. # ifdef DEBUG
  110. main(argc,argv)
  111. char *argv[];
  112. {
  113. if (argc == 2) {
  114. 	playinit();
  115. 	playstring(argv[1], strlen(argv[1]));
  116. }
  117. }
  118. # endif
  119. #endif	/* VPIX_MUSIC */
  120.  
  121. /*music.c*/