1 #include "spell-kind/spells-lite.h"
2 #include "dungeon/dungeon-flag-types.h"
3 #include "effect/attribute-types.h"
4 #include "effect/effect-characteristics.h"
5 #include "effect/effect-processor.h"
6 #include "floor/cave.h"
7 #include "floor/floor-util.h"
8 #include "floor/geometry.h"
9 #include "game-option/map-screen-options.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 "system/dungeon-info.h"
21 #include "system/floor-type-definition.h"
22 #include "system/grid-type-definition.h"
23 #include "system/monster-entity.h"
24 #include "system/monster-race-info.h"
25 #include "system/player-type-definition.h"
26 #include "system/terrain-type-definition.h"
27 #include "target/projection-path-calculator.h"
28 #include "timed-effect/player-blindness.h"
29 #include "timed-effect/timed-effects.h"
30 #include "util/bit-flags-calculator.h"
31 #include "util/point-2d.h"
32 #include "view/display-messages.h"
33 #include "world/world.h"
36 using PassBoldFunc = bool (*)(FloorType *, POSITION, POSITION);
39 * @brief 指定した座標全てを照らす。
40 * @param player_ptr プレイヤーへの参照ポインタ
41 * @param points 明るくすべき座標たち
44 * This routine clears the entire "temp" set.
45 * This routine will Perma-Lite all "temp" grids.
46 * This routine is used (only) by "lite_room()"
47 * Dark grids are illuminated.
48 * Also, process all affected monsters.
50 * SMART monsters always wake up when illuminated
51 * NORMAL monsters wake up 1/4 the time when illuminated
52 * STUPID monsters wake up 1/10 the time when illuminated
54 * @todo この辺、xとyが引数になっているが、player_ptr->xとplayer_ptr->yで全て置き換えが効くはず……
56 static void cave_temp_room_lite(PlayerType *player_ptr, const std::vector<Pos2D> &points)
58 for (const auto &point : points) {
59 const POSITION y = point.y;
60 const POSITION x = point.x;
62 auto *g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
63 g_ptr->info &= ~(CAVE_TEMP);
64 g_ptr->info |= (CAVE_GLOW);
66 PERCENTAGE chance = 25;
67 auto *m_ptr = &player_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
68 auto *r_ptr = &monraces_info[m_ptr->r_idx];
69 update_monster(player_ptr, g_ptr->m_idx, false);
70 if (r_ptr->behavior_flags.has(MonsterBehaviorType::STUPID)) {
73 if (r_ptr->behavior_flags.has(MonsterBehaviorType::SMART)) {
77 if (m_ptr->is_asleep() && (randint0(100) < chance)) {
78 (void)set_monster_csleep(player_ptr, g_ptr->m_idx, 0);
80 const auto m_name = monster_desc(player_ptr, m_ptr, 0);
81 msg_format(_("%s^が目を覚ました。", "%s^ wakes up."), m_name.data());
86 note_spot(player_ptr, y, x);
87 lite_spot(player_ptr, y, x);
88 update_local_illumination(player_ptr, y, x);
93 * @brief 指定した座標全てを暗くする。
94 * @param player_ptr プレイヤーへの参照ポインタ
95 * @param points 暗くすべき座標たち
98 * This routine clears the entire "temp" set.
99 * This routine will "darken" all "temp" grids.
100 * In addition, some of these grids will be "unmarked".
101 * This routine is used (only) by "unlite_room()"
102 * Also, process all affected monsters
104 * @todo この辺、xとyが引数になっているが、player_ptr->xとplayer_ptr->yで全て置き換えが効くはず……
106 static void cave_temp_room_unlite(PlayerType *player_ptr, const std::vector<Pos2D> &points)
108 for (const auto &point : points) {
109 const POSITION y = point.y;
110 const POSITION x = point.x;
112 auto *g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
113 bool do_dark = !g_ptr->is_mirror();
114 g_ptr->info &= ~(CAVE_TEMP);
119 if (player_ptr->current_floor_ptr->dun_level || !is_daytime()) {
120 for (int j = 0; j < 9; j++) {
121 POSITION by = y + ddy_ddd[j];
122 POSITION bx = x + ddx_ddd[j];
124 if (in_bounds2(player_ptr->current_floor_ptr, by, bx)) {
125 grid_type *cc_ptr = &player_ptr->current_floor_ptr->grid_array[by][bx];
127 if (terrains_info[cc_ptr->get_feat_mimic()].flags.has(TerrainCharacteristics::GLOW)) {
139 g_ptr->info &= ~(CAVE_GLOW);
140 if (terrains_info[g_ptr->get_feat_mimic()].flags.has_not(TerrainCharacteristics::REMEMBER)) {
141 if (!view_torch_grids) {
142 g_ptr->info &= ~(CAVE_MARK);
144 note_spot(player_ptr, y, x);
148 update_monster(player_ptr, g_ptr->m_idx, false);
151 lite_spot(player_ptr, y, x);
152 update_local_illumination(player_ptr, y, x);
157 * @brief 周辺に関数ポインタの条件に該当する地形がいくつあるかを計算する / Determine how much contiguous open space this grid is next to
158 * @param floor_ptr 配置するフロアの参照ポインタ
161 * @param pass_bold 地形条件を返す関数ポインタ
164 static int next_to_open(FloorType *floor_ptr, const POSITION cy, const POSITION cx, const PassBoldFunc pass_bold)
168 for (int i = 0; i < 16; i++) {
169 POSITION y = cy + ddy_cdd[i % 8];
170 POSITION x = cx + ddx_cdd[i % 8];
171 if (!pass_bold(floor_ptr, y, x)) {
182 return std::max(len, blen);
186 * @brief 周辺に関数ポインタの条件に該当する地形がいくつあるかを計算する / Determine how much contiguous open space this grid is next to
187 * @param floor_ptr 配置するフロアの参照ポインタ
190 * @param pass_bold 地形条件を返す関数ポインタ
193 static int next_to_walls_adj(FloorType *floor_ptr, const POSITION cy, const POSITION cx, const PassBoldFunc pass_bold)
197 for (DIRECTION i = 0; i < 8; i++) {
201 if (!pass_bold(floor_ptr, y, x)) {
210 * @brief (y,x) が指定条件を満たすなら points に加える
211 * @param player_ptr プレイヤーへの参照ポインタ
212 * @param points 座標記録用配列
215 * @param only_room 部屋内地形のみをチェック対象にするならば TRUE
216 * @param pass_bold 地形条件を返す関数ポインタ
218 static void cave_temp_room_aux(
219 PlayerType *player_ptr, std::vector<Pos2D> &points, const POSITION y, const POSITION x, const bool only_room, const PassBoldFunc pass_bold)
221 auto *floor_ptr = player_ptr->current_floor_ptr;
222 auto *g_ptr = &floor_ptr->grid_array[y][x];
224 // 既に points に追加済みなら何もしない。
225 if (g_ptr->info & (CAVE_TEMP)) {
229 if (!(g_ptr->info & (CAVE_ROOM))) {
233 if (!in_bounds2(floor_ptr, y, x)) {
236 if (distance(player_ptr->y, player_ptr->x, y, x) > get_max_range(player_ptr)) {
240 /* Verify this grid */
242 * The reason why it is ==6 instead of >5 is that 8 is impossible
243 * due to the check for cave_bold above.
244 * 7 lights dead-end corridors (you need to do this for the
245 * checkboard interesting rooms, so that the boundary is lit
247 * This leaves only a check for 6 bounding walls!
249 if (in_bounds(floor_ptr, y, x) && pass_bold(floor_ptr, y, x) && (next_to_walls_adj(floor_ptr, y, x, pass_bold) == 6) && (next_to_open(floor_ptr, y, x, pass_bold) <= 1)) {
254 // (y,x) を points に追加し、追加済みフラグを立てる。
255 points.emplace_back(y, x);
256 g_ptr->info |= (CAVE_TEMP);
260 * @brief (y,x) が明るくすべきマスなら points に加える
261 * @param player_ptr プレイヤーへの参照ポインタ
262 * @param points 座標記録用配列
266 static void cave_temp_lite_room_aux(PlayerType *player_ptr, std::vector<Pos2D> &points, const POSITION y, const POSITION x)
268 cave_temp_room_aux(player_ptr, points, y, x, false, cave_los_bold);
272 * @brief 指定のマスが光を通さず射線のみを通すかを返す。 / Aux function -- see below
273 * @param floor_ptr 配置するフロアの参照ポインタ
276 * @return 射線を通すならばtrueを返す。
278 static bool cave_pass_dark_bold(FloorType *floor_ptr, POSITION y, POSITION x)
280 return cave_has_flag_bold(floor_ptr, y, x, TerrainCharacteristics::PROJECT);
284 * @brief (y,x) が暗くすべきマスなら points に加える
285 * @param player_ptr プレイヤーへの参照ポインタ
289 static void cave_temp_unlite_room_aux(PlayerType *player_ptr, std::vector<Pos2D> &points, const POSITION y, const POSITION x)
291 cave_temp_room_aux(player_ptr, points, y, x, true, cave_pass_dark_bold);
295 * @brief (y1,x1) を含む全ての部屋を照らす。 / Illuminate any room containing the given location.
296 * @param player_ptr プレイヤーへの参照ポインタ
302 void lite_room(PlayerType *player_ptr, const POSITION y1, const POSITION x1)
305 std::vector<Pos2D> points;
307 auto *floor_ptr = player_ptr->current_floor_ptr;
309 // (y1,x1) を起点として明るくするマスを記録していく。
311 cave_temp_lite_room_aux(player_ptr, points, y1, x1);
312 for (size_t i = 0; i < size(points); i++) {
313 const auto &point = points[i];
314 const POSITION y = point.y;
315 const POSITION x = point.x;
317 if (!cave_los_bold(floor_ptr, y, x)) {
321 cave_temp_lite_room_aux(player_ptr, points, y + 1, x);
322 cave_temp_lite_room_aux(player_ptr, points, y - 1, x);
323 cave_temp_lite_room_aux(player_ptr, points, y, x + 1);
324 cave_temp_lite_room_aux(player_ptr, points, y, x - 1);
326 cave_temp_lite_room_aux(player_ptr, points, y + 1, x + 1);
327 cave_temp_lite_room_aux(player_ptr, points, y - 1, x - 1);
328 cave_temp_lite_room_aux(player_ptr, points, y - 1, x + 1);
329 cave_temp_lite_room_aux(player_ptr, points, y + 1, x - 1);
333 cave_temp_room_lite(player_ptr, points);
336 if (floor_ptr->grid_array[player_ptr->y][player_ptr->x].info & CAVE_GLOW) {
337 set_superstealth(player_ptr, false);
342 * @brief (y1,x1) を含む全ての部屋を暗くする。 / Darken all rooms containing the given location
343 * @param player_ptr プレイヤーへの参照ポインタ
347 void unlite_room(PlayerType *player_ptr, const POSITION y1, const POSITION x1)
350 std::vector<Pos2D> points;
352 auto *floor_ptr = player_ptr->current_floor_ptr;
354 // (y1,x1) を起点として暗くするマスを記録していく。
356 cave_temp_unlite_room_aux(player_ptr, points, y1, x1);
357 for (size_t i = 0; i < size(points); i++) {
358 const auto &point = points[i];
359 const POSITION y = point.y;
360 const POSITION x = point.x;
362 if (!cave_pass_dark_bold(floor_ptr, y, x)) {
366 cave_temp_unlite_room_aux(player_ptr, points, y + 1, x);
367 cave_temp_unlite_room_aux(player_ptr, points, y - 1, x);
368 cave_temp_unlite_room_aux(player_ptr, points, y, x + 1);
369 cave_temp_unlite_room_aux(player_ptr, points, y, x - 1);
371 cave_temp_unlite_room_aux(player_ptr, points, y + 1, x + 1);
372 cave_temp_unlite_room_aux(player_ptr, points, y - 1, x - 1);
373 cave_temp_unlite_room_aux(player_ptr, points, y - 1, x + 1);
374 cave_temp_unlite_room_aux(player_ptr, points, y + 1, x - 1);
378 cave_temp_room_unlite(player_ptr, points);
382 * @brief スターライトの効果を発生させる
383 * @param player_ptr プレイヤーへの参照ポインタ
384 * @param magic 魔法による効果であればTRUE、スターライトの杖による効果であればFALSE
387 bool starlight(PlayerType *player_ptr, bool magic)
389 if (!player_ptr->effects()->blindness()->is_blind() && !magic) {
390 msg_print(_("杖の先が明るく輝いた...", "The end of the staff glows brightly..."));
393 int num = damroll(5, 3);
395 POSITION y = 0, x = 0;
396 for (int k = 0; k < num; k++) {
400 scatter(player_ptr, &y, &x, player_ptr->y, player_ptr->x, 4, PROJECT_LOS);
401 if (!cave_has_flag_bold(player_ptr->current_floor_ptr, y, x, TerrainCharacteristics::PROJECT)) {
404 if (!player_bold(player_ptr, y, x)) {
409 project(player_ptr, 0, 0, y, x, damroll(6 + player_ptr->lev / 8, 10), AttributeType::LITE_WEAK,
410 (PROJECT_BEAM | PROJECT_THRU | PROJECT_GRID | PROJECT_KILL | PROJECT_LOS));
417 * @brief プレイヤー位置を中心にLITE_WEAK属性を通じた照明処理を行う / Hack -- call light around the player Affect all monsters in the projection radius
418 * @param player_ptr プレイヤーへの参照ポインタ
421 * @return 作用が実際にあった場合TRUEを返す
423 bool lite_area(PlayerType *player_ptr, int dam, POSITION rad)
425 if (player_ptr->current_floor_ptr->get_dungeon_definition().flags.has(DungeonFeatureType::DARKNESS)) {
426 msg_print(_("ダンジョンが光を吸収した。", "The darkness of this dungeon absorbs your light."));
430 if (!player_ptr->effects()->blindness()->is_blind()) {
431 msg_print(_("白い光が辺りを覆った。", "You are surrounded by a white light."));
434 BIT_FLAGS flg = PROJECT_GRID | PROJECT_KILL;
435 (void)project(player_ptr, 0, rad, player_ptr->y, player_ptr->x, dam, AttributeType::LITE_WEAK, flg);
437 lite_room(player_ptr, player_ptr->y, player_ptr->x);
443 * @brief プレイヤー位置を中心にLITE_DARK属性を通じた消灯処理を行う / Hack -- call light around the player Affect all monsters in the projection radius
444 * @param player_ptr プレイヤーへの参照ポインタ
447 * @return 作用が実際にあった場合TRUEを返す
449 bool unlite_area(PlayerType *player_ptr, int dam, POSITION rad)
451 if (!player_ptr->effects()->blindness()->is_blind()) {
452 msg_print(_("暗闇が辺りを覆った。", "Darkness surrounds you."));
455 BIT_FLAGS flg = PROJECT_GRID | PROJECT_KILL;
456 (void)project(player_ptr, 0, rad, player_ptr->y, player_ptr->x, dam, AttributeType::DARK_WEAK, flg);
458 unlite_room(player_ptr, player_ptr->y, player_ptr->x);
464 * @brief LITE_WEAK属性による光源ビーム処理
465 * @param player_ptr プレイヤーへの参照ポインタ
466 * @param dir 方向(5ならばグローバル変数 target_col/target_row の座標を目標にする)
468 * @return 作用が実際にあった場合TRUEを返す
470 bool lite_line(PlayerType *player_ptr, DIRECTION dir, int dam)
472 BIT_FLAGS flg = PROJECT_BEAM | PROJECT_GRID | PROJECT_KILL;
473 return project_hook(player_ptr, AttributeType::LITE_WEAK, dir, dam, flg);