Source:NetHack 3.4.3/src/minion.c

From NetHackWiki
Jump to: navigation, search

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

Top of file[edit]

  1. /*	SCCS Id: @(#)minion.c	3.4	2003/01/09	*/
  2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  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 "emin.h"
  3. #include "epri.h"

msummon[edit]

  1. void
  2. msummon(mon)		/* mon summons a monster */
  3. struct monst *mon;
  4. {
  5. 	register struct permonst *ptr;
  6. 	register int dtype = NON_PM, cnt = 0;
  7. 	aligntyp atyp;
  8. 	struct monst *mtmp;
  9.  
  10. 	if (mon) {
  11. 	    ptr = mon->data;
  12. 	    atyp = (ptr->maligntyp==A_NONE) ? A_NONE : sgn(ptr->maligntyp);
  13. 	    if (mon->ispriest || mon->data == &mons[PM_ALIGNED_PRIEST]
  14. 		|| mon->data == &mons[PM_ANGEL])
  15. 		atyp = EPRI(mon)->shralign;
  16. 	} else {
  17. 	    ptr = &mons[PM_WIZARD_OF_YENDOR];
  18. 	    atyp = (ptr->maligntyp==A_NONE) ? A_NONE : sgn(ptr->maligntyp);
  19. 	}
  20.  
  21. 	if (is_dprince(ptr) || (ptr == &mons[PM_WIZARD_OF_YENDOR])) {
  22. 	    dtype = (!rn2(20)) ? dprince(atyp) :
  23. 				 (!rn2(4)) ? dlord(atyp) : ndemon(atyp);
  24. 	    cnt = (!rn2(4) && is_ndemon(&mons[dtype])) ? 2 : 1;
  25. 	} else if (is_dlord(ptr)) {
  26. 	    dtype = (!rn2(50)) ? dprince(atyp) :
  27. 				 (!rn2(20)) ? dlord(atyp) : ndemon(atyp);
  28. 	    cnt = (!rn2(4) && is_ndemon(&mons[dtype])) ? 2 : 1;
  29. 	} else if (is_ndemon(ptr)) {
  30. 	    dtype = (!rn2(20)) ? dlord(atyp) :
  31. 				 (!rn2(6)) ? ndemon(atyp) : monsndx(ptr);
  32. 	    cnt = 1;
  33. 	} else if (is_lminion(mon)) {
  34. 	    dtype = (is_lord(ptr) && !rn2(20)) ? llord() :
  35. 		     (is_lord(ptr) || !rn2(6)) ? lminion() : monsndx(ptr);
  36. 	    cnt = (!rn2(4) && !is_lord(&mons[dtype])) ? 2 : 1;
  37. 	} else if (ptr == &mons[PM_ANGEL]) {
  38. 	    /* non-lawful angels can also summon */
  39. 	    if (!rn2(6)) {
  40. 		switch (atyp) { /* see summon_minion */
  41. 		case A_NEUTRAL:
  42. 		    dtype = PM_AIR_ELEMENTAL + rn2(4);
  43. 		    break;
  44. 		case A_CHAOTIC:
  45. 		case A_NONE:
  46. 		    dtype = ndemon(atyp);
  47. 		    break;
  48. 		}
  49. 	    } else {
  50. 		dtype = PM_ANGEL;
  51. 	    }
  52. 	    cnt = (!rn2(4) && !is_lord(&mons[dtype])) ? 2 : 1;
  53. 	}
  54.  
  55. 	if (dtype == NON_PM) return;
  56.  
  57. 	/* sanity checks */
  58. 	if (cnt > 1 && (mons[dtype].geno & G_UNIQ)) cnt = 1;
  59. 	/*
  60. 	 * If this daemon is unique and being re-summoned (the only way we
  61. 	 * could get this far with an extinct dtype), try another.
  62. 	 */
  63. 	if (mvitals[dtype].mvflags & G_GONE) {
  64. 	    dtype = ndemon(atyp);
  65. 	    if (dtype == NON_PM) return;
  66. 	}
  67.  
  68. 	while (cnt > 0) {
  69. 	    mtmp = makemon(&mons[dtype], u.ux, u.uy, NO_MM_FLAGS);
  70. 	    if (mtmp && (dtype == PM_ANGEL)) {
  71. 		/* alignment should match the summoner */
  72. 		EPRI(mtmp)->shralign = atyp;
  73. 	    }
  74. 	    cnt--;
  75. 	}
  76. }

