OSDN Git Service

[Refactor] #37353 player-move.h を追加。 / Add player-move.h.
[hengband/hengband.git] / src / trap.c
1 #include "angband.h"
2 #include "floor.h"
3 #include "trap.h"
4 #include "player-damage.h"
5 #include "player-move.h"
6 #include "projection.h"
7 #include "spells-summon.h"
8 #include "quest.h"
9 #include "artifact.h"
10 #include "feature.h"
11
12 static s16b normal_traps[MAX_NORMAL_TRAPS];
13
14
15 /*!
16 * @brief タグに従って、基本トラップテーブルを初期化する / Initialize arrays for normal traps
17 * @return なし
18 */
19 void init_normal_traps(void)
20 {
21         int cur_trap = 0;
22
23         normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_TRAPDOOR");
24         normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_PIT");
25         normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_SPIKED_PIT");
26         normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_POISON_PIT");
27         normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_TY_CURSE");
28         normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_TELEPORT");
29         normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_FIRE");
30         normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_ACID");
31         normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_SLOW");
32         normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_LOSE_STR");
33         normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_LOSE_DEX");
34         normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_LOSE_CON");
35         normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_BLIND");
36         normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_CONFUSE");
37         normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_POISON");
38         normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_SLEEP");
39         normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_TRAPS");
40         normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_ALARM");
41 }
42
43 /*!
44 * @brief 基本トラップをランダムに選択する /
45 * Get random trap
46 * @return 選択したトラップのID
47 * @details
48 * This routine should be redone to reflect trap "level".\n
49 * That is, it does not make sense to have spiked pits at 50 feet.\n
50 * Actually, it is not this routine, but the "trap instantiation"\n
51 * code, which should also check for "trap doors" on quest levels.\n
52 */
53 FEAT_IDX choose_random_trap(void)
54 {
55         FEAT_IDX feat;
56
57         /* Pick a trap */
58         while (1)
59         {
60                 /* Hack -- pick a trap */
61                 feat = normal_traps[randint0(MAX_NORMAL_TRAPS)];
62
63                 /* Accept non-trapdoors */
64                 if (!have_flag(f_info[feat].flags, FF_MORE)) break;
65
66                 /* Hack -- no trap doors on special levels */
67                 if (p_ptr->inside_arena || quest_number(current_floor_ptr->dun_level)) continue;
68
69                 /* Hack -- no trap doors on the deepest level */
70                 if (current_floor_ptr->dun_level >= d_info[p_ptr->dungeon_idx].maxdepth) continue;
71
72                 break;
73         }
74
75         return feat;
76 }
77
78 /*!
79 * @brief マスに存在するトラップを秘匿する /
80 * Disclose an invisible trap
81 * @param y 秘匿したいマスのY座標
82 * @param x 秘匿したいマスのX座標
83 * @return なし
84 */
85 void disclose_grid(POSITION y, POSITION x)
86 {
87         grid_type *g_ptr = &current_floor_ptr->grid_array[y][x];
88
89         if (cave_have_flag_grid(g_ptr, FF_SECRET))
90         {
91                 /* No longer hidden */
92                 cave_alter_feat(y, x, FF_SECRET);
93         }
94         else if (g_ptr->mimic)
95         {
96                 /* No longer hidden */
97                 g_ptr->mimic = 0;
98
99                 note_spot(y, x);
100                 lite_spot(y, x);
101         }
102 }
103
104 /*!
105 * @brief マスをトラップを配置する /
106 * The location must be a legal, naked, floor grid.
107 * @param y 配置したいマスのY座標
108 * @param x 配置したいマスのX座標
109 * @return
110 * Note that all traps start out as "invisible" and "untyped", and then\n
111 * when they are "discovered" (by detecting them or setting them off),\n
112 * the trap is "instantiated" as a visible, "typed", trap.\n
113 */
114 void place_trap(POSITION y, POSITION x)
115 {
116         grid_type *g_ptr = &current_floor_ptr->grid_array[y][x];
117
118         /* Paranoia -- verify location */
119         if (!in_bounds(y, x)) return;
120
121         /* Require empty, clean, floor grid */
122         if (!cave_clean_bold(y, x)) return;
123
124         /* Place an invisible trap */
125         g_ptr->mimic = g_ptr->feat;
126         g_ptr->feat = choose_random_trap();
127 }
128
129
130
131 /*!
132 * @brief プレイヤーへのトラップ命中判定 /
133 * Determine if a trap affects the player.
134 * @param power 基本回避難度
135 * @return トラップが命中した場合TRUEを返す。
136 * @details
137 * Always miss 5% of the time, Always hit 5% of the time.
138 * Otherwise, match trap power against player armor.
139 */
140 static int check_hit(int power)
141 {
142         int k;
143         ARMOUR_CLASS ac;
144
145         /* Percentile dice */
146         k = randint0(100);
147
148         /* Hack -- 5% hit, 5% miss */
149         if (k < 10) return (k < 5);
150
151         if (p_ptr->pseikaku == SEIKAKU_NAMAKE)
152                 if (one_in_(20)) return (TRUE);
153
154         /* Paranoia -- No power */
155         if (power <= 0) return (FALSE);
156
157         /* Total armor */
158         ac = p_ptr->ac + p_ptr->to_a;
159
160         /* Power competes against Armor */
161         if (randint1(power) > ((ac * 3) / 4)) return (TRUE);
162
163         /* Assume miss */
164         return (FALSE);
165 }
166
167
168 /*!
169 * @brief 落とし穴系トラップの判定とプレイヤーの被害処理
170 * @param trap_feat_type トラップの種別ID
171 * @return なし
172 */
173 static void hit_trap_pit(int trap_feat_type)
174 {
175         HIT_POINT dam;
176         concptr trap_name = "";
177         concptr spike_name = "";
178
179         switch (trap_feat_type)
180         {
181         case TRAP_PIT:
182                 trap_name = _("落とし穴", "a pit trap");
183                 break;
184         case TRAP_SPIKED_PIT:
185                 trap_name = _("スパイクが敷かれた落とし穴", "a spiked pit");
186                 spike_name = _("スパイク", "spikes");
187                 break;
188         case TRAP_POISON_PIT:
189                 trap_name = _("スパイクが敷かれた落とし穴", "a spiked pit");
190                 spike_name = _("毒を塗られたスパイク", "poisonous spikes");
191                 break;
192         default:
193                 return;
194         }
195
196         if (p_ptr->levitation)
197         {
198                 msg_format(_("%sを飛び越えた。", "You fly over %s."), trap_name);
199                 return;
200         }
201
202         msg_format(_("%sに落ちてしまった!", "You have fallen into %s!"), trap_name);
203
204         /* Base damage */
205         dam = damroll(2, 6);
206
207         /* Extra spike damage */
208         if ((trap_feat_type == TRAP_SPIKED_PIT || trap_feat_type == TRAP_POISON_PIT) &&
209                 one_in_(2))
210         {
211                 msg_format(_("%sが刺さった!", "You are impaled on %s!"), spike_name);
212
213                 dam = dam * 2;
214                 (void)set_cut(p_ptr->cut + randint1(dam));
215
216                 if (trap_feat_type == TRAP_POISON_PIT) {
217                         if (p_ptr->resist_pois || IS_OPPOSE_POIS())
218                         {
219                                 msg_print(_("しかし毒の影響はなかった!", "The poison does not affect you!"));
220                         }
221                         else
222                         {
223                                 dam = dam * 2;
224                                 (void)set_poisoned(p_ptr->poisoned + randint1(dam));
225                         }
226                 }
227         }
228
229         take_hit(DAMAGE_NOESCAPE, dam, trap_name, -1);
230 }
231
232 /*!
233 * @brief ダーツ系トラップ(通常ダメージ)の判定とプレイヤーの被害処理
234 * @return ダーツが命中した場合TRUEを返す
235 */
236 static bool hit_trap_dart(void)
237 {
238         bool hit = FALSE;
239
240         if (check_hit(125))
241         {
242                 msg_print(_("小さなダーツが飛んできて刺さった!", "A small dart hits you!"));
243                 take_hit(DAMAGE_ATTACK, damroll(1, 4), _("ダーツの罠", "a dart trap"), -1);
244                 if (!CHECK_MULTISHADOW()) hit = TRUE;
245         }
246         else
247         {
248                 msg_print(_("小さなダーツが飛んできた!が、運良く当たらなかった。", "A small dart barely misses you."));
249         }
250
251         return hit;
252 }
253
254 /*!
255 * @brief ダーツ系トラップ(通常ダメージ+能力値減少)の判定とプレイヤーの被害処理
256 * @param stat 低下する能力値ID
257 * @return なし
258 */
259 static void hit_trap_lose_stat(int stat)
260 {
261         if (hit_trap_dart())
262         {
263                 do_dec_stat(stat);
264         }
265 }
266
267 /*!
268 * @brief ダーツ系トラップ(通常ダメージ+減速)の判定とプレイヤーの被害処理
269 * @return なし
270 */
271 static void hit_trap_slow(void)
272 {
273         if (hit_trap_dart())
274         {
275                 set_slow(p_ptr->slow + randint0(20) + 20, FALSE);
276         }
277 }
278
279 /*!
280 * @brief ダーツ系トラップ(通常ダメージ+状態異常)の判定とプレイヤーの被害処理
281 * @param trap_message メッセージの補完文字列
282 * @param resist 状態異常に抵抗する判定が出たならTRUE
283 * @param set_status 状態異常を指定する関数ポインタ
284 * @param current_world_ptr->game_turn 状態異常の追加ターン量
285 * @return なし
286 */
287 static void hit_trap_set_abnormal_status(concptr trap_message, bool resist, bool(*set_status)(IDX), IDX turn_aux)
288 {
289         msg_print(trap_message);
290         if (!resist)
291         {
292                 set_status(turn_aux);
293         }
294 }
295
296 /*!
297 * @brief プレイヤーへのトラップ作動処理メインルーチン /
298 * Handle player hitting a real trap
299 * @param break_trap 作動後のトラップ破壊が確定しているならばTRUE
300 * @return なし
301 */
302 void hit_trap(bool break_trap)
303 {
304         int i, num, dam;
305         POSITION x = p_ptr->x, y = p_ptr->y;
306         grid_type *g_ptr = &current_floor_ptr->grid_array[y][x];
307         feature_type *f_ptr = &f_info[g_ptr->feat];
308         int trap_feat_type = have_flag(f_ptr->flags, FF_TRAP) ? f_ptr->subtype : NOT_TRAP;
309         concptr name = _("トラップ", "a trap");
310
311         disturb(FALSE, TRUE);
312
313         cave_alter_feat(y, x, FF_HIT_TRAP);
314
315         /* Analyze */
316         switch (trap_feat_type)
317         {
318         case TRAP_TRAPDOOR:
319         {
320                 if (p_ptr->levitation)
321                 {
322                         msg_print(_("落とし戸を飛び越えた。", "You fly over a trap door."));
323                 }
324                 else
325                 {
326                         msg_print(_("落とし戸に落ちた!", "You have fallen through a trap door!"));
327                         if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
328                                 msg_print(_("くっそ~!", ""));
329                         else if((p_ptr->pseikaku == SEIKAKU_CHARGEMAN))
330                                 msg_print(_("ジュラル星人の仕業に違いない!", ""));
331
332
333                         sound(SOUND_FALL);
334                         dam = damroll(2, 8);
335                         name = _("落とし戸", "a trap door");
336
337                         take_hit(DAMAGE_NOESCAPE, dam, name, -1);
338
339                         /* Still alive and autosave enabled */
340                         if (autosave_l && (p_ptr->chp >= 0))
341                                 do_cmd_save_game(TRUE);
342
343                         do_cmd_write_nikki(NIKKI_BUNSHOU, 0, _("落とし戸に落ちた", "You have fallen through a trap door!"));
344                         prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_DOWN | CFM_RAND_PLACE | CFM_RAND_CONNECT);
345
346                         /* Leaving */
347                         p_ptr->leaving = TRUE;
348                 }
349                 break;
350         }
351
352         case TRAP_PIT:
353         case TRAP_SPIKED_PIT:
354         case TRAP_POISON_PIT:
355         {
356                 hit_trap_pit(trap_feat_type);
357                 break;
358         }
359
360         case TRAP_TY_CURSE:
361         {
362                 msg_print(_("何かがピカッと光った!", "There is a flash of shimmering light!"));
363                 num = 2 + randint1(3);
364                 for (i = 0; i < num; i++)
365                 {
366                         (void)summon_specific(0, y, x, current_floor_ptr->dun_level, 0, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET), '\0');
367                 }
368
369                 if (current_floor_ptr->dun_level > randint1(100)) /* No nasty effect for low levels */
370                 {
371                         bool stop_ty = FALSE;
372                         int count = 0;
373
374                         do
375                         {
376                                 stop_ty = activate_ty_curse(stop_ty, &count);
377                         } while (one_in_(6));
378                 }
379                 break;
380         }
381
382         case TRAP_TELEPORT:
383         {
384                 msg_print(_("テレポート・トラップにひっかかった!", "You hit a teleport trap!"));
385                 teleport_player(100, TELEPORT_PASSIVE);
386                 break;
387         }
388
389         case TRAP_FIRE:
390         {
391                 msg_print(_("炎に包まれた!", "You are enveloped in flames!"));
392                 dam = damroll(4, 6);
393                 (void)fire_dam(dam, _("炎のトラップ", "a fire trap"), -1, FALSE);
394                 break;
395         }
396
397         case TRAP_ACID:
398         {
399                 msg_print(_("酸が吹きかけられた!", "You are splashed with acid!"));
400                 dam = damroll(4, 6);
401                 (void)acid_dam(dam, _("酸のトラップ", "an acid trap"), -1, FALSE);
402                 break;
403         }
404
405         case TRAP_SLOW:
406         {
407                 hit_trap_slow();
408                 break;
409         }
410
411         case TRAP_LOSE_STR:
412         {
413                 hit_trap_lose_stat(A_STR);
414                 break;
415         }
416
417         case TRAP_LOSE_DEX:
418         {
419                 hit_trap_lose_stat(A_DEX);
420                 break;
421         }
422
423         case TRAP_LOSE_CON:
424         {
425                 hit_trap_lose_stat(A_CON);
426                 break;
427         }
428
429         case TRAP_BLIND:
430         {
431                 hit_trap_set_abnormal_status(
432                         _("黒いガスに包み込まれた!", "A black gas surrounds you!"),
433                         p_ptr->resist_blind,
434                         set_blind, p_ptr->blind + (TIME_EFFECT)randint0(50) + 25);
435                 break;
436         }
437
438         case TRAP_CONFUSE:
439         {
440                 hit_trap_set_abnormal_status(
441                         _("きらめくガスに包み込まれた!", "A gas of scintillating colors surrounds you!"),
442                         p_ptr->resist_conf,
443                         set_confused, p_ptr->confused + (TIME_EFFECT)randint0(20) + 10);
444                 break;
445         }
446
447         case TRAP_POISON:
448         {
449                 hit_trap_set_abnormal_status(
450                         _("刺激的な緑色のガスに包み込まれた!", "A pungent green gas surrounds you!"),
451                         p_ptr->resist_pois || IS_OPPOSE_POIS(),
452                         set_poisoned, p_ptr->poisoned + (TIME_EFFECT)randint0(20) + 10);
453                 break;
454         }
455
456         case TRAP_SLEEP:
457         {
458                 msg_print(_("奇妙な白い霧に包まれた!", "A strange white mist surrounds you!"));
459                 if (!p_ptr->free_act)
460                 {
461                         msg_print(_("あなたは眠りに就いた。", "You fall asleep."));
462
463                         if (ironman_nightmare)
464                         {
465                                 msg_print(_("身の毛もよだつ光景が頭に浮かんだ。", "A horrible vision enters your mind."));
466
467                                 /* Have some nightmares */
468                                 sanity_blast(NULL, FALSE);
469
470                         }
471                         (void)set_paralyzed(p_ptr->paralyzed + randint0(10) + 5);
472                 }
473                 break;
474         }
475
476         case TRAP_TRAPS:
477         {
478                 msg_print(_("まばゆい閃光が走った!", "There is a bright flash of light!"));
479                 /* Make some new traps */
480                 project(0, 1, y, x, 0, GF_MAKE_TRAP, PROJECT_HIDE | PROJECT_JUMP | PROJECT_GRID, -1);
481
482                 break;
483         }
484
485         case TRAP_ALARM:
486         {
487                 msg_print(_("けたたましい音が鳴り響いた!", "An alarm sounds!"));
488
489                 aggravate_monsters(0);
490
491                 break;
492         }
493
494         case TRAP_OPEN:
495         {
496                 msg_print(_("大音響と共にまわりの壁が崩れた!", "Suddenly, surrounding walls are opened!"));
497                 (void)project(0, 3, y, x, 0, GF_DISINTEGRATE, PROJECT_GRID | PROJECT_HIDE, -1);
498                 (void)project(0, 3, y, x - 4, 0, GF_DISINTEGRATE, PROJECT_GRID | PROJECT_HIDE, -1);
499                 (void)project(0, 3, y, x + 4, 0, GF_DISINTEGRATE, PROJECT_GRID | PROJECT_HIDE, -1);
500                 aggravate_monsters(0);
501
502                 break;
503         }
504
505         case TRAP_ARMAGEDDON:
506         {
507                 static int levs[10] = { 0, 0, 20, 10, 5, 3, 2, 1, 1, 1 };
508                 int evil_idx = 0, good_idx = 0;
509
510                 DEPTH lev;
511                 msg_print(_("突然天界の戦争に巻き込まれた!", "Suddenly, you are surrounded by immotal beings!"));
512
513                 /* Summon Demons and Angels */
514                 for (lev = current_floor_ptr->dun_level; lev >= 20; lev -= 1 + lev / 16)
515                 {
516                         num = levs[MIN(lev / 10, 9)];
517                         for (i = 0; i < num; i++)
518                         {
519                                 POSITION x1 = rand_spread(x, 7);
520                                 POSITION y1 = rand_spread(y, 5);
521
522                                 /* Skip illegal grids */
523                                 if (!in_bounds(y1, x1)) continue;
524
525                                 /* Require line of projection */
526                                 if (!projectable(p_ptr->y, p_ptr->x, y1, x1)) continue;
527
528                                 if (summon_specific(0, y1, x1, lev, SUMMON_ARMAGE_EVIL, (PM_NO_PET), '\0'))
529                                         evil_idx = hack_m_idx_ii;
530
531                                 if (summon_specific(0, y1, x1, lev, SUMMON_ARMAGE_GOOD, (PM_NO_PET), '\0'))
532                                 {
533                                         good_idx = hack_m_idx_ii;
534                                 }
535
536                                 /* Let them fight each other */
537                                 if (evil_idx && good_idx)
538                                 {
539                                         monster_type *evil_ptr = &current_floor_ptr->m_list[evil_idx];
540                                         monster_type *good_ptr = &current_floor_ptr->m_list[good_idx];
541                                         evil_ptr->target_y = good_ptr->fy;
542                                         evil_ptr->target_x = good_ptr->fx;
543                                         good_ptr->target_y = evil_ptr->fy;
544                                         good_ptr->target_x = evil_ptr->fx;
545                                 }
546                         }
547                 }
548                 break;
549         }
550
551         case TRAP_PIRANHA:
552         {
553                 msg_print(_("突然壁から水が溢れ出した!ピラニアがいる!", "Suddenly, the room is filled with water with piranhas!"));
554
555                 /* Water fills room */
556                 fire_ball_hide(GF_WATER_FLOW, 0, 1, 10);
557
558                 /* Summon Piranhas */
559                 num = 1 + current_floor_ptr->dun_level / 20;
560                 for (i = 0; i < num; i++)
561                 {
562                         (void)summon_specific(0, y, x, current_floor_ptr->dun_level, SUMMON_PIRANHAS, (PM_ALLOW_GROUP | PM_NO_PET), '\0');
563                 }
564                 break;
565         }
566         }
567
568         if (break_trap && is_trap(g_ptr->feat))
569         {
570                 cave_alter_feat(y, x, FF_DISARM);
571                 msg_print(_("トラップを粉砕した。", "You destroyed the trap."));
572         }
573 }