Source:NetHack 2.2a/do wear.c

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

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

1.   /*	SCCS Id: @(#)do_wear.c	2.0	87/09/15 2.   /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3.     4.    #include   5.    #include "hack.h"  6.    extern char *nomovemsg; 7.   extern char quitchars[]; 8.   extern char *Doname; 9.    10.   off_msg(otmp) register struct obj *otmp; { 11.  	pline("You were wearing %s.", doname(otmp)); 12.  }  13.    14.   doremarm { 15.  	register struct obj *otmp; 16.  	if(!uarm && !uarmh && !uarms && !uarmg) { 17.  		pline("Not wearing any armor."); 18.  		return(0); 19.  	}  20.   	otmp = (!uarmh && !uarms && !uarmg) ? uarm : 21.  		(!uarms && !uarm && !uarmg) ? uarmh : 22.  		(!uarmh && !uarm && !uarmg) ? uarms : 23.  		(!uarmh && !uarm && !uarms) ? uarmg : 24.  		getobj("[", "take off"); 25.  	if(!otmp) return(0); 26.  	if(!(otmp->owornmask & (W_ARMOR - W_ARM2))) { 27.  		pline("You can't take that off."); 28.  		return(0); 29.  	}  30.   	if( otmp == uarmg && uwep && uwep->cursed ) {	/* myers@uwmacc */ 31.   pline("You seem not able to take off the gloves while holding your weapon."); 32.  		return(0); 33.  	}  34.   	(void) armoroff(otmp); 35.  	return(1); 36.  }  37.    38.   doremring { 39.  	if(!uleft && !uright){ 40.  		pline("Not wearing any ring."); 41.  		return(0); 42.  	}  43.   	if(!uleft) 44.  		return(dorr(uright)); 45.  	if(!uright) 46.  		return(dorr(uleft)); 47.  	if(uleft && uright) while(1) { 48.  		char answer; 49.   50.   		pline("What ring, Right or Left? [ rl?]"); 51.  		if(index(quitchars, (answer = readchar))) 52.  			return(0); 53.  		switch(answer) { 54.  		case 'l': 55.  		case 'L': 56.  			return(dorr(uleft)); 57.  		case 'r': 58.  		case 'R': 59.  			return(dorr(uright)); 60.  		case '?': 61.  			(void) doprring; 62.  			/* might look at morc here %% */ 63.  		}  64.   	}  65.   	/* NOTREACHED */ 66.  #ifdef LINT 67.  	return(0); 68.  #endif 69.  }  70.    71.   dorr(otmp) register struct obj *otmp; { 72.  	if(cursed(otmp)) return(0); 73.  	ringoff(otmp); 74.  	off_msg(otmp); 75.  	return(1); 76.  }  77.    78.   cursed(otmp) register struct obj *otmp; { 79.  	if(otmp->cursed){ 80.  		pline("You can't. It appears to be cursed."); 81.  		return(1); 82.  	}  83.   	return(0); 84.  }  85.    86.   armoroff(otmp) register struct obj *otmp; { 87.  register int delay = -objects[otmp->otyp].oc_delay; 88.  	if(cursed(otmp)) return(0); 89.  	setworn((struct obj *) 0, otmp->owornmask & W_ARMOR); 90.  	if(delay) { 91.  		nomul(delay); 92.  		switch(otmp->otyp) { 93.  		case HELMET: 94.  			nomovemsg = "You finished taking off your helmet."; 95.  			break; 96.  		case PAIR_OF_GLOVES: 97.  			nomovemsg = "You finished taking off your gloves"; 98.  			break; 99.  		default: 100. 			nomovemsg = "You finished taking off your suit."; 101. 		}  102.  	} else { 103. 		off_msg(otmp); 104. 	}  105.  	return(1); 106. }  107.   108.  doweararm { 109. 	register struct obj *otmp; 110. 	register int delay; 111. 	register int err = 0; 112. 	long mask = 0; 113.  114.  #ifdef KAA 115. 	if(!index("@enozCGHIKLNOTUVWXYZ&",u.usym)) { 116. 		pline("Don't even bother."); 117. 		return(0); 118. 	}  119.  #endif 120. 	otmp = getobj("[", "wear"); 121. 	if(!otmp) return(0); 122. 	if(otmp->owornmask & W_ARMOR) { 123. 		pline("You are already wearing that!"); 124. 		return(0); 125. 	}  126.  	if(otmp->otyp == HELMET){ 127. 		if(uarmh) { 128. 			pline("You are already wearing a helmet."); 129. 			err++; 130. 		} else 131. 			mask = W_ARMH; 132. 	} else if(otmp->otyp == SHIELD){ 133. 		if(uarms) pline("You are already wearing a shield."), err++; 134. 		if(uwep && uwep->otyp == TWO_HANDED_SWORD) 135. 	pline("You cannot wear a shield and wield a two handed sword."), err++; 136. 		if(!err) mask = W_ARMS; 137. 	} else if(otmp->otyp == PAIR_OF_GLOVES) { 138. 		if(uarmg) { 139. 			pline("You are already wearing gloves."); 140. 			err++; 141. 		} else 142. 		if(uwep && uwep->cursed) { 143. 			pline("You cannot wear gloves over your weapon."); 144. 			err++; 145. 		} else 146. 			mask = W_ARMG; 147. 	} else { 148. #ifdef KAA 149. 		if(cantweararm(u.usym)) { 150. 			pline("You can't wear armor!"); 151. 			return(0); 152. 		}  153.  #endif 154. 		if(uarm) { 155. 			if(otmp->otyp != ELVEN_CLOAK || uarm2) { 156. 				pline("You are already wearing some armor."); 157. 				err++; 158. 			}  159.  		}  160.  		if(!err) mask = W_ARM; 161. 	}  162.  	if(welded(otmp)) { 163. 		if(!err++) 164. 			pline("%s is welded to your hand.", Doname(uwep)); 165. 	}  166.  	if(err) return(0); 167. 	setworn(otmp, mask); 168. 	if(otmp == uwep) 169. 		setuwep((struct obj *) 0); 170. 	delay = -objects[otmp->otyp].oc_delay; 171. 	if(delay){ 172. 		nomul(delay); 173. 		nomovemsg = "You finished your dressing maneuvre."; 174. 	}  175.  	otmp->known = 1; 176. 	return(1); 177. }  178.   179.  dowearring { 180. 	register struct obj *otmp; 181. 	long mask = 0; 182. 	long oldprop; 183.  184.  	if(uleft && uright){ 185. 		pline("There are no more ring-fingers to fill."); 186. 		return(0); 187. 	}  188.  	otmp = getobj("=", "wear"); 189. 	if(!otmp) return(0); 190. 	if(otmp->owornmask & W_RING) { 191. 		pline("You are already wearing that!"); 192. 		return(0); 193. 	}  194.  	if(otmp == uleft || otmp == uright) { 195. 		pline("You are already wearing that."); 196. 		return(0); 197. 	}  198.  	if(welded(otmp)) { 199. 		pline("%s is welded to your hand.", Doname(uwep)); 200. 		return(0); 201. 	}  202.  	if(uleft) mask = RIGHT_RING; 203. 	else if(uright) mask = LEFT_RING; 204. 	else do { 205. 		char answer; 206.  207.  		pline("What ring-finger, Right or Left? "); 208. 		if(index(quitchars, (answer = readchar))) 209. 			return(0); 210. 		switch(answer){ 211. 		case 'l': 212. 		case 'L': 213. 			mask = LEFT_RING; 214. 			break; 215. 		case 'r': 216. 		case 'R': 217. 			mask = RIGHT_RING; 218. 			break; 219. 		}  220.  	} while(!mask); 221. 	setworn(otmp, mask); 222. 	if(otmp == uwep) 223. 		setuwep((struct obj *) 0); 224. 	oldprop = u.uprops[PROP(otmp->otyp)].p_flgs; 225. 	u.uprops[PROP(otmp->otyp)].p_flgs |= mask; 226. 	switch(otmp->otyp){ 227. 	case RIN_LEVITATION: 228. 		if(!oldprop) float_up; 229. 		break; 230. 	case RIN_GAIN_STRENGTH: 231. 		u.ustr += otmp->spe; 232. 		u.ustrmax += otmp->spe; 233. 		if(u.ustr > 118) u.ustr = 118; 234. 		if(u.ustrmax > 118) u.ustrmax = 118; 235. 		flags.botl = 1; 236. 		break; 237. 	case RIN_INCREASE_DAMAGE: 238. 		u.udaminc += otmp->spe; 239. 		break; 240. 	case RIN_PROTECTION_FROM_SHAPE_CHAN: 241. 		rescham; 242. 		break; 243. 	}  244.  	prinv(otmp); 245. 	return(1); 246. }  247.   248.  ringoff(obj) 249. register struct obj *obj; 250. {  251.  register long mask; 252. 	mask = obj->owornmask & W_RING; 253. 	setworn((struct obj *) 0, obj->owornmask); 254. 	if(!(u.uprops[PROP(obj->otyp)].p_flgs & mask)) 255. 		impossible("Strange... I didn't know you had that ring."); 256. 	u.uprops[PROP(obj->otyp)].p_flgs &= ~mask; 257. 	switch(obj->otyp) { 258. 	case RIN_FIRE_RESISTANCE: 259. 		/* Bad luck if the player is in hell... --jgm */ 260. 		if (!Fire_resistance && dlevel >= 30) { 261. 			pline("The flames of Hell burn you to a crisp."); 262. 			killer = "stupidity in hell"; 263. 			done("burned"); 264. 		}  265.  		break; 266. 	case RIN_LEVITATION: 267. 		if(!Levitation) {	/* no longer floating */ 268. 			float_down; 269. 		}  270.  		break; 271. 	case RIN_GAIN_STRENGTH: 272. 		u.ustr -= obj->spe; 273. 		u.ustrmax -= obj->spe; 274. 		if(u.ustr > 118) u.ustr = 118; 275. 		if(u.ustrmax > 118) u.ustrmax = 118; 276. 		flags.botl = 1; 277. 		break; 278. 	case RIN_INCREASE_DAMAGE: 279. 		u.udaminc -= obj->spe; 280. 		break; 281. 	case RIN_PROTECTION_FROM_SHAPE_CHAN: 282. #ifdef DGKMOD 283. 		/* If you're no longer protected, let the chameleons 284. 		 * change shape again -dgk 285. 		 */  286.  		restartcham; 287. #endif /* DGKMOD /**/ 288. 		break; 289. 	}  290.  }  291.   292.  find_ac{ 293. register int uac = 10; 294. #ifdef KAA 295. 	if (u.mtimedone) uac = mons[u.umonnum].ac; 296. #endif 297. 	if(uarm) uac -= ARM_BONUS(uarm); 298. 	if(uarm2) uac -= ARM_BONUS(uarm2); 299. 	if(uarmh) uac -= ARM_BONUS(uarmh); 300. 	if(uarms) uac -= ARM_BONUS(uarms); 301. 	if(uarmg) uac -= ARM_BONUS(uarmg); 302. 	if(uleft && uleft->otyp == RIN_PROTECTION) uac -= uleft->spe; 303. 	if(uright && uright->otyp == RIN_PROTECTION) uac -= uright->spe; 304. #ifdef PRAYERS 305. 	if (Protection & INTRINSIC) uac -= u.ublessed; 306. #endif 307. 	if(uac != u.uac){ 308. 		u.uac = uac; 309. 		flags.botl = 1; 310. 	}  311.  }  312.   313.  glibr{ 314. register struct obj *otmp; 315. int xfl = 0; 316. 	if(!uarmg) if(uleft || uright) { 317. 		/* Note: at present also cursed rings fall off */ 318. 		/* changed 10/30/86 by GAN */ 319. 		pline("Your %s off your fingers.",  320.  #ifdef HARD  321.  			((uleft && !uleft->cursed) && (uright && !uright->cursed)) ? "rings slip" : "ring slips"); 322. #else 323. 			(uleft && uright) ? "rings slip" : "ring slips"); 324.  #endif  325.  		xfl++;  326.  		if((otmp = uleft) != Null(obj)){  327.  			ringoff(uleft);  328.  			dropx(otmp);  329.  		}  330.  		if((otmp = uright) != Null(obj)){  331.  			ringoff(uright);  332.  			dropx(otmp);  333.  		}  334.  	}  335.  	if(((otmp = uwep) != Null(obj)) 336. #ifdef HARD 337. 	   && !otmp->cursed 338. #endif 339. 	) {  340.  		/* Note: at present also cursed weapons fall */  341.  		/* changed 10/30/86 by GAN */  342.  		setuwep((struct obj *) 0);  343.  		dropx(otmp);  344.  		pline("Your weapon %sslips from your hands.", 345. 			xfl ? "also " : ""); 346.  	}  347.  }  348.   349.  struct obj *  350.  some_armor{  351.  register struct obj *otmph = uarm;  352.  	if(uarmh && (!otmph || !rn2(4))) otmph = uarmh;  353.  	if(uarmg && (!otmph || !rn2(4))) otmph = uarmg;  354.  	if(uarms && (!otmph || !rn2(4))) otmph = uarms;  355.  	return(otmph);  356.  }  357.   358.  corrode_armor{  359.  register struct obj *otmph = some_armor;  360.  	if(otmph){  361.  		if(otmph->rustfree || 362. 		   otmph->otyp == CRYSTAL_PLATE_MAIL || 363. 		   otmph->otyp == ELVEN_CLOAK || 364. 		   otmph->otyp == LEATHER_ARMOR || 365. 		   otmph->otyp == STUDDED_LEATHER_ARMOR) {  366.  			pline("Your %s not affected!", 367. 				aobjnam(otmph, "are"));  368.  			return;  369.  		}  370.  		pline("Your %s!", aobjnam(otmph, "corrode"));  371.  		otmph->spe--;  372.  	}  373.  }  374.   375.  static  376.  remarm(obj) register struct obj *obj; {  377.  	if(!obj || obj->olet != '[')  378.  		return(0);  379.  	(void) marmoroff(obj);  380.  	return(1);  381.  }  382.   383.  static  384.  marmoroff(otmp) register struct obj *otmp; {  385.  register int delay = -objects[otmp->otyp].oc_delay;  386.  	if(cursed(otmp)) return(0);  387.  	setworn((struct obj *) 0, otmp->owornmask & W_ARMOR);  388.  	if(delay)  389.  		nomul(delay);  390.  	off_msg(otmp);  391.  	nomovemsg = "You finished taking off your armor.";  392.  	return(1);  393.  }  394.   395.  doddoremarm {  396.  	return(ggetobj("take off",remarm,0));  397.  }