Source:NetHack 1.3d/do wear.c

Below is the full text to do_wear.c from the source code of NetHack 1.3d. To link to a particular line, write [[NetHack 1.3d/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	1.3	87/07/14 2.   /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3.    /* do_wear.c - version 1.0.3 */ 4.    5.    #include   6.    #include "hack.h"  7.    extern char *nomovemsg; 8.   extern char quitchars[]; 9.   extern char *Doname; 10.   11.   off_msg(otmp) register struct obj *otmp; { 12.  	pline("You were wearing %s.", doname(otmp)); 13.  }  14.    15.   doremarm { 16.  	register struct obj *otmp; 17.  	if(!uarm && !uarmh && !uarms && !uarmg) { 18.  		pline("Not wearing any armor."); 19.  		return(0); 20.  	}  21.   	otmp = (!uarmh && !uarms && !uarmg) ? uarm : 22.  		(!uarms && !uarm && !uarmg) ? uarmh : 23.  		(!uarmh && !uarm && !uarmg) ? uarms : 24.  		(!uarmh && !uarm && !uarms) ? uarmg : 25.  		getobj("[", "take off"); 26.  	if(!otmp) return(0); 27.  	if(!(otmp->owornmask & (W_ARMOR - W_ARM2))) { 28.  		pline("You can't take that off."); 29.  		return(0); 30.  	}  31.   	if( otmp == uarmg && uwep && uwep->cursed ) {	/* myers@uwmacc */ 32.   pline("You seem not able to take off the gloves while holding your weapon."); 33.  		return(0); 34.  	}  35.   	(void) armoroff(otmp); 36.  	return(1); 37.  }  38.    39.   doremring { 40.  	if(!uleft && !uright){ 41.  		pline("Not wearing any ring."); 42.  		return(0); 43.  	}  44.   	if(!uleft) 45.  		return(dorr(uright)); 46.  	if(!uright) 47.  		return(dorr(uleft)); 48.  	if(uleft && uright) while(1) { 49.  		char answer; 50.   51.   		pline("What ring, Right or Left? [ rl?]"); 52.  		if(index(quitchars, (answer = readchar))) 53.  			return(0); 54.  		switch(answer) { 55.  		case 'l': 56.  		case 'L': 57.  			return(dorr(uleft)); 58.  		case 'r': 59.  		case 'R': 60.  			return(dorr(uright)); 61.  		case '?': 62.  			(void) doprring; 63.  			/* might look at morc here %% */ 64.  		}  65.   	}  66.   	/* NOTREACHED */ 67.  #ifdef lint 68.  	return(0); 69.  #endif 70.  }  71.    72.   dorr(otmp) register struct obj *otmp; { 73.  	if(cursed(otmp)) return(0); 74.  	ringoff(otmp); 75.  	off_msg(otmp); 76.  	return(1); 77.  }  78.    79.   cursed(otmp) register struct obj *otmp; { 80.  	if(otmp->cursed){ 81.  		pline("You can't. It appears to be cursed."); 82.  		return(1); 83.  	}  84.   	return(0); 85.  }  86.    87.   armoroff(otmp) register struct obj *otmp; { 88.  register int delay = -objects[otmp->otyp].oc_delay; 89.  	if(cursed(otmp)) return(0); 90.  	setworn((struct obj *) 0, otmp->owornmask & W_ARMOR); 91.  	if(delay) { 92.  		nomul(delay); 93.  		switch(otmp->otyp) { 94.  		case HELMET: 95.  			nomovemsg = "You finished taking off your helmet."; 96.  			break; 97.  		case PAIR_OF_GLOVES: 98.  			nomovemsg = "You finished taking off your gloves"; 99.  			break; 100. 		default: 101. 			nomovemsg = "You finished taking off your suit."; 102. 		}  103.  	} else { 104. 		off_msg(otmp); 105. 	}  106.  	return(1); 107. }  108.   109.  doweararm { 110. 	register struct obj *otmp; 111. 	register int delay; 112. 	register int err = 0; 113. 	long mask = 0; 114.  115.  #ifdef KAA 116. 	if(!index("@enozCGHIKLNOTUVWXYZ&",u.usym)) { 117. 		pline("Don't even bother."); 118. 		return(0); 119. 	}  120.  #endif 121. 	otmp = getobj("[", "wear"); 122. 	if(!otmp) return(0); 123. 	if(otmp->owornmask & W_ARMOR) { 124. 		pline("You are already wearing that!"); 125. 		return(0); 126. 	}  127.  	if(otmp->otyp == HELMET){ 128. 		if(uarmh) { 129. 			pline("You are already wearing a helmet."); 130. 			err++; 131. 		} else 132. 			mask = W_ARMH; 133. 	} else if(otmp->otyp == SHIELD){ 134. 		if(uarms) pline("You are already wearing a shield."), err++; 135. 		if(uwep && uwep->otyp == TWO_HANDED_SWORD) 136. 	pline("You cannot wear a shield and wield a two handed sword."), err++; 137. 		if(!err) mask = W_ARMS; 138. 	} else if(otmp->otyp == PAIR_OF_GLOVES) { 139. 		if(uarmg) { 140. 			pline("You are already wearing gloves."); 141. 			err++; 142. 		} else 143. 		if(uwep && uwep->cursed) { 144. 			pline("You cannot wear gloves over your weapon."); 145. 			err++; 146. 		} else 147. 			mask = W_ARMG; 148. 	} else { 149. #ifdef KAA 150. 		if(cantweararm(u.usym)) { 151. 			pline("You can't wear armor!"); 152. 			return(0); 153. 		}  154.  #endif 155. 		if(uarm) { 156. 			if(otmp->otyp != ELVEN_CLOAK || uarm2) { 157. 				pline("You are already wearing some armor."); 158. 				err++; 159. 			}  160.  		}  161.  		if(!err) mask = W_ARM; 162. 	}  163.  	if(welded(otmp)) { 164. 		if(!err++) 165. 			pline("%s is welded to your hand.", Doname(uwep)); 166. 	}  167.  	if(err) return(0); 168. 	setworn(otmp, mask); 169. 	if(otmp == uwep) 170. 		setuwep((struct obj *) 0); 171. 	delay = -objects[otmp->otyp].oc_delay; 172. 	if(delay){ 173. 		nomul(delay); 174. 		nomovemsg = "You finished your dressing manoeuvre."; 175. 	}  176.  	otmp->known = 1; 177. 	return(1); 178. }  179.   180.  dowearring { 181. 	register struct obj *otmp; 182. 	long mask = 0; 183. 	long oldprop; 184.  185.  	if(uleft && uright){ 186. 		pline("There are no more ring-fingers to fill."); 187. 		return(0); 188. 	}  189.  	otmp = getobj("=", "wear"); 190. 	if(!otmp) return(0); 191. 	if(otmp->owornmask & W_RING) { 192. 		pline("You are already wearing that!"); 193. 		return(0); 194. 	}  195.  	if(otmp == uleft || otmp == uright) { 196. 		pline("You are already wearing that."); 197. 		return(0); 198. 	}  199.  	if(welded(otmp)) { 200. 		pline("%s is welded to your hand.", Doname(uwep)); 201. 		return(0); 202. 	}  203.  	if(uleft) mask = RIGHT_RING; 204. 	else if(uright) mask = LEFT_RING; 205. 	else do { 206. 		char answer; 207.  208.  		pline("What ring-finger, Right or Left? "); 209. 		if(index(quitchars, (answer = readchar))) 210. 			return(0); 211. 		switch(answer){ 212. 		case 'l': 213. 		case 'L': 214. 			mask = LEFT_RING; 215. 			break; 216. 		case 'r': 217. 		case 'R': 218. 			mask = RIGHT_RING; 219. 			break; 220. 		}  221.  	} while(!mask); 222. 	setworn(otmp, mask); 223. 	if(otmp == uwep) 224. 		setuwep((struct obj *) 0); 225. 	oldprop = u.uprops[PROP(otmp->otyp)].p_flgs; 226. 	u.uprops[PROP(otmp->otyp)].p_flgs |= mask; 227. 	switch(otmp->otyp){ 228. 	case RIN_LEVITATION: 229. 		if(!oldprop) float_up; 230. 		break; 231. 	case RIN_GAIN_STRENGTH: 232. 		u.ustr += otmp->spe; 233. 		u.ustrmax += otmp->spe; 234. 		if(u.ustr > 118) u.ustr = 118; 235. 		if(u.ustrmax > 118) u.ustrmax = 118; 236. 		flags.botl = 1; 237. 		break; 238. 	case RIN_INCREASE_DAMAGE: 239. 		u.udaminc += otmp->spe; 240. 		break; 241. 	case RIN_PROTECTION_FROM_SHAPE_CHAN: 242. #ifdef DGKMOD 243. 		/* If you're no longer protected, let the chameleons 244. 		 * change shape again -dgk 245. 		 */  246.  		restartcham; 247. #else 248. 		rescham; 249. #endif /* DGKMOD /**/ 250. 		break; 251. 	}  252.  	prinv(otmp); 253. 	return(1); 254. }  255.   256.  ringoff(obj) 257. register struct obj *obj; 258. {  259.  register long mask; 260. 	mask = obj->owornmask & W_RING; 261. 	setworn((struct obj *) 0, obj->owornmask); 262. 	if(!(u.uprops[PROP(obj->otyp)].p_flgs & mask)) 263. 		impossible("Strange... I didnt know you had that ring."); 264. 	u.uprops[PROP(obj->otyp)].p_flgs &= ~mask; 265. 	switch(obj->otyp) { 266. 	case RIN_FIRE_RESISTANCE: 267. 		/* Bad luck if the player is in hell... --jgm */ 268. 		if (!Fire_resistance && dlevel >= 30) { 269. 			pline("The flames of Hell burn you to a crisp."); 270. 			killer = "stupidity in hell"; 271. 			done("burned"); 272. 		}  273.  		break; 274. 	case RIN_LEVITATION: 275. 		if(!Levitation) {	/* no longer floating */ 276. 			float_down; 277. 		}  278.  		break; 279. 	case RIN_GAIN_STRENGTH: 280. 		u.ustr -= obj->spe; 281. 		u.ustrmax -= obj->spe; 282. 		if(u.ustr > 118) u.ustr = 118; 283. 		if(u.ustrmax > 118) u.ustrmax = 118; 284. 		flags.botl = 1; 285. 		break; 286. 	case RIN_INCREASE_DAMAGE: 287. 		u.udaminc -= obj->spe; 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.  }