//*************************************************** void init_castle_contents(void) { unsigned j, k, x, y, level ; /* Init. all rooms to 101 (hidden, empty rooms) */ for (level=0; level<8; level++) { for (y=0; y<8; y++) { for (x=0; x<8; x++) { castle[x][y][level].contents = EMPTY_ROOM ; castle[x][y][level].is_known = 0 ; } } } /* Place entrance */ castle[0][3][0].contents = CASTLE_ENTRANCE ; castle[0][3][0].is_known = 1 ; // place two stairs per level for (level=0; level<7; level++) { place_stairs(level) ; place_stairs(level) ; } // place objects on each floor for (level=0; level<8; level++) { // place monsters for (j=MONSTER_BASE; j<=MONSTER_END; j++) LOCATE(level, j) ; for (k=0; k<3; k++) { // place room contents for (j=OBJECT_BASE; j<=OBJECT_END; j++) LOCATE(level, j) ; LOCATE(level, VENDOR) ; // place vendor } } // place treasures for (j=TREASURE_BASE; j<=TREASURE_END; j++) { place_treasure(j) ; } for (j=0; j<3; j++) { place_curse(j) ; } // place the runestaff place_runestaff() ; place_orb() ; // place orb last, so it ends up in empty room }
/** * Place some staircases near walls. * \param c the current chunk * \param feat the stair terrain type * \param num number of staircases to place * \param walls number of walls to surround the stairs (negotiable) */ void alloc_stairs(struct chunk *c, int feat, int num) { int i; /* Place "num" stairs */ for (i = 0; i < num; i++) { int y, x; bool done = false; /* Find the best possible place for the stairs */ if (cave_find_in_range(c, &y, 1, c->height - 2, &x, 1, c->width - 2, square_suits_stairs_well)) { place_stairs(c, y, x, feat); } else if (cave_find_in_range(c, &y, 1, c->height - 2, &x, 1, c->width - 2, square_suits_stairs_ok)) { place_stairs(c, y, x, feat); } else { int walls = 6; /* Gradually reduce number of walls if having trouble */ while (!done) { int j; /* Try hard to find a square with the given number of walls */ for (j = 0; j < 1000; j++) { int total_walls = 0; cave_find_in_range(c, &y, 1, c->height - 2, &x, 1, c->width - 2, square_isempty); if (square_isvault(c, y, x)|| square_isno_stairs(c, y, x)) { continue; } total_walls = square_num_walls_adjacent(c, y, x) + square_num_walls_diagonal(c, y, x); if (total_walls == walls) { place_stairs(c, y, x, feat); done = true; break; } } /* Require fewer walls */ if (walls) walls--; } } } }
int gen_dungeon(dungeon_t *d) { /* pair_t p1, p2; p1[dim_x] = rand_range(1, 158); p1[dim_y] = rand_range(1, 94); p2[dim_x] = rand_range(1, 158); p2[dim_y] = rand_range(1, 94); */ empty_dungeon(d); /* connect_two_points_recursive(d, p1, p2); return 0; */ do { make_rooms(d); } while (place_rooms(d)); connect_rooms(d); place_stairs(d); return 0; }
int gen_dungeon(dungeon_t *d) { empty_dungeon(d); do { make_rooms(d); } while (place_rooms(d)); connect_rooms(d); place_stairs(d); return 0; }
/** * Place some staircases near walls. * \param c the current chunk * \param feat the stair terrain type * \param num number of staircases to place * \param walls number of walls to surround the stairs (negotiable) */ void alloc_stairs(struct chunk *c, int feat, int num, int walls) { int y, x, i, j, done; /* Place "num" stairs */ for (i = 0; i < num; i++) { /* Place some stairs */ for (done = FALSE; !done; ) { /* Try several times, then decrease "walls" */ for (j = 0; !done && j <= 1000; j++) { find_empty(c, &y, &x); if (next_to_walls(c, y, x) < walls) continue; place_stairs(c, y, x, feat); done = TRUE; } /* Require fewer walls */ if (walls) walls--; } } }
/** * Place random stairs at (x, y). * \param c current chunk * \param y co-ordinates * \param x co-ordinates */ void place_random_stairs(struct chunk *c, int y, int x) { int feat = randint0(100) < 50 ? FEAT_LESS : FEAT_MORE; if (square_canputitem(c, y, x)) place_stairs(c, y, x, feat); }