Fandom

Wikihack

Source:NetHack 3.0.0/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 3.0.0. To link to a particular line, write [[NetHack 3.0.0/steal.c#line123]], for example.

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

The NetHack General Public License applies to screenshots, source code and other content from NetHack.
1.    /*	SCCS Id: @(#)steal.c	3.0	88/07/06
2.    /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3.    /* NetHack may be freely redistributed.  See license for details. */
4.    
5.    #include "hack.h"
6.    
7.    static char *
8.    equipname(otmp)
9.    
10.   	register struct obj *otmp;
11.   {
12.   
13.   	return (
14.   #ifdef SHIRT
15.   		(otmp == uarmu) ? "shirt" :
16.   #endif
17.   		(otmp == uarmf) ? "boots" :
18.   		(otmp == uarms) ? "shield" :
19.   		(otmp == uarmg) ? "gloves" :
20.   		(otmp == uarmc) ? "cloak" :
21.   		(otmp == uarmh) ? "helmet" : "armor");
22.   }
23.   
24.   long		/* actually returns something that fits in an int */
25.   somegold(){
26.   #ifdef LINT	/* long conv. ok */
27.   	return(0L);
28.   #else
29.   	return (long)( (u.ugold < 100) ? u.ugold :
30.   		(u.ugold > 10000) ? rnd(10000) : rnd((int) u.ugold) );
31.   #endif
32.   }
33.   
34.   void
35.   stealgold(mtmp)
36.   register struct monst *mtmp;
37.   {
38.   	register struct gold *gold = g_at(u.ux, u.uy);
39.   	register long tmp;
40.   	if(gold && ( !u.ugold || gold->amount > u.ugold || !rn2(5))) {
41.   		mtmp->mgold += gold->amount;
42.   		freegold(gold);
43.   		if(Invisible) newsym(u.ux, u.uy);
44.   		pline("%s quickly snatches some gold from between your %s!",
45.   			Monnam(mtmp), makeplural(body_part(FOOT)));
46.   		if(!u.ugold || !rn2(5)) {
47.   			rloc(mtmp);
48.   			mtmp->mflee = 1;
49.   		}
50.   	} else if(u.ugold) {
51.   		u.ugold -= (tmp = somegold());
52.   		Your("purse feels lighter.");
53.   		mtmp->mgold += tmp;
54.   		rloc(mtmp);
55.   		mtmp->mflee = 1;
56.   		flags.botl = 1;
57.   	}
58.   }
59.   
60.   /* steal armor after he finishes taking it off */
61.   unsigned int stealoid;		/* object to be stolen */
62.   unsigned int stealmid;		/* monster doing the stealing */
63.   
64.   static int
65.   stealarm(){
66.   	register struct monst *mtmp;
67.   	register struct obj *otmp;
68.   
69.   	for(otmp = invent; otmp; otmp = otmp->nobj)
70.   	  if(otmp->o_id == stealoid) {
71.   	    for(mtmp = fmon; mtmp; mtmp = mtmp->nmon)
72.   	      if(mtmp->m_id == stealmid) {
73.   		  freeinv(otmp);
74.   		  pline("%s steals %s!", Monnam(mtmp), doname(otmp));
75.   		  mpickobj(mtmp,otmp);
76.   		  mtmp->mflee = 1;
77.   		  rloc(mtmp);
78.   		break;
79.   	      }
80.   	    break;
81.   	  }
82.   	return stealoid = 0;
83.   }
84.   
85.   /* Returns 1 when something was stolen (or at least, when N should flee now)
86.    * Avoid stealing the object stealoid
87.    */
88.   int
89.   steal(mtmp)
90.   struct monst *mtmp;
91.   {
92.   	register struct obj *otmp;
93.   	register int tmp;
94.   	register int named = 0;
95.   
96.   	/* the following is true if successful on first of two attacks. */
97.   	if(dist(mtmp->mx, mtmp->my) > 3) return(0);
98.   
99.   	if(!invent){
100.  	    /* Not even a thousand men in armor can strip a naked man. */
101.  	    if(Blind)
102.  	      pline("Somebody tries to rob you, but finds nothing to steal.");
103.  	    else
104.  	      pline("%s tries to rob you, but she finds nothing to steal!",
105.  		Monnam(mtmp));
106.  	    return(1);	/* let her flee */
107.  	}
108.  
109.  	if(Adornment & LEFT_RING) {
110.  	    otmp = uleft;
111.  	    goto gotobj;
112.  	} else if(Adornment & RIGHT_RING) {
113.  	    otmp = uright;
114.  	    goto gotobj;
115.  	}
116.  
117.  	tmp = 0;
118.  	for(otmp = invent; otmp; otmp = otmp->nobj) if(otmp != uarmc)
119.  	    tmp += ((otmp->owornmask & (W_ARMOR | W_RING | W_AMUL | W_TOOL)) ? 5 : 1);
120.  	tmp = rn2(tmp);
121.  	for(otmp = invent; otmp; otmp = otmp->nobj) if(otmp != uarmc)
122.    	    if((tmp -= ((otmp->owornmask & (W_ARMOR | W_RING | W_AMUL | W_TOOL)) ? 5 : 1))
123.  			< 0) break;
124.  	if(!otmp) {
125.  		impossible("Steal fails!");
126.  		return(0);
127.  	}
128.  	/* can't steal armor while wearing cloak - so steal the cloak. */
129.  	if(otmp == uarm && uarmc) otmp = uarmc;
130.  #ifdef SHIRT
131.  	else if(otmp == uarmu && uarmc) otmp = uarmc;
132.  	else if(otmp == uarmu && uarm) otmp = uarm;
133.  #endif
134.  gotobj:
135.  	if(otmp->o_id == stealoid) return(0);
136.  
137.  #ifdef WALKIES
138.  	if(otmp->otyp == LEASH && otmp->leashmon) o_unleash(otmp);
139.  #endif
140.  
141.  	if((otmp->owornmask & (W_ARMOR | W_RING | W_AMUL | W_TOOL))){
142.  		switch(otmp->olet) {
143.  		case TOOL_SYM:
144.  			Blindf_off(otmp);
145.  			break;
146.  		case AMULET_SYM:
147.  			Amulet_off();
148.  			break;
149.  		case RING_SYM:
150.  			Ring_gone(otmp);
151.  			break;
152.  		case ARMOR_SYM:
153.  			if(multi < 0 || otmp == uarms){
154.  			  setworn((struct obj *) 0, otmp->owornmask & W_ARMOR);
155.  			  break;
156.  			}
157.  		{ int curssv = otmp->cursed;
158.  			otmp->cursed = 0;
159.  			stop_occupation();
160.  			if(flags.female)
161.  			    pline("%s charms you.  You gladly %s your %s.",
162.  				  Monnam(mtmp),
163.  				  curssv ? "let her take" : "hand over",
164.  				  equipname(otmp));
165.  			else
166.  			    pline("%s seduces you and %s off your %s.",
167.  				  Amonnam(mtmp, Blind ? "gentle" : "beautiful"),
168.  				  curssv ? "helps you to take" : "you start taking",
169.  				  equipname(otmp));
170.  			named++;
171.  			/* the following is to set multi for later on */
172.  			(void) nomul(-objects[otmp->otyp].oc_delay);
173.  
174.  			if (otmp == uarm)  (void) Armor_off();
175.  			else if (otmp == uarmc) (void) Cloak_off();
176.  			else if (otmp == uarmf) (void) Boots_off();
177.  			else if (otmp == uarmg) (void) Gloves_off();
178.  			else if (otmp == uarmh) (void) Helmet_off();
179.  			else if (otmp == uarms) (void) Shield_off();
180.  			else setworn((struct obj *)0, otmp->owornmask & W_ARMOR);
181.  			otmp->cursed = curssv;
182.  			if(multi < 0){
183.  				/*
184.  				multi = 0;
185.  				nomovemsg = 0;
186.  				afternmv = 0;
187.  				*/
188.  				stealoid = otmp->o_id;
189.  				stealmid = mtmp->m_id;
190.  				afternmv = stealarm;
191.  				return(0);
192.  			}
193.  			break;
194.  		}
195.  		default:
196.  			impossible("Tried to steal a strange worn thing.");
197.  		}
198.  	}
199.  	else if(otmp == uwep) uwepgone();
200.  
201.  	if(otmp == uball) unpunish();
202.  
203.  	freeinv(otmp);
204.  	pline("%s stole %s.", named ? "She" : Monnam(mtmp), doname(otmp));
205.  	mpickobj(mtmp,otmp);
206.  	return((multi < 0) ? 0 : 1);
207.  }
208.  
209.  void
210.  mpickobj(mtmp,otmp)
211.  register struct monst *mtmp;
212.  register struct obj *otmp;
213.  {
214.  	otmp->nobj = mtmp->minvent;
215.  	mtmp->minvent = otmp;
216.  }
217.  
218.  void
219.  stealamulet(mtmp)
220.  register struct monst *mtmp;
221.  {
222.  	register struct obj *otmp;
223.  
224.  	for(otmp = invent; otmp; otmp = otmp->nobj) {
225.  	    if(otmp->otyp == AMULET_OF_YENDOR) {
226.  		/* might be an imitation one */
227.  		setnotworn(otmp);
228.  		freeinv(otmp);
229.  		mpickobj(mtmp,otmp);
230.  		pline("%s stole %s!", Monnam(mtmp), doname(otmp));
231.  		rloc(mtmp);
232.  	    }
233.  	}
234.  }
235.  
236.  /* release the objects the killed animal has stolen */
237.  void
238.  relobj(mtmp,show)
239.  register struct monst *mtmp;
240.  register int show;
241.  {
242.  	register struct obj *otmp, *otmp2;
243.  
244.  	for(otmp = mtmp->minvent; otmp; otmp = otmp2){
245.  		otmp->ox = mtmp->mx;
246.  		otmp->oy = mtmp->my;
247.  		otmp2 = otmp->nobj;
248.  		otmp->nobj = fobj;
249.  		if (flooreffects(otmp,mtmp->mx,mtmp->my)) continue;
250.  		fobj = otmp;
251.  		levl[otmp->ox][otmp->oy].omask = 1;
252.  		stackobj(fobj);
253.  		if(show & cansee(mtmp->mx,mtmp->my))
254.  			atl(otmp->ox,otmp->oy,Hallucination?rndobjsym() : otmp->olet);
255.  	}
256.  	mtmp->minvent = (struct obj *) 0;
257.  	if(mtmp->mgold || mtmp->data->mlet == S_LEPRECHAUN) {
258.  		register long tmp;
259.  
260.  		tmp = (mtmp->mgold > 10000) ? 10000 : mtmp->mgold;
261.  		mkgold((long)(tmp + d(dlevel,30)), mtmp->mx, mtmp->my);
262.  		if(show & cansee(mtmp->mx,mtmp->my))
263.  			atl(mtmp->mx,mtmp->my, Hallucination ? rndobjsym() : GOLD_SYM);
264.  	}
265.  }

Also on Fandom

Random Wiki