OSDN Git Service

2dd7217e5bf5bcd67f1f3e95c1b508e911dfe1fc
[hengbandforosx/hengbandosx.git] / src / monster / monster-damage.cpp
1 /*
2  * @brief モンスターがダメージを受けた時の処理と経験値の加算処理
3  * @date 2021/08/04
4  * @author Hourier
5  */
6
7 #include "monster/monster-damage.h"
8 #include "core/player-redraw-types.h"
9 #include "core/speed-table.h"
10 #include "core/stuff-handler.h"
11 #include "dungeon/dungeon.h"
12 #include "game-option/birth-options.h"
13 #include "game-option/play-record-options.h"
14 #include "io/files-util.h"
15 #include "io/report.h"
16 #include "io/write-diary.h"
17 #include "main/sound-definitions-table.h"
18 #include "main/sound-of-music.h"
19 #include "mind/mind-ninja.h"
20 #include "monster-floor/monster-death.h"
21 #include "monster-floor/monster-remover.h"
22 #include "monster-floor/monster-summon.h"
23 #include "monster-floor/place-monster-types.h"
24 #include "monster-race/monster-race-hook.h"
25 #include "monster-race/monster-race.h"
26 #include "monster-race/race-ability-mask.h"
27 #include "monster-race/race-flags1.h"
28 #include "monster-race/race-flags2.h"
29 #include "monster-race/race-flags3.h"
30 #include "monster-race/race-flags7.h"
31 #include "monster-race/race-flags8.h"
32 #include "monster/monster-describer.h"
33 #include "monster/monster-description-types.h"
34 #include "monster/monster-info.h"
35 #include "monster/monster-status-setter.h"
36 #include "monster/monster-status.h"
37 #include "object-enchant/object-curse.h"
38 #include "player-info/avatar.h"
39 #include "player/player-status.h"
40 #include "player/special-defense-types.h"
41 #include "spell-kind/spells-random.h"
42 #include "status/experience.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 "util/bit-flags-calculator.h"
48 #include "view/display-messages.h"
49 #include "world/world.h"
50 #include <algorithm>
51
52 /*
53  * @brief コンストラクタ
54  * @param target_ptr プレーヤーへの参照ポインタ
55  * @param m_idx ダメージを与えたモンスターのID
56  * @param dam 与えたダメージ量
57  * @param fear ダメージによってモンスターが恐慌状態に陥ったならばtrue
58  * @param note モンスターが倒された際の特別なメッセージ述語
59  */
60 MonsterDamageProcessor::MonsterDamageProcessor(player_type *target_ptr, MONSTER_IDX m_idx, HIT_POINT dam, bool *fear)
61     : target_ptr(target_ptr)
62     , m_idx(m_idx)
63     , dam(dam)
64     , fear(fear)
65 {
66 }
67
68 /*!
69  * @brief モンスターのHPをダメージに応じて減算する /
70  * @return モンスターが生きていればfalse、死んだらtrue
71  */
72 bool MonsterDamageProcessor::mon_take_hit(concptr note)
73 {
74     auto *m_ptr = &this->target_ptr->current_floor_ptr->m_list[this->m_idx];
75     monster_type exp_mon;
76     (void)COPY(&exp_mon, m_ptr, monster_type);
77
78     auto exp_dam = (m_ptr->hp > this->dam) ? this->dam : m_ptr->hp;
79
80     this->get_exp_from_mon(&exp_mon, exp_dam);
81     if (this->genocide_chaos_patron()) {
82         return true;
83     }
84
85     m_ptr->hp -= this->dam;
86     m_ptr->dealt_damage += this->dam;
87     if (m_ptr->dealt_damage > m_ptr->max_maxhp * 100) {
88         m_ptr->dealt_damage = m_ptr->max_maxhp * 100;
89     }
90
91     if (current_world_ptr->wizard) {
92         msg_format(_("合計%d/%dのダメージを与えた。", "You do %d (out of %d) damage."), m_ptr->dealt_damage, m_ptr->maxhp);
93     }
94
95     auto *r_ptr = &r_info[m_ptr->r_idx];
96     if (m_ptr->hp < 0) {
97         this->death_special_flag_monster();
98         if (r_ptr->r_akills < MAX_SHORT) {
99             r_ptr->r_akills++;
100         }
101
102         this->increase_kill_numbers();
103         GAME_TEXT m_name[MAX_NLEN];
104         monster_desc(this->target_ptr, m_name, m_ptr, MD_TRUE_NAME);
105         this->death_amberites(m_name);
106         this->dying_scream(m_name);
107         this->change_virtue_non_beginner();
108         this->change_virtue_unique();
109         if (m_ptr->r_idx == MON_BEGGAR || m_ptr->r_idx == MON_LEPER) {
110             chg_virtue(this->target_ptr, V_COMPASSION, -1);
111         }
112
113         this->change_virtue_good_evil();
114         if (any_bits(r_ptr->flags3, RF3_UNDEAD) && any_bits(r_ptr->flags1, RF1_UNIQUE)) {
115             chg_virtue(this->target_ptr, V_VITALITY, 2);
116         }
117
118         this->change_virtue_revenge();
119         if (any_bits(r_ptr->flags2, RF2_MULTIPLY) && (r_ptr->r_akills > 1000) && one_in_(10)) {
120             chg_virtue(this->target_ptr, V_VALOUR, -1);
121         }
122
123         this->change_virtue_wild_thief();
124         auto magic_ability_flags = r_ptr->ability_flags;
125         magic_ability_flags.reset(RF_ABILITY_NOMAGIC_MASK);
126         if (any_bits(r_ptr->flags3, RF3_ANIMAL) && none_bits(r_ptr->flags3, RF3_EVIL) && magic_ability_flags.none()) {
127             if (one_in_(4)) {
128                 chg_virtue(this->target_ptr, V_NATURE, -1);
129             }
130         }
131
132         if (any_bits(r_ptr->flags1, RF1_UNIQUE) && record_destroy_uniq) {
133             char note_buf[160];
134             sprintf(note_buf, "%s%s", r_ptr->name.c_str(), m_ptr->mflag2.has(MFLAG2::CLONED) ? _("(クローン)", "(Clone)") : "");
135             exe_write_diary(this->target_ptr, DIARY_UNIQUE, 0, note_buf);
136         }
137
138         sound(SOUND_KILL);
139         if (note != nullptr) {
140             msg_format("%^s%s", m_name, note);
141         } else if (!m_ptr->ml) {
142             auto mes = is_echizen(this->target_ptr) ? _("せっかくだから%sを殺した。", "Because it's time, you have killed %s.")
143                                                     : _("%sを殺した。", "You have killed %s.");
144             msg_format(mes, m_name);
145         } else if (!monster_living(m_ptr->r_idx)) {
146             bool explode = false;
147             for (auto i = 0; i < 4; i++) {
148                 if (r_ptr->blow[i].method == RBM_EXPLODE) {
149                     explode = true;
150                 }
151             }
152
153             if (explode) {
154                 msg_format(_("%sは爆発して粉々になった。", "%^s explodes into tiny shreds."), m_name);
155             } else {
156                 auto mes = is_echizen(this->target_ptr) ? _("せっかくだから%sを殺した。", "Because it's time, you have destroyed %s.")
157                                                         : _("%sを殺した。", "You have destoryed %s.");
158                 msg_format(mes, m_name);
159             }
160         } else {
161             auto mes = is_echizen(this->target_ptr) ? _("せっかくだから%sを殺した。", "Because it's time, you have slained %s.")
162                                                     : _("%sを殺した。", "You have slained %s.");
163             msg_format(mes, m_name);
164         }
165
166         if (any_bits(r_ptr->flags1, RF1_UNIQUE) && m_ptr->mflag2.has_not(MFLAG2::CLONED) && !vanilla_town) {
167             for (auto i = 0; i < MAX_BOUNTY; i++) {
168                 if ((current_world_ptr->bounty_r_idx[i] == m_ptr->r_idx) && m_ptr->mflag2.has_not(MFLAG2::CHAMELEON)) {
169                     msg_format(_("%sの首には賞金がかかっている。", "There is a price on %s's head."), m_name);
170                     break;
171                 }
172             }
173         }
174
175         monster_death(this->target_ptr, this->m_idx, true);
176         this->summon_special_unique();
177         this->get_exp_from_mon(&exp_mon, exp_mon.max_maxhp * 2);
178         *this->fear = false;
179         return true;
180     }
181
182     if (monster_fear_remaining(m_ptr) && (this->dam > 0)) {
183         auto fear_remining = monster_fear_remaining(m_ptr) - randint1(this->dam);
184         if (set_monster_monfear(this->target_ptr, this->m_idx, fear_remining)) {
185             *this->fear = false;
186         }
187     }
188
189     // 恐怖の更なる加算.
190     if (!monster_fear_remaining(m_ptr) && none_bits(r_ptr->flags3, RF3_NO_FEAR)) {
191         int percentage = (100L * m_ptr->hp) / m_ptr->maxhp;
192         if ((randint1(10) >= percentage) || ((this->dam >= m_ptr->hp) && (randint0(100) < 80))) {
193             *this->fear = true;
194             (void)set_monster_monfear(
195                 this->target_ptr, this->m_idx, (randint1(10) + (((this->dam >= m_ptr->hp) && (percentage > 7)) ? 20 : ((11 - percentage) * 5))));
196         }
197     }
198
199     return false;
200 }
201
202 bool MonsterDamageProcessor::genocide_chaos_patron()
203 {
204     auto *m_ptr = &this->target_ptr->current_floor_ptr->m_list[this->m_idx];
205     if (!monster_is_valid(m_ptr)) {
206         this->m_idx = 0;
207     }
208
209     this->set_redraw();
210     (void)set_monster_csleep(this->target_ptr, this->m_idx, 0);
211     if (this->target_ptr->special_defense & NINJA_S_STEALTH) {
212         set_superstealth(this->target_ptr, false);
213     }
214
215     return this->m_idx == 0;
216 }
217
218 /*
219  * @brief たぬき、カメレオン、ナズグル、ユニークの死亡時処理
220  * @param m_ptr ダメージを与えたモンスターの構造体参照ポインタ
221  */
222 void MonsterDamageProcessor::death_special_flag_monster()
223 {
224     auto *m_ptr = &this->target_ptr->current_floor_ptr->m_list[this->m_idx];
225     auto r_idx = m_ptr->r_idx;
226     auto *r_ptr = &r_info[r_idx];
227     if (any_bits(r_info[r_idx].flags7, RF7_TANUKI)) {
228         r_ptr = &r_info[r_idx];
229         m_ptr->ap_r_idx = r_idx;
230         if (r_ptr->r_sights < MAX_SHORT) {
231             r_ptr->r_sights++;
232         }
233     }
234
235     if (m_ptr->mflag2.has(MFLAG2::CHAMELEON)) {
236         r_ptr = real_r_ptr(m_ptr);
237         if (r_ptr->r_sights < MAX_SHORT) {
238             r_ptr->r_sights++;
239         }
240     }
241
242     if (m_ptr->mflag2.has(MFLAG2::CLONED)) {
243         return;
244     }
245
246     if (any_bits(r_ptr->flags7, RF7_NAZGUL)) {
247         r_ptr->max_num--;
248         return;
249     }
250
251     if (none_bits(r_ptr->flags1, RF1_UNIQUE)) {
252         return;
253     }
254
255     this->death_unique_monster((monster_race_type)r_idx);
256 }
257
258 /*
259  * @brief ユニークの死亡処理
260  * @param r_idx 死亡したユニークの種族番号
261  */
262 void MonsterDamageProcessor::death_unique_monster(monster_race_type r_idx)
263 {
264     r_info[r_idx].max_num = 0;
265     std::vector<monster_race_type> combined_uniques;
266     if (!check_combined_unique(r_idx, &combined_uniques)) {
267         return;
268     }
269
270     std::vector<std::tuple<monster_race_type, monster_race_type, monster_race_type>> uniques;
271     const int one_unit = 3;
272     for (auto i = 0U; i < combined_uniques.size(); i += one_unit) {
273         auto unique = std::make_tuple(combined_uniques[i], combined_uniques[i + 1], combined_uniques[i + 2]);
274         uniques.push_back(unique);
275     }
276
277     this->death_combined_uniques(r_idx, &uniques);
278 }
279
280 /*
281  * @brief 死亡したモンスターが分裂/合体を行う特殊ユニークか否かの判定処理
282  * @param r_idx 死亡したモンスターの種族番号
283  * @param united_uniques 分裂/合体を行う特殊ユニーク
284  * @details 合体後、合体前1、合体前2 の順にpush_backすること
285  */
286 bool MonsterDamageProcessor::check_combined_unique(const monster_race_type r_idx, std::vector<monster_race_type> *combined_uniques)
287 {
288     combined_uniques->push_back(MON_BANORLUPART);
289     combined_uniques->push_back(MON_BANOR);
290     combined_uniques->push_back(MON_LUPART);
291
292     for (const auto &unique : *combined_uniques) {
293         if (r_idx == unique) {
294             return true;
295         }
296     }
297
298     return false;
299 }
300
301 /*
302  * @brief 分裂/合体を行う特殊ユニークの死亡処理
303  * @param m_ptr ダメージを与えたモンスターの構造体参照ポインタ
304  * @uniques 分裂/合体を行う特殊ユニークのリスト
305  */
306 void MonsterDamageProcessor::death_combined_uniques(
307     const monster_race_type r_idx, std::vector<std::tuple<monster_race_type, monster_race_type, monster_race_type>> *combined_uniques)
308 {
309     for (const auto &unique : *combined_uniques) {
310         auto united = (monster_race_type)0;
311         auto split1 = (monster_race_type)0;
312         auto split2 = (monster_race_type)0;
313         std::tie(united, split1, split2) = unique;
314         if ((r_idx == split1) || (r_idx == split2)) {
315             r_info[united].max_num = 0;
316             r_info[united].r_pkills++;
317             r_info[united].r_akills++;
318             if (r_info[united].r_tkills < MAX_SHORT) {
319                 r_info[united].r_tkills++;
320             }
321
322             continue;
323         }
324
325         if (r_idx != united) {
326             continue;
327         }
328
329         r_info[split1].max_num = 0;
330         r_info[split1].r_pkills++;
331         r_info[split1].r_akills++;
332         if (r_info[split1].r_tkills < MAX_SHORT) {
333             r_info[split1].r_tkills++;
334         }
335
336         r_info[split2].max_num = 0;
337         r_info[split2].r_pkills++;
338         r_info[split2].r_akills++;
339         if (r_info[split2].r_tkills < MAX_SHORT) {
340             r_info[split2].r_tkills++;
341         }
342     }
343 }
344
345 void MonsterDamageProcessor::increase_kill_numbers()
346 {
347     auto *m_ptr = &this->target_ptr->current_floor_ptr->m_list[this->m_idx];
348     auto *r_ptr = &r_info[m_ptr->r_idx];
349     if (((m_ptr->ml == 0) || this->target_ptr->image) && none_bits(r_ptr->flags1, RF1_UNIQUE)) {
350         return;
351     }
352
353     if (m_ptr->mflag2.has(MFLAG2::KAGE) && (r_info[MON_KAGE].r_pkills < MAX_SHORT)) {
354         r_info[MON_KAGE].r_pkills++;
355     } else if (r_ptr->r_pkills < MAX_SHORT) {
356         r_ptr->r_pkills++;
357     }
358
359     if (m_ptr->mflag2.has(MFLAG2::KAGE) && (r_info[MON_KAGE].r_tkills < MAX_SHORT)) {
360         r_info[MON_KAGE].r_tkills++;
361     } else if (r_ptr->r_tkills < MAX_SHORT) {
362         r_ptr->r_tkills++;
363     }
364
365     monster_race_track(this->target_ptr, m_ptr->ap_r_idx);
366 }
367
368 void MonsterDamageProcessor::death_amberites(GAME_TEXT *m_name)
369 {
370     auto *m_ptr = &this->target_ptr->current_floor_ptr->m_list[this->m_idx];
371     auto *r_ptr = &r_info[m_ptr->r_idx];
372     if (none_bits(r_ptr->flags3, RF3_AMBERITE) || one_in_(2)) {
373         return;
374     }
375
376     auto curses = 1 + randint1(3);
377     auto stop_ty = false;
378     auto count = 0;
379     msg_format(_("%^sは恐ろしい血の呪いをあなたにかけた!", "%^s puts a terrible blood curse on you!"), m_name);
380     curse_equipment(this->target_ptr, 100, 50);
381     do {
382         stop_ty = activate_ty_curse(this->target_ptr, stop_ty, &count);
383     } while (--curses);
384 }
385
386 void MonsterDamageProcessor::dying_scream(GAME_TEXT *m_name)
387 {
388     auto *m_ptr = &this->target_ptr->current_floor_ptr->m_list[this->m_idx];
389     auto *r_ptr = &r_info[m_ptr->r_idx];
390     if (none_bits(r_ptr->flags2, RF2_CAN_SPEAK)) {
391         return;
392     }
393
394     char line_got[1024];
395     if (!get_rnd_line(_("mondeath_j.txt", "mondeath.txt"), m_ptr->r_idx, line_got)) {
396         msg_format("%^s %s", m_name, line_got);
397     }
398
399 #ifdef WORLD_SCORE
400     if (m_ptr->r_idx == MON_SERPENT) {
401         screen_dump = make_screen_dump(this->target_ptr);
402     }
403 #endif
404 }
405
406 void MonsterDamageProcessor::change_virtue_non_beginner()
407 {
408     auto *floor_ptr = this->target_ptr->current_floor_ptr;
409     auto *m_ptr = &floor_ptr->m_list[this->m_idx];
410     auto *r_ptr = &r_info[m_ptr->r_idx];
411     if (d_info[this->target_ptr->dungeon_idx].flags.has(DF::BEGINNER)) {
412         return;
413     }
414
415     if ((floor_ptr->dun_level == 0) && !this->target_ptr->ambush_flag && !floor_ptr->inside_arena) {
416         chg_virtue(this->target_ptr, V_VALOUR, -1);
417     } else if (r_ptr->level > floor_ptr->dun_level) {
418         if (randint1(10) <= (r_ptr->level - floor_ptr->dun_level)) {
419             chg_virtue(this->target_ptr, V_VALOUR, 1);
420         }
421     }
422
423     if (r_ptr->level > 60) {
424         chg_virtue(this->target_ptr, V_VALOUR, 1);
425     }
426
427     if (r_ptr->level >= 2 * (this->target_ptr->lev + 1)) {
428         chg_virtue(this->target_ptr, V_VALOUR, 2);
429     }
430 }
431
432 void MonsterDamageProcessor::change_virtue_unique()
433 {
434     auto *floor_ptr = this->target_ptr->current_floor_ptr;
435     auto *m_ptr = &floor_ptr->m_list[this->m_idx];
436     auto *r_ptr = &r_info[m_ptr->r_idx];
437     if (none_bits(r_ptr->flags1, RF1_UNIQUE)) {
438         return;
439     }
440
441     if (any_bits(r_ptr->flags3, RF3_EVIL | RF3_GOOD)) {
442         chg_virtue(this->target_ptr, V_HARMONY, 2);
443     }
444
445     if (any_bits(r_ptr->flags3, RF3_GOOD)) {
446         chg_virtue(this->target_ptr, V_UNLIFE, 2);
447         chg_virtue(this->target_ptr, V_VITALITY, -2);
448     }
449
450     if (one_in_(3)) {
451         chg_virtue(this->target_ptr, V_INDIVIDUALISM, -1);
452     }
453 }
454
455 /*
456  * @brief 攻撃を与えたモンスターが天使か悪魔だった場合、徳を変化させる
457  * @details 天使かつ悪魔だった場合、天使であることが優先される
458  */
459 void MonsterDamageProcessor::change_virtue_good_evil()
460 {
461     auto *floor_ptr = this->target_ptr->current_floor_ptr;
462     auto *m_ptr = &floor_ptr->m_list[this->m_idx];
463     auto *r_ptr = &r_info[m_ptr->r_idx];
464     if (any_bits(r_ptr->flags3, RF3_GOOD) && ((r_ptr->level) / 10 + (3 * floor_ptr->dun_level) >= randint1(100))) {
465         chg_virtue(this->target_ptr, V_UNLIFE, 1);
466     }
467
468     if (any_bits(r_ptr->flags3, RF3_ANGEL)) {
469         if (any_bits(r_ptr->flags1, RF1_UNIQUE)) {
470             chg_virtue(this->target_ptr, V_FAITH, -2);
471         } else if ((r_ptr->level) / 10 + (3 * floor_ptr->dun_level) >= randint1(100)) {
472             auto change_value = any_bits(r_ptr->flags3, RF3_GOOD) ? -1 : 1;
473             chg_virtue(this->target_ptr, V_FAITH, change_value);
474         }
475
476         return;
477     }
478
479     if (any_bits(r_ptr->flags3, RF3_DEMON)) {
480         if (any_bits(r_ptr->flags1, RF1_UNIQUE)) {
481             chg_virtue(this->target_ptr, V_FAITH, 2);
482         } else if ((r_ptr->level) / 10 + (3 * floor_ptr->dun_level) >= randint1(100)) {
483             chg_virtue(this->target_ptr, V_FAITH, 1);
484         }
485     }
486 }
487
488 /*
489  * @brief 過去に@を殺したことがあるユニークにリゾンべを果たせたら徳を上げる
490  */
491 void MonsterDamageProcessor::change_virtue_revenge()
492 {
493     auto *floor_ptr = this->target_ptr->current_floor_ptr;
494     auto *m_ptr = &floor_ptr->m_list[this->m_idx];
495     auto *r_ptr = &r_info[m_ptr->r_idx];
496     if (r_ptr->r_deaths == 0) {
497         return;
498     }
499
500     if (any_bits(r_ptr->flags1, RF1_UNIQUE)) {
501         chg_virtue(this->target_ptr, V_HONOUR, 10);
502         return;
503     }
504
505     if ((r_ptr->level) / 10 + (2 * floor_ptr->dun_level) >= randint1(100)) {
506         chg_virtue(this->target_ptr, V_HONOUR, 1);
507     }
508 }
509
510 /*
511  * @brief 盗み逃げをするモンスター及び地上のモンスターを攻撃した際に徳を変化させる
512  */
513 void MonsterDamageProcessor::change_virtue_wild_thief()
514 {
515     auto *floor_ptr = this->target_ptr->current_floor_ptr;
516     auto *m_ptr = &floor_ptr->m_list[this->m_idx];
517     auto *r_ptr = &r_info[m_ptr->r_idx];
518     auto innocent = true;
519     auto thief = false;
520     for (auto i = 0; i < MAX_NUM_BLOWS; i++) {
521         if (r_ptr->blow[i].d_dice != 0) {
522             innocent = false;
523         }
524
525         if ((r_ptr->blow[i].effect == RBE_EAT_ITEM) || (r_ptr->blow[i].effect == RBE_EAT_GOLD)) {
526             thief = true;
527         }
528     }
529
530     if (r_ptr->level > 0) {
531         innocent = false;
532     }
533
534     if (thief) {
535         if (any_bits(r_ptr->flags1, RF1_UNIQUE)) {
536             chg_virtue(this->target_ptr, V_JUSTICE, 3);
537             return;
538         }
539         
540         if (1 + ((r_ptr->level) / 10 + (2 * floor_ptr->dun_level)) >= randint1(100)) {
541             chg_virtue(this->target_ptr, V_JUSTICE, 1);
542         }
543
544         return;
545     }
546     
547     if (innocent) {
548         chg_virtue(this->target_ptr, V_JUSTICE, -1);
549     }
550 }
551
552 /*!
553  * @brief モンスターに与えたダメージを元に経験値を加算する /
554  * Calculate experience point to be get
555  * @param m_ptr ダメージを与えたモンスターの構造体参照ポインタ
556  * @details
557  * <pre>
558  * Even the 64 bit operation is not big enough to avoid overflaw
559  * unless we carefully choose orders of ENERGY_MULTIPLICATION and ENERGY_DIVISION.
560  * Get the coefficient first, and multiply (potentially huge) base
561  * experience point of a monster later.
562  * </pre>
563  */
564 void MonsterDamageProcessor::get_exp_from_mon(monster_type *m_ptr, HIT_POINT exp_dam)
565 {
566     auto *r_ptr = &r_info[m_ptr->r_idx];
567     if (!monster_is_valid(m_ptr) || is_pet(m_ptr) || this->target_ptr->phase_out) {
568         return;
569     }
570
571     /*
572      * - Ratio of monster's level to player's level effects
573      * - Varying speed effects
574      * - Get a fraction in proportion of damage point
575      */
576     auto new_exp = r_ptr->level * SPEED_TO_ENERGY(m_ptr->mspeed) * exp_dam;
577     auto new_exp_frac = 0U;
578     auto div_h = 0;
579     auto div_l = (uint)((this->target_ptr->max_plv + 2) * SPEED_TO_ENERGY(r_ptr->speed));
580
581     /* Use (average maxhp * 2) as a denominator */
582     auto compensation = any_bits(r_ptr->flags1, RF1_FORCE_MAXHP) ? r_ptr->hside * 2 : r_ptr->hside + 1;
583     s64b_mul(&div_h, &div_l, 0, r_ptr->hdice * (ironman_nightmare ? 2 : 1) * compensation);
584
585     /* Special penalty in the wilderness */
586     if (!this->target_ptr->current_floor_ptr->dun_level && (none_bits(r_ptr->flags8, RF8_WILD_ONLY) || none_bits(r_ptr->flags1, RF1_UNIQUE))) {
587         s64b_mul(&div_h, &div_l, 0, 5);
588     }
589
590     /* Do ENERGY_DIVISION first to prevent overflaw */
591     s64b_div(&new_exp, &new_exp_frac, div_h, div_l);
592
593     /* Special penalty for mutiply-monster */
594     if (any_bits(r_ptr->flags2, RF2_MULTIPLY) || (m_ptr->r_idx == MON_DAWN)) {
595         int monnum_penarty = r_ptr->r_akills / 400;
596         if (monnum_penarty > 8) {
597             monnum_penarty = 8;
598         }
599
600         while (monnum_penarty--) {
601             /* Divide by 4 */
602             s64b_rshift(&new_exp, &new_exp_frac, 2);
603         }
604     }
605
606     /* Special penalty for rest_and_shoot exp scum */
607     if ((m_ptr->dealt_damage > m_ptr->max_maxhp) && (m_ptr->hp >= 0)) {
608         int over_damage = m_ptr->dealt_damage / m_ptr->max_maxhp;
609         if (over_damage > 32) {
610             over_damage = 32;
611         }
612
613         while (over_damage--) {
614             /* 9/10 for once */
615             s64b_mul(&new_exp, &new_exp_frac, 0, 9);
616             s64b_div(&new_exp, &new_exp_frac, 0, 10);
617         }
618     }
619
620     s64b_mul(&new_exp, &new_exp_frac, 0, r_ptr->mexp);
621     gain_exp_64(this->target_ptr, new_exp, new_exp_frac);
622 }
623
624 void MonsterDamageProcessor::set_redraw()
625 {
626     if (this->target_ptr->health_who == this->m_idx) {
627         this->target_ptr->redraw |= PR_HEALTH;
628     }
629
630     if (this->target_ptr->riding == this->m_idx) {
631         this->target_ptr->redraw |= PR_UHEALTH;
632     }
633 }
634
635 /*
636  * @brief 特定ユニークを倒した時に更にユニークを特殊召喚する処理
637  * @param m_ptr ダメージを与えた特定ユニークの構造体参照ポインタ
638  */
639 void MonsterDamageProcessor::summon_special_unique()
640 {
641     auto *m_ptr = &this->target_ptr->current_floor_ptr->m_list[this->m_idx];
642     auto *r_ptr = &r_info[m_ptr->r_idx];
643     bool is_special_summon = m_ptr->r_idx == MON_IKETA;
644     is_special_summon |= m_ptr->r_idx == MON_DOPPIO;
645     if (!is_special_summon || this->target_ptr->current_floor_ptr->inside_arena || this->target_ptr->phase_out) {
646         delete_monster_idx(this->target_ptr, this->m_idx);
647         return;
648     }
649
650     auto dummy_y = m_ptr->fy;
651     auto dummy_x = m_ptr->fx;
652     auto mode = (BIT_FLAGS)0;
653     if (is_pet(m_ptr)) {
654         mode |= PM_FORCE_PET;
655     }
656
657     MONRACE_IDX new_unique_idx;
658     concptr mes;
659     switch (m_ptr->r_idx) {
660     case MON_IKETA:
661         new_unique_idx = MON_BIKETAL;
662         mes = _("「ハァッハッハッハ!!私がバイケタルだ!!」", "Uwa-hahaha!  *I* am Biketal!");
663         break;
664     case MON_DOPPIO:
665         new_unique_idx = MON_DIAVOLO;
666         mes = _("「これは『試練』だ 過去に打ち勝てという『試練』とオレは受けとった」", "This is a 'trial'. I took it as a 'trial' to overcome in the past.");
667         break;
668     default: // バグでなければ入らない.
669         new_unique_idx = 0;
670         mes = "";
671         break;
672     }
673
674     delete_monster_idx(this->target_ptr, this->m_idx);
675     if (summon_named_creature(this->target_ptr, 0, dummy_y, dummy_x, new_unique_idx, mode)) {
676         msg_print(mes);
677     }
678 }