#endif does not take an argument, comment it out.
[dragonfly.git] / games / hack / hack.do_wear.c
1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 /* hack.do_wear.c - version 1.0.3 */
3 /* $FreeBSD: src/games/hack/hack.do_wear.c,v 1.3 1999/11/16 02:57:03 billf Exp $ */
4 /* $DragonFly: src/games/hack/hack.do_wear.c,v 1.3 2004/11/06 12:29:17 eirikn Exp $ */
5
6 #include "hack.h"
7 #include <stdio.h>
8 extern char *nomovemsg;
9 extern char quitchars[];
10 extern char *Doname();
11
12 off_msg(otmp) struct obj *otmp; {
13         pline("You were wearing %s.", doname(otmp));
14 }
15
16 doremarm() {
17         struct obj *otmp;
18         if(!uarm && !uarmh && !uarms && !uarmg) {
19                 pline("Not wearing any armor.");
20                 return(0);
21         }
22         otmp = (!uarmh && !uarms && !uarmg) ? uarm :
23                 (!uarms && !uarm && !uarmg) ? uarmh :
24                 (!uarmh && !uarm && !uarmg) ? uarms :
25                 (!uarmh && !uarm && !uarms) ? uarmg :
26                 getobj("[", "take off");
27         if(!otmp) return(0);
28         if(!(otmp->owornmask & (W_ARMOR - W_ARM2))) {
29                 pline("You can't take that off.");
30                 return(0);
31         }
32         if( otmp == uarmg && uwep && uwep->cursed ) {   /* myers@uwmacc */
33  pline("You seem not able to take off the gloves while holding your weapon.");
34                 return(0);
35         }
36         (void) armoroff(otmp);
37         return(1);
38 }
39
40 doremring() {
41         if(!uleft && !uright){
42                 pline("Not wearing any ring.");
43                 return(0);
44         }
45         if(!uleft)
46                 return(dorr(uright));
47         if(!uright)
48                 return(dorr(uleft));
49         if(uleft && uright) while(1) {
50                 char answer;
51
52                 pline("What ring, Right or Left? [ rl?]");
53                 if(index(quitchars, (answer = readchar())))
54                         return(0);
55                 switch(answer) {
56                 case 'l':
57                 case 'L':
58                         return(dorr(uleft));
59                 case 'r':
60                 case 'R':
61                         return(dorr(uright));
62                 case '?':
63                         (void) doprring();
64                         /* might look at morc here %% */
65                 }
66         }
67         /* NOTREACHED */
68 #ifdef lint
69         return(0);
70 #endif /* lint */
71 }
72
73 dorr(otmp) struct obj *otmp; {
74         if(cursed(otmp)) return(0);
75         ringoff(otmp);
76         off_msg(otmp);
77         return(1);
78 }
79
80 cursed(otmp) struct obj *otmp; {
81         if(otmp->cursed){
82                 pline("You can't. It appears to be cursed.");
83                 return(1);
84         }
85         return(0);
86 }
87
88 armoroff(otmp) struct obj *otmp; {
89 int delay = -objects[otmp->otyp].oc_delay;
90         if(cursed(otmp)) return(0);
91         setworn((struct obj *) 0, otmp->owornmask & W_ARMOR);
92         if(delay) {
93                 nomul(delay);
94                 switch(otmp->otyp) {
95                 case HELMET:
96                         nomovemsg = "You finished taking off your helmet.";
97                         break;
98                 case PAIR_OF_GLOVES:
99                         nomovemsg = "You finished taking off your gloves";
100                         break;
101                 default:
102                         nomovemsg = "You finished taking off your suit.";
103                 }
104         } else {
105                 off_msg(otmp);
106         }
107         return(1);
108 }
109
110 doweararm() {
111         struct obj *otmp;
112         int delay;
113         int err = 0;
114         long mask = 0;
115
116         otmp = getobj("[", "wear");
117         if(!otmp) return(0);
118         if(otmp->owornmask & W_ARMOR) {
119                 pline("You are already wearing that!");
120                 return(0);
121         }
122         if(otmp->otyp == HELMET){
123                 if(uarmh) {
124                         pline("You are already wearing a helmet.");
125                         err++;
126                 } else
127                         mask = W_ARMH;
128         } else if(otmp->otyp == SHIELD){
129                 if(uarms) pline("You are already wearing a shield."), err++;
130                 if(uwep && uwep->otyp == TWO_HANDED_SWORD)
131         pline("You cannot wear a shield and wield a two-handed sword."), err++;
132                 if(!err) mask = W_ARMS;
133         } else if(otmp->otyp == PAIR_OF_GLOVES) {
134                 if(uarmg) {
135                         pline("You are already wearing gloves.");
136                         err++;
137                 } else
138                 if(uwep && uwep->cursed) {
139                         pline("You cannot wear gloves over your weapon.");
140                         err++;
141                 } else
142                         mask = W_ARMG;
143         } else {
144                 if(uarm) {
145                         if(otmp->otyp != ELVEN_CLOAK || uarm2) {
146                                 pline("You are already wearing some armor.");
147                                 err++;
148                         }
149                 }
150                 if(!err) mask = W_ARM;
151         }
152         if(otmp == uwep && uwep->cursed) {
153                 if(!err++)
154                         pline("%s is welded to your hand.", Doname(uwep));
155         }
156         if(err) return(0);
157         setworn(otmp, mask);
158         if(otmp == uwep)
159                 setuwep((struct obj *) 0);
160         delay = -objects[otmp->otyp].oc_delay;
161         if(delay){
162                 nomul(delay);
163                 nomovemsg = "You finished your dressing manoeuvre.";
164         }
165         otmp->known = 1;
166         return(1);
167 }
168
169 dowearring() {
170         struct obj *otmp;
171         long mask = 0;
172         long oldprop;
173
174         if(uleft && uright){
175                 pline("There are no more ring-fingers to fill.");
176                 return(0);
177         }
178         otmp = getobj("=", "wear");
179         if(!otmp) return(0);
180         if(otmp->owornmask & W_RING) {
181                 pline("You are already wearing that!");
182                 return(0);
183         }
184         if(otmp == uleft || otmp == uright) {
185                 pline("You are already wearing that.");
186                 return(0);
187         }
188         if(otmp == uwep && uwep->cursed) {
189                 pline("%s is welded to your hand.", Doname(uwep));
190                 return(0);
191         }
192         if(uleft) mask = RIGHT_RING;
193         else if(uright) mask = LEFT_RING;
194         else do {
195                 char answer;
196
197                 pline("What ring-finger, Right or Left? ");
198                 if(index(quitchars, (answer = readchar())))
199                         return(0);
200                 switch(answer){
201                 case 'l':
202                 case 'L':
203                         mask = LEFT_RING;
204                         break;
205                 case 'r':
206                 case 'R':
207                         mask = RIGHT_RING;
208                         break;
209                 }
210         } while(!mask);
211         setworn(otmp, mask);
212         if(otmp == uwep)
213                 setuwep((struct obj *) 0);
214         oldprop = u.uprops[PROP(otmp->otyp)].p_flgs;
215         u.uprops[PROP(otmp->otyp)].p_flgs |= mask;
216         switch(otmp->otyp){
217         case RIN_LEVITATION:
218                 if(!oldprop) float_up();
219                 break;
220         case RIN_PROTECTION_FROM_SHAPE_CHANGERS:
221                 rescham();
222                 break;
223         case RIN_GAIN_STRENGTH:
224                 u.ustr += otmp->spe;
225                 u.ustrmax += otmp->spe;
226                 if(u.ustr > 118) u.ustr = 118;
227                 if(u.ustrmax > 118) u.ustrmax = 118;
228                 flags.botl = 1;
229                 break;
230         case RIN_INCREASE_DAMAGE:
231                 u.udaminc += otmp->spe;
232                 break;
233         }
234         prinv(otmp);
235         return(1);
236 }
237
238 ringoff(obj)
239 struct obj *obj;
240 {
241 long mask;
242         mask = obj->owornmask & W_RING;
243         setworn((struct obj *) 0, obj->owornmask);
244         if(!(u.uprops[PROP(obj->otyp)].p_flgs & mask))
245                 impossible("Strange... I didnt know you had that ring.");
246         u.uprops[PROP(obj->otyp)].p_flgs &= ~mask;
247         switch(obj->otyp) {
248         case RIN_FIRE_RESISTANCE:
249                 /* Bad luck if the player is in hell... --jgm */
250                 if (!Fire_resistance && dlevel >= 30) {
251                         pline("The flames of Hell burn you to a crisp.");
252                         killer = "stupidity in hell";
253                         done("burned");
254                 }
255                 break;
256         case RIN_LEVITATION:
257                 if(!Levitation) {       /* no longer floating */
258                         float_down();
259                 }
260                 break;
261         case RIN_GAIN_STRENGTH:
262                 u.ustr -= obj->spe;
263                 u.ustrmax -= obj->spe;
264                 if(u.ustr > 118) u.ustr = 118;
265                 if(u.ustrmax > 118) u.ustrmax = 118;
266                 flags.botl = 1;
267                 break;
268         case RIN_INCREASE_DAMAGE:
269                 u.udaminc -= obj->spe;
270                 break;
271         }
272 }
273
274 find_ac(){
275 int uac = 10;
276         if(uarm) uac -= ARM_BONUS(uarm);
277         if(uarm2) uac -= ARM_BONUS(uarm2);
278         if(uarmh) uac -= ARM_BONUS(uarmh);
279         if(uarms) uac -= ARM_BONUS(uarms);
280         if(uarmg) uac -= ARM_BONUS(uarmg);
281         if(uleft && uleft->otyp == RIN_PROTECTION) uac -= uleft->spe;
282         if(uright && uright->otyp == RIN_PROTECTION) uac -= uright->spe;
283         if(uac != u.uac){
284                 u.uac = uac;
285                 flags.botl = 1;
286         }
287 }
288
289 glibr(){
290 struct obj *otmp;
291 int xfl = 0;
292         if(!uarmg) if(uleft || uright) {
293                 /* Note: at present also cursed rings fall off */
294                 pline("Your %s off your fingers.",
295                         (uleft && uright) ? "rings slip" : "ring slips");
296                 xfl++;
297                 if((otmp = uleft) != Null(obj)){
298                         ringoff(uleft);
299                         dropx(otmp);
300                 }
301                 if((otmp = uright) != Null(obj)){
302                         ringoff(uright);
303                         dropx(otmp);
304                 }
305         }
306         if((otmp = uwep) != Null(obj)){
307                 /* Note: at present also cursed weapons fall */
308                 setuwep((struct obj *) 0);
309                 dropx(otmp);
310                 pline("Your weapon %sslips from your hands.",
311                         xfl ? "also " : "");
312         }
313 }
314
315 struct obj *
316 some_armor(){
317 struct obj *otmph = uarm;
318         if(uarmh && (!otmph || !rn2(4))) otmph = uarmh;
319         if(uarmg && (!otmph || !rn2(4))) otmph = uarmg;
320         if(uarms && (!otmph || !rn2(4))) otmph = uarms;
321         return(otmph);
322 }
323
324 corrode_armor(){
325 struct obj *otmph = some_armor();
326         if(otmph){
327                 if(otmph->rustfree ||
328                    otmph->otyp == ELVEN_CLOAK ||
329                    otmph->otyp == LEATHER_ARMOR ||
330                    otmph->otyp == STUDDED_LEATHER_ARMOR) {
331                         pline("Your %s not affected!",
332                                 aobjnam(otmph, "are"));
333                         return;
334                 }
335                 pline("Your %s!", aobjnam(otmph, "corrode"));
336                 otmph->spe--;
337         }
338 }