Annotation of early-roguelike/srogue/rings.c, Revision 1.1.1.1
1.1 rubenllo 1: /*
2: * routines dealing specifically with rings
3: *
4: * @(#)rings.c 9.0 (rdk) 7/17/84
5: *
6: * Super-Rogue
7: * Copyright (C) 1984 Robert D. Kindelberger
8: * All rights reserved.
9: *
10: * Based on "Rogue: Exploring the Dungeons of Doom"
11: * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
12: * All rights reserved.
13: *
14: * See the file LICENSE.TXT for full copyright and licensing information.
15: */
16:
17: #include <stdlib.h>
18: #include <string.h>
19: #include "rogue.h"
20: #include "rogue.ext"
21:
22: int gethand(bool isrmv);
23: int ring_eat(void);
24:
25: /*
26: * ring_on:
27: * Put on a ring
28: */
29: void
30: ring_on(void)
31: {
32: reg struct object *obj;
33: reg struct linked_list *item;
34: reg int ring, wh;
35: char buf[LINLEN];
36: bool okring;
37:
38: if (cur_ring[LEFT] != NULL && cur_ring[RIGHT] != NULL) {
39: msg("Already wearing two rings.");
40: after = FALSE;
41: return;
42: }
43: /*
44: * Make certain that it is somethings that we want to wear
45: */
46: if ((item = get_item("put on", RING)) == NULL)
47: return;
48: obj = OBJPTR(item);
49: if (obj->o_type != RING) {
50: msg("That won't fit on your finger.");
51: return;
52: }
53: /*
54: * find out which hand to put it on
55: */
56: if (is_current(obj))
57: return;
58: if (cur_ring[LEFT] == NULL && cur_ring[RIGHT] == NULL) {
59: if ((ring = gethand(FALSE)) < 0)
60: return;
61: }
62: else if (cur_ring[LEFT] == NULL)
63: ring = LEFT;
64: else
65: ring = RIGHT;
66: cur_ring[ring] = obj;
67: wh = obj->o_which;
68: /*
69: * okring = FALSE when:
70: * 1) ring is cursed and benefit = plus
71: * 2) ring is blessed and benefit = minus
72: */
73: okring = !((obj->o_ac > 0 && o_on(obj, ISCURSED)) ||
74: (obj->o_ac < 0 && o_on(obj, ISBLESS)));
75: /*
76: * Calculate the effect it has on the poor guy (if possible).
77: */
78: if (okring) {
79: switch (wh) {
80: case R_SPEED:
81: if (--obj->o_ac < 0) {
82: obj->o_ac = 0;
83: setoflg(obj,ISCURSED);
84: }
85: else {
86: add_haste(FALSE);
87: }
88: when R_GIANT: /* to 24 */
89: him->s_ef.a_str = MAXSTR;
90: when R_ADDSTR:
91: chg_abil(STR,obj->o_ac,FROMRING);
92: when R_KNOW:
93: chg_abil(WIS,obj->o_ac,FROMRING);
94: when R_DEX:
95: chg_abil(DEX,obj->o_ac,FROMRING);
96: when R_CONST:
97: chg_abil(CON,obj->o_ac,FROMRING);
98: when R_SEEINVIS:
99: player.t_flags |= CANSEE;
100: light(&hero);
101: mvwaddch(cw, hero.y, hero.x, PLAYER);
102: when R_AGGR:
103: aggravate();
104: when R_HEAVY:
105: updpack(); /* new pack weight */
106: when R_BLIND:
107: r_know[R_BLIND] = TRUE;
108: player.t_flags |= ISBLIND;
109: look(FALSE);
110: when R_SLOW:
111: player.t_flags |= ISSLOW;
112: when R_SAPEM:
113: fuse(sapem,TRUE,150);
114: when R_LIGHT: {
115: struct room *rop;
116:
117: r_know[R_LIGHT] = TRUE;
118: if ((rop = player.t_room) != NULL) {
119: rop->r_flags &= ~ISDARK;
120: light(&hero);
121: mvwaddch(cw, hero.y, hero.x, PLAYER);
122: }
123: }
124: }
125: }
126: if (r_know[wh] && r_guess[wh]) {
127: free(r_guess[wh]);
128: r_guess[wh] = NULL;
129: }
130: else if(!r_know[wh] && r_guess[wh] == NULL) {
131: mpos = 0;
132: strcpy(buf, r_stones[wh]);
133: msg(callit);
134: if (get_str(buf, cw) == NORM) {
135: r_guess[wh] = new(strlen(buf) + 1);
136: strcpy(r_guess[wh], buf);
137: }
138: }
139: mpos = 0;
140: msg("Now wearing %s",inv_name(obj,TRUE));
141: ringfood = ring_eat();
142: nochange = FALSE;
143: }
144:
145:
146: /*
147: * ring_off:
148: * Take off some ring
149: */
150: void
151: ring_off(void)
152: {
153: reg int ring;
154: reg struct object *obj;
155:
156: if (cur_ring[LEFT] == NULL && cur_ring[RIGHT] == NULL) {
157: msg("You're not wearing any rings.");
158: return;
159: }
160: else if (cur_ring[LEFT] == NULL)
161: ring = RIGHT;
162: else if (cur_ring[RIGHT] == NULL)
163: ring = LEFT;
164: else
165: if ((ring = gethand(TRUE)) < 0)
166: return;
167: mpos = 0;
168: obj = cur_ring[ring];
169: if (obj == NULL) {
170: msg("Not wearing such a ring.");
171: return;
172: }
173: if (dropcheck(obj)) {
174: msg("Was wearing %s", inv_name(obj, TRUE));
175: nochange = FALSE;
176: ringfood = ring_eat();
177: }
178: }
179:
180:
181: /*
182: * toss_ring:
183: * Remove a ring and stop its effects
184: */
185: void
186: toss_ring(struct object *what)
187: {
188: bool okring;
189:
190: /*
191: * okring = FALSE when:
192: * 1) ring is cursed and benefit = plus
193: * 2) ring is blessed and benefit = minus
194: */
195: okring = !((what->o_ac > 0 && o_on(what, ISCURSED)) ||
196: (what->o_ac < 0 && o_on(what, ISBLESS)));
197:
198: cur_ring[what == cur_ring[LEFT] ? LEFT : RIGHT] = NULL;
199: if (okring) {
200: switch (what->o_which) {
201: case R_SPEED:
202: extinguish(nohaste);
203: nohaste(FALSE);
204: when R_BLIND:
205: sight(FALSE);
206: when R_SLOW:
207: player.t_flags &= ~ISSLOW;
208: when R_SAPEM:
209: extinguish(sapem);
210: when R_GIANT:
211: him->s_ef = him->s_re;
212: ringabil();
213: when R_ADDSTR:
214: chg_abil(STR,-what->o_ac,FALSE);
215: when R_KNOW:
216: chg_abil(WIS,-what->o_ac,FALSE);
217: when R_DEX:
218: chg_abil(DEX,-what->o_ac,FALSE);
219: when R_CONST:
220: chg_abil(CON,-what->o_ac,FALSE);
221: when R_SEEINVIS:
222: player.t_flags &= ~CANSEE;
223: extinguish(unsee);
224: light(&hero);
225: mvwaddch(cw, hero.y, hero.x, PLAYER);
226: }
227: }
228: }
229:
230:
231: /*
232: * gethand:
233: * Get a hand to wear a ring
234: */
235: int
236: gethand(bool isrmv)
237: {
238: reg int c;
239: char *ptr;
240: struct object *obj;
241:
242: while(1) {
243: addmsg("Left or Right ring");
244: if (isrmv)
245: addmsg(starlist);
246: addmsg("? ");
247: endmsg();
248: c = readchar();
249: if (isupper(c))
250: c = tolower(c);
251: if (c == '*' && isrmv) {
252: wclear(hw);
253: obj = cur_ring[LEFT];
254: if (obj != NULL)
255: ptr = inv_name(obj, TRUE);
256: else
257: ptr = "none";
258: wprintw(hw, "L) %s\n\r",ptr);
259: obj = cur_ring[RIGHT];
260: if (obj != NULL)
261: ptr = inv_name(obj, TRUE);
262: else
263: ptr = "none";
264: wprintw(hw, "R) %s\n\r", ptr);
265: wprintw(hw, "\n\r\nWhich hand? ");
266: draw(hw);
267: c = readchar();
268: if (isupper(c))
269: c = tolower(c);
270: restscr(cw);
271: }
272: if (c == 'l')
273: return LEFT;
274: else if (c == 'r')
275: return RIGHT;
276: else if (c == ESCAPE)
277: return -1;
278: mpos = 0;
279: msg("L or R");
280: }
281: }
282:
283: /*
284: * ring_eat:
285: * How much food do the hero's rings use up?
286: */
287: int
288: ring_eat(void)
289: {
290: reg struct object *lb;
291: reg int hand, i, howmuch;
292: bool addit;
293:
294: howmuch = 0;
295: addit = TRUE;
296: for (i = LEFT; i <= RIGHT ; i += 1) {
297: lb = cur_ring[i];
298: if (lb != NULL) {
299: switch (lb->o_which) {
300: case R_REGEN:
301: case R_GIANT:
302: howmuch += 2;
303: when R_SPEED:
304: case R_SUSTSTR:
305: case R_SUSAB:
306: howmuch += 1;
307: when R_SEARCH:
308: howmuch += (rnd(100) < 33);
309: when R_DIGEST:
310: switch(lb->o_ac) {
311: case -3: if (rnd(100) < 25)
312: howmuch += 3;
313: when -2: if (rnd(100) < 50)
314: howmuch += 2;
315: when -1: howmuch += 1;
316: when 0: howmuch -= (rnd(100) < 50);
317: when 3: if (rnd(100) < 25)
318: howmuch -= 3;
319: when 2: if (rnd(100) < 50)
320: howmuch -= 2;
321: default: howmuch -= 1;
322: }
323: otherwise:
324: addit = FALSE;
325: }
326: if (addit) {
327: if (o_on(lb, ISBLESS))
328: howmuch -= 1;
329: else if (o_on(lb, ISCURSED))
330: howmuch += 1;
331: }
332: }
333: }
334: return howmuch;
335: }
336:
337:
338: /*
339: * ring_num:
340: * Print ring bonuses
341: */
342: char *
343: ring_num(struct object *what)
344: {
345: static char number[5];
346:
347: number[0] = '\0';
348: if (o_on(what,ISKNOW) || o_on(what,ISPOST)) {
349: if (magring(what)) { /* only rings with numbers */
350: number[0] = ' ';
351: strcpy(&number[1], num(what->o_ac, 0));
352: }
353: }
354: return number;
355: }
356:
357:
358: /*
359: * magring:
360: * Returns TRUE if a ring has a number, i.e. +2
361: */
362: bool
363: magring(struct object *what)
364: {
365: switch(what->o_which) {
366: case R_SPEED:
367: case R_ADDSTR:
368: case R_PROTECT:
369: case R_ADDHIT:
370: case R_ADDDAM:
371: case R_DIGEST:
372: case R_CONST:
373: case R_KNOW:
374: case R_DEX:
375: return TRUE;
376: default:
377: return FALSE;
378: }
379: }
380:
381:
382: /*
383: * ringabil:
384: * Compute effective abilities due to rings
385: */
386: void
387: ringabil(void)
388: {
389: reg struct object *rptr;
390: reg int i;
391:
392: for(i = LEFT; i <= RIGHT; i++) {
393: rptr = cur_ring[i];
394: if (rptr != NULL) {
395: switch(rptr->o_which) {
396: case R_ADDSTR:
397: chg_abil(STR,rptr->o_ac,FROMRING);
398: when R_DEX:
399: chg_abil(DEX,rptr->o_ac,FROMRING);
400: when R_KNOW:
401: chg_abil(WIS,rptr->o_ac,FROMRING);
402: when R_CONST:
403: chg_abil(CON,rptr->o_ac,FROMRING);
404: }
405: }
406: }
407: }
408:
409:
410: /*
411: * init_ring:
412: * Initialize a ring
413: */
414: void
415: init_ring(struct object *what, bool fromwiz)
416: {
417: /* fromwiz: TRUE when from wizards */
418: reg int much;
419:
420: switch (what->o_which) {
421: case R_DIGEST: /* -3 to +3 rings */
422: case R_ADDSTR:
423: case R_PROTECT:
424: case R_ADDHIT:
425: case R_ADDDAM:
426: case R_DEX:
427: case R_KNOW:
428: case R_CONST:
429: if (fromwiz) {
430: much = getbless(); /* get wizards response */
431: }
432: else { /* normal users */
433: if (rnd(100) < 25)
434: much = -rnd(3) - 1;
435: else
436: much = rnd(3) + 1;
437: }
438: what->o_ac = much;
439: if (much < 0)
440: setoflg(what,ISCURSED);
441: when R_SPEED:
442: what->o_ac = rnd(4) + 1;
443: when R_AGGR:
444: case R_DELUS:
445: case R_HEAVY:
446: case R_BLIND:
447: case R_SLOW:
448: case R_SAPEM:
449: case R_TELEPORT:
450: what->o_ac = 0;
451: setoflg(what,ISCURSED);
452: when R_GIANT:
453: what->o_ac = 25; /* lots !! of STR */
454: otherwise:
455: what->o_ac = 1;
456: }
457: what->o_type = RING;
458: what->o_weight = things[TYP_RING].mi_wght;
459: what->o_typname = things[TYP_RING].mi_name;
460: what->o_vol = itemvol(what);
461: }
462:
463: /*
464: * ringex:
465: * Get extra gains from rings
466: */
467: int
468: ringex(int rtype)
469: {
470: reg int howmuch = 0;
471:
472: if (isring(LEFT, rtype))
473: howmuch += cur_ring[LEFT]->o_ac;
474: if (isring(RIGHT, rtype))
475: howmuch += cur_ring[RIGHT]->o_ac;
476: return howmuch;
477: }
478:
479: /*
480: * iswearing:
481: * Returns TRUE when the hero is wearing a certain type of ring
482: */
483: bool
484: iswearing(int ring)
485: {
486: return (isring(LEFT,ring) || isring(RIGHT,ring));
487: }
488:
489: /*
490: * isring:
491: * Returns TRUE if a ring is on a hand
492: */
493: bool
494: isring(int hand, int ring)
495: {
496: if (cur_ring[hand] != NULL && cur_ring[hand]->o_which == ring)
497: return TRUE;
498: return FALSE;
499: }
CVSweb