```   1: /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2: /* hack.steal.c - version 1.0.3 */
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());
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:             pline("%s seduces you and %s off your %s.",
105:                 Amonnam(mtmp, Blind ? "gentle" : "beautiful"),
106:                 otmp->cursed ? "helps you to take"
107:                         : "you start taking",
108:                 (otmp == uarmg) ? "gloves" :
109:                 (otmp == uarmh) ? "helmet" : "armor");
110:             named++;
111:             (void) armoroff(otmp);
113:             if(multi < 0){
114:                 extern char *nomovemsg;
115:                 extern int (*afternmv)();
116:                 /*
117: 				multi = 0;
118: 				nomovemsg = 0;
119: 				afternmv = 0;
120: 				*/
121:                 stealoid = otmp->o_id;
122:                 stealmid = mtmp->m_id;
123:                 afternmv = stealarm;
124:                 return(0);
125:             }
126:             break;
127:         }
128:         default:
129:             impossible("Tried to steal a strange worn thing.");
130:         }
131:     }
132:     else if(otmp == uwep)
133:         setuwep((struct obj *) 0);
134:     if(otmp->olet == CHAIN_SYM) {
135:         impossible("How come you are carrying that chain?");
136:     }
137:     if(Punished && otmp == uball){
138:         Punished = 0;
139:         freeobj(uchain);
140:         free((char *) uchain);
141:         uchain = (struct obj *) 0;
142:         uball->spe = 0;
143:         uball = (struct obj *) 0;   /* superfluous */
144:     }
145:     freeinv(otmp);
146:     pline("%s stole %s.", named ? "She" : Monnam(mtmp), doname(otmp));
147:     mpickobj(mtmp,otmp);
148:     return((multi < 0) ? 0 : 1);
149: }
150:
151: mpickobj(mtmp,otmp)
152: register struct monst *mtmp;
153: register struct obj *otmp;
154: {
155:     otmp->nobj = mtmp->minvent;
156:     mtmp->minvent = otmp;
157: }
158:
159: stealamulet(mtmp)
160: register struct monst *mtmp;
161: {
162:     register struct obj *otmp;
163:
164:     for(otmp = invent; otmp; otmp = otmp->nobj) {
165:         if(otmp->olet == AMULET_SYM) {
166:         /* might be an imitation one */
167:         if(otmp == uwep) setuwep((struct obj *) 0);
168:         freeinv(otmp);
169:         mpickobj(mtmp,otmp);
170:         pline("%s stole %s!", Monnam(mtmp), doname(otmp));
171:         return(1);
172:         }
173:     }
174:     return(0);
175: }
176:
177: /* release the objects the killed animal has stolen */
178: relobj(mtmp,show)
179: register struct monst *mtmp;
180: register show;
181: {
182:     register struct obj *otmp, *otmp2;
183:
184:     for(otmp = mtmp->minvent; otmp; otmp = otmp2){
185:         otmp->ox = mtmp->mx;
186:         otmp->oy = mtmp->my;
187:         otmp2 = otmp->nobj;
188:         otmp->nobj = fobj;
189:         fobj = otmp;
190:         stackobj(fobj);
191:         if(show & cansee(mtmp->mx,mtmp->my))
192:             atl(otmp->ox,otmp->oy,otmp->olet);
193:     }
194:     mtmp->minvent = (struct obj *) 0;
195:     if(mtmp->mgold || mtmp->data->mlet == 'L') {
196:         register long tmp;
197:
198:         tmp = (mtmp->mgold > 10000) ? 10000 : mtmp->mgold;
199:         mkgold((long)(tmp + d(dlevel,30)), mtmp->mx, mtmp->my);
200:         if(show & cansee(mtmp->mx,mtmp->my))
201:             atl(mtmp->mx,mtmp->my,'\$');
202:     }
203: }
```

#### Defined functions

relobj defined in line 178; used 2 times
somegold defined in line 6; used 3 times
steal defined in line 63; used 1 times
stealamulet defined in line 159; used 1 times
stealarm defined in line 38; used 1 times
stealgold defined in line 12; used 1 times

#### Defined variables

stealmid defined in line 37; used 2 times
stealoid defined in line 36; used 4 times
 Last modified: 1985-10-01 Generated: 2016-12-26 Generated by src2html V0.67 page hit count: 2799