Source:NetHack 1.4f/steal.c

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

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

1.   /*	SCCS Id: @(#)steal.c	1.4	87/08/08 2.   /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3.    /* steal.c - version 1.0.3 */ 4.    5.    #include "hack.h"  6. 7.   long		/* actually returns something that fits in an int */ 8.   somegold{ 9.   	return( (u.ugold < 100) ? u.ugold :  10.   		(u.ugold > 10000) ? rnd(10000) : rnd((int) u.ugold) ); 11.  }  12.    13.   stealgold(mtmp)  register struct monst *mtmp; { 14.  register struct gold *gold = g_at(u.ux, u.uy); 15.  register long tmp; 16.  	if(gold && ( !u.ugold || gold->amount > u.ugold || !rn2(5))) { 17.  		mtmp->mgold += gold->amount; 18.  		freegold(gold); 19.  		if(Invisible) newsym(u.ux, u.uy); 20.  		pline("%s quickly snatches some gold from between your feet!",  21.   			Monnam(mtmp)); 22.  		if(!u.ugold || !rn2(5)) { 23.  			rloc(mtmp); 24.  			mtmp->mflee = 1; 25.  		}  26.   	} else if(u.ugold) { 27.  		u.ugold -= (tmp = somegold); 28.  		pline("Your purse feels lighter."); 29.  		mtmp->mgold += tmp; 30.  		rloc(mtmp); 31.  		mtmp->mflee = 1; 32.  		flags.botl = 1; 33.  	}  34.   }  35.    36.   /* steal armor after he finishes taking it off */ 37.  unsigned stealoid;		/* object to be stolen */ 38.  unsigned stealmid;		/* monster doing the stealing */ 39.  stealarm{ 40.  	register struct monst *mtmp; 41.  	register struct obj *otmp; 42.   43.   	for(otmp = invent; otmp; otmp = otmp->nobj) 44.  	  if(otmp->o_id == stealoid) { 45.  	    for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) 46.  	      if(mtmp->m_id == stealmid) { 47.  		if(dist(mtmp->mx,mtmp->my) < 3) { 48.  		  freeinv(otmp); 49.  		  pline("%s steals %s!", Monnam(mtmp), doname(otmp)); 50.  		  mpickobj(mtmp,otmp); 51.  		  mtmp->mflee = 1; 52.  		  rloc(mtmp); 53.  		}  54.   		break; 55.  	      }  56.   	    break; 57.  	  }  58.   	stealoid = 0; 59.  }  60.    61.   /* returns 1 when something was stolen */ 62.  /* (or at least, when N should flee now) */ 63.  /* avoid stealing the object stealoid */ 64.  steal(mtmp) 65.  struct monst *mtmp; 66.  {  67.   	register struct obj *otmp; 68.  	register tmp; 69.  	register named = 0; 70.   71.   	if(!invent){ 72.  	    if(Blind) 73.  	      pline("Somebody tries to rob you, but finds nothing to steal."); 74.  	    else 75.  	      pline("%s tries to rob you, but she finds nothing to steal!",  76.   		Monnam(mtmp)); 77.  	    return(1);	/* let her flee */ 78.  	}  79.   	tmp = 0; 80.  	for(otmp = invent; otmp; otmp = otmp->nobj) if(otmp != uarm2) 81.  		tmp += ((otmp->owornmask & (W_ARMOR | W_RING)) ? 5 : 1); 82.  	tmp = rn2(tmp); 83.  	for(otmp = invent; otmp; otmp = otmp->nobj) if(otmp != uarm2) 84.  		if((tmp -= ((otmp->owornmask & (W_ARMOR | W_RING)) ? 5 : 1))  85.   			< 0) break; 86.  	if(!otmp) { 87.  		impossible("Steal fails!"); 88.  		return(0); 89.  	}  90.   	if(otmp->o_id == stealoid) 91.  		return(0); 92.  	if((otmp->owornmask & (W_ARMOR | W_RING))){ 93.  		switch(otmp->olet) { 94.  		case RING_SYM: 95.  			ringoff(otmp); 96.  			break; 97.  		case ARMOR_SYM: 98.  			if(multi < 0 || otmp == uarms){ 99.  			  setworn((struct obj *) 0, otmp->owornmask & W_ARMOR); 100. 			  break; 101. 			}  102.  		{ int curssv = otmp->cursed; 103. 			otmp->cursed = 0; 104. 			stop_occupation; 105. 			if(flags.female) 106. 				pline("%s charms you.  You gladly hand over your humble garments.",  107.  				Monnam(mtmp)); 108. 			else 109. 				pline("%s seduces you and %s off your %s.",  110.  				Amonnam(mtmp, Blind ? "gentle" : "beautiful"), 111.  				otmp->cursed ? "helps you to take"  112.  					    : "you start taking",  113.  				(otmp == uarmg) ? "gloves" :  114.  				(otmp == uarmh) ? "helmet" : "armor"); 115. 			named++; 116. 			(void) armoroff(otmp); 117. 			otmp->cursed = curssv; 118. 			if(multi < 0){ 119. 				extern char *nomovemsg; 120. 				extern int (*afternmv); 121. 				/*  122.  				multi = 0; 123. 				nomovemsg = 0; 124. 				afternmv = 0; 125. 				*/  126.  				stealoid = otmp->o_id; 127. 				stealmid = mtmp->m_id; 128. 				afternmv = stealarm; 129. 				return(0); 130. 			}  131.  			break; 132. 		}  133.  		default: 134. 			impossible("Tried to steal a strange worn thing."); 135. 		}  136.  	}  137.  	else if(otmp == uwep) setuwep((struct obj *) 0); 138.  139.  	if(Punished && otmp == uball){ 140. 		Punished = 0; 141. 		freeobj(uchain); 142. 		free((char *) uchain); 143. 		uchain = (struct obj *) 0; 144. 		uball->spe = 0; 145. 		uball = (struct obj *) 0;	/* superfluous */ 146. 	}  147.  	freeinv(otmp); 148. 	pline("%s stole %s.", named ? "She" : Monnam(mtmp), doname(otmp)); 149. 	mpickobj(mtmp,otmp); 150. 	return((multi < 0) ? 0 : 1); 151. }  152.   153.  mpickobj(mtmp,otmp) 154. register struct monst *mtmp; 155. register struct obj *otmp; 156. {  157.  	otmp->nobj = mtmp->minvent; 158. 	mtmp->minvent = otmp; 159. }  160.   161.  stealamulet(mtmp) 162. register struct monst *mtmp; 163. {  164.  	register struct obj *otmp; 165.  166.  	for(otmp = invent; otmp; otmp = otmp->nobj) { 167. 	    if(otmp->olet == AMULET_SYM) { 168. 		/* might be an imitation one */ 169. 		if(otmp == uwep) setuwep((struct obj *) 0); 170. 		freeinv(otmp); 171. 		mpickobj(mtmp,otmp); 172. 		pline("%s stole %s!", Monnam(mtmp), doname(otmp)); 173. 		return(1); 174. 	    }  175.  	}  176.  	return(0); 177. }  178.   179.  /* release the objects the killed animal has stolen */ 180. relobj(mtmp,show) 181. register struct monst *mtmp; 182. register show; 183. {  184.  	register struct obj *otmp, *otmp2; 185.  186.  	for(otmp = mtmp->minvent; otmp; otmp = otmp2){ 187. 		otmp->ox = mtmp->mx; 188. 		otmp->oy = mtmp->my; 189. 		otmp2 = otmp->nobj; 190. 		otmp->nobj = fobj; 191. 		fobj = otmp; 192. 		stackobj(fobj); 193. 		if(show & cansee(mtmp->mx,mtmp->my)) 194. 			atl(otmp->ox,otmp->oy,Hallucination?rndobjsym : otmp->olet); 195. 	}  196.  	mtmp->minvent = (struct obj *) 0; 197. 	if(mtmp->mgold || mtmp->data->mlet == 'L') { 198. 		register long tmp; 199.  200.  		tmp = (mtmp->mgold > 10000) ? 10000 : mtmp->mgold; 201. 		mkgold((long)(tmp + d(dlevel,30)), mtmp->mx, mtmp->my); 202. 		if(show & cansee(mtmp->mx,mtmp->my)) 203. 			atl(mtmp->mx,mtmp->my, Hallucination ? rndobjsym : GOLD_SYM); 204. 	}  205.  }