1 #include "player/player-damage.h"
2 #include "autopick/autopick-pref-processor.h"
3 #include "blue-magic/blue-magic-checker.h"
4 #include "cmd-io/cmd-process-screen.h"
5 #include "core/asking-player.h"
6 #include "core/disturbance.h"
7 #include "core/player-redraw-types.h"
8 #include "core/player-update-types.h"
9 #include "core/stuff-handler.h"
10 #include "core/window-redrawer.h"
11 #include "dungeon/quest.h"
12 #include "flavor/flavor-describer.h"
13 #include "flavor/object-flavor-types.h"
14 #include "floor/wild.h"
15 #include "game-option/birth-options.h"
16 #include "game-option/cheat-options.h"
17 #include "game-option/game-play-options.h"
18 #include "game-option/input-options.h"
19 #include "game-option/play-record-options.h"
20 #include "game-option/special-options.h"
21 #include "inventory/inventory-damage.h"
22 #include "inventory/inventory-slot-types.h"
23 #include "io/input-key-acceptor.h"
24 #include "io/report.h"
25 #include "io/write-diary.h"
26 #include "main/music-definitions-table.h"
27 #include "main/sound-definitions-table.h"
28 #include "main/sound-of-music.h"
29 #include "market/arena-info-table.h"
30 #include "mind/mind-mirror-master.h"
31 #include "monster-race/monster-race.h"
32 #include "monster-race/race-flags2.h"
33 #include "monster-race/race-flags3.h"
34 #include "monster/monster-describer.h"
35 #include "monster/monster-description-types.h"
36 #include "monster/monster-info.h"
37 #include "mutation/mutation-flag-types.h"
38 #include "object-enchant/tr-types.h"
39 #include "object-hook/hook-armor.h"
40 #include "object/item-tester-hooker.h"
41 #include "object/object-broken.h"
42 #include "object/object-flags.h"
43 #include "player-info/avatar.h"
44 #include "player/player-class.h"
45 #include "player/player-personalities-types.h"
46 #include "player/player-race-types.h"
47 #include "player/race-info-table.h"
48 #include "player/special-defense-types.h"
49 #include "player/player-status-flags.h"
50 #include "player/player-status-resist.h"
51 #include "racial/racial-android.h"
52 #include "save/save.h"
53 #include "status/base-status.h"
54 #include "status/element-resistance.h"
55 #include "system/building-type-definition.h"
56 #include "system/floor-type-definition.h"
57 #include "term/screen-processor.h"
58 #include "term/term-color-types.h"
59 #include "util/bit-flags-calculator.h"
60 #include "util/string-processor.h"
61 #include "view/display-messages.h"
62 #include "world/world.h"
65 * @brief 酸攻撃による装備のAC劣化処理 /
66 * Acid has hit the player, attempt to affect some armor.
67 * @param 酸を浴びたキャラクタへの参照ポインタ
68 * @return 装備による軽減があったならTRUEを返す
70 * Note that the "base armor" of an object never changes.
71 * If any armor is damaged (or resists), the player takes less damage.
73 static bool acid_minus_ac(player_type *creature_ptr)
75 object_type *o_ptr = NULL;
76 BIT_FLAGS flgs[TR_FLAG_SIZE];
77 GAME_TEXT o_name[MAX_NLEN];
79 /* Pick a (possibly empty) creature_ptr->inventory_list slot */
80 switch (randint1(7)) {
82 o_ptr = &creature_ptr->inventory_list[INVEN_RARM];
85 o_ptr = &creature_ptr->inventory_list[INVEN_LARM];
88 o_ptr = &creature_ptr->inventory_list[INVEN_BODY];
91 o_ptr = &creature_ptr->inventory_list[INVEN_OUTER];
94 o_ptr = &creature_ptr->inventory_list[INVEN_HANDS];
97 o_ptr = &creature_ptr->inventory_list[INVEN_HEAD];
100 o_ptr = &creature_ptr->inventory_list[INVEN_FEET];
106 if (!object_is_armour(creature_ptr, o_ptr))
109 describe_flavor(creature_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
110 object_flags(creature_ptr, o_ptr, flgs);
111 /* No damage left to be done */
112 if (o_ptr->ac + o_ptr->to_a <= 0) {
113 msg_format(_("%sは既にボロボロだ!", "Your %s is already fully corroded!"), o_name);
118 if (has_flag(flgs, TR_IGNORE_ACID)) {
119 msg_format(_("しかし%sには効果がなかった!", "Your %s is unaffected!"), o_name);
123 msg_format(_("%sが酸で腐食した!", "Your %s is corroded!"), o_name);
125 /* Damage the item */
128 /* Calculate bonuses */
129 creature_ptr->update |= (PU_BONUS);
130 creature_ptr->window |= (PW_EQUIP | PW_PLAYER);
132 calc_android_exp(creature_ptr);
134 /* Item was damaged */
139 * @brief 酸属性によるプレイヤー損害処理 /
140 * Hurt the player with Acid
141 * @param creature_ptr 酸を浴びたキャラクタへの参照ポインタ
143 * @param kb_str ダメージ原因記述
144 * @param monspell 原因となったモンスター特殊攻撃ID
145 * @param aura オーラよるダメージが原因ならばTRUE
148 HIT_POINT acid_dam(player_type *creature_ptr, HIT_POINT dam, concptr kb_str, int monspell, bool aura)
150 HIT_POINT get_damage;
151 int inv = (dam < 30) ? 1 : (dam < 60) ? 2 : 3;
152 bool double_resist = is_oppose_acid(creature_ptr);
154 dam = dam * calc_acid_damage_rate(creature_ptr) / 100;
157 learn_spell(creature_ptr, monspell);
161 if (aura || !check_multishadow(creature_ptr)) {
162 if ((!(double_resist || creature_ptr->resist_acid)) && one_in_(HURT_CHANCE))
163 (void)do_dec_stat(creature_ptr, A_CHR);
165 /* If any armor gets hit, defend the player */
166 if (acid_minus_ac(creature_ptr))
170 get_damage = take_hit(creature_ptr, aura ? DAMAGE_NOESCAPE : DAMAGE_ATTACK, dam, kb_str, monspell);
172 /* Inventory damage */
173 if (!aura && !(double_resist && creature_ptr->resist_acid))
174 inventory_damage(creature_ptr, set_acid_destroy, inv);
179 * @brief 電撃属性によるプレイヤー損害処理 /
180 * Hurt the player with electricity
181 * @param creature_ptr 電撃を浴びたキャラクタへの参照ポインタ
183 * @param kb_str ダメージ原因記述
184 * @param monspell 原因となったモンスター特殊攻撃ID
185 * @param aura オーラよるダメージが原因ならばTRUE
188 HIT_POINT elec_dam(player_type *creature_ptr, HIT_POINT dam, concptr kb_str, int monspell, bool aura)
190 HIT_POINT get_damage;
191 int inv = (dam < 30) ? 1 : (dam < 60) ? 2 : 3;
192 bool double_resist = is_oppose_elec(creature_ptr);
194 dam = dam * calc_elec_damage_rate(creature_ptr) / 100;
197 learn_spell(creature_ptr, monspell);
201 if (aura || !check_multishadow(creature_ptr)) {
202 if ((!(double_resist || creature_ptr->resist_elec)) && one_in_(HURT_CHANCE))
203 (void)do_dec_stat(creature_ptr, A_DEX);
206 get_damage = take_hit(creature_ptr, aura ? DAMAGE_NOESCAPE : DAMAGE_ATTACK, dam, kb_str, monspell);
208 /* Inventory damage */
209 if (!aura && !(double_resist && creature_ptr->resist_elec))
210 inventory_damage(creature_ptr, set_elec_destroy, inv);
216 * @brief 火炎属性によるプレイヤー損害処理 /
217 * Hurt the player with Fire
218 * @param creature_ptr 火炎を浴びたキャラクタへの参照ポインタ
220 * @param kb_str ダメージ原因記述
221 * @param monspell 原因となったモンスター特殊攻撃ID
222 * @param aura オーラよるダメージが原因ならばTRUE
225 HIT_POINT fire_dam(player_type *creature_ptr, HIT_POINT dam, concptr kb_str, int monspell, bool aura)
227 HIT_POINT get_damage;
228 int inv = (dam < 30) ? 1 : (dam < 60) ? 2 : 3;
229 bool double_resist = is_oppose_fire(creature_ptr);
232 if (is_immune_fire(creature_ptr) || (dam <= 0)) {
233 learn_spell(creature_ptr, monspell);
237 dam = dam * calc_fire_damage_rate(creature_ptr) / 100;
239 if (aura || !check_multishadow(creature_ptr)) {
240 if ((!(double_resist || creature_ptr->resist_fire)) && one_in_(HURT_CHANCE))
241 (void)do_dec_stat(creature_ptr, A_STR);
244 get_damage = take_hit(creature_ptr, aura ? DAMAGE_NOESCAPE : DAMAGE_ATTACK, dam, kb_str, monspell);
246 /* Inventory damage */
247 if (!aura && !(double_resist && creature_ptr->resist_fire))
248 inventory_damage(creature_ptr, set_fire_destroy, inv);
254 * @brief 冷気属性によるプレイヤー損害処理 /
255 * Hurt the player with Cold
256 * @param creature_ptr 冷気を浴びたキャラクタへの参照ポインタ
258 * @param kb_str ダメージ原因記述
259 * @param monspell 原因となったモンスター特殊攻撃ID
260 * @param aura オーラよるダメージが原因ならばTRUE
263 HIT_POINT cold_dam(player_type *creature_ptr, HIT_POINT dam, concptr kb_str, int monspell, bool aura)
265 HIT_POINT get_damage;
266 int inv = (dam < 30) ? 1 : (dam < 60) ? 2 : 3;
267 bool double_resist = is_oppose_cold(creature_ptr);
270 if (is_immune_cold(creature_ptr) || (dam <= 0)) {
271 learn_spell(creature_ptr, monspell);
275 /* Vulnerability (Ouch!) */
276 dam = dam * calc_cold_damage_rate(creature_ptr) / 100;
278 /* Resist the damage */
279 if (creature_ptr->resist_cold)
284 if (aura || !check_multishadow(creature_ptr)) {
285 if ((!(double_resist || creature_ptr->resist_cold)) && one_in_(HURT_CHANCE))
286 (void)do_dec_stat(creature_ptr, A_STR);
289 get_damage = take_hit(creature_ptr, aura ? DAMAGE_NOESCAPE : DAMAGE_ATTACK, dam, kb_str, monspell);
291 /* Inventory damage */
292 if (!aura && !(double_resist && creature_ptr->resist_cold))
293 inventory_damage(creature_ptr, set_cold_destroy, inv);
299 * Decreases players hit points and sets death flag if necessary
301 * Invulnerability needs to be changed into a "shield"
303 * Hack -- this function allows the user to save (or quit)
304 * the game when he dies, since the "You die." message is shown before
305 * setting the player to "dead".
307 int take_hit(player_type *creature_ptr, int damage_type, HIT_POINT damage, concptr hit_from, int monspell)
309 int old_chp = creature_ptr->chp;
311 char death_message[1024];
314 int warning = (creature_ptr->mhp * hitpoint_warn / 10);
315 if (creature_ptr->is_dead)
318 if (creature_ptr->sutemi)
320 if (creature_ptr->special_defense & KATA_IAI)
321 damage += (damage + 4) / 5;
324 damage = (damage + 1) / 2;
326 if (damage_type != DAMAGE_USELIFE) {
327 disturb(creature_ptr, TRUE, TRUE);
329 creature_ptr->now_damaged = TRUE;
334 learn_spell(creature_ptr, monspell);
336 /* Mega-Hack -- Apply "invulnerability" */
337 if ((damage_type != DAMAGE_USELIFE) && (damage_type != DAMAGE_LOSELIFE)) {
338 if (is_invuln(creature_ptr) && (damage < 9000)) {
339 if (damage_type == DAMAGE_FORCE) {
340 msg_print(_("バリアが切り裂かれた!", "The attack cuts your shield of invulnerability open!"));
341 } else if (one_in_(PENETRATE_INVULNERABILITY)) {
342 msg_print(_("無敵のバリアを破って攻撃された!", "The attack penetrates your shield of invulnerability!"));
348 if (check_multishadow(creature_ptr)) {
349 if (damage_type == DAMAGE_FORCE) {
350 msg_print(_("幻影もろとも体が切り裂かれた!", "The attack hits Shadow together with you!"));
351 } else if (damage_type == DAMAGE_ATTACK) {
352 msg_print(_("攻撃は幻影に命中し、あなたには届かなかった。", "The attack hits Shadow, but you are unharmed!"));
357 if (creature_ptr->wraith_form) {
358 if (damage_type == DAMAGE_FORCE) {
359 msg_print(_("半物質の体が切り裂かれた!", "The attack cuts through your ethereal body!"));
362 if ((damage == 0) && one_in_(2))
367 if (creature_ptr->special_defense & KATA_MUSOU) {
369 if ((damage == 0) && one_in_(2))
372 } /* not if LOSELIFE USELIFE */
374 /* Hurt the player */
375 creature_ptr->chp -= damage;
376 if (damage_type == DAMAGE_GENO && creature_ptr->chp < 0) {
377 damage += creature_ptr->chp;
378 creature_ptr->chp = 0;
381 /* Display the hitpoints */
382 creature_ptr->redraw |= (PR_HP);
384 creature_ptr->window |= (PW_PLAYER);
386 if (damage_type != DAMAGE_GENO && creature_ptr->chp == 0) {
387 chg_virtue(creature_ptr, V_SACRIFICE, 1);
388 chg_virtue(creature_ptr, V_CHANCE, 2);
392 if (creature_ptr->chp < 0) {
393 bool android = (creature_ptr->prace == RACE_ANDROID ? TRUE : FALSE);
396 /* 死んだ時に強制終了して死を回避できなくしてみた by Habu */
398 if (!save_player(creature_ptr))
404 chg_virtue(creature_ptr, V_SACRIFICE, 10);
406 handle_stuff(creature_ptr);
407 creature_ptr->leaving = TRUE;
410 creature_ptr->is_dead = TRUE;
412 if (creature_ptr->current_floor_ptr->inside_arena) {
413 concptr m_name = r_name + r_info[arena_info[creature_ptr->arena_number].r_idx].name;
414 msg_format(_("あなたは%sの前に敗れ去った。", "You are beaten by %s."), m_name);
417 exe_write_diary(creature_ptr, DIARY_ARENA, -1 - creature_ptr->arena_number, m_name);
419 QUEST_IDX q_idx = quest_number(creature_ptr, creature_ptr->current_floor_ptr->dun_level);
420 bool seppuku = streq(hit_from, "Seppuku");
421 bool winning_seppuku = current_world_ptr->total_winner && seppuku;
423 play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_GAMEOVER);
426 /* Make screen dump */
427 screen_dump = make_screen_dump(creature_ptr, process_autopick_file_command);
430 /* Note cause of death */
432 strcpy(creature_ptr->died_from, hit_from);
434 if (!winning_seppuku)
435 strcpy(creature_ptr->died_from, "切腹");
440 sprintf(dummy, "%s%s%s", !creature_ptr->paralyzed ? "" : creature_ptr->free_act ? "彫像状態で" : "麻痺状態で",
441 creature_ptr->image ? "幻覚に歪んだ" : "", hit_from);
443 sprintf(dummy, "%s%s", hit_from, !creature_ptr->paralyzed ? "" : " while helpless");
445 angband_strcpy(creature_ptr->died_from, dummy, sizeof creature_ptr->died_from);
448 /* No longer a winner */
449 current_world_ptr->total_winner = FALSE;
451 if (winning_seppuku) {
452 exe_write_diary(creature_ptr, DIARY_DESCRIPTION, 0, _("勝利の後切腹した。", "committed seppuku after the winning."));
456 if (creature_ptr->current_floor_ptr->inside_arena)
457 strcpy(buf, _("アリーナ", "in the Arena"));
458 else if (!creature_ptr->current_floor_ptr->dun_level)
459 strcpy(buf, _("地上", "on the surface"));
460 else if (q_idx && (is_fixed_quest_idx(q_idx) && !((q_idx == QUEST_OBERON) || (q_idx == QUEST_SERPENT))))
461 strcpy(buf, _("クエスト", "in a quest"));
463 sprintf(buf, _("%d階", "level %d"), (int)creature_ptr->current_floor_ptr->dun_level);
465 sprintf(tmp, _("%sで%sに殺された。", "killed by %s %s."), buf, creature_ptr->died_from);
466 exe_write_diary(creature_ptr, DIARY_DESCRIPTION, 0, tmp);
469 exe_write_diary(creature_ptr, DIARY_GAMESTART, 1, _("-------- ゲームオーバー --------", "-------- Game Over --------"));
470 exe_write_diary(creature_ptr, DIARY_DESCRIPTION, 1, "\n\n\n\n");
474 if (get_check_strict(creature_ptr, _("画面を保存しますか?", "Dump the screen? "), CHECK_NO_HISTORY)) {
475 do_cmd_save_screen(creature_ptr, process_autopick_file_command);
480 /* Initialize "last message" buffer */
481 if (creature_ptr->last_message)
482 string_free(creature_ptr->last_message);
483 creature_ptr->last_message = NULL;
485 /* Hack -- Note death */
488 msg_format("あなたは%sました。", android ? "壊れ" : "死に");
490 msg_print(android ? "You are broken." : "You die.");
495 if (winning_seppuku) {
496 get_rnd_line(_("seppuku_j.txt", "seppuku.txt"), 0, death_message);
498 get_rnd_line(_("death_j.txt", "death.txt"), 0, death_message);
503 while (!get_string(winning_seppuku ? "辞世の句: " : "断末魔の叫び: ", death_message, 1024))
506 while (!get_string("Last word: ", death_message, 1024))
509 } while (winning_seppuku && !get_check_strict(creature_ptr, _("よろしいですか?", "Are you sure? "), CHECK_NO_HISTORY));
511 if (death_message[0] == '\0') {
513 strcpy(death_message, format("あなたは%sました。", android ? "壊れ" : "死に"));
515 strcpy(death_message, android ? "You are broken." : "You die.");
518 creature_ptr->last_message = string_make(death_message);
521 if (winning_seppuku) {
525 int msg_pos_x[9] = { 5, 7, 9, 12, 14, 17, 19, 21, 23 };
526 int msg_pos_y[9] = { 3, 4, 5, 4, 5, 4, 5, 6, 4 };
533 for (i = 0; i < 40; i++)
534 term_putstr(randint0(w / 2) * 2, randint0(h), 2, TERM_VIOLET, "υ");
537 if (strncmp(str, "「", 2) == 0)
540 str2 = angband_strstr(str, "」");
546 str2 = angband_strstr(str, " ");
553 term_putstr_v(w * 3 / 4 - 2 - msg_pos_x[i] * 2, msg_pos_y[i], len, TERM_WHITE, str);
564 term_putstr(w - 1, h - 1, 1, TERM_WHITE, " ");
568 /* Make screen dump */
569 screen_dump = make_screen_dump(creature_ptr, process_autopick_file_command);
572 /* Wait a key press */
576 msg_print(death_message);
584 handle_stuff(creature_ptr);
586 /* Hitpoint warning */
587 if (creature_ptr->chp < warning) {
588 /* Hack -- bell on first notice */
589 if (old_chp > warning)
594 if (record_danger && (old_chp > warning)) {
595 if (creature_ptr->image && damage_type == DAMAGE_ATTACK)
596 hit_from = _("何か", "something");
598 sprintf(tmp, _("%sによってピンチに陥った。", "was in a critical situation because of %s."), hit_from);
599 exe_write_diary(creature_ptr, DIARY_DESCRIPTION, 0, tmp);
603 /* stop auto_more even if DAMAGE_USELIFE */
604 creature_ptr->now_damaged = TRUE;
607 msg_print(_("*** 警告:低ヒット・ポイント! ***", "*** LOW HITPOINT WARNING! ***"));
611 if (creature_ptr->wild_mode && !creature_ptr->leaving && (creature_ptr->chp < MAX(warning, creature_ptr->mhp / 5))) {
612 change_wild_mode(creature_ptr, FALSE);
618 * @brief 属性に応じた敵オーラによるプレイヤーのダメージ処理
619 * @param m_ptr オーラを持つモンスターの構造体参照ポインタ
620 * @param immune ダメージを回避できる免疫フラグ
621 * @param flags_offset オーラフラグ配列の参照オフセット
622 * @param r_flags_offset モンスターの耐性配列の参照オフセット
623 * @param aura_flag オーラフラグ配列
624 * @param dam_func ダメージ処理を行う関数の参照ポインタ
625 * @param message オーラダメージを受けた際のメッセージ
628 static void process_aura_damage(monster_type *m_ptr, player_type *touched_ptr, bool immune, int flags_offset, int r_flags_offset, u32b aura_flag,
629 HIT_POINT (*dam_func)(player_type *creature_type, HIT_POINT dam, concptr kb_str, int monspell, bool aura), concptr message)
631 monster_race *r_ptr = &r_info[m_ptr->r_idx];
632 if (!(atoffset(BIT_FLAGS, r_ptr, flags_offset) & aura_flag) || immune)
635 GAME_TEXT mon_name[MAX_NLEN];
636 int aura_damage = damroll(1 + (r_ptr->level / 26), 1 + (r_ptr->level / 17));
638 monster_desc(touched_ptr, mon_name, m_ptr, MD_WRONGDOER_NAME);
640 dam_func(touched_ptr, aura_damage, mon_name, -1, TRUE);
642 if (is_original_ap_and_seen(touched_ptr, m_ptr)) {
643 atoffset(BIT_FLAGS, r_ptr, r_flags_offset) |= aura_flag;
646 handle_stuff(touched_ptr);
650 * @brief 敵オーラによるプレイヤーのダメージ処理
651 * @param m_ptr オーラを持つモンスターの構造体参照ポインタ
652 * @param touched_ptr オーラを持つ相手に振れたクリーチャーの参照ポインタ
655 void touch_zap_player(monster_type *m_ptr, player_type *touched_ptr)
657 process_aura_damage(m_ptr, touched_ptr, (bool)is_immune_fire(touched_ptr), offsetof(monster_race, flags2), offsetof(monster_race, r_flags2),
660 _("突然とても熱くなった!", "You are suddenly very hot!"));
661 process_aura_damage(m_ptr, touched_ptr, (bool)is_immune_cold(touched_ptr), offsetof(monster_race, flags3), offsetof(monster_race, r_flags3),
664 _("突然とても寒くなった!", "You are suddenly very cold!"));
665 process_aura_damage(m_ptr, touched_ptr, (bool)is_immune_elec(touched_ptr), offsetof(monster_race, flags2), offsetof(monster_race, r_flags2),
668 _("電撃をくらった!", "You get zapped!"));