[BACK]Return to hack.do_wear.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / games / hack

File: [cvs.NetBSD.org] / src / games / hack / hack.do_wear.c (download)

Revision 1.5, Wed Apr 2 18:36:36 2003 UTC (21 years ago) by jsm
Branch: MAIN
CVS Tags: yamt-pf42-baseX, yamt-pf42-base4, yamt-pf42-base3, yamt-pf42-base2, yamt-pf42-base, yamt-pf42, wrstuden-revivesa-base-3, wrstuden-revivesa-base-2, wrstuden-revivesa-base-1, wrstuden-revivesa-base, wrstuden-revivesa, wrstuden-fixsa-newbase, wrstuden-fixsa-base-1, wrstuden-fixsa-base, wrstuden-fixsa, netbsd-5-base, netbsd-5-2-RELEASE, netbsd-5-2-RC1, netbsd-5-2-3-RELEASE, netbsd-5-2-2-RELEASE, netbsd-5-2-1-RELEASE, netbsd-5-2, netbsd-5-1-RELEASE, netbsd-5-1-RC4, netbsd-5-1-RC3, netbsd-5-1-RC2, netbsd-5-1-RC1, netbsd-5-1-5-RELEASE, netbsd-5-1-4-RELEASE, netbsd-5-1-3-RELEASE, netbsd-5-1-2-RELEASE, netbsd-5-1-1-RELEASE, netbsd-5-1, netbsd-5-0-RELEASE, netbsd-5-0-RC4, netbsd-5-0-RC3, netbsd-5-0-RC2, netbsd-5-0-RC1, netbsd-5-0-2-RELEASE, netbsd-5-0-1-RELEASE, netbsd-5-0, netbsd-5, netbsd-4-base, netbsd-4-0-RELEASE, netbsd-4-0-RC5, netbsd-4-0-RC4, netbsd-4-0-RC3, netbsd-4-0-RC2, netbsd-4-0-RC1, netbsd-4-0-1-RELEASE, netbsd-4-0, netbsd-4, netbsd-3-base, netbsd-3-1-RELEASE, netbsd-3-1-RC4, netbsd-3-1-RC3, netbsd-3-1-RC2, netbsd-3-1-RC1, netbsd-3-1-1-RELEASE, netbsd-3-1, netbsd-3-0-RELEASE, netbsd-3-0-RC6, netbsd-3-0-RC5, netbsd-3-0-RC4, netbsd-3-0-RC3, netbsd-3-0-RC2, netbsd-3-0-RC1, netbsd-3-0-3-RELEASE, netbsd-3-0-2-RELEASE, netbsd-3-0-1-RELEASE, netbsd-3-0, netbsd-3, netbsd-2-base, netbsd-2-1-RELEASE, netbsd-2-1-RC6, netbsd-2-1-RC5, netbsd-2-1-RC4, netbsd-2-1-RC3, netbsd-2-1-RC2, netbsd-2-1-RC1, netbsd-2-1, netbsd-2-0-base, netbsd-2-0-RELEASE, netbsd-2-0-RC5, netbsd-2-0-RC4, netbsd-2-0-RC3, netbsd-2-0-RC2, netbsd-2-0-RC1, netbsd-2-0-3-RELEASE, netbsd-2-0-2-RELEASE, netbsd-2-0-1-RELEASE, netbsd-2-0, netbsd-2, mjf-devfs2-base, mjf-devfs2, matt-nb5-pq3-base, matt-nb5-pq3, matt-nb5-mips64-u2-k2-k4-k7-k8-k9, matt-nb5-mips64-u1-k1-k5, matt-nb5-mips64-premerge-20101231, matt-nb5-mips64-premerge-20091211, matt-nb5-mips64-k15, matt-nb5-mips64, matt-nb4-mips64-k7-u2a-k9b, matt-mips64-base2, matt-mips64-base, matt-mips64, matt-armv6-prevmlocking, matt-armv6-nbase, matt-armv6-base, matt-armv6, keiichi-mipv6-base, keiichi-mipv6, jym-xensuspend-nbase, jym-xensuspend-base, jym-xensuspend, hpcarm-cleanup-nbase, hpcarm-cleanup-base, hpcarm-cleanup, cube-autoconf-base, cube-autoconf, abandoned-netbsd-4-base, abandoned-netbsd-4
Changes since 1.4: +60 -3 lines

