Source:NetHack 2.3e/do wear.c

From NetHackWiki
Revision as of 03:11, 4 March 2008 by Kernigh bot (talk | contribs) (NetHack 2.3e/do wear.c moved to Source:NetHack 2.3e/do wear.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 do_wear.c from the source code of NetHack 2.3e. To link to a particular line, write [[NetHack 2.3e/do_wear.c#line123]], for example.

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

Screenshots and source code from Hack are used under the CWI license.

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