1 #include "spell-kind/earthquake.h"
2 #include "core/window-redrawer.h"
3 #include "dungeon/dungeon-flag-types.h"
4 #include "dungeon/quest.h"
5 #include "floor/cave.h"
6 #include "floor/floor-object.h"
7 #include "floor/geometry.h"
8 #include "game-option/play-record-options.h"
9 #include "game-option/text-display-options.h"
10 #include "grid/feature-flag-types.h"
11 #include "grid/feature.h"
12 #include "grid/grid.h"
13 #include "grid/stair.h"
14 #include "io/write-diary.h"
15 #include "mind/mind-ninja.h"
16 #include "monster-floor/monster-lite.h"
17 #include "monster-race/monster-race.h"
18 #include "monster/monster-describer.h"
19 #include "monster/monster-description-types.h"
20 #include "monster/monster-info.h"
21 #include "monster/monster-status-setter.h"
22 #include "monster/monster-update.h"
23 #include "monster/smart-learn-types.h"
24 #include "player/player-damage.h"
25 #include "player/player-move.h"
26 #include "player/player-status-flags.h"
27 #include "player/special-defense-types.h"
28 #include "status/bad-status-setter.h"
29 #include "system/dungeon-info.h"
30 #include "system/floor-type-definition.h"
31 #include "system/grid-type-definition.h"
32 #include "system/monster-entity.h"
33 #include "system/monster-race-info.h"
34 #include "system/player-type-definition.h"
35 #include "system/redrawing-flags-updater.h"
36 #include "system/terrain-type-definition.h"
37 #include "util/bit-flags-calculator.h"
38 #include "view/display-messages.h"
42 * Induce an "earthquake" of the given radius at the given location.
43 * @param player_ptrプレイヤーへの参照ポインタ
47 * @param m_idx 地震を起こしたモンスターID(0ならばプレイヤー)
48 * @return 効力があった場合TRUEを返す
50 bool earthquake(PlayerType *player_ptr, POSITION cy, POSITION cx, POSITION r, MONSTER_IDX m_idx)
52 auto *floor_ptr = player_ptr->current_floor_ptr;
53 if ((floor_ptr->is_in_quest() && QuestType::is_fixed(floor_ptr->quest_number)) || !floor_ptr->dun_level) {
62 for (auto y = 0; y < 32; y++) {
63 for (auto x = 0; x < 32; x++) {
70 for (auto dy = -r; dy <= r; dy++) {
71 for (auto dx = -r; dx <= r; dx++) {
72 const Pos2D pos(cy + dy, cx + dx);
73 if (!in_bounds(floor_ptr, pos.y, pos.x)) {
77 if (distance(cy, cx, pos.y, pos.x) > r) {
81 auto &grid = floor_ptr->get_grid(pos);
82 grid.info &= ~(CAVE_ROOM | CAVE_ICKY | CAVE_UNSAFE);
83 grid.info &= ~(CAVE_GLOW | CAVE_MARK | CAVE_KNOWN);
88 if (randint0(100) < 85) {
92 map[16 + pos.y - cy][16 + pos.x - cx] = true;
93 if (player_ptr->is_located_at(pos)) {
100 Pos2D p_pos_new(0, 0); // 落石を避けた後のプレイヤー座標
101 if (hurt && !has_pass_wall(player_ptr) && !has_kill_wall(player_ptr)) {
102 for (auto i = 0; i < 8; i++) {
103 auto y = player_ptr->y + ddy_ddd[i];
104 auto x = player_ptr->x + ddx_ddd[i];
105 if (!is_cave_empty_bold(player_ptr, y, x)) {
109 if (map[16 + y - cy][16 + x - cx]) {
113 if (floor_ptr->grid_array[y][x].has_monster()) {
118 if (randint0(sn) > 0) {
122 p_pos_new = { y, x };
125 constexpr static auto msgs = {
126 _("ダンジョンの壁が崩れた!", "The dungeon's ceiling collapses!"),
127 _("ダンジョンの床が不自然にねじ曲がった!", "The dungeon's floor twists in an unnatural way!"),
128 _("ダンジョンが揺れた!崩れた岩が頭に降ってきた!", "The dungeon quakes! You are pummeled with debris!"),
130 msg_print(rand_choice(msgs));
133 msg_print(_("あなたはひどい怪我を負った!", "You are severely crushed!"));
136 constexpr std::array<std::pair<bool, std::string_view>, 3> candidates = { {
137 { false, _("降り注ぐ岩をうまく避けた!", "You nimbly dodge the blast!") },
138 { true, _("岩石があなたに直撃した!", "You are bashed by rubble!") },
139 { true, _("あなたは床と壁との間に挟まれてしまった!", "You are crushed between the floor and ceiling!") },
142 const auto &[is_damaged, msg] = rand_choice(candidates);
146 damage = damroll(10, 4);
147 BadStatusSetter(player_ptr).mod_stun(randint1(50));
150 (void)move_player_effect(player_ptr, p_pos_new.y, p_pos_new.x, MPE_DONT_PICKUP);
153 map[16 + player_ptr->y - cy][16 + player_ptr->x - cx] = false;
158 auto *m_ptr = &floor_ptr->m_list[m_idx];
159 const auto m_name = monster_desc(player_ptr, m_ptr, MD_WRONGDOER_NAME);
160 killer = format(_("%sの起こした地震", "an earthquake caused by %s"), m_name.data());
162 killer = _("地震", "an earthquake");
165 take_hit(player_ptr, DAMAGE_ATTACK, damage, killer);
169 for (auto dy = -r; dy <= r; dy++) {
170 for (auto dx = -r; dx <= r; dx++) {
171 const Pos2D pos(cy + dy, cx + dx);
172 if (!map[16 + pos.y - cy][16 + pos.x - cx]) {
176 auto &grid = floor_ptr->get_grid(pos);
177 if (grid.m_idx == player_ptr->riding) {
181 if (!grid.has_monster()) {
185 auto *m_ptr = &floor_ptr->m_list[grid.m_idx];
186 auto *r_ptr = &m_ptr->get_monrace();
187 if (r_ptr->misc_flags.has(MonsterMiscType::QUESTOR)) {
188 map[16 + pos.y - cy][16 + pos.x - cx] = false;
192 if (r_ptr->feature_flags.has(MonsterFeatureType::KILL_WALL) || r_ptr->feature_flags.has(MonsterFeatureType::PASS_WALL)) {
197 if (r_ptr->behavior_flags.has_not(MonsterBehaviorType::NEVER_MOVE)) {
198 for (DIRECTION i = 0; i < 8; i++) {
199 const Pos2D pos_neighbor(pos.y + ddy_ddd[i], pos.x + ddx_ddd[i]);
200 if (!is_cave_empty_bold(player_ptr, pos_neighbor.y, pos_neighbor.x)) {
204 const auto &grid_neighbor = floor_ptr->get_grid(pos_neighbor);
205 if (grid_neighbor.is_rune_protection()) {
209 if (grid_neighbor.is_rune_explosion()) {
213 if (pattern_tile(floor_ptr, pos_neighbor.y, pos_neighbor.x)) {
217 if (map[16 + pos_neighbor.y - cy][16 + pos_neighbor.x - cx]) {
221 if (grid_neighbor.has_monster()) {
225 if (player_ptr->is_located_at(pos)) {
231 if (randint0(sn) > 0) {
235 p_pos_new = pos_neighbor;
239 const auto m_name = monster_desc(player_ptr, m_ptr, 0);
240 if (!ignore_unview || is_seen(player_ptr, m_ptr)) {
241 msg_format(_("%s^は苦痛で泣きわめいた!", "%s^ wails out in pain!"), m_name.data());
244 damage = (sn ? damroll(4, 8) : (m_ptr->hp + 1));
245 (void)set_monster_csleep(player_ptr, grid.m_idx, 0);
248 if (!ignore_unview || is_seen(player_ptr, m_ptr)) {
249 msg_format(_("%s^は岩石に埋もれてしまった!", "%s^ is embedded in the rock!"), m_name.data());
252 if (grid.has_monster()) {
253 const auto &m_ref = floor_ptr->m_list[grid.m_idx];
254 if (record_named_pet && m_ref.is_named_pet()) {
255 const auto m2_name = monster_desc(player_ptr, m_ptr, MD_INDEF_VISIBLE);
256 exe_write_diary(player_ptr, DiaryKind::NAMED_PET, RECORD_NAMED_PET_EARTHQUAKE, m2_name);
260 delete_monster(player_ptr, pos.y, pos.x);
268 const auto m_idx_aux = grid.m_idx;
270 floor_ptr->get_grid(p_pos_new).m_idx = m_idx_aux;
271 m_ptr->fy = p_pos_new.y;
272 m_ptr->fx = p_pos_new.x;
273 update_monster(player_ptr, m_idx_aux, true);
274 lite_spot(player_ptr, pos.y, pos.x);
275 lite_spot(player_ptr, p_pos_new.y, p_pos_new.x);
279 clear_mon_lite(floor_ptr);
280 for (auto dy = -r; dy <= r; dy++) {
281 for (auto dx = -r; dx <= r; dx++) {
284 if (!map[16 + yy - cy][16 + xx - cx]) {
288 if (!cave_valid_bold(floor_ptr, yy, xx)) {
292 delete_all_items_from_floor(player_ptr, yy, xx);
293 int t = cave_has_flag_bold(floor_ptr, yy, xx, TerrainCharacteristics::PROJECT) ? randint0(100) : 200;
295 cave_set_feat(player_ptr, yy, xx, feat_granite);
300 cave_set_feat(player_ptr, yy, xx, feat_quartz_vein);
305 cave_set_feat(player_ptr, yy, xx, feat_magma_vein);
309 cave_set_feat(player_ptr, yy, xx, rand_choice(feat_ground_type));
313 for (auto dy = -r; dy <= r; dy++) {
314 for (auto dx = -r; dx <= r; dx++) {
315 const Pos2D pos(cy + dy, cx + dx);
316 if (!in_bounds(floor_ptr, pos.y, pos.x)) {
320 if (distance(cy, cx, pos.y, pos.x) > r) {
324 auto &grid = floor_ptr->get_grid(pos);
325 if (grid.is_mirror()) {
326 grid.info |= CAVE_GLOW;
330 if (floor_ptr->get_dungeon_definition().flags.has(DungeonFeatureType::DARKNESS)) {
334 for (auto j = 0; j < 9; j++) {
335 const Pos2D pos_neighbor(pos.y + ddy_ddd[j], pos.x + ddx_ddd[j]);
336 if (!in_bounds2(floor_ptr, pos_neighbor.y, pos_neighbor.x)) {
340 const auto &grid_neighbor = floor_ptr->get_grid(pos_neighbor);
341 if (grid_neighbor.get_terrain_mimic().flags.has(TerrainCharacteristics::GLOW)) {
342 grid.info |= CAVE_GLOW;
349 auto &rfu = RedrawingFlagsUpdater::get_instance();
350 static constexpr auto flags_srf = {
351 StatusRecalculatingFlag::UN_VIEW,
352 StatusRecalculatingFlag::UN_LITE,
353 StatusRecalculatingFlag::VIEW,
354 StatusRecalculatingFlag::LITE,
355 StatusRecalculatingFlag::FLOW,
356 StatusRecalculatingFlag::MONSTER_LITE,
357 StatusRecalculatingFlag::MONSTER_STATUSES,
359 rfu.set_flags(flags_srf);
360 static constexpr auto flags_mwrf = {
361 MainWindowRedrawingFlag::HEALTH,
362 MainWindowRedrawingFlag::UHEALTH,
363 MainWindowRedrawingFlag::MAP,
365 rfu.set_flags(flags_mwrf);
366 static constexpr auto flags_swrf = {
367 SubWindowRedrawingFlag::OVERHEAD,
368 SubWindowRedrawingFlag::DUNGEON,
370 rfu.set_flags(flags_swrf);
371 if (floor_ptr->grid_array[player_ptr->y][player_ptr->x].info & CAVE_GLOW) {
372 set_superstealth(player_ptr, false);