Hack is now BSD-licensed.  Thanks to Andries Brouwer, Jay Fenlason and
CWI <http://www.cwi.nl/~aeb/games/hack/hack.html>.  Via OpenBSD.
Addresses part of PR bin/5850.

/*	$NetBSD: hack.do_wear.c,v 1.5 2003/04/02 18:36:36 jsm Exp $	*/

/*
 * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
 * Amsterdam
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 * - Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 *
 * - Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 *
 * - Neither the name of the Stichting Centrum voor Wiskunde en
 * Informatica, nor the names of its contributors may be used to endorse or
 * promote products derived from this software without specific prior
 * written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * Copyright (c) 1982 Jay Fenlason <hack@gnu.org>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: hack.do_wear.c,v 1.5 2003/04/02 18:36:36 jsm Exp $");
#endif				/* not lint */

#include "hack.h"
#include "extern.h"

void
off_msg(otmp)
	struct obj     *otmp;
{
	pline("You were wearing %s.", doname(otmp));
}

int
doremarm()
{
	struct obj     *otmp;
	if (!uarm && !uarmh && !uarms && !uarmg) {
		pline("Not wearing any armor.");
		return (0);
	}
	otmp = (!uarmh && !uarms && !uarmg) ? uarm :
		(!uarms && !uarm && !uarmg) ? uarmh :
		(!uarmh && !uarm && !uarmg) ? uarms :
		(!uarmh && !uarm && !uarms) ? uarmg :
		getobj("[", "take off");
	if (!otmp)
		return (0);
	if (!(otmp->owornmask & (W_ARMOR - W_ARM2))) {
		pline("You can't take that off.");
		return (0);
	}
	if (otmp == uarmg && uwep && uwep->cursed) {	/* myers@uwmacc */
		pline("You seem not able to take off the gloves while holding your weapon.");
		return (0);
	}
	(void) armoroff(otmp);
	return (1);
}

int
doremring()
{
	if (!uleft && !uright) {
		pline("Not wearing any ring.");
		return (0);
	}
	if (!uleft)
		return (dorr(uright));
	if (!uright)
		return (dorr(uleft));
	if (uleft && uright)
		while (1) {
			char            answer;

			pline("What ring, Right or Left? [ rl?]");
			if (strchr(quitchars, (answer = readchar())))
				return (0);
			switch (answer) {
			case 'l':
			case 'L':
				return (dorr(uleft));
			case 'r':
			case 'R':
				return (dorr(uright));
			case '?':
				(void) doprring();
				/* might look at morc here %% */
			}
		}
	/* NOTREACHED */
	return (0);
}

int
dorr(otmp)
	struct obj     *otmp;
{
	if (cursed(otmp))
		return (0);
	ringoff(otmp);
	off_msg(otmp);
	return (1);
}

int
cursed(otmp)
	struct obj     *otmp;
{
	if (otmp->cursed) {
		pline("You can't. It appears to be cursed.");
		return (1);
	}
	return (0);
}

int
armoroff(otmp)
	struct obj     *otmp;
{
	int             delay = -objects[otmp->otyp].oc_delay;
	if (cursed(otmp))
		return (0);
	setworn((struct obj *) 0, otmp->owornmask & W_ARMOR);
	if (delay) {
		nomul(delay);
		switch (otmp->otyp) {
		case HELMET:
			nomovemsg = "You finished taking off your helmet.";
			break;
		case PAIR_OF_GLOVES:
			nomovemsg = "You finished taking off your gloves";
			break;
		default:
			nomovemsg = "You finished taking off your suit.";
		}
	} else {
		off_msg(otmp);
	}
	return (1);
}

