OSDN Git Service

[Refactor] message_pain 関数を MonsterPainDescriber で置き換える
authorHabu <habu1010+github@gmail.com>
Wed, 28 Dec 2022 12:52:27 +0000 (21:52 +0900)
committerHabu <habu1010+github@gmail.com>
Wed, 28 Dec 2022 13:03:25 +0000 (22:03 +0900)
src/combat/shoot.cpp
src/effect/effect-monster.cpp
src/monster/monster-describer.cpp
src/monster/monster-describer.h
src/object-use/throw-execution.cpp

index b118c9b..31a8060 100644 (file)
@@ -40,6 +40,7 @@
 #include "monster/monster-damage.h"
 #include "monster/monster-describer.h"
 #include "monster/monster-info.h"
+#include "monster/monster-pain-describer.h"
 #include "monster/monster-status-setter.h"
 #include "monster/monster-status.h"
 #include "monster/monster-update.h"
@@ -861,7 +862,10 @@ void exe_fire(PlayerType *player_ptr, INVENTORY_IDX item, ItemEntity *j_ptr, SPE
                             msg_format(_("%sは%sに突き刺さった!", "%^s is stuck in %s!"), o_name, m_name.data());
                         }
 
-                        message_pain(player_ptr, c_mon_ptr->m_idx, tdam);
+                        if (const auto pain_message = MonsterPainDescriber(player_ptr, c_mon_ptr->m_idx).describe(tdam);
+                            !pain_message.empty()) {
+                            msg_print(pain_message);
+                        }
 
                         /* Anger the monster */
                         if (tdam > 0) {
index 81481b6..f497e33 100644 (file)
@@ -36,6 +36,7 @@
 #include "monster/monster-describer.h"
 #include "monster/monster-description-types.h"
 #include "monster/monster-info.h"
+#include "monster/monster-pain-describer.h"
 #include "monster/monster-status-setter.h"
 #include "monster/monster-status.h"
 #include "monster/monster-update.h"
@@ -211,7 +212,10 @@ static void effect_damage_makes_sleep(PlayerType *player_ptr, effect_monster_typ
     if (em_ptr->note && em_ptr->seen_msg) {
         msg_format("%^s%s", em_ptr->m_name, em_ptr->note);
     } else if (em_ptr->see_s_msg) {
-        message_pain(player_ptr, em_ptr->g_ptr->m_idx, em_ptr->dam);
+        const auto pain_message = MonsterPainDescriber(player_ptr, em_ptr->g_ptr->m_idx).describe(em_ptr->dam);
+        if (!pain_message.empty()) {
+            msg_print(pain_message);
+        }
     } else {
         player_ptr->current_floor_ptr->monster_noise = true;
     }
@@ -301,7 +305,10 @@ static bool deal_effect_damage_from_player(PlayerType *player_ptr, effect_monste
     if (em_ptr->note && em_ptr->seen) {
         msg_format(_("%s%s", "%^s%s"), em_ptr->m_name, em_ptr->note);
     } else if (em_ptr->known && (em_ptr->dam || !em_ptr->do_fear)) {
-        message_pain(player_ptr, em_ptr->g_ptr->m_idx, em_ptr->dam);
+        const auto pain_message = MonsterPainDescriber(player_ptr, em_ptr->g_ptr->m_idx).describe(em_ptr->dam);
+        if (!pain_message.empty()) {
+            msg_print(pain_message);
+        }
     }
 
     if (((em_ptr->dam > 0) || em_ptr->get_angry) && !em_ptr->do_sleep) {
index 5902856..de92ef4 100644 (file)
@@ -273,294 +273,3 @@ std::string monster_desc(PlayerType *player_ptr, const MonsterEntity *m_ptr, BIT
 
     return ss.str();
 }
-
-/*!
- * @brief ダメージを受けたモンスターの様子を記述する / Dump a message describing a monster's reaction to damage
- * @param player_ptr プレイヤーへの参照ポインタ
- * @param m_idx モンスター情報ID
- * @param dam 与えたダメージ
- * @details
- * Technically should attempt to treat "Beholder"'s as jelly's
- */
-void message_pain(PlayerType *player_ptr, MONSTER_IDX m_idx, int dam)
-{
-    auto *m_ptr = &player_ptr->current_floor_ptr->m_list[m_idx];
-    auto *r_ptr = &monraces_info[m_ptr->r_idx];
-
-    const auto m_name = monster_desc(player_ptr, m_ptr, 0);
-
-    if (dam == 0) {
-        if (m_ptr->ml) {
-            msg_format(_("%^sはダメージを受けていない。", "%^s is unharmed."), m_name.data());
-        }
-        return;
-    }
-
-    int newhp = m_ptr->hp;
-    int oldhp = newhp + dam;
-    int tmp = (newhp * 100L) / oldhp;
-    PERCENTAGE percentage = tmp;
-
-    if (angband_strchr(",ejmvwQ", r_ptr->d_char)) {
-        if (percentage > 95) {
-            msg_format(_("%^sはほとんど気にとめていない。", "%^s barely notices."), m_name.data());
-        } else if (percentage > 75) {
-            msg_format(_("%^sはしり込みした。", "%^s flinches."), m_name.data());
-        } else if (percentage > 50) {
-            msg_format(_("%^sは縮こまった。", "%^s squelches."), m_name.data());
-        } else if (percentage > 35) {
-            msg_format(_("%^sは痛みに震えた。", "%^s quivers in pain."), m_name.data());
-        } else if (percentage > 20) {
-            msg_format(_("%^sは身もだえした。", "%^s writhes about."), m_name.data());
-        } else if (percentage > 10) {
-            msg_format(_("%^sは苦痛で身もだえした。", "%^s writhes in agony."), m_name.data());
-        } else {
-            msg_format(_("%^sはぐにゃぐにゃと痙攣した。", "%^s jerks limply."), m_name.data());
-        }
-        return;
-    }
-
-    if (angband_strchr("l", r_ptr->d_char)) {
-        if (percentage > 95) {
-            msg_format(_("%^sはほとんど気にとめていない。", "%^s barely notices."), m_name.data());
-        } else if (percentage > 75) {
-            msg_format(_("%^sはしり込みした。", "%^s flinches."), m_name.data());
-        } else if (percentage > 50) {
-            msg_format(_("%^sは躊躇した。", "%^s hesitates."), m_name.data());
-        } else if (percentage > 35) {
-            msg_format(_("%^sは痛みに震えた。", "%^s quivers in pain."), m_name.data());
-        } else if (percentage > 20) {
-            msg_format(_("%^sは身もだえした。", "%^s writhes about."), m_name.data());
-        } else if (percentage > 10) {
-            msg_format(_("%^sは苦痛で身もだえした。", "%^s writhes in agony."), m_name.data());
-        } else {
-            msg_format(_("%^sはぐにゃぐにゃと痙攣した。", "%^s jerks limply."), m_name.data());
-        }
-        return;
-    }
-
-    if (angband_strchr("g#+<>", r_ptr->d_char)) {
-        if (percentage > 95) {
-            msg_format(_("%sは攻撃を気にとめていない。", "%^s ignores the attack."), m_name.data());
-        } else if (percentage > 75) {
-            msg_format(_("%sは攻撃に肩をすくめた。", "%^s shrugs off the attack."), m_name.data());
-        } else if (percentage > 50) {
-            msg_format(_("%^sは雷鳴のように吠えた。", "%^s roars thunderously."), m_name.data());
-        } else if (percentage > 35) {
-            msg_format(_("%^sは苦しげに吠えた。", "%^s rumbles."), m_name.data());
-        } else if (percentage > 20) {
-            msg_format(_("%^sはうめいた。", "%^s grunts."), m_name.data());
-        } else if (percentage > 10) {
-            msg_format(_("%^sは躊躇した。", "%^s hesitates."), m_name.data());
-        } else {
-            msg_format(_("%^sはくしゃくしゃになった。", "%^s crumples."), m_name.data());
-        }
-        return;
-    }
-
-    if (angband_strchr("JMR", r_ptr->d_char) || !isalpha(r_ptr->d_char)) {
-        if (percentage > 95) {
-            msg_format(_("%^sはほとんど気にとめていない。", "%^s barely notices."), m_name.data());
-        } else if (percentage > 75) {
-            msg_format(_("%^sはシーッと鳴いた。", "%^s hisses."), m_name.data());
-        } else if (percentage > 50) {
-            msg_format(_("%^sは怒って頭を上げた。", "%^s rears up in anger."), m_name.data());
-        } else if (percentage > 35) {
-            msg_format(_("%^sは猛然と威嚇した。", "%^s hisses furiously."), m_name.data());
-        } else if (percentage > 20) {
-            msg_format(_("%^sは身もだえした。", "%^s writhes about."), m_name.data());
-        } else if (percentage > 10) {
-            msg_format(_("%^sは苦痛で身もだえした。", "%^s writhes in agony."), m_name.data());
-        } else {
-            msg_format(_("%^sはぐにゃぐにゃと痙攣した。", "%^s jerks limply."), m_name.data());
-        }
-        return;
-    }
-
-    if (angband_strchr("f", r_ptr->d_char)) {
-        if (percentage > 95) {
-            msg_format(_("%sは攻撃に肩をすくめた。", "%^s shrugs off the attack."), m_name.data());
-        } else if (percentage > 75) {
-            msg_format(_("%^sは吠えた。", "%^s roars."), m_name.data());
-        } else if (percentage > 50) {
-            msg_format(_("%^sは怒って吠えた。", "%^s growls angrily."), m_name.data());
-        } else if (percentage > 35) {
-            msg_format(_("%^sは痛みでシーッと鳴いた。", "%^s hisses with pain."), m_name.data());
-        } else if (percentage > 20) {
-            msg_format(_("%^sは痛みで弱々しく鳴いた。", "%^s mewls in pain."), m_name.data());
-        } else if (percentage > 10) {
-            msg_format(_("%^sは苦痛にうめいた。", "%^s hisses in agony."), m_name.data());
-        } else {
-            msg_format(_("%sは哀れな鳴き声を出した。", "%^s mewls pitifully."), m_name.data());
-        }
-        return;
-    }
-
-    if (angband_strchr("acFIKS", r_ptr->d_char)) {
-        if (percentage > 95) {
-            msg_format(_("%sは攻撃を気にとめていない。", "%^s ignores the attack."), m_name.data());
-        } else if (percentage > 75) {
-            msg_format(_("%^sはキーキー鳴いた。", "%^s chitters."), m_name.data());
-        } else if (percentage > 50) {
-            msg_format(_("%^sはヨロヨロ逃げ回った。", "%^s scuttles about."), m_name.data());
-        } else if (percentage > 35) {
-            msg_format(_("%^sはうるさく鳴いた。", "%^s twitters."), m_name.data());
-        } else if (percentage > 20) {
-            msg_format(_("%^sは痛みに痙攣した。", "%^s jerks in pain."), m_name.data());
-        } else if (percentage > 10) {
-            msg_format(_("%^sは苦痛で痙攣した。", "%^s jerks in agony."), m_name.data());
-        } else {
-            msg_format(_("%^sはピクピクひきつった。", "%^s twitches."), m_name.data());
-        }
-        return;
-    }
-
-    if (angband_strchr("B", r_ptr->d_char)) {
-        if (percentage > 95) {
-            msg_format(_("%^sはさえずった。", "%^s chirps."), m_name.data());
-        } else if (percentage > 75) {
-            msg_format(_("%^sはピーピー鳴いた。", "%^s twitters."), m_name.data());
-        } else if (percentage > 50) {
-            msg_format(_("%^sはギャーギャー鳴いた。", "%^s squawks."), m_name.data());
-        } else if (percentage > 35) {
-            msg_format(_("%^sはギャーギャー鳴きわめいた。", "%^s chatters."), m_name.data());
-        } else if (percentage > 20) {
-            msg_format(_("%^sは苦しんだ。", "%^s jeers."), m_name.data());
-        } else if (percentage > 10) {
-            msg_format(_("%^sはのたうち回った。", "%^s flutters about."), m_name.data());
-        } else {
-            msg_format(_("%^sはキーキーと鳴き叫んだ。", "%^s squeaks."), m_name.data());
-        }
-        return;
-    }
-
-    if (angband_strchr("duDLUW", r_ptr->d_char)) {
-        if (percentage > 95) {
-            msg_format(_("%sは攻撃を気にとめていない。", "%^s ignores the attack."), m_name.data());
-        } else if (percentage > 75) {
-            msg_format(_("%^sはしり込みした。", "%^s flinches."), m_name.data());
-        } else if (percentage > 50) {
-            msg_format(_("%^sは痛みでシーッと鳴いた。", "%^s hisses in pain."), m_name.data());
-        } else if (percentage > 35) {
-            msg_format(_("%^sは痛みでうなった。", "%^s snarls with pain."), m_name.data());
-        } else if (percentage > 20) {
-            msg_format(_("%^sは痛みに吠えた。", "%^s roars with pain."), m_name.data());
-        } else if (percentage > 10) {
-            msg_format(_("%^sは苦しげに叫んだ。", "%^s gasps."), m_name.data());
-        } else {
-            msg_format(_("%^sは弱々しくうなった。", "%^s snarls feebly."), m_name.data());
-        }
-        return;
-    }
-
-    if (angband_strchr("s", r_ptr->d_char)) {
-        if (percentage > 95) {
-            msg_format(_("%sは攻撃を気にとめていない。", "%^s ignores the attack."), m_name.data());
-        } else if (percentage > 75) {
-            msg_format(_("%sは攻撃に肩をすくめた。", "%^s shrugs off the attack."), m_name.data());
-        } else if (percentage > 50) {
-            msg_format(_("%^sはカタカタと笑った。", "%^s rattles."), m_name.data());
-        } else if (percentage > 35) {
-            msg_format(_("%^sはよろめいた。", "%^s stumbles."), m_name.data());
-        } else if (percentage > 20) {
-            msg_format(_("%^sはカタカタ言った。", "%^s rattles."), m_name.data());
-        } else if (percentage > 10) {
-            msg_format(_("%^sはよろめいた。", "%^s staggers."), m_name.data());
-        } else {
-            msg_format(_("%^sはガタガタ言った。", "%^s clatters."), m_name.data());
-        }
-        return;
-    }
-
-    if (angband_strchr("z", r_ptr->d_char)) {
-        if (percentage > 95) {
-            msg_format(_("%sは攻撃を気にとめていない。", "%^s ignores the attack."), m_name.data());
-        } else if (percentage > 75) {
-            msg_format(_("%sは攻撃に肩をすくめた。", "%^s shrugs off the attack."), m_name.data());
-        } else if (percentage > 50) {
-            msg_format(_("%^sはうめいた。", "%^s groans."), m_name.data());
-        } else if (percentage > 35) {
-            msg_format(_("%sは苦しげにうめいた。", "%^s moans."), m_name.data());
-        } else if (percentage > 20) {
-            msg_format(_("%^sは躊躇した。", "%^s hesitates."), m_name.data());
-        } else if (percentage > 10) {
-            msg_format(_("%^sはうなった。", "%^s grunts."), m_name.data());
-        } else {
-            msg_format(_("%^sはよろめいた。", "%^s staggers."), m_name.data());
-        }
-        return;
-    }
-
-    if (angband_strchr("G", r_ptr->d_char)) {
-        if (percentage > 95) {
-            msg_format(_("%sは攻撃を気にとめていない。", "%^s ignores the attack."), m_name.data());
-        } else if (percentage > 75) {
-            msg_format(_("%sは攻撃に肩をすくめた。", "%^s shrugs off the attack."), m_name.data());
-        } else if (percentage > 50) {
-            msg_format(_("%sはうめいた。", "%^s moans."), m_name.data());
-        } else if (percentage > 35) {
-            msg_format(_("%^sは泣きわめいた。", "%^s wails."), m_name.data());
-        } else if (percentage > 20) {
-            msg_format(_("%^sは吠えた。", "%^s howls."), m_name.data());
-        } else if (percentage > 10) {
-            msg_format(_("%sは弱々しくうめいた。", "%^s moans softly."), m_name.data());
-        } else {
-            msg_format(_("%^sはかすかにうめいた。", "%^s sighs."), m_name.data());
-        }
-        return;
-    }
-
-    if (angband_strchr("CZ", r_ptr->d_char)) {
-        if (percentage > 95) {
-            msg_format(_("%^sは攻撃に肩をすくめた。", "%^s shrugs off the attack."), m_name.data());
-        } else if (percentage > 75) {
-            msg_format(_("%^sは痛みでうなった。", "%^s snarls with pain."), m_name.data());
-        } else if (percentage > 50) {
-            msg_format(_("%^sは痛みでキャンキャン吠えた。", "%^s yelps in pain."), m_name.data());
-        } else if (percentage > 35) {
-            msg_format(_("%^sは痛みで鳴きわめいた。", "%^s howls in pain."), m_name.data());
-        } else if (percentage > 20) {
-            msg_format(_("%^sは苦痛のあまり鳴きわめいた。", "%^s howls in agony."), m_name.data());
-        } else if (percentage > 10) {
-            msg_format(_("%^sは苦痛でもだえ苦しんだ。", "%^s writhes in agony."), m_name.data());
-        } else {
-            msg_format(_("%^sは弱々しく吠えた。", "%^s yelps feebly."), m_name.data());
-        }
-        return;
-    }
-
-    if (angband_strchr("Xbilqrt", r_ptr->d_char)) {
-        if (percentage > 95) {
-            msg_format(_("%^sは攻撃を気にとめていない。", "%^s ignores the attack."), m_name.data());
-        } else if (percentage > 75) {
-            msg_format(_("%^sは痛みでうなった。", "%^s grunts with pain."), m_name.data());
-        } else if (percentage > 50) {
-            msg_format(_("%^sは痛みで叫んだ。", "%^s squeals in pain."), m_name.data());
-        } else if (percentage > 35) {
-            msg_format(_("%^sは痛みで絶叫した。", "%^s shrieks in pain."), m_name.data());
-        } else if (percentage > 20) {
-            msg_format(_("%^sは苦痛のあまり絶叫した。", "%^s shrieks in agony."), m_name.data());
-        } else if (percentage > 10) {
-            msg_format(_("%^sは苦痛でもだえ苦しんだ。", "%^s writhes in agony."), m_name.data());
-        } else {
-            msg_format(_("%^sは弱々しく叫んだ。", "%^s cries out feebly."), m_name.data());
-        }
-        return;
-    }
-
-    if (percentage > 95) {
-        msg_format(_("%^sは攻撃に肩をすくめた。", "%^s shrugs off the attack."), m_name.data());
-    } else if (percentage > 75) {
-        msg_format(_("%^sは痛みでうなった。", "%^s grunts with pain."), m_name.data());
-    } else if (percentage > 50) {
-        msg_format(_("%^sは痛みで叫んだ。", "%^s cries out in pain."), m_name.data());
-    } else if (percentage > 35) {
-        msg_format(_("%^sは痛みで絶叫した。", "%^s screams in pain."), m_name.data());
-    } else if (percentage > 20) {
-        msg_format(_("%^sは苦痛のあまり絶叫した。", "%^s screams in agony."), m_name.data());
-    } else if (percentage > 10) {
-        msg_format(_("%^sは苦痛でもだえ苦しんだ。", "%^s writhes in agony."), m_name.data());
-    } else {
-        msg_format(_("%^sは弱々しく叫んだ。", "%^s cries out feebly."), m_name.data());
-    }
-}
index e052dbe..bdf778f 100644 (file)
@@ -6,4 +6,3 @@
 class MonsterEntity;
 class PlayerType;
 std::string monster_desc(PlayerType *player_ptr, const MonsterEntity *m_ptr, BIT_FLAGS mode);
-void message_pain(PlayerType *player_ptr, MONSTER_IDX m_idx, int dam);
index d8f3bbe..6aecb0f 100644 (file)
@@ -36,6 +36,7 @@
 #include "monster/monster-damage.h"
 #include "monster/monster-describer.h"
 #include "monster/monster-info.h"
+#include "monster/monster-pain-describer.h"
 #include "monster/monster-status-setter.h"
 #include "monster/monster-status.h"
 #include "object-enchant/tr-types.h"
@@ -450,7 +451,11 @@ void ObjectThrowEntity::attack_racial_power()
         return;
     }
 
-    message_pain(this->player_ptr, this->g_ptr->m_idx, this->tdam);
+    if (const auto pain_message = MonsterPainDescriber(player_ptr, this->g_ptr->m_idx).describe(this->tdam);
+        !pain_message.empty()) {
+        msg_print(pain_message);
+    }
+
     if ((this->tdam > 0) && !this->q_ptr->is_potion()) {
         anger_monster(this->player_ptr, this->m_ptr);
     }