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