OSDN Git Service

[Refactor] #919 Removed cave_los_grid() and moved cave_has_los_grid() from cave.cpp...
[hengbandforosx/hengbandosx.git] / src / spell-realm / spells-chaos.cpp
1 #include "spell-realm/spells-chaos.h"
2 #include "core/player-redraw-types.h"
3 #include "core/player-update-types.h"
4 #include "core/window-redrawer.h"
5 #include "dungeon/quest.h"
6 #include "effect/effect-characteristics.h"
7 #include "effect/effect-processor.h"
8 #include "floor/cave.h"
9 #include "floor/geometry.h"
10 #include "grid/feature.h"
11 #include "grid/grid.h"
12 #include "monster/monster-describer.h"
13 #include "monster/monster-status-setter.h"
14 #include "monster/monster-status.h"
15 #include "player/player-class.h"
16 #include "player/player-damage.h"
17 #include "spell-kind/spells-floor.h"
18 #include "spell-kind/spells-launcher.h"
19 #include "spell/spell-types.h"
20 #include "system/floor-type-definition.h"
21 #include "system/grid-type-definition.h"
22 #include "system/monster-type-definition.h"
23 #include "system/player-type-definition.h"
24 #include "target/projection-path-calculator.h"
25 #include "util/bit-flags-calculator.h"
26 #include "view/display-messages.h"
27
28 /*!
29  * @brief 虚無招来処理 /
30  * @param caster_ptr プレーヤーへの参照ポインタ
31  * @details
32  * Sorry, it becomes not (void)...
33  */
34 void call_the_void(player_type *caster_ptr)
35 {
36     grid_type *g_ptr;
37     bool do_call = true;
38     for (int i = 0; i < 9; i++) {
39         g_ptr = &caster_ptr->current_floor_ptr->grid_array[caster_ptr->y + ddy_ddd[i]][caster_ptr->x + ddx_ddd[i]];
40
41         if (!g_ptr->cave_has_flag(FF_PROJECT)) {
42             if (!g_ptr->mimic || !has_flag(f_info[g_ptr->mimic].flags, FF_PROJECT) || !permanent_wall(&f_info[g_ptr->feat])) {
43                 do_call = false;
44                 break;
45             }
46         }
47     }
48
49     if (do_call) {
50         for (int i = 1; i < 10; i++) {
51             if (i - 5)
52                 fire_ball(caster_ptr, GF_ROCKET, i, 175, 2);
53         }
54
55         for (int i = 1; i < 10; i++) {
56             if (i - 5)
57                 fire_ball(caster_ptr, GF_MANA, i, 175, 3);
58         }
59
60         for (int i = 1; i < 10; i++) {
61             if (i - 5)
62                 fire_ball(caster_ptr, GF_NUKE, i, 175, 4);
63         }
64
65         return;
66     }
67
68     bool is_special_fllor = caster_ptr->current_floor_ptr->inside_quest && is_fixed_quest_idx(caster_ptr->current_floor_ptr->inside_quest);
69     is_special_fllor |= !caster_ptr->current_floor_ptr->dun_level;
70     if (is_special_fllor) {
71         msg_print(_("地面が揺れた。", "The ground trembles."));
72         return;
73     }
74
75 #ifdef JP
76     msg_format("あなたは%sを壁に近すぎる場所で唱えてしまった!", ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "祈り" : "呪文"));
77 #else
78     msg_format("You %s the %s too close to a wall!", ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "recite" : "cast"),
79         ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "prayer" : "spell"));
80 #endif
81     msg_print(_("大きな爆発音があった!", "There is a loud explosion!"));
82
83     if (one_in_(666)) {
84         if (!vanish_dungeon(caster_ptr))
85             msg_print(_("ダンジョンは一瞬静まり返った。", "The dungeon becomes quiet for a moment."));
86         take_hit(caster_ptr, DAMAGE_NOESCAPE, 100 + randint1(150), _("自殺的な虚無招来", "a suicidal Call the Void"));
87         return;
88     }
89
90     if (destroy_area(caster_ptr, caster_ptr->y, caster_ptr->x, 15 + caster_ptr->lev + randint0(11), false))
91         msg_print(_("ダンジョンが崩壊した...", "The dungeon collapses..."));
92     else
93         msg_print(_("ダンジョンは大きく揺れた。", "The dungeon trembles."));
94     take_hit(caster_ptr, DAMAGE_NOESCAPE, 100 + randint1(150), _("自殺的な虚無招来", "a suicidal Call the Void"));
95 }
96
97 /*!
98  * @brief 虚無招来によるフロア中の全壁除去処理 /
99  * Vanish all walls in this floor
100  * @param caster_ptr プレーヤーへの参照ポインタ
101  * @param caster_ptr 術者の参照ポインタ
102  * @return 実際に処理が反映された場合TRUE
103  */
104 bool vanish_dungeon(player_type *caster_ptr)
105 {
106     bool is_special_floor = caster_ptr->current_floor_ptr->inside_quest && is_fixed_quest_idx(caster_ptr->current_floor_ptr->inside_quest);
107     is_special_floor |= !caster_ptr->current_floor_ptr->dun_level;
108     if (is_special_floor)
109         return false;
110
111     grid_type *g_ptr;
112     feature_type *f_ptr;
113     monster_type *m_ptr;
114     GAME_TEXT m_name[MAX_NLEN];
115     for (POSITION y = 1; y < caster_ptr->current_floor_ptr->height - 1; y++) {
116         for (POSITION x = 1; x < caster_ptr->current_floor_ptr->width - 1; x++) {
117             g_ptr = &caster_ptr->current_floor_ptr->grid_array[y][x];
118
119             f_ptr = &f_info[g_ptr->feat];
120             g_ptr->info &= ~(CAVE_ROOM | CAVE_ICKY);
121             m_ptr = &caster_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
122             if (g_ptr->m_idx && monster_csleep_remaining(m_ptr)) {
123                 (void)set_monster_csleep(caster_ptr, g_ptr->m_idx, 0);
124                 if (m_ptr->ml) {
125                     monster_desc(caster_ptr, m_name, m_ptr, 0);
126                     msg_format(_("%^sが目を覚ました。", "%^s wakes up."), m_name);
127                 }
128             }
129
130             if (has_flag(f_ptr->flags, FF_HURT_DISI))
131                 cave_alter_feat(caster_ptr, y, x, FF_HURT_DISI);
132         }
133     }
134
135     for (POSITION x = 0; x < caster_ptr->current_floor_ptr->width; x++) {
136         g_ptr = &caster_ptr->current_floor_ptr->grid_array[0][x];
137         f_ptr = &f_info[g_ptr->mimic];
138         g_ptr->info &= ~(CAVE_ROOM | CAVE_ICKY);
139
140         if (g_ptr->mimic && has_flag(f_ptr->flags, FF_HURT_DISI)) {
141             g_ptr->mimic = feat_state(caster_ptr->current_floor_ptr, g_ptr->mimic, FF_HURT_DISI);
142             if (!has_flag(f_info[g_ptr->mimic].flags, FF_REMEMBER))
143                 g_ptr->info &= ~(CAVE_MARK);
144         }
145
146         g_ptr = &caster_ptr->current_floor_ptr->grid_array[caster_ptr->current_floor_ptr->height - 1][x];
147         f_ptr = &f_info[g_ptr->mimic];
148         g_ptr->info &= ~(CAVE_ROOM | CAVE_ICKY);
149
150         if (g_ptr->mimic && has_flag(f_ptr->flags, FF_HURT_DISI)) {
151             g_ptr->mimic = feat_state(caster_ptr->current_floor_ptr, g_ptr->mimic, FF_HURT_DISI);
152             if (!has_flag(f_info[g_ptr->mimic].flags, FF_REMEMBER))
153                 g_ptr->info &= ~(CAVE_MARK);
154         }
155     }
156
157     /* Special boundary walls -- Left and right */
158     for (POSITION y = 1; y < (caster_ptr->current_floor_ptr->height - 1); y++) {
159         g_ptr = &caster_ptr->current_floor_ptr->grid_array[y][0];
160         f_ptr = &f_info[g_ptr->mimic];
161         g_ptr->info &= ~(CAVE_ROOM | CAVE_ICKY);
162
163         if (g_ptr->mimic && has_flag(f_ptr->flags, FF_HURT_DISI)) {
164             g_ptr->mimic = feat_state(caster_ptr->current_floor_ptr, g_ptr->mimic, FF_HURT_DISI);
165             if (!has_flag(f_info[g_ptr->mimic].flags, FF_REMEMBER))
166                 g_ptr->info &= ~(CAVE_MARK);
167         }
168
169         g_ptr = &caster_ptr->current_floor_ptr->grid_array[y][caster_ptr->current_floor_ptr->width - 1];
170         f_ptr = &f_info[g_ptr->mimic];
171         g_ptr->info &= ~(CAVE_ROOM | CAVE_ICKY);
172
173         if (g_ptr->mimic && has_flag(f_ptr->flags, FF_HURT_DISI)) {
174             g_ptr->mimic = feat_state(caster_ptr->current_floor_ptr, g_ptr->mimic, FF_HURT_DISI);
175             if (!has_flag(f_info[g_ptr->mimic].flags, FF_REMEMBER))
176                 g_ptr->info &= ~(CAVE_MARK);
177         }
178     }
179
180     caster_ptr->update |= (PU_UN_VIEW | PU_UN_LITE | PU_VIEW | PU_LITE | PU_FLOW | PU_MON_LITE | PU_MONSTERS);
181     caster_ptr->redraw |= (PR_MAP);
182     caster_ptr->window_flags |= (PW_OVERHEAD | PW_DUNGEON);
183     return true;
184 }
185
186 /*!
187  * @brief カオス魔法「流星群」/トランプ魔法「隕石のカード」の処理としてプレイヤーを中心に隕石落下処理を10+1d10回繰り返す。
188  * / Drop 10+1d10 meteor ball at random places near the player
189  * @param caster_ptr プレーヤーへの参照ポインタ
190  * @param dam ダメージ
191  * @param rad 効力の半径
192  * @details このファイルにいるのは、spells-trump.c と比べて行数が少なかったため。それ以上の意図はない
193  */
194 void cast_meteor(player_type *caster_ptr, HIT_POINT dam, POSITION rad)
195 {
196     int b = 10 + randint1(10);
197     for (int i = 0; i < b; i++) {
198         POSITION y = 0, x = 0;
199         int count;
200
201         for (count = 0; count <= 20; count++) {
202             int dy, dx, d;
203
204             x = caster_ptr->x - 8 + randint0(17);
205             y = caster_ptr->y - 8 + randint0(17);
206             dx = (caster_ptr->x > x) ? (caster_ptr->x - x) : (x - caster_ptr->x);
207             dy = (caster_ptr->y > y) ? (caster_ptr->y - y) : (y - caster_ptr->y);
208             d = (dy > dx) ? (dy + (dx >> 1)) : (dx + (dy >> 1));
209
210             if (d >= 9)
211                 continue;
212
213             floor_type *floor_ptr = caster_ptr->current_floor_ptr;
214             if (!in_bounds(floor_ptr, y, x) || !projectable(caster_ptr, caster_ptr->y, caster_ptr->x, y, x)
215                 || !cave_has_flag_bold(floor_ptr, y, x, FF_PROJECT))
216                 continue;
217
218             break;
219         }
220
221         if (count > 20)
222             continue;
223
224         project(caster_ptr, 0, rad, y, x, dam, GF_METEOR, PROJECT_KILL | PROJECT_JUMP | PROJECT_ITEM);
225     }
226 }