Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / games / hack / hack.steal.c
1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 /* hack.steal.c - version 1.0.3 */
3 /* $FreeBSD: src/games/hack/hack.steal.c,v 1.4 1999/11/16 10:26:38 marcel Exp $ */
4 /* $DragonFly: src/games/hack/hack.steal.c,v 1.2 2003/06/17 04:25:24 dillon Exp $ */
5
6 #include "hack.h"
7
8 long            /* actually returns something that fits in an int */
9 somegold(){
10         return( (u.ugold < 100) ? u.ugold :
11                 (u.ugold > 10000) ? rnd(10000) : rnd((int) u.ugold) );
12 }
13
14 stealgold(mtmp)  struct monst *mtmp; {
15 struct gold *gold = g_at(u.ux, u.uy);
16 long tmp;
17         if(gold && ( !u.ugold || gold->amount > u.ugold || !rn2(5))) {
18                 mtmp->mgold += gold->amount;
19                 freegold(gold);
20                 if(Invisible) newsym(u.ux, u.uy);
21                 pline("%s quickly snatches some gold from between your feet!",
22                         Monnam(mtmp));
23                 if(!u.ugold || !rn2(5)) {
24                         rloc(mtmp);
25                         mtmp->mflee = 1;
26                 }
27         } else if(u.ugold) {
28                 u.ugold -= (tmp = somegold());
29                 pline("Your purse feels lighter.");
30                 mtmp->mgold += tmp;
31                 rloc(mtmp);
32                 mtmp->mflee = 1;
33                 flags.botl = 1;
34         }
35 }
36
37 /* steal armor after he finishes taking it off */
38 unsigned stealoid;              /* object to be stolen */
39 unsigned stealmid;              /* monster doing the stealing */
40 stealarm(){
41         struct monst *mtmp;
42         struct obj *otmp;
43
44         for(otmp = invent; otmp; otmp = otmp->nobj)
45           if(otmp->o_id == stealoid) {
46             for(mtmp = fmon; mtmp; mtmp = mtmp->nmon)
47               if(mtmp->m_id == stealmid) {
48                 if(dist(mtmp->mx,mtmp->my) < 3) {
49                   freeinv(otmp);
50                   pline("%s steals %s!", Monnam(mtmp), doname(otmp));
51                   mpickobj(mtmp,otmp);
52                   mtmp->mflee = 1;
53                   rloc(mtmp);
54                 }
55                 break;
56               }
57             break;
58           }
59         stealoid = 0;
60 }
61
62 /* returns 1 when something was stolen */
63 /* (or at least, when N should flee now) */
64 /* avoid stealing the object stealoid */
65 steal(mtmp)
66 struct monst *mtmp;
67 {
68         struct obj *otmp;
69         int tmp;
70         int named = 0;
71
72         if(!invent){
73             if(Blind)
74               pline("Somebody tries to rob you, but finds nothing to steal.");
75             else
76               pline("%s tries to rob you, but she finds nothing to steal!",
77                 Monnam(mtmp));
78             return(1);  /* let her flee */
79         }
80         tmp = 0;
81         for(otmp = invent; otmp; otmp = otmp->nobj) if(otmp != uarm2)
82                 tmp += ((otmp->owornmask & (W_ARMOR | W_RING)) ? 5 : 1);
83         tmp = rn2(tmp);
84         for(otmp = invent; otmp; otmp = otmp->nobj) if(otmp != uarm2)
85                 if((tmp -= ((otmp->owornmask & (W_ARMOR | W_RING)) ? 5 : 1))
86                         < 0) break;
87         if(!otmp) {
88                 impossible("Steal fails!");
89                 return(0);
90         }
91         if(otmp->o_id == stealoid)
92                 return(0);
93         if((otmp->owornmask & (W_ARMOR | W_RING))){
94                 switch(otmp->olet) {
95                 case RING_SYM:
96                         ringoff(otmp);
97                         break;
98                 case ARMOR_SYM:
99                         if(multi < 0 || otmp == uarms){
100                           setworn((struct obj *) 0, otmp->owornmask & W_ARMOR);
101                           break;
102                         }
103                 { int curssv = otmp->cursed;
104                         otmp->cursed = 0;
105                         stop_occupation();
106                         pline("%s seduces you and %s off your %s.",
107                                 Amonnam(mtmp, Blind ? "gentle" : "beautiful"),
108                                 otmp->cursed ? "helps you to take"
109                                             : "you start taking",
110                                 (otmp == uarmg) ? "gloves" :
111                                 (otmp == uarmh) ? "helmet" : "armor");
112                         named++;
113                         (void) armoroff(otmp);
114                         otmp->cursed = curssv;
115                         if(multi < 0){
116                                 extern char *nomovemsg;
117                                 extern int (*afternmv)();
118                                 /*
119                                 multi = 0;
120                                 nomovemsg = 0;
121                                 afternmv = 0;
122                                 */
123                                 stealoid = otmp->o_id;
124                                 stealmid = mtmp->m_id;
125                                 afternmv = stealarm;
126                                 return(0);
127                         }
128                         break;
129                 }
130                 default:
131                         impossible("Tried to steal a strange worn thing.");
132                 }
133         }
134         else if(otmp == uwep)
135                 setuwep((struct obj *) 0);
136         if(otmp->olet == CHAIN_SYM) {
137                 impossible("How come you are carrying that chain?");
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 struct monst *mtmp;
155 struct obj *otmp;
156 {
157         otmp->nobj = mtmp->minvent;
158         mtmp->minvent = otmp;
159 }
160
161 stealamulet(mtmp)
162 struct monst *mtmp;
163 {
164         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 struct monst *mtmp;
182 int show;
183 {
184         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,otmp->olet);
195         }
196         mtmp->minvent = (struct obj *) 0;
197         if(mtmp->mgold || mtmp->data->mlet == 'L') {
198                 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,'$');
204         }
205 }