Source:NetHack 3.1.0/minion.c

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

Warning! This is the source code from an old release. For the latest release, see Source code

1.   /*	SCCS Id: @(#)minion.c	3.1	92/11/01	*/ 2.   /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3.    /* NetHack may be freely redistributed. See license for details. */ 4.     5.    #include "hack.h"  6.    #include "emin.h"  7.    #include "epri.h"  8. 9.   void 10.  msummon(ptr)		/* ptr summons a monster */ 11.  	register struct permonst *ptr; 12.  {  13.   	register int dtype = 0, cnt = 0; 14.   15.   	if(is_dprince(ptr) || (ptr == &mons[PM_WIZARD_OF_YENDOR])) { 16.   17.   	    dtype = (!rn2(20)) ? dprince : (!rn2(4)) ? dlord : ndemon; 18.  	    cnt = (!rn2(4) && !is_dprince(&mons[dtype])) ? 2 : 1; 19.    20.   	} else if(is_dlord(ptr)) { 21.   22.   	    dtype = (!rn2(50)) ? dprince : (!rn2(20)) ? dlord : ndemon; 23.  	    cnt = (!rn2(4) && is_ndemon(&mons[dtype])) ? 2 : 1; 24.    25.   	} else if(is_ndemon(ptr)) { 26.   27.   	    dtype = (!rn2(20)) ? dlord : (!rn2(6)) ? ndemon : monsndx(ptr); 28.  	    cnt = 1; 29.  	} else if(is_lminion(ptr)) { 30.   31.   	    dtype = (is_lord(ptr) && !rn2(20)) ? llord : 32.  		     (is_lord(ptr) || !rn2(6)) ? lminion : monsndx(ptr); 33.  	    cnt = (!rn2(4) && !is_lord(&mons[dtype])) ? 2 : 1; 34.    35.   	}  36.    37.   	if(!dtype) return; 38.   39.   	while(cnt > 0) { 40.   41.   	    (void)makemon(&mons[dtype], u.ux, u.uy); 42.  	    cnt--; 43.  	}  44.   	return; 45.  }  46.    47.   void 48.  summon_minion(alignment, talk) 49.      aligntyp alignment; 50.      boolean talk; 51.  {  52.       register struct monst *mon; 53.      int mnum; 54.   55.       switch(alignment) { 56.      case A_LAWFUL: { 57.  	mnum = lminion; 58.  	break; 59.      }  60.       case A_NEUTRAL: { 61.  	mnum = PM_AIR_ELEMENTAL + rn2(4); 62.  	break; 63.      }  64.       case A_CHAOTIC: 65.  	mnum = ndemon; 66.  	break; 67.      default: 68.  	impossible("unaligned player?"); 69.  	mnum = ndemon; 70.  	break; 71.      }  72.       if(mons[mnum].pxlth == 0) { 73.  	struct permonst *pm = &mons[mnum]; 74.  	pm->pxlth = sizeof(struct emin); 75.  	mon = makemon(pm, u.ux, u.uy); 76.  	pm->pxlth = 0; 77.  	if(mon) { 78.  	    mon->isminion = TRUE; 79.  	    EMIN(mon)->min_align = alignment; 80.  	}  81.       } else if (mnum == PM_ANGEL) { 82.  	mon = makemon(&mons[mnum], u.ux, u.uy); 83.  	if (mon) { 84.  	    mon->isminion = TRUE; 85.  	    EPRI(mon)->shralign = alignment;	/* always A_LAWFUL here */ 86.  	}  87.       } else 88.  	mon = makemon(&mons[mnum], u.ux, u.uy); 89.      if(mon) { 90.  	if(talk) { 91.  	    pline("The voice of %s booms:", align_gname(alignment)); 92.  	    verbalize("Thou shalt pay for thy indiscretion!"); 93.  	    if(!Blind) 94.  		pline("%s appears before you.", Amonnam(mon)); 95.  	}  96.   	mon->mpeaceful = FALSE; 97.  	/* don't call set_malign; player was naughty */ 98.      }  99.   }  100.   101.  #define	Athome	(Inhell && !mtmp->cham) 102.  103.  int 104. demon_talk(mtmp)		/* returns 1 if it won't attack. */ 105.  register struct monst *mtmp; 106. {  107.  	long	demand, offer; 108.  109.  	if(uwep && uwep->oartifact == ART_EXCALIBUR) { 110. 	    pline("%s looks very angry.", Amonnam(mtmp)); 111. 	    mtmp->mpeaceful = mtmp->mtame = 0; 112. 	    newsym(mtmp->mx, mtmp->my); 113. 	    return 0; 114. 	}  115.   116.  	/* Slight advantage given. */ 117.  	if(is_dprince(mtmp->data) && mtmp->minvis) { 118. 	    mtmp->minvis = 0; 119. 	    if (!Blind) pline("%s appears before you.", Amonnam(mtmp)); 120. 	    newsym(mtmp->mx,mtmp->my); 121. 	}  122.  	if(u.usym == S_DEMON) {	/* Won't blackmail their own. */ 123.   124.  	    pline("%s says, \"Good hunting, %s.\" and vanishes.",  125.  		  Amonnam(mtmp), flags.female ? "Sister" : "Brother"); 126. 	    rloc(mtmp); 127. 	    return(1); 128. 	}  129.  	demand = (u.ugold * (rnd(80) + 20 * Athome)) / 100; 130. 	if(!demand)  		/* you have no gold */ 131. 	    return mtmp->mpeaceful = 0; 132. 	else { 133.  134.  	    pline("%s demands %ld zorkmid%s for safe passage.",  135.  		  Amonnam(mtmp), demand, plur(demand)); 136.  137.  	    if((offer = bribe(mtmp)) >= demand) { 138. 		pline("%s vanishes, laughing about cowardly mortals.",  139.  		      Amonnam(mtmp)); 140. 	    } else { 141. 		if((long)rnd(40) > (demand - offer)) { 142. 		    pline("%s scowls at you menacingly, then vanishes.",  143.  			  Amonnam(mtmp)); 144. 		} else { 145. 		    pline("%s gets angry...", Amonnam(mtmp)); 146. 		    return mtmp->mpeaceful = 0; 147. 		}  148.  	    }  149.  	}  150.  	mongone(mtmp); 151. 	return(1); 152. }  153.   154.  long 155. bribe(mtmp) 156. struct monst *mtmp; 157. {  158.  	char buf[80]; 159. 	long offer; 160.  161.  	getlin("How much will you offer?", buf); 162. 	(void) sscanf(buf, "%ld", &offer); 163.  164.  /*Michael Paddon -- fix for negative offer to monster*/	/*JAR880815 - */ 165.  	if(offer < 0L) { 166.  		You("try to shortchange %s, but fumble.",  167.   			mon_nam(mtmp)); 168.  		offer = 0L; 169.  	} else if(offer == 0L) { 170. 		You("refuse."); 171.  	} else if(offer >= u.ugold) { 172. 		You("give %s all your gold.", mon_nam(mtmp)); 173. 		offer = u.ugold; 174. 	} else You("give %s %ld zorkmid%s.", mon_nam(mtmp), offer,  175.  		   plur(offer)); 176.  177.  	u.ugold -= offer; 178. 	mtmp->mgold += offer; 179. 	flags.botl = 1; 180. 	return(offer); 181. }  182.   183.  int 184. dprince { 185. 	int	tryct, pm; 186.  187.  	for(tryct = 0; tryct < 20; tryct++) { 188. 	    pm = rn1(PM_DEMOGORGON + 1 - PM_ORCUS, PM_ORCUS); 189. 	    if(!(mons[pm].geno & (G_GENOD | G_EXTINCT))) 190. 		return(pm); 191. 	}  192.  	return(dlord);	/* approximate */ 193. }  194.   195.  int 196. dlord 197. {  198.  	int	tryct, pm; 199.  200.  	for(tryct = 0; tryct < 20; tryct++) { 201. 	    pm = rn1(PM_YEENOGHU + 1 - PM_JUIBLEX, PM_JUIBLEX); 202. 	    if(!(mons[pm].geno & (G_GENOD | G_EXTINCT))) 203. 		return(pm); 204. 	}  205.  	return(ndemon);	/* approximate */ 206. }  207.   208.  /* create lawful (good) lord */ 209. int 210. llord 211. {  212.  	if(!(mons[PM_ARCHON].geno & (G_GENOD | G_EXTINCT))) 213. 		return(PM_ARCHON); 214.  215.  	return(lminion);	/* approximate */ 216. }  217.   218.  int 219. lminion 220. {  221.  	int	tryct; 222. 	struct	permonst *ptr; 223.  224.  	for(tryct = 0; tryct < 20; tryct++) 225. 	    if((ptr = mkclass(S_ANGEL,0)) && !is_lord(ptr)) 226. 		return(monsndx(ptr)); 227.  228.  	return(0); 229. }  230.   231.  int 232. ndemon 233. {  234.  	int	tryct; 235. 	struct	permonst *ptr; 236.  237.  	for (tryct = 0; tryct < 20; tryct++) { 238. 	    ptr = mkclass(S_DEMON, 0); 239. 	    if (is_ndemon(ptr)) 240. 		return(monsndx(ptr)); 241. 	}  242.   243.  	return(0); 244. }  245.   246.  /*minion.c*/