6 #include "player-damage.h"
7 #include "player-move.h"
8 #include "player-effects.h"
9 #include "player-class.h"
10 #include "player-personality.h"
11 #include "spells-summon.h"
15 #include "player-status.h"
19 #include "floor-save.h"
24 #include "realm-song.h"
26 static s16b normal_traps[MAX_NORMAL_TRAPS];
33 * Each chest has a certain set of traps, determined by pval
34 * Each chest has a "pval" from 1 to the chest level (max 55)
35 * If the "pval" is negative then the trap has been disarmed
36 * The "pval" of a chest determines the quality of its treasure
37 * Note that disarming a trap on a chest also removes the lock.
40 const int chest_traps[64] =
47 (CHEST_LOSE_CON), /* 5 == best small wooden */
55 (CHEST_LOSE_STR | CHEST_LOSE_CON),
56 (CHEST_LOSE_STR | CHEST_LOSE_CON),
57 (CHEST_SUMMON), /* 15 == best large wooden */
62 (CHEST_LOSE_STR | CHEST_LOSE_CON),
67 (CHEST_EXPLODE), /* 25 == best small iron */
70 (CHEST_POISON | CHEST_LOSE_CON),
71 (CHEST_LOSE_STR | CHEST_LOSE_CON),
72 (CHEST_EXPLODE | CHEST_SUMMON),
74 (CHEST_POISON | CHEST_SUMMON),
75 (CHEST_E_SUMMON | CHEST_ALARM),
77 (CHEST_EXPLODE | CHEST_SUMMON), /* 35 == best large iron */
79 (CHEST_SUMMON | CHEST_ALARM),
81 (CHEST_EXPLODE | CHEST_SUMMON),
82 (CHEST_EXPLODE | CHEST_SUMMON),
83 (CHEST_POISON | CHEST_PARALYZE),
86 (CHEST_EXPLODE | CHEST_E_SUMMON | CHEST_ALARM),
87 (CHEST_H_SUMMON), /* 45 == best small steel */
89 (CHEST_EXPLODE | CHEST_SUMMON | CHEST_ALARM),
91 (CHEST_RUNES_OF_EVIL),
92 (CHEST_EXPLODE | CHEST_SUMMON | CHEST_ALARM),
93 (CHEST_BIRD_STORM | CHEST_ALARM),
94 (CHEST_H_SUMMON | CHEST_ALARM),
95 (CHEST_RUNES_OF_EVIL),
96 (CHEST_H_SUMMON | CHEST_SCATTER | CHEST_ALARM),
97 (CHEST_RUNES_OF_EVIL | CHEST_EXPLODE), /* 55 == best large steel */
98 (CHEST_EXPLODE | CHEST_SUMMON),
99 (CHEST_EXPLODE | CHEST_SUMMON),
100 (CHEST_EXPLODE | CHEST_SUMMON),
101 (CHEST_EXPLODE | CHEST_SUMMON),
102 (CHEST_EXPLODE | CHEST_SUMMON),
103 (CHEST_EXPLODE | CHEST_SUMMON),
104 (CHEST_EXPLODE | CHEST_SUMMON),
105 (CHEST_EXPLODE | CHEST_SUMMON),
110 * @brief タグに従って、基本トラップテーブルを初期化する / Initialize arrays for normal traps
113 void init_normal_traps(void)
117 normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_TRAPDOOR");
118 normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_PIT");
119 normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_SPIKED_PIT");
120 normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_POISON_PIT");
121 normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_TY_CURSE");
122 normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_TELEPORT");
123 normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_FIRE");
124 normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_ACID");
125 normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_SLOW");
126 normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_LOSE_STR");
127 normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_LOSE_DEX");
128 normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_LOSE_CON");
129 normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_BLIND");
130 normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_CONFUSE");
131 normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_POISON");
132 normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_SLEEP");
133 normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_TRAPS");
134 normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_ALARM");
138 * @brief 基本トラップをランダムに選択する /
140 * @return 選択したトラップのID
142 * This routine should be redone to reflect trap "level".\n
143 * That is, it does not make sense to have spiked pits at 50 feet.\n
144 * Actually, it is not this routine, but the "trap instantiation"\n
145 * code, which should also check for "trap doors" on quest levels.\n
147 FEAT_IDX choose_random_trap(void)
154 /* Hack -- pick a trap */
155 feat = normal_traps[randint0(MAX_NORMAL_TRAPS)];
157 /* Accept non-trapdoors */
158 if (!have_flag(f_info[feat].flags, FF_MORE)) break;
160 /* Hack -- no trap doors on special levels */
161 if (p_ptr->inside_arena || quest_number(current_floor_ptr->dun_level)) continue;
163 /* Hack -- no trap doors on the deepest level */
164 if (current_floor_ptr->dun_level >= d_info[p_ptr->dungeon_idx].maxdepth) continue;
173 * @brief マスに存在する隠しトラップを公開する /
174 * Disclose an invisible trap
175 * @param y 秘匿したいマスのY座標
176 * @param x 秘匿したいマスのX座標
179 void disclose_grid(POSITION y, POSITION x)
181 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
183 if (cave_have_flag_grid(g_ptr, FF_SECRET))
185 /* No longer hidden */
186 cave_alter_feat(y, x, FF_SECRET);
188 else if (g_ptr->mimic)
190 /* No longer hidden */
199 * @brief マスをトラップを配置する /
200 * The location must be a legal, naked, floor grid.
201 * @param y 配置したいマスのY座標
202 * @param x 配置したいマスのX座標
204 * Note that all traps start out as "invisible" and "untyped", and then\n
205 * when they are "discovered" (by detecting them or setting them off),\n
206 * the trap is "instantiated" as a visible, "typed", trap.\n
208 void place_trap(POSITION y, POSITION x)
210 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
212 /* Paranoia -- verify location */
213 if (!in_bounds(y, x)) return;
215 /* Require empty, clean, floor grid */
216 if (!cave_clean_bold(y, x)) return;
218 /* Place an invisible trap */
219 g_ptr->mimic = g_ptr->feat;
220 g_ptr->feat = choose_random_trap();
226 * @brief プレイヤーへのトラップ命中判定 /
227 * Determine if a trap affects the player.
228 * @param power 基本回避難度
229 * @return トラップが命中した場合TRUEを返す。
231 * Always miss 5% of the time, Always hit 5% of the time.
232 * Otherwise, match trap power against player armor.
234 static int check_hit(int power)
239 /* Percentile dice */
242 /* Hack -- 5% hit, 5% miss */
243 if (k < 10) return (k < 5);
245 if (p_ptr->pseikaku == SEIKAKU_NAMAKE)
246 if (one_in_(20)) return (TRUE);
248 /* Paranoia -- No power */
249 if (power <= 0) return (FALSE);
252 ac = p_ptr->ac + p_ptr->to_a;
254 /* Power competes against Armor */
255 if (randint1(power) > ((ac * 3) / 4)) return (TRUE);
263 * @brief 落とし穴系トラップの判定とプレイヤーの被害処理
264 * @param trap_feat_type トラップの種別ID
267 static void hit_trap_pit(int trap_feat_type)
270 concptr trap_name = "";
271 concptr spike_name = "";
273 switch (trap_feat_type)
276 trap_name = _("落とし穴", "a pit trap");
278 case TRAP_SPIKED_PIT:
279 trap_name = _("スパイクが敷かれた落とし穴", "a spiked pit");
280 spike_name = _("スパイク", "spikes");
282 case TRAP_POISON_PIT:
283 trap_name = _("スパイクが敷かれた落とし穴", "a spiked pit");
284 spike_name = _("毒を塗られたスパイク", "poisonous spikes");
290 if (p_ptr->levitation)
292 msg_format(_("%sを飛び越えた。", "You fly over %s."), trap_name);
296 msg_format(_("%sに落ちてしまった!", "You have fallen into %s!"), trap_name);
301 /* Extra spike damage */
302 if ((trap_feat_type == TRAP_SPIKED_PIT || trap_feat_type == TRAP_POISON_PIT) &&
305 msg_format(_("%sが刺さった!", "You are impaled on %s!"), spike_name);
308 (void)set_cut(p_ptr,p_ptr->cut + randint1(dam));
310 if (trap_feat_type == TRAP_POISON_PIT) {
311 if (p_ptr->resist_pois || IS_OPPOSE_POIS())
313 msg_print(_("しかし毒の影響はなかった!", "The poison does not affect you!"));
318 (void)set_poisoned(p_ptr, p_ptr->poisoned + randint1(dam));
323 take_hit(p_ptr, DAMAGE_NOESCAPE, dam, trap_name, -1);
327 * @brief ダーツ系トラップ(通常ダメージ)の判定とプレイヤーの被害処理
328 * @return ダーツが命中した場合TRUEを返す
330 static bool hit_trap_dart(void)
336 msg_print(_("小さなダーツが飛んできて刺さった!", "A small dart hits you!"));
337 take_hit(p_ptr, DAMAGE_ATTACK, damroll(1, 4), _("ダーツの罠", "a dart trap"), -1);
338 if (!CHECK_MULTISHADOW(p_ptr)) hit = TRUE;
342 msg_print(_("小さなダーツが飛んできた!が、運良く当たらなかった。", "A small dart barely misses you."));
349 * @brief ダーツ系トラップ(通常ダメージ+能力値減少)の判定とプレイヤーの被害処理
350 * @param stat 低下する能力値ID
353 static void hit_trap_lose_stat(int stat)
357 do_dec_stat(p_ptr, stat);
362 * @brief ダーツ系トラップ(通常ダメージ+減速)の判定とプレイヤーの被害処理
365 static void hit_trap_slow(void)
369 set_slow(p_ptr, p_ptr->slow + randint0(20) + 20, FALSE);
374 * @brief ダーツ系トラップ(通常ダメージ+状態異常)の判定とプレイヤーの被害処理
375 * @param trap_message メッセージの補完文字列
376 * @param resist 状態異常に抵抗する判定が出たならTRUE
377 * @param set_status 状態異常を指定する関数ポインタ
378 * @param current_world_ptr->game_turn 状態異常の追加ターン量
381 static void hit_trap_set_abnormal_status(concptr trap_message, bool resist, bool(*set_status)(IDX), IDX turn_aux)
383 msg_print(trap_message);
386 set_status(turn_aux);
390 static void hit_trap_set_abnormal_status_p(concptr trap_message, bool resist, bool(*set_status)(player_type *, IDX), IDX turn_aux)
392 msg_print(trap_message);
395 set_status(p_ptr, turn_aux);
400 * @brief プレイヤーへのトラップ作動処理メインルーチン /
401 * Handle player hitting a real trap
402 * @param break_trap 作動後のトラップ破壊が確定しているならばTRUE
405 void hit_trap(bool break_trap)
408 POSITION x = p_ptr->x, y = p_ptr->y;
409 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
410 feature_type *f_ptr = &f_info[g_ptr->feat];
411 int trap_feat_type = have_flag(f_ptr->flags, FF_TRAP) ? f_ptr->subtype : NOT_TRAP;
412 concptr name = _("トラップ", "a trap");
414 disturb(p_ptr, FALSE, TRUE);
416 cave_alter_feat(y, x, FF_HIT_TRAP);
419 switch (trap_feat_type)
423 if (p_ptr->levitation)
425 msg_print(_("落とし戸を飛び越えた。", "You fly over a trap door."));
429 msg_print(_("落とし戸に落ちた!", "You have fallen through a trap door!"));
430 if ((p_ptr->pseikaku == SEIKAKU_COMBAT) || (p_ptr->inventory_list[INVEN_BOW].name1 == ART_CRIMSON))
431 msg_print(_("くっそ~!", ""));
432 else if((p_ptr->pseikaku == SEIKAKU_CHARGEMAN))
433 msg_print(_("ジュラル星人の仕業に違いない!", ""));
438 name = _("落とし戸", "a trap door");
440 take_hit(p_ptr, DAMAGE_NOESCAPE, dam, name, -1);
442 /* Still alive and autosave enabled */
443 if (autosave_l && (p_ptr->chp >= 0))
444 do_cmd_save_game(TRUE);
446 exe_write_diary(p_ptr, NIKKI_BUNSHOU, 0, _("落とし戸に落ちた", "You have fallen through a trap door!"));
447 prepare_change_floor_mode(CFM_SAVE_FLOORS | CFM_DOWN | CFM_RAND_PLACE | CFM_RAND_CONNECT);
448 p_ptr->leaving = TRUE;
454 case TRAP_SPIKED_PIT:
455 case TRAP_POISON_PIT:
457 hit_trap_pit(trap_feat_type);
463 msg_print(_("何かがピカッと光った!", "There is a flash of shimmering light!"));
464 num = 2 + randint1(3);
465 for (i = 0; i < num; i++)
467 (void)summon_specific(0, y, x, current_floor_ptr->dun_level, 0, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
470 if (current_floor_ptr->dun_level > randint1(100)) /* No nasty effect for low levels */
472 bool stop_ty = FALSE;
477 stop_ty = activate_ty_curse(stop_ty, &count);
478 } while (one_in_(6));
485 msg_print(_("テレポート・トラップにひっかかった!", "You hit a teleport trap!"));
486 teleport_player(100, TELEPORT_PASSIVE);
492 msg_print(_("炎に包まれた!", "You are enveloped in flames!"));
494 (void)fire_dam(dam, _("炎のトラップ", "a fire trap"), -1, FALSE);
500 msg_print(_("酸が吹きかけられた!", "You are splashed with acid!"));
502 (void)acid_dam(dam, _("酸のトラップ", "an acid trap"), -1, FALSE);
514 hit_trap_lose_stat(A_STR);
520 hit_trap_lose_stat(A_DEX);
526 hit_trap_lose_stat(A_CON);
532 hit_trap_set_abnormal_status_p(
533 _("黒いガスに包み込まれた!", "A black gas surrounds you!"),
535 set_blind, p_ptr->blind + (TIME_EFFECT)randint0(50) + 25);
541 hit_trap_set_abnormal_status_p(
542 _("きらめくガスに包み込まれた!", "A gas of scintillating colors surrounds you!"),
544 set_confused, p_ptr->confused + (TIME_EFFECT)randint0(20) + 10);
550 hit_trap_set_abnormal_status_p(
551 _("刺激的な緑色のガスに包み込まれた!", "A pungent green gas surrounds you!"),
552 p_ptr->resist_pois || IS_OPPOSE_POIS(),
553 set_poisoned, p_ptr->poisoned + (TIME_EFFECT)randint0(20) + 10);
559 msg_print(_("奇妙な白い霧に包まれた!", "A strange white mist surrounds you!"));
560 if (!p_ptr->free_act)
562 msg_print(_("あなたは眠りに就いた。", "You fall asleep."));
564 if (ironman_nightmare)
566 msg_print(_("身の毛もよだつ光景が頭に浮かんだ。", "A horrible vision enters your mind."));
568 /* Have some nightmares */
569 sanity_blast(p_ptr, NULL, FALSE);
572 (void)set_paralyzed(p_ptr, p_ptr->paralyzed + randint0(10) + 5);
579 msg_print(_("まばゆい閃光が走った!", "There is a bright flash of light!"));
580 /* Make some new traps */
581 project(0, 1, y, x, 0, GF_MAKE_TRAP, PROJECT_HIDE | PROJECT_JUMP | PROJECT_GRID, -1);
588 msg_print(_("けたたましい音が鳴り響いた!", "An alarm sounds!"));
590 aggravate_monsters(0);
597 msg_print(_("大音響と共にまわりの壁が崩れた!", "Suddenly, surrounding walls are opened!"));
598 (void)project(0, 3, y, x, 0, GF_DISINTEGRATE, PROJECT_GRID | PROJECT_HIDE, -1);
599 (void)project(0, 3, y, x - 4, 0, GF_DISINTEGRATE, PROJECT_GRID | PROJECT_HIDE, -1);
600 (void)project(0, 3, y, x + 4, 0, GF_DISINTEGRATE, PROJECT_GRID | PROJECT_HIDE, -1);
601 aggravate_monsters(0);
606 case TRAP_ARMAGEDDON:
608 static int levs[10] = { 0, 0, 20, 10, 5, 3, 2, 1, 1, 1 };
609 int evil_idx = 0, good_idx = 0;
612 msg_print(_("突然天界の戦争に巻き込まれた!", "Suddenly, you are surrounded by immotal beings!"));
614 /* Summon Demons and Angels */
615 for (lev = current_floor_ptr->dun_level; lev >= 20; lev -= 1 + lev / 16)
617 num = levs[MIN(lev / 10, 9)];
618 for (i = 0; i < num; i++)
620 POSITION x1 = rand_spread(x, 7);
621 POSITION y1 = rand_spread(y, 5);
623 if (!in_bounds(y1, x1)) continue;
625 /* Require line of projection */
626 if (!projectable(p_ptr->y, p_ptr->x, y1, x1)) continue;
628 if (summon_specific(0, y1, x1, lev, SUMMON_ARMAGE_EVIL, (PM_NO_PET)))
629 evil_idx = hack_m_idx_ii;
631 if (summon_specific(0, y1, x1, lev, SUMMON_ARMAGE_GOOD, (PM_NO_PET)))
633 good_idx = hack_m_idx_ii;
636 /* Let them fight each other */
637 if (evil_idx && good_idx)
639 monster_type *evil_ptr = ¤t_floor_ptr->m_list[evil_idx];
640 monster_type *good_ptr = ¤t_floor_ptr->m_list[good_idx];
641 evil_ptr->target_y = good_ptr->fy;
642 evil_ptr->target_x = good_ptr->fx;
643 good_ptr->target_y = evil_ptr->fy;
644 good_ptr->target_x = evil_ptr->fx;
653 msg_print(_("突然壁から水が溢れ出した!ピラニアがいる!", "Suddenly, the room is filled with water with piranhas!"));
655 /* Water fills room */
656 fire_ball_hide(GF_WATER_FLOW, 0, 1, 10);
658 /* Summon Piranhas */
659 num = 1 + current_floor_ptr->dun_level / 20;
660 for (i = 0; i < num; i++)
662 (void)summon_specific(0, y, x, current_floor_ptr->dun_level, SUMMON_PIRANHAS, (PM_ALLOW_GROUP | PM_NO_PET));
668 if (break_trap && is_trap(g_ptr->feat))
670 cave_alter_feat(y, x, FF_DISARM);
671 msg_print(_("トラップを粉砕した。", "You destroyed the trap."));