1*d060781dSmrg /* $NetBSD: hack.wield.c,v 1.8 2011/07/02 02:09:08 mrg Exp $ */
23ea4a95cSchristos
3210cab45Smycroft /*
41c7f94e5Sjsm * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
51c7f94e5Sjsm * Amsterdam
61c7f94e5Sjsm * All rights reserved.
71c7f94e5Sjsm *
81c7f94e5Sjsm * Redistribution and use in source and binary forms, with or without
91c7f94e5Sjsm * modification, are permitted provided that the following conditions are
101c7f94e5Sjsm * met:
111c7f94e5Sjsm *
121c7f94e5Sjsm * - Redistributions of source code must retain the above copyright notice,
131c7f94e5Sjsm * this list of conditions and the following disclaimer.
141c7f94e5Sjsm *
151c7f94e5Sjsm * - Redistributions in binary form must reproduce the above copyright
161c7f94e5Sjsm * notice, this list of conditions and the following disclaimer in the
171c7f94e5Sjsm * documentation and/or other materials provided with the distribution.
181c7f94e5Sjsm *
191c7f94e5Sjsm * - Neither the name of the Stichting Centrum voor Wiskunde en
201c7f94e5Sjsm * Informatica, nor the names of its contributors may be used to endorse or
211c7f94e5Sjsm * promote products derived from this software without specific prior
221c7f94e5Sjsm * written permission.
231c7f94e5Sjsm *
241c7f94e5Sjsm * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
251c7f94e5Sjsm * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
261c7f94e5Sjsm * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
271c7f94e5Sjsm * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
281c7f94e5Sjsm * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
291c7f94e5Sjsm * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
301c7f94e5Sjsm * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
311c7f94e5Sjsm * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
321c7f94e5Sjsm * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
331c7f94e5Sjsm * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
341c7f94e5Sjsm * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
351c7f94e5Sjsm */
361c7f94e5Sjsm
371c7f94e5Sjsm /*
381c7f94e5Sjsm * Copyright (c) 1982 Jay Fenlason <hack@gnu.org>
391c7f94e5Sjsm * All rights reserved.
401c7f94e5Sjsm *
411c7f94e5Sjsm * Redistribution and use in source and binary forms, with or without
421c7f94e5Sjsm * modification, are permitted provided that the following conditions
431c7f94e5Sjsm * are met:
441c7f94e5Sjsm * 1. Redistributions of source code must retain the above copyright
451c7f94e5Sjsm * notice, this list of conditions and the following disclaimer.
461c7f94e5Sjsm * 2. Redistributions in binary form must reproduce the above copyright
471c7f94e5Sjsm * notice, this list of conditions and the following disclaimer in the
481c7f94e5Sjsm * documentation and/or other materials provided with the distribution.
491c7f94e5Sjsm * 3. The name of the author may not be used to endorse or promote products
501c7f94e5Sjsm * derived from this software without specific prior written permission.
511c7f94e5Sjsm *
521c7f94e5Sjsm * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
531c7f94e5Sjsm * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
541c7f94e5Sjsm * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
551c7f94e5Sjsm * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
561c7f94e5Sjsm * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
571c7f94e5Sjsm * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
581c7f94e5Sjsm * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
591c7f94e5Sjsm * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
601c7f94e5Sjsm * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
611c7f94e5Sjsm * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62210cab45Smycroft */
63210cab45Smycroft
643ea4a95cSchristos #include <sys/cdefs.h>
65210cab45Smycroft #ifndef lint
66*d060781dSmrg __RCSID("$NetBSD: hack.wield.c,v 1.8 2011/07/02 02:09:08 mrg Exp $");
67210cab45Smycroft #endif /* not lint */
6861f28255Scgd
6961f28255Scgd #include "hack.h"
703ea4a95cSchristos #include "extern.h"
7161f28255Scgd
723ea4a95cSchristos void
setuwep(struct obj * obj)731fa8a9a6Sdholland setuwep(struct obj *obj)
743ea4a95cSchristos {
7561f28255Scgd setworn(obj, W_WEP);
7661f28255Scgd }
7761f28255Scgd
783ea4a95cSchristos int
dowield(void)791fa8a9a6Sdholland dowield(void)
8061f28255Scgd {
813ea4a95cSchristos struct obj *wep;
823ea4a95cSchristos int res = 0;
8361f28255Scgd
8461f28255Scgd multi = 0;
853ea4a95cSchristos if (!(wep = getobj("#-)", "wield"))) /* nothing */
863ea4a95cSchristos ;
8761f28255Scgd else if (uwep == wep)
8861f28255Scgd pline("You are already wielding that!");
8961f28255Scgd else if (uwep && uwep->cursed)
9061f28255Scgd pline("The %s welded to your hand!",
9161f28255Scgd aobjnam(uwep, "are"));
9261f28255Scgd else if (wep == &zeroobj) {
9361f28255Scgd if (uwep == 0) {
9461f28255Scgd pline("You are already empty handed.");
9561f28255Scgd } else {
9661f28255Scgd setuwep((struct obj *) 0);
9761f28255Scgd res++;
9861f28255Scgd pline("You are empty handed.");
9961f28255Scgd }
10061f28255Scgd } else if (uarms && wep->otyp == TWO_HANDED_SWORD)
10161f28255Scgd pline("You cannot wield a two-handed sword and wear a shield.");
10261f28255Scgd else if (wep->owornmask & (W_ARMOR | W_RING))
10361f28255Scgd pline("You cannot wield that!");
10461f28255Scgd else {
10561f28255Scgd setuwep(wep);
10661f28255Scgd res++;
10761f28255Scgd if (uwep->cursed)
10861f28255Scgd pline("The %s %s to your hand!",
10961f28255Scgd aobjnam(uwep, "weld"),
11061f28255Scgd (uwep->quan == 1) ? "itself" : "themselves"); /* a3 */
1113ea4a95cSchristos else
1123ea4a95cSchristos prinv(uwep);
11361f28255Scgd }
11461f28255Scgd return (res);
11561f28255Scgd }
11661f28255Scgd
1173ea4a95cSchristos void
corrode_weapon(void)1181fa8a9a6Sdholland corrode_weapon(void)
1193ea4a95cSchristos {
1203ea4a95cSchristos if (!uwep || uwep->olet != WEAPON_SYM)
1213ea4a95cSchristos return; /* %% */
12261f28255Scgd if (uwep->rustfree)
12361f28255Scgd pline("Your %s not affected.", aobjnam(uwep, "are"));
12461f28255Scgd else {
12561f28255Scgd pline("Your %s!", aobjnam(uwep, "corrode"));
12661f28255Scgd uwep->spe--;
12761f28255Scgd }
12861f28255Scgd }
12961f28255Scgd
1303ea4a95cSchristos int
chwepon(struct obj * otmp,int amount)1311fa8a9a6Sdholland chwepon(struct obj *otmp, int amount)
13261f28255Scgd {
133ab8b6343Sjsm const char *color = (amount < 0) ? "black" : "green";
134*d060781dSmrg const char *stime;
13561f28255Scgd if (!uwep || uwep->olet != WEAPON_SYM) {
13661f28255Scgd strange_feeling(otmp,
13761f28255Scgd (amount > 0) ? "Your hands twitch."
13861f28255Scgd : "Your hands itch.");
13961f28255Scgd return (0);
14061f28255Scgd }
14161f28255Scgd if (uwep->otyp == WORM_TOOTH && amount > 0) {
14261f28255Scgd uwep->otyp = CRYSKNIFE;
14361f28255Scgd pline("Your weapon seems sharper now.");
14461f28255Scgd uwep->cursed = 0;
14561f28255Scgd return (1);
14661f28255Scgd }
14761f28255Scgd if (uwep->otyp == CRYSKNIFE && amount < 0) {
14861f28255Scgd uwep->otyp = WORM_TOOTH;
14961f28255Scgd pline("Your weapon looks duller now.");
15061f28255Scgd return (1);
15161f28255Scgd }
15261f28255Scgd /* there is a (soft) upper limit to uwep->spe */
15361f28255Scgd if (amount > 0 && uwep->spe > 5 && rn2(3)) {
15461f28255Scgd pline("Your %s violently green for a while and then evaporate%s.",
15561f28255Scgd aobjnam(uwep, "glow"), plur(uwep->quan));
15661f28255Scgd while (uwep) /* let all of them disappear */
15761f28255Scgd /* note: uwep->quan = 1 is nogood if unpaid */
15861f28255Scgd useup(uwep);
15961f28255Scgd return (1);
16061f28255Scgd }
1613ea4a95cSchristos if (!rn2(6))
1623ea4a95cSchristos amount *= 2;
163*d060781dSmrg stime = (amount * amount == 1) ? "moment" : "while";
16461f28255Scgd pline("Your %s %s for a %s.",
165*d060781dSmrg aobjnam(uwep, "glow"), color, stime);
16661f28255Scgd uwep->spe += amount;
1673ea4a95cSchristos if (amount > 0)
1683ea4a95cSchristos uwep->cursed = 0;
16961f28255Scgd return (1);
17061f28255Scgd }
171