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