summon_minion[edit]

  1. void
  2. summon_minion(alignment, talk)
  3. aligntyp alignment;
  4. boolean talk;
  5. {
  6. register struct monst *mon;
  7. int mnum;
  8.  
  9. switch ((int)alignment) {
  10. 	case A_LAWFUL:
  11. 	    mnum = lminion();
  12. 	    break;
  13. 	case A_NEUTRAL:
  14. 	    mnum = PM_AIR_ELEMENTAL + rn2(4);
  15. 	    break;
  16. 	case A_CHAOTIC:
  17. 	case A_NONE:
  18. 	    mnum = ndemon(alignment);
  19. 	    break;
  20. 	default:
  21. 	    impossible("unaligned player?");
  22. 	    mnum = ndemon(A_NONE);
  23. 	    break;
  24. }
  25. if (mnum == NON_PM) {
  26. 	mon = 0;
  27. } else if (mons[mnum].pxlth == 0) {
  28. 	struct permonst *pm = &mons[mnum];
  29. 	mon = makemon(pm, u.ux, u.uy, MM_EMIN);
  30. 	if (mon) {
  31. 	    mon->isminion = TRUE;
  32. 	    EMIN(mon)->min_align = alignment;
  33. 	}
  34. } else if (mnum == PM_ANGEL) {
  35. 	mon = makemon(&mons[mnum], u.ux, u.uy, NO_MM_FLAGS);
  36. 	if (mon) {
  37. 	    mon->isminion = TRUE;
  38. 	    EPRI(mon)->shralign = alignment;	/* always A_LAWFUL here */
  39. 	}
  40. } else
  41. 	mon = makemon(&mons[mnum], u.ux, u.uy, NO_MM_FLAGS);
  42. if (mon) {
  43. 	if (talk) {
  44. 	    pline_The("voice of %s booms:", align_gname(alignment));
  45. 	    verbalize("Thou shalt pay for thy indiscretion!");
  46. 	    if (!Blind)
  47. 		pline("%s appears before you.", Amonnam(mon));
  48. 	}
  49. 	mon->mpeaceful = FALSE;
  50. 	/* don't call set_malign(); player was naughty */
  51. }
  52. }

demon_talk[edit]

  1. #define Athome	(Inhell && !mtmp->cham)
  2.  
  3. int
  4. demon_talk(mtmp)		/* returns 1 if it won't attack. */
  5. register struct monst *mtmp;
  6. {
  7. 	long cash, demand, offer;
  8.  
  9. 	if (uwep && uwep->oartifact == ART_EXCALIBUR) {
  10. 	    pline("%s looks very angry.", Amonnam(mtmp));
  11. 	    mtmp->mpeaceful = mtmp->mtame = 0;
  12. 	    set_malign(mtmp);
  13. 	    newsym(mtmp->mx, mtmp->my);
  14. 	    return 0;
  15. 	}
  16.  
  17. 	/* Slight advantage given. */
  18. 	if (is_dprince(mtmp->data) && mtmp->minvis) {
  19. 	    mtmp->minvis = mtmp->perminvis = 0;
  20. 	    if (!Blind) pline("%s appears before you.", Amonnam(mtmp));
  21. 	    newsym(mtmp->mx,mtmp->my);
  22. 	}
  23. 	if (youmonst.data->mlet == S_DEMON) {	/* Won't blackmail their own. */
  24. 	    pline("%s says, \"Good hunting, %s.\"",
  25. 		  Amonnam(mtmp), flags.female ? "Sister" : "Brother");
  26. 	    if (!tele_restrict(mtmp)) (void) rloc(mtmp, FALSE);
  27. 	    return(1);
  28. 	}
  29. #ifndef GOLDOBJ
  30. 	cash = u.ugold;
  31. #else
  32. 	cash = money_cnt(invent);
  33. #endif
  34. 	demand = (cash * (rnd(80) + 20 * Athome)) /
  35. 	    (100 * (1 + (sgn(u.ualign.type) == sgn(mtmp->data->maligntyp))));
  36.  
  37. 	if (!demand) {		/* you have no gold */
  38. 	    mtmp->mpeaceful = 0;
  39. 	    set_malign(mtmp);
  40. 	    return 0;
  41. 	} else {
  42. 	    /* make sure that the demand is unmeetable if the monster
  43. 	       has the Amulet, preventing monster from being satisified
  44. 	       and removed from the game (along with said Amulet...) */
  45. 	    if (mon_has_amulet(mtmp))
  46. 		demand = cash + (long)rn1(1000,40);
  47.  
  48. 	    pline("%s demands %ld %s for safe passage.",
  49. 		  Amonnam(mtmp), demand, currency(demand));
  50.  
  51. 	    if ((offer = bribe(mtmp)) >= demand) {
  52. 		pline("%s vanishes, laughing about cowardly mortals.",
  53. 		      Amonnam(mtmp));
  54. 	    } else if (offer > 0L && (long)rnd(40) > (demand - offer)) {
  55. 		pline("%s scowls at you menacingly, then vanishes.",
  56. 		      Amonnam(mtmp));
  57. 	    } else {
  58. 		pline("%s gets angry...", Amonnam(mtmp));
  59. 		mtmp->mpeaceful = 0;
  60. 		set_malign(mtmp);
  61. 		return 0;
  62. 	    }
  63. 	}
  64. 	mongone(mtmp);
  65. 	return(1);
  66. }

