#include "player/special-defense-types.h"
#include "racial/class-racial-switcher.h"
#include "racial/mutation-racial-selector.h"
-#include "racial/race-racial-switcher.h"
-#include "racial/racial-switcher.h"
+#include "action/racial-execution.h"
+#include "racial/race-racial-command-setter.h"
#include "racial/racial-util.h"
#include "status/action-setter.h"
#include "term/screen-processor.h"
#include "util/int-char-converter.h"
-static bool input_racial_technique_selection(player_type *creature_ptr, rc_type *rc_ptr)
+static bool input_racial_power_selection(player_type *creature_ptr, rc_type *rc_ptr)
{
switch (rc_ptr->choice) {
case '0':
}
}
+static bool check_input_racial_power(player_type *creature_ptr, rc_type *rc_ptr)
+{
+ if (!use_menu || rc_ptr->choice == ' ')
+ return FALSE;
+
+ if (input_racial_power_selection(creature_ptr, rc_ptr))
+ return TRUE;
+
+ if (rc_ptr->menu_line > rc_ptr->num)
+ rc_ptr->menu_line -= rc_ptr->num;
+
+ return FALSE;
+}
+
static void display_racial_list(rc_type *rc_ptr, char *dummy)
{
strcpy(dummy, "");
1, 0);
}
+static void select_racial_power(player_type *creature_ptr, rc_type *rc_ptr)
+{
+ char dummy[80];
+ display_racial_list(rc_ptr, dummy);
+ byte y = 2;
+ byte x = 0;
+ int ctr = 0;
+ while (ctr < rc_ptr->num) {
+ TERM_LEN x1 = ((ctr < 18) ? x : x + 40);
+ TERM_LEN y1 = ((ctr < 18) ? y + ctr : y + ctr - 18);
+ if (use_menu) {
+ if (ctr == (rc_ptr->menu_line - 1))
+ strcpy(dummy, _(" 》 ", " > "));
+ else
+ strcpy(dummy, " ");
+ } else {
+ char letter;
+ if (ctr < 26)
+ letter = I2A(ctr);
+ else
+ letter = '0' + ctr - 26;
+
+ sprintf(dummy, " %c) ", letter);
+ }
+
+ strcat(dummy,
+ 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,
+ 100 - racial_chance(creature_ptr, &rc_ptr->power_desc[ctr])));
+ prt(dummy, y1, x1);
+ ctr++;
+ }
+}
+
+static bool check_racial_power_choice(player_type *creature_ptr, rc_type *rc_ptr)
+{
+ if ((rc_ptr->choice != ' ') && (rc_ptr->choice != '*') && (rc_ptr->choice != '?') && (!use_menu || !rc_ptr->ask))
+ return FALSE;
+
+ if (!rc_ptr->redraw || use_menu) {
+ select_racial_power(creature_ptr, rc_ptr);
+ return TRUE;
+ }
+
+ rc_ptr->redraw = FALSE;
+ screen_load();
+ return TRUE;
+}
+
+static void decide_racial_command(rc_type *rc_ptr)
+{
+ if (use_menu)
+ return;
+
+ if (rc_ptr->choice == '\r' && rc_ptr->num == 1)
+ rc_ptr->choice = 'a';
+
+ if (!isalpha(rc_ptr->choice)) {
+ rc_ptr->ask = FALSE;
+ rc_ptr->command_code = rc_ptr->choice - '0' + 26;
+ return;
+ }
+
+ rc_ptr->ask = (isupper(rc_ptr->choice));
+ if (rc_ptr->ask)
+ rc_ptr->choice = (char)tolower(rc_ptr->choice);
+
+ rc_ptr->command_code = (islower(rc_ptr->choice) ? A2I(rc_ptr->choice) : -1);
+}
+
+static bool ask_invoke_racial_power(rc_type *rc_ptr)
+{
+ if ((rc_ptr->command_code < 0) || (rc_ptr->command_code >= rc_ptr->num)) {
+ bell();
+ return FALSE;
+ }
+
+ if (!rc_ptr->ask)
+ return TRUE;
+
+ char tmp_val[160];
+ (void)strnfmt(tmp_val, 78, _("%sを使いますか? ", "Use %s? "), rc_ptr->power_desc[rc_ptr->command_code].racial_name);
+ return get_check(tmp_val);
+}
+
+static bool process_racial_power_choice(player_type *creature_ptr, rc_type *rc_ptr)
+{
+ rc_ptr->choice = (always_show_list || use_menu) ? ESCAPE : 1;
+ while (!rc_ptr->flag) {
+ if (rc_ptr->choice == ESCAPE)
+ rc_ptr->choice = ' ';
+ else if (!get_com(rc_ptr->out_val, &rc_ptr->choice, FALSE))
+ break;
+
+ if (check_input_racial_power(creature_ptr, rc_ptr))
+ return TRUE;
+
+ if (check_racial_power_choice(creature_ptr, rc_ptr))
+ continue;
+
+ decide_racial_command(rc_ptr);
+ if (!ask_invoke_racial_power(rc_ptr))
+ continue;
+
+ rc_ptr->flag = TRUE;
+ }
+
+ return FALSE;
+}
+
+static bool repeat_racial_power(player_type *creature_ptr, rc_type *rc_ptr)
+{
+ if (repeat_pull(&rc_ptr->command_code) && (rc_ptr->command_code >= 0) && (rc_ptr->command_code < rc_ptr->num))
+ return FALSE;
+
+ if (use_menu)
+ screen_save();
+
+ if (process_racial_power_choice(creature_ptr, rc_ptr))
+ return TRUE;
+
+ if (rc_ptr->redraw)
+ screen_load();
+
+ if (!rc_ptr->flag) {
+ free_turn(creature_ptr);
+ return TRUE;
+ }
+
+ repeat_push(rc_ptr->command_code);
+ return FALSE;
+}
+
+static void check_cast_racial_power(player_type *creature_ptr, rc_type *rc_ptr)
+{
+ switch (check_racial_level(creature_ptr, &rc_ptr->power_desc[rc_ptr->command_code])) {
+ case RACIAL_SUCCESS:
+ if (rc_ptr->power_desc[rc_ptr->command_code].number < 0)
+ rc_ptr->cast = exe_racial_power(creature_ptr, rc_ptr->power_desc[rc_ptr->command_code].number);
+ else
+ rc_ptr->cast = exe_mutation_power(creature_ptr, rc_ptr->power_desc[rc_ptr->command_code].number);
+
+ break;
+ case RACIAL_FAILURE:
+ rc_ptr->cast = TRUE;
+ break;
+ case RACIAL_CANCEL:
+ rc_ptr->cast = FALSE;
+ break;
+ }
+}
+
+static bool reduce_mana_by_racial(player_type *creature_ptr, rc_type *rc_ptr)
+{
+ int racial_cost = rc_ptr->power_desc[rc_ptr->command_code].racial_cost;
+ if (racial_cost == 0)
+ return FALSE;
+
+ int actual_racial_cost = racial_cost / 2 + randint1(racial_cost / 2);
+ if (creature_ptr->csp >= actual_racial_cost) {
+ creature_ptr->csp -= actual_racial_cost;
+ return TRUE;
+ }
+
+ actual_racial_cost -= creature_ptr->csp;
+ creature_ptr->csp = 0;
+ take_hit(creature_ptr, DAMAGE_USELIFE, actual_racial_cost, _("過度の集中", "concentrating too hard"), -1);
+ return TRUE;
+}
+
/*!
* @brief レイシャル・パワーコマンドのメインルーチン / Allow user to choose a power (racial / mutation) to activate
* @param creature_ptr プレーヤーへの参照ポインタ
rc_type *rc_ptr = initialize_rc_type(creature_ptr, &tmp_rc);
switch_class_racial(creature_ptr, rc_ptr);
if (creature_ptr->mimic_form)
- switch_mimic_racial(creature_ptr, rc_ptr);
+ set_mimic_racial_command(creature_ptr, rc_ptr);
else
- switch_race_racial(creature_ptr, rc_ptr);
+ set_race_racial_command(creature_ptr, rc_ptr);
select_mutation_racial(creature_ptr, rc_ptr);
rc_ptr->flag = FALSE;
_("(特殊能力 %c-%c, *'で一覧, ESCで中断) どの特殊能力を使いますか?", "(Powers %c-%c, *=List, ESC=exit) Use which power? "), I2A(0),
(rc_ptr->num <= 26) ? I2A(rc_ptr->num - 1) : '0' + rc_ptr->num - 27);
- if (!repeat_pull(&rc_ptr->command_code) || rc_ptr->command_code < 0 || rc_ptr->command_code >= rc_ptr->num) {
- if (use_menu)
- screen_save();
-
- rc_ptr->choice = (always_show_list || use_menu) ? ESCAPE : 1;
- while (!rc_ptr->flag) {
- if (rc_ptr->choice == ESCAPE)
- rc_ptr->choice = ' ';
- else if (!get_com(rc_ptr->out_val, &rc_ptr->choice, FALSE))
- break;
-
- if (use_menu && rc_ptr->choice != ' ') {
- if (input_racial_technique_selection(creature_ptr, rc_ptr))
- return;
-
- if (rc_ptr->menu_line > rc_ptr->num)
- rc_ptr->menu_line -= rc_ptr->num;
- }
-
- if ((rc_ptr->choice == ' ') || (rc_ptr->choice == '*') || (rc_ptr->choice == '?') || (use_menu && rc_ptr->ask)) {
- if (!rc_ptr->redraw || use_menu) {
- char dummy[80];
- display_racial_list(rc_ptr, dummy);
- byte y = 2;
- byte x = 0;
- int ctr = 0;
- while (ctr < rc_ptr->num) {
- TERM_LEN x1 = ((ctr < 18) ? x : x + 40);
- TERM_LEN y1 = ((ctr < 18) ? y + ctr : y + ctr - 18);
- if (use_menu) {
- if (ctr == (rc_ptr->menu_line - 1))
- strcpy(dummy, _(" 》 ", " > "));
- else
- strcpy(dummy, " ");
- } else {
- char letter;
- if (ctr < 26)
- letter = I2A(ctr);
- else
- letter = '0' + ctr - 26;
- sprintf(dummy, " %c) ", letter);
- }
-
- strcat(dummy,
- 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, 100 - racial_chance(creature_ptr, &rc_ptr->power_desc[ctr])));
- prt(dummy, y1, x1);
- ctr++;
- }
- } else {
- rc_ptr->redraw = FALSE;
- screen_load();
- }
-
- continue;
- }
-
- if (!use_menu) {
- if (rc_ptr->choice == '\r' && rc_ptr->num == 1)
- rc_ptr->choice = 'a';
-
- if (isalpha(rc_ptr->choice)) {
- rc_ptr->ask = (isupper(rc_ptr->choice));
- if (rc_ptr->ask)
- rc_ptr->choice = (char)tolower(rc_ptr->choice);
-
- rc_ptr->command_code = (islower(rc_ptr->choice) ? A2I(rc_ptr->choice) : -1);
- } else {
- rc_ptr->ask = FALSE;
- rc_ptr->command_code = rc_ptr->choice - '0' + 26;
- }
- }
-
- if ((rc_ptr->command_code < 0) || (rc_ptr->command_code >= rc_ptr->num)) {
- bell();
- continue;
- }
-
- if (rc_ptr->ask) {
- char tmp_val[160];
- (void)strnfmt(tmp_val, 78, _("%sを使いますか? ", "Use %s? "), rc_ptr->power_desc[rc_ptr->command_code].racial_name);
- if (!get_check(tmp_val))
- continue;
- }
-
- rc_ptr->flag = TRUE;
- }
-
- if (rc_ptr->redraw)
- screen_load();
-
- if (!rc_ptr->flag) {
- free_turn(creature_ptr);
- return;
- }
-
- repeat_push(rc_ptr->command_code);
- }
-
- switch (racial_aux(creature_ptr, &rc_ptr->power_desc[rc_ptr->command_code])) {
- case 1:
- if (rc_ptr->power_desc[rc_ptr->command_code].number < 0)
- rc_ptr->cast = exe_racial_power(creature_ptr, rc_ptr->power_desc[rc_ptr->command_code].number);
- else
- rc_ptr->cast = exe_mutation_power(creature_ptr, rc_ptr->power_desc[rc_ptr->command_code].number);
- break;
- case 0:
- rc_ptr->cast = FALSE;
- break;
- case -1:
- rc_ptr->cast = TRUE;
- break;
- }
+ if (repeat_racial_power(creature_ptr, rc_ptr))
+ return;
+ check_cast_racial_power(creature_ptr, rc_ptr);
if (!rc_ptr->cast) {
free_turn(creature_ptr);
return;
}
- int racial_cost = rc_ptr->power_desc[rc_ptr->command_code].racial_cost;
- if (racial_cost == 0)
+ if (!reduce_mana_by_racial(creature_ptr, rc_ptr))
return;
- int actual_racial_cost = racial_cost / 2 + randint1(racial_cost / 2);
- if (creature_ptr->csp < actual_racial_cost) {
- actual_racial_cost -= creature_ptr->csp;
- creature_ptr->csp = 0;
- take_hit(creature_ptr, DAMAGE_USELIFE, actual_racial_cost, _("過度の集中", "concentrating too hard"), -1);
- } else
- creature_ptr->csp -= actual_racial_cost;
-
creature_ptr->redraw |= PR_HP | PR_MANA;
creature_ptr->window |= PW_PLAYER | PW_SPELL;
}