8 #include "io/write-diary.h"
9 #include "cmd/cmd-dump.h"
10 #include "realm-song.h"
13 #include "object-flavor.h"
14 #include "object-hook.h"
15 #include "object-broken.h"
16 #include "player-move.h"
17 #include "player-damage.h"
18 #include "player-personality.h"
19 #include "player-status.h"
20 #include "player-effects.h"
21 #include "player-class.h"
22 #include "player-race.h"
23 #include "monster-spell.h"
25 #include "view-mainwindow.h"
34 * todo 元々「破損したアイテムの数」をreturnしていました
35 * しかし調査の結果、どの関数も戻り値を使用していませんでした
36 * よって戻りをvoidとし、破損したアイテム数を計上しているローカル変数を削除しました
37 * 確認後、問題がなければ本コメントを削除の上コミット願います
38 * そして英語のコメントにある「stealing」とは一体…詳細不明につき残しました
39 * なお「toryを省略する必要はないじゃろ」との独断により関数名を変更しました
40 * 気に入らなければ元に戻して下さい。。。 by Hourier
42 * @brief アイテムを指定確率で破損させる /
43 * Destroys a type of item on a given percent chance
44 * @param player_ptr プレーヤーへの参照ポインタ
45 * @param typ 破損判定関数ポインタ
49 * Note that missiles are no longer necessarily all destroyed
50 * Destruction taken from "melee.c" code for "stealing".
51 * New-style wands and rods handled correctly. -LM-
53 void inventory_damage(player_type *player_ptr, inven_func typ, int perc)
58 GAME_TEXT o_name[MAX_NLEN];
60 if (CHECK_MULTISHADOW(player_ptr) || player_ptr->current_floor_ptr->inside_arena) return;
62 /* Scan through the slots backwards */
63 for (i = 0; i < INVEN_PACK; i++)
65 o_ptr = &player_ptr->inventory_list[i];
66 if (!o_ptr->k_idx) continue;
68 /* Hack -- for now, skip artifacts */
69 if (object_is_artifact(o_ptr)) continue;
71 /* Give this item slot a shot at death */
72 if (!(*typ)(o_ptr)) continue;
74 /* Count the casualties */
75 for (amt = j = 0; j < o_ptr->number; ++j)
77 if (randint0(100) < perc) amt++;
80 /* Some casualities */
83 object_desc(player_ptr, o_name, o_ptr, OD_OMIT_PREFIX);
85 msg_format(_("%s(%c)が%s壊れてしまった!", "%sour %s (%c) %s destroyed!"),
87 o_name, index_to_label(i), ((o_ptr->number > 1) ?
88 ((amt == o_ptr->number) ? "全部" : (amt > 1 ? "何個か" : "一個")) : ""));
90 ((o_ptr->number > 1) ? ((amt == o_ptr->number) ? "All of y" :
91 (amt > 1 ? "Some of y" : "One of y")) : "Y"), o_name, index_to_label(i), ((amt > 1) ? "were" : "was"));
95 if (IS_ECHIZEN(player_ptr))
96 msg_print("やりやがったな!");
97 else if ((player_ptr->pseikaku == SEIKAKU_CHARGEMAN))
99 if (randint0(2) == 0) msg_print(_("ジュラル星人め!", ""));
100 else msg_print(_("弱い者いじめは止めるんだ!", ""));
104 /* Potions smash open */
105 if (object_is_potion(o_ptr))
107 (void)potion_smash_effect(player_ptr, 0, player_ptr->y, player_ptr->x, o_ptr->k_idx);
110 /* Reduce the charges of rods/wands */
111 reduce_charges(o_ptr, amt);
113 /* Destroy "amt" items */
114 inven_item_increase(player_ptr, i, -amt);
115 inven_item_optimize(player_ptr, i);
121 * @brief 酸攻撃による装備のAC劣化処理 /
122 * Acid has hit the player, attempt to affect some armor.
123 * @param 酸を浴びたキャラクタへの参照ポインタ
124 * @return 装備による軽減があったならTRUEを返す
126 * Note that the "base armor" of an object never changes.
127 * If any armor is damaged (or resists), the player takes less damage.
129 static bool acid_minus_ac(player_type *creature_ptr)
131 object_type *o_ptr = NULL;
132 BIT_FLAGS flgs[TR_FLAG_SIZE];
133 GAME_TEXT o_name[MAX_NLEN];
135 /* Pick a (possibly empty) creature_ptr->inventory_list slot */
138 case 1: o_ptr = &creature_ptr->inventory_list[INVEN_RARM]; break;
139 case 2: o_ptr = &creature_ptr->inventory_list[INVEN_LARM]; break;
140 case 3: o_ptr = &creature_ptr->inventory_list[INVEN_BODY]; break;
141 case 4: o_ptr = &creature_ptr->inventory_list[INVEN_OUTER]; break;
142 case 5: o_ptr = &creature_ptr->inventory_list[INVEN_HANDS]; break;
143 case 6: o_ptr = &creature_ptr->inventory_list[INVEN_HEAD]; break;
144 case 7: o_ptr = &creature_ptr->inventory_list[INVEN_FEET]; break;
147 if (!o_ptr->k_idx) return FALSE;
148 if (!object_is_armour(o_ptr)) return FALSE;
150 object_desc(creature_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
151 object_flags(o_ptr, flgs);
152 /* No damage left to be done */
153 if (o_ptr->ac + o_ptr->to_a <= 0)
155 msg_format(_("%sは既にボロボロだ!", "Your %s is already fully corroded!"), o_name);
160 if (have_flag(flgs, TR_IGNORE_ACID))
162 msg_format(_("しかし%sには効果がなかった!", "Your %s is unaffected!"), o_name);
166 msg_format(_("%sが酸で腐食した!", "Your %s is corroded!"), o_name);
168 /* Damage the item */
171 /* Calculate bonuses */
172 creature_ptr->update |= (PU_BONUS);
173 creature_ptr->window |= (PW_EQUIP | PW_PLAYER);
175 calc_android_exp(creature_ptr);
177 /* Item was damaged */
183 * @brief 酸属性によるプレイヤー損害処理 /
184 * Hurt the player with Acid
185 * @param creature_ptr 酸を浴びたキャラクタへの参照ポインタ
187 * @param kb_str ダメージ原因記述
188 * @param monspell 原因となったモンスター特殊攻撃ID
189 * @param aura オーラよるダメージが原因ならばTRUE
192 HIT_POINT acid_dam(player_type *creature_ptr, HIT_POINT dam, concptr kb_str, int monspell, bool aura)
194 HIT_POINT get_damage;
195 int inv = (dam < 30) ? 1 : (dam < 60) ? 2 : 3;
196 bool double_resist = is_oppose_acid(creature_ptr);
199 if (creature_ptr->immune_acid || (dam <= 0))
201 learn_spell(creature_ptr, monspell);
205 /* Vulnerability (Ouch!) */
206 if (creature_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
207 if (creature_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
209 /* Resist the damage */
210 if (creature_ptr->resist_acid) dam = (dam + 2) / 3;
211 if (double_resist) dam = (dam + 2) / 3;
213 if (aura || !CHECK_MULTISHADOW(creature_ptr))
215 if ((!(double_resist || creature_ptr->resist_acid)) &&
216 one_in_(HURT_CHANCE))
217 (void)do_dec_stat(creature_ptr, A_CHR);
219 /* If any armor gets hit, defend the player */
220 if (acid_minus_ac(creature_ptr)) dam = (dam + 1) / 2;
223 get_damage = take_hit(creature_ptr, aura ? DAMAGE_NOESCAPE : DAMAGE_ATTACK, dam, kb_str, monspell);
225 /* Inventory damage */
226 if (!aura && !(double_resist && creature_ptr->resist_acid))
227 inventory_damage(creature_ptr, set_acid_destroy, inv);
233 * @brief 電撃属性によるプレイヤー損害処理 /
234 * Hurt the player with electricity
235 * @param creature_ptr 電撃を浴びたキャラクタへの参照ポインタ
237 * @param kb_str ダメージ原因記述
238 * @param monspell 原因となったモンスター特殊攻撃ID
239 * @param aura オーラよるダメージが原因ならばTRUE
242 HIT_POINT elec_dam(player_type *creature_ptr, HIT_POINT dam, concptr kb_str, int monspell, bool aura)
244 HIT_POINT get_damage;
245 int inv = (dam < 30) ? 1 : (dam < 60) ? 2 : 3;
246 bool double_resist = is_oppose_elec(creature_ptr);
249 if (creature_ptr->immune_elec || (dam <= 0))
251 learn_spell(creature_ptr, monspell);
255 /* Vulnerability (Ouch!) */
256 if (creature_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
257 if (creature_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
258 if (PRACE_IS_(creature_ptr, RACE_ANDROID)) dam += dam / 3;
260 /* Resist the damage */
261 if (creature_ptr->resist_elec) dam = (dam + 2) / 3;
262 if (double_resist) dam = (dam + 2) / 3;
264 if (aura || !CHECK_MULTISHADOW(creature_ptr))
266 if ((!(double_resist || creature_ptr->resist_elec)) &&
267 one_in_(HURT_CHANCE))
268 (void)do_dec_stat(creature_ptr, A_DEX);
271 get_damage = take_hit(creature_ptr, aura ? DAMAGE_NOESCAPE : DAMAGE_ATTACK, dam, kb_str, monspell);
273 /* Inventory damage */
274 if (!aura && !(double_resist && creature_ptr->resist_elec))
275 inventory_damage(creature_ptr, set_elec_destroy, inv);
282 * @brief 火炎属性によるプレイヤー損害処理 /
283 * Hurt the player with Fire
284 * @param creature_ptr 火炎を浴びたキャラクタへの参照ポインタ
286 * @param kb_str ダメージ原因記述
287 * @param monspell 原因となったモンスター特殊攻撃ID
288 * @param aura オーラよるダメージが原因ならばTRUE
291 HIT_POINT fire_dam(player_type *creature_ptr, HIT_POINT dam, concptr kb_str, int monspell, bool aura)
293 HIT_POINT get_damage;
294 int inv = (dam < 30) ? 1 : (dam < 60) ? 2 : 3;
295 bool double_resist = is_oppose_fire(creature_ptr);
298 if (creature_ptr->immune_fire || (dam <= 0))
300 learn_spell(creature_ptr, monspell);
304 /* Vulnerability (Ouch!) */
305 if (creature_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
306 if (PRACE_IS_(creature_ptr, RACE_ENT)) dam += dam / 3;
307 if (creature_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
309 /* Resist the damage */
310 if (creature_ptr->resist_fire) dam = (dam + 2) / 3;
311 if (double_resist) dam = (dam + 2) / 3;
313 if (aura || !CHECK_MULTISHADOW(creature_ptr))
315 if ((!(double_resist || creature_ptr->resist_fire)) &&
316 one_in_(HURT_CHANCE))
317 (void)do_dec_stat(creature_ptr, A_STR);
320 get_damage = take_hit(creature_ptr, aura ? DAMAGE_NOESCAPE : DAMAGE_ATTACK, dam, kb_str, monspell);
322 /* Inventory damage */
323 if (!aura && !(double_resist && creature_ptr->resist_fire))
324 inventory_damage(creature_ptr, set_fire_destroy, inv);
331 * @brief 冷気属性によるプレイヤー損害処理 /
332 * Hurt the player with Cold
333 * @param creature_ptr 冷気を浴びたキャラクタへの参照ポインタ
335 * @param kb_str ダメージ原因記述
336 * @param monspell 原因となったモンスター特殊攻撃ID
337 * @param aura オーラよるダメージが原因ならばTRUE
340 HIT_POINT cold_dam(player_type *creature_ptr, HIT_POINT dam, concptr kb_str, int monspell, bool aura)
342 HIT_POINT get_damage;
343 int inv = (dam < 30) ? 1 : (dam < 60) ? 2 : 3;
344 bool double_resist = is_oppose_cold(creature_ptr);
347 if (creature_ptr->immune_cold || (dam <= 0))
349 learn_spell(creature_ptr, monspell);
353 /* Vulnerability (Ouch!) */
354 if (creature_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
355 if (creature_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
357 /* Resist the damage */
358 if (creature_ptr->resist_cold) dam = (dam + 2) / 3;
359 if (double_resist) dam = (dam + 2) / 3;
361 if (aura || !CHECK_MULTISHADOW(creature_ptr))
363 if ((!(double_resist || creature_ptr->resist_cold)) &&
364 one_in_(HURT_CHANCE))
365 (void)do_dec_stat(creature_ptr, A_STR);
368 get_damage = take_hit(creature_ptr, aura ? DAMAGE_NOESCAPE : DAMAGE_ATTACK, dam, kb_str, monspell);
370 /* Inventory damage */
371 if (!aura && !(double_resist && creature_ptr->resist_cold))
372 inventory_damage(creature_ptr, set_cold_destroy, inv);
379 * Decreases players hit points and sets death flag if necessary
381 * Invulnerability needs to be changed into a "shield"
383 * Hack -- this function allows the user to save (or quit)
384 * the game when he dies, since the "You die." message is shown before
385 * setting the player to "dead".
388 int take_hit(player_type *creature_ptr, int damage_type, HIT_POINT damage, concptr hit_from, int monspell)
390 int old_chp = creature_ptr->chp;
392 char death_message[1024];
395 int warning = (creature_ptr->mhp * hitpoint_warn / 10);
396 if (creature_ptr->is_dead) return 0;
398 if (creature_ptr->sutemi) damage *= 2;
399 if (creature_ptr->special_defense & KATA_IAI) damage += (damage + 4) / 5;
401 if (easy_band) damage = (damage + 1) / 2;
403 if (damage_type != DAMAGE_USELIFE)
405 disturb(creature_ptr, TRUE, TRUE);
408 creature_ptr->now_damaged = TRUE;
412 if (monspell >= 0) learn_spell(creature_ptr, monspell);
414 /* Mega-Hack -- Apply "invulnerability" */
415 if ((damage_type != DAMAGE_USELIFE) && (damage_type != DAMAGE_LOSELIFE))
417 if (IS_INVULN(creature_ptr) && (damage < 9000))
419 if (damage_type == DAMAGE_FORCE)
421 msg_print(_("バリアが切り裂かれた!", "The attack cuts your shield of invulnerability open!"));
423 else if (one_in_(PENETRATE_INVULNERABILITY))
425 msg_print(_("無敵のバリアを破って攻撃された!", "The attack penetrates your shield of invulnerability!"));
433 if (CHECK_MULTISHADOW(creature_ptr))
435 if (damage_type == DAMAGE_FORCE)
437 msg_print(_("幻影もろとも体が切り裂かれた!", "The attack hits Shadow together with you!"));
439 else if (damage_type == DAMAGE_ATTACK)
441 msg_print(_("攻撃は幻影に命中し、あなたには届かなかった。", "The attack hits Shadow, but you are unharmed!"));
446 if (creature_ptr->wraith_form)
448 if (damage_type == DAMAGE_FORCE)
450 msg_print(_("半物質の体が切り裂かれた!", "The attack cuts through your ethereal body!"));
455 if ((damage == 0) && one_in_(2)) damage = 1;
459 if (creature_ptr->special_defense & KATA_MUSOU)
462 if ((damage == 0) && one_in_(2)) damage = 1;
464 } /* not if LOSELIFE USELIFE */
466 /* Hurt the player */
467 creature_ptr->chp -= damage;
468 if (damage_type == DAMAGE_GENO && creature_ptr->chp < 0)
470 damage += creature_ptr->chp;
471 creature_ptr->chp = 0;
474 /* Display the hitpoints */
475 creature_ptr->redraw |= (PR_HP);
477 creature_ptr->window |= (PW_PLAYER);
479 if (damage_type != DAMAGE_GENO && creature_ptr->chp == 0)
481 chg_virtue(creature_ptr, V_SACRIFICE, 1);
482 chg_virtue(creature_ptr, V_CHANCE, 2);
486 if (creature_ptr->chp < 0)
488 bool android = (creature_ptr->prace == RACE_ANDROID ? TRUE : FALSE);
491 /* 死んだ時に強制終了して死を回避できなくしてみた by Habu */
493 if (!save_player(creature_ptr)) msg_print("セーブ失敗!");
498 chg_virtue(creature_ptr, V_SACRIFICE, 10);
500 handle_stuff(creature_ptr);
501 creature_ptr->leaving = TRUE;
504 creature_ptr->is_dead = TRUE;
506 if (creature_ptr->current_floor_ptr->inside_arena)
508 concptr m_name = r_name + r_info[arena_info[creature_ptr->arena_number].r_idx].name;
509 msg_format(_("あなたは%sの前に敗れ去った。", "You are beaten by %s."), m_name);
511 if (record_arena) exe_write_diary(creature_ptr, DIARY_ARENA, -1 - creature_ptr->arena_number, m_name);
515 QUEST_IDX q_idx = quest_number(creature_ptr, creature_ptr->current_floor_ptr->dun_level);
516 bool seppuku = streq(hit_from, "Seppuku");
517 bool winning_seppuku = current_world_ptr->total_winner && seppuku;
519 play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_GAMEOVER);
522 /* Make screen dump */
523 screen_dump = make_screen_dump(creature_ptr);
526 /* Note cause of death */
529 strcpy(creature_ptr->died_from, hit_from);
531 if (!winning_seppuku) strcpy(creature_ptr->died_from, "切腹");
538 sprintf(dummy, "%s%s%s", !creature_ptr->paralyzed ? "" : creature_ptr->free_act ? "彫像状態で" : "麻痺状態で", creature_ptr->image ? "幻覚に歪んだ" : "", hit_from);
540 sprintf(dummy, "%s%s", hit_from, !creature_ptr->paralyzed ? "" : " while helpless");
542 my_strcpy(creature_ptr->died_from, dummy, sizeof creature_ptr->died_from);
545 /* No longer a winner */
546 current_world_ptr->total_winner = FALSE;
550 exe_write_diary(creature_ptr, DIARY_DESCRIPTION, 0, _("勝利の後切腹した。", "committed seppuku after the winning."));
556 if (creature_ptr->current_floor_ptr->inside_arena)
557 strcpy(buf, _("アリーナ", "in the Arena"));
558 else if (!creature_ptr->current_floor_ptr->dun_level)
559 strcpy(buf, _("地上", "on the surface"));
560 else if (q_idx && (is_fixed_quest_idx(q_idx) &&
561 !((q_idx == QUEST_OBERON) || (q_idx == QUEST_SERPENT))))
562 strcpy(buf, _("クエスト", "in a quest"));
564 sprintf(buf, _("%d階", "level %d"), (int)creature_ptr->current_floor_ptr->dun_level);
566 sprintf(tmp, _("%sで%sに殺された。", "killed by %s %s."), buf, creature_ptr->died_from);
567 exe_write_diary(creature_ptr, DIARY_DESCRIPTION, 0, tmp);
570 exe_write_diary(creature_ptr, DIARY_GAMESTART, 1, _("-------- ゲームオーバー --------", "-------- Game Over --------"));
571 exe_write_diary(creature_ptr, DIARY_DESCRIPTION, 1, "\n\n\n\n");
575 if (get_check_strict(_("画面を保存しますか?", "Dump the screen? "), CHECK_NO_HISTORY))
577 do_cmd_save_screen(creature_ptr);
582 /* Initialize "last message" buffer */
583 if (creature_ptr->last_message) string_free(creature_ptr->last_message);
584 creature_ptr->last_message = NULL;
586 /* Hack -- Note death */
590 msg_format("あなたは%sました。", android ? "壊れ" : "死に");
592 msg_print(android ? "You are broken." : "You die.");
601 get_rnd_line(_("seppuku_j.txt", "seppuku.txt"), 0, death_message);
605 get_rnd_line(_("death_j.txt", "death.txt"), 0, death_message);
611 while (!get_string(winning_seppuku ? "辞世の句: " : "断末魔の叫び: ", death_message, 1024));
613 while (!get_string("Last word: ", death_message, 1024));
615 } while (winning_seppuku && !get_check_strict(_("よろしいですか?", "Are you sure? "), CHECK_NO_HISTORY));
617 if (death_message[0] == '\0')
620 strcpy(death_message, format("あなたは%sました。", android ? "壊れ" : "死に"));
622 strcpy(death_message, android ? "You are broken." : "You die.");
625 else creature_ptr->last_message = string_make(death_message);
633 int msg_pos_x[9] = { 5, 7, 9, 12, 14, 17, 19, 21, 23 };
634 int msg_pos_y[9] = { 3, 4, 5, 4, 5, 4, 5, 6, 4 };
641 for (i = 0; i < 40; i++)
642 Term_putstr(randint0(w / 2) * 2, randint0(h), 2, TERM_VIOLET, "υ");
645 if (strncmp(str, "「", 2) == 0) str += 2;
647 str2 = my_strstr(str, "」");
648 if (str2 != NULL) *str2 = '\0';
653 str2 = my_strstr(str, " ");
654 if (str2 == NULL) len = strlen(str);
655 else len = str2 - str;
659 Term_putstr_v(w * 3 / 4 - 2 - msg_pos_x[i] * 2, msg_pos_y[i], len,
661 if (str2 == NULL) break;
665 if (*str == 0) break;
669 Term_putstr(w - 1, h - 1, 1, TERM_WHITE, " ");
673 /* Make screen dump */
674 screen_dump = make_screen_dump(creature_ptr);
677 /* Wait a key press */
682 msg_print(death_message);
690 handle_stuff(creature_ptr);
692 /* Hitpoint warning */
693 if (creature_ptr->chp < warning)
695 /* Hack -- bell on first notice */
696 if (old_chp > warning) bell();
700 if (record_danger && (old_chp > warning))
702 if (creature_ptr->image && damage_type == DAMAGE_ATTACK)
703 hit_from = _("何か", "something");
705 sprintf(tmp, _("%sによってピンチに陥った。", "was in a critical situation because of %s."), hit_from);
706 exe_write_diary(creature_ptr, DIARY_DESCRIPTION, 0, tmp);
711 /* stop auto_more even if DAMAGE_USELIFE */
712 creature_ptr->now_damaged = TRUE;
715 msg_print(_("*** 警告:低ヒット・ポイント! ***", "*** LOW HITPOINT WARNING! ***"));
719 if (creature_ptr->wild_mode && !creature_ptr->leaving && (creature_ptr->chp < MAX(warning, creature_ptr->mhp / 5)))
721 change_wild_mode(creature_ptr, FALSE);