bribe[edit]

  1. long
  2. bribe(mtmp)
  3. struct monst *mtmp;
  4. {
  5. 	char buf[BUFSZ];
  6. 	long offer;
  7. #ifdef GOLDOBJ
  8. 	long umoney = money_cnt(invent);
  9. #endif
  10.  
  11. 	getlin("How much will you offer?", buf);
  12. 	if (sscanf(buf, "%ld", &offer) != 1) offer = 0L;
  13.  
  14. 	/*Michael Paddon -- fix for negative offer to monster*/
  15. 	/*JAR880815 - */
  16. 	if (offer < 0L) {
  17. 		You("try to shortchange %s, but fumble.",
  18. 			mon_nam(mtmp));
  19. 		return 0L;
  20. 	} else if (offer == 0L) {
  21. 		You("refuse.");
  22. 		return 0L;
  23. #ifndef GOLDOBJ
  24. 	} else if (offer >= u.ugold) {
  25. 		You("give %s all your gold.", mon_nam(mtmp));
  26. 		offer = u.ugold;
  27. 	} else {
  28. 		You("give %s %ld %s.", mon_nam(mtmp), offer, currency(offer));
  29. 	}
  30. 	u.ugold -= offer;
  31. 	mtmp->mgold += offer;
  32. #else
  33. 	} else if (offer >= umoney) {
  34. 		You("give %s all your gold.", mon_nam(mtmp));
  35. 		offer = umoney;
  36. 	} else {
  37. 		You("give %s %ld %s.", mon_nam(mtmp), offer, currency(offer));
  38. 	}
  39. 	(void) money2mon(mtmp, offer);
  40. #endif
  41. 	flags.botl = 1;
  42. 	return(offer);
  43. }

dprince[edit]

  1. int
  2. dprince(atyp)
  3. aligntyp atyp;
  4. {
  5. 	int tryct, pm;
  6.  
  7. 	for (tryct = 0; tryct < 20; tryct++) {
  8. 	    pm = rn1(PM_DEMOGORGON + 1 - PM_ORCUS, PM_ORCUS);
  9. 	    if (!(mvitals[pm].mvflags & G_GONE) &&
  10. 		    (atyp == A_NONE || sgn(mons[pm].maligntyp) == sgn(atyp)))
  11. 		return(pm);
  12. 	}
  13. 	return(dlord(atyp));	/* approximate */
  14. }

dlord[edit]

  1. int
  2. dlord(atyp)
  3. aligntyp atyp;
  4. {
  5. 	int tryct, pm;
  6.  
  7. 	for (tryct = 0; tryct < 20; tryct++) {
  8. 	    pm = rn1(PM_YEENOGHU + 1 - PM_JUIBLEX, PM_JUIBLEX);
  9. 	    if (!(mvitals[pm].mvflags & G_GONE) &&
  10. 		    (atyp == A_NONE || sgn(mons[pm].maligntyp) == sgn(atyp)))
  11. 		return(pm);
  12. 	}
  13. 	return(ndemon(atyp));	/* approximate */
  14. }

llord[edit]

  1. /* create lawful (good) lord */
  2. int
  3. llord()
  4. {
  5. 	if (!(mvitals[PM_ARCHON].mvflags & G_GONE))
  6. 		return(PM_ARCHON);
  7.  
  8. 	return(lminion());	/* approximate */
  9. }

lminion[edit]

  1. int
  2. lminion()
  3. {
  4. 	int	tryct;
  5. 	struct	permonst *ptr;
  6.  
  7. 	for (tryct = 0; tryct < 20; tryct++) {
  8. 	    ptr = mkclass(S_ANGEL,0);
  9. 	    if (ptr && !is_lord(ptr))
  10. 		return(monsndx(ptr));
  11. 	}
  12.  
  13. 	return NON_PM;
  14. }

ndemon[edit]

  1. int
  2. ndemon(atyp)
  3. aligntyp atyp;
  4. {
  5. 	int	tryct;
  6. 	struct	permonst *ptr;
  7.  
  8. 	for (tryct = 0; tryct < 20; tryct++) {
  9. 	    ptr = mkclass(S_DEMON, 0);
  10. 	    if (ptr && is_ndemon(ptr) &&
  11. 		    (atyp == A_NONE || sgn(ptr->maligntyp) == sgn(atyp)))
  12. 		return(monsndx(ptr));
  13. 	}
  14.  
  15. 	return NON_PM;
  16. }
  17.  
  18. /*minion.c*/