OSDN Git Service

[Add] @return を不要に書き込んだことによる警告をひとまず置換で修正.
[hengbandforosx/hengbandosx.git] / src / mind / mind-blue-mage.cpp
1 #include "mind/mind-blue-mage.h"
2 #include "action/action-limited.h"
3 #include "blue-magic/blue-magic-caster.h"
4 #include "blue-magic/learnt-power-getter.h"
5 #include "core/asking-player.h"
6 #include "core/player-redraw-types.h"
7 #include "core/window-redrawer.h"
8 #include "game-option/disturbance-options.h"
9 #include "game-option/input-options.h"
10 #include "main/sound-definitions-table.h"
11 #include "main/sound-of-music.h"
12 #include "monster-race/race-ability-mask.h"
13 #include "mspell/monster-power-table.h"
14 #include "player-info/avatar.h"
15 #include "player-status/player-energy.h"
16 #include "player/player-status-table.h"
17 #include "realm/realm-types.h"
18 #include "spell/spell-info.h"
19 #include "status/bad-status-setter.h"
20 #include "status/base-status.h"
21 #include "system/player-type-definition.h"
22 #include "term/screen-processor.h"
23 #include "view/display-messages.h"
24
25 /*!
26  * @brief 青魔法コマンドのメインルーチン /
27  * do_cmd_cast calls this function if the player's class is 'Blue-Mage'.
28  * @return 処理を実行したらTRUE、キャンセルした場合FALSEを返す。
29  */
30 bool do_cmd_cast_learned(player_type *caster_ptr)
31 {
32     SPELL_IDX n = 0;
33     PERCENTAGE chance;
34     PERCENTAGE minfail = 0;
35     PLAYER_LEVEL plev = caster_ptr->lev;
36     monster_power spell;
37     bool cast;
38     MANA_POINT need_mana;
39
40     if (cmd_limit_confused(caster_ptr))
41         return FALSE;
42
43     if (!get_learned_power(caster_ptr, &n))
44         return FALSE;
45
46     spell = monster_powers[n];
47     need_mana = mod_need_mana(caster_ptr, spell.smana, 0, REALM_NONE);
48     if (need_mana > caster_ptr->csp) {
49         msg_print(_("MPが足りません。", "You do not have enough mana to use this power."));
50         if (!over_exert)
51             return FALSE;
52
53         if (!get_check(_("それでも挑戦しますか? ", "Attempt it anyway? ")))
54             return FALSE;
55     }
56
57     chance = spell.fail;
58     if (plev > spell.level)
59         chance -= 3 * (plev - spell.level);
60     else
61         chance += (spell.level - plev);
62
63     chance -= 3 * (adj_mag_stat[caster_ptr->stat_index[A_INT]] - 1);
64     chance = mod_spell_chance_1(caster_ptr, chance);
65     if (need_mana > caster_ptr->csp) {
66         chance += 5 * (need_mana - caster_ptr->csp);
67     }
68
69     minfail = adj_mag_fail[caster_ptr->stat_index[A_INT]];
70     if (chance < minfail)
71         chance = minfail;
72
73     if (caster_ptr->stun > 50)
74         chance += 25;
75     else if (caster_ptr->stun)
76         chance += 15;
77
78     if (chance > 95)
79         chance = 95;
80
81     chance = mod_spell_chance_2(caster_ptr, chance);
82     const auto spell_type = static_cast<RF_ABILITY>(n);
83     if (randint0(100) < chance) {
84         if (flush_failure)
85             flush();
86
87         msg_print(_("魔法をうまく唱えられなかった。", "You failed to concentrate hard enough!"));
88         sound(SOUND_FAIL);
89         if (RF_ABILITY_SUMMON_MASK.has(spell_type))
90             cast = cast_learned_spell(caster_ptr, spell_type, FALSE);
91     } else {
92         sound(SOUND_ZAP);
93         cast = cast_learned_spell(caster_ptr, spell_type, TRUE);
94         if (!cast)
95             return FALSE;
96     }
97
98     if (need_mana <= caster_ptr->csp) {
99         caster_ptr->csp -= need_mana;
100     } else {
101         int oops = need_mana;
102         caster_ptr->csp = 0;
103         caster_ptr->csp_frac = 0;
104         msg_print(_("精神を集中しすぎて気を失ってしまった!", "You faint from the effort!"));
105         (void)set_paralyzed(caster_ptr, caster_ptr->paralyzed + randint1(5 * oops + 1));
106         chg_virtue(caster_ptr, V_KNOWLEDGE, -10);
107         if (randint0(100) < 50) {
108             bool perm = (randint0(100) < 25);
109             msg_print(_("体を悪くしてしまった!", "You have damaged your health!"));
110             (void)dec_stat(caster_ptr, A_CON, 15 + randint1(10), perm);
111         }
112     }
113
114     PlayerEnergy(caster_ptr).set_player_turn_energy(100);
115     caster_ptr->redraw |= PR_MANA;
116     caster_ptr->window_flags |= PW_PLAYER | PW_SPELL;
117     return TRUE;
118 }