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