OSDN Git Service

Merge pull request #857 from sikabane-works/feature/fix-doxygen-syntax
[hengbandforosx/hengbandosx.git] / src / room / vault-builder.cpp
1 #include "room/vault-builder.h"
2 #include "floor/cave.h"
3 #include "floor/floor-generator-util.h"
4 #include "floor/floor-util.h"
5 #include "game-option/cheat-options.h"
6 #include "grid/feature-flag-types.h"
7 #include "grid/grid.h"
8 #include "grid/object-placer.h"
9 #include "grid/trap.h"
10 #include "monster-floor/monster-generator.h"
11 #include "monster-floor/place-monster-types.h"
12 #include "system/floor-type-definition.h"
13 #include "view/display-messages.h"
14
15 /*
16  * Grid based version of "creature_bold()"
17  */
18 static bool player_grid(player_type *player_ptr, grid_type *g_ptr) { return g_ptr == &player_ptr->current_floor_ptr->grid_array[player_ptr->y][player_ptr->x]; }
19
20 /*
21  * Grid based version of "cave_empty_bold()"
22  */
23 static bool is_cave_empty_grid(player_type *player_ptr, grid_type *g_ptr)
24 {
25     bool is_empty_grid = cave_has_flag_grid(g_ptr, FF_PLACE);
26     is_empty_grid &= g_ptr->m_idx == 0;
27     is_empty_grid &= !player_grid(player_ptr, g_ptr);
28     return is_empty_grid;
29 }
30
31 /*!
32  * @brief 特殊な部屋地形向けにモンスターを配置する / Place some sleeping monsters near the given location
33  * @param player_ptr プレーヤーへの参照ポインタ
34  * @param y1 モンスターを配置したいマスの中心Y座標
35  * @param x1 モンスターを配置したいマスの中心X座標
36  * @param num 配置したいモンスターの数
37  * @return なし
38  * @details
39  * Only really called by some of the "vault" routines.
40  */
41 void vault_monsters(player_type *player_ptr, POSITION y1, POSITION x1, int num)
42 {
43     floor_type *floor_ptr = player_ptr->current_floor_ptr;
44     for (int k = 0; k < num; k++) {
45         for (int i = 0; i < 9; i++) {
46             int d = 1;
47             POSITION y, x;
48             scatter(player_ptr, &y, &x, y1, x1, d, 0);
49             grid_type *g_ptr;
50             g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
51             if (!is_cave_empty_grid(player_ptr, g_ptr))
52                 continue;
53
54             floor_ptr->monster_level = floor_ptr->base_level + 2;
55             (void)place_monster(player_ptr, y, x, PM_ALLOW_SLEEP | PM_ALLOW_GROUP);
56             floor_ptr->monster_level = floor_ptr->base_level;
57         }
58     }
59 }
60
61 /*!
62  * @brief 特殊な部屋向けに各種アイテムを配置する / Create up to "num" objects near the given coordinates
63  * @param player_ptr プレーヤーへの参照ポインタ
64  * @param y 配置したい中心マスのY座標
65  * @param x 配置したい中心マスのX座標
66  * @param num 配置したい数
67  * @return なし
68  * @details
69  * Only really called by some of the "vault" routines.
70  */
71 void vault_objects(player_type *player_ptr, POSITION y, POSITION x, int num)
72 {
73     floor_type *floor_ptr = player_ptr->current_floor_ptr;
74     for (; num > 0; --num) {
75         int j = y, k = x;
76         int dummy = 0;
77         for (int i = 0; i < 11; ++i) {
78             while (dummy < SAFE_MAX_ATTEMPTS) {
79                 j = rand_spread(y, 2);
80                 k = rand_spread(x, 3);
81                 dummy++;
82                 if (!in_bounds(floor_ptr, j, k))
83                     continue;
84                 break;
85             }
86
87             if (dummy >= SAFE_MAX_ATTEMPTS && cheat_room) {
88                 msg_print(_("警告!地下室のアイテムを配置できません!", "Warning! Could not place vault object!"));
89             }
90
91             grid_type *g_ptr;
92             g_ptr = &floor_ptr->grid_array[j][k];
93             if (!is_floor_grid(g_ptr) || g_ptr->o_idx)
94                 continue;
95
96             if (randint0(100) < 75) {
97                 place_object(player_ptr, j, k, 0L);
98             } else {
99                 place_gold(player_ptr, j, k);
100             }
101
102             break;
103         }
104     }
105 }
106
107 /*!
108  * @brief 特殊な部屋向けに各種アイテムを配置する(vault_trapのサブセット) / Place a trap with a given displacement of point
109  * @param y トラップを配置したいマスの中心Y座標
110  * @param x トラップを配置したいマスの中心X座標
111  * @param yd Y方向の配置分散マス数
112  * @param xd X方向の配置分散マス数
113  * @return なし
114  * @details
115  * Only really called by some of the "vault" routines.
116  */
117 static void vault_trap_aux(player_type *player_ptr, POSITION y, POSITION x, POSITION yd, POSITION xd)
118 {
119     grid_type *g_ptr;
120     floor_type *floor_ptr = player_ptr->current_floor_ptr;
121     int y1 = y, x1 = x;
122     int dummy = 0;
123     for (int count = 0; count <= 5; count++) {
124         while (dummy < SAFE_MAX_ATTEMPTS) {
125             y1 = rand_spread(y, yd);
126             x1 = rand_spread(x, xd);
127             dummy++;
128             if (!in_bounds(floor_ptr, y1, x1))
129                 continue;
130             break;
131         }
132
133         if (dummy >= SAFE_MAX_ATTEMPTS && cheat_room) {
134             msg_print(_("警告!地下室のトラップを配置できません!", "Warning! Could not place vault trap!"));
135         }
136
137         g_ptr = &floor_ptr->grid_array[y1][x1];
138         if (!is_floor_grid(g_ptr) || g_ptr->o_idx || g_ptr->m_idx)
139             continue;
140
141         place_trap(player_ptr, y1, x1);
142         break;
143     }
144 }
145
146 /*!
147  * @brief 特殊な部屋向けに各種アイテムを配置する(メインルーチン) / Place some traps with a given displacement of given location
148  * @param player_ptr プレーヤーへの参照ポインタ
149  * @param y トラップを配置したいマスの中心Y座標
150  * @param x トラップを配置したいマスの中心X座標
151  * @param yd Y方向の配置分散マス数
152  * @param xd X方向の配置分散マス数
153  * @param num 配置したいトラップの数
154  * @return なし
155  * @details
156  * Only really called by some of the "vault" routines.
157  * @todo rooms-normal からしか呼ばれていない、要調整
158  */
159 void vault_traps(player_type *player_ptr, POSITION y, POSITION x, POSITION yd, POSITION xd, int num)
160 {
161     for (int i = 0; i < num; i++)
162         vault_trap_aux(player_ptr, y, x, yd, xd);
163 }