3 * @brief ¥À¥ó¥¸¥ç¥ó¤ÎÀ¸À®½èÍý¤Î´ð´´Éôʬ / low-level dungeon creation primitives
6 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke\n
8 * This software may be copied and distributed for educational, research,\n
9 * and not for profit purposes provided that this copyright and statement\n
10 * are included in all such copies. Other copyrights may also apply.\n
12 * 2014 Deskull Doxygen¸þ¤±¤Î¥³¥á¥ó¥ÈÀ°Íý\n
21 * @brief ¿·µ¬¥Õ¥í¥¢¤ËÆþ¤ê¤¿¤Æ¤Î¥×¥ì¥¤¥ä¡¼¤ò¥é¥ó¥À¥à¤Ê¾ì½ê¤ËÇÛÃÖ¤¹¤ë / Returns random co-ordinates for player/monster/object
22 * @return ÇÛÃÖ¤ËÀ®¸ù¤·¤¿¤éTRUE¤òÊÖ¤¹
24 bool new_player_spot(void)
27 int max_attempts = 10000;
32 /* Place the player */
33 while (max_attempts--)
35 /* Pick a legal spot */
36 y = rand_range(1, cur_hgt - 2);
37 x = rand_range(1, cur_wid - 2);
41 /* Must be a "naked" floor grid */
42 if (c_ptr->m_idx) continue;
45 f_ptr = &f_info[c_ptr->feat];
47 if (max_attempts > 5000) /* Rule 1 */
49 if (!have_flag(f_ptr->flags, FF_FLOOR)) continue;
53 if (!have_flag(f_ptr->flags, FF_MOVE)) continue;
54 if (have_flag(f_ptr->flags, FF_HIT_TRAP)) continue;
57 /* Refuse to start on anti-teleport grids in dungeon */
58 if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) continue;
60 if (!player_can_enter(c_ptr->feat, 0)) continue;
61 if (!in_bounds(y, x)) continue;
63 /* Refuse to start on anti-teleport grids */
64 if (c_ptr->info & (CAVE_ICKY)) continue;
70 if (max_attempts < 1) /* Should be -1, actually if we failed... */
73 /* Save the new player grid */
83 * @brief ½êÄê¤Î°ÌÃ֤˾å¤ê³¬Ãʤ«²¼¤ê³¬ÃʤòÇÛÃÖ¤¹¤ë / Place an up/down staircase at given location
84 * @param y ÇÛÃÖ¤ò»î¤ß¤¿¤¤¥Þ¥¹¤ÎYºÂɸ
85 * @param x ÇÛÃÖ¤ò»î¤ß¤¿¤¤¥Þ¥¹¤ÎXºÂɸ
88 void place_random_stairs(int y, int x)
90 bool up_stairs = TRUE;
91 bool down_stairs = TRUE;
96 if (!is_floor_grid(c_ptr) || c_ptr->o_idx) return;
103 if (ironman_downward)
107 if (dun_level >= d_info[dungeon_type].maxdepth)
111 if (quest_number(dun_level) && (dun_level > 1))
114 /* We can't place both */
115 if (down_stairs && up_stairs)
117 /* Choose a staircase randomly */
118 if (randint0(100) < 50)
124 /* Place the stairs */
126 place_up_stairs(y, x);
127 else if (down_stairs)
128 place_down_stairs(y, x);
132 * @brief ½êÄê¤Î°ÌÃ֤ˤµ¤Þ¤¶¤Þ¤Ê¾õÂÖ¤ä¼ïÎà¤Î¥É¥¢¤òÇÛÃÖ¤¹¤ë / Place a random type of door at the given location
133 * @param y ¥É¥¢¤ÎÇÛÃÖ¤ò»î¤ß¤¿¤¤¥Þ¥¹¤ÎYºÂɸ
134 * @param x ¥É¥¢¤ÎÇÛÃÖ¤ò»î¤ß¤¿¤¤¥Þ¥¹¤ÎXºÂɸ
135 * @param room Éô²°¤ËÀܤ·¤Æ¤¤¤ë¾ì¹ç¸þ¤±¤Î¥É¥¢À¸À®¤«Èݤ«
138 void place_random_door(int y, int x, bool room)
141 s16b feat = feat_none;
142 cave_type *c_ptr = &cave[y][x];
144 /* Initialize mimic info */
147 if (d_info[dungeon_type].flags1 & DF1_NO_DOORS)
149 place_floor_bold(y, x);
153 type = ((d_info[dungeon_type].flags1 & DF1_CURTAIN) &&
154 one_in_((d_info[dungeon_type].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
155 ((d_info[dungeon_type].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
157 /* Choose an object */
158 tmp = randint0(1000);
160 /* Open doors (300/1000) */
163 /* Create open door */
164 feat = feat_door[type].open;
167 /* Broken doors (100/1000) */
170 /* Create broken door */
171 feat = feat_door[type].broken;
174 /* Secret doors (200/1000) */
177 /* Create secret door */
178 place_closed_door(y, x, type);
180 if (type != DOOR_CURTAIN)
182 /* Hide. If on the edge of room, use outer wall. */
183 c_ptr->mimic = room ? feat_wall_outer : fill_type[randint0(100)];
185 /* Floor type terrain cannot hide a door */
186 if (feat_supports_los(c_ptr->mimic) && !feat_supports_los(c_ptr->feat))
188 if (have_flag(f_info[c_ptr->mimic].flags, FF_MOVE) || have_flag(f_info[c_ptr->mimic].flags, FF_CAN_FLY))
190 c_ptr->feat = one_in_(2) ? c_ptr->mimic : floor_type[randint0(100)];
197 /* Closed, locked, or stuck doors (400/1000) */
198 else place_closed_door(y, x, type);
202 if (feat != feat_none)
204 set_cave_feat(y, x, feat);
208 place_floor_bold(y, x);
212 delete_monster(y, x);
216 * @brief ½êÄê¤Î°ÌÃ֤˳Ƽï¤ÎÊĤ¸¤¿¥É¥¢¤òÇÛÃÖ¤¹¤ë / Place a random type of normal door at the given location.
217 * @param y ¥É¥¢¤ÎÇÛÃÖ¤ò»î¤ß¤¿¤¤¥Þ¥¹¤ÎYºÂɸ
218 * @param x ¥É¥¢¤ÎÇÛÃÖ¤ò»î¤ß¤¿¤¤¥Þ¥¹¤ÎXºÂɸ
219 * @param type ¥É¥¢¤ÎÃÏ·ÁID
222 void place_closed_door(int y, int x, int type)
225 s16b feat = feat_none;
227 if (d_info[dungeon_type].flags1 & DF1_NO_DOORS)
229 place_floor_bold(y, x);
233 /* Choose an object */
236 /* Closed doors (300/400) */
239 /* Create closed door */
240 feat = feat_door[type].closed;
243 /* Locked doors (99/400) */
246 /* Create locked door */
247 feat = feat_locked_door_random(type);
250 /* Stuck doors (1/400) */
253 /* Create jammed door */
254 feat = feat_jammed_door_random(type);
257 if (feat != feat_none)
259 cave_set_feat(y, x, feat);
261 /* Now it is not floor */
262 cave[y][x].info &= ~(CAVE_MASK);
266 place_floor_bold(y, x);
271 * @brief ĹÊý·Á¤Î¶õƶ¤òÀ¸À®¤¹¤ë / Make an empty square floor, for the middle of rooms
272 * @param x1 ĹÊý·Á¤Îº¸Ã¼XºÂɸ(-1)
273 * @param x2 ĹÊý·Á¤Î±¦Ã¼XºÂɸ(+1)
274 * @param y1 ĹÊý·Á¤Î¾åüYºÂɸ(-1)
275 * @param y2 ĹÊý·Á¤Î²¼Ã¼YºÂɸ(+1)
276 * @param light ¾ÈÌÀ¤ÎÍ̵
279 void place_floor(int x1, int x2, int y1, int y2, bool light)
283 /* Place a full floor under the room */
284 for (y = y1 - 1; y <= y2 + 1; y++)
286 for (x = x1 - 1; x <= x2 + 1; x++)
288 place_floor_bold(y, x);
289 add_cave_info(y, x, CAVE_ROOM);
290 if (light) add_cave_info(y, x, CAVE_GLOW);
297 * @brief ĹÊý·Á¤ÎÉô²°¤òÀ¸À®¤¹¤ë / Make an empty square room, only floor and wall grids
298 * @param x1 ĹÊý·Á¤Îº¸Ã¼XºÂɸ(-1)
299 * @param x2 ĹÊý·Á¤Î±¦Ã¼XºÂɸ(+1)
300 * @param y1 ĹÊý·Á¤Î¾åüYºÂɸ(-1)
301 * @param y2 ĹÊý·Á¤Î²¼Ã¼YºÂɸ(+1)
302 * @param light ¾ÈÌÀ¤ÎÍ̵
305 void place_room(int x1, int x2, int y1, int y2, bool light)
309 place_floor(x1, x2, y1, y2, light);
311 /* Walls around the room */
312 for (y = y1 - 1; y <= y2 + 1; y++)
314 place_outer_bold(y, x1 - 1);
315 place_outer_bold(y, x2 + 1);
317 for (x = x1 - 1; x <= x2 + 1; x++)
319 place_outer_bold(y1 - 1, x);
320 place_outer_bold(y2 + 1, x);
326 * @brief Æüì¤ÊÉô²°¸þ¤±¤Ë³Æ¼ï¥¢¥¤¥Æ¥à¤òÇÛÃÖ¤¹¤ë / Create up to "num" objects near the given coordinates
327 * @param y ÇÛÃÖ¤·¤¿¤¤Ãæ¿´¥Þ¥¹¤ÎYºÂɸ
328 * @param x ÇÛÃÖ¤·¤¿¤¤Ãæ¿´¥Þ¥¹¤ÎXºÂɸ
329 * @param num ÇÛÃÖ¤·¤¿¤¤¿ô
332 * Only really called by some of the "vault" routines.
334 void vault_objects(int y, int x, int num)
337 int i = 0, j = y, k = x;
342 /* Attempt to place 'num' objects */
343 for (; num > 0; --num)
345 /* Try up to 11 spots looking for empty space */
346 for (i = 0; i < 11; ++i)
348 /* Pick a random location */
349 while (dummy < SAFE_MAX_ATTEMPTS)
351 j = rand_spread(y, 2);
352 k = rand_spread(x, 3);
354 if (!in_bounds(j, k)) continue;
359 if (dummy >= SAFE_MAX_ATTEMPTS)
364 msg_print("·Ù¹ð¡ªÃϲ¼¼¼¤Î¥¢¥¤¥Æ¥à¤òÇÛÃ֤Ǥ¤Þ¤»¤ó¡ª");
366 msg_print("Warning! Could not place vault object!");
373 /* Require "clean" floor space */
375 if (!is_floor_grid(c_ptr) || c_ptr->o_idx) continue;
378 if (randint0(100) < 75)
380 place_object(j, k, 0L);
389 /* Placement accomplished */
396 * @brief Æüì¤ÊÉô²°¸þ¤±¤Ë³Æ¼ï¥¢¥¤¥Æ¥à¤òÇÛÃÖ¤¹¤ë(vault_trap¤Î¥µ¥Ö¥»¥Ã¥È) / Place a trap with a given displacement of point
397 * @param y ¥È¥é¥Ã¥×¤òÇÛÃÖ¤·¤¿¤¤¥Þ¥¹¤ÎÃæ¿´YºÂɸ
398 * @param x ¥È¥é¥Ã¥×¤òÇÛÃÖ¤·¤¿¤¤¥Þ¥¹¤ÎÃæ¿´XºÂɸ
399 * @param yd YÊý¸þ¤ÎÇÛÃÖʬ»¶¥Þ¥¹¿ô
400 * @param xd XÊý¸þ¤ÎÇÛÃÖʬ»¶¥Þ¥¹¿ô
403 * Only really called by some of the "vault" routines.
405 void vault_trap_aux(int y, int x, int yd, int xd)
407 int count = 0, y1 = y, x1 = x;
413 for (count = 0; count <= 5; count++)
416 while (dummy < SAFE_MAX_ATTEMPTS)
418 y1 = rand_spread(y, yd);
419 x1 = rand_spread(x, xd);
421 if (!in_bounds(y1, x1)) continue;
425 if (dummy >= SAFE_MAX_ATTEMPTS)
430 msg_print("·Ù¹ð¡ªÃϲ¼¼¼¤Î¥È¥é¥Ã¥×¤òÇÛÃ֤Ǥ¤Þ¤»¤ó¡ª");
432 msg_print("Warning! Could not place vault trap!");
438 /* Require "naked" floor grids */
439 c_ptr = &cave[y1][x1];
440 if (!is_floor_grid(c_ptr) || c_ptr->o_idx || c_ptr->m_idx) continue;
451 * @brief Æüì¤ÊÉô²°¸þ¤±¤Ë³Æ¼ï¥¢¥¤¥Æ¥à¤òÇÛÃÖ¤¹¤ë(¥á¥¤¥ó¥ë¡¼¥Á¥ó) / Place some traps with a given displacement of given location
452 * @param y ¥È¥é¥Ã¥×¤òÇÛÃÖ¤·¤¿¤¤¥Þ¥¹¤ÎÃæ¿´YºÂɸ
453 * @param x ¥È¥é¥Ã¥×¤òÇÛÃÖ¤·¤¿¤¤¥Þ¥¹¤ÎÃæ¿´XºÂɸ
454 * @param yd YÊý¸þ¤ÎÇÛÃÖʬ»¶¥Þ¥¹¿ô
455 * @param xd XÊý¸þ¤ÎÇÛÃÖʬ»¶¥Þ¥¹¿ô
456 * @param num ÇÛÃÖ¤·¤¿¤¤¥È¥é¥Ã¥×¤Î¿ô
459 * Only really called by some of the "vault" routines.
461 void vault_traps(int y, int x, int yd, int xd, int num)
465 for (i = 0; i < num; i++)
467 vault_trap_aux(y, x, yd, xd);
472 * @brief Æüì¤ÊÉô²°ÃÏ·Á¸þ¤±¤Ë¥â¥ó¥¹¥¿¡¼¤òÇÛÃÖ¤¹¤ë / Hack -- Place some sleeping monsters near the given location
473 * @param y1 ¥â¥ó¥¹¥¿¡¼¤òÇÛÃÖ¤·¤¿¤¤¥Þ¥¹¤ÎÃæ¿´YºÂɸ
474 * @param x1 ¥â¥ó¥¹¥¿¡¼¤òÇÛÃÖ¤·¤¿¤¤¥Þ¥¹¤ÎÃæ¿´XºÂɸ
475 * @param num ÇÛÃÖ¤·¤¿¤¤¥â¥ó¥¹¥¿¡¼¤Î¿ô
478 * Only really called by some of the "vault" routines.
480 void vault_monsters(int y1, int x1, int num)
485 /* Try to summon "num" monsters "near" the given location */
486 for (k = 0; k < num; k++)
488 /* Try nine locations */
489 for (i = 0; i < 9; i++)
493 /* Pick a nearby location */
494 scatter(&y, &x, y1, x1, d, 0);
496 /* Require "empty" floor grids */
498 if (!cave_empty_grid(c_ptr)) continue;
500 /* Place the monster (allow groups) */
501 monster_level = base_level + 2;
502 (void)place_monster(y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
503 monster_level = base_level;
510 * @brief build_tunnelÍѤËÄÌÏ©¤ò·¡¤ë¤¿¤á¤ÎÊý¸þ¤ò°ÌÃÖ´Ø·¸Ä̤ê¤Ë·è¤á¤ë / Always picks a correct direction
511 * @param rdir YÊý¸þ¤Ë¼è¤ë¤Ù¤¥Ù¥¯¥È¥ëÃͤòÊÖ¤¹»²¾È¥Ý¥¤¥ó¥¿
512 * @param cdir XÊý¸þ¤Ë¼è¤ë¤Ù¤¥Ù¥¯¥È¥ëÃͤòÊÖ¤¹»²¾È¥Ý¥¤¥ó¥¿
513 * @param y1 »ÏÅÀYºÂɸ
514 * @param x1 »ÏÅÀXºÂɸ
515 * @param y2 ½ªÅÀYºÂɸ
516 * @param x2 ½ªÅÀXºÂɸ
519 void correct_dir(int *rdir, int *cdir, int y1, int x1, int y2, int x2)
521 /* Extract vertical and horizontal directions */
522 *rdir = (y1 == y2) ? 0 : (y1 < y2) ? 1 : -1;
523 *cdir = (x1 == x2) ? 0 : (x1 < x2) ? 1 : -1;
525 /* Never move diagonally */
528 if (randint0(100) < 50)
536 * @brief build_tunnelÍѤËÄÌÏ©¤ò·¡¤ë¤¿¤á¤ÎÊý¸þ¤ò¥é¥ó¥À¥à¤Ë·è¤á¤ë / Pick a random direction
537 * @param rdir YÊý¸þ¤Ë¼è¤ë¤Ù¤¥Ù¥¯¥È¥ëÃͤòÊÖ¤¹»²¾È¥Ý¥¤¥ó¥¿
538 * @param cdir XÊý¸þ¤Ë¼è¤ë¤Ù¤¥Ù¥¯¥È¥ëÃͤòÊÖ¤¹»²¾È¥Ý¥¤¥ó¥¿
541 void rand_dir(int *rdir, int *cdir)
543 /* Pick a random direction */
546 /* Extract the dy/dx components */
552 /* Function that sees if a square is a floor. (Includes range checking.) */
553 bool get_is_floor(int x, int y)
555 if (!in_bounds(y, x))
561 /* Do the real check */
562 if (is_floor_bold(y, x)) return (TRUE);
568 /* Set a square to be floor. (Includes range checking.) */
569 void set_floor(int x, int y)
571 if (!in_bounds(y, x))
577 if (cave[y][x].info & CAVE_ROOM)
579 /* A room border don't touch. */
583 /* Set to be floor if is a wall (don't touch lakes). */
584 if (is_extra_bold(y, x))
585 place_floor_bold(y, x);
591 * Constructs a tunnel between two points
593 * This function must be called BEFORE any streamers are created,
594 * since we use the special "granite wall" sub-types to keep track
595 * of legal places for corridors to pierce rooms.
597 * We use "door_flag" to prevent excessive construction of doors
598 * along overlapping corridors.
600 * We queue the tunnel grids to prevent door creation along a corridor
601 * which intersects itself.
603 * We queue the wall piercing grids to prevent a corridor from leaving
604 * a room and then coming back in through the same entrance.
606 * We "pierce" grids which are "outer" walls of rooms, and when we
607 * do so, we change all adjacent "outer" walls of rooms into "solid"
608 * walls so that no two corridors may use adjacent grids for exits.
610 * The "solid" wall check prevents corridors from "chopping" the
611 * corners of rooms off, as well as "silly" door placement, and
612 * "excessively wide" room entrances.
616 * inner -- inner room walls
617 * outer -- outer room walls
618 * solid -- solid room walls
620 bool build_tunnel(int row1, int col1, int row2, int col2)
623 int tmp_row, tmp_col;
624 int row_dir, col_dir;
625 int start_row, start_col;
626 int main_loop_count = 0;
628 bool door_flag = FALSE;
632 /* Save the starting location */
636 /* Start out in the correct direction */
637 correct_dir(&row_dir, &col_dir, row1, col1, row2, col2);
639 /* Keep going until done (or bored) */
640 while ((row1 != row2) || (col1 != col2))
642 /* Mega-Hack -- Paranoia -- prevent infinite loops */
643 if (main_loop_count++ > 2000) return FALSE;
645 /* Allow bends in the tunnel */
646 if (randint0(100) < dun_tun_chg)
648 /* Acquire the correct direction */
649 correct_dir(&row_dir, &col_dir, row1, col1, row2, col2);
651 /* Random direction */
652 if (randint0(100) < dun_tun_rnd)
654 rand_dir(&row_dir, &col_dir);
658 /* Get the next location */
659 tmp_row = row1 + row_dir;
660 tmp_col = col1 + col_dir;
663 /* Extremely Important -- do not leave the dungeon */
664 while (!in_bounds(tmp_row, tmp_col))
666 /* Acquire the correct direction */
667 correct_dir(&row_dir, &col_dir, row1, col1, row2, col2);
669 /* Random direction */
670 if (randint0(100) < dun_tun_rnd)
672 rand_dir(&row_dir, &col_dir);
675 /* Get the next location */
676 tmp_row = row1 + row_dir;
677 tmp_col = col1 + col_dir;
681 /* Access the location */
682 c_ptr = &cave[tmp_row][tmp_col];
684 /* Avoid "solid" walls */
685 if (is_solid_grid(c_ptr)) continue;
687 /* Pierce "outer" walls of rooms */
688 if (is_outer_grid(c_ptr))
690 /* Acquire the "next" location */
691 y = tmp_row + row_dir;
692 x = tmp_col + col_dir;
694 /* Hack -- Avoid outer/solid walls */
695 if (is_outer_bold(y, x)) continue;
696 if (is_solid_bold(y, x)) continue;
698 /* Accept this location */
702 /* Save the wall location */
703 if (dun->wall_n < WALL_MAX)
705 dun->wall[dun->wall_n].y = row1;
706 dun->wall[dun->wall_n].x = col1;
711 /* Forbid re-entry near this piercing */
712 for (y = row1 - 1; y <= row1 + 1; y++)
714 for (x = col1 - 1; x <= col1 + 1; x++)
716 /* Convert adjacent "outer" walls as "solid" walls */
717 if (is_outer_bold(y, x))
719 /* Change the wall to a "solid" wall */
720 place_solid_noperm_bold(y, x);
726 /* Travel quickly through rooms */
727 else if (c_ptr->info & (CAVE_ROOM))
729 /* Accept the location */
734 /* Tunnel through all other walls */
735 else if (is_extra_grid(c_ptr) || is_inner_grid(c_ptr) || is_solid_grid(c_ptr))
737 /* Accept this location */
741 /* Save the tunnel location */
742 if (dun->tunn_n < TUNN_MAX)
744 dun->tunn[dun->tunn_n].y = row1;
745 dun->tunn[dun->tunn_n].x = col1;
750 /* Allow door in next grid */
754 /* Handle corridor intersections or overlaps */
757 /* Accept the location */
761 /* Collect legal door locations */
764 /* Save the door location */
765 if (dun->door_n < DOOR_MAX)
767 dun->door[dun->door_n].y = row1;
768 dun->door[dun->door_n].x = col1;
773 /* No door in next grid */
777 /* Hack -- allow pre-emptive tunnel termination */
778 if (randint0(100) >= dun_tun_con)
780 /* Distance between row1 and start_row */
781 tmp_row = row1 - start_row;
782 if (tmp_row < 0) tmp_row = (-tmp_row);
784 /* Distance between col1 and start_col */
785 tmp_col = col1 - start_col;
786 if (tmp_col < 0) tmp_col = (-tmp_col);
788 /* Terminate the tunnel */
789 if ((tmp_row > 10) || (tmp_col > 10)) break;
799 * This routine adds the square to the tunnel
800 * It also checks for SOLID walls - and returns a nearby
801 * non-SOLID square in (x,y) so that a simple avoiding
802 * routine can be used. The returned boolean value reflects
803 * whether or not this routine hit a SOLID wall.
805 * "affectwall" toggles whether or not this new square affects
806 * the boundaries of rooms. - This is used by the catacomb
809 static bool set_tunnel(int *x, int *y, bool affectwall)
813 cave_type *c_ptr = &cave[*y][*x];
815 if (!in_bounds(*y, *x)) return TRUE;
817 if (is_inner_grid(c_ptr))
822 if (is_extra_bold(*y,*x))
824 /* Save the tunnel location */
825 if (dun->tunn_n < TUNN_MAX)
827 dun->tunn[dun->tunn_n].y = *y;
828 dun->tunn[dun->tunn_n].x = *x;
836 if (is_floor_bold(*y, *x))
838 /* Don't do anything */
842 if (is_outer_grid(c_ptr) && affectwall)
844 /* Save the wall location */
845 if (dun->wall_n < WALL_MAX)
847 dun->wall[dun->wall_n].y = *y;
848 dun->wall[dun->wall_n].x = *x;
853 /* Forbid re-entry near this piercing */
854 for (j = *y - 1; j <= *y + 1; j++)
856 for (i = *x - 1; i <= *x + 1; i++)
858 /* Convert adjacent "outer" walls as "solid" walls */
859 if (is_outer_bold(j, i))
861 /* Change the wall to a "solid" wall */
862 place_solid_noperm_bold(j, i);
867 /* Clear mimic type */
868 cave[*y][*x].mimic = 0;
870 place_floor_bold(*y, *x);
875 if (is_solid_grid(c_ptr) && affectwall)
877 /* cannot place tunnel here - use a square to the side */
879 /* find usable square and return value in (x,y) */
885 while ((i > 0) && is_solid_bold(*y + dy, *x + dx))
887 dy = randint0(3) - 1;
888 dx = randint0(3) - 1;
890 if (!in_bounds(*y + dy, *x + dx))
901 /* Failed for some reason: hack - ignore the solidness */
902 place_outer_grid(c_ptr);
907 /* Give new, acceptable coordinate. */
919 * This routine creates the catacomb-like tunnels by removing extra rock.
920 * Note that this routine is only called on "even" squares - so it gives
921 * a natural checkerboard pattern.
923 static void create_cata_tunnel(int x, int y)
930 set_tunnel(&x1, &y1, FALSE);
934 set_tunnel(&x1, &y1, FALSE);
938 set_tunnel(&x1, &y1, FALSE);
942 set_tunnel(&x1, &y1, FALSE);
947 * This routine does the bulk of the work in creating the new types of tunnels.
948 * It is designed to use very simple algorithms to go from (x1,y1) to (x2,y2)
949 * It doesn't need to add any complexity - straight lines are fine.
950 * The SOLID walls are avoided by a recursive algorithm which tries random ways
951 * around the obstical until it works. The number of itterations is counted, and it
952 * this gets too large the routine exits. This should stop any crashes - but may leave
953 * small gaps in the tunnel where there are too many SOLID walls.
955 * Type 1 tunnels are extremely simple - straight line from A to B. This is only used
956 * as a part of the dodge SOLID walls algorithm.
958 * Type 2 tunnels are made of two straight lines at right angles. When this is used with
959 * short line segments it gives the "cavelike" tunnels seen deeper in the dungeon.
961 * Type 3 tunnels are made of two straight lines like type 2, but with extra rock removed.
962 * This, when used with longer line segments gives the "catacomb-like" tunnels seen near
965 static void short_seg_hack(int x1, int y1, int x2, int y2, int type, int count, bool *fail)
970 /* Check for early exit */
971 if (!(*fail)) return;
973 length = distance(x1, y1, x2, y2);
977 if ((type == 1) && (length != 0))
980 for (i = 0; i <= length; i++)
982 x = x1 + i * (x2 - x1) / length;
983 y = y1 + i * (y2 - y1) / length;
984 if (!set_tunnel(&x, &y, TRUE))
988 /* This isn't working - probably have an infinite loop */
993 /* solid wall - so try to go around */
994 short_seg_hack(x, y, x1 + (i - 1) * (x2 - x1) / length, y1 + (i - 1) * (y2 - y1) / length, 1, count, fail);
995 short_seg_hack(x, y, x1 + (i + 1) * (x2 - x1) / length, y1 + (i + 1) * (y2 - y1) / length, 1, count, fail);
999 else if ((type == 2) || (type == 3))
1003 for (i = x1; i <= x2; i++)
1007 if (!set_tunnel(&x, &y, TRUE))
1009 /* solid wall - so try to go around */
1010 short_seg_hack(x, y, i - 1, y1, 1, count, fail);
1011 short_seg_hack(x, y, i + 1, y1, 1, count, fail);
1013 if ((type == 3) && ((x + y) % 2))
1015 create_cata_tunnel(i, y1);
1021 for (i = x2; i <= x1; i++)
1025 if (!set_tunnel(&x, &y, TRUE))
1027 /* solid wall - so try to go around */
1028 short_seg_hack(x, y, i - 1, y1, 1, count, fail);
1029 short_seg_hack(x, y, i + 1, y1, 1, count, fail);
1031 if ((type == 3) && ((x + y) % 2))
1033 create_cata_tunnel(i, y1);
1040 for (i = y1; i <= y2; i++)
1044 if (!set_tunnel(&x, &y, TRUE))
1046 /* solid wall - so try to go around */
1047 short_seg_hack(x, y, x2, i - 1, 1, count, fail);
1048 short_seg_hack(x, y, x2, i + 1, 1, count, fail);
1050 if ((type == 3) && ((x + y) % 2))
1052 create_cata_tunnel(x2, i);
1058 for (i = y2; i <= y1; i++)
1062 if (!set_tunnel(&x, &y, TRUE))
1064 /* solid wall - so try to go around */
1065 short_seg_hack(x, y, x2, i - 1, 1, count, fail);
1066 short_seg_hack(x, y, x2, i + 1, 1, count, fail);
1068 if ((type == 3) && ((x + y) % 2))
1070 create_cata_tunnel(x2, i);
1079 * This routine maps a path from (x1, y1) to (x2, y2) avoiding SOLID walls.
1080 * Permanent rock is ignored in this path finding- sometimes there is no
1081 * path around anyway -so there will be a crash if we try to find one.
1082 * This routine is much like the river creation routine in Zangband.
1083 * It works by dividing a line segment into two. The segments are divided
1084 * until they are less than "cutoff" - when the corresponding routine from
1085 * "short_seg_hack" is called.
1086 * Note it is VERY important that the "stop if hit another passage" logic
1087 * stays as is. Without this the dungeon turns into Swiss Cheese...
1089 bool build_tunnel2(int x1, int y1, int x2, int y2, int type, int cutoff)
1092 int changex, changey;
1095 bool retval, firstsuccede;
1098 length = distance(x1, y1, x2, y2);
1100 if (length > cutoff)
1103 * Divide path in half and call routine twice.
1108 /* perturbation perpendicular to path */
1109 changex = (randint0(abs(dy) + 2) * 2 - abs(dy) - 1) / 2;
1111 /* perturbation perpendicular to path */
1112 changey = (randint0(abs(dx) + 2) * 2 - abs(dx) - 1) / 2;
1114 /* Work out "mid" ponit */
1115 x3 = x1 + dx + changex;
1116 y3 = y1 + dy + changey;
1118 /* See if in bounds - if not - do not perturb point */
1119 if (!in_bounds(y3, x3))
1125 c_ptr = &cave[y3][x3];
1126 if (is_solid_grid(c_ptr))
1128 /* move midpoint a bit to avoid problem. */
1134 while ((i > 0) && is_solid_bold(y3 + dy, x3 + dx))
1136 dy = randint0(3) - 1;
1137 dx = randint0(3) - 1;
1138 if (!in_bounds(y3 + dy, x3 + dx))
1148 /* Failed for some reason: hack - ignore the solidness */
1149 place_outer_bold(y3, x3);
1155 c_ptr = &cave[y3][x3];
1158 if (is_floor_grid(c_ptr))
1160 if (build_tunnel2(x1, y1, x3, y3, type, cutoff))
1162 if ((cave[y3][x3].info & CAVE_ROOM) || (randint1(100) > 95))
1164 /* do second half only if works + if have hit a room */
1165 retval = build_tunnel2(x3, y3, x2, y2, type, cutoff);
1169 /* have hit another tunnel - make a set of doors here */
1172 /* Save the door location */
1173 if (dun->door_n < DOOR_MAX)
1175 dun->door[dun->door_n].y = y3;
1176 dun->door[dun->door_n].x = x3;
1181 firstsuccede = TRUE;
1185 /* false- didn't work all the way */
1187 firstsuccede = FALSE;
1192 /* tunnel through walls */
1193 if (build_tunnel2(x1, y1, x3, y3, type, cutoff))
1195 retval = build_tunnel2(x3, y3, x2, y2, type, cutoff);
1196 firstsuccede = TRUE;
1200 /* false- didn't work all the way */
1202 firstsuccede = FALSE;
1207 /* only do this if the first half has worked */
1208 set_tunnel(&x3, &y3, TRUE);
1210 /* return value calculated above */
1215 /* Do a short segment */
1217 short_seg_hack(x1, y1, x2, y2, type, 0, &retval);
1219 /* Hack - ignore return value so avoid infinite loops */