Source:Hack 1.0/hack.steal.c

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

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

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