Make sure we look at the correct sub op codes when
[dragonfly.git] / games / hack / hack.do_wear.c
blobbeb9d67fc99b0851011d98865858da10f1153155
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 /* $DragonFly: src/games/hack/hack.do_wear.c,v 1.5 2006/08/21 19:45:32 pavalos Exp $ */
6 #include "hack.h"
7 extern char quitchars[];
9 static void off_msg(struct obj *);
10 static int dorr(struct obj *);
11 static bool cursed(struct obj *);
13 static void
14 off_msg(struct obj *otmp)
16 pline("You were wearing %s.", doname(otmp));
19 int
20 doremarm(void)
22 struct obj *otmp;
23 if(!uarm && !uarmh && !uarms && !uarmg) {
24 pline("Not wearing any armor.");
25 return(0);
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);
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);
41 armoroff(otmp);
42 return(1);
45 int
46 doremring(void)
48 if(!uleft && !uright){
49 pline("Not wearing any ring.");
50 return(0);
52 if(!uleft)
53 return(dorr(uright));
54 if(!uright)
55 return(dorr(uleft));
56 if(uleft && uright) while(1) {
57 char answer;
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 '?':
70 doprring();
71 /* might look at morc here %% */
74 /* NOTREACHED */
75 return(0);
78 static int
79 dorr(struct obj *otmp)
81 if(cursed(otmp)) return(0);
82 ringoff(otmp);
83 off_msg(otmp);
84 return(1);
87 static bool
88 cursed(struct obj *otmp)
90 if(otmp->cursed){
91 pline("You can't. It appears to be cursed.");
92 return(1);
94 return(0);
98 bool
99 armoroff(struct obj *otmp)
101 int delay = -objects[otmp->otyp].oc_delay;
102 if(cursed(otmp)) return(0);
103 setworn((struct obj *) 0, otmp->owornmask & W_ARMOR);
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.";
116 } else {
117 off_msg(otmp);
119 return(1);
123 doweararm(void)
125 struct obj *otmp;
126 int delay;
127 int err = 0;
128 long mask = 0;
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);
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++;
164 if(!err) mask = W_ARM;
166 if(otmp == uwep && uwep->cursed) {
167 if(!err++)
168 pline("%s is welded to your hand.", Doname(uwep));
170 if(err) return(0);
171 setworn(otmp, mask);
172 if(otmp == uwep)
173 setuwep((struct obj *) 0);
174 delay = -objects[otmp->otyp].oc_delay;
175 if(delay){
176 nomul(delay);
177 nomovemsg = "You finished your dressing manoeuvre.";
179 otmp->known = 1;
180 return(1);
184 dowearring(void)
186 struct obj *otmp;
187 long mask = 0;
188 long oldprop;
190 if(uleft && uright){
191 pline("There are no more ring-fingers to fill.");
192 return(0);
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);
200 if(otmp == uleft || otmp == uright) {
201 pline("You are already wearing that.");
202 return(0);
204 if(otmp == uwep && uwep->cursed) {
205 pline("%s is welded to your hand.", Doname(uwep));
206 return(0);
208 if(uleft) mask = RIGHT_RING;
209 else if(uright) mask = LEFT_RING;
210 else do {
211 char answer;
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;
226 } while(!mask);
227 setworn(otmp, mask);
228 if(otmp == uwep)
229 setuwep((struct obj *) 0);
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;
250 prinv(otmp);
251 return(1);
254 void
255 ringoff(struct obj *obj)
257 long mask;
258 mask = obj->owornmask & W_RING;
259 setworn((struct obj *) 0, obj->owornmask);
260 if(!(u.uprops[PROP(obj->otyp)].p_flgs & mask))
261 impossible("Strange... I didnt know you had that ring.");
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");
271 break;
272 case RIN_LEVITATION:
273 if(!Levitation) { /* no longer floating */
274 float_down();
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;
290 void
291 find_ac(void)
293 int 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;
307 void
308 glibr(void)
310 struct obj *otmp;
311 int 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++;
317 if((otmp = uleft) != Null(obj)){
318 ringoff(uleft);
319 dropx(otmp);
321 if((otmp = uright) != Null(obj)){
322 ringoff(uright);
323 dropx(otmp);
326 if((otmp = uwep) != Null(obj)){
327 /* Note: at present also cursed weapons fall */
328 setuwep((struct obj *) 0);
329 dropx(otmp);
330 pline("Your weapon %sslips from your hands.",
331 xfl ? "also " : "");
335 struct obj *
336 some_armor(void)
338 struct 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);
345 void
346 corrode_armor(void)
348 struct 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;
358 pline("Your %s!", aobjnam(otmph, "corrode"));
359 otmph->spe--;