Home | History | Annotate | Line # | Download | only in hack
hack.wield.c revision 1.4
      1  1.4  christos /*	$NetBSD: hack.wield.c,v 1.4 1997/10/19 16:59:27 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.wield.c,v 1.4 1997/10/19 16:59:27 christos Exp $");
     10  1.4  christos #endif				/* not lint */
     11  1.1       cgd 
     12  1.4  christos #include "hack.h"
     13  1.4  christos #include "extern.h"
     14  1.1       cgd 
     15  1.4  christos void
     16  1.4  christos setuwep(obj)
     17  1.4  christos 	struct obj     *obj;
     18  1.4  christos {
     19  1.1       cgd 	setworn(obj, W_WEP);
     20  1.1       cgd }
     21  1.1       cgd 
     22  1.4  christos int
     23  1.1       cgd dowield()
     24  1.1       cgd {
     25  1.4  christos 	struct obj     *wep;
     26  1.4  christos 	int             res = 0;
     27  1.1       cgd 
     28  1.1       cgd 	multi = 0;
     29  1.4  christos 	if (!(wep = getobj("#-)", "wield")))	/* nothing */
     30  1.4  christos 		;
     31  1.4  christos 	else if (uwep == wep)
     32  1.1       cgd 		pline("You are already wielding that!");
     33  1.4  christos 	else if (uwep && uwep->cursed)
     34  1.1       cgd 		pline("The %s welded to your hand!",
     35  1.4  christos 		      aobjnam(uwep, "are"));
     36  1.4  christos 	else if (wep == &zeroobj) {
     37  1.4  christos 		if (uwep == 0) {
     38  1.1       cgd 			pline("You are already empty handed.");
     39  1.1       cgd 		} else {
     40  1.1       cgd 			setuwep((struct obj *) 0);
     41  1.1       cgd 			res++;
     42  1.1       cgd 			pline("You are empty handed.");
     43  1.1       cgd 		}
     44  1.4  christos 	} else if (uarms && wep->otyp == TWO_HANDED_SWORD)
     45  1.4  christos 		pline("You cannot wield a two-handed sword and wear a shield.");
     46  1.4  christos 	else if (wep->owornmask & (W_ARMOR | W_RING))
     47  1.1       cgd 		pline("You cannot wield that!");
     48  1.1       cgd 	else {
     49  1.1       cgd 		setuwep(wep);
     50  1.1       cgd 		res++;
     51  1.4  christos 		if (uwep->cursed)
     52  1.4  christos 			pline("The %s %s to your hand!",
     53  1.4  christos 			      aobjnam(uwep, "weld"),
     54  1.4  christos 			      (uwep->quan == 1) ? "itself" : "themselves");	/* a3 */
     55  1.4  christos 		else
     56  1.4  christos 			prinv(uwep);
     57  1.1       cgd 	}
     58  1.4  christos 	return (res);
     59  1.1       cgd }
     60  1.1       cgd 
     61  1.4  christos void
     62  1.4  christos corrode_weapon()
     63  1.4  christos {
     64  1.4  christos 	if (!uwep || uwep->olet != WEAPON_SYM)
     65  1.4  christos 		return;		/* %% */
     66  1.4  christos 	if (uwep->rustfree)
     67  1.1       cgd 		pline("Your %s not affected.", aobjnam(uwep, "are"));
     68  1.1       cgd 	else {
     69  1.1       cgd 		pline("Your %s!", aobjnam(uwep, "corrode"));
     70  1.1       cgd 		uwep->spe--;
     71  1.1       cgd 	}
     72  1.1       cgd }
     73  1.1       cgd 
     74  1.4  christos int
     75  1.4  christos chwepon(otmp, amount)
     76  1.4  christos 	struct obj     *otmp;
     77  1.4  christos 	int amount;
     78  1.1       cgd {
     79  1.4  christos 	char           *color = (amount < 0) ? "black" : "green";
     80  1.4  christos 	char           *time;
     81  1.4  christos 	if (!uwep || uwep->olet != WEAPON_SYM) {
     82  1.1       cgd 		strange_feeling(otmp,
     83  1.4  christos 				(amount > 0) ? "Your hands twitch."
     84  1.4  christos 				: "Your hands itch.");
     85  1.4  christos 		return (0);
     86  1.1       cgd 	}
     87  1.4  christos 	if (uwep->otyp == WORM_TOOTH && amount > 0) {
     88  1.1       cgd 		uwep->otyp = CRYSKNIFE;
     89  1.1       cgd 		pline("Your weapon seems sharper now.");
     90  1.1       cgd 		uwep->cursed = 0;
     91  1.4  christos 		return (1);
     92  1.1       cgd 	}
     93  1.4  christos 	if (uwep->otyp == CRYSKNIFE && amount < 0) {
     94  1.1       cgd 		uwep->otyp = WORM_TOOTH;
     95  1.1       cgd 		pline("Your weapon looks duller now.");
     96  1.4  christos 		return (1);
     97  1.1       cgd 	}
     98  1.1       cgd 	/* there is a (soft) upper limit to uwep->spe */
     99  1.4  christos 	if (amount > 0 && uwep->spe > 5 && rn2(3)) {
    100  1.4  christos 		pline("Your %s violently green for a while and then evaporate%s.",
    101  1.4  christos 		      aobjnam(uwep, "glow"), plur(uwep->quan));
    102  1.4  christos 		while (uwep)	/* let all of them disappear */
    103  1.4  christos 			/* note: uwep->quan = 1 is nogood if unpaid */
    104  1.4  christos 			useup(uwep);
    105  1.4  christos 		return (1);
    106  1.4  christos 	}
    107  1.4  christos 	if (!rn2(6))
    108  1.4  christos 		amount *= 2;
    109  1.4  christos 	time = (amount * amount == 1) ? "moment" : "while";
    110  1.1       cgd 	pline("Your %s %s for a %s.",
    111  1.4  christos 	      aobjnam(uwep, "glow"), color, time);
    112  1.1       cgd 	uwep->spe += amount;
    113  1.4  christos 	if (amount > 0)
    114  1.4  christos 		uwep->cursed = 0;
    115  1.4  christos 	return (1);
    116  1.1       cgd }
    117