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