hack.do_wear.c revision 1.3
1/*	$OpenBSD: hack.do_wear.c,v 1.3 2001/01/28 23:41:43 niklas Exp $	*/
2
3/*
4 * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
5 */
6
7#ifndef lint
8static char rcsid[] = "$OpenBSD: hack.do_wear.c,v 1.3 2001/01/28 23:41:43 niklas Exp $";
9#endif /* not lint */
10
11#include "hack.h"
12#include <stdio.h>
13extern char *nomovemsg;
14extern char quitchars[];
15extern char *Doname();
16
17off_msg(otmp) register struct obj *otmp; {
18	pline("You were wearing %s.", doname(otmp));
19}
20
21doremarm() {
22	register struct obj *otmp;
23	if(!uarm && !uarmh && !uarms && !uarmg) {
24		pline("Not wearing any armor.");
25		return(0);
26	}
27	otmp = (!uarmh && !uarms && !uarmg) ? uarm :
28		(!uarms && !uarm && !uarmg) ? uarmh :
29		(!uarmh && !uarm && !uarmg) ? uarms :
30		(!uarmh && !uarm && !uarms) ? uarmg :
31		getobj("[", "take off");
32	if(!otmp) return(0);
33	if(!(otmp->owornmask & (W_ARMOR - W_ARM2))) {
34		pline("You can't take that off.");
35		return(0);
36	}
37	if( otmp == uarmg && uwep && uwep->cursed ) {	/* myers@uwmacc */
38 pline("You seem not able to take off the gloves while holding your weapon.");
39		return(0);
40	}
41	(void) armoroff(otmp);
42	return(1);
43}
44
45doremring() {
46	if(!uleft && !uright){
47		pline("Not wearing any ring.");
48		return(0);
49	}
50	if(!uleft)
51		return(dorr(uright));
52	if(!uright)
53		return(dorr(uleft));
54	if(uleft && uright) while(1) {
55		char answer;
56
57		pline("What ring, Right or Left? [ rl?]");
58		if(strchr(quitchars, (answer = readchar())))
59			return(0);
60		switch(answer) {
61		case 'l':
62		case 'L':
63			return(dorr(uleft));
64		case 'r':
65		case 'R':
66			return(dorr(uright));
67		case '?':
68			(void) doprring();
69			/* might look at morc here %% */
70		}
71	}
72	/* NOTREACHED */
73#ifdef lint
74	return(0);
75#endif lint
76}
77
78dorr(otmp) register struct obj *otmp; {
79	if(cursed(otmp)) return(0);
80	ringoff(otmp);
81	off_msg(otmp);
82	return(1);
83}
84
85cursed(otmp) register struct obj *otmp; {
86	if(otmp->cursed){
87		pline("You can't. It appears to be cursed.");
88		return(1);
89	}
90	return(0);
91}
92
93armoroff(otmp) register struct obj *otmp; {
94register int delay = -objects[otmp->otyp].oc_delay;
95	if(cursed(otmp)) return(0);
96	setworn((struct obj *) 0, otmp->owornmask & W_ARMOR);
97	if(delay) {
98		nomul(delay);
99		switch(otmp->otyp) {
100		case HELMET:
101			nomovemsg = "You finished taking off your helmet.";
102			break;
103		case PAIR_OF_GLOVES:
104			nomovemsg = "You finished taking off your gloves";
105			break;
106		default:
107			nomovemsg = "You finished taking off your suit.";
108		}
109	} else {
110		off_msg(otmp);
111	}
112	return(1);
113}
114
115doweararm() {
116	register struct obj *otmp;
117	register int delay;
118	register int err = 0;
119	long mask = 0;
120
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		if(uarm) {
150			if(otmp->otyp != ELVEN_CLOAK || uarm2) {
151				pline("You are already wearing some armor.");
152				err++;
153			}
154		}
155		if(!err) mask = W_ARM;
156	}
157	if(otmp == uwep && uwep->cursed) {
158		if(!err++)
159			pline("%s is welded to your hand.", Doname(uwep));
160	}
161	if(err) return(0);
162	setworn(otmp, mask);
163	if(otmp == uwep)
164		setuwep((struct obj *) 0);
165	delay = -objects[otmp->otyp].oc_delay;
166	if(delay){
167		nomul(delay);
168		nomovemsg = "You finished your dressing manoeuvre.";
169	}
170	otmp->known = 1;
171	return(1);
172}
173
174dowearring() {
175	register struct obj *otmp;
176	long mask = 0;
177	long oldprop;
178
179	if(uleft && uright){
180		pline("There are no more ring-fingers to fill.");
181		return(0);
182	}
183	otmp = getobj("=", "wear");
184	if(!otmp) return(0);
185	if(otmp->owornmask & W_RING) {
186		pline("You are already wearing that!");
187		return(0);
188	}
189	if(otmp == uleft || otmp == uright) {
190		pline("You are already wearing that.");
191		return(0);
192	}
193	if(otmp == uwep && uwep->cursed) {
194		pline("%s is welded to your hand.", Doname(uwep));
195		return(0);
196	}
197	if(uleft) mask = RIGHT_RING;
198	else if(uright) mask = LEFT_RING;
199	else do {
200		char answer;
201
202 		pline("What ring-finger, Right or Left? ");
203		if(strchr(quitchars, (answer = readchar())))
204			return(0);
205		switch(answer){
206		case 'l':
207		case 'L':
208			mask = LEFT_RING;
209			break;
210		case 'r':
211		case 'R':
212			mask = RIGHT_RING;
213			break;
214		}
215	} while(!mask);
216	setworn(otmp, mask);
217	if(otmp == uwep)
218		setuwep((struct obj *) 0);
219	oldprop = u.uprops[PROP(otmp->otyp)].p_flgs;
220	u.uprops[PROP(otmp->otyp)].p_flgs |= mask;
221	switch(otmp->otyp){
222	case RIN_LEVITATION:
223		if(!oldprop) float_up();
224		break;
225	case RIN_PROTECTION_FROM_SHAPE_CHANGERS:
226		rescham();
227		break;
228	case RIN_GAIN_STRENGTH:
229		u.ustr += otmp->spe;
230		u.ustrmax += otmp->spe;
231		if(u.ustr > 118) u.ustr = 118;
232		if(u.ustrmax > 118) u.ustrmax = 118;
233		flags.botl = 1;
234		break;
235	case RIN_INCREASE_DAMAGE:
236		u.udaminc += otmp->spe;
237		break;
238	}
239	prinv(otmp);
240	return(1);
241}
242
243ringoff(obj)
244register struct obj *obj;
245{
246register long mask;
247	mask = obj->owornmask & W_RING;
248	setworn((struct obj *) 0, obj->owornmask);
249	if(!(u.uprops[PROP(obj->otyp)].p_flgs & mask))
250		impossible("Strange... I didnt know you had that ring.");
251	u.uprops[PROP(obj->otyp)].p_flgs &= ~mask;
252	switch(obj->otyp) {
253	case RIN_FIRE_RESISTANCE:
254		/* Bad luck if the player is in hell... --jgm */
255		if (!Fire_resistance && dlevel >= 30) {
256			pline("The flames of Hell burn you to a crisp.");
257			killer = "stupidity in hell";
258			done("burned");
259		}
260		break;
261	case RIN_LEVITATION:
262		if(!Levitation) {	/* no longer floating */
263			float_down();
264		}
265		break;
266	case RIN_GAIN_STRENGTH:
267		u.ustr -= obj->spe;
268		u.ustrmax -= obj->spe;
269		if(u.ustr > 118) u.ustr = 118;
270		if(u.ustrmax > 118) u.ustrmax = 118;
271		flags.botl = 1;
272		break;
273	case RIN_INCREASE_DAMAGE:
274		u.udaminc -= obj->spe;
275		break;
276	}
277}
278
279find_ac(){
280register int uac = 10;
281	if(uarm) uac -= ARM_BONUS(uarm);
282	if(uarm2) uac -= ARM_BONUS(uarm2);
283	if(uarmh) uac -= ARM_BONUS(uarmh);
284	if(uarms) uac -= ARM_BONUS(uarms);
285	if(uarmg) uac -= ARM_BONUS(uarmg);
286	if(uleft && uleft->otyp == RIN_PROTECTION) uac -= uleft->spe;
287	if(uright && uright->otyp == RIN_PROTECTION) uac -= uright->spe;
288	if(uac != u.uac){
289		u.uac = uac;
290		flags.botl = 1;
291	}
292}
293
294glibr(){
295register struct obj *otmp;
296int xfl = 0;
297	if(!uarmg) if(uleft || uright) {
298		/* Note: at present also cursed rings fall off */
299		pline("Your %s off your fingers.",
300			(uleft && uright) ? "rings slip" : "ring slips");
301		xfl++;
302		if((otmp = uleft) != Null(obj)){
303			ringoff(uleft);
304			dropx(otmp);
305		}
306		if((otmp = uright) != Null(obj)){
307			ringoff(uright);
308			dropx(otmp);
309		}
310	}
311	if((otmp = uwep) != Null(obj)){
312		/* Note: at present also cursed weapons fall */
313		setuwep((struct obj *) 0);
314		dropx(otmp);
315		pline("Your weapon %sslips from your hands.",
316			xfl ? "also " : "");
317	}
318}
319
320struct obj *
321some_armor(){
322register struct obj *otmph = uarm;
323	if(uarmh && (!otmph || !rn2(4))) otmph = uarmh;
324	if(uarmg && (!otmph || !rn2(4))) otmph = uarmg;
325	if(uarms && (!otmph || !rn2(4))) otmph = uarms;
326	return(otmph);
327}
328
329corrode_armor(){
330register struct obj *otmph = some_armor();
331	if(otmph){
332		if(otmph->rustfree ||
333		   otmph->otyp == ELVEN_CLOAK ||
334		   otmph->otyp == LEATHER_ARMOR ||
335		   otmph->otyp == STUDDED_LEATHER_ARMOR) {
336			pline("Your %s not affected!",
337				aobjnam(otmph, "are"));
338			return;
339		}
340		pline("Your %s!", aobjnam(otmph, "corrode"));
341		otmph->spe--;
342	}
343}
344