1 #include "monster-floor/monster-death.h"
2 #include "artifact/fixed-art-generator.h"
3 #include "cmd-building/cmd-building.h"
4 #include "core/player-redraw-types.h"
5 #include "core/player-update-types.h"
6 #include "dungeon/dungeon.h"
7 #include "dungeon/quest-completion-checker.h"
8 #include "effect/effect-characteristics.h"
9 #include "effect/effect-processor.h"
10 #include "floor/floor-object.h"
11 #include "game-option/birth-options.h"
12 #include "game-option/play-record-options.h"
13 #include "io/write-diary.h"
14 #include "lore/lore-store.h"
15 #include "main/music-definitions-table.h"
16 #include "main/sound-of-music.h"
17 #include "market/arena-info-table.h"
18 #include "monster-floor/monster-death-util.h"
19 #include "monster-floor/monster-object.h"
20 #include "monster-floor/special-death-switcher.h"
21 #include "monster-race/monster-race-hook.h"
22 #include "monster-race/monster-race.h"
23 #include "monster-race/race-flags1.h"
24 #include "monster-race/race-flags2.h"
25 #include "monster-race/race-flags7.h"
26 #include "monster-race/race-flags9.h"
27 #include "monster-race/race-indice-types.h"
28 #include "monster/monster-describer.h"
29 #include "monster/monster-description-types.h"
30 #include "monster/monster-flag-types.h"
31 #include "monster/monster-info.h"
32 #include "monster/monster-list.h"
33 #include "object-enchant/apply-magic.h"
34 #include "object-enchant/item-apply-magic.h"
35 #include "object/object-kind-hook.h"
36 #include "pet/pet-fall-off.h"
37 #include "player/patron.h"
38 #include "sv-definition/sv-other-types.h"
39 #include "sv-definition/sv-scroll-types.h"
40 #include "system/artifact-type-definition.h"
41 #include "system/building-type-definition.h"
42 #include "system/floor-type-definition.h"
43 #include "system/monster-race-definition.h"
44 #include "system/monster-type-definition.h"
45 #include "system/player-type-definition.h"
46 #include "system/system-variables.h"
47 #include "util/bit-flags-calculator.h"
48 #include "view/display-messages.h"
49 #include "world/world.h"
51 static void write_pet_death(PlayerType *player_ptr, monster_death_type *md_ptr)
53 md_ptr->md_y = md_ptr->m_ptr->fy;
54 md_ptr->md_x = md_ptr->m_ptr->fx;
55 if (record_named_pet && is_pet(md_ptr->m_ptr) && md_ptr->m_ptr->nickname) {
56 GAME_TEXT m_name[MAX_NLEN];
57 monster_desc(player_ptr, m_name, md_ptr->m_ptr, MD_INDEF_VISIBLE);
58 exe_write_diary(player_ptr, DIARY_NAMED_PET, 3, m_name);
62 static void on_dead_explosion(PlayerType *player_ptr, monster_death_type *md_ptr)
64 for (int i = 0; i < 4; i++) {
65 if (md_ptr->r_ptr->blow[i].method != RaceBlowMethodType::EXPLODE) {
69 BIT_FLAGS flg = PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL;
70 AttributeType typ = mbe_info[enum2i(md_ptr->r_ptr->blow[i].effect)].explode_type;
71 DICE_NUMBER d_dice = md_ptr->r_ptr->blow[i].d_dice;
72 DICE_SID d_side = md_ptr->r_ptr->blow[i].d_side;
73 int damage = damroll(d_dice, d_side);
74 (void)project(player_ptr, md_ptr->m_idx, 3, md_ptr->md_y, md_ptr->md_x, damage, typ, flg);
79 static void on_defeat_arena_monster(PlayerType *player_ptr, monster_death_type *md_ptr)
81 auto *floor_ptr = player_ptr->current_floor_ptr;
82 if (!floor_ptr->inside_arena || is_pet(md_ptr->m_ptr)) {
86 player_ptr->exit_bldg = true;
87 if (player_ptr->arena_number > MAX_ARENA_MONS) {
88 msg_print(_("素晴らしい!君こそ真の勝利者だ。", "You are a Genuine Champion!"));
90 msg_print(_("勝利!チャンピオンへの道を進んでいる。", "Victorious! You're on your way to becoming Champion."));
93 if (arena_info[player_ptr->arena_number].tval > ItemKindType::NONE) {
96 q_ptr->prep(lookup_kind(arena_info[player_ptr->arena_number].tval, arena_info[player_ptr->arena_number].sval));
97 apply_magic_to_object(player_ptr, q_ptr, floor_ptr->object_level, AM_NO_FIXED_ART);
98 (void)drop_near(player_ptr, q_ptr, -1, md_ptr->md_y, md_ptr->md_x);
101 if (player_ptr->arena_number > MAX_ARENA_MONS) {
102 player_ptr->arena_number++;
105 player_ptr->arena_number++;
110 GAME_TEXT m_name[MAX_NLEN];
111 monster_desc(player_ptr, m_name, md_ptr->m_ptr, MD_WRONGDOER_NAME);
112 exe_write_diary(player_ptr, DIARY_ARENA, player_ptr->arena_number, m_name);
115 static void drop_corpse(PlayerType *player_ptr, monster_death_type *md_ptr)
117 auto *floor_ptr = player_ptr->current_floor_ptr;
118 bool is_drop_corpse = one_in_(md_ptr->r_ptr->kind_flags.has(MonsterKindType::UNIQUE) ? 1 : 4);
119 is_drop_corpse &= (md_ptr->r_ptr->flags9 & (RF9_DROP_CORPSE | RF9_DROP_SKELETON)) != 0;
120 is_drop_corpse &= !(floor_ptr->inside_arena || player_ptr->phase_out || md_ptr->cloned || ((md_ptr->m_ptr->r_idx == w_ptr->today_mon) && is_pet(md_ptr->m_ptr)));
121 if (!is_drop_corpse) {
126 if (!(md_ptr->r_ptr->flags9 & RF9_DROP_SKELETON)) {
128 } else if ((md_ptr->r_ptr->flags9 & RF9_DROP_CORPSE) && md_ptr->r_ptr->kind_flags.has(MonsterKindType::UNIQUE)) {
130 } else if (md_ptr->r_ptr->flags9 & RF9_DROP_CORPSE) {
131 if ((0 - ((md_ptr->m_ptr->maxhp) / 4)) > md_ptr->m_ptr->hp) {
143 auto *q_ptr = &forge;
144 q_ptr->prep(lookup_kind(ItemKindType::CORPSE, (corpse ? SV_CORPSE : SV_SKELETON)));
145 apply_magic_to_object(player_ptr, q_ptr, floor_ptr->object_level, AM_NO_FIXED_ART);
146 q_ptr->pval = md_ptr->m_ptr->r_idx;
147 (void)drop_near(player_ptr, q_ptr, -1, md_ptr->md_y, md_ptr->md_x);
151 * @brief アーティファクトのドロップ判定処理
152 * @param player_ptr プレイヤーへの参照ポインタ
153 * @param md_ptr モンスター死亡構造体への参照ポインタ
154 * @return 何かドロップするなら1以上、何もドロップしないなら0
156 static ARTIFACT_IDX drop_artifact_index(PlayerType *player_ptr, monster_death_type *md_ptr)
158 ARTIFACT_IDX a_idx = 0;
159 PERCENTAGE chance = 0;
160 for (int i = 0; i < 4; i++) {
161 if (!md_ptr->r_ptr->artifact_id[i]) {
165 a_idx = md_ptr->r_ptr->artifact_id[i];
166 chance = md_ptr->r_ptr->artifact_percent[i];
167 if ((randint0(100) >= chance) && !w_ptr->wizard) {
171 if (drop_single_artifact(player_ptr, md_ptr, a_idx)) {
180 * @brief 特定アーティファクトのドロップ処理
181 * @param player_ptr プレイヤーへの参照ポインタ
182 * @param md_ptr モンスター死亡構造体への参照ポインタ
183 * @param a_ix ドロップを試みるアーティファクトID
184 * @return ドロップするならtrue
186 bool drop_single_artifact(PlayerType *player_ptr, monster_death_type *md_ptr, ARTIFACT_IDX a_idx)
188 auto *a_ptr = &a_info[a_idx];
189 if (a_ptr->cur_num == 1) {
193 if (create_named_art(player_ptr, a_idx, md_ptr->md_y, md_ptr->md_x)) {
196 if (w_ptr->character_dungeon) {
197 a_ptr->floor_id = player_ptr->floor_id;
200 if (!preserve_mode) {
209 static KIND_OBJECT_IDX drop_dungeon_final_artifact(PlayerType *player_ptr, monster_death_type *md_ptr, ARTIFACT_IDX a_idx)
211 auto k_idx = d_info[player_ptr->dungeon_idx].final_object != 0 ? d_info[player_ptr->dungeon_idx].final_object : lookup_kind(ItemKindType::SCROLL, SV_SCROLL_ACQUIREMENT);
212 if (d_info[player_ptr->dungeon_idx].final_artifact == 0) {
216 a_idx = d_info[player_ptr->dungeon_idx].final_artifact;
217 auto *a_ptr = &a_info[a_idx];
218 if (a_ptr->cur_num == 1) {
221 if (create_named_art(player_ptr, a_idx, md_ptr->md_y, md_ptr->md_x)) {
223 if (w_ptr->character_dungeon) {
224 a_ptr->floor_id = player_ptr->floor_id;
226 } else if (!preserve_mode) {
230 return d_info[player_ptr->dungeon_idx].final_object ? k_idx : 0;
233 static void drop_artifact(PlayerType *player_ptr, monster_death_type *md_ptr)
235 if (!md_ptr->drop_chosen_item) {
239 ARTIFACT_IDX a_idx = drop_artifact_index(player_ptr, md_ptr);
240 if (((md_ptr->r_ptr->flags7 & RF7_GUARDIAN) == 0) || (d_info[player_ptr->dungeon_idx].final_guardian != md_ptr->m_ptr->r_idx)) {
244 KIND_OBJECT_IDX k_idx = drop_dungeon_final_artifact(player_ptr, md_ptr, a_idx);
247 auto *q_ptr = &forge;
249 apply_magic_to_object(player_ptr, q_ptr, player_ptr->current_floor_ptr->object_level, AM_NO_FIXED_ART | AM_GOOD);
250 (void)drop_near(player_ptr, q_ptr, -1, md_ptr->md_y, md_ptr->md_x);
253 msg_format(_("あなたは%sを制覇した!", "You have conquered %s!"), d_info[player_ptr->dungeon_idx].name.c_str());
256 static void decide_drop_quality(monster_death_type *md_ptr)
258 md_ptr->mo_mode = 0L;
259 if (md_ptr->r_ptr->flags1 & RF1_DROP_GOOD) {
260 md_ptr->mo_mode |= AM_GOOD;
263 if (md_ptr->r_ptr->flags1 & RF1_DROP_GREAT) {
264 md_ptr->mo_mode |= (AM_GOOD | AM_GREAT);
268 static int decide_drop_numbers(PlayerType *player_ptr, monster_death_type *md_ptr, const bool drop_item)
270 int drop_numbers = 0;
271 if ((md_ptr->r_ptr->flags1 & RF1_DROP_60) && (randint0(100) < 60)) {
275 if ((md_ptr->r_ptr->flags1 & RF1_DROP_90) && (randint0(100) < 90)) {
279 if (md_ptr->r_ptr->flags1 & RF1_DROP_1D2) {
280 drop_numbers += damroll(1, 2);
283 if (md_ptr->r_ptr->flags1 & RF1_DROP_2D2) {
284 drop_numbers += damroll(2, 2);
287 if (md_ptr->r_ptr->flags1 & RF1_DROP_3D2) {
288 drop_numbers += damroll(3, 2);
291 if (md_ptr->r_ptr->flags1 & RF1_DROP_4D2) {
292 drop_numbers += damroll(4, 2);
295 if (md_ptr->cloned && md_ptr->r_ptr->kind_flags.has_not(MonsterKindType::UNIQUE)) {
299 if (is_pet(md_ptr->m_ptr) || player_ptr->phase_out || player_ptr->current_floor_ptr->inside_arena) {
303 if (!drop_item && (md_ptr->r_ptr->d_char != '$')) {
307 if ((md_ptr->r_ptr->flags2 & (RF2_MULTIPLY)) && (md_ptr->r_ptr->r_akills > 1024)) {
314 static void drop_items_golds(PlayerType *player_ptr, monster_death_type *md_ptr, int drop_numbers)
318 for (int i = 0; i < drop_numbers; i++) {
320 auto *q_ptr = &forge;
322 if (md_ptr->do_gold && (!md_ptr->do_item || (randint0(100) < 50))) {
323 if (!make_gold(player_ptr, q_ptr)) {
329 if (!make_object(player_ptr, q_ptr, md_ptr->mo_mode)) {
336 (void)drop_near(player_ptr, q_ptr, -1, md_ptr->md_y, md_ptr->md_x);
339 auto *floor_ptr = player_ptr->current_floor_ptr;
340 floor_ptr->object_level = floor_ptr->base_level;
342 bool visible = (md_ptr->m_ptr->ml && !player_ptr->hallucinated) || (md_ptr->r_ptr->kind_flags.has(MonsterKindType::UNIQUE));
343 if (visible && (dump_item || dump_gold)) {
344 lore_treasure(player_ptr, md_ptr->m_idx, dump_item, dump_gold);
349 * @brief 最終ボス(混沌のサーペント)を倒したときの処理
350 * @param player_ptr プレイヤー情報への参照ポインタ
352 static void on_defeat_last_boss(PlayerType *player_ptr)
354 w_ptr->total_winner = true;
355 add_winner_class(player_ptr->pclass);
356 player_ptr->redraw |= PR_TITLE;
357 play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_FINAL_QUEST_CLEAR);
358 exe_write_diary(player_ptr, DIARY_DESCRIPTION, 0, _("見事に変愚蛮怒の勝利者となった!", "finally became *WINNER* of Hengband!"));
359 patron_list[player_ptr->chaos_patron].admire(player_ptr);
360 msg_print(_("*** おめでとう ***", "*** CONGRATULATIONS ***"));
361 msg_print(_("あなたはゲームをコンプリートしました。", "You have won the game!"));
362 msg_print(_("準備が整ったら引退(自殺コマンド)しても結構です。", "You may retire (commit suicide) when you are ready."));
366 * @brief モンスターが死亡した時の処理 /
367 * Handle the "death" of a monster.
368 * @param m_idx 死亡したモンスターのID
369 * @param drop_item TRUEならばモンスターのドロップ処理を行う
370 * @param type ラストアタックの属性 (単一属性)
372 void monster_death(PlayerType *player_ptr, MONSTER_IDX m_idx, bool drop_item, AttributeType type)
374 AttributeFlags flags;
377 monster_death(player_ptr, m_idx, drop_item, flags);
381 * @brief モンスターが死亡した時の処理 /
382 * Handle the "death" of a monster.
383 * @param m_idx 死亡したモンスターのID
384 * @param drop_item TRUEならばモンスターのドロップ処理を行う
385 * @param attribute_flags ラストアタックの属性 (複数属性)
388 * Disperse treasures centered at the monster location based on the
389 * various flags contained in the monster flags fields.
390 * Check for "Quest" completion when a quest monster is killed.
391 * Note that only the player can induce "monster_death()" on Uniques.
392 * Thus (for now) all Quest monsters should be Uniques.
393 * Note that monsters can now carry objects, and when a monster dies,
394 * it drops all of its objects, which may disappear in crowded rooms.
397 void monster_death(PlayerType *player_ptr, MONSTER_IDX m_idx, bool drop_item, AttributeFlags attribute_flags)
399 monster_death_type tmp_md;
400 monster_death_type *md_ptr = initialize_monster_death_type(player_ptr, &tmp_md, m_idx, drop_item);
401 if (w_ptr->timewalk_m_idx && w_ptr->timewalk_m_idx == m_idx) {
402 w_ptr->timewalk_m_idx = 0;
405 // プレイヤーしかユニークを倒せないのでここで時間を記録
406 if (md_ptr->r_ptr->kind_flags.has(MonsterKindType::UNIQUE) && md_ptr->m_ptr->mflag2.has_not(MonsterConstantFlagType::CLONED)) {
408 md_ptr->r_ptr->defeat_time = w_ptr->play_time;
409 md_ptr->r_ptr->defeat_level = player_ptr->lev;
412 if (md_ptr->r_ptr->flags7 & (RF7_LITE_MASK | RF7_DARK_MASK)) {
413 player_ptr->update |= PU_MON_LITE;
416 write_pet_death(player_ptr, md_ptr);
417 on_dead_explosion(player_ptr, md_ptr);
418 if (md_ptr->m_ptr->mflag2.has(MonsterConstantFlagType::CHAMELEON)) {
419 choose_new_monster(player_ptr, m_idx, true, MON_CHAMELEON);
420 md_ptr->r_ptr = &r_info[md_ptr->m_ptr->r_idx];
423 QuestCompletionChecker(player_ptr, md_ptr->m_ptr).complete();
424 on_defeat_arena_monster(player_ptr, md_ptr);
425 if (m_idx == player_ptr->riding && process_fall_off_horse(player_ptr, -1, false)) {
426 msg_print(_("地面に落とされた。", "You have fallen from the pet you were riding."));
429 drop_corpse(player_ptr, md_ptr);
430 monster_drop_carried_objects(player_ptr, md_ptr->m_ptr);
431 decide_drop_quality(md_ptr);
432 switch_special_death(player_ptr, md_ptr, attribute_flags);
433 drop_artifact(player_ptr, md_ptr);
434 int drop_numbers = decide_drop_numbers(player_ptr, md_ptr, drop_item);
435 coin_type = md_ptr->force_coin;
436 auto *floor_ptr = player_ptr->current_floor_ptr;
437 floor_ptr->object_level = (floor_ptr->dun_level + md_ptr->r_ptr->level) / 2;
438 drop_items_golds(player_ptr, md_ptr, drop_numbers);
439 if (((md_ptr->r_ptr->flags1 & RF1_QUESTOR) == 0) || player_ptr->phase_out || (md_ptr->m_ptr->r_idx != MON_SERPENT) || md_ptr->cloned) {
443 on_defeat_last_boss(player_ptr);
447 * @brief モンスターを撃破した際の述語メッセージを返す /
448 * Return monster death string
449 * @param r_ptr 撃破されたモンスターの種族情報を持つ構造体の参照ポインタ
450 * @return 撃破されたモンスターの述語
452 concptr extract_note_dies(MONRACE_IDX r_idx)
454 auto *r_ptr = &r_info[r_idx];
455 if (monster_living(r_idx)) {
456 return _("は死んだ。", " dies.");
459 for (int i = 0; i < 4; i++) {
460 if (r_ptr->blow[i].method == RaceBlowMethodType::EXPLODE) {
461 return _("は爆発して粉々になった。", " explodes into tiny shreds.");
465 return _("を倒した。", " is destroyed.");