Source:NetHack 3.4.3/src/mplayer.c

From NetHackWiki
Jump to: navigation, search

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

Top of file[edit]

  1. /*	SCCS Id: @(#)mplayer.c	3.4	1997/02/04	*/
  2. /*	Copyright (c) Izchak Miller, 1992.			  */
  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.  
  3. STATIC_DCL const char *NDECL(dev_name);
  4. STATIC_DCL void FDECL(get_mplname, (struct monst *, char *));
  5. STATIC_DCL void FDECL(mk_mplayer_armor, (struct monst *, SHORT_P));

developers[edit]

  1. /* These are the names of those who
  2. * contributed to the development of NetHack 3.2/3.3/3.4.
  3. *
  4. * Keep in alphabetical order within teams.
  5. * Same first name is entered once within each team.
  6. */
  7. static const char *developers[] = {
  8. 	/* devteam */
  9. 	"Dave", "Dean", "Eric", "Izchak", "Janet", "Jessie",
  10. 	"Ken", "Kevin", "Michael", "Mike", "Pat", "Paul", "Steve", "Timo",
  11. 	"Warwick",
  12. 	/* PC team */
  13. 	"Bill", "Eric", "Keizo", "Ken", "Kevin", "Michael", "Mike", "Paul",
  14. 	"Stephen", "Steve", "Timo", "Yitzhak",
  15. 	/* Amiga team */
  16. 	"Andy", "Gregg", "Janne", "Keni", "Mike", "Olaf", "Richard",
  17. 	/* Mac team */
  18. 	"Andy", "Chris", "Dean", "Jon", "Jonathan", "Kevin", "Wang",
  19. 	/* Atari team */
  20. 	"Eric", "Marvin", "Warwick",
  21. 	/* NT team */
  22. 	"Alex", "Dion", "Michael",
  23. 	/* OS/2 team */
  24. 	"Helge", "Ron", "Timo",
  25. 	/* VMS team */
  26. 	"Joshua", "Pat",
  27. 	""};

dev_name[edit]

  1. /* return a randomly chosen developer name */
  2. STATIC_OVL const char *
  3. dev_name()
  4. {
  5. 	register int i, m = 0, n = SIZE(developers);
  6. 	register struct monst *mtmp;
  7. 	register boolean match;
  8.  
  9. 	do {
  10. 	    match = FALSE;
  11. 	    i = rn2(n);
  12. 	    for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
  13. 		if(!is_mplayer(mtmp->data)) continue;
  14. 		if(!strncmp(developers[i], NAME(mtmp),
  15. 			               strlen(developers[i]))) {
  16. 		    match = TRUE;
  17. 		    break;
  18. 	        }
  19. 	    }
  20. 	    m++;
  21. 	} while (match && m < 100); /* m for insurance */
  22.  
  23. 	if (match) return (const char *)0;
  24. 	return(developers[i]);
  25. }

get_mplname[edit]

  1. STATIC_OVL void
  2. get_mplname(mtmp, nam)
  3. register struct monst *mtmp;
  4. char *nam;
  5. {
  6. 	boolean fmlkind = is_female(mtmp->data);
  7. 	const char *devnam;
  8.  
  9. 	devnam = dev_name();
  10. 	if (!devnam)
  11. 	    Strcpy(nam, fmlkind ? "Eve" : "Adam");
  12. 	else if (fmlkind && !!strcmp(devnam, "Janet"))
  13. 	    Strcpy(nam, rn2(2) ? "Maud" : "Eve");
  14. 	else Strcpy(nam, devnam);
  15.  
  16. 	if (fmlkind || !strcmp(nam, "Janet"))
  17. 	    mtmp->female = 1;
  18. 	else
  19. 	    mtmp->female = 0;
  20. 	Strcat(nam, " the ");
  21. 	Strcat(nam, rank_of((int)mtmp->m_lev,
  22. 			    monsndx(mtmp->data),
  23. 			    (boolean)mtmp->female));
  24. }

