Annotation of researchv10no/games/rogue/rings.c, revision 1.1.1.1

1.1       root        1: #include <curses.h>
                      2: #include "rogue.h"
                      3: 
                      4: /*
                      5:  * routines dealing specifically with rings
                      6:  *
                      7:  * @(#)rings.c 3.17 (Berkeley) 6/15/81
                      8:  */
                      9: 
                     10: char *malloc();
                     11: 
                     12: ring_on()
                     13: {
                     14:     register struct object *obj;
                     15:     register struct linked_list *item;
                     16:     register int ring;
                     17:     str_t save_max;
                     18:     char buf[80];
                     19: 
                     20:     item = get_item("put on", RING);
                     21:     /*
                     22:      * Make certain that it is somethings that we want to wear
                     23:      */
                     24:     if (item == NULL)
                     25:        return;
                     26:     obj = (struct object *) ldata(item);
                     27:     if (obj->o_type != RING)
                     28:     {
                     29:        if (!terse)
                     30:            msg("It would be difficult to wrap that around a finger");
                     31:        else
                     32:            msg("Not a ring");
                     33:        return;
                     34:     }
                     35: 
                     36:     /*
                     37:      * find out which hand to put it on
                     38:      */
                     39:     if (is_current(obj))
                     40:        return;
                     41: 
                     42:     if (cur_ring[LEFT] == NULL && cur_ring[RIGHT] == NULL)
                     43:     {
                     44:        if ((ring = gethand()) < 0)
                     45:            return;
                     46:     }
                     47:     else if (cur_ring[LEFT] == NULL)
                     48:        ring = LEFT;
                     49:     else if (cur_ring[RIGHT] == NULL)
                     50:        ring = RIGHT;
                     51:     else
                     52:     {
                     53:        if (!terse)
                     54:            msg("You already have a ring on each hand");
                     55:        else
                     56:            msg("Wearing two");
                     57:        return;
                     58:     }
                     59:     cur_ring[ring] = obj;
                     60: 
                     61:     /*
                     62:      * Calculate the effect it has on the poor guy.
                     63:      */
                     64:     switch (obj->o_which)
                     65:     {
                     66:        case R_ADDSTR:
                     67:            save_max = max_stats.s_str;
                     68:            chg_str(obj->o_ac);
                     69:            max_stats.s_str = save_max;
                     70:            break;
                     71:        case R_SEEINVIS:
                     72:            player.t_flags |= CANSEE;
                     73:            light(&hero);
                     74:            mvwaddch(cw, hero.y, hero.x, PLAYER);
                     75:            break;
                     76:        case R_AGGR:
                     77:            aggravate();
                     78:            break;
                     79:     }
                     80:     status();
                     81:     if (r_know[obj->o_which] && r_guess[obj->o_which])
                     82:     {
                     83:        cfree(r_guess[obj->o_which]);
                     84:        r_guess[obj->o_which] = NULL;
                     85:     }
                     86:     else if (!r_know[obj->o_which] && askme && r_guess[obj->o_which] == NULL)
                     87:     {
                     88:        mpos = 0;
                     89:        msg(terse ? "Call it: " : "What do you want to call it? ");
                     90:        if (get_str(buf, cw) == NORM)
                     91:        {
                     92:            r_guess[obj->o_which] = malloc((unsigned int) strlen(buf) + 1);
                     93:            strcpy(r_guess[obj->o_which], buf);
                     94:        }
                     95:        msg("");
                     96:     }
                     97: }
                     98: 
                     99: ring_off()
                    100: {
                    101:     register int ring;
                    102:     register struct object *obj;
                    103: 
                    104:     if (cur_ring[LEFT] == NULL && cur_ring[RIGHT] == NULL)
                    105:     {
                    106:        if (terse)
                    107:            msg("No rings");
                    108:        else
                    109:            msg("You aren't wearing any rings");
                    110:        return;
                    111:     }
                    112:     else if (cur_ring[LEFT] == NULL)
                    113:        ring = RIGHT;
                    114:     else if (cur_ring[RIGHT] == NULL)
                    115:        ring = LEFT;
                    116:     else
                    117:        if ((ring = gethand()) < 0)
                    118:            return;
                    119:     mpos = 0;
                    120:     obj = cur_ring[ring];
                    121:     if (obj == NULL)
                    122:     {
                    123:        msg("Not wearing such a ring");
                    124:        return;
                    125:     }
                    126:     if (dropcheck(obj))
                    127:        msg("Was wearing %s", inv_name(obj, TRUE));
                    128: }
                    129: 
                    130: gethand()
                    131: {
                    132:     register int c;
                    133: 
                    134:     for (;;)
                    135:     {
                    136:        if (terse)
                    137:            msg("Left or Right ring? ");
                    138:        else
                    139:            msg("Left hand or right hand? ");
                    140:        if ((c = readchar()) == 'l' || c == 'L')
                    141:            return LEFT;
                    142:        else if (c == 'r' || c == 'R')
                    143:            return RIGHT;
                    144:        else if (c == ESCAPE)
                    145:            return -1;
                    146:        mpos = 0;
                    147:        if (terse)
                    148:            msg("L or R");
                    149:        else
                    150:            msg("Please type L or R");
                    151:     }
                    152: }
                    153: 
                    154: /*
                    155:  * how much food does this ring use up?
                    156:  */
                    157: ring_eat(hand)
                    158: register int hand;
                    159: {
                    160:     if (cur_ring[hand] == NULL)
                    161:        return 0;
                    162:     switch (cur_ring[hand]->o_which)
                    163:     {
                    164:        case R_REGEN:
                    165:            return 2;
                    166:        case R_SUSTSTR:
                    167:            return 1;
                    168:        case R_SEARCH:
                    169:            return (rnd(100) < 33);
                    170:        case R_DIGEST:
                    171:            return -(rnd(100) < 50);
                    172:        default:
                    173:            return 0;
                    174:     }
                    175: }
                    176: 
                    177: /*
                    178:  * print ring bonuses
                    179:  */
                    180: char *
                    181: ring_num(obj)
                    182: register struct object *obj;
                    183: {
                    184:     static char buf[5];
                    185: 
                    186:     if (!(obj->o_flags & ISKNOW))
                    187:        return "";
                    188:     switch (obj->o_which)
                    189:     {
                    190:        when R_PROTECT:
                    191:        case R_ADDSTR:
                    192:        case R_ADDDAM:
                    193:        case R_ADDHIT:
                    194:            buf[0] = ' ';
                    195:            strcpy(&buf[1], num(obj->o_ac, 0));
                    196:        otherwise:
                    197:            return "";
                    198:     }
                    199:     return buf;
                    200: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.