int
doweararm()
{
	struct obj     *otmp;
	int             delay;
	int             err = 0;
	long            mask = 0;

	otmp = getobj("[", "wear");
	if (!otmp)
		return (0);
	if (otmp->owornmask & W_ARMOR) {
		pline("You are already wearing that!");
		return (0);
	}
	if (otmp->otyp == HELMET) {
		if (uarmh) {
			pline("You are already wearing a helmet.");
			err++;
		} else
			mask = W_ARMH;
	} else if (otmp->otyp == SHIELD) {
		if (uarms)
			pline("You are already wearing a shield."), err++;
		if (uwep && uwep->otyp == TWO_HANDED_SWORD)
			pline("You cannot wear a shield and wield a two-handed sword."), err++;
		if (!err)
			mask = W_ARMS;
	} else if (otmp->otyp == PAIR_OF_GLOVES) {
		if (uarmg) {
			pline("You are already wearing gloves.");
			err++;
		} else if (uwep && uwep->cursed) {
			pline("You cannot wear gloves over your weapon.");
			err++;
		} else
			mask = W_ARMG;
	} else {
		if (uarm) {
			if (otmp->otyp != ELVEN_CLOAK || uarm2) {
				pline("You are already wearing some armor.");
				err++;
			}
		}
		if (!err)
			mask = W_ARM;
	}
	if (otmp == uwep && uwep->cursed) {
		if (!err++)
			pline("%s is welded to your hand.", Doname(uwep));
	}
	if (err)
		return (0);
	setworn(otmp, mask);
	if (otmp == uwep)
		setuwep((struct obj *) 0);
	delay = -objects[otmp->otyp].oc_delay;
	if (delay) {
		nomul(delay);
		nomovemsg = "You finished your dressing manoeuvre.";
	}
	otmp->known = 1;
	return (1);
}

int
dowearring()
{
	struct obj     *otmp;
	long            mask = 0;
	long            oldprop;

	if (uleft && uright) {
		pline("There are no more ring-fingers to fill.");
		return (0);
	}
	otmp = getobj("=", "wear");
	if (!otmp)
		return (0);
	if (otmp->owornmask & W_RING) {
		pline("You are already wearing that!");
		return (0);
	}
	if (otmp == uleft || otmp == uright) {
		pline("You are already wearing that.");
		return (0);
	}
	if (otmp == uwep && uwep->cursed) {
		pline("%s is welded to your hand.", Doname(uwep));
		return (0);
	}
	if (uleft)
		mask = RIGHT_RING;
	else if (uright)
		mask = LEFT_RING;
	else
		do {
			char            answer;

			pline("What ring-finger, Right or Left? ");
			if (strchr(quitchars, (answer = readchar())))
				return (0);
			switch (answer) {
			case 'l':
			case 'L':
				mask = LEFT_RING;
				break;
			case 'r':
			case 'R':
				mask = RIGHT_RING;
				break;
			}
		} while (!mask);
	setworn(otmp, mask);
	if (otmp == uwep)
		setuwep((struct obj *) 0);
	oldprop = u.uprops[PROP(otmp->otyp)].p_flgs;
	u.uprops[PROP(otmp->otyp)].p_flgs |= mask;
	switch (otmp->otyp) {
	case RIN_LEVITATION:
		if (!oldprop)
			float_up();
		break;
	case RIN_PROTECTION_FROM_SHAPE_CHANGERS:
		rescham();
		break;
	case RIN_GAIN_STRENGTH:
		u.ustr += otmp->spe;
		u.ustrmax += otmp->spe;
		if (u.ustr > 118)
			u.ustr = 118;
		if (u.ustrmax > 118)
			u.ustrmax = 118;
		flags.botl = 1;
		break;
	case RIN_INCREASE_DAMAGE:
		u.udaminc += otmp->spe;
		break;
	}
	prinv(otmp);
	return (1);
}

