Annotation of 43BSDReno/games/rogue/ring.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1988 The Regents of the University of California.
                      3:  * All rights reserved.
                      4:  *
                      5:  * This code is derived from software contributed to Berkeley by
                      6:  * Timothy C. Stoehr.
                      7:  *
                      8:  * Redistribution and use in source and binary forms are permitted
                      9:  * provided that: (1) source distributions retain this entire copyright
                     10:  * notice and comment, and (2) distributions including binaries display
                     11:  * the following acknowledgement:  ``This product includes software
                     12:  * developed by the University of California, Berkeley and its contributors''
                     13:  * in the documentation or other materials provided with the distribution
                     14:  * and in all advertising materials mentioning features or use of this
                     15:  * software. Neither the name of the University nor the names of its
                     16:  * contributors may be used to endorse or promote products derived
                     17:  * from this software without specific prior written permission.
                     18:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
                     19:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
                     20:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     21:  */
                     22: 
                     23: #ifndef lint
                     24: static char sccsid[] = "@(#)ring.c     5.3 (Berkeley) 6/1/90";
                     25: #endif /* not lint */
                     26: 
                     27: /*
                     28:  * ring.c
                     29:  *
                     30:  * This source herein may be modified and/or distributed by anybody who
                     31:  * so desires, with the following restrictions:
                     32:  *    1.)  No portion of this notice shall be removed.
                     33:  *    2.)  Credit shall not be taken for the creation of this source.
                     34:  *    3.)  This code is not to be traded, sold, or used for personal
                     35:  *         gain or profit.
                     36:  *
                     37:  */
                     38: 
                     39: #include "rogue.h"
                     40: 
                     41: char *left_or_right = "left or right hand?";
                     42: char *no_ring = "there's no ring on that hand";
                     43: short stealthy;
                     44: short r_rings;
                     45: short add_strength;
                     46: short e_rings;
                     47: short regeneration;
                     48: short ring_exp;
                     49: short auto_search;
                     50: boolean r_teleport;
                     51: boolean r_see_invisible;
                     52: boolean sustain_strength;
                     53: boolean maintain_armor;
                     54: 
                     55: extern char *curse_message;
                     56: extern boolean wizard;
                     57: 
                     58: put_on_ring()
                     59: {
                     60:        short ch;
                     61:        char desc[DCOLS];
                     62:        object *ring;
                     63: 
                     64:        if (r_rings == 2) {
                     65:                message("wearing two rings already", 0);
                     66:                return;
                     67:        }
                     68:        if ((ch = pack_letter("put on what?", RING)) == CANCEL) {
                     69:                return;
                     70:        }
                     71:        if (!(ring = get_letter_object(ch))) {
                     72:                message("no such item.", 0);
                     73:                return;
                     74:        }
                     75:        if (!(ring->what_is & RING)) {
                     76:                message("that's not a ring", 0);
                     77:                return;
                     78:        }
                     79:        if (ring->in_use_flags & (ON_LEFT_HAND | ON_RIGHT_HAND)) {
                     80:                message("that ring is already being worn", 0);
                     81:                return;
                     82:        }
                     83:        if (r_rings == 1) {
                     84:                ch = (rogue.left_ring ? 'r' : 'l');
                     85:        } else {
                     86:                message(left_or_right, 0);
                     87:                do {
                     88:                        ch = rgetchar();
                     89:                } while ((ch != CANCEL) && (ch != 'l') && (ch != 'r') && (ch != '\n') &&
                     90:                                (ch != '\r'));
                     91:        }
                     92:        if ((ch != 'l') && (ch != 'r')) {
                     93:                check_message();
                     94:                return;
                     95:        }
                     96:        if (((ch == 'l') && rogue.left_ring)||((ch == 'r') && rogue.right_ring)) {
                     97:                check_message();
                     98:                message("there's already a ring on that hand", 0);
                     99:                return;
                    100:        }
                    101:        if (ch == 'l') {
                    102:                do_put_on(ring, 1);
                    103:        } else {
                    104:                do_put_on(ring, 0);
                    105:        }
                    106:        ring_stats(1);
                    107:        check_message();
                    108:        get_desc(ring, desc);
                    109:        message(desc, 0);
                    110:        (void) reg_move();
                    111: }
                    112: 
                    113: /*
                    114:  * Do not call ring_stats() from within do_put_on().  It will cause
                    115:  * serious problems when do_put_on() is called from read_pack() in restore().
                    116:  */
                    117: 
                    118: do_put_on(ring, on_left)
                    119: object *ring;
                    120: boolean on_left;
                    121: {
                    122:        if (on_left) {
                    123:                ring->in_use_flags |= ON_LEFT_HAND;
                    124:                rogue.left_ring = ring;
                    125:        } else {
                    126:                ring->in_use_flags |= ON_RIGHT_HAND;
                    127:                rogue.right_ring = ring;
                    128:        }
                    129: }
                    130: 
                    131: remove_ring()
                    132: {
                    133:        boolean left = 0, right = 0;
                    134:        short ch;
                    135:        char buf[DCOLS];
                    136:        object *ring;
                    137: 
                    138:        if (r_rings == 0) {
                    139:                inv_rings();
                    140:        } else if (rogue.left_ring && !rogue.right_ring) {
                    141:                left = 1;
                    142:        } else if (!rogue.left_ring && rogue.right_ring) {
                    143:                right = 1;
                    144:        } else {
                    145:                message(left_or_right, 0);
                    146:                do {
                    147:                        ch = rgetchar();
                    148:                } while ((ch != CANCEL) && (ch != 'l') && (ch != 'r') &&
                    149:                        (ch != '\n') && (ch != '\r'));
                    150:                left = (ch == 'l');
                    151:                right = (ch == 'r');
                    152:                check_message();
                    153:        }
                    154:        if (left || right) {
                    155:                if (left) {
                    156:                        if (rogue.left_ring) {
                    157:                                ring = rogue.left_ring;
                    158:                        } else {
                    159:                                message(no_ring, 0);
                    160:                        }
                    161:                } else {
                    162:                        if (rogue.right_ring) {
                    163:                                ring = rogue.right_ring;
                    164:                        } else {
                    165:                                message(no_ring, 0);
                    166:                        }
                    167:                }
                    168:                if (ring->is_cursed) {
                    169:                        message(curse_message, 0);
                    170:                } else {
                    171:                        un_put_on(ring);
                    172:                        (void) strcpy(buf, "removed ");
                    173:                        get_desc(ring, buf + 8);
                    174:                        message(buf, 0);
                    175:                        (void) reg_move();
                    176:                }
                    177:        }
                    178: }
                    179: 
                    180: un_put_on(ring)
                    181: object *ring;
                    182: {
                    183:        if (ring && (ring->in_use_flags & ON_LEFT_HAND)) {
                    184:                ring->in_use_flags &= (~ON_LEFT_HAND);
                    185:                rogue.left_ring = 0;
                    186:        } else if (ring && (ring->in_use_flags & ON_RIGHT_HAND)) {
                    187:                ring->in_use_flags &= (~ON_RIGHT_HAND);
                    188:                rogue.right_ring = 0;
                    189:        }
                    190:        ring_stats(1);
                    191: }
                    192: 
                    193: gr_ring(ring, assign_wk)
                    194: object *ring;
                    195: boolean assign_wk;
                    196: {
                    197:        ring->what_is = RING;
                    198:        if (assign_wk) {
                    199:                ring->which_kind = get_rand(0, (RINGS - 1));
                    200:        }
                    201:        ring->class = 0;
                    202: 
                    203:        switch(ring->which_kind) {
                    204:        /*
                    205:        case STEALTH:
                    206:                break;
                    207:        case SLOW_DIGEST:
                    208:                break;
                    209:        case REGENERATION:
                    210:                break;
                    211:        case R_SEE_INVISIBLE:
                    212:                break;
                    213:        case SUSTAIN_STRENGTH:
                    214:                break;
                    215:        case R_MAINTAIN_ARMOR:
                    216:                break;
                    217:        case SEARCHING:
                    218:                break;
                    219:        */
                    220:        case R_TELEPORT:
                    221:                ring->is_cursed = 1;
                    222:                break;
                    223:        case ADD_STRENGTH:
                    224:        case DEXTERITY:
                    225:                while ((ring->class = (get_rand(0, 4) - 2)) == 0) ;
                    226:                ring->is_cursed = (ring->class < 0);
                    227:                break;
                    228:        case ADORNMENT:
                    229:                ring->is_cursed = coin_toss();
                    230:                break;
                    231:        }
                    232: }
                    233: 
                    234: inv_rings()
                    235: {
                    236:        char buf[DCOLS];
                    237: 
                    238:        if (r_rings == 0) {
                    239:                message("not wearing any rings", 0);
                    240:        } else {
                    241:                if (rogue.left_ring) {
                    242:                        get_desc(rogue.left_ring, buf);
                    243:                        message(buf, 0);
                    244:                }
                    245:                if (rogue.right_ring) {
                    246:                        get_desc(rogue.right_ring, buf);
                    247:                        message(buf, 0);
                    248:                }
                    249:        }
                    250:        if (wizard) {
                    251:                sprintf(buf, "ste %d, r_r %d, e_r %d, r_t %d, s_s %d, a_s %d, reg %d, r_e %d, s_i %d, m_a %d, aus %d",
                    252:                        stealthy, r_rings, e_rings, r_teleport, sustain_strength,
                    253:                        add_strength, regeneration, ring_exp, r_see_invisible,
                    254:                        maintain_armor, auto_search);
                    255:                message(buf, 0);
                    256:        }
                    257: }
                    258: 
                    259: ring_stats(pr)
                    260: boolean pr;
                    261: {
                    262:        short i;
                    263:        object *ring;
                    264: 
                    265:        stealthy = 0;
                    266:        r_rings = 0;
                    267:        e_rings = 0;
                    268:        r_teleport = 0;
                    269:        sustain_strength = 0;
                    270:        add_strength = 0;
                    271:        regeneration = 0;
                    272:        ring_exp = 0;
                    273:        r_see_invisible = 0;
                    274:        maintain_armor = 0;
                    275:        auto_search = 0;
                    276: 
                    277:        for (i = 0; i < 2; i++) {
                    278:                if (!(ring = ((i == 0) ? rogue.left_ring : rogue.right_ring))) {
                    279:                        continue;
                    280:                }
                    281:                r_rings++;
                    282:                e_rings++;
                    283:                switch(ring->which_kind) {
                    284:                case STEALTH:
                    285:                        stealthy++;
                    286:                        break;
                    287:                case R_TELEPORT:
                    288:                        r_teleport = 1;
                    289:                        break;
                    290:                case REGENERATION:
                    291:                        regeneration++;
                    292:                        break;
                    293:                case SLOW_DIGEST:
                    294:                        e_rings -= 2;
                    295:                        break;
                    296:                case ADD_STRENGTH:
                    297:                        add_strength += ring->class;
                    298:                        break;
                    299:                case SUSTAIN_STRENGTH:
                    300:                        sustain_strength = 1;
                    301:                        break;
                    302:                case DEXTERITY:
                    303:                        ring_exp += ring->class;
                    304:                        break;
                    305:                case ADORNMENT:
                    306:                        break;
                    307:                case R_SEE_INVISIBLE:
                    308:                        r_see_invisible = 1;
                    309:                        break;
                    310:                case MAINTAIN_ARMOR:
                    311:                        maintain_armor = 1;
                    312:                        break;
                    313:                case SEARCHING:
                    314:                        auto_search += 2;
                    315:                        break;
                    316:                }
                    317:        }
                    318:        if (pr) {
                    319:                print_stats(STAT_STRENGTH);
                    320:                relight();
                    321:        }
                    322: }

unix.superglobalmegacorp.com

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