📄 monster.c
字号:
return(1); } return(0);}move_mon_to(monster, row, col)register object *monster;register short row, col;{ short c; register mrow, mcol; mrow = monster->row; mcol = monster->col; dungeon[mrow][mcol] &= ~MONSTER; dungeon[row][col] |= MONSTER; c = mvinch(mrow, mcol); if ((c >= 'A') && (c <= 'Z')) { if (!detect_monster) { mvaddch(mrow, mcol, monster->trail_char); } else { if (rogue_can_see(mrow, mcol)) { mvaddch(mrow, mcol, monster->trail_char); } else { if (monster->trail_char == '.') { monster->trail_char = ' '; } mvaddch(mrow, mcol, monster->trail_char); } } } monster->trail_char = mvinch(row, col); if (!blind && (detect_monster || rogue_can_see(row, col))) { if ((!(monster->m_flags & INVISIBLE) || (detect_monster || see_invisible || r_see_invisible))) { mvaddch(row, col, gmc(monster)); } } if ((dungeon[row][col] & DOOR) && (get_room_number(row, col) != cur_room) && (dungeon[mrow][mcol] == FLOOR) && !blind) { mvaddch(mrow, mcol, ' '); } if (dungeon[row][col] & DOOR) { dr_course(monster, ((dungeon[mrow][mcol] & TUNNEL) ? 1 : 0), row, col); } else { monster->row = row; monster->col = col; }}mon_can_go(monster, row, col)register object *monster;register short row, col;{ object *obj; short dr, dc; dr = monster->row - row; /* check if move distance > 1 */ if ((dr >= 2) || (dr <= -2)) { return(0); } dc = monster->col - col; if ((dc >= 2) || (dc <= -2)) { return(0); } if ((!dungeon[monster->row][col]) || (!dungeon[row][monster->col])) { return(0); } if ((!is_passable(row, col)) || (dungeon[row][col] & MONSTER)) { return(0); } if ((monster->row!=row)&&(monster->col!=col)&&((dungeon[row][col]&DOOR) || (dungeon[monster->row][monster->col]&DOOR))) { return(0); } if (!(monster->m_flags & (FLITS | CONFUSED | CAN_FLIT)) && (monster->trow == NO_ROOM)) { if ((monster->row < rogue.row) && (row < monster->row)) return(0); if ((monster->row > rogue.row) && (row > monster->row)) return(0); if ((monster->col < rogue.col) && (col < monster->col)) return(0); if ((monster->col > rogue.col) && (col > monster->col)) return(0); } if (dungeon[row][col] & OBJECT) { obj = object_at(&level_objects, row, col); if ((obj->what_is == SCROL) && (obj->which_kind == SCARE_MONSTER)) { return(0); } } return(1);}wake_up(monster)object *monster;{ if (!(monster->m_flags & NAPPING)) { monster->m_flags &= (~(ASLEEP | IMITATES | WAKENS)); }}wake_room(rn, entering, row, col)short rn;boolean entering;short row, col;{ object *monster; short wake_percent; boolean in_room; wake_percent = (rn == party_room) ? PARTY_WAKE_PERCENT : WAKE_PERCENT; if (stealthy > 0) { wake_percent /= (STEALTH_FACTOR + stealthy); } monster = level_monsters.next_monster; while (monster) { in_room = (rn == get_room_number(monster->row, monster->col)); if (in_room) { if (entering) { monster->trow = NO_ROOM; } else { monster->trow = row; monster->tcol = col; } } if ((monster->m_flags & WAKENS) && (rn == get_room_number(monster->row, monster->col))) { if (rand_percent(wake_percent)) { wake_up(monster); } } monster = monster->next_monster; }}char *mon_name(monster)object *monster;{ short ch; if (blind || ((monster->m_flags & INVISIBLE) && !(detect_monster || see_invisible || r_see_invisible))) { return("something"); } if (halluc) { ch = get_rand('A', 'Z') - 'A'; return(m_names[ch]); } ch = monster->m_char - 'A'; return(m_names[ch]);}rogue_is_around(row, col)register row, col;{ short rdif, cdif, retval; rdif = row - rogue.row; cdif = col - rogue.col; retval = (rdif >= -1) && (rdif <= 1) && (cdif >= -1) && (cdif <= 1); return(retval);}wanderer(){ object *monster; short row, col, i; boolean found = 0; for (i = 0; ((i < 15) && (!found)); i++) { monster = gr_monster((object *) 0, 0); if (!(monster->m_flags & (WAKENS | WANDERS))) { free_object(monster); } else { found = 1; } } if (found) { found = 0; wake_up(monster); for (i = 0; ((i < 25) && (!found)); i++) { gr_row_col(&row, &col, (FLOOR | TUNNEL | STAIRS | OBJECT)); if (!rogue_can_see(row, col)) { put_m_at(row, col, monster); found = 1; } } if (!found) { free_object(monster); } }}show_monsters(){ object *monster; detect_monster = 1; if (blind) { return; } monster = level_monsters.next_monster; while (monster) { mvaddch(monster->row, monster->col, monster->m_char); if (monster->m_flags & IMITATES) { monster->m_flags &= (~IMITATES); monster->m_flags |= WAKENS; } monster = monster->next_monster; }}create_monster(){ short row, col; short i; boolean found = 0; object *monster; row = rogue.row; col = rogue.col; for (i = 0; i < 9; i++) { rand_around(i, &row, &col); if (((row == rogue.row) && (col = rogue.col)) || (row < MIN_ROW) || (row > (DROWS-2)) || (col < 0) || (col > (DCOLS-1))) { continue; } if ((!(dungeon[row][col] & MONSTER)) && (dungeon[row][col] & (FLOOR|TUNNEL|STAIRS|DOOR))) { found = 1; break; } } if (found) { monster = gr_monster((object *) 0, 0); put_m_at(row, col, monster); mvaddch(row, col, gmc(monster)); if (monster->m_flags & (WANDERS | WAKENS)) { wake_up(monster); } } else { message("you hear a faint cry of anguish in the distance", 0); }}put_m_at(row, col, monster)short row, col;object *monster;{ monster->row = row; monster->col = col; dungeon[row][col] |= MONSTER; monster->trail_char = mvinch(row, col); (void) add_to_pack(monster, &level_monsters, 0); aim_monster(monster);}aim_monster(monster)object *monster;{ short i, rn, d, r; rn = get_room_number(monster->row, monster->col); r = get_rand(0, 12); for (i = 0; i < 4; i++) { d = (r + i) % 4; if (rooms[rn].doors[d].oth_room != NO_ROOM) { monster->trow = rooms[rn].doors[d].door_row; monster->tcol = rooms[rn].doors[d].door_col; break; } }}rogue_can_see(row, col)register row, col;{ register retval; retval = !blind && (((get_room_number(row, col) == cur_room) && !(rooms[cur_room].is_room & R_MAZE)) || rogue_is_around(row, col)); return(retval);}move_confused(monster)object *monster;{ short i, row, col; if (!(monster->m_flags & ASLEEP)) { if (--monster->moves_confused <= 0) { monster->m_flags &= (~CONFUSED); } if (monster->m_flags & STATIONARY) { return(coin_toss() ? 1 : 0); } else if (rand_percent(15)) { return(1); } row = monster->row; col = monster->col; for (i = 0; i < 9; i++) { rand_around(i, &row, &col); if ((row == rogue.row) && (col == rogue.col)) { return(0); } if (mtry(monster, row, col)) { return(1); } } } return(0);}flit(monster)object *monster;{ short i, row, col; if (!rand_percent(FLIT_PERCENT + ((monster->m_flags & FLIES) ? 20 : 0))) { return(0); } if (rand_percent(10)) { return(1); } row = monster->row; col = monster->col; for (i = 0; i < 9; i++) { rand_around(i, &row, &col); if ((row == rogue.row) && (col == rogue.col)) { continue; } if (mtry(monster, row, col)) { return(1); } } return(1);}gr_obj_char(){ short r; char *rs = "%!?]=/):*"; r = get_rand(0, 8); return(rs[r]);}no_room_for_monster(rn)int rn;{ short i, j; for (i = rooms[rn].top_row+1; i < rooms[rn].bottom_row; i++) { for (j = rooms[rn].left_col+1; j < rooms[rn].right_col; j++) { if (!(dungeon[i][j] & MONSTER)) { return(0); } } } return(1);}aggravate(){ object *monster; message("you hear a high pitched humming noise", 0); monster = level_monsters.next_monster; while (monster) { wake_up(monster); monster->m_flags &= (~IMITATES); if (rogue_can_see(monster->row, monster->col)) { mvaddch(monster->row, monster->col, monster->m_char); } monster = monster->next_monster; }}booleanmon_sees(monster, row, col)object *monster;{ short rn, rdif, cdif, retval; rn = get_room_number(row, col); if ( (rn != NO_ROOM) && (rn == get_room_number(monster->row, monster->col)) && !(rooms[rn].is_room & R_MAZE)) { return(1); } rdif = row - monster->row; cdif = col - monster->col; retval = (rdif >= -1) && (rdif <= 1) && (cdif >= -1) && (cdif <= 1); return(retval);}mv_aquatars(){ object *monster; monster = level_monsters.next_monster; while (monster) { if ((monster->m_char == 'A') && mon_can_go(monster, rogue.row, rogue.col)) { mv_1_monster(monster, rogue.row, rogue.col); monster->m_flags |= ALREADY_MOVED; } monster = monster->next_monster; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -