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