3 #include "floor-save.h"
4 #include "floor-generate.h"
9 #include "object-hook.h"
11 #include "player-effects.h"
14 #include "objectkind.h"
18 * The array of floor [MAX_WID][MAX_HGT].
19 * Not completely allocated, that would be inefficient
20 * Not completely hardcoded, that would overflow memory
22 floor_type floor_info;
25 * The array of saved floors
27 saved_floor_type saved_floors[MAX_SAVED_FLOORS];
30 * Grid based version of "cave_empty_bold()"
32 bool is_cave_empty_grid(player_type *player_ptr, grid_type *g_ptr)
34 bool is_empty_grid = cave_have_flag_grid(g_ptr, FF_PLACE);
35 is_empty_grid &= g_ptr->m_idx == 0;
36 is_empty_grid &= !player_grid(player_ptr, g_ptr);
41 bool pattern_tile(floor_type *floor_ptr, POSITION y, POSITION x)
43 return cave_have_flag_bold(floor_ptr, y, x, FF_PATTERN);
48 * Determine if a "legal" grid is an "empty" floor grid
49 * Determine if monsters are allowed to move into a grid
51 * Line 1 -- forbid non-placement grids
52 * Line 2 -- forbid normal monsters
53 * Line 3 -- forbid the player
55 bool is_cave_empty_bold(player_type *player_ptr, POSITION y, POSITION x)
57 floor_type *floor_ptr = player_ptr->current_floor_ptr;
58 bool is_empty_grid = cave_have_flag_bold(floor_ptr, y, x, FF_PLACE);
59 is_empty_grid &= !(floor_ptr->grid_array[y][x].m_idx);
60 is_empty_grid &= !player_bold(player_ptr, y, x);
66 * Determine if a "legal" grid is an "empty" floor grid
67 * Determine if monster generation is allowed in a grid
69 * Line 1 -- forbid non-empty grids
70 * Line 2 -- forbid trees while dungeon generation
72 bool is_cave_empty_bold2(player_type *player_ptr, POSITION y, POSITION x)
74 bool is_empty_grid = is_cave_empty_bold(player_ptr, y, x);
75 is_empty_grid &= current_world_ptr->character_dungeon || !cave_have_flag_bold(player_ptr->current_floor_ptr, y, x, FF_TREE);
81 * @brief 鍵のかかったドアを配置する
82 * @param player_ptr プレーヤーへの参照ポインタ
83 * @param y 配置したいフロアのY座標
84 * @param x 配置したいフロアのX座標
87 void place_locked_door(player_type *player_ptr, POSITION y, POSITION x)
89 floor_type *floor_ptr = player_ptr->current_floor_ptr;
90 if (d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
92 place_bold(player_ptr, y, x, gb_floor);
96 set_cave_feat(floor_ptr, y, x, feat_locked_door_random((d_info[player_ptr->dungeon_idx].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR));
97 floor_ptr->grid_array[y][x].info &= ~(CAVE_FLOOR);
98 delete_monster(player_ptr, y, x);
104 * @param player_ptr プレーヤーへの参照ポインタ
105 * @param y 配置したいフロアのY座標
106 * @param x 配置したいフロアのX座標
107 * @param type DOOR_DEFAULT / DOOR_DOOR / DOOR_GLASS_DOOR / DOOR_CURTAIN のいずれか
110 void place_secret_door(player_type *player_ptr, POSITION y, POSITION x, int type)
112 floor_type *floor_ptr = player_ptr->current_floor_ptr;
113 if (d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
115 place_bold(player_ptr, y, x, gb_floor);
119 if (type == DOOR_DEFAULT)
121 type = ((d_info[floor_ptr->dungeon_idx].flags1 & DF1_CURTAIN) &&
122 one_in_((d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
123 ((d_info[floor_ptr->dungeon_idx].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
126 place_closed_door(player_ptr, y, x, type);
127 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
128 if (type != DOOR_CURTAIN)
130 g_ptr->mimic = feat_wall_inner;
131 if (feat_supports_los(g_ptr->mimic) && !feat_supports_los(g_ptr->feat))
133 if (have_flag(f_info[g_ptr->mimic].flags, FF_MOVE) || have_flag(f_info[g_ptr->mimic].flags, FF_CAN_FLY))
135 g_ptr->feat = one_in_(2) ? g_ptr->mimic : feat_ground_type[randint0(100)];
142 g_ptr->info &= ~(CAVE_FLOOR);
143 delete_monster(player_ptr, y, x);
146 static int scent_when = 0;
149 * Characters leave scent trails for perceptive monsters to track.
151 * Smell is rather more limited than sound. Many creatures cannot use
152 * it at all, it doesn't extend very far outwards from the character's
153 * current position, and monsters can use it to home in the character,
154 * but not to run away from him.
156 * Smell is valued according to age. When a character takes his turn,
157 * scent is aged by one, and new scent of the current age is laid down.
158 * Speedy characters leave more scent, true, but it also ages faster,
159 * which makes it harder to hunt them down.
161 * Whenever the age count loops, most of the scent trail is erased and
162 * the age of the remainder is recalculated.
164 void update_smell(floor_type *floor_ptr, player_type *subject_ptr)
166 /* Create a table that controls the spread of scent */
167 const int scent_adjust[5][5] =
176 if (++scent_when == 254)
178 for (POSITION y = 0; y < floor_ptr->height; y++)
180 for (POSITION x = 0; x < floor_ptr->width; x++)
182 int w = floor_ptr->grid_array[y][x].when;
183 floor_ptr->grid_array[y][x].when = (w > 128) ? (w - 128) : 0;
190 for (POSITION i = 0; i < 5; i++)
192 for (POSITION j = 0; j < 5; j++)
195 POSITION y = i + subject_ptr->y - 2;
196 POSITION x = j + subject_ptr->x - 2;
197 if (!in_bounds(floor_ptr, y, x)) continue;
199 g_ptr = &floor_ptr->grid_array[y][x];
200 if (!cave_have_flag_grid(g_ptr, FF_MOVE) && !is_closed_door(subject_ptr, g_ptr->feat)) continue;
201 if (!player_has_los_bold(subject_ptr, y, x)) continue;
202 if (scent_adjust[i][j] == -1) continue;
204 g_ptr->when = scent_when + scent_adjust[i][j];
211 * Hack -- forget the "flow" information
213 void forget_flow(floor_type *floor_ptr)
215 for (POSITION y = 0; y < floor_ptr->height; y++)
217 for (POSITION x = 0; x < floor_ptr->width; x++)
219 floor_ptr->grid_array[y][x].dist = 0;
220 floor_ptr->grid_array[y][x].cost = 0;
221 floor_ptr->grid_array[y][x].when = 0;
228 * Routine used by the random vault creators to add a door to a location
229 * Note that range checking has to be done in the calling routine.
231 * The doors must be INSIDE the allocated region.
233 void add_door(player_type *player_ptr, POSITION x, POSITION y)
235 floor_type *floor_ptr = player_ptr->current_floor_ptr;
236 if (!is_outer_bold(floor_ptr, y, x)) return;
247 if (is_floor_bold(floor_ptr, y - 1, x) && is_floor_bold(floor_ptr, y + 1, x) &&
248 (is_outer_bold(floor_ptr, y, x - 1) && is_outer_bold(floor_ptr, y, x + 1)))
250 place_secret_door(player_ptr, y, x, DOOR_DEFAULT);
251 place_bold(player_ptr, y, x - 1, gb_solid);
252 place_bold(player_ptr, y, x + 1, gb_solid);
260 * where x = don't care
263 if (is_outer_bold(floor_ptr, y - 1, x) && is_outer_bold(floor_ptr, y + 1, x) &&
264 is_floor_bold(floor_ptr, y, x - 1) && is_floor_bold(floor_ptr, y, x + 1))
266 place_secret_door(player_ptr, y, x, DOOR_DEFAULT);
267 place_bold(player_ptr, y - 1, x, gb_solid);
268 place_bold(player_ptr, y + 1, x, gb_solid);
274 * @brief 所定の位置に上り階段か下り階段を配置する / Place an up/down staircase at given location
275 * @param player_ptr プレーヤーへの参照ポインタ
276 * @param y 配置を試みたいマスのY座標
277 * @param x 配置を試みたいマスのX座標
280 void place_random_stairs(player_type *player_ptr, POSITION y, POSITION x)
282 bool up_stairs = TRUE;
283 bool down_stairs = TRUE;
285 floor_type *floor_ptr = player_ptr->current_floor_ptr;
286 g_ptr = &floor_ptr->grid_array[y][x];
287 if (!is_floor_grid(g_ptr) || g_ptr->o_idx) return;
289 if (!floor_ptr->dun_level) up_stairs = FALSE;
290 if (ironman_downward) up_stairs = FALSE;
291 if (floor_ptr->dun_level >= d_info[player_ptr->dungeon_idx].maxdepth) down_stairs = FALSE;
292 if (quest_number(player_ptr, floor_ptr->dun_level) && (floor_ptr->dun_level > 1)) down_stairs = FALSE;
294 if (down_stairs && up_stairs)
296 if (randint0(100) < 50) up_stairs = FALSE;
297 else down_stairs = FALSE;
300 if (up_stairs) set_cave_feat(floor_ptr, y, x, feat_up_stair);
301 else if (down_stairs) set_cave_feat(floor_ptr, y, x, feat_down_stair);
306 * @brief LOS(Line Of Sight / 視線が通っているか)の判定を行う。
307 * @param player_ptr プレーヤーへの参照ポインタ
312 * @return LOSが通っているならTRUEを返す。
314 * A simple, fast, integer-based line-of-sight algorithm. By Joseph Hall,\n
315 * 4116 Brewster Drive, Raleigh NC 27606. Email to jnh@ecemwl.ncsu.edu.\n
317 * Returns TRUE if a line of sight can be traced from (x1,y1) to (x2,y2).\n
319 * The LOS begins at the center of the tile (x1,y1) and ends at the center of\n
320 * the tile (x2,y2). If los() is to return TRUE, all of the tiles this line\n
321 * passes through must be floor tiles, except for (x1,y1) and (x2,y2).\n
323 * We assume that the "mathematical corner" of a non-floor tile does not\n
324 * block line of sight.\n
326 * Because this function uses (short) ints for all calculations, overflow may\n
327 * occur if dx and dy exceed 90.\n
329 * Once all the degenerate cases are eliminated, the values "qx", "qy", and\n
330 * "m" are multiplied by a scale factor "f1 = abs(dx * dy * 2)", so that\n
331 * we can use integer arithmetic.\n
333 * We travel from start to finish along the longer axis, starting at the border\n
334 * between the first and second tiles, where the y offset = .5 * slope, taking\n
335 * into account the scale factor. See below.\n
337 * Also note that this function and the "move towards target" code do NOT\n
338 * share the same properties. Thus, you can see someone, target them, and\n
339 * then fire a bolt at them, but the bolt may hit a wall, not them. However\n,
340 * by clever choice of target locations, you can sometimes throw a "curve".\n
342 * Note that "line of sight" is not "reflexive" in all cases.\n
344 * Use the "projectable()" routine to test "spell/missile line of sight".\n
346 * Use the "update_view()" function to determine player line-of-sight.\n
348 bool los(player_type *player_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2)
350 POSITION dy = y2 - y1;
351 POSITION dx = x2 - x1;
352 POSITION ay = ABS(dy);
353 POSITION ax = ABS(dx);
354 if ((ax < 2) && (ay < 2)) return TRUE;
356 /* Directly South/North */
357 floor_type *floor_ptr = player_ptr->current_floor_ptr;
361 /* South -- check for walls */
364 for (ty = y1 + 1; ty < y2; ty++)
366 if (!cave_los_bold(floor_ptr, ty, x1)) return FALSE;
370 /* North -- check for walls */
373 for (ty = y1 - 1; ty > y2; ty--)
375 if (!cave_los_bold(floor_ptr, ty, x1)) return FALSE;
383 /* Directly East/West */
386 /* East -- check for walls */
389 for (tx = x1 + 1; tx < x2; tx++)
391 if (!cave_los_bold(floor_ptr, y1, tx)) return FALSE;
395 /* West -- check for walls */
398 for (tx = x1 - 1; tx > x2; tx--)
400 if (!cave_los_bold(floor_ptr, y1, tx)) return FALSE;
407 POSITION sx = (dx < 0) ? -1 : 1;
408 POSITION sy = (dy < 0) ? -1 : 1;
414 if (cave_los_bold(floor_ptr, y1 + sy, x1)) return TRUE;
421 if (cave_los_bold(floor_ptr, y1, x1 + sx)) return TRUE;
425 POSITION f2 = (ax * ay);
426 POSITION f1 = f2 << 1;
444 /* Note (below) the case (qy == f2), where */
445 /* the LOS exactly meets the corner of a tile. */
448 if (!cave_los_bold(floor_ptr, ty, tx)) return FALSE;
461 if (!cave_los_bold(floor_ptr, ty, tx)) return FALSE;
475 /* Travel vertically */
476 POSITION qx = ax * ax;
489 /* Note (below) the case (qx == f2), where */
490 /* the LOS exactly meets the corner of a tile. */
493 if (!cave_los_bold(floor_ptr, ty, tx)) return FALSE;
506 if (!cave_los_bold(floor_ptr, ty, tx)) return FALSE;
522 * Determine if a bolt spell cast from (y1,x1) to (y2,x2) will arrive
523 * at the final destination, assuming no monster gets in the way.
525 * This is slightly (but significantly) different from "los(y1,x1,y2,x2)".
527 bool projectable(player_type *player_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2)
530 int grid_n = project_path(player_ptr, grid_g, (project_length ? project_length : MAX_RANGE), y1, x1, y2, x2, 0);
531 if (!grid_n) return TRUE;
533 POSITION y = GRID_Y(grid_g[grid_n - 1]);
534 POSITION x = GRID_X(grid_g[grid_n - 1]);
535 if ((y != y2) || (x != x2)) return FALSE;
542 * @brief 特殊な部屋地形向けにモンスターを配置する / Hack -- Place some sleeping monsters near the given location
543 * @param player_ptr プレーヤーへの参照ポインタ
544 * @param y1 モンスターを配置したいマスの中心Y座標
545 * @param x1 モンスターを配置したいマスの中心X座標
546 * @param num 配置したいモンスターの数
549 * Only really called by some of the "vault" routines.
551 void vault_monsters(player_type *player_ptr, POSITION y1, POSITION x1, int num)
553 floor_type *floor_ptr = player_ptr->current_floor_ptr;
554 for (int k = 0; k < num; k++)
556 for (int i = 0; i < 9; i++)
560 scatter(player_ptr, &y, &x, y1, x1, d, 0);
562 g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
563 if (!is_cave_empty_grid(player_ptr, g_ptr)) continue;
565 floor_ptr->monster_level = floor_ptr->base_level + 2;
566 (void)place_monster(player_ptr, y, x, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
567 floor_ptr->monster_level = floor_ptr->base_level;
574 * @brief 指定された座標が地震や階段生成の対象となるマスかを返す。 / Determine if a given location may be "destroyed"
575 * @param player_ptr プレーヤーへの参照ポインタ
578 * @return 各種の変更が可能ならTRUEを返す。
580 * 条件は永久地形でなく、なおかつ該当のマスにアーティファクトが存在しないか、である。英語の旧コメントに反して*破壊*の抑止判定には現在使われていない。
582 bool cave_valid_bold(floor_type *floor_ptr, POSITION y, POSITION x)
584 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
585 if (cave_perma_grid(g_ptr)) return FALSE;
587 OBJECT_IDX next_o_idx = 0;
588 for (OBJECT_IDX this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
591 o_ptr = &floor_ptr->o_list[this_o_idx];
592 next_o_idx = o_ptr->next_o_idx;
593 if (object_is_artifact(o_ptr)) return FALSE;
601 * Change the "feat" flag for a grid, and notice/redraw the grid
603 void cave_set_feat(player_type *player_ptr, POSITION y, POSITION x, FEAT_IDX feat)
605 floor_type *floor_ptr = player_ptr->current_floor_ptr;
606 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
607 feature_type *f_ptr = &f_info[feat];
608 if (!current_world_ptr->character_dungeon)
612 if (have_flag(f_ptr->flags, FF_GLOW) && !(d_info[floor_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
614 for (DIRECTION i = 0; i < 9; i++)
616 POSITION yy = y + ddy_ddd[i];
617 POSITION xx = x + ddx_ddd[i];
618 if (!in_bounds2(floor_ptr, yy, xx)) continue;
619 floor_ptr->grid_array[yy][xx].info |= CAVE_GLOW;
626 bool old_los = cave_have_flag_bold(floor_ptr, y, x, FF_LOS);
627 bool old_mirror = is_mirror_grid(g_ptr);
631 g_ptr->info &= ~(CAVE_OBJECT);
632 if (old_mirror && (d_info[floor_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
634 g_ptr->info &= ~(CAVE_GLOW);
635 if (!view_torch_grids) g_ptr->info &= ~(CAVE_MARK);
637 update_local_illumination(player_ptr, y, x);
640 if (!have_flag(f_ptr->flags, FF_REMEMBER)) g_ptr->info &= ~(CAVE_MARK);
641 if (g_ptr->m_idx) update_monster(player_ptr, g_ptr->m_idx, FALSE);
643 note_spot(player_ptr, y, x);
644 lite_spot(player_ptr, y, x);
645 if (old_los ^ have_flag(f_ptr->flags, FF_LOS))
648 #ifdef COMPLEX_WALL_ILLUMINATION /* COMPLEX_WALL_ILLUMINATION */
650 update_local_illumination(player_ptr, y, x);
652 #endif /* COMPLEX_WALL_ILLUMINATION */
654 player_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE | PU_MONSTERS);
657 if (!have_flag(f_ptr->flags, FF_GLOW) || (d_info[player_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
660 for (DIRECTION i = 0; i < 9; i++)
662 POSITION yy = y + ddy_ddd[i];
663 POSITION xx = x + ddx_ddd[i];
664 if (!in_bounds2(floor_ptr, yy, xx)) continue;
667 cc_ptr = &floor_ptr->grid_array[yy][xx];
668 cc_ptr->info |= CAVE_GLOW;
670 if (player_has_los_grid(cc_ptr))
672 if (cc_ptr->m_idx) update_monster(player_ptr, cc_ptr->m_idx, FALSE);
673 note_spot(player_ptr, yy, xx);
674 lite_spot(player_ptr, yy, xx);
677 update_local_illumination(player_ptr, yy, xx);
680 if (player_ptr->special_defense & NINJA_S_STEALTH)
682 if (floor_ptr->grid_array[player_ptr->y][player_ptr->x].info & CAVE_GLOW) set_superstealth(player_ptr, FALSE);
688 * @brief 所定の位置にさまざまな状態や種類のドアを配置する / Place a random type of door at the given location
689 * @param player_ptr プレーヤーへの参照ポインタ
690 * @param y ドアの配置を試みたいマスのY座標
691 * @param x ドアの配置を試みたいマスのX座標
692 * @param room 部屋に接している場合向けのドア生成か否か
695 void place_random_door(player_type *player_ptr, POSITION y, POSITION x, bool room)
697 floor_type *floor_ptr = player_ptr->current_floor_ptr;
698 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
701 if (d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
703 place_bold(player_ptr, y, x, gb_floor);
707 int type = ((d_info[floor_ptr->dungeon_idx].flags1 & DF1_CURTAIN) &&
708 one_in_((d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_CAVE) ? 16 : 256)) ? DOOR_CURTAIN :
709 ((d_info[floor_ptr->dungeon_idx].flags1 & DF1_GLASS_DOOR) ? DOOR_GLASS_DOOR : DOOR_DOOR);
711 int tmp = randint0(1000);
712 FEAT_IDX feat = feat_none;
715 feat = feat_door[type].open;
719 feat = feat_door[type].broken;
723 place_closed_door(player_ptr, y, x, type);
725 if (type != DOOR_CURTAIN)
727 g_ptr->mimic = room ? feat_wall_outer : feat_wall_type[randint0(100)];
728 if (feat_supports_los(g_ptr->mimic) && !feat_supports_los(g_ptr->feat))
730 if (have_flag(f_info[g_ptr->mimic].flags, FF_MOVE) || have_flag(f_info[g_ptr->mimic].flags, FF_CAN_FLY))
732 g_ptr->feat = one_in_(2) ? g_ptr->mimic : feat_ground_type[randint0(100)];
740 place_closed_door(player_ptr, y, x, type);
745 delete_monster(player_ptr, y, x);
749 if (feat != feat_none)
751 set_cave_feat(floor_ptr, y, x, feat);
755 place_bold(player_ptr, y, x, gb_floor);
758 delete_monster(player_ptr, y, x);
763 * @brief グローバルオブジェクト配列を初期化する /
764 * Delete all the items when player leaves the level
765 * @note we do NOT visually reflect these (irrelevant) changes
767 * Hack -- we clear the "g_ptr->o_idx" field for every grid,
768 * and the "m_ptr->next_o_idx" field for every monster, since
769 * we know we are clearing every object. Technically, we only
770 * clear those fields for grids/monsters containing objects,
771 * and we clear it once for every such object.
774 void wipe_o_list(floor_type *floor_ptr)
776 for (int i = 1; i < floor_ptr->o_max; i++)
778 object_type *o_ptr = &floor_ptr->o_list[i];
779 if (!OBJECT_IS_VALID(o_ptr)) continue;
781 if (!current_world_ptr->character_dungeon || preserve_mode)
783 if (object_is_fixed_artifact(o_ptr) && !object_is_known(o_ptr))
785 a_info[o_ptr->name1].cur_num = 0;
789 if (OBJECT_IS_HELD_MONSTER(o_ptr))
792 m_ptr = &floor_ptr->m_list[o_ptr->held_m_idx];
793 m_ptr->hold_o_idx = 0;
799 POSITION y = o_ptr->iy;
800 POSITION x = o_ptr->ix;
802 g_ptr = &floor_ptr->grid_array[y][x];
807 floor_ptr->o_max = 1;
808 floor_ptr->o_cnt = 0;
813 * @brief 所定の位置に各種の閉じたドアを配置する / Place a random type of normal door at the given location.
814 * @param player_ptr プレーヤーへの参照ポインタ
815 * @param y ドアの配置を試みたいマスのY座標
816 * @param x ドアの配置を試みたいマスのX座標
817 * @param type ドアの地形ID
820 void place_closed_door(player_type *player_ptr, POSITION y, POSITION x, int type)
822 floor_type *floor_ptr = player_ptr->current_floor_ptr;
823 if (d_info[floor_ptr->dungeon_idx].flags1 & DF1_NO_DOORS)
825 place_bold(player_ptr, y, x, gb_floor);
829 int tmp = randint0(400);
830 FEAT_IDX feat = feat_none;
833 /* Create closed door */
834 feat = feat_door[type].closed;
838 feat = feat_locked_door_random(type);
842 feat = feat_jammed_door_random(type);
845 if (feat == feat_none)
847 place_bold(player_ptr, y, x, gb_floor);
851 cave_set_feat(player_ptr, y, x, feat);
852 floor_ptr->grid_array[y][x].info &= ~(CAVE_MASK);
857 * @brief 特殊な部屋向けに各種アイテムを配置する(vault_trapのサブセット) / Place a trap with a given displacement of point
858 * @param y トラップを配置したいマスの中心Y座標
859 * @param x トラップを配置したいマスの中心X座標
860 * @param yd Y方向の配置分散マス数
861 * @param xd X方向の配置分散マス数
864 * Only really called by some of the "vault" routines.
866 void vault_trap_aux(player_type *player_ptr, POSITION y, POSITION x, POSITION yd, POSITION xd)
869 floor_type *floor_ptr = player_ptr->current_floor_ptr;
872 for (int count = 0; count <= 5; count++)
874 while (dummy < SAFE_MAX_ATTEMPTS)
876 y1 = rand_spread(y, yd);
877 x1 = rand_spread(x, xd);
879 if (!in_bounds(floor_ptr, y1, x1)) continue;
883 if (dummy >= SAFE_MAX_ATTEMPTS && cheat_room)
885 msg_print(_("警告!地下室のトラップを配置できません!", "Warning! Could not place vault trap!"));
888 g_ptr = &floor_ptr->grid_array[y1][x1];
889 if (!is_floor_grid(g_ptr) || g_ptr->o_idx || g_ptr->m_idx) continue;
891 place_trap(player_ptr, y1, x1);
898 * @brief 指定のマスが床系地形であるかを返す / Function that sees if a square is a floor. (Includes range checking.)
899 * @param x チェックするマスのX座標
900 * @param y チェックするマスのY座標
901 * @return 床系地形ならばTRUE
903 bool get_is_floor(floor_type *floor_ptr, POSITION x, POSITION y)
905 if (!in_bounds(floor_ptr, y, x))
910 if (is_floor_bold(floor_ptr, y, x)) return TRUE;
917 * @brief 隣接4マスに存在する通路の数を返す / Count the number of "corridor" grids adjacent to the given grid.
918 * @param y1 基準となるマスのY座標
919 * @param x1 基準となるマスのX座標
921 * @note Assumes "in_bounds(y1, x1)"
923 * XXX XXX This routine currently only counts actual "empty floor"\n
924 * grids which are not in rooms. We might want to also count stairs,\n
925 * open doors, closed doors, etc.
927 static int next_to_corr(floor_type *floor_ptr, POSITION y1, POSITION x1)
930 for (int i = 0; i < 4; i++)
932 POSITION y = y1 + ddy_ddd[i];
933 POSITION x = x1 + ddx_ddd[i];
935 g_ptr = &floor_ptr->grid_array[y][x];
937 if (cave_have_flag_grid(g_ptr, FF_WALL)) continue;
938 if (!is_floor_grid(g_ptr)) continue;
939 if (g_ptr->info & (CAVE_ROOM)) continue;
948 * @brief ドアを設置可能な地形かを返す / Determine if the given location is "between" two walls, and "next to" two corridor spaces.
949 * @param y 判定を行いたいマスのY座標
950 * @param x 判定を行いたいマスのX座標
951 * @return ドアを設置可能ならばTRUEを返す
952 * @note Assumes "in_bounds()"
955 * Assumes "in_bounds()"\n
957 static bool possible_doorway(floor_type *floor_ptr, POSITION y, POSITION x)
959 if (next_to_corr(floor_ptr, y, x) < 2) return FALSE;
962 if (cave_have_flag_bold(floor_ptr, y - 1, x, FF_WALL) &&
963 cave_have_flag_bold(floor_ptr, y + 1, x, FF_WALL))
968 /* Check Horizontal */
969 if (cave_have_flag_bold(floor_ptr, y, x - 1, FF_WALL) &&
970 cave_have_flag_bold(floor_ptr, y, x + 1, FF_WALL))
980 * @brief ドアの設置を試みる / Places door at y, x position if at least 2 walls found
981 * @param player_ptr プレーヤーへの参照ポインタ
982 * @param y 設置を行いたいマスのY座標
983 * @param x 設置を行いたいマスのX座標
986 void try_door(player_type *player_ptr, POSITION y, POSITION x)
988 floor_type *floor_ptr = player_ptr->current_floor_ptr;
989 if (!in_bounds(floor_ptr, y, x)) return;
991 if (cave_have_flag_bold(floor_ptr, y, x, FF_WALL)) return;
992 if (floor_ptr->grid_array[y][x].info & (CAVE_ROOM)) return;
994 bool can_place_door = randint0(100) < dun_tun_jct;
995 can_place_door &= possible_doorway(floor_ptr, y, x);
996 can_place_door &= (d_info[player_ptr->dungeon_idx].flags1 & DF1_NO_DOORS) == 0;
999 place_random_door(player_ptr, y, x, FALSE);
1004 FEAT_IDX conv_dungeon_feat(floor_type *floor_ptr, FEAT_IDX newfeat)
1006 feature_type *f_ptr = &f_info[newfeat];
1007 if (have_flag(f_ptr->flags, FF_CONVERT))
1009 switch (f_ptr->subtype)
1011 case CONVERT_TYPE_FLOOR:
1012 return feat_ground_type[randint0(100)];
1013 case CONVERT_TYPE_WALL:
1014 return feat_wall_type[randint0(100)];
1015 case CONVERT_TYPE_INNER:
1016 return feat_wall_inner;
1017 case CONVERT_TYPE_OUTER:
1018 return feat_wall_outer;
1019 case CONVERT_TYPE_SOLID:
1020 return feat_wall_solid;
1021 case CONVERT_TYPE_STREAM1:
1022 return d_info[floor_ptr->dungeon_idx].stream1;
1023 case CONVERT_TYPE_STREAM2:
1024 return d_info[floor_ptr->dungeon_idx].stream2;
1029 else return newfeat;
1034 * @brief 特殊な部屋向けに各種アイテムを配置する / Create up to "num" objects near the given coordinates
1035 * @param player_ptr プレーヤーへの参照ポインタ
1036 * @param y 配置したい中心マスのY座標
1037 * @param x 配置したい中心マスのX座標
1041 * Only really called by some of the "vault" routines.
1043 void vault_objects(player_type *player_ptr, POSITION y, POSITION x, int num)
1045 floor_type *floor_ptr = player_ptr->current_floor_ptr;
1046 for (; num > 0; --num)
1050 for (int i = 0; i < 11; ++i)
1052 while (dummy < SAFE_MAX_ATTEMPTS)
1054 j = rand_spread(y, 2);
1055 k = rand_spread(x, 3);
1057 if (!in_bounds(floor_ptr, j, k)) continue;
1061 if (dummy >= SAFE_MAX_ATTEMPTS && cheat_room)
1063 msg_print(_("警告!地下室のアイテムを配置できません!", "Warning! Could not place vault object!"));
1067 g_ptr = &floor_ptr->grid_array[j][k];
1068 if (!is_floor_grid(g_ptr) || g_ptr->o_idx) continue;
1070 if (randint0(100) < 75)
1072 place_object(player_ptr, j, k, 0L);
1076 place_gold(player_ptr, j, k);
1086 * @brief 始点から終点への直線経路を返す /
1087 * Determine the path taken by a projection.
1088 * @param player_ptr プレーヤーへの参照ポインタ
1089 * @param gp 経路座標リストを返す参照ポインタ
1099 * The projection will always start from the grid (y1,x1), and will travel
1100 * towards the grid (y2,x2), touching one grid per unit of distance along
1101 * the major axis, and stopping when it enters the destination grid or a
1102 * wall grid, or has travelled the maximum legal distance of "range".
1104 * Note that "distance" in this function (as in the "update_view()" code)
1105 * is defined as "MAX(dy,dx) + MIN(dy,dx)/2", which means that the player
1106 * actually has an "octagon of projection" not a "circle of projection".
1108 * The path grids are saved into the grid array pointed to by "gp", and
1109 * there should be room for at least "range" grids in "gp". Note that
1110 * due to the way in which distance is calculated, this function normally
1111 * uses fewer than "range" grids for the projection path, so the result
1112 * of this function should never be compared directly to "range". Note
1113 * that the initial grid (y1,x1) is never saved into the grid array, not
1114 * even if the initial grid is also the final grid.
1116 * The "flg" flags can be used to modify the behavior of this function.
1118 * In particular, the "PROJECT_STOP" and "PROJECT_THRU" flags have the same
1119 * semantics as they do for the "project" function, namely, that the path
1120 * will stop as soon as it hits a monster, or that the path will continue
1121 * through the destination grid, respectively.
1123 * The "PROJECT_JUMP" flag, which for the "project()" function means to
1124 * start at a special grid (which makes no sense in this function), means
1125 * that the path should be "angled" slightly if needed to avoid any wall
1126 * grids, allowing the player to "target" any grid which is in "view".
1127 * This flag is non-trivial and has not yet been implemented, but could
1128 * perhaps make use of the "vinfo" array (above).
1130 * This function returns the number of grids (if any) in the path. This
1131 * function will return zero if and only if (y1,x1) and (y2,x2) are equal.
1133 * This algorithm is similar to, but slightly different from, the one used
1134 * by "update_view_los()", and very different from the one used by "los()".
1137 sint project_path(player_type *player_ptr, u16b *gp, POSITION range, POSITION y1, POSITION x1, POSITION y2, POSITION x2, BIT_FLAGS flg)
1139 if ((x1 == x2) && (y1 == y2)) return 0;
1169 int half = (ay * ax);
1170 int full = half << 1;
1173 floor_type *floor_ptr = player_ptr->current_floor_ptr;
1191 gp[n++] = GRID(y, x);
1192 if ((n + (k >> 1)) >= range) break;
1194 if (!(flg & (PROJECT_THRU)))
1196 if ((x == x2) && (y == y2)) break;
1199 if (flg & (PROJECT_DISI))
1201 if ((n > 0) && cave_stop_disintegration(floor_ptr, y, x)) break;
1203 else if (flg & (PROJECT_LOS))
1205 if ((n > 0) && !cave_los_bold(floor_ptr, y, x)) break;
1207 else if (!(flg & (PROJECT_PATH)))
1209 if ((n > 0) && !cave_have_flag_bold(floor_ptr, y, x, FF_PROJECT)) break;
1212 if (flg & (PROJECT_STOP))
1215 (player_bold(player_ptr, y, x) || floor_ptr->grid_array[y][x].m_idx != 0))
1219 if (!in_bounds(floor_ptr, y, x)) break;
1254 gp[n++] = GRID(y, x);
1255 if ((n + (k >> 1)) >= range) break;
1257 if (!(flg & (PROJECT_THRU)))
1259 if ((x == x2) && (y == y2)) break;
1262 if (flg & (PROJECT_DISI))
1264 if ((n > 0) && cave_stop_disintegration(floor_ptr, y, x)) break;
1266 else if (flg & (PROJECT_LOS))
1268 if ((n > 0) && !cave_los_bold(floor_ptr, y, x)) break;
1270 else if (!(flg & (PROJECT_PATH)))
1272 if ((n > 0) && !cave_have_flag_bold(floor_ptr, y, x, FF_PROJECT)) break;
1275 if (flg & (PROJECT_STOP))
1278 (player_bold(player_ptr, y, x) || floor_ptr->grid_array[y][x].m_idx != 0))
1282 if (!in_bounds(floor_ptr, y, x)) break;
1306 gp[n++] = GRID(y, x);
1307 if ((n + (n >> 1)) >= range) break;
1309 if (!(flg & (PROJECT_THRU)))
1311 if ((x == x2) && (y == y2)) break;
1314 if (flg & (PROJECT_DISI))
1316 if ((n > 0) && cave_stop_disintegration(floor_ptr, y, x)) break;
1318 else if (flg & (PROJECT_LOS))
1320 if ((n > 0) && !cave_los_bold(floor_ptr, y, x)) break;
1322 else if (!(flg & (PROJECT_PATH)))
1324 if ((n > 0) && !cave_have_flag_bold(floor_ptr, y, x, FF_PROJECT)) break;
1327 if (flg & (PROJECT_STOP))
1330 (player_bold(player_ptr, y, x) || floor_ptr->grid_array[y][x].m_idx != 0))
1334 if (!in_bounds(floor_ptr, y, x)) break;
1345 * @brief 指定のマスを床地形に変える / Set a square to be floor. (Includes range checking.)
1346 * @param player_ptr プレーヤーへの参照ポインタ
1347 * @param x 地形を変えたいマスのX座標
1348 * @param y 地形を変えたいマスのY座標
1351 void set_floor(player_type *player_ptr, POSITION x, POSITION y)
1353 floor_type *floor_ptr = player_ptr->current_floor_ptr;
1354 if (!in_bounds(floor_ptr, y, x))
1359 if (floor_ptr->grid_array[y][x].info & CAVE_ROOM)
1364 if (is_extra_bold(floor_ptr, y, x))
1365 place_bold(player_ptr, y, x, gb_floor);
1370 * @brief フロアの指定位置に生成階に応じたベースアイテムの生成を行う。
1371 * Attempt to place an object (normal or good/great) at the given location.
1372 * @param owner_ptr プレーヤーへの参照ポインタ
1373 * @param y 配置したいフロアのY座標
1374 * @param x 配置したいフロアのX座標
1375 * @param mode オプションフラグ
1376 * @return 生成に成功したらTRUEを返す。
1378 * This routine plays nasty games to generate the "special artifacts".\n
1379 * This routine uses "object_level" for the "generation level".\n
1380 * This routine requires a clean floor grid destination.\n
1382 void place_object(player_type *owner_ptr, POSITION y, POSITION x, BIT_FLAGS mode)
1384 floor_type *floor_ptr = owner_ptr->current_floor_ptr;
1385 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
1388 if (!in_bounds(floor_ptr, y, x)) return;
1389 if (!cave_drop_bold(floor_ptr, y, x)) return;
1390 if (g_ptr->o_idx) return;
1394 if (!make_object(owner_ptr, q_ptr, mode)) return;
1396 OBJECT_IDX o_idx = o_pop(floor_ptr);
1399 if (object_is_fixed_artifact(q_ptr))
1401 a_info[q_ptr->name1].cur_num = 0;
1408 o_ptr = &floor_ptr->o_list[o_idx];
1409 object_copy(o_ptr, q_ptr);
1413 o_ptr->next_o_idx = g_ptr->o_idx;
1415 g_ptr->o_idx = o_idx;
1416 note_spot(owner_ptr, y, x);
1417 lite_spot(owner_ptr, y, x);
1422 * @brief フロアの指定位置に生成階に応じた財宝オブジェクトの生成を行う。
1423 * Places a treasure (Gold or Gems) at given location
1424 * @param player_ptr プレーヤーへの参照ポインタ
1425 * @param y 配置したいフロアのY座標
1426 * @param x 配置したいフロアのX座標
1427 * @return 生成に成功したらTRUEを返す。
1429 * The location must be a legal, clean, floor grid.
1431 void place_gold(player_type *player_ptr, POSITION y, POSITION x)
1433 floor_type *floor_ptr = player_ptr->current_floor_ptr;
1434 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
1435 if (!in_bounds(floor_ptr, y, x)) return;
1436 if (!cave_drop_bold(floor_ptr, y, x)) return;
1437 if (g_ptr->o_idx) return;
1443 if (!make_gold(floor_ptr, q_ptr)) return;
1445 OBJECT_IDX o_idx = o_pop(floor_ptr);
1446 if (o_idx == 0) return;
1449 o_ptr = &floor_ptr->o_list[o_idx];
1450 object_copy(o_ptr, q_ptr);
1454 o_ptr->next_o_idx = g_ptr->o_idx;
1456 g_ptr->o_idx = o_idx;
1457 note_spot(player_ptr, y, x);
1458 lite_spot(player_ptr, y, x);
1463 * @brief 指定位置に存在するモンスターを削除する / Delete the monster, if any, at a given location
1464 * @param player_ptr プレーヤーへの参照ポインタ
1469 void delete_monster(player_type *player_ptr, POSITION y, POSITION x)
1472 floor_type *floor_ptr = player_ptr->current_floor_ptr;
1473 if (!in_bounds(floor_ptr, y, x)) return;
1475 g_ptr = &floor_ptr->grid_array[y][x];
1476 if (g_ptr->m_idx) delete_monster_idx(player_ptr, g_ptr->m_idx);
1481 * @brief グローバルオブジェクト配列に対し指定範囲のオブジェクトを整理してIDの若い順に寄せる /
1482 * Move an object from index i1 to index i2 in the object list
1483 * @param i1 整理したい配列の始点
1484 * @param i2 整理したい配列の終点
1487 static void compact_objects_aux(floor_type *floor_ptr, OBJECT_IDX i1, OBJECT_IDX i2)
1489 if (i1 == i2) return;
1492 for (OBJECT_IDX i = 1; i < floor_ptr->o_max; i++)
1494 o_ptr = &floor_ptr->o_list[i];
1495 if (!o_ptr->k_idx) continue;
1497 if (o_ptr->next_o_idx == i1)
1499 o_ptr->next_o_idx = i2;
1503 o_ptr = &floor_ptr->o_list[i1];
1505 if (OBJECT_IS_HELD_MONSTER(o_ptr))
1507 monster_type *m_ptr;
1508 m_ptr = &floor_ptr->m_list[o_ptr->held_m_idx];
1509 if (m_ptr->hold_o_idx == i1)
1511 m_ptr->hold_o_idx = i2;
1516 POSITION y = o_ptr->iy;
1517 POSITION x = o_ptr->ix;
1519 g_ptr = &floor_ptr->grid_array[y][x];
1521 if (g_ptr->o_idx == i1)
1527 floor_ptr->o_list[i2] = floor_ptr->o_list[i1];
1533 * @brief グローバルオブジェクト配列から優先度の低いものを削除し、データを圧縮する。 /
1534 * Compact and Reorder the object list.
1535 * @param player_ptr プレーヤーへの参照ポインタ
1536 * @param size 最低でも減らしたいオブジェクト数の水準
1540 * This function can be very dangerous, use with caution!\n
1542 * When actually "compacting" objects, we base the saving throw on a\n
1543 * combination of object level, distance from player, and current\n
1546 * After "compacting" (if needed), we "reorder" the objects into a more\n
1547 * compact order, and we reset the allocation info, and the "live" array.\n
1549 void compact_objects(player_type *player_ptr, int size)
1554 msg_print(_("アイテム情報を圧縮しています...", "Compacting objects..."));
1555 player_ptr->redraw |= (PR_MAP);
1556 player_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
1559 floor_type *floor_ptr = player_ptr->current_floor_ptr;
1560 for (int num = 0, cnt = 1; num < size; cnt++)
1562 int cur_lev = 5 * cnt;
1563 int cur_dis = 5 * (20 - cnt);
1564 for (OBJECT_IDX i = 1; i < floor_ptr->o_max; i++)
1566 o_ptr = &floor_ptr->o_list[i];
1568 if (!OBJECT_IS_VALID(o_ptr)) continue;
1569 if (k_info[o_ptr->k_idx].level > cur_lev) continue;
1572 if (OBJECT_IS_HELD_MONSTER(o_ptr))
1574 monster_type *m_ptr;
1575 m_ptr = &floor_ptr->m_list[o_ptr->held_m_idx];
1579 if (randint0(100) < 90) continue;
1587 if ((cur_dis > 0) && (distance(player_ptr->y, player_ptr->x, y, x) < cur_dis)) continue;
1590 if ((object_is_fixed_artifact(o_ptr) || o_ptr->art_name) &&
1591 (cnt < 1000)) chance = 100;
1593 if (randint0(100) < chance) continue;
1595 delete_object_idx(player_ptr, i);
1600 for (OBJECT_IDX i = floor_ptr->o_max - 1; i >= 1; i--)
1602 o_ptr = &floor_ptr->o_list[i];
1603 if (o_ptr->k_idx) continue;
1605 compact_objects_aux(floor_ptr, floor_ptr->o_max - 1, i);
1612 * @brief 特殊な部屋向けに各種アイテムを配置する(メインルーチン) / Place some traps with a given displacement of given location
1613 * @param player_ptr プレーヤーへの参照ポインタ
1614 * @param y トラップを配置したいマスの中心Y座標
1615 * @param x トラップを配置したいマスの中心X座標
1616 * @param yd Y方向の配置分散マス数
1617 * @param xd X方向の配置分散マス数
1618 * @param num 配置したいトラップの数
1621 * Only really called by some of the "vault" routines.
1623 void vault_traps(player_type *player_ptr, POSITION y, POSITION x, POSITION yd, POSITION xd, int num)
1625 for (int i = 0; i < num; i++)
1627 vault_trap_aux(player_ptr, y, x, yd, xd);
1633 * Standard "find me a location" function
1635 * Obtains a legal location within the given distance of the initial
1636 * location, and with "los()" from the source to destination location.
1638 * This function is often called from inside a loop which searches for
1639 * locations while increasing the "d" distance.
1641 * Currently the "m" parameter is unused.
1643 void scatter(player_type *player_ptr, POSITION *yp, POSITION *xp, POSITION y, POSITION x, POSITION d, BIT_FLAGS mode)
1645 floor_type *floor_ptr = player_ptr->current_floor_ptr;
1649 ny = rand_spread(y, d);
1650 nx = rand_spread(x, d);
1652 if (!in_bounds(floor_ptr, ny, nx)) continue;
1653 if ((d > 1) && (distance(y, x, ny, nx) > d)) continue;
1654 if (mode & PROJECT_LOS)
1656 if (los(player_ptr, y, x, ny, nx)) break;
1660 if (projectable(player_ptr, y, x, ny, nx)) break;
1669 * @brief 指定のマスが光を通すか(LOSフラグを持つか)を返す。 / Aux function -- see below
1670 * @param floor_ptr 配置するフロアの参照ポインタ
1673 * @return 光を通すならばtrueを返す。
1675 bool cave_los_bold(floor_type *floor_ptr, POSITION y, POSITION x)
1677 return feat_supports_los(floor_ptr->grid_array[y][x].feat);