1 #include "dungeon/dungeon-flag-types.h"
2 #include "dungeon/dungeon.h"
3 #include "effect/effect-characteristics.h"
4 #include "effect/effect-processor.h"
5 #include "floor/cave.h"
6 #include "floor/geometry.h"
7 #include "floor/floor-util.h"
8 #include "game-option/map-screen-options.h"
9 #include "grid/feature.h"
10 #include "grid/grid.h"
11 #include "mind/mind-ninja.h"
12 #include "monster-race/monster-race.h"
13 #include "monster-race/race-flags2.h"
14 #include "monster/monster-describer.h"
15 #include "monster/monster-status-setter.h"
16 #include "monster/monster-status.h"
17 #include "monster/monster-update.h"
18 #include "player/special-defense-types.h"
19 #include "spell-kind/spells-launcher.h"
20 #include "spell-kind/spells-lite.h"
21 #include "spell/spell-types.h"
22 #include "system/floor-type-definition.h"
23 #include "system/grid-type-definition.h"
24 #include "system/monster-race-definition.h"
25 #include "system/monster-type-definition.h"
26 #include "system/player-type-definition.h"
27 #include "target/projection-path-calculator.h"
28 #include "util/bit-flags-calculator.h"
29 #include "util/point-2d.h"
30 #include "view/display-messages.h"
31 #include "world/world.h"
34 using PassBoldFunc = bool (*)(floor_type *, POSITION, POSITION);
37 * @brief 指定した座標全てを照らす。
38 * @param player_ptr プレーヤーへの参照ポインタ
39 * @param points 明るくすべき座標たち
42 * This routine clears the entire "temp" set.
43 * This routine will Perma-Lite all "temp" grids.
44 * This routine is used (only) by "lite_room()"
45 * Dark grids are illuminated.
46 * Also, process all affected monsters.
48 * SMART monsters always wake up when illuminated
49 * NORMAL monsters wake up 1/4 the time when illuminated
50 * STUPID monsters wake up 1/10 the time when illuminated
52 * @todo この辺、xとyが引数になっているが、player_ptr->xとplayer_ptr->yで全て置き換えが効くはず……
54 static void cave_temp_room_lite(player_type *player_ptr, const std::vector<Pos2D> &points)
56 for (const auto &point : points) {
57 const POSITION y = point.y;
58 const POSITION x = point.x;
60 grid_type *g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
61 g_ptr->info &= ~(CAVE_TEMP);
62 g_ptr->info |= (CAVE_GLOW);
64 PERCENTAGE chance = 25;
65 monster_type *m_ptr = &player_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
66 monster_race *r_ptr = &r_info[m_ptr->r_idx];
67 update_monster(player_ptr, g_ptr->m_idx, false);
68 if (r_ptr->flags2 & (RF2_STUPID))
70 if (r_ptr->flags2 & (RF2_SMART))
73 if (monster_csleep_remaining(m_ptr) && (randint0(100) < chance)) {
74 (void)set_monster_csleep(player_ptr, g_ptr->m_idx, 0);
76 GAME_TEXT m_name[MAX_NLEN];
77 monster_desc(player_ptr, m_name, m_ptr, 0);
78 msg_format(_("%^sが目を覚ました。", "%^s wakes up."), m_name);
83 note_spot(player_ptr, y, x);
84 lite_spot(player_ptr, y, x);
85 update_local_illumination(player_ptr, y, x);
90 * @brief 指定した座標全てを暗くする。
91 * @param player_ptr プレーヤーへの参照ポインタ
92 * @param points 暗くすべき座標たち
95 * This routine clears the entire "temp" set.
96 * This routine will "darken" all "temp" grids.
97 * In addition, some of these grids will be "unmarked".
98 * This routine is used (only) by "unlite_room()"
99 * Also, process all affected monsters
101 * @todo この辺、xとyが引数になっているが、player_ptr->xとplayer_ptr->yで全て置き換えが効くはず……
103 static void cave_temp_room_unlite(player_type *player_ptr, const std::vector<Pos2D> &points)
105 for (const auto &point : points) {
106 const POSITION y = point.y;
107 const POSITION x = point.x;
109 grid_type *g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
110 bool do_dark = !g_ptr->is_mirror();
111 g_ptr->info &= ~(CAVE_TEMP);
115 if (player_ptr->current_floor_ptr->dun_level || !is_daytime()) {
116 for (int j = 0; j < 9; j++) {
117 POSITION by = y + ddy_ddd[j];
118 POSITION bx = x + ddx_ddd[j];
120 if (in_bounds2(player_ptr->current_floor_ptr, by, bx)) {
121 grid_type *cc_ptr = &player_ptr->current_floor_ptr->grid_array[by][bx];
123 if (f_info[cc_ptr->get_feat_mimic()].flags.has(FF::GLOW)) {
134 g_ptr->info &= ~(CAVE_GLOW);
135 if (f_info[g_ptr->get_feat_mimic()].flags.has_not(FF::REMEMBER)) {
136 if (!view_torch_grids)
137 g_ptr->info &= ~(CAVE_MARK);
138 note_spot(player_ptr, y, x);
142 update_monster(player_ptr, g_ptr->m_idx, false);
145 lite_spot(player_ptr, y, x);
146 update_local_illumination(player_ptr, y, x);
151 * @brief 周辺に関数ポインタの条件に該当する地形がいくつあるかを計算する / Determine how much contiguous open space this grid is next to
152 * @param floor_ptr 配置するフロアの参照ポインタ
155 * @param pass_bold 地形条件を返す関数ポインタ
158 static int next_to_open(floor_type *floor_ptr, const POSITION cy, const POSITION cx, const PassBoldFunc pass_bold)
162 for (int i = 0; i < 16; i++) {
163 POSITION y = cy + ddy_cdd[i % 8];
164 POSITION x = cx + ddx_cdd[i % 8];
165 if (!pass_bold(floor_ptr, y, x)) {
176 return MAX(len, blen);
180 * @brief 周辺に関数ポインタの条件に該当する地形がいくつあるかを計算する / Determine how much contiguous open space this grid is next to
181 * @param floor_ptr 配置するフロアの参照ポインタ
184 * @param pass_bold 地形条件を返す関数ポインタ
187 static int next_to_walls_adj(floor_type *floor_ptr, const POSITION cy, const POSITION cx, const PassBoldFunc pass_bold)
191 for (DIRECTION i = 0; i < 8; i++) {
195 if (!pass_bold(floor_ptr, y, x))
203 * @brief (y,x) が指定条件を満たすなら points に加える
204 * @param player_ptr プレーヤーへの参照ポインタ
205 * @param points 座標記録用配列
208 * @param only_room 部屋内地形のみをチェック対象にするならば TRUE
209 * @param pass_bold 地形条件を返す関数ポインタ
211 static void cave_temp_room_aux(
212 player_type *player_ptr, std::vector<Pos2D> &points, const POSITION y, const POSITION x, const bool only_room, const PassBoldFunc pass_bold)
214 floor_type *floor_ptr = player_ptr->current_floor_ptr;
215 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
217 // 既に points に追加済みなら何もしない。
218 if (g_ptr->info & (CAVE_TEMP))
221 if (!(g_ptr->info & (CAVE_ROOM))) {
224 if (!in_bounds2(floor_ptr, y, x))
226 if (distance(player_ptr->y, player_ptr->x, y, x) > get_max_range(player_ptr))
229 /* Verify this grid */
231 * The reason why it is ==6 instead of >5 is that 8 is impossible
232 * due to the check for cave_bold above.
233 * 7 lights dead-end corridors (you need to do this for the
234 * checkboard interesting rooms, so that the boundary is lit
236 * This leaves only a check for 6 bounding walls!
238 if (in_bounds(floor_ptr, y, x) && pass_bold(floor_ptr, y, x) && (next_to_walls_adj(floor_ptr, y, x, pass_bold) == 6)
239 && (next_to_open(floor_ptr, y, x, pass_bold) <= 1))
243 // (y,x) を points に追加し、追加済みフラグを立てる。
244 points.emplace_back(y, x);
245 g_ptr->info |= (CAVE_TEMP);
249 * @brief (y,x) が明るくすべきマスなら points に加える
250 * @param player_ptr プレーヤーへの参照ポインタ
251 * @param points 座標記録用配列
255 static void cave_temp_lite_room_aux(player_type *player_ptr, std::vector<Pos2D> &points, const POSITION y, const POSITION x)
257 cave_temp_room_aux(player_ptr, points, y, x, false, cave_los_bold);
261 * @brief 指定のマスが光を通さず射線のみを通すかを返す。 / Aux function -- see below
262 * @param floor_ptr 配置するフロアの参照ポインタ
265 * @return 射線を通すならばtrueを返す。
267 static bool cave_pass_dark_bold(floor_type *floor_ptr, POSITION y, POSITION x) { return cave_has_flag_bold(floor_ptr, y, x, FF::PROJECT); }
270 * @brief (y,x) が暗くすべきマスなら points に加える
271 * @param player_ptr プレーヤーへの参照ポインタ
275 static void cave_temp_unlite_room_aux(player_type *player_ptr, std::vector<Pos2D> &points, const POSITION y, const POSITION x)
277 cave_temp_room_aux(player_ptr, points, y, x, true, cave_pass_dark_bold);
281 * @brief (y1,x1) を含む全ての部屋を照らす。 / Illuminate any room containing the given location.
282 * @param player_ptr プレーヤーへの参照ポインタ
288 void lite_room(player_type *player_ptr, const POSITION y1, const POSITION x1)
291 std::vector<Pos2D> points;
293 floor_type *floor_ptr = player_ptr->current_floor_ptr;
295 // (y1,x1) を起点として明るくするマスを記録していく。
297 cave_temp_lite_room_aux(player_ptr, points, y1, x1);
298 for (size_t i = 0; i < size(points); i++) {
299 const auto &point = points[i];
300 const POSITION y = point.y;
301 const POSITION x = point.x;
303 if (!cave_los_bold(floor_ptr, y, x))
306 cave_temp_lite_room_aux(player_ptr, points, y + 1, x);
307 cave_temp_lite_room_aux(player_ptr, points, y - 1, x);
308 cave_temp_lite_room_aux(player_ptr, points, y, x + 1);
309 cave_temp_lite_room_aux(player_ptr, points, y, x - 1);
311 cave_temp_lite_room_aux(player_ptr, points, y + 1, x + 1);
312 cave_temp_lite_room_aux(player_ptr, points, y - 1, x - 1);
313 cave_temp_lite_room_aux(player_ptr, points, y - 1, x + 1);
314 cave_temp_lite_room_aux(player_ptr, points, y + 1, x - 1);
318 cave_temp_room_lite(player_ptr, points);
321 if (player_ptr->special_defense & NINJA_S_STEALTH) {
322 if (floor_ptr->grid_array[player_ptr->y][player_ptr->x].info & CAVE_GLOW)
323 set_superstealth(player_ptr, false);
328 * @brief (y1,x1) を含む全ての部屋を暗くする。 / Darken all rooms containing the given location
329 * @param player_ptr プレーヤーへの参照ポインタ
333 void unlite_room(player_type *player_ptr, const POSITION y1, const POSITION x1)
336 std::vector<Pos2D> points;
338 floor_type *floor_ptr = player_ptr->current_floor_ptr;
340 // (y1,x1) を起点として暗くするマスを記録していく。
342 cave_temp_unlite_room_aux(player_ptr, points, y1, x1);
343 for (size_t i = 0; i < size(points); i++) {
344 const auto &point = points[i];
345 const POSITION y = point.y;
346 const POSITION x = point.x;
348 if (!cave_pass_dark_bold(floor_ptr, y, x))
351 cave_temp_unlite_room_aux(player_ptr, points, y + 1, x);
352 cave_temp_unlite_room_aux(player_ptr, points, y - 1, x);
353 cave_temp_unlite_room_aux(player_ptr, points, y, x + 1);
354 cave_temp_unlite_room_aux(player_ptr, points, y, x - 1);
356 cave_temp_unlite_room_aux(player_ptr, points, y + 1, x + 1);
357 cave_temp_unlite_room_aux(player_ptr, points, y - 1, x - 1);
358 cave_temp_unlite_room_aux(player_ptr, points, y - 1, x + 1);
359 cave_temp_unlite_room_aux(player_ptr, points, y + 1, x - 1);
363 cave_temp_room_unlite(player_ptr, points);
367 * @brief スターライトの効果を発生させる
368 * @param player_ptr プレーヤーへの参照ポインタ
369 * @param magic 魔法による効果であればTRUE、スターライトの杖による効果であればFALSE
372 bool starlight(player_type *player_ptr, bool magic)
374 if (!player_ptr->blind && !magic) {
375 msg_print(_("杖の先が明るく輝いた...", "The end of the staff glows brightly..."));
378 HIT_POINT num = damroll(5, 3);
380 POSITION y = 0, x = 0;
381 for (int k = 0; k < num; k++) {
385 scatter(player_ptr, &y, &x, player_ptr->y, player_ptr->x, 4, PROJECT_LOS);
386 if (!cave_has_flag_bold(player_ptr->current_floor_ptr, y, x, FF::PROJECT))
388 if (!player_bold(player_ptr, y, x))
392 project(player_ptr, 0, 0, y, x, damroll(6 + player_ptr->lev / 8, 10), GF_LITE_WEAK,
393 (PROJECT_BEAM | PROJECT_THRU | PROJECT_GRID | PROJECT_KILL | PROJECT_LOS));
400 * @brief プレイヤー位置を中心にLITE_WEAK属性を通じた照明処理を行う / Hack -- call light around the player Affect all monsters in the projection radius
401 * @param player_ptr プレーヤーへの参照ポインタ
404 * @return 作用が実際にあった場合TRUEを返す
406 bool lite_area(player_type *player_ptr, HIT_POINT dam, POSITION rad)
408 if (d_info[player_ptr->dungeon_idx].flags.has(DF::DARKNESS)) {
409 msg_print(_("ダンジョンが光を吸収した。", "The darkness of this dungeon absorbs your light."));
413 if (!player_ptr->blind) {
414 msg_print(_("白い光が辺りを覆った。", "You are surrounded by a white light."));
417 BIT_FLAGS flg = PROJECT_GRID | PROJECT_KILL;
418 (void)project(player_ptr, 0, rad, player_ptr->y, player_ptr->x, dam, GF_LITE_WEAK, flg);
420 lite_room(player_ptr, player_ptr->y, player_ptr->x);
426 * @brief プレイヤー位置を中心にLITE_DARK属性を通じた消灯処理を行う / Hack -- call light around the player Affect all monsters in the projection radius
427 * @param player_ptr プレーヤーへの参照ポインタ
430 * @return 作用が実際にあった場合TRUEを返す
432 bool unlite_area(player_type *player_ptr, HIT_POINT dam, POSITION rad)
434 if (!player_ptr->blind) {
435 msg_print(_("暗闇が辺りを覆った。", "Darkness surrounds you."));
438 BIT_FLAGS flg = PROJECT_GRID | PROJECT_KILL;
439 (void)project(player_ptr, 0, rad, player_ptr->y, player_ptr->x, dam, GF_DARK_WEAK, flg);
441 unlite_room(player_ptr, player_ptr->y, player_ptr->x);
447 * @brief LITE_WEAK属性による光源ビーム処理
448 * @param player_ptr プレーヤーへの参照ポインタ
449 * @param dir 方向(5ならばグローバル変数 target_col/target_row の座標を目標にする)
451 * @return 作用が実際にあった場合TRUEを返す
453 bool lite_line(player_type *player_ptr, DIRECTION dir, HIT_POINT dam)
455 BIT_FLAGS flg = PROJECT_BEAM | PROJECT_GRID | PROJECT_KILL;
456 return (project_hook(player_ptr, GF_LITE_WEAK, dir, dam, flg));