Source:NetHack 3.0.0/wield.c

From NetHackWiki
Revision as of 05:49, 4 March 2008 by Kernigh bot (talk | contribs) (NetHack 3.0.0/wield.c moved to Source:NetHack 3.0.0/wield.c: Robot: moved page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Below is the full text to wield.c from the source code of NetHack 3.0.0. To link to a particular line, write [[NetHack 3.0.0/wield.c#line123]], for example.

Warning! This is the source code from an old release. For the latest release, see Source code

The NetHack General Public License applies to screenshots, source code and other content from NetHack.

This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.

1.    /*	SCCS Id: @(#)wield.c	3.0	87/05/10
2.    /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3.    /* NetHack may be freely redistributed.  See license for details. */
4.    
5.    #include	"hack.h"
6.    
7.    /* Note: setuwep() with a null obj, and uwepgone(), are NOT the same!  Sometimes
8.     * unwielding a weapon can kill you, and lifesaving will then put it back into
9.     * your hand.  If lifesaving is permitted to do this, use
10.    * setwuep((struct obj *)0); otherwise use uwepgone().
11.    * (The second function should probably be #ifdef NAMED_ITEMS since only then
12.    * may unwielding a weapon kill you, but...)
13.    */
14.   void
15.   setuwep(obj)
16.   register struct obj *obj;
17.   {
18.   	setworn(obj, W_WEP);
19.   	if (!obj) unweapon = TRUE;	/* for "bare hands" message */
20.   }
21.   
22.   void
23.   uwepgone()
24.   {
25.   	if (uwep) {
26.   		setnotworn(uwep);
27.   		unweapon = TRUE;
28.   	}
29.   }
30.   
31.   static const char wield_objs[] = { '#', '-', WEAPON_SYM, 0 };
32.   
33.   int
34.   dowield()
35.   {
36.   	register struct obj *wep;
37.   	register int res = 0;
38.   
39.   	multi = 0;
40.   #ifdef POLYSELF
41.   	if (cantwield(uasmon)) {
42.   		pline("Don't be ridiculous!");
43.   		return(0);
44.   	}
45.   #endif
46.   	if(!(wep = getobj(wield_objs, "wield"))) /* nothing */;
47.   	else if(uwep == wep)
48.   		You("are already wielding that!");
49.   	else if(welded(uwep))
50.   		weldmsg(uwep, TRUE);
51.   	else if(wep == &zeroobj) {
52.   	    if(uwep == 0)
53.   		You("are already empty %s.", body_part(HANDED));
54.   	    else  {
55.   	  	You("are empty %s.", body_part(HANDED));
56.   	  	setuwep((struct obj *) 0);
57.   	  	res++;
58.   	    }
59.   	} else if(!uarmg &&
60.   #ifdef POLYSELF
61.   		!resists_ston(uasmon) &&
62.   #endif
63.   		(wep->otyp == CORPSE && wep->corpsenm == PM_COCKATRICE)) {
64.   	    /* Prevent wielding cockatrice when not wearing gloves --KAA */
65.   	    You("wield the cockatrice corpse in your bare %s.",
66.   			makeplural(body_part(HAND)));
67.   	    You("turn to stone...");
68.   	    killer="cockatrice corpse";
69.   	    done("stoned");
70.   	} else if(uarms && bimanual(wep))
71.   	    You("cannot wield a two-handed %s and hold a shield.",
72.   		 is_sword(wep) ? "sword" : "weapon");
73.   	else if(wep->owornmask & (W_ARMOR | W_RING | W_AMUL | W_TOOL))
74.   		You("cannot wield that!");
75.   	else {
76.   		res++;
77.   		if(wep->cursed && (wep->olet == WEAPON_SYM ||
78.   			wep->otyp == HEAVY_IRON_BALL || wep->otyp == PICK_AXE ||
79.   			wep->otyp == TIN_OPENER)) {
80.   		    pline("The %s %s to your %s!",
81.   			aobjnam(wep, "weld"),
82.   			(wep->quan == 1) ? "itself" : "themselves", /* a3 */
83.   			body_part(HAND));
84.   		    wep->bknown = 1;
85.   		} else {
86.   			/* The message must be printed before setuwep (since
87.   			 * you might die and be revived from changing weapons),
88.   			 * and the message must be before the death message and
89.   			 * Lifesaved rewielding.  Yet we want the message to say
90.   			 * "weapon in hand", thus this kludge.
91.   			 */
92.   			long dummy = wep->owornmask;
93.   			wep->owornmask |= W_WEP;
94.   			prinv(wep);
95.   			wep->owornmask = dummy;
96.   		}
97.   		setuwep(wep);
98.   	}
99.   	if(res && uwep)
100.  		unweapon = (uwep->otyp >= BOW || uwep->otyp <= BOOMERANG) ?
101.  		TRUE : FALSE;
102.  	return(res);
103.  }
104.  
105.  void
106.  corrode_weapon(){
107.  	if(!uwep || uwep->olet != WEAPON_SYM) return;	/* %% */
108.  	if(uwep->rustfree || objects[uwep->otyp].oc_material != METAL)
109.  		Your("%s not affected.", aobjnam(uwep, "are"));
110.  	else if (uwep->spe > -6) {
111.  		Your("%s!", aobjnam(uwep, "corrode"));
112.  		uwep->spe--;
113.  	} else	Your("%s quite rusted now.", aobjnam(uwep, "look"));
114.  }
115.  
116.  int
117.  chwepon(otmp, amount)
118.  register struct obj *otmp;
119.  register int amount;
120.  {
121.  	register const char *color = Hallucination ? hcolor() :
122.  				     (amount < 0) ? black : blue;
123.  	register char *xtime;
124.  
125.  	if(!uwep || (uwep->olet != WEAPON_SYM && uwep->otyp != PICK_AXE)) {
126.  		char buf[36];
127.  
128.  		Sprintf(buf, "Your %s %s.", makeplural(body_part(HAND)),
129.  			(amount > 0) ? "twitch" : "itch");
130.  		strange_feeling(otmp, buf);
131.  		return(0);
132.  	}
133.  
134.  #ifdef WORM
135.  	if(uwep->otyp == WORM_TOOTH && amount > 0) {
136.  		uwep->otyp = CRYSKNIFE;
137.  		Your("weapon seems sharper now.");
138.  		uwep->cursed = 0;
139.  		return(1);
140.  	}
141.  
142.  	if(uwep->otyp == CRYSKNIFE && amount < 0) {
143.  		uwep->otyp = WORM_TOOTH;
144.  		Your("weapon looks duller now.");
145.  		return(1);
146.  	}
147.  #endif
148.  #ifdef NAMED_ITEMS
149.  	if(is_artifact(uwep) && restr_name(uwep, ONAME(uwep)) &&
150.  		amount<0) {
151.  	    if (!Blind)
152.  		Your("%s faintly %s.", aobjnam(uwep, "glow"), color);
153.  	    return(1);
154.  	}
155.  #endif
156.  	/* there is a (soft) upper and lower limit to uwep->spe */
157.  	if(abs(uwep->spe) > 5 && rn2(3)) {
158.  	    if (!Blind)
159.  	    Your("%s violently %s for a while and then evaporate%s.",
160.  		aobjnam(uwep,"glow"), color, uwep->quan == 1 ? "s" : "");
161.  	    else
162.  		Your("%s.", aobjnam(uwep, "evaporate"));
163.  
164.  	    while(uwep)		/* let all of them disappear */
165.  				/* note: uwep->quan = 1 is nogood if unpaid */
166.  		useup(uwep);
167.  	    return(1);
168.  	}
169.  	if (!Blind) {
170.  	    xtime = (amount*amount == 1) ? "moment" : "while";
171.  	    Your("%s %s for a %s.",
172.  		  aobjnam(uwep, "glow"), color, xtime);
173.  	}
174.  	uwep->spe += amount;
175.  	if(amount > 0) uwep->cursed = 0;
176.  	return(1);
177.  }
178.  
179.  int
180.  welded(obj)
181.  register struct obj *obj;
182.  {
183.  	if (obj && obj == uwep && obj->cursed &&
184.  		  (obj->olet == WEAPON_SYM || obj->otyp == HEAVY_IRON_BALL ||
185.  		   obj->otyp == TIN_OPENER || obj->otyp == PICK_AXE))
186.  	{
187.  		obj->bknown = 1;
188.  		return 1;
189.  	}
190.  	return 0;
191.  }
192.  
193.  /* The reason for "specific" is historical; some parts of the code used
194.   * the object name and others just used "weapon"/"sword".  This function
195.   * replaced all of those.  Which one we use is really arbitrary.
196.   */
197.  void
198.  weldmsg(obj, specific)
199.  register struct obj *obj;
200.  boolean specific;
201.  {
202.  	char buf[BUFSZ];
203.  
204.  	if (specific) {
205.  		long savewornmask = obj->owornmask;
206.  		obj->owornmask &= ~W_WEP;
207.  		Strcpy(buf, Doname2(obj));
208.  		obj->owornmask = savewornmask;
209.  	} else
210.  		Sprintf(buf, "Your %s%s",
211.  			is_sword(obj) ? "sword" : "weapon",
212.  			((obj->quan > 1) ? "s" : ""));
213.  	Strcat(buf, (obj->quan==1) ? " is" : " are");
214.  #ifdef POLYSELF
215.  	Sprintf(eos(buf), " welded to your %s!",
216.  		bimanual(obj) ? makeplural(body_part(HAND)) : body_part(HAND));
217.  #else
218.  	Sprintf(eos(buf), " welded to your hand%s!",
219.  		bimanual(obj) ? "s" : "");
220.  #endif
221.  	pline(buf);
222.  }