xref: /dragonfly/games/hack/hack.do_wear.c (revision 984263bc)
1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 /* hack.do_wear.c - version 1.0.3 */
3 /* $FreeBSD: src/games/hack/hack.do_wear.c,v 1.3 1999/11/16 02:57:03 billf Exp $ */
4 
5 #include "hack.h"
6 #include <stdio.h>
7 extern char *nomovemsg;
8 extern char quitchars[];
9 extern char *Doname();
10 
11 off_msg(otmp) struct obj *otmp; {
12 	pline("You were wearing %s.", doname(otmp));
13 }
14 
15 doremarm() {
16 	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 lint
70 }
71 
72 dorr(otmp) struct obj *otmp; {
73 	if(cursed(otmp)) return(0);
74 	ringoff(otmp);
75 	off_msg(otmp);
76 	return(1);
77 }
78 
79 cursed(otmp) 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) struct obj *otmp; {
88 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 	struct obj *otmp;
111 	int delay;
112 	int err = 0;
113 	long mask = 0;
114 
115 	otmp = getobj("[", "wear");
116 	if(!otmp) return(0);
117 	if(otmp->owornmask & W_ARMOR) {
118 		pline("You are already wearing that!");
119 		return(0);
120 	}
121 	if(otmp->otyp == HELMET){
122 		if(uarmh) {
123 			pline("You are already wearing a helmet.");
124 			err++;
125 		} else
126 			mask = W_ARMH;
127 	} else if(otmp->otyp == SHIELD){
128 		if(uarms) pline("You are already wearing a shield."), err++;
129 		if(uwep && uwep->otyp == TWO_HANDED_SWORD)
130 	pline("You cannot wear a shield and wield a two-handed sword."), err++;
131 		if(!err) mask = W_ARMS;
132 	} else if(otmp->otyp == PAIR_OF_GLOVES) {
133 		if(uarmg) {
134 			pline("You are already wearing gloves.");
135 			err++;
136 		} else
137 		if(uwep && uwep->cursed) {
138 			pline("You cannot wear gloves over your weapon.");
139 			err++;
140 		} else
141 			mask = W_ARMG;
142 	} else {
143 		if(uarm) {
144 			if(otmp->otyp != ELVEN_CLOAK || uarm2) {
145 				pline("You are already wearing some armor.");
146 				err++;
147 			}
148 		}
149 		if(!err) mask = W_ARM;
150 	}
151 	if(otmp == uwep && uwep->cursed) {
152 		if(!err++)
153 			pline("%s is welded to your hand.", Doname(uwep));
154 	}
155 	if(err) return(0);
156 	setworn(otmp, mask);
157 	if(otmp == uwep)
158 		setuwep((struct obj *) 0);
159 	delay = -objects[otmp->otyp].oc_delay;
160 	if(delay){
161 		nomul(delay);
162 		nomovemsg = "You finished your dressing manoeuvre.";
163 	}
164 	otmp->known = 1;
165 	return(1);
166 }
167 
168 dowearring() {
169 	struct obj *otmp;
170 	long mask = 0;
171 	long oldprop;
172 
173 	if(uleft && uright){
174 		pline("There are no more ring-fingers to fill.");
175 		return(0);
176 	}
177 	otmp = getobj("=", "wear");
178 	if(!otmp) return(0);
179 	if(otmp->owornmask & W_RING) {
180 		pline("You are already wearing that!");
181 		return(0);
182 	}
183 	if(otmp == uleft || otmp == uright) {
184 		pline("You are already wearing that.");
185 		return(0);
186 	}
187 	if(otmp == uwep && uwep->cursed) {
188 		pline("%s is welded to your hand.", Doname(uwep));
189 		return(0);
190 	}
191 	if(uleft) mask = RIGHT_RING;
192 	else if(uright) mask = LEFT_RING;
193 	else do {
194 		char answer;
195 
196  		pline("What ring-finger, Right or Left? ");
197 		if(index(quitchars, (answer = readchar())))
198 			return(0);
199 		switch(answer){
200 		case 'l':
201 		case 'L':
202 			mask = LEFT_RING;
203 			break;
204 		case 'r':
205 		case 'R':
206 			mask = RIGHT_RING;
207 			break;
208 		}
209 	} while(!mask);
210 	setworn(otmp, mask);
211 	if(otmp == uwep)
212 		setuwep((struct obj *) 0);
213 	oldprop = u.uprops[PROP(otmp->otyp)].p_flgs;
214 	u.uprops[PROP(otmp->otyp)].p_flgs |= mask;
215 	switch(otmp->otyp){
216 	case RIN_LEVITATION:
217 		if(!oldprop) float_up();
218 		break;
219 	case RIN_PROTECTION_FROM_SHAPE_CHANGERS:
220 		rescham();
221 		break;
222 	case RIN_GAIN_STRENGTH:
223 		u.ustr += otmp->spe;
224 		u.ustrmax += otmp->spe;
225 		if(u.ustr > 118) u.ustr = 118;
226 		if(u.ustrmax > 118) u.ustrmax = 118;
227 		flags.botl = 1;
228 		break;
229 	case RIN_INCREASE_DAMAGE:
230 		u.udaminc += otmp->spe;
231 		break;
232 	}
233 	prinv(otmp);
234 	return(1);
235 }
236 
237 ringoff(obj)
238 struct obj *obj;
239 {
240 long mask;
241 	mask = obj->owornmask & W_RING;
242 	setworn((struct obj *) 0, obj->owornmask);
243 	if(!(u.uprops[PROP(obj->otyp)].p_flgs & mask))
244 		impossible("Strange... I didnt know you had that ring.");
245 	u.uprops[PROP(obj->otyp)].p_flgs &= ~mask;
246 	switch(obj->otyp) {
247 	case RIN_FIRE_RESISTANCE:
248 		/* Bad luck if the player is in hell... --jgm */
249 		if (!Fire_resistance && dlevel >= 30) {
250 			pline("The flames of Hell burn you to a crisp.");
251 			killer = "stupidity in hell";
252 			done("burned");
253 		}
254 		break;
255 	case RIN_LEVITATION:
256 		if(!Levitation) {	/* no longer floating */
257 			float_down();
258 		}
259 		break;
260 	case RIN_GAIN_STRENGTH:
261 		u.ustr -= obj->spe;
262 		u.ustrmax -= obj->spe;
263 		if(u.ustr > 118) u.ustr = 118;
264 		if(u.ustrmax > 118) u.ustrmax = 118;
265 		flags.botl = 1;
266 		break;
267 	case RIN_INCREASE_DAMAGE:
268 		u.udaminc -= obj->spe;
269 		break;
270 	}
271 }
272 
273 find_ac(){
274 int uac = 10;
275 	if(uarm) uac -= ARM_BONUS(uarm);
276 	if(uarm2) uac -= ARM_BONUS(uarm2);
277 	if(uarmh) uac -= ARM_BONUS(uarmh);
278 	if(uarms) uac -= ARM_BONUS(uarms);
279 	if(uarmg) uac -= ARM_BONUS(uarmg);
280 	if(uleft && uleft->otyp == RIN_PROTECTION) uac -= uleft->spe;
281 	if(uright && uright->otyp == RIN_PROTECTION) uac -= uright->spe;
282 	if(uac != u.uac){
283 		u.uac = uac;
284 		flags.botl = 1;
285 	}
286 }
287 
288 glibr(){
289 struct obj *otmp;
290 int xfl = 0;
291 	if(!uarmg) if(uleft || uright) {
292 		/* Note: at present also cursed rings fall off */
293 		pline("Your %s off your fingers.",
294 			(uleft && uright) ? "rings slip" : "ring slips");
295 		xfl++;
296 		if((otmp = uleft) != Null(obj)){
297 			ringoff(uleft);
298 			dropx(otmp);
299 		}
300 		if((otmp = uright) != Null(obj)){
301 			ringoff(uright);
302 			dropx(otmp);
303 		}
304 	}
305 	if((otmp = uwep) != Null(obj)){
306 		/* Note: at present also cursed weapons fall */
307 		setuwep((struct obj *) 0);
308 		dropx(otmp);
309 		pline("Your weapon %sslips from your hands.",
310 			xfl ? "also " : "");
311 	}
312 }
313 
314 struct obj *
315 some_armor(){
316 struct obj *otmph = uarm;
317 	if(uarmh && (!otmph || !rn2(4))) otmph = uarmh;
318 	if(uarmg && (!otmph || !rn2(4))) otmph = uarmg;
319 	if(uarms && (!otmph || !rn2(4))) otmph = uarms;
320 	return(otmph);
321 }
322 
323 corrode_armor(){
324 struct obj *otmph = some_armor();
325 	if(otmph){
326 		if(otmph->rustfree ||
327 		   otmph->otyp == ELVEN_CLOAK ||
328 		   otmph->otyp == LEATHER_ARMOR ||
329 		   otmph->otyp == STUDDED_LEATHER_ARMOR) {
330 			pline("Your %s not affected!",
331 				aobjnam(otmph, "are"));
332 			return;
333 		}
334 		pline("Your %s!", aobjnam(otmph, "corrode"));
335 		otmph->spe--;
336 	}
337 }
338