mk_mplayer_armor[edit]

  1. STATIC_OVL void
  2. mk_mplayer_armor(mon, typ)
  3. struct monst *mon;
  4. short typ;
  5. {
  6. 	struct obj *obj;
  7.  
  8. 	if (typ == STRANGE_OBJECT) return;
  9. 	obj = mksobj(typ, FALSE, FALSE);
  10. 	if (!rn2(3)) obj->oerodeproof = 1;
  11. 	if (!rn2(3)) curse(obj);
  12. 	if (!rn2(3)) bless(obj);
  13. 	/* Most players who get to the endgame who have cursed equipment
  14. 	 * have it because the wizard or other monsters cursed it, so its
  15. 	 * chances of having plusses is the same as usual....
  16. 	 */
  17. 	obj->spe = rn2(10) ? (rn2(3) ? rn2(5) : rn1(4,4)) : -rnd(3);
  18. 	(void) mpickobj(mon, obj);
  19. }

mk_mplayer[edit]

  1. struct monst *
  2. mk_mplayer(ptr, x, y, special)
  3. register struct permonst *ptr;
  4. xchar x, y;
  5. register boolean special;
  6. {
  7. 	register struct monst *mtmp;
  8. 	char nam[PL_NSIZ];
  9.  
  10. 	if(!is_mplayer(ptr))
  11. 		return((struct monst *)0);
  12.  
  13. 	if(MON_AT(x, y))
  14. 		(void) rloc(m_at(x, y), FALSE); /* insurance */
  15.  
  16. 	if(!In_endgame(&u.uz)) special = FALSE;
  17.  
  18. 	if ((mtmp = makemon(ptr, x, y, NO_MM_FLAGS)) != 0) {
  19. 	    short weapon = rn2(2) ? LONG_SWORD : rnd_class(SPEAR, BULLWHIP);
  20. 	    short armor = rnd_class(GRAY_DRAGON_SCALE_MAIL, YELLOW_DRAGON_SCALE_MAIL);
  21. 	    short cloak = !rn2(8) ? STRANGE_OBJECT :
  22. 	    		rnd_class(OILSKIN_CLOAK, CLOAK_OF_DISPLACEMENT);
  23. 	    short helm = !rn2(8) ? STRANGE_OBJECT :
  24. 	    		rnd_class(ELVEN_LEATHER_HELM, HELM_OF_TELEPATHY);
  25. 	    short shield = !rn2(8) ? STRANGE_OBJECT :
  26. 	    		rnd_class(ELVEN_SHIELD, SHIELD_OF_REFLECTION);
  27. 	    int quan;
  28. 	    struct obj *otmp;
  29.  
  30. 	    mtmp->m_lev = (special ? rn1(16,15) : rnd(16));
  31. 	    mtmp->mhp = mtmp->mhpmax = d((int)mtmp->m_lev,10) +
  32. 					(special ? (30 + rnd(30)) : 30);
  33. 	    if(special) {
  34. 	        get_mplname(mtmp, nam);
  35. 	        mtmp = christen_monst(mtmp, nam);
  36. 		/* that's why they are "stuck" in the endgame :-) */
  37. 		(void)mongets(mtmp, FAKE_AMULET_OF_YENDOR);
  38. 	    }
  39. 	    mtmp->mpeaceful = 0;
  40. 	    set_malign(mtmp); /* peaceful may have changed again */
  41.  
  42. 	    switch(monsndx(ptr)) {
  43. 		case PM_ARCHEOLOGIST:
  44. 		    if (rn2(2)) weapon = BULLWHIP;
  45. 		    break;
  46. 		case PM_BARBARIAN:
  47. 		    if (rn2(2)) {
  48. 		    	weapon = rn2(2) ? TWO_HANDED_SWORD : BATTLE_AXE;
  49. 		    	shield = STRANGE_OBJECT;
  50. 		    }
  51. 		    if (rn2(2)) armor = rnd_class(PLATE_MAIL, CHAIN_MAIL);
  52. 		    if (helm == HELM_OF_BRILLIANCE) helm = STRANGE_OBJECT;
  53. 		    break;
  54. 		case PM_CAVEMAN:
  55. 		case PM_CAVEWOMAN:
  56. 		    if (rn2(4)) weapon = MACE;
  57. 		    else if (rn2(2)) weapon = CLUB;
  58. 		    if (helm == HELM_OF_BRILLIANCE) helm = STRANGE_OBJECT;
  59. 		    break;
  60. 		case PM_HEALER:
  61. 		    if (rn2(4)) weapon = QUARTERSTAFF;
  62. 		    else if (rn2(2)) weapon = rn2(2) ? UNICORN_HORN : SCALPEL;
  63. 		    if (rn2(4)) helm = rn2(2) ? HELM_OF_BRILLIANCE : HELM_OF_TELEPATHY;
  64. 		    if (rn2(2)) shield = STRANGE_OBJECT;
  65. 		    break;
  66. 		case PM_KNIGHT:
  67. 		    if (rn2(4)) weapon = LONG_SWORD;
  68. 		    if (rn2(2)) armor = rnd_class(PLATE_MAIL, CHAIN_MAIL);
  69. 		    break;
  70. 		case PM_MONK:
  71. 		    weapon = STRANGE_OBJECT;
  72. 		    armor = STRANGE_OBJECT;
  73. 		    cloak = ROBE;
  74. 		    if (rn2(2)) shield = STRANGE_OBJECT;
  75. 		    break;
  76. 		case PM_PRIEST:
  77. 		case PM_PRIESTESS:
  78. 		    if (rn2(2)) weapon = MACE;
  79. 		    if (rn2(2)) armor = rnd_class(PLATE_MAIL, CHAIN_MAIL);
  80. 		    if (rn2(4)) cloak = ROBE;
  81. 		    if (rn2(4)) helm = rn2(2) ? HELM_OF_BRILLIANCE : HELM_OF_TELEPATHY;
  82. 		    if (rn2(2)) shield = STRANGE_OBJECT;
  83. 		    break;
  84. 		case PM_RANGER:
  85. 		    if (rn2(2)) weapon = ELVEN_DAGGER;
  86. 		    break;
  87. 		case PM_ROGUE:
  88. 		    if (rn2(2)) weapon = SHORT_SWORD;
  89. 		    break;
  90. 		case PM_SAMURAI:
  91. 		    if (rn2(2)) weapon = KATANA;
  92. 		    break;
  93. #ifdef TOURIST
  94. 		case PM_TOURIST:
  95. 		    /* Defaults are just fine */
  96. 		    break;
  97. #endif
  98. 		case PM_VALKYRIE:
  99. 		    if (rn2(2)) weapon = WAR_HAMMER;
  100. 		    if (rn2(2)) armor = rnd_class(PLATE_MAIL, CHAIN_MAIL);
  101. 		    break;
  102. 		case PM_WIZARD:
  103. 		    if (rn2(4)) weapon = rn2(2) ? QUARTERSTAFF : ATHAME;
  104. 		    if (rn2(2)) {
  105. 		    	armor = rn2(2) ? BLACK_DRAGON_SCALE_MAIL :
  106. 		    			SILVER_DRAGON_SCALE_MAIL;
  107. 		    	cloak = CLOAK_OF_MAGIC_RESISTANCE;
  108. 		    }
  109. 		    if (rn2(4)) helm = HELM_OF_BRILLIANCE;
  110. 		    shield = STRANGE_OBJECT;
  111. 		    break;
  112. 		default: impossible("bad mplayer monster");
  113. 		    weapon = 0;
  114. 		    break;
  115. 	    }
  116.  
  117. 	    if (weapon != STRANGE_OBJECT) {
  118. 		otmp = mksobj(weapon, TRUE, FALSE);
  119. 		otmp->spe = (special ? rn1(5,4) : rn2(4));
  120. 		if (!rn2(3)) otmp->oerodeproof = 1;
  121. 		else if (!rn2(2)) otmp->greased = 1;
  122. 		if (special && rn2(2))
  123. 		    otmp = mk_artifact(otmp, A_NONE);
  124. 		/* mplayers knew better than to overenchant Magicbane */
  125. 		if (otmp->oartifact == ART_MAGICBANE)
  126. 		    otmp->spe = rnd(4);
  127. 		(void) mpickobj(mtmp, otmp);
  128. 	    }
  129.  
  130. 	    if(special) {
  131. 		if (!rn2(10))
  132. 		    (void) mongets(mtmp, rn2(3) ? LUCKSTONE : LOADSTONE);
  133. 		mk_mplayer_armor(mtmp, armor);
  134. 		mk_mplayer_armor(mtmp, cloak);
  135. 		mk_mplayer_armor(mtmp, helm);
  136. 		mk_mplayer_armor(mtmp, shield);
  137. 		if (rn2(8))
  138. 		    mk_mplayer_armor(mtmp, rnd_class(LEATHER_GLOVES,
  139. 					       GAUNTLETS_OF_DEXTERITY));
  140. 		if (rn2(8))
  141. 		    mk_mplayer_armor(mtmp, rnd_class(LOW_BOOTS, LEVITATION_BOOTS));
  142. 		m_dowear(mtmp, TRUE);
  143.  
  144. 		quan = rn2(3) ? rn2(3) : rn2(16);
  145. 		while(quan--)
  146. 		    (void)mongets(mtmp, rnd_class(DILITHIUM_CRYSTAL, JADE));
  147. 		/* To get the gold "right" would mean a player can double his */
  148. 		/* gold supply by killing one mplayer.  Not good. */
  149. #ifndef GOLDOBJ
  150. 		mtmp->mgold = rn2(1000);
  151. #else
  152. 		mkmonmoney(mtmp, rn2(1000));
  153. #endif
  154. 		quan = rn2(10);
  155. 		while(quan--)
  156. 		    (void) mpickobj(mtmp, mkobj(RANDOM_CLASS, FALSE));
  157. 	    }
  158. 	    quan = rnd(3);
  159. 	    while(quan--)
  160. 		(void)mongets(mtmp, rnd_offensive_item(mtmp));
  161. 	    quan = rnd(3);
  162. 	    while(quan--)
  163. 		(void)mongets(mtmp, rnd_defensive_item(mtmp));
  164. 	    quan = rnd(3);
  165. 	    while(quan--)
  166. 		(void)mongets(mtmp, rnd_misc_item(mtmp));
  167. 	}
  168.  
  169. 	return(mtmp);
  170. }

