1 #include "cmd-action/cmd-racial.h"
2 #include "action/action-limited.h"
3 #include "action/mutation-execution.h"
4 #include "core/asking-player.h"
5 #include "core/player-redraw-types.h"
6 #include "core/player-update-types.h"
7 #include "core/window-redrawer.h"
8 #include "game-option/text-display-options.h"
9 #include "io/command-repeater.h"
10 #include "io/input-key-requester.h"
11 #include "main/sound-of-music.h"
12 #include "mutation/mutation-flag-types.h"
13 #include "player/attack-defense-types.h"
14 #include "player/player-damage.h"
15 #include "player/special-defense-types.h"
16 #include "racial/class-racial-switcher.h"
17 #include "racial/mutation-racial-selector.h"
18 #include "racial/race-racial-switcher.h"
19 #include "racial/racial-switcher.h"
20 #include "racial/racial-util.h"
21 #include "status/action-setter.h"
22 #include "term/screen-processor.h"
23 #include "util/int-char-converter.h"
25 static bool input_racial_power_selection(player_type *creature_ptr, rc_type *rc_ptr)
27 switch (rc_ptr->choice) {
30 free_turn(creature_ptr);
35 rc_ptr->menu_line += (rc_ptr->num - 1);
48 if (rc_ptr->menu_line > 18)
49 rc_ptr->menu_line -= 18;
50 else if (rc_ptr->menu_line + 18 <= rc_ptr->num)
51 rc_ptr->menu_line += 18;
57 rc_ptr->command_code = rc_ptr->menu_line - 1;
65 static bool check_input_racial_power(player_type *creature_ptr, rc_type *rc_ptr)
67 if (!use_menu || rc_ptr->choice == ' ')
70 if (input_racial_power_selection(creature_ptr, rc_ptr))
73 if (rc_ptr->menu_line > rc_ptr->num)
74 rc_ptr->menu_line -= rc_ptr->num;
79 static void display_racial_list(rc_type *rc_ptr, char *dummy)
82 rc_ptr->redraw = TRUE;
86 if (rc_ptr->num < 18) {
87 prt(_(" Lv MP 失率", " Lv Cost Fail"), 1, 0);
91 prt(_(" Lv MP 失率 Lv MP 失率",
92 " Lv Cost Fail Lv Cost Fail"),
96 static void select_racial_power(player_type *creature_ptr, rc_type *rc_ptr)
99 display_racial_list(rc_ptr, dummy);
103 while (ctr < rc_ptr->num) {
104 TERM_LEN x1 = ((ctr < 18) ? x : x + 40);
105 TERM_LEN y1 = ((ctr < 18) ? y + ctr : y + ctr - 18);
107 if (ctr == (rc_ptr->menu_line - 1))
108 strcpy(dummy, _(" 》 ", " > "));
116 letter = '0' + ctr - 26;
118 sprintf(dummy, " %c) ", letter);
122 format("%-23.23s %2d %4d %3d%%", rc_ptr->power_desc[ctr].racial_name, rc_ptr->power_desc[ctr].min_level, rc_ptr->power_desc[ctr].cost,
123 100 - racial_chance(creature_ptr, &rc_ptr->power_desc[ctr])));
129 static bool check_racial_power_choice(player_type *creature_ptr, rc_type *rc_ptr)
131 if ((rc_ptr->choice != ' ') && (rc_ptr->choice != '*') && (rc_ptr->choice != '?') && (!use_menu || !rc_ptr->ask))
134 if (!rc_ptr->redraw || use_menu) {
135 select_racial_power(creature_ptr, rc_ptr);
139 rc_ptr->redraw = FALSE;
144 static void decide_racial_command(rc_type *rc_ptr)
149 if (rc_ptr->choice == '\r' && rc_ptr->num == 1)
150 rc_ptr->choice = 'a';
152 if (!isalpha(rc_ptr->choice)) {
154 rc_ptr->command_code = rc_ptr->choice - '0' + 26;
158 rc_ptr->ask = (isupper(rc_ptr->choice));
160 rc_ptr->choice = (char)tolower(rc_ptr->choice);
162 rc_ptr->command_code = (islower(rc_ptr->choice) ? A2I(rc_ptr->choice) : -1);
165 static bool ask_invoke_racial_power(rc_type *rc_ptr)
167 if ((rc_ptr->command_code < 0) || (rc_ptr->command_code >= rc_ptr->num)) {
176 (void)strnfmt(tmp_val, 78, _("%sを使いますか? ", "Use %s? "), rc_ptr->power_desc[rc_ptr->command_code].racial_name);
177 return get_check(tmp_val);
180 static bool process_racial_power_choice(player_type *creature_ptr, rc_type *rc_ptr)
182 rc_ptr->choice = (always_show_list || use_menu) ? ESCAPE : 1;
183 while (!rc_ptr->flag) {
184 if (rc_ptr->choice == ESCAPE)
185 rc_ptr->choice = ' ';
186 else if (!get_com(rc_ptr->out_val, &rc_ptr->choice, FALSE))
189 if (check_input_racial_power(creature_ptr, rc_ptr))
192 if (check_racial_power_choice(creature_ptr, rc_ptr))
195 decide_racial_command(rc_ptr);
196 if (!ask_invoke_racial_power(rc_ptr))
206 * @brief レイシャル・パワーコマンドのメインルーチン / Allow user to choose a power (racial / mutation) to activate
207 * @param creature_ptr プレーヤーへの参照ポインタ
210 void do_cmd_racial_power(player_type *creature_ptr)
212 if (creature_ptr->wild_mode)
215 if (cmd_limit_confused(creature_ptr)) {
216 free_turn(creature_ptr);
220 if (creature_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
221 set_action(creature_ptr, ACTION_NONE);
224 rc_type *rc_ptr = initialize_rc_type(creature_ptr, &tmp_rc);
225 switch_class_racial(creature_ptr, rc_ptr);
226 if (creature_ptr->mimic_form)
227 switch_mimic_racial(creature_ptr, rc_ptr);
229 switch_race_racial(creature_ptr, rc_ptr);
231 select_mutation_racial(creature_ptr, rc_ptr);
232 rc_ptr->flag = FALSE;
233 rc_ptr->redraw = FALSE;
235 (void)strnfmt(rc_ptr->out_val, 78,
236 _("(特殊能力 %c-%c, *'で一覧, ESCで中断) どの特殊能力を使いますか?", "(Powers %c-%c, *=List, ESC=exit) Use which power? "), I2A(0),
237 (rc_ptr->num <= 26) ? I2A(rc_ptr->num - 1) : '0' + rc_ptr->num - 27);
239 if (!repeat_pull(&rc_ptr->command_code) || rc_ptr->command_code < 0 || rc_ptr->command_code >= rc_ptr->num) {
243 if (process_racial_power_choice(creature_ptr, rc_ptr))
250 free_turn(creature_ptr);
254 repeat_push(rc_ptr->command_code);
257 switch (racial_aux(creature_ptr, &rc_ptr->power_desc[rc_ptr->command_code])) {
259 if (rc_ptr->power_desc[rc_ptr->command_code].number < 0)
260 rc_ptr->cast = exe_racial_power(creature_ptr, rc_ptr->power_desc[rc_ptr->command_code].number);
262 rc_ptr->cast = exe_mutation_power(creature_ptr, rc_ptr->power_desc[rc_ptr->command_code].number);
266 rc_ptr->cast = FALSE;
274 free_turn(creature_ptr);
278 int racial_cost = rc_ptr->power_desc[rc_ptr->command_code].racial_cost;
279 if (racial_cost == 0)
282 int actual_racial_cost = racial_cost / 2 + randint1(racial_cost / 2);
283 if (creature_ptr->csp >= actual_racial_cost) {
284 creature_ptr->csp -= actual_racial_cost;
286 actual_racial_cost -= creature_ptr->csp;
287 creature_ptr->csp = 0;
288 take_hit(creature_ptr, DAMAGE_USELIFE, actual_racial_cost, _("過度の集中", "concentrating too hard"), -1);
291 creature_ptr->redraw |= PR_HP | PR_MANA;
292 creature_ptr->window |= PW_PLAYER | PW_SPELL;