/* * Places some staircases near walls */ static bool alloc_stairs(int feat, int num, int walls) { int i; int shaft_num = 0; feature_type *f_ptr = &f_info[feat]; if (have_flag(f_ptr->flags, FF_LESS)) { /* No up stairs in town or in ironman mode */ if (ironman_downward || !dun_level) return TRUE; /* No way out!! if ( dun_level == d_info[dungeon_type].mindepth && (dungeon_flags[dungeon_type] & DUNGEON_NO_ENTRANCE) ) { return TRUE; } if ( dun_level == d_info[dungeon_type].mindepth + 1 && (dungeon_flags[dungeon_type] & DUNGEON_NO_ENTRANCE) ) { shaft_num = 0; } else */if (dun_level > d_info[dungeon_type].mindepth) shaft_num = (randint1(num+1))/2; } else if (have_flag(f_ptr->flags, FF_MORE)) { /* player must complete the quest to gain the down staircase */ if (!quests_allow_downstairs()) return TRUE; /* No downstairs on random wilderness entrances */ if (d_info[dungeon_type].flags1 & DF1_RANDOM) return TRUE; /* No downstairs at the bottom */ if (dun_level >= d_info[dungeon_type].maxdepth) return TRUE; if ( dun_level < d_info[dungeon_type].maxdepth - 1 /* Note: If we exclude downshafts, then the astute player can be certain * that normal stairs do *not* lead to a quest level. Instead, we'll change * the behavior of FF_SHAFT in do_cmd_go_down. */ /*&& quests_allow_downshaft()*/) { shaft_num = (randint1(num)+1)/2; if (quickband) shaft_num *= 2; } } /* Paranoia */ else return FALSE; /* Place "num" stairs */ for (i = 0; i < num; i++) { while (TRUE) { int y = 0, x = 0; cave_type *c_ptr; int candidates = 0; int pick; for (y = 1; y < cur_hgt - 1; y++) { for (x = 1; x < cur_wid - 1; x++) { if (alloc_stairs_aux(y, x, walls)) { /* A valid space found */ candidates++; } } } /* No valid place! */ if (!candidates) { /* There are exactly no place! */ if (walls <= 0) return FALSE; /* Decrease walls limit, and try again */ walls--; continue; } /* Choose a random one */ pick = randint1(candidates); for (y = 1; y < cur_hgt - 1; y++) { for (x = 1; x < cur_wid - 1; x++) { if (alloc_stairs_aux(y, x, walls)) { pick--; /* Is this a picked one? */ if (!pick) break; } } if (!pick) break; } /* Access the grid */ c_ptr = &cave[y][x]; /* Clear possible garbage of hidden trap */ c_ptr->mimic = 0; /* Clear previous contents, add stairs */ c_ptr->feat = (i < shaft_num) ? feat_state(feat, FF_SHAFT) : feat; /* No longer "FLOOR" */ c_ptr->info &= ~(CAVE_FLOOR); /* Success */ break; } } return TRUE; }
/* * Places some staircases near walls */ static bool alloc_stairs(int feat, int num, int walls) { int i; int shaft_num = 0; feature_type *f_ptr = &f_info[feat]; if (have_flag(f_ptr->flags, FF_LESS)) { /* No up stairs in town or in ironman mode */ if (ironman_downward || !dun_level) return TRUE; if (dun_level > d_info[dungeon_type].mindepth) shaft_num = (randint1(num+1))/2; } else if (have_flag(f_ptr->flags, FF_MORE)) { int q_idx = quest_number(dun_level); /* No downstairs on quest levels */ if (dun_level > 1 && q_idx) { monster_race *r_ptr = &r_info[quest[q_idx].r_idx]; /* The quest monster(s) is still alive? */ if (!(r_ptr->flags1 & RF1_UNIQUE) || 0 < r_ptr->max_num) return TRUE; } /* No downstairs at the bottom */ if (dun_level >= d_info[dungeon_type].maxdepth) return TRUE; if ((dun_level < d_info[dungeon_type].maxdepth-1) && !quest_number(dun_level+1)) shaft_num = (randint1(num)+1)/2; } /* Paranoia */ else return FALSE; /* Place "num" stairs */ for (i = 0; i < num; i++) { while (TRUE) { int y = 0, x = 0; cave_type *c_ptr; int candidates = 0; int pick; for (y = 1; y < cur_hgt - 1; y++) { for (x = 1; x < cur_wid - 1; x++) { if (alloc_stairs_aux(y, x, walls)) { /* A valid space found */ candidates++; } } } /* No valid place! */ if (!candidates) { /* There are exactly no place! */ if (walls <= 0) return FALSE; /* Decrease walls limit, and try again */ walls--; continue; } /* Choose a random one */ pick = randint1(candidates); for (y = 1; y < cur_hgt - 1; y++) { for (x = 1; x < cur_wid - 1; x++) { if (alloc_stairs_aux(y, x, walls)) { pick--; /* Is this a picked one? */ if (!pick) break; } } if (!pick) break; } /* Access the grid */ c_ptr = &cave[y][x]; /* Clear possible garbage of hidden trap */ c_ptr->mimic = 0; /* Clear previous contents, add stairs */ c_ptr->feat = (i < shaft_num) ? feat_state(feat, FF_SHAFT) : feat; /* No longer "FLOOR" */ c_ptr->info &= ~(CAVE_FLOOR); /* Success */ break; } } return TRUE; }