void
ringoff(obj)
	struct obj     *obj;
{
	long            mask;
	mask = obj->owornmask & W_RING;
	setworn((struct obj *) 0, obj->owornmask);
	if (!(u.uprops[PROP(obj->otyp)].p_flgs & mask))
		impossible("Strange... I didnt know you had that ring.");
	u.uprops[PROP(obj->otyp)].p_flgs &= ~mask;
	switch (obj->otyp) {
	case RIN_FIRE_RESISTANCE:
		/* Bad luck if the player is in hell... --jgm */
		if (!Fire_resistance && dlevel >= 30) {
			pline("The flames of Hell burn you to a crisp.");
			killer = "stupidity in hell";
			done("burned");
		}
		break;
	case RIN_LEVITATION:
		if (!Levitation) {	/* no longer floating */
			float_down();
		}
		break;
	case RIN_GAIN_STRENGTH:
		u.ustr -= obj->spe;
		u.ustrmax -= obj->spe;
		if (u.ustr > 118)
			u.ustr = 118;
		if (u.ustrmax > 118)
			u.ustrmax = 118;
		flags.botl = 1;
		break;
	case RIN_INCREASE_DAMAGE:
		u.udaminc -= obj->spe;
		break;
	}
}

void
find_ac()
{
	int             uac = 10;
	if (uarm)
		uac -= ARM_BONUS(uarm);
	if (uarm2)
		uac -= ARM_BONUS(uarm2);
	if (uarmh)
		uac -= ARM_BONUS(uarmh);
	if (uarms)
		uac -= ARM_BONUS(uarms);
	if (uarmg)
		uac -= ARM_BONUS(uarmg);
	if (uleft && uleft->otyp == RIN_PROTECTION)
		uac -= uleft->spe;
	if (uright && uright->otyp == RIN_PROTECTION)
		uac -= uright->spe;
	if (uac != u.uac) {
		u.uac = uac;
		flags.botl = 1;
	}
}

void
glibr()
{
	struct obj     *otmp;
	int             xfl = 0;
	if (!uarmg)
		if (uleft || uright) {
			/* Note: at present also cursed rings fall off */
			pline("Your %s off your fingers.",
			   (uleft && uright) ? "rings slip" : "ring slips");
			xfl++;
			if ((otmp = uleft) != Null(obj)) {
				ringoff(uleft);
				dropx(otmp);
			}
			if ((otmp = uright) != Null(obj)) {
				ringoff(uright);
				dropx(otmp);
			}
		}
	if ((otmp = uwep) != Null(obj)) {
		/* Note: at present also cursed weapons fall */
		setuwep((struct obj *) 0);
		dropx(otmp);
		pline("Your weapon %sslips from your hands.",
		      xfl ? "also " : "");
	}
}

struct obj     *
some_armor()
{
	struct obj     *otmph = uarm;
	if (uarmh && (!otmph || !rn2(4)))
		otmph = uarmh;
	if (uarmg && (!otmph || !rn2(4)))
		otmph = uarmg;
	if (uarms && (!otmph || !rn2(4)))
		otmph = uarms;
	return (otmph);
}

void
corrode_armor()
{
	struct obj     *otmph = some_armor();
	if (otmph) {
		if (otmph->rustfree ||
		    otmph->otyp == ELVEN_CLOAK ||
		    otmph->otyp == LEATHER_ARMOR ||
		    otmph->otyp == STUDDED_LEATHER_ARMOR) {
			pline("Your %s not affected!",
			      aobjnam(otmph, "are"));
			return;
		}
		pline("Your %s!", aobjnam(otmph, "corrode"));
		otmph->spe--;
	}
}