OSDN Git Service

[Refactor] #935 マクロ関数SINGING_SONG_ID を普通の関数に置換した / Changed macro function SINGING_SON...
[hengbandforosx/hengbandosx.git] / src / spell-realm / spells-song.cpp
1 #include "spell-realm/spells-song.h"
2 #include "core/disturbance.h"
3 #include "core/player-redraw-types.h"
4 #include "core/player-update-types.h"
5 #include "core/stuff-handler.h"
6 #include "core/window-redrawer.h"
7 #include "game-option/disturbance-options.h"
8 #include "player/attack-defense-types.h"
9 #include "player/player-skill.h"
10 #include "realm/realm-song-numbers.h"
11 #include "spell/spell-info.h"
12 #include "spell/spells-execution.h"
13 #include "spell/technic-info-table.h"
14 #include "system/floor-type-definition.h"
15 #include "system/player-type-definition.h"
16 #include "view/display-messages.h"
17
18 /*!
19  * @brief プレイヤーの歌に関する継続処理
20  * @return なし
21  */
22 void check_music(player_type *caster_ptr)
23 {
24     if (caster_ptr->pclass != CLASS_BARD)
25         return;
26
27     auto interupting_song_effect = get_interrupting_song_effect(caster_ptr);
28     if ((get_singing_song_effect(caster_ptr) == 0) && (interupting_song_effect == 0))
29         return;
30
31     if (caster_ptr->anti_magic) {
32         stop_singing(caster_ptr);
33         return;
34     }
35
36     int spell = get_singing_song_id(caster_ptr);
37     const magic_type *s_ptr;
38     s_ptr = &technic_info[REALM_MUSIC - MIN_TECHNIC][spell];
39
40     MANA_POINT need_mana = mod_need_mana(caster_ptr, s_ptr->smana, spell, REALM_MUSIC);
41     u32b need_mana_frac = 0;
42
43     s64b_rshift(&need_mana, &need_mana_frac, 1);
44     if (s64b_cmp(caster_ptr->csp, caster_ptr->csp_frac, need_mana, need_mana_frac) < 0) {
45         stop_singing(caster_ptr);
46         return;
47     } else {
48         s64b_sub(&(caster_ptr->csp), &(caster_ptr->csp_frac), need_mana, need_mana_frac);
49
50         caster_ptr->redraw |= PR_MANA;
51         if (interupting_song_effect != 0) {
52             set_singing_song_effect(caster_ptr, interupting_song_effect);
53             set_interrupting_song_effect(caster_ptr, MUSIC_NONE);
54             msg_print(_("歌を再開した。", "You resume singing."));
55             caster_ptr->action = ACTION_SING;
56             caster_ptr->update |= (PU_BONUS | PU_HP | PU_MONSTERS);
57             caster_ptr->redraw |= (PR_MAP | PR_STATUS | PR_STATE);
58             caster_ptr->window_flags |= (PW_OVERHEAD | PW_DUNGEON);
59         }
60     }
61
62     if (caster_ptr->spell_exp[spell] < SPELL_EXP_BEGINNER)
63         caster_ptr->spell_exp[spell] += 5;
64     else if (caster_ptr->spell_exp[spell] < SPELL_EXP_SKILLED) {
65         if (one_in_(2) && (caster_ptr->current_floor_ptr->dun_level > 4) && ((caster_ptr->current_floor_ptr->dun_level + 10) > caster_ptr->lev))
66             caster_ptr->spell_exp[spell] += 1;
67     } else if (caster_ptr->spell_exp[spell] < SPELL_EXP_EXPERT) {
68         if (one_in_(5) && ((caster_ptr->current_floor_ptr->dun_level + 5) > caster_ptr->lev)
69             && ((caster_ptr->current_floor_ptr->dun_level + 5) > s_ptr->slevel))
70             caster_ptr->spell_exp[spell] += 1;
71     } else if (caster_ptr->spell_exp[spell] < SPELL_EXP_MASTER) {
72         if (one_in_(5) && ((caster_ptr->current_floor_ptr->dun_level + 5) > caster_ptr->lev) && (caster_ptr->current_floor_ptr->dun_level > s_ptr->slevel))
73             caster_ptr->spell_exp[spell] += 1;
74     }
75
76     exe_spell(caster_ptr, REALM_MUSIC, spell, SPELL_CONT);
77 }
78
79 /*!
80  * @brief 隠遁の歌の継続時間をセットする / Set "tim_stealth", notice observable changes
81  * @param v 継続時間
82  * @param do_dec 現在の継続時間より長い値のみ上書きする
83  * @return ステータスに影響を及ぼす変化があった場合TRUEを返す。
84  */
85 bool set_tim_stealth(player_type *creature_ptr, TIME_EFFECT v, bool do_dec)
86 {
87     bool notice = FALSE;
88     v = (v > 10000) ? 10000 : (v < 0) ? 0 : v;
89
90     if (creature_ptr->is_dead)
91         return FALSE;
92
93     if (v) {
94         if (creature_ptr->tim_stealth && !do_dec) {
95             if (creature_ptr->tim_stealth > v)
96                 return FALSE;
97         } else if (!is_time_limit_stealth(creature_ptr)) {
98             msg_print(_("足音が小さくなった!", "You begin to walk silently!"));
99             notice = TRUE;
100         }
101     } else {
102         if (creature_ptr->tim_stealth && !music_singing(creature_ptr, MUSIC_STEALTH)) {
103             msg_print(_("足音が大きくなった。", "You no longer walk silently."));
104             notice = TRUE;
105         }
106     }
107
108     creature_ptr->tim_stealth = v;
109     creature_ptr->redraw |= (PR_STATUS);
110
111     if (!notice)
112         return FALSE;
113
114     if (disturb_state)
115         disturb(creature_ptr, FALSE, FALSE);
116     creature_ptr->update |= (PU_BONUS);
117     handle_stuff(creature_ptr);
118     return TRUE;
119 }