OSDN Git Service

9f7379ff0c24886f7e30d7c0907986f291a9ae60
[hengband/hengband.git] / src / mind / mind-mirror-master.c
1 #include "mind/mind-mirror-master.h"
2 #include "cmd-action/cmd-pet.h"
3 #include "core/disturbance.h"
4 #include "core/player-redraw-types.h"
5 #include "core/player-update-types.h"
6 #include "core/stuff-handler.h"
7 #include "effect/effect-characteristics.h"
8 #include "effect/effect-feature.h"
9 #include "effect/effect-item.h"
10 #include "effect/effect-monster.h"
11 #include "effect/spells-effect-util.h"
12 #include "floor/cave.h"
13 #include "floor/floor.h"
14 #include "game-option/disturbance-options.h"
15 #include "game-option/special-options.h"
16 #include "grid/feature.h"
17 #include "io/cursor.h"
18 #include "io/screen-util.h"
19 #include "spell-kind/spells-sight.h"
20 #include "spell-kind/spells-teleport.h"
21 #include "spell/process-effect.h"
22 #include "spell/spell-types.h"
23 #include "system/floor-type-definition.h"
24 #include "target/grid-selector.h"
25 #include "term/gameterm.h"
26 #include "util/bit-flags-calculator.h"
27 #include "view/display-messages.h"
28 #include "world/world.h"
29
30 /*
31  * @brief Multishadow effects is determined by turn
32  */
33 bool check_multishadow(player_type *creature_ptr) { return (creature_ptr->multishadow != 0) && ((current_world_ptr->game_turn & 1) != 0); }
34
35 /*!
36  * 静水
37  * @param creature_ptr プレーヤーへの参照ポインタ
38  * @return ペットを操っている場合を除きTRUE
39  */
40 bool mirror_concentration(player_type *creature_ptr)
41 {
42     if (total_friends) {
43         msg_print(_("今はペットを操ることに集中していないと。", "Your pets demand all of your attention."));
44         return FALSE;
45     }
46
47     if (!is_mirror_grid(&creature_ptr->current_floor_ptr->grid_array[creature_ptr->y][creature_ptr->x])) {
48         msg_print(_("鏡の上でないと集中できない!", "There's no mirror here!"));
49         return TRUE;
50     }
51
52     msg_print(_("少し頭がハッキリした。", "You feel your head clear a little."));
53
54     creature_ptr->csp += (5 + creature_ptr->lev * creature_ptr->lev / 100);
55     if (creature_ptr->csp >= creature_ptr->msp) {
56         creature_ptr->csp = creature_ptr->msp;
57         creature_ptr->csp_frac = 0;
58     }
59
60     creature_ptr->redraw |= PR_MANA;
61     return TRUE;
62 }
63
64 /*!
65  * @brief 全鏡の消去 / Remove all mirrors in this floor
66  * @param caster_ptr プレーヤーへの参照ポインタ
67  * @param explode 爆発処理を伴うならばTRUE
68  * @return なし
69  */
70 void remove_all_mirrors(player_type *caster_ptr, bool explode)
71 {
72     for (POSITION x = 0; x < caster_ptr->current_floor_ptr->width; x++) {
73         for (POSITION y = 0; y < caster_ptr->current_floor_ptr->height; y++) {
74             if (!is_mirror_grid(&caster_ptr->current_floor_ptr->grid_array[y][x]))
75                 continue;
76
77             remove_mirror(caster_ptr, y, x);
78             if (!explode)
79                 continue;
80
81             project(caster_ptr, 0, 2, y, x, caster_ptr->lev / 2 + 5, GF_SHARDS,
82                 (PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_JUMP | PROJECT_NO_HANGEKI), -1);
83         }
84     }
85 }
86
87 /*!
88  * @brief 鏡魔法「封魔結界」の効果処理
89  * @param dam ダメージ量
90  * @return 効果があったらTRUEを返す
91  */
92 bool binding_field(player_type *caster_ptr, HIT_POINT dam)
93 {
94     POSITION mirror_x[10], mirror_y[10]; /* 鏡はもっと少ない */
95     int mirror_num = 0; /* 鏡の数 */
96     int msec = delay_factor * delay_factor * delay_factor;
97
98     /* 三角形の頂点 */
99     POSITION point_x[3];
100     POSITION point_y[3];
101
102     /* Default target of monsterspell is player */
103     monster_target_y = caster_ptr->y;
104     monster_target_x = caster_ptr->x;
105
106     for (POSITION x = 0; x < caster_ptr->current_floor_ptr->width; x++) {
107         for (POSITION y = 0; y < caster_ptr->current_floor_ptr->height; y++) {
108             if (is_mirror_grid(&caster_ptr->current_floor_ptr->grid_array[y][x]) && distance(caster_ptr->y, caster_ptr->x, y, x) <= get_max_range(caster_ptr)
109                 && distance(caster_ptr->y, caster_ptr->x, y, x) != 0 && player_has_los_bold(caster_ptr, y, x)
110                 && projectable(caster_ptr, caster_ptr->y, caster_ptr->x, y, x)) {
111                 mirror_y[mirror_num] = y;
112                 mirror_x[mirror_num] = x;
113                 mirror_num++;
114             }
115         }
116     }
117
118     if (mirror_num < 2)
119         return FALSE;
120
121     point_x[0] = randint0(mirror_num);
122     do {
123         point_x[1] = randint0(mirror_num);
124     } while (point_x[0] == point_x[1]);
125
126     point_y[0] = mirror_y[point_x[0]];
127     point_x[0] = mirror_x[point_x[0]];
128     point_y[1] = mirror_y[point_x[1]];
129     point_x[1] = mirror_x[point_x[1]];
130     point_y[2] = caster_ptr->y;
131     point_x[2] = caster_ptr->x;
132
133     POSITION x = point_x[0] + point_x[1] + point_x[2];
134     POSITION y = point_y[0] + point_y[1] + point_y[2];
135
136     POSITION centersign = (point_x[0] * 3 - x) * (point_y[1] * 3 - y) - (point_y[0] * 3 - y) * (point_x[1] * 3 - x);
137     if (centersign == 0)
138         return FALSE;
139
140     POSITION x1 = point_x[0] < point_x[1] ? point_x[0] : point_x[1];
141     x1 = x1 < point_x[2] ? x1 : point_x[2];
142     POSITION y1 = point_y[0] < point_y[1] ? point_y[0] : point_y[1];
143     y1 = y1 < point_y[2] ? y1 : point_y[2];
144
145     POSITION x2 = point_x[0] > point_x[1] ? point_x[0] : point_x[1];
146     x2 = x2 > point_x[2] ? x2 : point_x[2];
147     POSITION y2 = point_y[0] > point_y[1] ? point_y[0] : point_y[1];
148     y2 = y2 > point_y[2] ? y2 : point_y[2];
149
150     for (y = y1; y <= y2; y++) {
151         for (x = x1; x <= x2; x++) {
152             if (centersign * ((point_x[0] - x) * (point_y[1] - y) - (point_y[0] - y) * (point_x[1] - x)) >= 0
153                 && centersign * ((point_x[1] - x) * (point_y[2] - y) - (point_y[1] - y) * (point_x[2] - x)) >= 0
154                 && centersign * ((point_x[2] - x) * (point_y[0] - y) - (point_y[2] - y) * (point_x[0] - x)) >= 0) {
155                 if (player_has_los_bold(caster_ptr, y, x) && projectable(caster_ptr, caster_ptr->y, caster_ptr->x, y, x)) {
156                     if (!(caster_ptr->blind) && panel_contains(y, x)) {
157                         u16b p = bolt_pict(y, x, y, x, GF_MANA);
158                         print_rel(caster_ptr, PICT_C(p), PICT_A(p), y, x);
159                         move_cursor_relative(y, x);
160                         term_fresh();
161                         term_xtra(TERM_XTRA_DELAY, msec);
162                     }
163                 }
164             }
165         }
166     }
167
168     for (y = y1; y <= y2; y++) {
169         for (x = x1; x <= x2; x++) {
170             if (centersign * ((point_x[0] - x) * (point_y[1] - y) - (point_y[0] - y) * (point_x[1] - x)) >= 0
171                 && centersign * ((point_x[1] - x) * (point_y[2] - y) - (point_y[1] - y) * (point_x[2] - x)) >= 0
172                 && centersign * ((point_x[2] - x) * (point_y[0] - y) - (point_y[2] - y) * (point_x[0] - x)) >= 0) {
173                 if (player_has_los_bold(caster_ptr, y, x) && projectable(caster_ptr, caster_ptr->y, caster_ptr->x, y, x)) {
174                     (void)affect_feature(caster_ptr, 0, 0, y, x, dam, GF_MANA);
175                 }
176             }
177         }
178     }
179
180     for (y = y1; y <= y2; y++) {
181         for (x = x1; x <= x2; x++) {
182             if (centersign * ((point_x[0] - x) * (point_y[1] - y) - (point_y[0] - y) * (point_x[1] - x)) >= 0
183                 && centersign * ((point_x[1] - x) * (point_y[2] - y) - (point_y[1] - y) * (point_x[2] - x)) >= 0
184                 && centersign * ((point_x[2] - x) * (point_y[0] - y) - (point_y[2] - y) * (point_x[0] - x)) >= 0) {
185                 if (player_has_los_bold(caster_ptr, y, x) && projectable(caster_ptr, caster_ptr->y, caster_ptr->x, y, x)) {
186                     (void)affect_item(caster_ptr, 0, 0, y, x, dam, GF_MANA);
187                 }
188             }
189         }
190     }
191
192     for (y = y1; y <= y2; y++) {
193         for (x = x1; x <= x2; x++) {
194             if (centersign * ((point_x[0] - x) * (point_y[1] - y) - (point_y[0] - y) * (point_x[1] - x)) >= 0
195                 && centersign * ((point_x[1] - x) * (point_y[2] - y) - (point_y[1] - y) * (point_x[2] - x)) >= 0
196                 && centersign * ((point_x[2] - x) * (point_y[0] - y) - (point_y[2] - y) * (point_x[0] - x)) >= 0) {
197                 if (player_has_los_bold(caster_ptr, y, x) && projectable(caster_ptr, caster_ptr->y, caster_ptr->x, y, x)) {
198                     (void)affect_monster(caster_ptr, 0, 0, y, x, dam, GF_MANA, (PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_JUMP), TRUE);
199                 }
200             }
201         }
202     }
203
204     if (one_in_(7)) {
205         msg_print(_("鏡が結界に耐えきれず、壊れてしまった。", "The field broke a mirror"));
206         remove_mirror(caster_ptr, point_y[0], point_x[0]);
207     }
208
209     return TRUE;
210 }
211
212 /*!
213  * @brief 鏡魔法「鏡の封印」の効果処理
214  * @param dam ダメージ量
215  * @return 効果があったらTRUEを返す
216  */
217 void seal_of_mirror(player_type *caster_ptr, HIT_POINT dam)
218 {
219     for (POSITION x = 0; x < caster_ptr->current_floor_ptr->width; x++) {
220         for (POSITION y = 0; y < caster_ptr->current_floor_ptr->height; y++) {
221             if (!is_mirror_grid(&caster_ptr->current_floor_ptr->grid_array[y][x]))
222                 continue;
223
224             if (!affect_monster(caster_ptr, 0, 0, y, x, dam, GF_GENOCIDE, (PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_JUMP), TRUE))
225                 continue;
226
227             if (!caster_ptr->current_floor_ptr->grid_array[y][x].m_idx) {
228                 remove_mirror(caster_ptr, y, x);
229             }
230         }
231     }
232 }
233
234 /*!
235  * 幻惑の光 @ 鏡使いだけでなく混沌の戦士も使える
236  * @param creature_ptr プレーヤーへの参照ポインタ
237  * @return 常にTRUE
238  */
239 bool confusing_light(player_type *creature_ptr)
240 {
241     msg_print(_("辺りを睨んだ...", "You glare nearby monsters..."));
242     slow_monsters(creature_ptr, creature_ptr->lev);
243     stun_monsters(creature_ptr, creature_ptr->lev * 4);
244     confuse_monsters(creature_ptr, creature_ptr->lev * 4);
245     turn_monsters(creature_ptr, creature_ptr->lev * 4);
246     stasis_monsters(creature_ptr, creature_ptr->lev * 4);
247     return TRUE;
248 }
249
250 /*!
251  * @brief 鏡設置処理
252  * @return 実際に設置が行われた場合TRUEを返す
253  */
254 bool place_mirror(player_type *caster_ptr)
255 {
256     if (!cave_clean_bold(caster_ptr->current_floor_ptr, caster_ptr->y, caster_ptr->x)) {
257         msg_print(_("床上のアイテムが呪文を跳ね返した。", "The object resists the spell."));
258         return FALSE;
259     }
260
261     /* Create a mirror */
262     caster_ptr->current_floor_ptr->grid_array[caster_ptr->y][caster_ptr->x].info |= CAVE_OBJECT;
263     caster_ptr->current_floor_ptr->grid_array[caster_ptr->y][caster_ptr->x].mimic = feat_mirror;
264
265     /* Turn on the light */
266     caster_ptr->current_floor_ptr->grid_array[caster_ptr->y][caster_ptr->x].info |= CAVE_GLOW;
267
268     note_spot(caster_ptr, caster_ptr->y, caster_ptr->x);
269     lite_spot(caster_ptr, caster_ptr->y, caster_ptr->x);
270     update_local_illumination(caster_ptr, caster_ptr->y, caster_ptr->x);
271
272     return TRUE;
273 }
274
275 /*!
276  * @brief 鏡抜け処理のメインルーチン /
277  * Mirror Master's Dimension Door
278  * @param caster_ptr プレーヤーへの参照ポインタ
279  * @return ターンを消費した場合TRUEを返す
280  */
281 bool mirror_tunnel(player_type *caster_ptr)
282 {
283     POSITION x = 0, y = 0;
284     if (!tgt_pt(caster_ptr, &x, &y))
285         return FALSE;
286     if (exe_dimension_door(caster_ptr, x, y))
287         return TRUE;
288
289     msg_print(_("鏡の世界をうまく通れなかった!", "You fail to pass the mirror plane correctly!"));
290     return TRUE;
291 }
292
293 /*
294  * Set "multishadow", notice observable changes
295  */
296 bool set_multishadow(player_type *creature_ptr, TIME_EFFECT v, bool do_dec)
297 {
298     bool notice = FALSE;
299     v = (v > 10000) ? 10000 : (v < 0) ? 0 : v;
300
301     if (creature_ptr->is_dead)
302         return FALSE;
303
304     if (v) {
305         if (creature_ptr->multishadow && !do_dec) {
306             if (creature_ptr->multishadow > v)
307                 return FALSE;
308         } else if (!creature_ptr->multishadow) {
309             msg_print(_("あなたの周りに幻影が生まれた。", "Your Shadow enveloped you."));
310             notice = TRUE;
311         }
312     } else {
313         if (creature_ptr->multishadow) {
314             msg_print(_("幻影が消えた。", "Your Shadow disappears."));
315             notice = TRUE;
316         }
317     }
318
319     creature_ptr->multishadow = v;
320     creature_ptr->redraw |= (PR_STATUS);
321
322     if (!notice)
323         return FALSE;
324
325     if (disturb_state)
326         disturb(creature_ptr, FALSE, FALSE);
327     creature_ptr->update |= (PU_BONUS);
328     handle_stuff(creature_ptr);
329     return TRUE;
330 }
331
332 /*!
333  * @brief 一時的破片のオーラの継続時間をセットする / Set "dustrobe", notice observable changes
334  * @param v 継続時間
335  * @param do_dec 現在の継続時間より長い値のみ上書きする
336  * @return ステータスに影響を及ぼす変化があった場合TRUEを返す。
337  */
338 bool set_dustrobe(player_type *creature_ptr, TIME_EFFECT v, bool do_dec)
339 {
340     bool notice = FALSE;
341     v = (v > 10000) ? 10000 : (v < 0) ? 0 : v;
342
343     if (creature_ptr->is_dead)
344         return FALSE;
345
346     if (v) {
347         if (creature_ptr->dustrobe && !do_dec) {
348             if (creature_ptr->dustrobe > v)
349                 return FALSE;
350         } else if (!creature_ptr->dustrobe) {
351             msg_print(_("体が鏡のオーラで覆われた。", "You were enveloped by mirror shards."));
352             notice = TRUE;
353         }
354     } else {
355         if (creature_ptr->dustrobe) {
356             msg_print(_("鏡のオーラが消えた。", "The mirror shards disappear."));
357             notice = TRUE;
358         }
359     }
360
361     creature_ptr->dustrobe = v;
362     creature_ptr->redraw |= (PR_STATUS);
363
364     if (!notice)
365         return FALSE;
366
367     if (disturb_state)
368         disturb(creature_ptr, FALSE, FALSE);
369     creature_ptr->update |= (PU_BONUS);
370     handle_stuff(creature_ptr);
371     return TRUE;
372 }