1 #include "monster-floor/monster-death.h"
2 #include "art-definition/art-armor-types.h"
3 #include "art-definition/art-bow-types.h"
4 #include "art-definition/art-protector-types.h"
5 #include "art-definition/art-weapon-types.h"
6 #include "art-definition/random-art-effects.h"
7 #include "artifact/fixed-art-generator.h"
8 #include "core/player-redraw-types.h"
9 #include "core/player-update-types.h"
10 #include "dungeon/dungeon.h"
11 #include "dungeon/quest-completion-checker.h"
12 #include "effect/effect-characteristics.h"
13 #include "effect/effect-processor.h"
14 #include "floor/cave.h"
15 #include "floor/floor-object.h"
16 #include "floor/floor.h"
17 #include "game-option/birth-options.h"
18 #include "game-option/play-record-options.h"
19 #include "grid/grid.h"
20 #include "io/write-diary.h"
21 #include "lore/lore-store.h"
22 #include "main/music-definitions-table.h"
23 #include "main/sound-of-music.h"
24 #include "market/arena-info-table.h"
25 #include "monster-floor/monster-object.h"
26 #include "monster-floor/monster-summon.h"
27 #include "monster-floor/place-monster-types.h"
28 #include "monster-race/monster-race-hook.h"
29 #include "monster-race/monster-race.h"
30 #include "monster-race/race-flags1.h"
31 #include "monster-race/race-flags2.h"
32 #include "monster-race/race-flags7.h"
33 #include "monster-race/race-flags9.h"
34 #include "monster-race/race-indice-types.h"
35 #include "monster/monster-describer.h"
36 #include "monster/monster-description-types.h"
37 #include "monster/monster-flag-types.h"
38 #include "monster/monster-info.h"
39 #include "monster/monster-list.h"
40 #include "monster/smart-learn-types.h"
41 #include "object-enchant/apply-magic.h"
42 #include "object-enchant/item-apply-magic.h"
43 #include "object/object-generator.h"
44 #include "object/object-kind-hook.h"
45 #include "pet/pet-fall-off.h"
46 #include "player/patron.h"
47 #include "spell/spell-types.h"
48 #include "spell/spells-summon.h"
49 #include "sv-definition/sv-other-types.h"
50 #include "sv-definition/sv-protector-types.h"
51 #include "sv-definition/sv-scroll-types.h"
52 #include "sv-definition/sv-weapon-types.h"
53 #include "system/artifact-type-definition.h"
54 #include "system/floor-type-definition.h"
55 #include "system/monster-type-definition.h"
56 #include "system/system-variables.h"
57 #include "view/display-messages.h"
58 #include "world/world.h"
61 * @brief モンスターを倒した際の財宝svalを返す
62 * @param r_idx 倒したモンスターの種族ID
65 * Hack -- Return the "automatic coin type" of a monster race
66 * Used to allocate proper treasure when "Creeping coins" die
67 * Note the use of actual "monster names"
69 static OBJECT_SUBTYPE_VALUE get_coin_type(MONRACE_IDX r_idx)
72 case MON_COPPER_COINS:
74 case MON_SILVER_COINS:
78 case MON_MITHRIL_COINS:
79 case MON_MITHRIL_GOLEM:
81 case MON_ADAMANT_COINS:
89 * @brief モンスターが死亡した時の処理 /
90 * Handle the "death" of a monster.
91 * @param m_idx 死亡したモンスターのID
92 * @param drop_item TRUEならばモンスターのドロップ処理を行う
93 * @return 撃破されたモンスターの述語
96 * Disperse treasures centered at the monster location based on the
97 * various flags contained in the monster flags fields.
98 * Check for "Quest" completion when a quest monster is killed.
99 * Note that only the player can induce "monster_death()" on Uniques.
100 * Thus (for now) all Quest monsters should be Uniques.
101 * Note that monsters can now carry objects, and when a monster dies,
102 * it drops all of its objects, which may disappear in crowded rooms.
105 void monster_death(player_type *player_ptr, MONSTER_IDX m_idx, bool drop_item)
107 floor_type *floor_ptr = player_ptr->current_floor_ptr;
108 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
109 monster_race *r_ptr = &r_info[m_ptr->r_idx];
111 bool do_gold = (!(r_ptr->flags1 & RF1_ONLY_ITEM));
112 bool do_item = (!(r_ptr->flags1 & RF1_ONLY_GOLD));
113 bool cloned = (m_ptr->smart & SM_CLONED) ? TRUE : FALSE;
114 int force_coin = get_coin_type(m_ptr->r_idx);
116 bool drop_chosen_item = drop_item && !cloned && !floor_ptr->inside_arena && !player_ptr->phase_out && !is_pet(m_ptr);
118 if (current_world_ptr->timewalk_m_idx && current_world_ptr->timewalk_m_idx == m_idx) {
119 current_world_ptr->timewalk_m_idx = 0;
122 if (r_ptr->flags7 & (RF7_LITE_MASK | RF7_DARK_MASK)) {
123 player_ptr->update |= (PU_MON_LITE);
126 POSITION y = m_ptr->fy;
127 POSITION x = m_ptr->fx;
129 if (record_named_pet && is_pet(m_ptr) && m_ptr->nickname) {
130 GAME_TEXT m_name[MAX_NLEN];
132 monster_desc(player_ptr, m_name, m_ptr, MD_INDEF_VISIBLE);
133 exe_write_diary(player_ptr, DIARY_NAMED_PET, 3, m_name);
136 for (int i = 0; i < 4; i++) {
137 if (r_ptr->blow[i].method != RBM_EXPLODE)
140 BIT_FLAGS flg = PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL;
141 EFFECT_ID typ = mbe_info[r_ptr->blow[i].effect].explode_type;
142 DICE_NUMBER d_dice = r_ptr->blow[i].d_dice;
143 DICE_SID d_side = r_ptr->blow[i].d_side;
144 HIT_POINT damage = damroll(d_dice, d_side);
146 project(player_ptr, m_idx, 3, y, x, damage, typ, flg, -1);
150 if (m_ptr->mflag2 & MFLAG2_CHAMELEON) {
151 choose_new_monster(player_ptr, m_idx, TRUE, MON_CHAMELEON);
152 r_ptr = &r_info[m_ptr->r_idx];
155 check_quest_completion(player_ptr, m_ptr);
159 if (floor_ptr->inside_arena && !is_pet(m_ptr)) {
160 player_ptr->exit_bldg = TRUE;
161 if (player_ptr->arena_number > MAX_ARENA_MONS) {
162 msg_print(_("素晴らしい!君こそ真の勝利者だ。", "You are a Genuine Champion!"));
164 msg_print(_("勝利!チャンピオンへの道を進んでいる。", "Victorious! You're on your way to becoming Champion."));
167 if (arena_info[player_ptr->arena_number].tval) {
169 object_prep(player_ptr, q_ptr, lookup_kind(arena_info[player_ptr->arena_number].tval, arena_info[player_ptr->arena_number].sval));
170 apply_magic(player_ptr, q_ptr, floor_ptr->object_level, AM_NO_FIXED_ART);
171 (void)drop_near(player_ptr, q_ptr, -1, y, x);
174 if (player_ptr->arena_number > MAX_ARENA_MONS)
175 player_ptr->arena_number++;
176 player_ptr->arena_number++;
178 GAME_TEXT m_name[MAX_NLEN];
179 monster_desc(player_ptr, m_name, m_ptr, MD_WRONGDOER_NAME);
180 exe_write_diary(player_ptr, DIARY_ARENA, player_ptr->arena_number, m_name);
184 if (m_idx == player_ptr->riding && process_fall_off_horse(player_ptr, -1, FALSE)) {
185 msg_print(_("地面に落とされた。", "You have fallen from the pet you were riding."));
188 bool is_drop_corpse = one_in_(r_ptr->flags1 & RF1_UNIQUE ? 1 : 4);
189 is_drop_corpse &= (r_ptr->flags9 & (RF9_DROP_CORPSE | RF9_DROP_SKELETON)) != 0;
190 is_drop_corpse &= !(floor_ptr->inside_arena || player_ptr->phase_out || cloned || ((m_ptr->r_idx == today_mon) && is_pet(m_ptr)));
191 if (is_drop_corpse) {
194 if (!(r_ptr->flags9 & RF9_DROP_SKELETON))
196 else if ((r_ptr->flags9 & RF9_DROP_CORPSE) && (r_ptr->flags1 & RF1_UNIQUE))
198 else if (r_ptr->flags9 & RF9_DROP_CORPSE) {
199 if ((0 - ((m_ptr->maxhp) / 4)) > m_ptr->hp) {
209 object_prep(player_ptr, q_ptr, lookup_kind(TV_CORPSE, (corpse ? SV_CORPSE : SV_SKELETON)));
210 apply_magic(player_ptr, q_ptr, floor_ptr->object_level, AM_NO_FIXED_ART);
211 q_ptr->pval = m_ptr->r_idx;
212 (void)drop_near(player_ptr, q_ptr, -1, y, x);
215 monster_drop_carried_objects(player_ptr, m_ptr);
218 if (r_ptr->flags1 & RF1_DROP_GOOD)
220 if (r_ptr->flags1 & RF1_DROP_GREAT)
223 switch (m_ptr->r_idx) {
224 case MON_PINK_HORROR: {
225 if (floor_ptr->inside_arena || player_ptr->phase_out)
229 for (int i = 0; i < 2; i++) {
230 POSITION wy = y, wx = x;
231 bool pet = is_pet(m_ptr);
235 mode |= PM_FORCE_PET;
238 if (summon_specific(player_ptr, (pet ? -1 : m_idx), wy, wx, 100, SUMMON_BLUE_HORROR, mode)) {
239 if (player_can_see_bold(player_ptr, wy, wx))
245 msg_print(_("ピンク・ホラーは分裂した!", "The Pink horror divides!"));
250 case MON_BLOODLETTER: {
251 if (!drop_chosen_item || (randint1(100) >= 15))
255 object_prep(player_ptr, q_ptr, lookup_kind(TV_SWORD, SV_BLADE_OF_CHAOS));
256 apply_magic(player_ptr, q_ptr, floor_ptr->object_level, AM_NO_FIXED_ART | mo_mode);
257 (void)drop_near(player_ptr, q_ptr, -1, y, x);
261 if (!drop_chosen_item || (floor_ptr->dun_level <= 9))
266 if ((floor_ptr->dun_level > 49) && one_in_(5))
267 get_obj_num_hook = kind_is_good_book;
269 get_obj_num_hook = kind_is_book;
271 make_object(player_ptr, q_ptr, mo_mode);
272 (void)drop_near(player_ptr, q_ptr, -1, y, x);
276 if (floor_ptr->inside_arena || player_ptr->phase_out)
281 POSITION wy = y, wx = x;
283 bool pet = is_pet(m_ptr);
285 scatter(player_ptr, &wy, &wx, y, x, 20, 0);
286 } while (!(in_bounds(floor_ptr, wy, wx) && is_cave_empty_bold2(player_ptr, wy, wx)) && --attempts);
293 mode |= PM_FORCE_PET;
295 if (summon_specific(player_ptr, (pet ? -1 : m_idx), wy, wx, 100, SUMMON_DAWN, mode)) {
296 if (player_can_see_bold(player_ptr, wy, wx))
297 msg_print(_("新たな戦士が現れた!", "A new warrior steps forth!"));
303 BIT_FLAGS flg = PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL;
304 (void)project(player_ptr, m_idx, 6, y, x, 100, GF_CHAOS, flg, -1);
307 case MON_UNICORN_ORD:
310 if (player_ptr->pseikaku != PERSONALITY_LAZY)
312 if (!drop_chosen_item)
315 ARTIFACT_IDX a_idx = 0;
316 artifact_type *a_ptr = NULL;
318 switch (randint0(3)) {
320 a_idx = ART_NAMAKE_HAMMER;
323 a_idx = ART_NAMAKE_BOW;
326 a_idx = ART_NAMAKE_ARMOR;
330 a_ptr = &a_info[a_idx];
331 } while (a_ptr->cur_num);
333 if (create_named_art(player_ptr, a_idx, y, x)) {
335 if (current_world_ptr->character_dungeon)
336 a_ptr->floor_id = player_ptr->floor_id;
337 } else if (!preserve_mode)
343 if (!drop_chosen_item)
347 object_prep(player_ptr, q_ptr, lookup_kind(TV_HAFTED, SV_GROND));
348 q_ptr->name1 = ART_GROND;
349 apply_magic(player_ptr, q_ptr, -1, AM_GOOD | AM_GREAT);
350 (void)drop_near(player_ptr, q_ptr, -1, y, x);
352 object_prep(player_ptr, q_ptr, lookup_kind(TV_CROWN, SV_CHAOS));
353 q_ptr->name1 = ART_CHAOS;
354 apply_magic(player_ptr, q_ptr, -1, AM_GOOD | AM_GREAT);
355 (void)drop_near(player_ptr, q_ptr, -1, y, x);
358 case MON_B_DEATH_SWORD: {
359 if (!drop_chosen_item)
363 object_prep(player_ptr, q_ptr, lookup_kind(TV_SWORD, randint1(2)));
364 (void)drop_near(player_ptr, q_ptr, -1, y, x);
369 bool is_drop_can = drop_chosen_item;
370 bool is_silver = m_ptr->r_idx == MON_A_SILVER;
371 is_silver &= r_ptr->r_akills % 5 == 0;
372 is_drop_can &= (m_ptr->r_idx == MON_A_GOLD) || is_silver;
377 object_prep(player_ptr, q_ptr, lookup_kind(TV_CHEST, SV_CHEST_KANDUME));
378 apply_magic(player_ptr, q_ptr, floor_ptr->object_level, AM_NO_FIXED_ART);
379 (void)drop_near(player_ptr, q_ptr, -1, y, x);
383 BIT_FLAGS flg = PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL;
384 (void)project(player_ptr, m_idx, 3, y, x, damroll(20, 10), GF_FIRE, flg, -1);
387 case MON_MIDDLE_AQUA_FIRST:
388 case MON_LARGE_AQUA_FIRST:
389 case MON_EXTRA_LARGE_AQUA_FIRST:
390 case MON_MIDDLE_AQUA_SECOND:
391 case MON_LARGE_AQUA_SECOND:
392 case MON_EXTRA_LARGE_AQUA_SECOND: {
393 if (floor_ptr->inside_arena || player_ptr->phase_out)
397 const int popped_bubbles = 4;
398 for (int i = 0; i < popped_bubbles; i++) {
399 POSITION wy = y, wx = x;
400 bool pet = is_pet(m_ptr);
401 BIT_FLAGS mode = PM_NONE;
404 mode |= PM_FORCE_PET;
406 MONSTER_IDX smaller_bubblle = m_ptr->r_idx - 1;
407 if (summon_named_creature(player_ptr, (pet ? -1 : m_idx), wy, wx, smaller_bubblle, mode) && player_can_see_bold(player_ptr, wy, wx))
412 msg_print(_("泡が弾けた!", "The bubble pops!"));
416 case MON_TOTEM_MOAI: {
417 if (floor_ptr->inside_arena || player_ptr->phase_out || one_in_(8))
420 POSITION wy = y, wx = x;
422 bool pet = is_pet(m_ptr);
424 scatter(player_ptr, &wy, &wx, y, x, 20, 0);
425 } while (!(in_bounds(floor_ptr, wy, wx) && is_cave_empty_bold2(player_ptr, wy, wx)) && --attempts);
430 BIT_FLAGS mode = PM_NONE;
432 mode |= PM_FORCE_PET;
434 if (summon_named_creature(player_ptr, (pet ? -1 : m_idx), wy, wx, MON_TOTEM_MOAI, mode) && player_can_see_bold(player_ptr, wy, wx))
435 msg_print(_("新たなモアイが現れた!", "A new moai steps forth!"));
440 if (!drop_chosen_item)
443 switch (r_ptr->d_char) {
445 if (floor_ptr->dun_level <= 0)
450 get_obj_num_hook = kind_is_cloak;
451 make_object(player_ptr, q_ptr, mo_mode);
452 (void)drop_near(player_ptr, q_ptr, -1, y, x);
456 if (floor_ptr->dun_level <= 4)
461 get_obj_num_hook = kind_is_polearm;
462 make_object(player_ptr, q_ptr, mo_mode);
463 (void)drop_near(player_ptr, q_ptr, -1, y, x);
467 if (floor_ptr->dun_level <= 19)
472 get_obj_num_hook = kind_is_armor;
473 make_object(player_ptr, q_ptr, mo_mode);
474 (void)drop_near(player_ptr, q_ptr, -1, y, x);
478 if (floor_ptr->dun_level <= 4)
482 get_obj_num_hook = kind_is_hafted;
483 make_object(player_ptr, q_ptr, mo_mode);
484 (void)drop_near(player_ptr, q_ptr, -1, y, x);
488 if (m_ptr->r_idx == MON_STORMBRINGER)
493 get_obj_num_hook = kind_is_sword;
494 make_object(player_ptr, q_ptr, mo_mode);
495 (void)drop_near(player_ptr, q_ptr, -1, y, x);
502 if (drop_chosen_item) {
503 ARTIFACT_IDX a_idx = 0;
504 PERCENTAGE chance = 0;
505 for (int i = 0; i < 4; i++) {
506 if (!r_ptr->artifact_id[i])
508 a_idx = r_ptr->artifact_id[i];
509 chance = r_ptr->artifact_percent[i];
510 if (randint0(100) < chance || current_world_ptr->wizard) {
511 artifact_type *a_ptr = &a_info[a_idx];
512 if (!a_ptr->cur_num) {
513 if (create_named_art(player_ptr, a_idx, y, x)) {
515 if (current_world_ptr->character_dungeon)
516 a_ptr->floor_id = player_ptr->floor_id;
517 } else if (!preserve_mode) {
524 if ((r_ptr->flags7 & RF7_GUARDIAN) && (d_info[player_ptr->dungeon_idx].final_guardian == m_ptr->r_idx)) {
525 KIND_OBJECT_IDX k_idx = d_info[player_ptr->dungeon_idx].final_object != 0 ? d_info[player_ptr->dungeon_idx].final_object
526 : lookup_kind(TV_SCROLL, SV_SCROLL_ACQUIREMENT);
528 if (d_info[player_ptr->dungeon_idx].final_artifact != 0) {
529 a_idx = d_info[player_ptr->dungeon_idx].final_artifact;
530 artifact_type *a_ptr = &a_info[a_idx];
531 if (!a_ptr->cur_num) {
532 if (create_named_art(player_ptr, a_idx, y, x)) {
534 if (current_world_ptr->character_dungeon)
535 a_ptr->floor_id = player_ptr->floor_id;
536 } else if (!preserve_mode) {
540 if (!d_info[player_ptr->dungeon_idx].final_object)
547 object_prep(player_ptr, q_ptr, k_idx);
548 apply_magic(player_ptr, q_ptr, floor_ptr->object_level, AM_NO_FIXED_ART | AM_GOOD);
549 (void)drop_near(player_ptr, q_ptr, -1, y, x);
552 msg_format(_("あなたは%sを制覇した!", "You have conquered %s!"), d_name + d_info[player_ptr->dungeon_idx].name);
557 if ((r_ptr->flags1 & RF1_DROP_60) && (randint0(100) < 60))
559 if ((r_ptr->flags1 & RF1_DROP_90) && (randint0(100) < 90))
561 if (r_ptr->flags1 & RF1_DROP_1D2)
562 number += damroll(1, 2);
563 if (r_ptr->flags1 & RF1_DROP_2D2)
564 number += damroll(2, 2);
565 if (r_ptr->flags1 & RF1_DROP_3D2)
566 number += damroll(3, 2);
567 if (r_ptr->flags1 & RF1_DROP_4D2)
568 number += damroll(4, 2);
570 if (cloned && !(r_ptr->flags1 & RF1_UNIQUE))
573 if (is_pet(m_ptr) || player_ptr->phase_out || floor_ptr->inside_arena)
576 if (!drop_item && (r_ptr->d_char != '$'))
579 if ((r_ptr->flags2 & (RF2_MULTIPLY)) && (r_ptr->r_akills > 1024))
582 coin_type = force_coin;
583 floor_ptr->object_level = (floor_ptr->dun_level + r_ptr->level) / 2;
587 for (int i = 0; i < number; i++) {
591 if (do_gold && (!do_item || (randint0(100) < 50))) {
592 if (!make_gold(player_ptr, q_ptr))
596 if (!make_object(player_ptr, q_ptr, mo_mode))
601 (void)drop_near(player_ptr, q_ptr, -1, y, x);
604 floor_ptr->object_level = floor_ptr->base_level;
606 bool visible = (m_ptr->ml && !player_ptr->image) || ((r_ptr->flags1 & RF1_UNIQUE) != 0);
607 if (visible && (dump_item || dump_gold)) {
608 lore_treasure(player_ptr, m_idx, dump_item, dump_gold);
611 if (!(r_ptr->flags1 & RF1_QUESTOR))
613 if (player_ptr->phase_out)
615 if ((m_ptr->r_idx != MON_SERPENT) || cloned)
618 current_world_ptr->total_winner = TRUE;
619 player_ptr->redraw |= (PR_TITLE);
620 play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_FINAL_QUEST_CLEAR);
621 exe_write_diary(player_ptr, DIARY_DESCRIPTION, 0, _("見事に変愚蛮怒の勝利者となった!", "finally became *WINNER* of Hengband!"));
622 admire_from_patron(player_ptr);
623 msg_print(_("*** おめでとう ***", "*** CONGRATULATIONS ***"));
624 msg_print(_("あなたはゲームをコンプリートしました。", "You have won the game!"));
625 msg_print(_("準備が整ったら引退(自殺コマンド)しても結構です。", "You may retire (commit suicide) when you are ready."));
629 * @brief モンスターを撃破した際の述語メッセージを返す /
630 * Return monster death string
631 * @param r_ptr 撃破されたモンスターの種族情報を持つ構造体の参照ポインタ
632 * @return 撃破されたモンスターの述語
634 concptr extract_note_dies(MONRACE_IDX r_idx)
636 monster_race *r_ptr = &r_info[r_idx];
637 if (monster_living(r_idx))
638 return _("は死んだ。", " dies.");
640 for (int i = 0; i < 4; i++) {
641 if (r_ptr->blow[i].method == RBM_EXPLODE) {
642 return _("は爆発して粉々になった。", " explodes into tiny shreds.");
646 return _("を倒した。", " is destroyed.");