hack.do_wear.c revision 1.7 1 1.7 dholland /* $NetBSD: hack.do_wear.c,v 1.7 2009/08/12 07:28:40 dholland 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.7 dholland __RCSID("$NetBSD: hack.do_wear.c,v 1.7 2009/08/12 07:28:40 dholland 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.7 dholland static int dorr(struct obj *);
73 1.7 dholland static int cursed(struct obj *);
74 1.7 dholland
75 1.7 dholland static void
76 1.6 dholland off_msg(struct obj *otmp)
77 1.4 christos {
78 1.1 cgd pline("You were wearing %s.", doname(otmp));
79 1.1 cgd }
80 1.1 cgd
81 1.4 christos int
82 1.6 dholland doremarm(void)
83 1.4 christos {
84 1.4 christos struct obj *otmp;
85 1.4 christos if (!uarm && !uarmh && !uarms && !uarmg) {
86 1.1 cgd pline("Not wearing any armor.");
87 1.4 christos return (0);
88 1.1 cgd }
89 1.1 cgd otmp = (!uarmh && !uarms && !uarmg) ? uarm :
90 1.1 cgd (!uarms && !uarm && !uarmg) ? uarmh :
91 1.1 cgd (!uarmh && !uarm && !uarmg) ? uarms :
92 1.1 cgd (!uarmh && !uarm && !uarms) ? uarmg :
93 1.1 cgd getobj("[", "take off");
94 1.4 christos if (!otmp)
95 1.4 christos return (0);
96 1.4 christos if (!(otmp->owornmask & (W_ARMOR - W_ARM2))) {
97 1.1 cgd pline("You can't take that off.");
98 1.4 christos return (0);
99 1.1 cgd }
100 1.4 christos if (otmp == uarmg && uwep && uwep->cursed) { /* myers@uwmacc */
101 1.4 christos pline("You seem not able to take off the gloves while holding your weapon.");
102 1.4 christos return (0);
103 1.1 cgd }
104 1.1 cgd (void) armoroff(otmp);
105 1.4 christos return (1);
106 1.1 cgd }
107 1.1 cgd
108 1.4 christos int
109 1.6 dholland doremring(void)
110 1.4 christos {
111 1.4 christos if (!uleft && !uright) {
112 1.1 cgd pline("Not wearing any ring.");
113 1.4 christos return (0);
114 1.1 cgd }
115 1.4 christos if (!uleft)
116 1.4 christos return (dorr(uright));
117 1.4 christos if (!uright)
118 1.4 christos return (dorr(uleft));
119 1.4 christos if (uleft && uright)
120 1.4 christos while (1) {
121 1.4 christos char answer;
122 1.4 christos
123 1.4 christos pline("What ring, Right or Left? [ rl?]");
124 1.4 christos if (strchr(quitchars, (answer = readchar())))
125 1.4 christos return (0);
126 1.4 christos switch (answer) {
127 1.4 christos case 'l':
128 1.4 christos case 'L':
129 1.4 christos return (dorr(uleft));
130 1.4 christos case 'r':
131 1.4 christos case 'R':
132 1.4 christos return (dorr(uright));
133 1.4 christos case '?':
134 1.4 christos (void) doprring();
135 1.4 christos /* might look at morc here %% */
136 1.4 christos }
137 1.1 cgd }
138 1.1 cgd /* NOTREACHED */
139 1.4 christos return (0);
140 1.1 cgd }
141 1.1 cgd
142 1.7 dholland static int
143 1.6 dholland dorr(struct obj *otmp)
144 1.4 christos {
145 1.4 christos if (cursed(otmp))
146 1.4 christos return (0);
147 1.1 cgd ringoff(otmp);
148 1.1 cgd off_msg(otmp);
149 1.4 christos return (1);
150 1.1 cgd }
151 1.1 cgd
152 1.7 dholland static int
153 1.6 dholland cursed(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.6 dholland armoroff(struct obj *otmp)
164 1.4 christos {
165 1.4 christos int delay = -objects[otmp->otyp].oc_delay;
166 1.4 christos if (cursed(otmp))
167 1.4 christos return (0);
168 1.1 cgd setworn((struct obj *) 0, otmp->owornmask & W_ARMOR);
169 1.4 christos if (delay) {
170 1.1 cgd nomul(delay);
171 1.4 christos switch (otmp->otyp) {
172 1.1 cgd case HELMET:
173 1.1 cgd nomovemsg = "You finished taking off your helmet.";
174 1.1 cgd break;
175 1.1 cgd case PAIR_OF_GLOVES:
176 1.1 cgd nomovemsg = "You finished taking off your gloves";
177 1.1 cgd break;
178 1.1 cgd default:
179 1.1 cgd nomovemsg = "You finished taking off your suit.";
180 1.1 cgd }
181 1.1 cgd } else {
182 1.1 cgd off_msg(otmp);
183 1.1 cgd }
184 1.4 christos return (1);
185 1.1 cgd }
186 1.1 cgd
187 1.4 christos int
188 1.6 dholland doweararm(void)
189 1.4 christos {
190 1.4 christos struct obj *otmp;
191 1.4 christos int delay;
192 1.4 christos int err = 0;
193 1.4 christos long mask = 0;
194 1.1 cgd
195 1.1 cgd otmp = getobj("[", "wear");
196 1.4 christos if (!otmp)
197 1.4 christos return (0);
198 1.4 christos if (otmp->owornmask & W_ARMOR) {
199 1.1 cgd pline("You are already wearing that!");
200 1.4 christos return (0);
201 1.1 cgd }
202 1.4 christos if (otmp->otyp == HELMET) {
203 1.4 christos if (uarmh) {
204 1.1 cgd pline("You are already wearing a helmet.");
205 1.1 cgd err++;
206 1.1 cgd } else
207 1.1 cgd mask = W_ARMH;
208 1.4 christos } else if (otmp->otyp == SHIELD) {
209 1.4 christos if (uarms)
210 1.4 christos pline("You are already wearing a shield."), err++;
211 1.4 christos if (uwep && uwep->otyp == TWO_HANDED_SWORD)
212 1.4 christos pline("You cannot wear a shield and wield a two-handed sword."), err++;
213 1.4 christos if (!err)
214 1.4 christos mask = W_ARMS;
215 1.4 christos } else if (otmp->otyp == PAIR_OF_GLOVES) {
216 1.4 christos if (uarmg) {
217 1.1 cgd pline("You are already wearing gloves.");
218 1.1 cgd err++;
219 1.4 christos } else if (uwep && uwep->cursed) {
220 1.1 cgd pline("You cannot wear gloves over your weapon.");
221 1.1 cgd err++;
222 1.1 cgd } else
223 1.1 cgd mask = W_ARMG;
224 1.1 cgd } else {
225 1.4 christos if (uarm) {
226 1.4 christos if (otmp->otyp != ELVEN_CLOAK || uarm2) {
227 1.1 cgd pline("You are already wearing some armor.");
228 1.1 cgd err++;
229 1.1 cgd }
230 1.1 cgd }
231 1.4 christos if (!err)
232 1.4 christos mask = W_ARM;
233 1.1 cgd }
234 1.4 christos if (otmp == uwep && uwep->cursed) {
235 1.4 christos if (!err++)
236 1.1 cgd pline("%s is welded to your hand.", Doname(uwep));
237 1.1 cgd }
238 1.4 christos if (err)
239 1.4 christos return (0);
240 1.1 cgd setworn(otmp, mask);
241 1.4 christos if (otmp == uwep)
242 1.1 cgd setuwep((struct obj *) 0);
243 1.1 cgd delay = -objects[otmp->otyp].oc_delay;
244 1.4 christos if (delay) {
245 1.1 cgd nomul(delay);
246 1.1 cgd nomovemsg = "You finished your dressing manoeuvre.";
247 1.1 cgd }
248 1.1 cgd otmp->known = 1;
249 1.4 christos return (1);
250 1.1 cgd }
251 1.1 cgd
252 1.4 christos int
253 1.6 dholland dowearring(void)
254 1.4 christos {
255 1.4 christos struct obj *otmp;
256 1.4 christos long mask = 0;
257 1.4 christos long oldprop;
258 1.1 cgd
259 1.4 christos if (uleft && uright) {
260 1.1 cgd pline("There are no more ring-fingers to fill.");
261 1.4 christos return (0);
262 1.1 cgd }
263 1.1 cgd otmp = getobj("=", "wear");
264 1.4 christos if (!otmp)
265 1.4 christos return (0);
266 1.4 christos if (otmp->owornmask & W_RING) {
267 1.1 cgd pline("You are already wearing that!");
268 1.4 christos return (0);
269 1.1 cgd }
270 1.4 christos if (otmp == uleft || otmp == uright) {
271 1.1 cgd pline("You are already wearing that.");
272 1.4 christos return (0);
273 1.1 cgd }
274 1.4 christos if (otmp == uwep && uwep->cursed) {
275 1.1 cgd pline("%s is welded to your hand.", Doname(uwep));
276 1.4 christos return (0);
277 1.1 cgd }
278 1.4 christos if (uleft)
279 1.4 christos mask = RIGHT_RING;
280 1.4 christos else if (uright)
281 1.4 christos mask = LEFT_RING;
282 1.4 christos else
283 1.4 christos do {
284 1.4 christos char answer;
285 1.4 christos
286 1.4 christos pline("What ring-finger, Right or Left? ");
287 1.4 christos if (strchr(quitchars, (answer = readchar())))
288 1.4 christos return (0);
289 1.4 christos switch (answer) {
290 1.4 christos case 'l':
291 1.4 christos case 'L':
292 1.4 christos mask = LEFT_RING;
293 1.4 christos break;
294 1.4 christos case 'r':
295 1.4 christos case 'R':
296 1.4 christos mask = RIGHT_RING;
297 1.4 christos break;
298 1.4 christos }
299 1.4 christos } while (!mask);
300 1.1 cgd setworn(otmp, mask);
301 1.4 christos if (otmp == uwep)
302 1.1 cgd setuwep((struct obj *) 0);
303 1.1 cgd oldprop = u.uprops[PROP(otmp->otyp)].p_flgs;
304 1.1 cgd u.uprops[PROP(otmp->otyp)].p_flgs |= mask;
305 1.4 christos switch (otmp->otyp) {
306 1.1 cgd case RIN_LEVITATION:
307 1.4 christos if (!oldprop)
308 1.4 christos float_up();
309 1.1 cgd break;
310 1.1 cgd case RIN_PROTECTION_FROM_SHAPE_CHANGERS:
311 1.1 cgd rescham();
312 1.1 cgd break;
313 1.1 cgd case RIN_GAIN_STRENGTH:
314 1.1 cgd u.ustr += otmp->spe;
315 1.1 cgd u.ustrmax += otmp->spe;
316 1.4 christos if (u.ustr > 118)
317 1.4 christos u.ustr = 118;
318 1.4 christos if (u.ustrmax > 118)
319 1.4 christos u.ustrmax = 118;
320 1.1 cgd flags.botl = 1;
321 1.1 cgd break;
322 1.1 cgd case RIN_INCREASE_DAMAGE:
323 1.1 cgd u.udaminc += otmp->spe;
324 1.1 cgd break;
325 1.1 cgd }
326 1.1 cgd prinv(otmp);
327 1.4 christos return (1);
328 1.1 cgd }
329 1.1 cgd
330 1.4 christos void
331 1.6 dholland ringoff(struct obj *obj)
332 1.1 cgd {
333 1.4 christos long mask;
334 1.1 cgd mask = obj->owornmask & W_RING;
335 1.1 cgd setworn((struct obj *) 0, obj->owornmask);
336 1.4 christos if (!(u.uprops[PROP(obj->otyp)].p_flgs & mask))
337 1.1 cgd impossible("Strange... I didnt know you had that ring.");
338 1.1 cgd u.uprops[PROP(obj->otyp)].p_flgs &= ~mask;
339 1.4 christos switch (obj->otyp) {
340 1.1 cgd case RIN_FIRE_RESISTANCE:
341 1.1 cgd /* Bad luck if the player is in hell... --jgm */
342 1.1 cgd if (!Fire_resistance && dlevel >= 30) {
343 1.1 cgd pline("The flames of Hell burn you to a crisp.");
344 1.1 cgd killer = "stupidity in hell";
345 1.1 cgd done("burned");
346 1.1 cgd }
347 1.1 cgd break;
348 1.1 cgd case RIN_LEVITATION:
349 1.4 christos if (!Levitation) { /* no longer floating */
350 1.1 cgd float_down();
351 1.1 cgd }
352 1.1 cgd break;
353 1.1 cgd case RIN_GAIN_STRENGTH:
354 1.1 cgd u.ustr -= obj->spe;
355 1.1 cgd u.ustrmax -= obj->spe;
356 1.4 christos if (u.ustr > 118)
357 1.4 christos u.ustr = 118;
358 1.4 christos if (u.ustrmax > 118)
359 1.4 christos u.ustrmax = 118;
360 1.1 cgd flags.botl = 1;
361 1.1 cgd break;
362 1.1 cgd case RIN_INCREASE_DAMAGE:
363 1.1 cgd u.udaminc -= obj->spe;
364 1.1 cgd break;
365 1.1 cgd }
366 1.1 cgd }
367 1.1 cgd
368 1.4 christos void
369 1.6 dholland find_ac(void)
370 1.4 christos {
371 1.4 christos int uac = 10;
372 1.4 christos if (uarm)
373 1.4 christos uac -= ARM_BONUS(uarm);
374 1.4 christos if (uarm2)
375 1.4 christos uac -= ARM_BONUS(uarm2);
376 1.4 christos if (uarmh)
377 1.4 christos uac -= ARM_BONUS(uarmh);
378 1.4 christos if (uarms)
379 1.4 christos uac -= ARM_BONUS(uarms);
380 1.4 christos if (uarmg)
381 1.4 christos uac -= ARM_BONUS(uarmg);
382 1.4 christos if (uleft && uleft->otyp == RIN_PROTECTION)
383 1.4 christos uac -= uleft->spe;
384 1.4 christos if (uright && uright->otyp == RIN_PROTECTION)
385 1.4 christos uac -= uright->spe;
386 1.4 christos if (uac != u.uac) {
387 1.1 cgd u.uac = uac;
388 1.1 cgd flags.botl = 1;
389 1.1 cgd }
390 1.1 cgd }
391 1.1 cgd
392 1.4 christos void
393 1.6 dholland glibr(void)
394 1.4 christos {
395 1.4 christos struct obj *otmp;
396 1.4 christos int xfl = 0;
397 1.4 christos if (!uarmg)
398 1.4 christos if (uleft || uright) {
399 1.4 christos /* Note: at present also cursed rings fall off */
400 1.4 christos pline("Your %s off your fingers.",
401 1.4 christos (uleft && uright) ? "rings slip" : "ring slips");
402 1.4 christos xfl++;
403 1.4 christos if ((otmp = uleft) != Null(obj)) {
404 1.4 christos ringoff(uleft);
405 1.4 christos dropx(otmp);
406 1.4 christos }
407 1.4 christos if ((otmp = uright) != Null(obj)) {
408 1.4 christos ringoff(uright);
409 1.4 christos dropx(otmp);
410 1.4 christos }
411 1.1 cgd }
412 1.4 christos if ((otmp = uwep) != Null(obj)) {
413 1.1 cgd /* Note: at present also cursed weapons fall */
414 1.1 cgd setuwep((struct obj *) 0);
415 1.1 cgd dropx(otmp);
416 1.1 cgd pline("Your weapon %sslips from your hands.",
417 1.4 christos xfl ? "also " : "");
418 1.1 cgd }
419 1.1 cgd }
420 1.1 cgd
421 1.4 christos struct obj *
422 1.6 dholland some_armor(void)
423 1.4 christos {
424 1.4 christos struct obj *otmph = uarm;
425 1.4 christos if (uarmh && (!otmph || !rn2(4)))
426 1.4 christos otmph = uarmh;
427 1.4 christos if (uarmg && (!otmph || !rn2(4)))
428 1.4 christos otmph = uarmg;
429 1.4 christos if (uarms && (!otmph || !rn2(4)))
430 1.4 christos otmph = uarms;
431 1.4 christos return (otmph);
432 1.4 christos }
433 1.4 christos
434 1.4 christos void
435 1.6 dholland corrode_armor(void)
436 1.4 christos {
437 1.4 christos struct obj *otmph = some_armor();
438 1.4 christos if (otmph) {
439 1.4 christos if (otmph->rustfree ||
440 1.4 christos otmph->otyp == ELVEN_CLOAK ||
441 1.4 christos otmph->otyp == LEATHER_ARMOR ||
442 1.4 christos otmph->otyp == STUDDED_LEATHER_ARMOR) {
443 1.1 cgd pline("Your %s not affected!",
444 1.4 christos aobjnam(otmph, "are"));
445 1.1 cgd return;
446 1.1 cgd }
447 1.1 cgd pline("Your %s!", aobjnam(otmph, "corrode"));
448 1.1 cgd otmph->spe--;
449 1.1 cgd }
450 1.1 cgd }
451