Fandom

Wikihack

Source:NetHack 2.3e/steal.c

2,034pages on
this wiki
Add New Page
Talk0

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

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

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

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

Also on Fandom

Random Wiki