hack.do_wear.c revision 1.5 1 1.5 jsm /* $NetBSD: hack.do_wear.c,v 1.5 2003/04/02 18:36:36 jsm Exp $ */
2 1.4 christos
3 1.2 mycroft /*
4 1.5 jsm * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
5 1.5 jsm * Amsterdam
6 1.5 jsm * All rights reserved.
7 1.5 jsm *
8 1.5 jsm * Redistribution and use in source and binary forms, with or without
9 1.5 jsm * modification, are permitted provided that the following conditions are
10 1.5 jsm * met:
11 1.5 jsm *
12 1.5 jsm * - Redistributions of source code must retain the above copyright notice,
13 1.5 jsm * this list of conditions and the following disclaimer.
14 1.5 jsm *
15 1.5 jsm * - Redistributions in binary form must reproduce the above copyright
16 1.5 jsm * notice, this list of conditions and the following disclaimer in the
17 1.5 jsm * documentation and/or other materials provided with the distribution.
18 1.5 jsm *
19 1.5 jsm * - Neither the name of the Stichting Centrum voor Wiskunde en
20 1.5 jsm * Informatica, nor the names of its contributors may be used to endorse or
21 1.5 jsm * promote products derived from this software without specific prior
22 1.5 jsm * written permission.
23 1.5 jsm *
24 1.5 jsm * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
25 1.5 jsm * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26 1.5 jsm * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
27 1.5 jsm * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
28 1.5 jsm * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 1.5 jsm * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 1.5 jsm * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31 1.5 jsm * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 1.5 jsm * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 1.5 jsm * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 1.5 jsm * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 1.5 jsm */
36 1.5 jsm
37 1.5 jsm /*
38 1.5 jsm * Copyright (c) 1982 Jay Fenlason <hack (at) gnu.org>
39 1.5 jsm * All rights reserved.
40 1.5 jsm *
41 1.5 jsm * Redistribution and use in source and binary forms, with or without
42 1.5 jsm * modification, are permitted provided that the following conditions
43 1.5 jsm * are met:
44 1.5 jsm * 1. Redistributions of source code must retain the above copyright
45 1.5 jsm * notice, this list of conditions and the following disclaimer.
46 1.5 jsm * 2. Redistributions in binary form must reproduce the above copyright
47 1.5 jsm * notice, this list of conditions and the following disclaimer in the
48 1.5 jsm * documentation and/or other materials provided with the distribution.
49 1.5 jsm * 3. The name of the author may not be used to endorse or promote products
50 1.5 jsm * derived from this software without specific prior written permission.
51 1.5 jsm *
52 1.5 jsm * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
53 1.5 jsm * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
54 1.5 jsm * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
55 1.5 jsm * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
56 1.5 jsm * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
57 1.5 jsm * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
58 1.5 jsm * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
59 1.5 jsm * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
60 1.5 jsm * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
61 1.5 jsm * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62 1.2 mycroft */
63 1.2 mycroft
64 1.4 christos #include <sys/cdefs.h>
65 1.2 mycroft #ifndef lint
66 1.5 jsm __RCSID("$NetBSD: hack.do_wear.c,v 1.5 2003/04/02 18:36:36 jsm Exp $");
67 1.4 christos #endif /* not lint */
68 1.1 cgd
69 1.1 cgd #include "hack.h"
70 1.4 christos #include "extern.h"
71 1.1 cgd
72 1.4 christos void
73 1.4 christos off_msg(otmp)
74 1.4 christos struct obj *otmp;
75 1.4 christos {
76 1.1 cgd pline("You were wearing %s.", doname(otmp));
77 1.1 cgd }
78 1.1 cgd
79 1.4 christos int
80 1.4 christos doremarm()
81 1.4 christos {
82 1.4 christos struct obj *otmp;
83 1.4 christos if (!uarm && !uarmh && !uarms && !uarmg) {
84 1.1 cgd pline("Not wearing any armor.");
85 1.4 christos return (0);
86 1.1 cgd }
87 1.1 cgd otmp = (!uarmh && !uarms && !uarmg) ? uarm :
88 1.1 cgd (!uarms && !uarm && !uarmg) ? uarmh :
89 1.1 cgd (!uarmh && !uarm && !uarmg) ? uarms :
90 1.1 cgd (!uarmh && !uarm && !uarms) ? uarmg :
91 1.1 cgd getobj("[", "take off");
92 1.4 christos if (!otmp)
93 1.4 christos return (0);
94 1.4 christos if (!(otmp->owornmask & (W_ARMOR - W_ARM2))) {
95 1.1 cgd pline("You can't take that off.");
96 1.4 christos return (0);
97 1.1 cgd }
98 1.4 christos if (otmp == uarmg && uwep && uwep->cursed) { /* myers@uwmacc */
99 1.4 christos pline("You seem not able to take off the gloves while holding your weapon.");
100 1.4 christos return (0);
101 1.1 cgd }
102 1.1 cgd (void) armoroff(otmp);
103 1.4 christos return (1);
104 1.1 cgd }
105 1.1 cgd
106 1.4 christos int
107 1.4 christos doremring()
108 1.4 christos {
109 1.4 christos if (!uleft && !uright) {
110 1.1 cgd pline("Not wearing any ring.");
111 1.4 christos return (0);
112 1.1 cgd }
113 1.4 christos if (!uleft)
114 1.4 christos return (dorr(uright));
115 1.4 christos if (!uright)
116 1.4 christos return (dorr(uleft));
117 1.4 christos if (uleft && uright)
118 1.4 christos while (1) {
119 1.4 christos char answer;
120 1.4 christos
121 1.4 christos pline("What ring, Right or Left? [ rl?]");
122 1.4 christos if (strchr(quitchars, (answer = readchar())))
123 1.4 christos return (0);
124 1.4 christos switch (answer) {
125 1.4 christos case 'l':
126 1.4 christos case 'L':
127 1.4 christos return (dorr(uleft));
128 1.4 christos case 'r':
129 1.4 christos case 'R':
130 1.4 christos return (dorr(uright));
131 1.4 christos case '?':
132 1.4 christos (void) doprring();
133 1.4 christos /* might look at morc here %% */
134 1.4 christos }
135 1.1 cgd }
136 1.1 cgd /* NOTREACHED */
137 1.4 christos return (0);
138 1.1 cgd }
139 1.1 cgd
140 1.4 christos int
141 1.4 christos dorr(otmp)
142 1.4 christos struct obj *otmp;
143 1.4 christos {
144 1.4 christos if (cursed(otmp))
145 1.4 christos return (0);
146 1.1 cgd ringoff(otmp);
147 1.1 cgd off_msg(otmp);
148 1.4 christos return (1);
149 1.1 cgd }
150 1.1 cgd
151 1.4 christos int
152 1.4 christos cursed(otmp)
153 1.4 christos struct obj *otmp;
154 1.4 christos {
155 1.4 christos if (otmp->cursed) {
156 1.1 cgd pline("You can't. It appears to be cursed.");
157 1.4 christos return (1);
158 1.1 cgd }
159 1.4 christos return (0);
160 1.1 cgd }
161 1.1 cgd
162 1.4 christos int
163 1.4 christos armoroff(otmp)
164 1.4 christos struct obj *otmp;
165 1.4 christos {
166 1.4 christos int delay = -objects[otmp->otyp].oc_delay;
167 1.4 christos if (cursed(otmp))
168 1.4 christos return (0);
169 1.1 cgd setworn((struct obj *) 0, otmp->owornmask & W_ARMOR);
170 1.4 christos if (delay) {
171 1.1 cgd nomul(delay);
172 1.4 christos switch (otmp->otyp) {
173 1.1 cgd case HELMET:
174 1.1 cgd nomovemsg = "You finished taking off your helmet.";
175 1.1 cgd break;
176 1.1 cgd case PAIR_OF_GLOVES:
177 1.1 cgd nomovemsg = "You finished taking off your gloves";
178 1.1 cgd break;
179 1.1 cgd default:
180 1.1 cgd nomovemsg = "You finished taking off your suit.";
181 1.1 cgd }
182 1.1 cgd } else {
183 1.1 cgd off_msg(otmp);
184 1.1 cgd }
185 1.4 christos return (1);
186 1.1 cgd }
187 1.1 cgd
188 1.4 christos int
189 1.4 christos doweararm()
190 1.4 christos {
191 1.4 christos struct obj *otmp;
192 1.4 christos int delay;
193 1.4 christos int err = 0;
194 1.4 christos long mask = 0;
195 1.1 cgd
196 1.1 cgd otmp = getobj("[", "wear");
197 1.4 christos if (!otmp)
198 1.4 christos return (0);
199 1.4 christos if (otmp->owornmask & W_ARMOR) {
200 1.1 cgd pline("You are already wearing that!");
201 1.4 christos return (0);
202 1.1 cgd }
203 1.4 christos if (otmp->otyp == HELMET) {
204 1.4 christos if (uarmh) {
205 1.1 cgd pline("You are already wearing a helmet.");
206 1.1 cgd err++;
207 1.1 cgd } else
208 1.1 cgd mask = W_ARMH;
209 1.4 christos } else if (otmp->otyp == SHIELD) {
210 1.4 christos if (uarms)
211 1.4 christos pline("You are already wearing a shield."), err++;
212 1.4 christos if (uwep && uwep->otyp == TWO_HANDED_SWORD)
213 1.4 christos pline("You cannot wear a shield and wield a two-handed sword."), err++;
214 1.4 christos if (!err)
215 1.4 christos mask = W_ARMS;
216 1.4 christos } else if (otmp->otyp == PAIR_OF_GLOVES) {
217 1.4 christos if (uarmg) {
218 1.1 cgd pline("You are already wearing gloves.");
219 1.1 cgd err++;
220 1.4 christos } else if (uwep && uwep->cursed) {
221 1.1 cgd pline("You cannot wear gloves over your weapon.");
222 1.1 cgd err++;
223 1.1 cgd } else
224 1.1 cgd mask = W_ARMG;
225 1.1 cgd } else {
226 1.4 christos if (uarm) {
227 1.4 christos if (otmp->otyp != ELVEN_CLOAK || uarm2) {
228 1.1 cgd pline("You are already wearing some armor.");
229 1.1 cgd err++;
230 1.1 cgd }
231 1.1 cgd }
232 1.4 christos if (!err)
233 1.4 christos mask = W_ARM;
234 1.1 cgd }
235 1.4 christos if (otmp == uwep && uwep->cursed) {
236 1.4 christos if (!err++)
237 1.1 cgd pline("%s is welded to your hand.", Doname(uwep));
238 1.1 cgd }
239 1.4 christos if (err)
240 1.4 christos return (0);
241 1.1 cgd setworn(otmp, mask);
242 1.4 christos if (otmp == uwep)
243 1.1 cgd setuwep((struct obj *) 0);
244 1.1 cgd delay = -objects[otmp->otyp].oc_delay;
245 1.4 christos if (delay) {
246 1.1 cgd nomul(delay);
247 1.1 cgd nomovemsg = "You finished your dressing manoeuvre.";
248 1.1 cgd }
249 1.1 cgd otmp->known = 1;
250 1.4 christos return (1);
251 1.1 cgd }
252 1.1 cgd
253 1.4 christos int
254 1.4 christos dowearring()
255 1.4 christos {
256 1.4 christos struct obj *otmp;
257 1.4 christos long mask = 0;
258 1.4 christos long oldprop;
259 1.1 cgd
260 1.4 christos if (uleft && uright) {
261 1.1 cgd pline("There are no more ring-fingers to fill.");
262 1.4 christos return (0);
263 1.1 cgd }
264 1.1 cgd otmp = getobj("=", "wear");
265 1.4 christos if (!otmp)
266 1.4 christos return (0);
267 1.4 christos if (otmp->owornmask & W_RING) {
268 1.1 cgd pline("You are already wearing that!");
269 1.4 christos return (0);
270 1.1 cgd }
271 1.4 christos if (otmp == uleft || otmp == uright) {
272 1.1 cgd pline("You are already wearing that.");
273 1.4 christos return (0);
274 1.1 cgd }
275 1.4 christos if (otmp == uwep && uwep->cursed) {
276 1.1 cgd pline("%s is welded to your hand.", Doname(uwep));
277 1.4 christos return (0);
278 1.1 cgd }
279 1.4 christos if (uleft)
280 1.4 christos mask = RIGHT_RING;
281 1.4 christos else if (uright)
282 1.4 christos mask = LEFT_RING;
283 1.4 christos else
284 1.4 christos do {
285 1.4 christos char answer;
286 1.4 christos
287 1.4 christos pline("What ring-finger, Right or Left? ");
288 1.4 christos if (strchr(quitchars, (answer = readchar())))
289 1.4 christos return (0);
290 1.4 christos switch (answer) {
291 1.4 christos case 'l':
292 1.4 christos case 'L':
293 1.4 christos mask = LEFT_RING;
294 1.4 christos break;
295 1.4 christos case 'r':
296 1.4 christos case 'R':
297 1.4 christos mask = RIGHT_RING;
298 1.4 christos break;
299 1.4 christos }
300 1.4 christos } while (!mask);
301 1.1 cgd setworn(otmp, mask);
302 1.4 christos if (otmp == uwep)
303 1.1 cgd setuwep((struct obj *) 0);
304 1.1 cgd oldprop = u.uprops[PROP(otmp->otyp)].p_flgs;
305 1.1 cgd u.uprops[PROP(otmp->otyp)].p_flgs |= mask;
306 1.4 christos switch (otmp->otyp) {
307 1.1 cgd case RIN_LEVITATION:
308 1.4 christos if (!oldprop)
309 1.4 christos float_up();
310 1.1 cgd break;
311 1.1 cgd case RIN_PROTECTION_FROM_SHAPE_CHANGERS:
312 1.1 cgd rescham();
313 1.1 cgd break;
314 1.1 cgd case RIN_GAIN_STRENGTH:
315 1.1 cgd u.ustr += otmp->spe;
316 1.1 cgd u.ustrmax += otmp->spe;
317 1.4 christos if (u.ustr > 118)
318 1.4 christos u.ustr = 118;
319 1.4 christos if (u.ustrmax > 118)
320 1.4 christos u.ustrmax = 118;
321 1.1 cgd flags.botl = 1;
322 1.1 cgd break;
323 1.1 cgd case RIN_INCREASE_DAMAGE:
324 1.1 cgd u.udaminc += otmp->spe;
325 1.1 cgd break;
326 1.1 cgd }
327 1.1 cgd prinv(otmp);
328 1.4 christos return (1);
329 1.1 cgd }
330 1.1 cgd
331 1.4 christos void
332 1.1 cgd ringoff(obj)
333 1.4 christos struct obj *obj;
334 1.1 cgd {
335 1.4 christos long mask;
336 1.1 cgd mask = obj->owornmask & W_RING;
337 1.1 cgd setworn((struct obj *) 0, obj->owornmask);
338 1.4 christos if (!(u.uprops[PROP(obj->otyp)].p_flgs & mask))
339 1.1 cgd impossible("Strange... I didnt know you had that ring.");
340 1.1 cgd u.uprops[PROP(obj->otyp)].p_flgs &= ~mask;
341 1.4 christos switch (obj->otyp) {
342 1.1 cgd case RIN_FIRE_RESISTANCE:
343 1.1 cgd /* Bad luck if the player is in hell... --jgm */
344 1.1 cgd if (!Fire_resistance && dlevel >= 30) {
345 1.1 cgd pline("The flames of Hell burn you to a crisp.");
346 1.1 cgd killer = "stupidity in hell";
347 1.1 cgd done("burned");
348 1.1 cgd }
349 1.1 cgd break;
350 1.1 cgd case RIN_LEVITATION:
351 1.4 christos if (!Levitation) { /* no longer floating */
352 1.1 cgd float_down();
353 1.1 cgd }
354 1.1 cgd break;
355 1.1 cgd case RIN_GAIN_STRENGTH:
356 1.1 cgd u.ustr -= obj->spe;
357 1.1 cgd u.ustrmax -= obj->spe;
358 1.4 christos if (u.ustr > 118)
359 1.4 christos u.ustr = 118;
360 1.4 christos if (u.ustrmax > 118)
361 1.4 christos u.ustrmax = 118;
362 1.1 cgd flags.botl = 1;
363 1.1 cgd break;
364 1.1 cgd case RIN_INCREASE_DAMAGE:
365 1.1 cgd u.udaminc -= obj->spe;
366 1.1 cgd break;
367 1.1 cgd }
368 1.1 cgd }
369 1.1 cgd
370 1.4 christos void
371 1.4 christos find_ac()
372 1.4 christos {
373 1.4 christos int uac = 10;
374 1.4 christos if (uarm)
375 1.4 christos uac -= ARM_BONUS(uarm);
376 1.4 christos if (uarm2)
377 1.4 christos uac -= ARM_BONUS(uarm2);
378 1.4 christos if (uarmh)
379 1.4 christos uac -= ARM_BONUS(uarmh);
380 1.4 christos if (uarms)
381 1.4 christos uac -= ARM_BONUS(uarms);
382 1.4 christos if (uarmg)
383 1.4 christos uac -= ARM_BONUS(uarmg);
384 1.4 christos if (uleft && uleft->otyp == RIN_PROTECTION)
385 1.4 christos uac -= uleft->spe;
386 1.4 christos if (uright && uright->otyp == RIN_PROTECTION)
387 1.4 christos uac -= uright->spe;
388 1.4 christos if (uac != u.uac) {
389 1.1 cgd u.uac = uac;
390 1.1 cgd flags.botl = 1;
391 1.1 cgd }
392 1.1 cgd }
393 1.1 cgd
394 1.4 christos void
395 1.4 christos glibr()
396 1.4 christos {
397 1.4 christos struct obj *otmp;
398 1.4 christos int xfl = 0;
399 1.4 christos if (!uarmg)
400 1.4 christos if (uleft || uright) {
401 1.4 christos /* Note: at present also cursed rings fall off */
402 1.4 christos pline("Your %s off your fingers.",
403 1.4 christos (uleft && uright) ? "rings slip" : "ring slips");
404 1.4 christos xfl++;
405 1.4 christos if ((otmp = uleft) != Null(obj)) {
406 1.4 christos ringoff(uleft);
407 1.4 christos dropx(otmp);
408 1.4 christos }
409 1.4 christos if ((otmp = uright) != Null(obj)) {
410 1.4 christos ringoff(uright);
411 1.4 christos dropx(otmp);
412 1.4 christos }
413 1.1 cgd }
414 1.4 christos if ((otmp = uwep) != Null(obj)) {
415 1.1 cgd /* Note: at present also cursed weapons fall */
416 1.1 cgd setuwep((struct obj *) 0);
417 1.1 cgd dropx(otmp);
418 1.1 cgd pline("Your weapon %sslips from your hands.",
419 1.4 christos xfl ? "also " : "");
420 1.1 cgd }
421 1.1 cgd }
422 1.1 cgd
423 1.4 christos struct obj *
424 1.4 christos some_armor()
425 1.4 christos {
426 1.4 christos struct obj *otmph = uarm;
427 1.4 christos if (uarmh && (!otmph || !rn2(4)))
428 1.4 christos otmph = uarmh;
429 1.4 christos if (uarmg && (!otmph || !rn2(4)))
430 1.4 christos otmph = uarmg;
431 1.4 christos if (uarms && (!otmph || !rn2(4)))
432 1.4 christos otmph = uarms;
433 1.4 christos return (otmph);
434 1.4 christos }
435 1.4 christos
436 1.4 christos void
437 1.4 christos corrode_armor()
438 1.4 christos {
439 1.4 christos struct obj *otmph = some_armor();
440 1.4 christos if (otmph) {
441 1.4 christos if (otmph->rustfree ||
442 1.4 christos otmph->otyp == ELVEN_CLOAK ||
443 1.4 christos otmph->otyp == LEATHER_ARMOR ||
444 1.4 christos otmph->otyp == STUDDED_LEATHER_ARMOR) {
445 1.1 cgd pline("Your %s not affected!",
446 1.4 christos aobjnam(otmph, "are"));
447 1.1 cgd return;
448 1.1 cgd }
449 1.1 cgd pline("Your %s!", aobjnam(otmph, "corrode"));
450 1.1 cgd otmph->spe--;
451 1.1 cgd }
452 1.1 cgd }
453