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