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/game-play-options.h"
13 #include "game-option/play-record-options.h"
14 #include "io/write-diary.h"
15 #include "lore/lore-store.h"
16 #include "main/music-definitions-table.h"
17 #include "main/sound-of-music.h"
18 #include "market/arena-info-table.h"
19 #include "monster-floor/monster-death-util.h"
20 #include "monster-floor/monster-object.h"
21 #include "monster-floor/special-death-switcher.h"
22 #include "monster-race/monster-race-hook.h"
23 #include "monster-race/monster-race.h"
24 #include "monster-race/race-flags1.h"
25 #include "monster-race/race-flags2.h"
26 #include "monster-race/race-flags7.h"
27 #include "monster-race/race-flags9.h"
28 #include "monster-race/race-indice-types.h"
29 #include "monster/monster-describer.h"
30 #include "monster/monster-description-types.h"
31 #include "monster/monster-flag-types.h"
32 #include "monster/monster-info.h"
33 #include "monster/monster-list.h"
34 #include "object-enchant/apply-magic.h"
35 #include "object-enchant/item-apply-magic.h"
36 #include "object/object-kind-hook.h"
37 #include "pet/pet-fall-off.h"
38 #include "player/patron.h"
39 #include "sv-definition/sv-other-types.h"
40 #include "sv-definition/sv-scroll-types.h"
41 #include "system/artifact-type-definition.h"
42 #include "system/building-type-definition.h"
43 #include "system/floor-type-definition.h"
44 #include "system/monster-race-definition.h"
45 #include "system/monster-type-definition.h"
46 #include "system/player-type-definition.h"
47 #include "system/system-variables.h"
48 #include "util/bit-flags-calculator.h"
49 #include "view/display-messages.h"
50 #include "world/world.h"
52 static void write_pet_death(player_type *player_ptr, monster_death_type *md_ptr)
54 md_ptr->md_y = md_ptr->m_ptr->fy;
55 md_ptr->md_x = md_ptr->m_ptr->fx;
56 if (record_named_pet && is_pet(md_ptr->m_ptr) && md_ptr->m_ptr->nickname) {
57 GAME_TEXT m_name[MAX_NLEN];
58 monster_desc(player_ptr, m_name, md_ptr->m_ptr, MD_INDEF_VISIBLE);
59 exe_write_diary(player_ptr, DIARY_NAMED_PET, 3, m_name);
63 static void on_dead_explosion(player_type *player_ptr, monster_death_type *md_ptr)
65 for (int i = 0; i < 4; i++) {
66 if (md_ptr->r_ptr->blow[i].method != RBM_EXPLODE)
69 BIT_FLAGS flg = PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL;
70 EFFECT_ID typ = mbe_info[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 HIT_POINT 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(player_type *player_ptr, monster_death_type *md_ptr)
81 floor_type *floor_ptr = player_ptr->current_floor_ptr;
82 if (!floor_ptr->inside_arena || is_pet(md_ptr->m_ptr))
85 player_ptr->exit_bldg = true;
86 if (player_ptr->arena_number > MAX_ARENA_MONS)
87 msg_print(_("素晴らしい!君こそ真の勝利者だ。", "You are a Genuine Champion!"));
89 msg_print(_("勝利!チャンピオンへの道を進んでいる。", "Victorious! You're on your way to becoming Champion."));
91 if (arena_info[player_ptr->arena_number].tval) {
93 object_type *q_ptr = &forge;
94 q_ptr->prep(lookup_kind(arena_info[player_ptr->arena_number].tval, arena_info[player_ptr->arena_number].sval));
95 apply_magic_to_object(player_ptr, q_ptr, floor_ptr->object_level, AM_NO_FIXED_ART);
96 (void)drop_near(player_ptr, q_ptr, -1, md_ptr->md_y, md_ptr->md_x);
99 if (player_ptr->arena_number > MAX_ARENA_MONS)
100 player_ptr->arena_number++;
102 player_ptr->arena_number++;
106 GAME_TEXT m_name[MAX_NLEN];
107 monster_desc(player_ptr, m_name, md_ptr->m_ptr, MD_WRONGDOER_NAME);
108 exe_write_diary(player_ptr, DIARY_ARENA, player_ptr->arena_number, m_name);
111 static void drop_corpse(player_type *player_ptr, monster_death_type *md_ptr)
113 floor_type *floor_ptr = player_ptr->current_floor_ptr;
114 bool is_drop_corpse = one_in_(md_ptr->r_ptr->flags1 & RF1_UNIQUE ? 1 : 4);
115 is_drop_corpse &= (md_ptr->r_ptr->flags9 & (RF9_DROP_CORPSE | RF9_DROP_SKELETON)) != 0;
116 is_drop_corpse &= !(floor_ptr->inside_arena || player_ptr->phase_out || md_ptr->cloned
117 || ((md_ptr->m_ptr->r_idx == w_ptr->today_mon) && is_pet(md_ptr->m_ptr)));
122 if (!(md_ptr->r_ptr->flags9 & RF9_DROP_SKELETON))
124 else if ((md_ptr->r_ptr->flags9 & RF9_DROP_CORPSE) && (md_ptr->r_ptr->flags1 & RF1_UNIQUE))
126 else if (md_ptr->r_ptr->flags9 & RF9_DROP_CORPSE) {
127 if ((0 - ((md_ptr->m_ptr->maxhp) / 4)) > md_ptr->m_ptr->hp) {
137 object_type *q_ptr = &forge;
138 q_ptr->prep(lookup_kind(TV_CORPSE, (corpse ? SV_CORPSE : SV_SKELETON)));
139 apply_magic_to_object(player_ptr, q_ptr, floor_ptr->object_level, AM_NO_FIXED_ART);
140 q_ptr->pval = md_ptr->m_ptr->r_idx;
141 (void)drop_near(player_ptr, q_ptr, -1, md_ptr->md_y, md_ptr->md_x);
145 * @brief アーティファクトのドロップ判定処理
146 * @param player_ptr プレイヤーへの参照ポインタ
147 * @param md_ptr モンスター死亡構造体への参照ポインタ
148 * @return 何かドロップするなら1以上、何もドロップしないなら0
150 static ARTIFACT_IDX drop_artifact_index(player_type *player_ptr, monster_death_type *md_ptr)
152 ARTIFACT_IDX a_idx = 0;
153 PERCENTAGE chance = 0;
154 for (int i = 0; i < 4; i++) {
155 if (!md_ptr->r_ptr->artifact_id[i])
158 a_idx = md_ptr->r_ptr->artifact_id[i];
159 chance = md_ptr->r_ptr->artifact_percent[i];
160 if (allow_debug_options) {
162 // @todo ここより下の処理は関数分割で何とかしたい.
163 // 処理を送るだけのif文は気持ち悪い.
164 } else if (randint0(100) >= chance) {
168 artifact_type *a_ptr = &a_info[a_idx];
169 if (a_ptr->cur_num == 1)
172 if (create_named_art(player_ptr, a_idx, md_ptr->md_y, md_ptr->md_x)) {
174 if (w_ptr->character_dungeon)
175 a_ptr->floor_id = player_ptr->floor_id;
180 if (!preserve_mode) {
189 static KIND_OBJECT_IDX drop_dungeon_final_artifact(player_type *player_ptr, monster_death_type *md_ptr, ARTIFACT_IDX a_idx)
191 KIND_OBJECT_IDX k_idx
192 = d_info[player_ptr->dungeon_idx].final_object != 0 ? d_info[player_ptr->dungeon_idx].final_object : lookup_kind(TV_SCROLL, SV_SCROLL_ACQUIREMENT);
193 if (d_info[player_ptr->dungeon_idx].final_artifact == 0)
196 a_idx = d_info[player_ptr->dungeon_idx].final_artifact;
197 artifact_type *a_ptr = &a_info[a_idx];
198 if (a_ptr->cur_num == 1)
200 if (create_named_art(player_ptr, a_idx, md_ptr->md_y, md_ptr->md_x)) {
202 if (w_ptr->character_dungeon)
203 a_ptr->floor_id = player_ptr->floor_id;
204 } else if (!preserve_mode) {
208 return d_info[player_ptr->dungeon_idx].final_object ? k_idx : 0;
211 static void drop_artifact(player_type *player_ptr, monster_death_type *md_ptr)
213 if (!md_ptr->drop_chosen_item)
216 ARTIFACT_IDX a_idx = drop_artifact_index(player_ptr, md_ptr);
217 if (((md_ptr->r_ptr->flags7 & RF7_GUARDIAN) == 0) || (d_info[player_ptr->dungeon_idx].final_guardian != md_ptr->m_ptr->r_idx))
220 KIND_OBJECT_IDX k_idx = drop_dungeon_final_artifact(player_ptr, md_ptr, a_idx);
223 object_type *q_ptr = &forge;
225 apply_magic_to_object(player_ptr, q_ptr, player_ptr->current_floor_ptr->object_level, AM_NO_FIXED_ART | AM_GOOD);
226 (void)drop_near(player_ptr, q_ptr, -1, md_ptr->md_y, md_ptr->md_x);
229 msg_format(_("あなたは%sを制覇した!", "You have conquered %s!"), d_info[player_ptr->dungeon_idx].name.c_str());
232 static void decide_drop_quality(monster_death_type *md_ptr)
234 md_ptr->mo_mode = 0L;
235 if (md_ptr->r_ptr->flags1 & RF1_DROP_GOOD)
236 md_ptr->mo_mode |= AM_GOOD;
238 if (md_ptr->r_ptr->flags1 & RF1_DROP_GREAT)
239 md_ptr->mo_mode |= (AM_GOOD | AM_GREAT);
242 static int decide_drop_numbers(player_type *player_ptr, monster_death_type *md_ptr, const bool drop_item)
244 int drop_numbers = 0;
245 if ((md_ptr->r_ptr->flags1 & RF1_DROP_60) && (randint0(100) < 60))
248 if ((md_ptr->r_ptr->flags1 & RF1_DROP_90) && (randint0(100) < 90))
251 if (md_ptr->r_ptr->flags1 & RF1_DROP_1D2)
252 drop_numbers += damroll(1, 2);
254 if (md_ptr->r_ptr->flags1 & RF1_DROP_2D2)
255 drop_numbers += damroll(2, 2);
257 if (md_ptr->r_ptr->flags1 & RF1_DROP_3D2)
258 drop_numbers += damroll(3, 2);
260 if (md_ptr->r_ptr->flags1 & RF1_DROP_4D2)
261 drop_numbers += damroll(4, 2);
263 if (md_ptr->cloned && !(md_ptr->r_ptr->flags1 & RF1_UNIQUE))
266 if (is_pet(md_ptr->m_ptr) || player_ptr->phase_out || player_ptr->current_floor_ptr->inside_arena)
269 if (!drop_item && (md_ptr->r_ptr->d_char != '$'))
272 if ((md_ptr->r_ptr->flags2 & (RF2_MULTIPLY)) && (md_ptr->r_ptr->r_akills > 1024))
278 static void drop_items_golds(player_type *player_ptr, monster_death_type *md_ptr, int drop_numbers)
282 for (int i = 0; i < drop_numbers; i++) {
284 object_type *q_ptr = &forge;
286 if (md_ptr->do_gold && (!md_ptr->do_item || (randint0(100) < 50))) {
287 if (!make_gold(player_ptr, q_ptr))
292 if (!make_object(player_ptr, q_ptr, md_ptr->mo_mode))
298 (void)drop_near(player_ptr, q_ptr, -1, md_ptr->md_y, md_ptr->md_x);
301 floor_type *floor_ptr = player_ptr->current_floor_ptr;
302 floor_ptr->object_level = floor_ptr->base_level;
304 bool visible = (md_ptr->m_ptr->ml && !player_ptr->hallucinated) || ((md_ptr->r_ptr->flags1 & RF1_UNIQUE) != 0);
305 if (visible && (dump_item || dump_gold))
306 lore_treasure(player_ptr, md_ptr->m_idx, dump_item, dump_gold);
310 * @brief 最終ボス(混沌のサーペント)を倒したときの処理
311 * @param player_ptr プレイヤー情報への参照ポインタ
313 static void on_defeat_last_boss(player_type *player_ptr)
315 w_ptr->total_winner = true;
316 add_winner_class(player_ptr->pclass);
317 player_ptr->redraw |= PR_TITLE;
318 play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_FINAL_QUEST_CLEAR);
319 exe_write_diary(player_ptr, DIARY_DESCRIPTION, 0, _("見事に変愚蛮怒の勝利者となった!", "finally became *WINNER* of Hengband!"));
320 admire_from_patron(player_ptr);
321 msg_print(_("*** おめでとう ***", "*** CONGRATULATIONS ***"));
322 msg_print(_("あなたはゲームをコンプリートしました。", "You have won the game!"));
323 msg_print(_("準備が整ったら引退(自殺コマンド)しても結構です。", "You may retire (commit suicide) when you are ready."));
327 * @brief モンスターが死亡した時の処理 /
328 * Handle the "death" of a monster.
329 * @param m_idx 死亡したモンスターのID
330 * @param drop_item TRUEならばモンスターのドロップ処理を行う
331 * @return 撃破されたモンスターの述語
334 * Disperse treasures centered at the monster location based on the
335 * various flags contained in the monster flags fields.
336 * Check for "Quest" completion when a quest monster is killed.
337 * Note that only the player can induce "monster_death()" on Uniques.
338 * Thus (for now) all Quest monsters should be Uniques.
339 * Note that monsters can now carry objects, and when a monster dies,
340 * it drops all of its objects, which may disappear in crowded rooms.
343 void monster_death(player_type *player_ptr, MONSTER_IDX m_idx, bool drop_item)
345 monster_death_type tmp_md;
346 monster_death_type *md_ptr = initialize_monster_death_type(player_ptr, &tmp_md, m_idx, drop_item);
347 if (w_ptr->timewalk_m_idx && w_ptr->timewalk_m_idx == m_idx)
348 w_ptr->timewalk_m_idx = 0;
350 // プレイヤーしかユニークを倒せないのでここで時間を記録
351 if (any_bits(md_ptr->r_ptr->flags1, RF1_UNIQUE) && md_ptr->m_ptr->mflag2.has_not(MFLAG2::CLONED)) {
353 md_ptr->r_ptr->defeat_time = w_ptr->play_time;
354 md_ptr->r_ptr->defeat_level = player_ptr->lev;
357 if (md_ptr->r_ptr->flags7 & (RF7_LITE_MASK | RF7_DARK_MASK))
358 player_ptr->update |= PU_MON_LITE;
360 write_pet_death(player_ptr, md_ptr);
361 on_dead_explosion(player_ptr, md_ptr);
362 if (md_ptr->m_ptr->mflag2.has(MFLAG2::CHAMELEON)) {
363 choose_new_monster(player_ptr, m_idx, true, MON_CHAMELEON);
364 md_ptr->r_ptr = &r_info[md_ptr->m_ptr->r_idx];
367 check_quest_completion(player_ptr, md_ptr->m_ptr);
368 on_defeat_arena_monster(player_ptr, md_ptr);
369 if (m_idx == player_ptr->riding && process_fall_off_horse(player_ptr, -1, false))
370 msg_print(_("地面に落とされた。", "You have fallen from the pet you were riding."));
372 drop_corpse(player_ptr, md_ptr);
373 monster_drop_carried_objects(player_ptr, md_ptr->m_ptr);
374 decide_drop_quality(md_ptr);
375 switch_special_death(player_ptr, md_ptr);
376 drop_artifact(player_ptr, md_ptr);
377 int drop_numbers = decide_drop_numbers(player_ptr, md_ptr, drop_item);
378 coin_type = md_ptr->force_coin;
379 floor_type *floor_ptr = player_ptr->current_floor_ptr;
380 floor_ptr->object_level = (floor_ptr->dun_level + md_ptr->r_ptr->level) / 2;
381 drop_items_golds(player_ptr, md_ptr, drop_numbers);
382 if (((md_ptr->r_ptr->flags1 & RF1_QUESTOR) == 0) || player_ptr->phase_out || (md_ptr->m_ptr->r_idx != MON_SERPENT) || md_ptr->cloned)
385 on_defeat_last_boss(player_ptr);
389 * @brief モンスターを撃破した際の述語メッセージを返す /
390 * Return monster death string
391 * @param r_ptr 撃破されたモンスターの種族情報を持つ構造体の参照ポインタ
392 * @return 撃破されたモンスターの述語
394 concptr extract_note_dies(MONRACE_IDX r_idx)
396 monster_race *r_ptr = &r_info[r_idx];
397 if (monster_living(r_idx))
398 return _("は死んだ。", " dies.");
400 for (int i = 0; i < 4; i++)
401 if (r_ptr->blow[i].method == RBM_EXPLODE)
402 return _("は爆発して粉々になった。", " explodes into tiny shreds.");
404 return _("を倒した。", " is destroyed.");