OSDN Git Service

9df1ad51dbf2127653ee57095b3f2c4723a1dbf8
[hengbandforosx/hengbandosx.git] / src / grid / stair.cpp
1 #include "grid/stair.h"
2 #include "dungeon/dungeon.h"
3 #include "dungeon/quest.h"
4 #include "game-option/birth-options.h"
5 #include "floor/cave.h"
6 #include "grid/feature.h"
7 #include "grid/grid.h"
8 #include "object-hook/hook-enchant.h"
9 #include "system/floor-type-definition.h"
10 #include "system/grid-type-definition.h"
11 #include "system/object-type-definition.h"
12 #include "system/player-type-definition.h"
13
14 /*!
15  * @brief 所定の位置に上り階段か下り階段を配置する / Place an up/down staircase at given location
16  * @param player_ptr プレーヤーへの参照ポインタ
17  * @param y 配置を試みたいマスのY座標
18  * @param x 配置を試みたいマスのX座標
19  */
20 void place_random_stairs(player_type *player_ptr, POSITION y, POSITION x)
21 {
22     bool up_stairs = true;
23     bool down_stairs = true;
24     grid_type *g_ptr;
25     floor_type *floor_ptr = player_ptr->current_floor_ptr;
26     g_ptr = &floor_ptr->grid_array[y][x];
27     if (!g_ptr->is_floor() || !g_ptr->o_idx_list.empty())
28         return;
29
30     if (!floor_ptr->dun_level)
31         up_stairs = false;
32
33     if (ironman_downward)
34         up_stairs = false;
35
36     if (floor_ptr->dun_level >= d_info[player_ptr->dungeon_idx].maxdepth)
37         down_stairs = false;
38
39     if (quest_number(player_ptr, floor_ptr->dun_level) && (floor_ptr->dun_level > 1))
40         down_stairs = false;
41
42     if (down_stairs && up_stairs) {
43         if (randint0(100) < 50)
44             up_stairs = false;
45         else
46             down_stairs = false;
47     }
48
49     if (up_stairs)
50         set_cave_feat(floor_ptr, y, x, feat_up_stair);
51     else if (down_stairs)
52         set_cave_feat(floor_ptr, y, x, feat_down_stair);
53 }
54
55 /*!
56  * @brief 指定された座標が地震や階段生成の対象となるマスかを返す。 / Determine if a given location may be "destroyed"
57  * @param player_ptr プレーヤーへの参照ポインタ
58  * @param y y座標
59  * @param x x座標
60  * @return 各種の変更が可能ならTRUEを返す。
61  * @details
62  * 条件は永久地形でなく、なおかつ該当のマスにアーティファクトが存在しないか、である。英語の旧コメントに反して*破壊*の抑止判定には現在使われていない。
63  */
64 bool cave_valid_bold(floor_type *floor_ptr, POSITION y, POSITION x)
65 {
66     grid_type *g_ptr = &floor_ptr->grid_array[y][x];
67     if (cave_has_flag_grid(g_ptr, FF_PERMANENT))
68         return false;
69
70     for (const auto this_o_idx : g_ptr->o_idx_list) {
71         object_type *o_ptr;
72         o_ptr = &floor_ptr->o_list[this_o_idx];
73         if (object_is_artifact(o_ptr))
74             return false;
75     }
76
77     return true;
78 }