create_mplayers[edit]

  1. /* create the indicated number (num) of monster-players,
  2. * randomly chosen, and in randomly chosen (free) locations
  3. * on the level.  If "special", the size of num should not
  4. * be bigger than the number of _non-repeated_ names in the
  5. * developers array, otherwise a bunch of Adams and Eves will
  6. * fill up the overflow.
  7. */
  8. void
  9. create_mplayers(num, special)
  10. register int num;
  11. boolean special;
  12. {
  13. 	int pm, x, y;
  14. 	struct monst fakemon;
  15.  
  16. 	while(num) {
  17. 		int tryct = 0;
  18.  
  19. 		/* roll for character class */
  20. 		pm = PM_ARCHEOLOGIST + rn2(PM_WIZARD - PM_ARCHEOLOGIST + 1);
  21. 		fakemon.data = &mons[pm];
  22.  
  23. 		/* roll for an available location */
  24. 		do {
  25. 		    x = rn1(COLNO-4, 2);
  26. 		    y = rnd(ROWNO-2);
  27. 		} while(!goodpos(x, y, &fakemon, 0) && tryct++ <= 50);
  28.  
  29. 		/* if pos not found in 50 tries, don't bother to continue */
  30. 		if(tryct > 50) return;
  31.  
  32. 		(void) mk_mplayer(&mons[pm], (xchar)x, (xchar)y, special);
  33. 		num--;
  34. 	}
  35. }

mplayer_talk[edit]

  1. void
  2. mplayer_talk(mtmp)
  3. register struct monst *mtmp;
  4. {
  5. 	static const char *same_class_msg[3] = {
  6. 		"I can't win, and neither will you!",
  7. 		"You don't deserve to win!",
  8. 		"Mine should be the honor, not yours!",
  9. 	},		  *other_class_msg[3] = {
  10. 		"The low-life wants to talk, eh?",
  11. 		"Fight, scum!",
  12. 		"Here is what I have to say!",
  13. 	};
  14.  
  15. 	if(mtmp->mpeaceful) return; /* will drop to humanoid talk */
  16.  
  17. 	pline("Talk? -- %s",
  18. 		(mtmp->data == &mons[urole.malenum] ||
  19. 		mtmp->data == &mons[urole.femalenum]) ?
  20. 		same_class_msg[rn2(3)] : other_class_msg[rn2(3)]);
  21. }
  22.  
  23. /*mplayer.c*/