OSDN Git Service

[Refactor] #2713 PlayerType::dungeon_idx をFloorType::dungeon_idx へ吸収合併した
[hengbandforosx/hengbandosx.git] / src / grid / stair.cpp
1 #include "grid/stair.h"
2 #include "dungeon/quest.h"
3 #include "floor/cave.h"
4 #include "game-option/birth-options.h"
5 #include "grid/feature.h"
6 #include "grid/grid.h"
7 #include "system/dungeon-info.h"
8 #include "system/floor-type-definition.h"
9 #include "system/grid-type-definition.h"
10 #include "system/item-entity.h"
11 #include "system/player-type-definition.h"
12 #include "system/terrain-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(PlayerType *player_ptr, POSITION y, POSITION x)
21 {
22     bool up_stairs = true;
23     bool down_stairs = true;
24     auto &floor = *player_ptr->current_floor_ptr;
25     const auto *g_ptr = &floor.grid_array[y][x];
26     if (!g_ptr->is_floor() || !g_ptr->o_idx_list.empty()) {
27         return;
28     }
29
30     if (!floor.dun_level) {
31         up_stairs = false;
32     }
33
34     if (ironman_downward) {
35         up_stairs = false;
36     }
37
38     if (floor.dun_level >= dungeons_info[floor.dungeon_idx].maxdepth) {
39         down_stairs = false;
40     }
41
42     if (inside_quest(quest_number(floor, floor.dun_level)) && (floor.dun_level > 1)) {
43         down_stairs = false;
44     }
45
46     if (down_stairs && up_stairs) {
47         if (randint0(100) < 50) {
48             up_stairs = false;
49         } else {
50             down_stairs = false;
51         }
52     }
53
54     if (up_stairs) {
55         set_cave_feat(&floor, y, x, feat_up_stair);
56     } else if (down_stairs) {
57         set_cave_feat(&floor, y, x, feat_down_stair);
58     }
59 }
60
61 /*!
62  * @brief 指定された座標が地震や階段生成の対象となるマスかを返す。 / Determine if a given location may be "destroyed"
63  * @param player_ptr プレイヤーへの参照ポインタ
64  * @param y y座標
65  * @param x x座標
66  * @return 各種の変更が可能ならTRUEを返す。
67  * @details
68  * 条件は永久地形でなく、なおかつ該当のマスにアーティファクトが存在しないか、である。英語の旧コメントに反して*破壊*の抑止判定には現在使われていない。
69  */
70 bool cave_valid_bold(FloorType *floor_ptr, POSITION y, POSITION x)
71 {
72     auto *g_ptr = &floor_ptr->grid_array[y][x];
73     if (g_ptr->cave_has_flag(TerrainCharacteristics::PERMANENT)) {
74         return false;
75     }
76
77     for (const auto this_o_idx : g_ptr->o_idx_list) {
78         ItemEntity *o_ptr;
79         o_ptr = &floor_ptr->o_list[this_o_idx];
80         if (o_ptr->is_fixed_or_random_artifact()) {
81             return false;
82         }
83     }
84
85     return true;
86 }