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)
68 BIT_FLAGS flg = PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL;
69 AttributeType typ = mbe_info[enum2i(md_ptr->r_ptr->blow[i].effect)].explode_type;
70 DICE_NUMBER d_dice = md_ptr->r_ptr->blow[i].d_dice;
71 DICE_SID d_side = md_ptr->r_ptr->blow[i].d_side;
72 HIT_POINT damage = damroll(d_dice, d_side);
73 (void)project(player_ptr, md_ptr->m_idx, 3, md_ptr->md_y, md_ptr->md_x, damage, typ, flg);
78 static void on_defeat_arena_monster(PlayerType *player_ptr, monster_death_type *md_ptr)
80 auto *floor_ptr = player_ptr->current_floor_ptr;
81 if (!floor_ptr->inside_arena || is_pet(md_ptr->m_ptr))
84 player_ptr->exit_bldg = true;
85 if (player_ptr->arena_number > MAX_ARENA_MONS)
86 msg_print(_("素晴らしい!君こそ真の勝利者だ。", "You are a Genuine Champion!"));
88 msg_print(_("勝利!チャンピオンへの道を進んでいる。", "Victorious! You're on your way to becoming Champion."));
90 if (arena_info[player_ptr->arena_number].tval > ItemKindType::NONE) {
93 q_ptr->prep(lookup_kind(arena_info[player_ptr->arena_number].tval, arena_info[player_ptr->arena_number].sval));
94 apply_magic_to_object(player_ptr, q_ptr, floor_ptr->object_level, AM_NO_FIXED_ART);
95 (void)drop_near(player_ptr, q_ptr, -1, md_ptr->md_y, md_ptr->md_x);
98 if (player_ptr->arena_number > MAX_ARENA_MONS)
99 player_ptr->arena_number++;
101 player_ptr->arena_number++;
105 GAME_TEXT m_name[MAX_NLEN];
106 monster_desc(player_ptr, m_name, md_ptr->m_ptr, MD_WRONGDOER_NAME);
107 exe_write_diary(player_ptr, DIARY_ARENA, player_ptr->arena_number, m_name);
110 static void drop_corpse(PlayerType *player_ptr, monster_death_type *md_ptr)
112 auto *floor_ptr = player_ptr->current_floor_ptr;
113 bool is_drop_corpse = one_in_(md_ptr->r_ptr->kind_flags.has(MonsterKindType::UNIQUE) ? 1 : 4);
114 is_drop_corpse &= (md_ptr->r_ptr->flags9 & (RF9_DROP_CORPSE | RF9_DROP_SKELETON)) != 0;
115 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)));
120 if (!(md_ptr->r_ptr->flags9 & RF9_DROP_SKELETON))
122 else if ((md_ptr->r_ptr->flags9 & RF9_DROP_CORPSE) && md_ptr->r_ptr->kind_flags.has(MonsterKindType::UNIQUE))
124 else if (md_ptr->r_ptr->flags9 & RF9_DROP_CORPSE) {
125 if ((0 - ((md_ptr->m_ptr->maxhp) / 4)) > md_ptr->m_ptr->hp) {
135 auto *q_ptr = &forge;
136 q_ptr->prep(lookup_kind(ItemKindType::CORPSE, (corpse ? SV_CORPSE : SV_SKELETON)));
137 apply_magic_to_object(player_ptr, q_ptr, floor_ptr->object_level, AM_NO_FIXED_ART);
138 q_ptr->pval = md_ptr->m_ptr->r_idx;
139 (void)drop_near(player_ptr, q_ptr, -1, md_ptr->md_y, md_ptr->md_x);
143 * @brief アーティファクトのドロップ判定処理
144 * @param player_ptr プレイヤーへの参照ポインタ
145 * @param md_ptr モンスター死亡構造体への参照ポインタ
146 * @return 何かドロップするなら1以上、何もドロップしないなら0
148 static ARTIFACT_IDX drop_artifact_index(PlayerType *player_ptr, monster_death_type *md_ptr)
150 ARTIFACT_IDX a_idx = 0;
151 PERCENTAGE chance = 0;
152 for (int i = 0; i < 4; i++) {
153 if (!md_ptr->r_ptr->artifact_id[i])
156 a_idx = md_ptr->r_ptr->artifact_id[i];
157 chance = md_ptr->r_ptr->artifact_percent[i];
158 if ((randint0(100) >= chance) && !w_ptr->wizard)
161 if (drop_single_artifact(player_ptr, md_ptr, a_idx))
169 * @brief 特定アーティファクトのドロップ処理
170 * @param player_ptr プレイヤーへの参照ポインタ
171 * @param md_ptr モンスター死亡構造体への参照ポインタ
172 * @param a_ix ドロップを試みるアーティファクトID
173 * @return ドロップするならtrue
175 bool drop_single_artifact(PlayerType *player_ptr, monster_death_type *md_ptr, ARTIFACT_IDX a_idx)
177 auto *a_ptr = &a_info[a_idx];
178 if (a_ptr->cur_num == 1)
181 if (create_named_art(player_ptr, a_idx, md_ptr->md_y, md_ptr->md_x)) {
184 if (w_ptr->character_dungeon) {
185 a_ptr->floor_id = player_ptr->floor_id;
188 if (!preserve_mode) {
197 static KIND_OBJECT_IDX drop_dungeon_final_artifact(PlayerType *player_ptr, monster_death_type *md_ptr, ARTIFACT_IDX a_idx)
199 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);
200 if (d_info[player_ptr->dungeon_idx].final_artifact == 0)
203 a_idx = d_info[player_ptr->dungeon_idx].final_artifact;
204 auto *a_ptr = &a_info[a_idx];
205 if (a_ptr->cur_num == 1)
207 if (create_named_art(player_ptr, a_idx, md_ptr->md_y, md_ptr->md_x)) {
209 if (w_ptr->character_dungeon)
210 a_ptr->floor_id = player_ptr->floor_id;
211 } else if (!preserve_mode) {
215 return d_info[player_ptr->dungeon_idx].final_object ? k_idx : 0;
218 static void drop_artifact(PlayerType *player_ptr, monster_death_type *md_ptr)
220 if (!md_ptr->drop_chosen_item)
223 ARTIFACT_IDX a_idx = drop_artifact_index(player_ptr, md_ptr);
224 if (((md_ptr->r_ptr->flags7 & RF7_GUARDIAN) == 0) || (d_info[player_ptr->dungeon_idx].final_guardian != md_ptr->m_ptr->r_idx))
227 KIND_OBJECT_IDX k_idx = drop_dungeon_final_artifact(player_ptr, md_ptr, a_idx);
230 auto *q_ptr = &forge;
232 apply_magic_to_object(player_ptr, q_ptr, player_ptr->current_floor_ptr->object_level, AM_NO_FIXED_ART | AM_GOOD);
233 (void)drop_near(player_ptr, q_ptr, -1, md_ptr->md_y, md_ptr->md_x);
236 msg_format(_("あなたは%sを制覇した!", "You have conquered %s!"), d_info[player_ptr->dungeon_idx].name.c_str());
239 static void decide_drop_quality(monster_death_type *md_ptr)
241 md_ptr->mo_mode = 0L;
242 if (md_ptr->r_ptr->flags1 & RF1_DROP_GOOD)
243 md_ptr->mo_mode |= AM_GOOD;
245 if (md_ptr->r_ptr->flags1 & RF1_DROP_GREAT)
246 md_ptr->mo_mode |= (AM_GOOD | AM_GREAT);
249 static int decide_drop_numbers(PlayerType *player_ptr, monster_death_type *md_ptr, const bool drop_item)
251 int drop_numbers = 0;
252 if ((md_ptr->r_ptr->flags1 & RF1_DROP_60) && (randint0(100) < 60))
255 if ((md_ptr->r_ptr->flags1 & RF1_DROP_90) && (randint0(100) < 90))
258 if (md_ptr->r_ptr->flags1 & RF1_DROP_1D2)
259 drop_numbers += damroll(1, 2);
261 if (md_ptr->r_ptr->flags1 & RF1_DROP_2D2)
262 drop_numbers += damroll(2, 2);
264 if (md_ptr->r_ptr->flags1 & RF1_DROP_3D2)
265 drop_numbers += damroll(3, 2);
267 if (md_ptr->r_ptr->flags1 & RF1_DROP_4D2)
268 drop_numbers += damroll(4, 2);
270 if (md_ptr->cloned && md_ptr->r_ptr->kind_flags.has_not(MonsterKindType::UNIQUE))
273 if (is_pet(md_ptr->m_ptr) || player_ptr->phase_out || player_ptr->current_floor_ptr->inside_arena)
276 if (!drop_item && (md_ptr->r_ptr->d_char != '$'))
279 if ((md_ptr->r_ptr->flags2 & (RF2_MULTIPLY)) && (md_ptr->r_ptr->r_akills > 1024))
285 static void drop_items_golds(PlayerType *player_ptr, monster_death_type *md_ptr, int drop_numbers)
289 for (int i = 0; i < drop_numbers; i++) {
291 auto *q_ptr = &forge;
293 if (md_ptr->do_gold && (!md_ptr->do_item || (randint0(100) < 50))) {
294 if (!make_gold(player_ptr, q_ptr))
299 if (!make_object(player_ptr, q_ptr, md_ptr->mo_mode))
305 (void)drop_near(player_ptr, q_ptr, -1, md_ptr->md_y, md_ptr->md_x);
308 auto *floor_ptr = player_ptr->current_floor_ptr;
309 floor_ptr->object_level = floor_ptr->base_level;
311 bool visible = (md_ptr->m_ptr->ml && !player_ptr->hallucinated) || (md_ptr->r_ptr->kind_flags.has(MonsterKindType::UNIQUE));
312 if (visible && (dump_item || dump_gold))
313 lore_treasure(player_ptr, md_ptr->m_idx, dump_item, dump_gold);
317 * @brief 最終ボス(混沌のサーペント)を倒したときの処理
318 * @param player_ptr プレイヤー情報への参照ポインタ
320 static void on_defeat_last_boss(PlayerType *player_ptr)
322 w_ptr->total_winner = true;
323 add_winner_class(player_ptr->pclass);
324 player_ptr->redraw |= PR_TITLE;
325 play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_FINAL_QUEST_CLEAR);
326 exe_write_diary(player_ptr, DIARY_DESCRIPTION, 0, _("見事に変愚蛮怒の勝利者となった!", "finally became *WINNER* of Hengband!"));
327 patron_list[player_ptr->chaos_patron].admire(player_ptr);
328 msg_print(_("*** おめでとう ***", "*** CONGRATULATIONS ***"));
329 msg_print(_("あなたはゲームをコンプリートしました。", "You have won the game!"));
330 msg_print(_("準備が整ったら引退(自殺コマンド)しても結構です。", "You may retire (commit suicide) when you are ready."));
334 * @brief モンスターが死亡した時の処理 /
335 * Handle the "death" of a monster.
336 * @param m_idx 死亡したモンスターのID
337 * @param drop_item TRUEならばモンスターのドロップ処理を行う
338 * @param type ラストアタックの属性 (単一属性)
340 void monster_death(PlayerType *player_ptr, MONSTER_IDX m_idx, bool drop_item, AttributeType type)
342 AttributeFlags flags;
345 monster_death(player_ptr, m_idx, drop_item, flags);
349 * @brief モンスターが死亡した時の処理 /
350 * Handle the "death" of a monster.
351 * @param m_idx 死亡したモンスターのID
352 * @param drop_item TRUEならばモンスターのドロップ処理を行う
353 * @param attribute_flags ラストアタックの属性 (複数属性)
356 * Disperse treasures centered at the monster location based on the
357 * various flags contained in the monster flags fields.
358 * Check for "Quest" completion when a quest monster is killed.
359 * Note that only the player can induce "monster_death()" on Uniques.
360 * Thus (for now) all Quest monsters should be Uniques.
361 * Note that monsters can now carry objects, and when a monster dies,
362 * it drops all of its objects, which may disappear in crowded rooms.
365 void monster_death(PlayerType *player_ptr, MONSTER_IDX m_idx, bool drop_item, AttributeFlags attribute_flags)
367 monster_death_type tmp_md;
368 monster_death_type *md_ptr = initialize_monster_death_type(player_ptr, &tmp_md, m_idx, drop_item);
369 if (w_ptr->timewalk_m_idx && w_ptr->timewalk_m_idx == m_idx)
370 w_ptr->timewalk_m_idx = 0;
372 // プレイヤーしかユニークを倒せないのでここで時間を記録
373 if (md_ptr->r_ptr->kind_flags.has(MonsterKindType::UNIQUE) && md_ptr->m_ptr->mflag2.has_not(MonsterConstantFlagType::CLONED)) {
375 md_ptr->r_ptr->defeat_time = w_ptr->play_time;
376 md_ptr->r_ptr->defeat_level = player_ptr->lev;
379 if (md_ptr->r_ptr->flags7 & (RF7_LITE_MASK | RF7_DARK_MASK))
380 player_ptr->update |= PU_MON_LITE;
382 write_pet_death(player_ptr, md_ptr);
383 on_dead_explosion(player_ptr, md_ptr);
384 if (md_ptr->m_ptr->mflag2.has(MonsterConstantFlagType::CHAMELEON)) {
385 choose_new_monster(player_ptr, m_idx, true, MON_CHAMELEON);
386 md_ptr->r_ptr = &r_info[md_ptr->m_ptr->r_idx];
389 QuestCompletionChecker(player_ptr, md_ptr->m_ptr).complete();
390 on_defeat_arena_monster(player_ptr, md_ptr);
391 if (m_idx == player_ptr->riding && process_fall_off_horse(player_ptr, -1, false))
392 msg_print(_("地面に落とされた。", "You have fallen from the pet you were riding."));
394 drop_corpse(player_ptr, md_ptr);
395 monster_drop_carried_objects(player_ptr, md_ptr->m_ptr);
396 decide_drop_quality(md_ptr);
397 switch_special_death(player_ptr, md_ptr, attribute_flags);
398 drop_artifact(player_ptr, md_ptr);
399 int drop_numbers = decide_drop_numbers(player_ptr, md_ptr, drop_item);
400 coin_type = md_ptr->force_coin;
401 auto *floor_ptr = player_ptr->current_floor_ptr;
402 floor_ptr->object_level = (floor_ptr->dun_level + md_ptr->r_ptr->level) / 2;
403 drop_items_golds(player_ptr, md_ptr, drop_numbers);
404 if (((md_ptr->r_ptr->flags1 & RF1_QUESTOR) == 0) || player_ptr->phase_out || (md_ptr->m_ptr->r_idx != MON_SERPENT) || md_ptr->cloned)
407 on_defeat_last_boss(player_ptr);
411 * @brief モンスターを撃破した際の述語メッセージを返す /
412 * Return monster death string
413 * @param r_ptr 撃破されたモンスターの種族情報を持つ構造体の参照ポインタ
414 * @return 撃破されたモンスターの述語
416 concptr extract_note_dies(MONRACE_IDX r_idx)
418 auto *r_ptr = &r_info[r_idx];
419 if (monster_living(r_idx))
420 return _("は死んだ。", " dies.");
422 for (int i = 0; i < 4; i++)
423 if (r_ptr->blow[i].method == RaceBlowMethodType::EXPLODE)
424 return _("は爆発して粉々になった。", " explodes into tiny shreds.");
426 return _("を倒した。", " is destroyed.");