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