1*aed906e4Smestre /* $OpenBSD: hack.wield.c,v 1.7 2016/01/09 18:33:15 mestre Exp $ */
2d0b779f3Sniklas
3df930be7Sderaadt /*
4d25013f2Scamield * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
5d25013f2Scamield * Amsterdam
6d25013f2Scamield * All rights reserved.
7d25013f2Scamield *
8d25013f2Scamield * Redistribution and use in source and binary forms, with or without
9d25013f2Scamield * modification, are permitted provided that the following conditions are
10d25013f2Scamield * met:
11d25013f2Scamield *
12d25013f2Scamield * - Redistributions of source code must retain the above copyright notice,
13d25013f2Scamield * this list of conditions and the following disclaimer.
14d25013f2Scamield *
15d25013f2Scamield * - Redistributions in binary form must reproduce the above copyright
16d25013f2Scamield * notice, this list of conditions and the following disclaimer in the
17d25013f2Scamield * documentation and/or other materials provided with the distribution.
18d25013f2Scamield *
19d25013f2Scamield * - Neither the name of the Stichting Centrum voor Wiskunde en
20d25013f2Scamield * Informatica, nor the names of its contributors may be used to endorse or
21d25013f2Scamield * promote products derived from this software without specific prior
22d25013f2Scamield * written permission.
23d25013f2Scamield *
24d25013f2Scamield * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
25d25013f2Scamield * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26d25013f2Scamield * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
27d25013f2Scamield * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
28d25013f2Scamield * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29d25013f2Scamield * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30d25013f2Scamield * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31d25013f2Scamield * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32d25013f2Scamield * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33d25013f2Scamield * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34d25013f2Scamield * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35d25013f2Scamield */
36d25013f2Scamield
37d25013f2Scamield /*
38d25013f2Scamield * Copyright (c) 1982 Jay Fenlason <hack@gnu.org>
39d25013f2Scamield * All rights reserved.
40d25013f2Scamield *
41d25013f2Scamield * Redistribution and use in source and binary forms, with or without
42d25013f2Scamield * modification, are permitted provided that the following conditions
43d25013f2Scamield * are met:
44d25013f2Scamield * 1. Redistributions of source code must retain the above copyright
45d25013f2Scamield * notice, this list of conditions and the following disclaimer.
46d25013f2Scamield * 2. Redistributions in binary form must reproduce the above copyright
47d25013f2Scamield * notice, this list of conditions and the following disclaimer in the
48d25013f2Scamield * documentation and/or other materials provided with the distribution.
49d25013f2Scamield * 3. The name of the author may not be used to endorse or promote products
50d25013f2Scamield * derived from this software without specific prior written permission.
51d25013f2Scamield *
52d25013f2Scamield * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
53d25013f2Scamield * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
54d25013f2Scamield * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
55d25013f2Scamield * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
56d25013f2Scamield * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
57d25013f2Scamield * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
58d25013f2Scamield * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
59d25013f2Scamield * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
60d25013f2Scamield * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
61d25013f2Scamield * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62df930be7Sderaadt */
63df930be7Sderaadt
64df930be7Sderaadt #include "hack.h"
65*aed906e4Smestre
66df930be7Sderaadt extern struct obj zeroobj;
67df930be7Sderaadt
684a5fbbc4Spjanzen void
setuwep(struct obj * obj)694a5fbbc4Spjanzen setuwep(struct obj *obj)
704a5fbbc4Spjanzen {
71df930be7Sderaadt setworn(obj, W_WEP);
72df930be7Sderaadt }
73df930be7Sderaadt
744a5fbbc4Spjanzen int
dowield(void)75*aed906e4Smestre dowield(void)
76df930be7Sderaadt {
774a5fbbc4Spjanzen struct obj *wep;
784a5fbbc4Spjanzen int res = 0;
79df930be7Sderaadt
80df930be7Sderaadt multi = 0;
81df930be7Sderaadt if(!(wep = getobj("#-)", "wield"))) /* nothing */;
82df930be7Sderaadt else if(uwep == wep)
83df930be7Sderaadt pline("You are already wielding that!");
84df930be7Sderaadt else if(uwep && uwep->cursed)
85df930be7Sderaadt pline("The %s welded to your hand!",
86df930be7Sderaadt aobjnam(uwep, "are"));
87df930be7Sderaadt else if(wep == &zeroobj) {
88df930be7Sderaadt if(uwep == 0){
89df930be7Sderaadt pline("You are already empty handed.");
90df930be7Sderaadt } else {
91df930be7Sderaadt setuwep((struct obj *) 0);
92df930be7Sderaadt res++;
93df930be7Sderaadt pline("You are empty handed.");
94df930be7Sderaadt }
95df930be7Sderaadt } else if(uarms && wep->otyp == TWO_HANDED_SWORD)
96df930be7Sderaadt pline("You cannot wield a two-handed sword and wear a shield.");
97df930be7Sderaadt else if(wep->owornmask & (W_ARMOR | W_RING))
98df930be7Sderaadt pline("You cannot wield that!");
99df930be7Sderaadt else {
100df930be7Sderaadt setuwep(wep);
101df930be7Sderaadt res++;
102df930be7Sderaadt if(uwep->cursed)
103df930be7Sderaadt pline("The %s %s to your hand!",
104df930be7Sderaadt aobjnam(uwep, "weld"),
105df930be7Sderaadt (uwep->quan == 1) ? "itself" : "themselves"); /* a3 */
106df930be7Sderaadt else prinv(uwep);
107df930be7Sderaadt }
108df930be7Sderaadt return(res);
109df930be7Sderaadt }
110df930be7Sderaadt
1114a5fbbc4Spjanzen void
corrode_weapon(void)112*aed906e4Smestre corrode_weapon(void)
1134a5fbbc4Spjanzen {
114df930be7Sderaadt if(!uwep || uwep->olet != WEAPON_SYM) return; /* %% */
115df930be7Sderaadt if(uwep->rustfree)
116df930be7Sderaadt pline("Your %s not affected.", aobjnam(uwep, "are"));
117df930be7Sderaadt else {
118df930be7Sderaadt pline("Your %s!", aobjnam(uwep, "corrode"));
119df930be7Sderaadt uwep->spe--;
120df930be7Sderaadt }
121df930be7Sderaadt }
122df930be7Sderaadt
1234a5fbbc4Spjanzen int
chwepon(struct obj * otmp,int amount)1244a5fbbc4Spjanzen chwepon(struct obj *otmp, int amount)
125df930be7Sderaadt {
1264a5fbbc4Spjanzen char *color = (amount < 0) ? "black" : "green";
1274a5fbbc4Spjanzen char *time;
1284a5fbbc4Spjanzen
129df930be7Sderaadt if(!uwep || uwep->olet != WEAPON_SYM) {
130df930be7Sderaadt strange_feeling(otmp,
131df930be7Sderaadt (amount > 0) ? "Your hands twitch."
132df930be7Sderaadt : "Your hands itch.");
133df930be7Sderaadt return(0);
134df930be7Sderaadt }
135df930be7Sderaadt
136df930be7Sderaadt if(uwep->otyp == WORM_TOOTH && amount > 0) {
137df930be7Sderaadt uwep->otyp = CRYSKNIFE;
138df930be7Sderaadt pline("Your weapon seems sharper now.");
139df930be7Sderaadt uwep->cursed = 0;
140df930be7Sderaadt return(1);
141df930be7Sderaadt }
142df930be7Sderaadt
143df930be7Sderaadt if(uwep->otyp == CRYSKNIFE && amount < 0) {
144df930be7Sderaadt uwep->otyp = WORM_TOOTH;
145df930be7Sderaadt pline("Your weapon looks duller now.");
146df930be7Sderaadt return(1);
147df930be7Sderaadt }
148df930be7Sderaadt
149df930be7Sderaadt /* there is a (soft) upper limit to uwep->spe */
150df930be7Sderaadt if(amount > 0 && uwep->spe > 5 && rn2(3)) {
151df930be7Sderaadt pline("Your %s violently green for a while and then evaporate%s.",
152df930be7Sderaadt aobjnam(uwep, "glow"), plur(uwep->quan));
153df930be7Sderaadt while(uwep) /* let all of them disappear */
154df930be7Sderaadt /* note: uwep->quan = 1 is nogood if unpaid */
155df930be7Sderaadt useup(uwep);
156df930be7Sderaadt return(1);
157df930be7Sderaadt }
158df930be7Sderaadt if(!rn2(6)) amount *= 2;
159df930be7Sderaadt time = (amount*amount == 1) ? "moment" : "while";
160df930be7Sderaadt pline("Your %s %s for a %s.",
161df930be7Sderaadt aobjnam(uwep, "glow"), color, time);
162df930be7Sderaadt uwep->spe += amount;
163df930be7Sderaadt if(amount > 0) uwep->cursed = 0;
164df930be7Sderaadt return(1);
165df930be7Sderaadt }
166