Annotation of 43BSDReno/games/rogue/trap.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[] = "@(#)trap.c     5.3 (Berkeley) 6/1/90";
                     25: #endif /* not lint */
                     26: 
                     27: /*
                     28:  * trap.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: trap traps[MAX_TRAPS];
                     42: boolean trap_door = 0;
                     43: short bear_trap = 0;
                     44: 
                     45: char *trap_strings[TRAPS * 2] = {
                     46:        "trap door",
                     47:                        "you fell down a trap",
                     48:        "bear trap",
                     49:                        "you are caught in a bear trap",
                     50:        "teleport trap",
                     51:                        "teleport",
                     52:        "poison dart trap",
                     53:                        "a small dart just hit you in the shoulder",
                     54:        "sleeping gas trap",
                     55:                        "a strange white mist envelops you and you fall asleep",
                     56:        "rust trap",
                     57:                        "a gush of water hits you on the head"
                     58: };
                     59: 
                     60: extern short cur_level, party_room;
                     61: extern char *new_level_message;
                     62: extern boolean interrupted;
                     63: extern short ring_exp;
                     64: extern boolean sustain_strength;
                     65: extern short blind;
                     66: 
                     67: trap_at(row, col)
                     68: register row, col;
                     69: {
                     70:        short i;
                     71: 
                     72:        for (i = 0; ((i < MAX_TRAPS) && (traps[i].trap_type != NO_TRAP)); i++) {
                     73:                if ((traps[i].trap_row == row) && (traps[i].trap_col == col)) {
                     74:                        return(traps[i].trap_type);
                     75:                }
                     76:        }
                     77:        return(NO_TRAP);
                     78: }
                     79: 
                     80: trap_player(row, col)
                     81: short row, col;
                     82: {
                     83:        short t;
                     84: 
                     85:        if ((t = trap_at(row, col)) == NO_TRAP) {
                     86:                return;
                     87:        }
                     88:        dungeon[row][col] &= (~HIDDEN);
                     89:        if (rand_percent(rogue.exp + ring_exp)) {
                     90:                message("the trap failed", 1);
                     91:                return;
                     92:        }
                     93:        switch(t) {
                     94:        case TRAP_DOOR:
                     95:                trap_door = 1;
                     96:                new_level_message = trap_strings[(t*2)+1];
                     97:                break;
                     98:        case BEAR_TRAP:
                     99:                message(trap_strings[(t*2)+1], 1);
                    100:                bear_trap = get_rand(4, 7);
                    101:                break;
                    102:        case TELE_TRAP:
                    103:                mvaddch(rogue.row, rogue.col, '^');
                    104:                tele();
                    105:                break;
                    106:        case DART_TRAP:
                    107:                message(trap_strings[(t*2)+1], 1);
                    108:                rogue.hp_current -= get_damage("1d6", 1);
                    109:                if (rogue.hp_current <= 0) {
                    110:                        rogue.hp_current = 0;
                    111:                }
                    112:                if ((!sustain_strength) && rand_percent(40) &&
                    113:                        (rogue.str_current >= 3)) {
                    114:                        rogue.str_current--;
                    115:                }
                    116:                print_stats(STAT_HP | STAT_STRENGTH);
                    117:                if (rogue.hp_current <= 0) {
                    118:                        killed_by((object *) 0, POISON_DART);
                    119:                }
                    120:                break;
                    121:        case SLEEPING_GAS_TRAP:
                    122:                message(trap_strings[(t*2)+1], 1);
                    123:                take_a_nap();
                    124:                break;
                    125:        case RUST_TRAP:
                    126:                message(trap_strings[(t*2)+1], 1);
                    127:                rust((object *) 0);
                    128:                break;
                    129:        }
                    130: }
                    131: 
                    132: add_traps()
                    133: {
                    134:        short i, n, tries = 0;
                    135:        short row, col;
                    136: 
                    137:        if (cur_level <= 2) {
                    138:                n = 0;
                    139:        } else if (cur_level <= 7) {
                    140:                n = get_rand(0, 2);
                    141:        } else if (cur_level <= 11) {
                    142:                n = get_rand(1, 2);
                    143:        } else if (cur_level <= 16) {
                    144:                n = get_rand(2, 3);
                    145:        } else if (cur_level <= 21) {
                    146:                n = get_rand(2, 4);
                    147:        } else if (cur_level <= (AMULET_LEVEL + 2)) {
                    148:                n = get_rand(3, 5);
                    149:        } else {
                    150:                n = get_rand(5, MAX_TRAPS);
                    151:        }
                    152:        for (i = 0; i < n; i++) {
                    153:                traps[i].trap_type = get_rand(0, (TRAPS - 1));
                    154: 
                    155:                if ((i == 0) && (party_room != NO_ROOM)) {
                    156:                        do {
                    157:                                row = get_rand((rooms[party_room].top_row+1),
                    158:                                                (rooms[party_room].bottom_row-1));
                    159:                                col = get_rand((rooms[party_room].left_col+1),
                    160:                                                (rooms[party_room].right_col-1));
                    161:                                tries++;
                    162:                        } while (((dungeon[row][col] & (OBJECT|STAIRS|TRAP|TUNNEL)) ||
                    163:                                        (dungeon[row][col] == NOTHING)) && (tries < 15));
                    164:                        if (tries >= 15) {
                    165:                                gr_row_col(&row, &col, (FLOOR | MONSTER));
                    166:                        }
                    167:                } else {
                    168:                        gr_row_col(&row, &col, (FLOOR | MONSTER));
                    169:                }
                    170:                traps[i].trap_row = row;
                    171:                traps[i].trap_col = col;
                    172:                dungeon[row][col] |= (TRAP | HIDDEN);
                    173:        }
                    174: }
                    175: 
                    176: id_trap()
                    177: {
                    178:        short dir, row, col, d, t;
                    179: 
                    180:        message("direction? ", 0);
                    181: 
                    182:        while (!is_direction(dir = rgetchar(), &d)) {
                    183:                sound_bell();
                    184:        }
                    185:        check_message();
                    186: 
                    187:        if (dir == CANCEL) {
                    188:                return;
                    189:        }
                    190:        row = rogue.row;
                    191:        col = rogue.col;
                    192: 
                    193:        get_dir_rc(d, &row, &col, 0);
                    194: 
                    195:        if ((dungeon[row][col] & TRAP) && (!(dungeon[row][col] & HIDDEN))) {
                    196:                t = trap_at(row, col);
                    197:                message(trap_strings[t*2], 0);
                    198:        } else {
                    199:                message("no trap there", 0);
                    200:        }
                    201: }
                    202: 
                    203: show_traps()
                    204: {
                    205:        short i, j;
                    206: 
                    207:        for (i = 0; i < DROWS; i++) {
                    208:                for (j = 0; j < DCOLS; j++) {
                    209:                        if (dungeon[i][j] & TRAP) {
                    210:                                mvaddch(i, j, '^');
                    211:                        }
                    212:                }
                    213:        }
                    214: }
                    215: 
                    216: search(n, is_auto)
                    217: short n;
                    218: boolean is_auto;
                    219: {
                    220:        short s, i, j, row, col, t;
                    221:        short shown = 0, found = 0;
                    222:        static boolean reg_search;
                    223: 
                    224:        for (i = -1; i <= 1; i++) {
                    225:                for (j = -1; j <= 1; j++) {
                    226:                        row = rogue.row + i;
                    227:                        col = rogue.col + j;
                    228:                        if ((row < MIN_ROW) || (row >= (DROWS-1)) ||
                    229:                                        (col < 0) || (col >= DCOLS)) {
                    230:                                continue;
                    231:                        }
                    232:                        if (dungeon[row][col] & HIDDEN) {
                    233:                                found++;
                    234:                        }
                    235:                }
                    236:        }
                    237:        for (s = 0; s < n; s++) {
                    238:                for (i = -1; i <= 1; i++) {
                    239:                        for (j = -1; j <= 1; j++) {
                    240:                                row = rogue.row + i;
                    241:                                col = rogue.col + j ;
                    242:                                if ((row < MIN_ROW) || (row >= (DROWS-1)) ||
                    243:                                                (col < 0) || (col >= DCOLS)) {
                    244:                                        continue;
                    245:                                }
                    246:                                if (dungeon[row][col] & HIDDEN) {
                    247:                                        if (rand_percent(17 + (rogue.exp + ring_exp))) {
                    248:                                                dungeon[row][col] &= (~HIDDEN);
                    249:                                                if ((!blind) && ((row != rogue.row) ||
                    250:                                                                (col != rogue.col))) {
                    251:                                                        mvaddch(row, col, get_dungeon_char(row, col));
                    252:                                                }
                    253:                                                shown++;
                    254:                                                if (dungeon[row][col] & TRAP) {
                    255:                                                        t = trap_at(row, col);
                    256:                                                        message(trap_strings[t*2], 1);
                    257:                                                }
                    258:                                        }
                    259:                                }
                    260:                                if (((shown == found) && (found > 0)) || interrupted) {
                    261:                                        return;
                    262:                                }
                    263:                        }
                    264:                }
                    265:                if ((!is_auto) && (reg_search = !reg_search)) {
                    266:                        (void) reg_move();
                    267:                }
                    268:        }
                    269: }

unix.superglobalmegacorp.com

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