5 #include "player-damage.h"
6 #include "player-move.h"
7 #include "player-effects.h"
8 #include "spells-summon.h"
12 #include "player-status.h"
16 #include "floor-save.h"
22 static s16b normal_traps[MAX_NORMAL_TRAPS];
29 * Each chest has a certain set of traps, determined by pval
30 * Each chest has a "pval" from 1 to the chest level (max 55)
31 * If the "pval" is negative then the trap has been disarmed
32 * The "pval" of a chest determines the quality of its treasure
33 * Note that disarming a trap on a chest also removes the lock.
36 const int chest_traps[64] =
43 (CHEST_LOSE_CON), /* 5 == best small wooden */
51 (CHEST_LOSE_STR | CHEST_LOSE_CON),
52 (CHEST_LOSE_STR | CHEST_LOSE_CON),
53 (CHEST_SUMMON), /* 15 == best large wooden */
58 (CHEST_LOSE_STR | CHEST_LOSE_CON),
63 (CHEST_EXPLODE), /* 25 == best small iron */
66 (CHEST_POISON | CHEST_LOSE_CON),
67 (CHEST_LOSE_STR | CHEST_LOSE_CON),
68 (CHEST_EXPLODE | CHEST_SUMMON),
70 (CHEST_POISON | CHEST_SUMMON),
71 (CHEST_E_SUMMON | CHEST_ALARM),
73 (CHEST_EXPLODE | CHEST_SUMMON), /* 35 == best large iron */
75 (CHEST_SUMMON | CHEST_ALARM),
77 (CHEST_EXPLODE | CHEST_SUMMON),
78 (CHEST_EXPLODE | CHEST_SUMMON),
79 (CHEST_POISON | CHEST_PARALYZE),
82 (CHEST_EXPLODE | CHEST_E_SUMMON | CHEST_ALARM),
83 (CHEST_H_SUMMON), /* 45 == best small steel */
85 (CHEST_EXPLODE | CHEST_SUMMON | CHEST_ALARM),
87 (CHEST_RUNES_OF_EVIL),
88 (CHEST_EXPLODE | CHEST_SUMMON | CHEST_ALARM),
89 (CHEST_BIRD_STORM | CHEST_ALARM),
90 (CHEST_H_SUMMON | CHEST_ALARM),
91 (CHEST_RUNES_OF_EVIL),
92 (CHEST_H_SUMMON | CHEST_SCATTER | CHEST_ALARM),
93 (CHEST_RUNES_OF_EVIL | CHEST_EXPLODE), /* 55 == best large steel */
94 (CHEST_EXPLODE | CHEST_SUMMON),
95 (CHEST_EXPLODE | CHEST_SUMMON),
96 (CHEST_EXPLODE | CHEST_SUMMON),
97 (CHEST_EXPLODE | CHEST_SUMMON),
98 (CHEST_EXPLODE | CHEST_SUMMON),
99 (CHEST_EXPLODE | CHEST_SUMMON),
100 (CHEST_EXPLODE | CHEST_SUMMON),
101 (CHEST_EXPLODE | CHEST_SUMMON),
106 * @brief タグに従って、基本トラップテーブルを初期化する / Initialize arrays for normal traps
109 void init_normal_traps(void)
113 normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_TRAPDOOR");
114 normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_PIT");
115 normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_SPIKED_PIT");
116 normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_POISON_PIT");
117 normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_TY_CURSE");
118 normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_TELEPORT");
119 normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_FIRE");
120 normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_ACID");
121 normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_SLOW");
122 normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_LOSE_STR");
123 normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_LOSE_DEX");
124 normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_LOSE_CON");
125 normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_BLIND");
126 normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_CONFUSE");
127 normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_POISON");
128 normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_SLEEP");
129 normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_TRAPS");
130 normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_ALARM");
134 * @brief 基本トラップをランダムに選択する /
136 * @return 選択したトラップのID
138 * This routine should be redone to reflect trap "level".\n
139 * That is, it does not make sense to have spiked pits at 50 feet.\n
140 * Actually, it is not this routine, but the "trap instantiation"\n
141 * code, which should also check for "trap doors" on quest levels.\n
143 FEAT_IDX choose_random_trap(void)
150 /* Hack -- pick a trap */
151 feat = normal_traps[randint0(MAX_NORMAL_TRAPS)];
153 /* Accept non-trapdoors */
154 if (!have_flag(f_info[feat].flags, FF_MORE)) break;
156 /* Hack -- no trap doors on special levels */
157 if (p_ptr->inside_arena || quest_number(current_floor_ptr->dun_level)) continue;
159 /* Hack -- no trap doors on the deepest level */
160 if (current_floor_ptr->dun_level >= d_info[p_ptr->dungeon_idx].maxdepth) continue;
169 * @brief マスに存在するトラップを秘匿する /
170 * Disclose an invisible trap
171 * @param y 秘匿したいマスのY座標
172 * @param x 秘匿したいマスのX座標
175 void disclose_grid(POSITION y, POSITION x)
177 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
179 if (cave_have_flag_grid(g_ptr, FF_SECRET))
181 /* No longer hidden */
182 cave_alter_feat(y, x, FF_SECRET);
184 else if (g_ptr->mimic)
186 /* No longer hidden */
195 * @brief マスをトラップを配置する /
196 * The location must be a legal, naked, floor grid.
197 * @param y 配置したいマスのY座標
198 * @param x 配置したいマスのX座標
200 * Note that all traps start out as "invisible" and "untyped", and then\n
201 * when they are "discovered" (by detecting them or setting them off),\n
202 * the trap is "instantiated" as a visible, "typed", trap.\n
204 void place_trap(POSITION y, POSITION x)
206 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
208 /* Paranoia -- verify location */
209 if (!in_bounds(y, x)) return;
211 /* Require empty, clean, floor grid */
212 if (!cave_clean_bold(y, x)) return;
214 /* Place an invisible trap */
215 g_ptr->mimic = g_ptr->feat;
216 g_ptr->feat = choose_random_trap();
222 * @brief プレイヤーへのトラップ命中判定 /
223 * Determine if a trap affects the player.
224 * @param power 基本回避難度
225 * @return トラップが命中した場合TRUEを返す。
227 * Always miss 5% of the time, Always hit 5% of the time.
228 * Otherwise, match trap power against player armor.
230 static int check_hit(int power)
235 /* Percentile dice */
238 /* Hack -- 5% hit, 5% miss */
239 if (k < 10) return (k < 5);
241 if (p_ptr->pseikaku == SEIKAKU_NAMAKE)
242 if (one_in_(20)) return (TRUE);
244 /* Paranoia -- No power */
245 if (power <= 0) return (FALSE);
248 ac = p_ptr->ac + p_ptr->to_a;
250 /* Power competes against Armor */
251 if (randint1(power) > ((ac * 3) / 4)) return (TRUE);
259 * @brief 落とし穴系トラップの判定とプレイヤーの被害処理
260 * @param trap_feat_type トラップの種別ID
263 static void hit_trap_pit(int trap_feat_type)
266 concptr trap_name = "";
267 concptr spike_name = "";
269 switch (trap_feat_type)
272 trap_name = _("落とし穴", "a pit trap");
274 case TRAP_SPIKED_PIT:
275 trap_name = _("スパイクが敷かれた落とし穴", "a spiked pit");
276 spike_name = _("スパイク", "spikes");
278 case TRAP_POISON_PIT:
279 trap_name = _("スパイクが敷かれた落とし穴", "a spiked pit");
280 spike_name = _("毒を塗られたスパイク", "poisonous spikes");
286 if (p_ptr->levitation)
288 msg_format(_("%sを飛び越えた。", "You fly over %s."), trap_name);
292 msg_format(_("%sに落ちてしまった!", "You have fallen into %s!"), trap_name);
297 /* Extra spike damage */
298 if ((trap_feat_type == TRAP_SPIKED_PIT || trap_feat_type == TRAP_POISON_PIT) &&
301 msg_format(_("%sが刺さった!", "You are impaled on %s!"), spike_name);
304 (void)set_cut(p_ptr->cut + randint1(dam));
306 if (trap_feat_type == TRAP_POISON_PIT) {
307 if (p_ptr->resist_pois || IS_OPPOSE_POIS())
309 msg_print(_("しかし毒の影響はなかった!", "The poison does not affect you!"));
314 (void)set_poisoned(p_ptr->poisoned + randint1(dam));
319 take_hit(DAMAGE_NOESCAPE, dam, trap_name, -1);
323 * @brief ダーツ系トラップ(通常ダメージ)の判定とプレイヤーの被害処理
324 * @return ダーツが命中した場合TRUEを返す
326 static bool hit_trap_dart(void)
332 msg_print(_("小さなダーツが飛んできて刺さった!", "A small dart hits you!"));
333 take_hit(DAMAGE_ATTACK, damroll(1, 4), _("ダーツの罠", "a dart trap"), -1);
334 if (!CHECK_MULTISHADOW()) hit = TRUE;
338 msg_print(_("小さなダーツが飛んできた!が、運良く当たらなかった。", "A small dart barely misses you."));
345 * @brief ダーツ系トラップ(通常ダメージ+能力値減少)の判定とプレイヤーの被害処理
346 * @param stat 低下する能力値ID
349 static void hit_trap_lose_stat(int stat)
358 * @brief ダーツ系トラップ(通常ダメージ+減速)の判定とプレイヤーの被害処理
361 static void hit_trap_slow(void)
365 set_slow(p_ptr->slow + randint0(20) + 20, FALSE);
370 * @brief ダーツ系トラップ(通常ダメージ+状態異常)の判定とプレイヤーの被害処理
371 * @param trap_message メッセージの補完文字列
372 * @param resist 状態異常に抵抗する判定が出たならTRUE
373 * @param set_status 状態異常を指定する関数ポインタ
374 * @param current_world_ptr->game_turn 状態異常の追加ターン量
377 static void hit_trap_set_abnormal_status(concptr trap_message, bool resist, bool(*set_status)(IDX), IDX turn_aux)
379 msg_print(trap_message);
382 set_status(turn_aux);
387 * @brief プレイヤーへのトラップ作動処理メインルーチン /
388 * Handle player hitting a real trap
389 * @param break_trap 作動後のトラップ破壊が確定しているならばTRUE
392 void hit_trap(bool break_trap)
395 POSITION x = p_ptr->x, y = p_ptr->y;
396 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
397 feature_type *f_ptr = &f_info[g_ptr->feat];
398 int trap_feat_type = have_flag(f_ptr->flags, FF_TRAP) ? f_ptr->subtype : NOT_TRAP;
399 concptr name = _("トラップ", "a trap");
401 disturb(FALSE, TRUE);
403 cave_alter_feat(y, x, FF_HIT_TRAP);
406 switch (trap_feat_type)
410 if (p_ptr->levitation)
412 msg_print(_("落とし戸を飛び越えた。", "You fly over a trap door."));
416 msg_print(_("落とし戸に落ちた!", "You have fallen through a trap door!"));
417 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (inventory[INVEN_BOW].name1 == ART_CRIMSON))
418 msg_print(_("くっそ~!", ""));
419 else if((p_ptr->pseikaku == SEIKAKU_CHARGEMAN))
420 msg_print(_("ジュラル星人の仕業に違いない!", ""));
425 name = _("落とし戸", "a trap door");
427 take_hit(DAMAGE_NOESCAPE, dam, name, -1);
429 /* Still alive and autosave enabled */
430 if (autosave_l && (p_ptr->chp >= 0))
431 do_cmd_save_game(TRUE);
433 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, _("落とし戸に落ちた", "You have fallen through a trap door!"));
434 prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_DOWN | CFM_RAND_PLACE | CFM_RAND_CONNECT);
435 p_ptr->leaving = TRUE;
441 case TRAP_SPIKED_PIT:
442 case TRAP_POISON_PIT:
444 hit_trap_pit(trap_feat_type);
450 msg_print(_("何かがピカッと光った!", "There is a flash of shimmering light!"));
451 num = 2 + randint1(3);
452 for (i = 0; i < num; i++)
454 (void)summon_specific(0, y, x, current_floor_ptr->dun_level, 0, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET), '\0');
457 if (current_floor_ptr->dun_level > randint1(100)) /* No nasty effect for low levels */
459 bool stop_ty = FALSE;
464 stop_ty = activate_ty_curse(stop_ty, &count);
465 } while (one_in_(6));
472 msg_print(_("テレポート・トラップにひっかかった!", "You hit a teleport trap!"));
473 teleport_player(100, TELEPORT_PASSIVE);
479 msg_print(_("炎に包まれた!", "You are enveloped in flames!"));
481 (void)fire_dam(dam, _("炎のトラップ", "a fire trap"), -1, FALSE);
487 msg_print(_("酸が吹きかけられた!", "You are splashed with acid!"));
489 (void)acid_dam(dam, _("酸のトラップ", "an acid trap"), -1, FALSE);
501 hit_trap_lose_stat(A_STR);
507 hit_trap_lose_stat(A_DEX);
513 hit_trap_lose_stat(A_CON);
519 hit_trap_set_abnormal_status(
520 _("黒いガスに包み込まれた!", "A black gas surrounds you!"),
522 set_blind, p_ptr->blind + (TIME_EFFECT)randint0(50) + 25);
528 hit_trap_set_abnormal_status(
529 _("きらめくガスに包み込まれた!", "A gas of scintillating colors surrounds you!"),
531 set_confused, p_ptr->confused + (TIME_EFFECT)randint0(20) + 10);
537 hit_trap_set_abnormal_status(
538 _("刺激的な緑色のガスに包み込まれた!", "A pungent green gas surrounds you!"),
539 p_ptr->resist_pois || IS_OPPOSE_POIS(),
540 set_poisoned, p_ptr->poisoned + (TIME_EFFECT)randint0(20) + 10);
546 msg_print(_("奇妙な白い霧に包まれた!", "A strange white mist surrounds you!"));
547 if (!p_ptr->free_act)
549 msg_print(_("あなたは眠りに就いた。", "You fall asleep."));
551 if (ironman_nightmare)
553 msg_print(_("身の毛もよだつ光景が頭に浮かんだ。", "A horrible vision enters your mind."));
555 /* Have some nightmares */
556 sanity_blast(NULL, FALSE);
559 (void)set_paralyzed(p_ptr->paralyzed + randint0(10) + 5);
566 msg_print(_("まばゆい閃光が走った!", "There is a bright flash of light!"));
567 /* Make some new traps */
568 project(0, 1, y, x, 0, GF_MAKE_TRAP, PROJECT_HIDE | PROJECT_JUMP | PROJECT_GRID, -1);
575 msg_print(_("けたたましい音が鳴り響いた!", "An alarm sounds!"));
577 aggravate_monsters(0);
584 msg_print(_("大音響と共にまわりの壁が崩れた!", "Suddenly, surrounding walls are opened!"));
585 (void)project(0, 3, y, x, 0, GF_DISINTEGRATE, PROJECT_GRID | PROJECT_HIDE, -1);
586 (void)project(0, 3, y, x - 4, 0, GF_DISINTEGRATE, PROJECT_GRID | PROJECT_HIDE, -1);
587 (void)project(0, 3, y, x + 4, 0, GF_DISINTEGRATE, PROJECT_GRID | PROJECT_HIDE, -1);
588 aggravate_monsters(0);
593 case TRAP_ARMAGEDDON:
595 static int levs[10] = { 0, 0, 20, 10, 5, 3, 2, 1, 1, 1 };
596 int evil_idx = 0, good_idx = 0;
599 msg_print(_("突然天界の戦争に巻き込まれた!", "Suddenly, you are surrounded by immotal beings!"));
601 /* Summon Demons and Angels */
602 for (lev = current_floor_ptr->dun_level; lev >= 20; lev -= 1 + lev / 16)
604 num = levs[MIN(lev / 10, 9)];
605 for (i = 0; i < num; i++)
607 POSITION x1 = rand_spread(x, 7);
608 POSITION y1 = rand_spread(y, 5);
610 /* Skip illegal grids */
611 if (!in_bounds(y1, x1)) continue;
613 /* Require line of projection */
614 if (!projectable(p_ptr->y, p_ptr->x, y1, x1)) continue;
616 if (summon_specific(0, y1, x1, lev, SUMMON_ARMAGE_EVIL, (PM_NO_PET), '\0'))
617 evil_idx = hack_m_idx_ii;
619 if (summon_specific(0, y1, x1, lev, SUMMON_ARMAGE_GOOD, (PM_NO_PET), '\0'))
621 good_idx = hack_m_idx_ii;
624 /* Let them fight each other */
625 if (evil_idx && good_idx)
627 monster_type *evil_ptr = ¤t_floor_ptr->m_list[evil_idx];
628 monster_type *good_ptr = ¤t_floor_ptr->m_list[good_idx];
629 evil_ptr->target_y = good_ptr->fy;
630 evil_ptr->target_x = good_ptr->fx;
631 good_ptr->target_y = evil_ptr->fy;
632 good_ptr->target_x = evil_ptr->fx;
641 msg_print(_("突然壁から水が溢れ出した!ピラニアがいる!", "Suddenly, the room is filled with water with piranhas!"));
643 /* Water fills room */
644 fire_ball_hide(GF_WATER_FLOW, 0, 1, 10);
646 /* Summon Piranhas */
647 num = 1 + current_floor_ptr->dun_level / 20;
648 for (i = 0; i < num; i++)
650 (void)summon_specific(0, y, x, current_floor_ptr->dun_level, SUMMON_PIRANHAS, (PM_ALLOW_GROUP | PM_NO_PET), '\0');
656 if (break_trap && is_trap(g_ptr->feat))
658 cave_alter_feat(y, x, FF_DISARM);
659 msg_print(_("トラップを粉砕した。", "You destroyed the trap."));