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-generator.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/system-variables.h"
45 #include "view/display-messages.h"
46 #include "world/world.h"
48 static void write_pet_death(player_type *player_ptr, monster_death_type *md_ptr)
50 md_ptr->md_y = md_ptr->m_ptr->fy;
51 md_ptr->md_x = md_ptr->m_ptr->fx;
52 if (record_named_pet && is_pet(md_ptr->m_ptr) && md_ptr->m_ptr->nickname) {
53 GAME_TEXT m_name[MAX_NLEN];
54 monster_desc(player_ptr, m_name, md_ptr->m_ptr, MD_INDEF_VISIBLE);
55 exe_write_diary(player_ptr, DIARY_NAMED_PET, 3, m_name);
59 static void on_dead_explosion(player_type *player_ptr, monster_death_type *md_ptr)
61 for (int i = 0; i < 4; i++) {
62 if (md_ptr->r_ptr->blow[i].method != RBM_EXPLODE)
65 BIT_FLAGS flg = PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL;
66 EFFECT_ID typ = mbe_info[md_ptr->r_ptr->blow[i].effect].explode_type;
67 DICE_NUMBER d_dice = md_ptr->r_ptr->blow[i].d_dice;
68 DICE_SID d_side = md_ptr->r_ptr->blow[i].d_side;
69 HIT_POINT damage = damroll(d_dice, d_side);
70 (void)project(player_ptr, md_ptr->m_idx, 3, md_ptr->md_y, md_ptr->md_x, damage, typ, flg, -1);
75 static void on_defeat_arena_monster(player_type *player_ptr, monster_death_type *md_ptr)
77 floor_type *floor_ptr = player_ptr->current_floor_ptr;
78 if (!floor_ptr->inside_arena || is_pet(md_ptr->m_ptr))
81 player_ptr->exit_bldg = TRUE;
82 if (player_ptr->arena_number > MAX_ARENA_MONS)
83 msg_print(_("素晴らしい!君こそ真の勝利者だ。", "You are a Genuine Champion!"));
85 msg_print(_("勝利!チャンピオンへの道を進んでいる。", "Victorious! You're on your way to becoming Champion."));
87 if (arena_info[player_ptr->arena_number].tval) {
89 object_type *q_ptr = &forge;
90 object_prep(player_ptr, q_ptr, lookup_kind(arena_info[player_ptr->arena_number].tval, arena_info[player_ptr->arena_number].sval));
91 apply_magic(player_ptr, q_ptr, floor_ptr->object_level, AM_NO_FIXED_ART);
92 (void)drop_near(player_ptr, q_ptr, -1, md_ptr->md_y, md_ptr->md_x);
95 if (player_ptr->arena_number > MAX_ARENA_MONS)
96 player_ptr->arena_number++;
98 player_ptr->arena_number++;
102 GAME_TEXT m_name[MAX_NLEN];
103 monster_desc(player_ptr, m_name, md_ptr->m_ptr, MD_WRONGDOER_NAME);
104 exe_write_diary(player_ptr, DIARY_ARENA, player_ptr->arena_number, m_name);
107 static void drop_corpse(player_type *player_ptr, monster_death_type *md_ptr)
109 floor_type *floor_ptr = player_ptr->current_floor_ptr;
110 bool is_drop_corpse = one_in_(md_ptr->r_ptr->flags1 & RF1_UNIQUE ? 1 : 4);
111 is_drop_corpse &= (md_ptr->r_ptr->flags9 & (RF9_DROP_CORPSE | RF9_DROP_SKELETON)) != 0;
112 is_drop_corpse &= !(floor_ptr->inside_arena || player_ptr->phase_out || md_ptr->cloned
113 || ((md_ptr->m_ptr->r_idx == current_world_ptr->today_mon) && is_pet(md_ptr->m_ptr)));
118 if (!(md_ptr->r_ptr->flags9 & RF9_DROP_SKELETON))
120 else if ((md_ptr->r_ptr->flags9 & RF9_DROP_CORPSE) && (md_ptr->r_ptr->flags1 & RF1_UNIQUE))
122 else if (md_ptr->r_ptr->flags9 & RF9_DROP_CORPSE) {
123 if ((0 - ((md_ptr->m_ptr->maxhp) / 4)) > md_ptr->m_ptr->hp) {
133 object_type *q_ptr = &forge;
134 object_prep(player_ptr, q_ptr, lookup_kind(TV_CORPSE, (corpse ? SV_CORPSE : SV_SKELETON)));
135 apply_magic(player_ptr, q_ptr, floor_ptr->object_level, AM_NO_FIXED_ART);
136 q_ptr->pval = md_ptr->m_ptr->r_idx;
137 (void)drop_near(player_ptr, q_ptr, -1, md_ptr->md_y, md_ptr->md_x);
141 * @brief アーティファクトのドロップ判定処理
142 * @param player_ptr プレーヤーへの参照ポインタ
143 * @param md_ptr モンスター死亡構造体への参照ポインタ
144 * @return 何かドロップするなら1以上、何もドロップしないなら0
146 static ARTIFACT_IDX drop_artifact_index(player_type *player_ptr, monster_death_type *md_ptr)
148 ARTIFACT_IDX a_idx = 0;
149 PERCENTAGE chance = 0;
150 for (int i = 0; i < 4; i++) {
151 if (!md_ptr->r_ptr->artifact_id[i])
154 a_idx = md_ptr->r_ptr->artifact_id[i];
155 chance = md_ptr->r_ptr->artifact_percent[i];
156 if ((randint0(100) >= chance) && !current_world_ptr->wizard)
159 artifact_type *a_ptr = &a_info[a_idx];
160 if (a_ptr->cur_num == 1)
163 if (create_named_art(player_ptr, a_idx, md_ptr->md_y, md_ptr->md_x)) {
165 if (current_world_ptr->character_dungeon)
166 a_ptr->floor_id = player_ptr->floor_id;
171 if (!preserve_mode) {
180 static KIND_OBJECT_IDX drop_dungeon_final_artifact(player_type *player_ptr, monster_death_type *md_ptr, ARTIFACT_IDX a_idx)
182 KIND_OBJECT_IDX k_idx
183 = d_info[player_ptr->dungeon_idx].final_object != 0 ? d_info[player_ptr->dungeon_idx].final_object : lookup_kind(TV_SCROLL, SV_SCROLL_ACQUIREMENT);
184 if (d_info[player_ptr->dungeon_idx].final_artifact == 0)
187 a_idx = d_info[player_ptr->dungeon_idx].final_artifact;
188 artifact_type *a_ptr = &a_info[a_idx];
189 if (a_ptr->cur_num == 1)
191 if (create_named_art(player_ptr, a_idx, md_ptr->md_y, md_ptr->md_x)) {
193 if (current_world_ptr->character_dungeon)
194 a_ptr->floor_id = player_ptr->floor_id;
195 } else if (!preserve_mode) {
199 return d_info[player_ptr->dungeon_idx].final_object ? k_idx : 0;
202 static void drop_artifact(player_type *player_ptr, monster_death_type *md_ptr)
204 if (!md_ptr->drop_chosen_item)
207 ARTIFACT_IDX a_idx = drop_artifact_index(player_ptr, md_ptr);
208 if (((md_ptr->r_ptr->flags7 & RF7_GUARDIAN) == 0) || (d_info[player_ptr->dungeon_idx].final_guardian != md_ptr->m_ptr->r_idx))
211 KIND_OBJECT_IDX k_idx = drop_dungeon_final_artifact(player_ptr, md_ptr, a_idx);
214 object_type *q_ptr = &forge;
215 object_prep(player_ptr, q_ptr, k_idx);
216 apply_magic(player_ptr, q_ptr, player_ptr->current_floor_ptr->object_level, AM_NO_FIXED_ART | AM_GOOD);
217 (void)drop_near(player_ptr, q_ptr, -1, md_ptr->md_y, md_ptr->md_x);
220 msg_format(_("あなたは%sを制覇した!", "You have conquered %s!"), d_name + d_info[player_ptr->dungeon_idx].name);
223 static void decide_drop_quality(monster_death_type *md_ptr)
225 md_ptr->mo_mode = 0L;
226 if (md_ptr->r_ptr->flags1 & RF1_DROP_GOOD)
227 md_ptr->mo_mode |= AM_GOOD;
229 if (md_ptr->r_ptr->flags1 & RF1_DROP_GREAT)
230 md_ptr->mo_mode |= (AM_GOOD | AM_GREAT);
233 static int decide_drop_numbers(player_type *player_ptr, monster_death_type *md_ptr, const bool drop_item)
235 int drop_numbers = 0;
236 if ((md_ptr->r_ptr->flags1 & RF1_DROP_60) && (randint0(100) < 60))
239 if ((md_ptr->r_ptr->flags1 & RF1_DROP_90) && (randint0(100) < 90))
242 if (md_ptr->r_ptr->flags1 & RF1_DROP_1D2)
243 drop_numbers += damroll(1, 2);
245 if (md_ptr->r_ptr->flags1 & RF1_DROP_2D2)
246 drop_numbers += damroll(2, 2);
248 if (md_ptr->r_ptr->flags1 & RF1_DROP_3D2)
249 drop_numbers += damroll(3, 2);
251 if (md_ptr->r_ptr->flags1 & RF1_DROP_4D2)
252 drop_numbers += damroll(4, 2);
254 if (md_ptr->cloned && !(md_ptr->r_ptr->flags1 & RF1_UNIQUE))
257 if (is_pet(md_ptr->m_ptr) || player_ptr->phase_out || player_ptr->current_floor_ptr->inside_arena)
260 if (!drop_item && (md_ptr->r_ptr->d_char != '$'))
263 if ((md_ptr->r_ptr->flags2 & (RF2_MULTIPLY)) && (md_ptr->r_ptr->r_akills > 1024))
269 static void drop_items_golds(player_type *player_ptr, monster_death_type *md_ptr, int drop_numbers)
273 for (int i = 0; i < drop_numbers; i++) {
275 object_type *q_ptr = &forge;
277 if (md_ptr->do_gold && (!md_ptr->do_item || (randint0(100) < 50))) {
278 if (!make_gold(player_ptr, q_ptr))
283 if (!make_object(player_ptr, q_ptr, md_ptr->mo_mode))
289 (void)drop_near(player_ptr, q_ptr, -1, md_ptr->md_y, md_ptr->md_x);
292 floor_type *floor_ptr = player_ptr->current_floor_ptr;
293 floor_ptr->object_level = floor_ptr->base_level;
295 bool visible = (md_ptr->m_ptr->ml && !player_ptr->image) || ((md_ptr->r_ptr->flags1 & RF1_UNIQUE) != 0);
296 if (visible && (dump_item || dump_gold))
297 lore_treasure(player_ptr, md_ptr->m_idx, dump_item, dump_gold);
300 static void on_defeat_last_boss(player_type *player_ptr)
302 current_world_ptr->total_winner = TRUE;
303 player_ptr->redraw |= PR_TITLE;
304 play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_FINAL_QUEST_CLEAR);
305 exe_write_diary(player_ptr, DIARY_DESCRIPTION, 0, _("見事に変愚蛮怒の勝利者となった!", "finally became *WINNER* of Hengband!"));
306 admire_from_patron(player_ptr);
307 msg_print(_("*** おめでとう ***", "*** CONGRATULATIONS ***"));
308 msg_print(_("あなたはゲームをコンプリートしました。", "You have won the game!"));
309 msg_print(_("準備が整ったら引退(自殺コマンド)しても結構です。", "You may retire (commit suicide) when you are ready."));
313 * @brief モンスターが死亡した時の処理 /
314 * Handle the "death" of a monster.
315 * @param m_idx 死亡したモンスターのID
316 * @param drop_item TRUEならばモンスターのドロップ処理を行う
317 * @return 撃破されたモンスターの述語
320 * Disperse treasures centered at the monster location based on the
321 * various flags contained in the monster flags fields.
322 * Check for "Quest" completion when a quest monster is killed.
323 * Note that only the player can induce "monster_death()" on Uniques.
324 * Thus (for now) all Quest monsters should be Uniques.
325 * Note that monsters can now carry objects, and when a monster dies,
326 * it drops all of its objects, which may disappear in crowded rooms.
329 void monster_death(player_type *player_ptr, MONSTER_IDX m_idx, bool drop_item)
331 monster_death_type tmp_md;
332 monster_death_type *md_ptr = initialize_monster_death_type(player_ptr, &tmp_md, m_idx, drop_item);
333 if (current_world_ptr->timewalk_m_idx && current_world_ptr->timewalk_m_idx == m_idx)
334 current_world_ptr->timewalk_m_idx = 0;
336 if (md_ptr->r_ptr->flags7 & (RF7_LITE_MASK | RF7_DARK_MASK))
337 player_ptr->update |= PU_MON_LITE;
339 write_pet_death(player_ptr, md_ptr);
340 on_dead_explosion(player_ptr, md_ptr);
341 if (md_ptr->m_ptr->mflag2.has(MFLAG2::CHAMELEON)) {
342 choose_new_monster(player_ptr, m_idx, TRUE, MON_CHAMELEON);
343 md_ptr->r_ptr = &r_info[md_ptr->m_ptr->r_idx];
346 check_quest_completion(player_ptr, md_ptr->m_ptr);
347 on_defeat_arena_monster(player_ptr, md_ptr);
348 if (m_idx == player_ptr->riding && process_fall_off_horse(player_ptr, -1, FALSE))
349 msg_print(_("地面に落とされた。", "You have fallen from the pet you were riding."));
351 drop_corpse(player_ptr, md_ptr);
352 monster_drop_carried_objects(player_ptr, md_ptr->m_ptr);
353 decide_drop_quality(md_ptr);
354 switch_special_death(player_ptr, md_ptr);
355 drop_artifact(player_ptr, md_ptr);
356 int drop_numbers = decide_drop_numbers(player_ptr, md_ptr, drop_item);
357 coin_type = md_ptr->force_coin;
358 floor_type *floor_ptr = player_ptr->current_floor_ptr;
359 floor_ptr->object_level = (floor_ptr->dun_level + md_ptr->r_ptr->level) / 2;
360 drop_items_golds(player_ptr, md_ptr, drop_numbers);
361 if (((md_ptr->r_ptr->flags1 & RF1_QUESTOR) == 0) || player_ptr->phase_out || (md_ptr->m_ptr->r_idx != MON_SERPENT) || md_ptr->cloned)
364 on_defeat_last_boss(player_ptr);
368 * @brief モンスターを撃破した際の述語メッセージを返す /
369 * Return monster death string
370 * @param r_ptr 撃破されたモンスターの種族情報を持つ構造体の参照ポインタ
371 * @return 撃破されたモンスターの述語
373 concptr extract_note_dies(MONRACE_IDX r_idx)
375 monster_race *r_ptr = &r_info[r_idx];
376 if (monster_living(r_idx))
377 return _("は死んだ。", " dies.");
379 for (int i = 0; i < 4; i++)
380 if (r_ptr->blow[i].method == RBM_EXPLODE)
381 return _("は爆発して粉々になった。", " explodes into tiny shreds.");
383 return _("を倒した。", " is destroyed.");