/* Ask & execute a power */ void do_cmd_power() { s32b x_idx; power_type *x_ptr; bool push = TRUE; /* Get the skill, if available */ if (repeat_pull(&x_idx)) { if ((x_idx < 0) || (x_idx >= power_max)) return; x_ptr = &powers_type[x_idx]; push = FALSE; } else if (!command_arg) x_ptr = select_power(&x_idx); else { x_idx = command_arg - 1; if ((x_idx < 0) || (x_idx >= power_max)) return; x_ptr = &powers_type[x_idx]; } if (x_ptr == NULL) return; if (push) repeat_push(x_idx); if (flag_get(&p_ptr->powers, x_idx)) power_activate(x_idx); else msg_print("You do not have access to this power."); }
static int get_snipe_power(int *sn, bool only_browse) { int i; int num = 0; int y = 1; int x = 20; int plev = p_ptr->lev; int ask; char choice; char out_val[160]; cptr p = "power"; snipe_power spell; bool flag, redraw; #ifdef ALLOW_REPEAT /* TNB */ repeat_push(*sn); /* Assume cancelled */ *sn = (-1); /* Repeat previous command */ /* Get the spell, if available */ if (repeat_pull(sn)) { /* Verify the spell */ if ((snipe_powers[*sn].min_lev <= plev) && (snipe_powers[*sn].mana_cost <= (int)p_ptr->concent)) { /* Success */ return (TRUE); } } #endif /* ALLOW_REPEAT -- TNB */ /* Nothing chosen yet */ flag = FALSE; /* No redraw yet */ redraw = FALSE; for (i = 0; i < MAX_SNIPE_POWERS; i++) { if ((snipe_powers[i].min_lev <= plev) && ((only_browse) || (snipe_powers[i].mana_cost <= (int)p_ptr->concent))) { num = i; } } /* Build a prompt (accept all spells) */ if (only_browse) { (void)strnfmt(out_val, 78, "(%^ss %c-%c, *=List, ESC=exit) Use which %s? ", p, I2A(0), I2A(num), p); } else { (void)strnfmt(out_val, 78, "(%^ss %c-%c, *=List, ESC=exit) Use which %s? ", p, I2A(0), I2A(num), p); } /* Get a spell from the user */ choice = always_show_list ? ESCAPE : 1; while (!flag) { if(choice == ESCAPE) choice = ' '; else if( !get_com(out_val, &choice, FALSE) )break; /* Request redraw */ if ((choice == ' ') || (choice == '*') || (choice == '?')) { /* Show the list */ if (!redraw) { char psi_desc[80]; /* Show list */ redraw = TRUE; /* Save the screen */ if (!only_browse) screen_save(); /* Display a list of spells */ prt("", y, x); put_str("Name", y, x + 5); if (only_browse) put_str("Lv Pow", y, x + 35); /* Dump the spells */ for (i = 0; i < MAX_SNIPE_POWERS; i++) { Term_erase(x, y + i + 1, 255); /* Access the spell */ spell = snipe_powers[i]; if (spell.min_lev > plev) continue; if (!only_browse && (spell.mana_cost > (int)p_ptr->concent)) continue; /* Dump the spell --(-- */ if (only_browse) sprintf(psi_desc, " %c) %-30s%2d %4d", I2A(i), spell.name, spell.min_lev, spell.mana_cost); else sprintf(psi_desc, " %c) %-30s", I2A(i), spell.name); prt(psi_desc, y + i + 1, x); } /* Clear the bottom line */ prt("", y + i + 1, x); } /* Hide the list */ else { /* Hide list */ redraw = FALSE; /* Restore the screen */ if (!only_browse) screen_load(); } /* Redo asking */ continue; } /* Note verify */ ask = isupper(choice); /* Lowercase */ if (ask) choice = tolower(choice); /* Extract request */ i = (islower(choice) ? A2I(choice) : -1); /* Totally Illegal */ if ((i < 0) || (i > num) || (!only_browse &&(snipe_powers[i].mana_cost > (int)p_ptr->concent))) { bell(); continue; } /* Save the spell index */ spell = snipe_powers[i]; /* Verify it */ if (ask) { char tmp_val[160]; /* Prompt */ (void)strnfmt(tmp_val, 78, "Use %s? ", snipe_powers[i].name); /* Belay that order */ if (!get_check(tmp_val)) continue; } /* Stop the loop */ flag = TRUE; } /* Restore the screen */ if (redraw && !only_browse) screen_load(); /* Show choices */ p_ptr->window |= (PW_SPELL); /* Window stuff */ window_stuff(); /* Abort if needed */ if (!flag) return (FALSE); /* Save the choice */ (*sn) = i; #ifdef ALLOW_REPEAT /* TNB */ repeat_push(*sn); #endif /* ALLOW_REPEAT -- TNB */ /* Success */ return (TRUE); }
/* * Request a "quantity" from the user * * Hack -- allow "command_arg" to specify a quantity */ s16b get_quantity(cptr prompt, int max) { int amt; char tmp[80]; char buf[80]; /* Use "command_arg" */ if (p_ptr->cmd.arg) { /* Extract a number */ amt = p_ptr->cmd.arg; /* Clear "cmd.arg" */ p_ptr->cmd.arg = 0; /* Enforce the maximum */ if (amt > max) amt = max; /* Use it */ return (amt); } /* Get the item index */ if ((max != 1) && repeat_pull(&amt)) { /* Enforce the maximum */ if (amt > max) amt = max; /* Enforce the minimum */ if (amt < 0) amt = 0; /* Use it */ return (amt); } /* Build a prompt if needed */ if (!prompt) { /* Build a prompt */ strnfmt(tmp, 80, "Quantity (1-%d): ", max); /* Use that prompt */ prompt = tmp; } /* Default to one */ amt = 1; /* Build the default */ strnfmt(buf, 80, "%d", amt); /* Ask for a quantity */ if (!get_string(buf, 7, prompt)) return (0); /* Extract a number */ amt = atoi(buf); /* A letter means "all" */ if (isalpha(buf[0])) amt = max; /* Enforce the maximum */ if (amt > max) amt = max; /* Enforce the minimum */ if (amt < 0) amt = 0; if (amt) repeat_push(amt); /* Return the result */ return (amt); }
/* * Display a menu, and get a choice. * Return false if escape is pressed. * * 'options' is an array that contains the strings to print. * plus all the functions to call together with the * flags for each option. * 'select' shows the default/current option. * If negative, it is ignored. * 'scroll' controls whether or not to allow scrolling option * selection. * 'disp' contains an optional function to print some extra * information when constucting the menu. * 'prompt' is an optional prompt. */ bool display_menu(menu_type *options, int select, bool scroll, int disp(int), cptr prompt) { int i = -1, j, cnt; bool ask = FALSE; char choice; int num = 0; int save_choice; /* Calculate the number of strings we have */ while (options[num].text) num++; /* Paranoia XXX XXX XXX */ message_flush(); /* Save the screen */ screen_save(); /* Show the list */ cnt = show_menu(num, options, select, scroll, disp, prompt); /* Paranoia */ if (!cnt) { while (inkey() != ESCAPE) { /* Do nothing */ } /* Restore the screen */ screen_load(); return (FALSE); } /* Get a command from the user */ while (TRUE) { /* Try to get previously saved value */ if (!repeat_pull(&i)) { /* Try to match with available options */ i = get_choice(&choice, num, &ask); } /* Handle "cancel" */ if (i == -2) { /* Restore the screen */ screen_load(); return (FALSE); } /* No match? */ if (i == -1) { /* Pick default option */ if ((choice == '\r') || (choice == ' ')) { i = 0; /* Scan options */ if (num > 1) { /* Count active options up to our selection */ for (j = 0; j < select; j++) { if (options[j].flags & MN_ACTIVE) { i++; } } } } /* Scroll selected option up or down */ else if ((choice == '8') && scroll) { do { /* Find previous option */ select--; /* Scroll over */ if (select < 0) select = num - 1; } while(!(options[select].flags & MN_SELECT)); /* Show the list */ show_menu(num, options, select, scroll, disp, prompt); /* Next time */ continue; } /* Scroll selected option up or down */ else if ((choice == '2') && scroll) { do { /* Find next option */ select++; /* Scroll over */ if (select >= num) select = 0; } while(!(options[select].flags & MN_SELECT)); /* Show the list */ show_menu(num, options, select, scroll, disp, prompt); /* Next time */ continue; } /* Context-sensitive help */ else if (choice == '?') { /* Do we have a help entry? */ if ((select >= 0) && options[select].help) { /* Show the information */ show_file(options[select].help, NULL, 0, 0); /* Show the list */ show_menu(num, options, select, scroll, disp, prompt); /* Next time */ continue; } else { bell("No context sensitive help available!"); continue; } } } /* Totally Illegal */ if ((i < 0) || (i >= cnt)) { bell("Illegal choice!"); continue; } save_choice = i; /* Find the action to call */ for (j = 0; j < num; j++) { if (options[j].flags & MN_ACTIVE) { if (!i) { /* Verify it */ if (ask) { /* Belay that order */ if (!get_check("Use %s? ", options[j].text)) { /* Show the list */ show_menu(num, options, select, scroll, disp, prompt); break; } } /* Hack - restore the screen */ if (options[j].flags & MN_CLEAR) { screen_load(); } if (options[j].action(j)) { /* Hack - restore the screen */ if (!(options[j].flags & MN_CLEAR)) { /* Restore the screen */ screen_load(); } /* Save for later */ repeat_push(save_choice); /* Success */ return (TRUE); } /* Hack - save the screen */ if (options[j].flags & MN_CLEAR) { screen_save(); } /* * Select this option for next time * if had a previous selection. */ if ((select >= 0) && (options[j].flags & MN_SELECT)) { select = j; } /* Hack - flush messages */ message_flush(); /* Show the list */ show_menu(num, options, select, scroll, disp, prompt); /* Get a new command */ break; } /* Decrement count until reach selected option */ i--; } } } /* Paranoia for dumb compilers */ quit("Unreachable code in display_menu"); return (FALSE); }
static int get_class_power(int *sn) { int i; int num = 0; int y = 1; int x = 10; int minfail =0; int plev = p_ptr->lev; int chance; int ask; int use_mind; char choice; char out_val[160]; char comment[80]; cptr p; mind_type spell; mind_power *mind_ptr; bool flag, redraw; /* Insert if /if else statement here for classflag. */ if ((cp_ptr->flags) & CF_OFFICER) { use_mind = MIND_OFFICER; p = "commanding presence"; } else if ((cp_ptr->flags) & CF_AESTHETE) { use_mind = MIND_AESTHETE; p = "skill"; } else if ((cp_ptr->flags) & CF_EXPLORER) { use_mind = MIND_EXPLORER; p = "talent"; } else if ((cp_ptr->flags) & CF_MEDIUM) { use_mind = MIND_MEDIUM; p = "mental power"; } else if ((cp_ptr->flags) & CF_RECKONER) { use_mind = MIND_RECKONER; p = "reality alteration"; } else if ((cp_ptr->flags) & CF_TOURIST) { use_mind = MIND_TOURIST; p = "tourism dept."; } else if ((cp_ptr->flags) & CF_HUSSAR) { use_mind = MIND_HUSSAR; p = "combat techniques"; } else if ((cp_ptr->flags) & CF_NATURE) { use_mind = MIND_NATURE; p = "natural empathy"; } else if ((cp_ptr->flags) & CF_NINJA) { use_mind = MIND_NINJA; p = "ninjutsu"; } else { msg_print("You have no powers."); } mind_ptr = &mind_powers[use_mind]; /* Assume cancelled */ *sn = (-1); #ifdef ALLOW_REPEAT /* TNB */ /* Get the spell, if available */ if (repeat_pull(sn)) { /* Verify the spell */ if (mind_ptr->info[*sn].min_lev <= plev) { /* Success */ return (TRUE); } } #endif /* ALLOW_REPEAT -- TNB */ /* Nothing chosen yet */ flag = FALSE; /* No redraw yet */ redraw = FALSE; for (i = 0; i < MAX_CLASS_POWERS; i++) { if (mind_ptr->info[i].min_lev <= plev) { num++; } } /* Build a prompt (accept all spells) */ (void)strnfmt(out_val, 78, "(%^ss %c-%c, *=List, ESC=exit) Use which %s? ", p, I2A(0), I2A(num - 1), p); /* Get a spell from the user */ while (!flag && get_com(out_val, &choice)) { /* Request redraw */ if ((choice == ' ') || (choice == '*') || (choice == '?')) { /* Show the list */ if (!redraw) { char psi_desc[80]; /* Show list */ redraw = TRUE; /* Save the screen */ screen_save(); prt("", y, x); put_str("Name", y, x + 5); put_str(format("Lv MP Fail Info"), y, x + 35); /* Dump the spells */ for (i = 0; i < MAX_CLASS_POWERS; i++) { /* Access the spell */ spell = mind_ptr->info[i]; if (spell.min_lev > plev) break; chance = spell.fail; /* Reduce failure rate by "effective" level adjustment */ chance -= 3 * (plev - spell.min_lev); /* Reduce failure rate by INT/WIS adjustment */ chance -= 3 * (adj_mag_stat[p_ptr->stat_ind[cp_ptr->spell_stat]] - 1); /* Not enough mana to cast */ if (spell.mana_cost > p_ptr->csp) { chance += 5 * (spell.mana_cost - p_ptr->csp); } /* Extract the minimum failure rate */ minfail = adj_mag_fail[p_ptr->stat_ind[cp_ptr->spell_stat]]; /* Minimum failure rate */ if (chance < minfail) chance = minfail; /* Stunning makes spells harder */ if (p_ptr->stun > 50) chance += 25; else if (p_ptr->stun) chance += 15; /* Always a 5 percent chance of working */ if (chance > 95) chance = 95; /* Get info */ mindcraft_info(comment, use_mind, i); sprintf(psi_desc, " %c) ",I2A(i)); strcat(psi_desc, format("%-30s%2d %4d %3d%%%s", spell.name, spell.min_lev, spell.mana_cost, chance, comment)); prt(psi_desc, y + i + 1, x); } /* Clear the bottom line */ prt("", y + i + 1, x); } /* Hide the list */ else { /* Hide list */ redraw = FALSE; /* Restore the screen */ screen_load(); } /* Redo asking */ continue; } /* Note verify */ ask = isupper(choice); /* Lowercase */ if (ask) choice = tolower(choice); /* Extract request */ i = (islower(choice) ? A2I(choice) : -1); /* Totally Illegal */ if ((i < 0) || (i >= num)) { bell("Illegal class power choice!"); continue; } /* Save the spell index */ spell = mind_ptr->info[i]; /* Verify it */ if (ask) { char tmp_val[160]; /* Prompt */ (void)strnfmt(tmp_val, 78, "Use %s? ", spell.name); /* Belay that order */ if (!get_check(tmp_val)) continue; } /* Stop the loop */ flag = TRUE; } /* Restore the screen */ if (redraw) screen_load(); /* Show choices */ /* Update */ p_ptr->window |= (PW_OVERHEAD); /* Window stuff */ window_stuff(); /* Abort if needed */ if (!flag) return (FALSE); /* Save the choice */ (*sn) = i; #ifdef ALLOW_REPEAT /* TNB */ repeat_push(*sn); #endif /* ALLOW_REPEAT -- TNB */ /* Success */ return (TRUE); }
/* Ask & execute a skill */ void do_cmd_activate_skill() { int x_idx; bool push = TRUE; /* Get the skill, if available */ if (repeat_pull(&x_idx)) { push = FALSE; } else if (!command_arg) x_idx = do_cmd_activate_skill_aux(); else { int i, j; x_idx = command_arg; /* Check validity */ for (i = 1; i < max_s_idx; i++) { if (s_info[i].value && (s_info[i].action_mkey == x_idx)) break; } for (j = 0; j < max_ab_idx; j++) { if (ab_info[j].acquired && (ab_info[j].action_mkey == x_idx)) break; } if ((j == max_ab_idx) && (i == max_s_idx)) { msg_print("Uh?"); return; } } if (x_idx == -1) return; if (push) repeat_push(x_idx); if (!x_idx) { choose_melee(); return; } /* Break goi/manashield */ if (p_ptr->invuln) { set_invuln(0); } if (p_ptr->disrupt_shield) { set_disrupt_shield(0); } switch (x_idx) { case MKEY_ANTIMAGIC: do_cmd_unbeliever(); break; case MKEY_MINDCRAFT: do_cmd_mindcraft(); break; case MKEY_ALCHEMY: do_cmd_alchemist(); break; case MKEY_MIMIC: do_cmd_mimic(); break; case MKEY_POWER_MAGE: do_cmd_powermage(); break; case MKEY_RUNE: do_cmd_runecrafter(); break; case MKEY_FORGING: do_cmd_archer(); break; case MKEY_INCARNATION: do_cmd_possessor(); break; case MKEY_TELEKINESIS: do_cmd_portable_hole(); break; case MKEY_BLADE: do_cmd_blade(); break; case MKEY_SUMMON: do_cmd_summoner(); break; case MKEY_NECRO: do_cmd_necromancer(); break; case MKEY_SYMBIOTIC: do_cmd_symbiotic(); break; case MKEY_TRAP: do_cmd_set_trap(); break; case MKEY_STEAL: do_cmd_steal(); break; case MKEY_DODGE: use_ability_blade(); break; case MKEY_SCHOOL: cast_school_spell(); break; case MKEY_COPY: do_cmd_copy_spell(); break; case MKEY_BOULDER: do_cmd_create_boulder(); break; case MKEY_COMPANION: if (get_skill(SKILL_LORE) >= 12) do_cmd_companion(); else msg_print("You need a skill level of at least 12."); break; case MKEY_PIERCING: do_cmd_set_piercing(); break; default: process_hooks(HOOK_MKEY, "(d)", x_idx); break; } }
/* * Allow user to choose a power (racial / mutation) to activate */ void do_cmd_racial_power(void) { power_desc_type power_desc[36]; int num, ask, i = 0; bool flag, redraw; char choice; char out_val[160]; const mutation_type *mut_ptr; /* Wipe desc */ for (num = 0; num < 36; num++) { strcpy(power_desc[num].name, ""); power_desc[num].number = 0; } /* Reset num */ num = 0; /* Not when we're confused */ if (p_ptr->confused) { msg_print("You are too confused to use any powers!"); p_ptr->energy_use = 0; return; } /* Look for racial powers */ for (i = 0; i < MAX_RACE_POWERS; i++) { mut_ptr = &race_powers[i]; if (mut_ptr->which == p_ptr->prace) { strcpy(power_desc[num].name, mut_ptr->name); power_desc[num].level = mut_ptr->level; power_desc[num].cost = mut_ptr->cost; power_desc[num].fail = 100 - racial_chance(mut_ptr->level, mut_ptr->stat, mut_ptr->diff); power_desc[num].number = -1; power_desc[num++].power = mut_ptr; } } /* Not if we don't have any */ if (num == 0 && !p_ptr->muta1) { msg_print("You have no powers to activate."); p_ptr->energy_use = 0; return; } /* Look for appropriate mutations */ if (p_ptr->muta1) { for (i = 0; i < MUT_PER_SET; i++) { mut_ptr = &mutations[i]; if (p_ptr->muta1 & mut_ptr->which) { strcpy(power_desc[num].name, mut_ptr->name); power_desc[num].level = mut_ptr->level; power_desc[num].cost = mut_ptr->cost; power_desc[num].fail = 100 - racial_chance(mut_ptr->level, mut_ptr->stat, mut_ptr->diff); power_desc[num].number = mut_ptr->which; power_desc[num++].power = mut_ptr; } } } /* Nothing chosen yet */ flag = FALSE; /* No redraw yet */ redraw = FALSE; /* Build a prompt */ (void)strnfmt(out_val, 78, "(Powers %c-%c, *=List, ESC=exit) Use which power? ", I2A(0), (num <= 26) ? I2A(num - 1) : '0' + num - 27); if (!repeat_pull(&i) || i<0 || i>=num) { /* Get a spell from the user */ while (!flag && get_com(out_val, &choice)) { /* Request redraw */ if ((choice == ' ') || (choice == '*') || (choice == '?')) { /* Show the list */ if (!redraw) { byte y = 1, x = 0; int ctr = 0; char dummy[80]; char letter; int x1, y1; strcpy(dummy, ""); /* Show list */ redraw = TRUE; /* Save the screen */ screen_save(); /* Print header(s) */ if (num < 17) prt(" Lv Cost Fail", y++, x); else prt(" Lv Cost Fail Lv Cost Fail", y++, x); /* Print list */ while (ctr < num) { /* letter/number for power selection */ if (ctr < 26) letter = I2A(ctr); else letter = '0' + ctr - 26; x1 = ((ctr < 17) ? x : x + 40); y1 = ((ctr < 17) ? y + ctr : y + ctr - 17); sprintf(dummy, " %c) %-23.23s %2d %4d %3d%%", letter, power_desc[ctr].name, power_desc[ctr].level, power_desc[ctr].cost, power_desc[ctr].fail); prt(dummy, y1, x1); ctr++; } } /* Hide the list */ else { /* Hide list */ redraw = FALSE; /* Restore the screen */ screen_load(); } /* Redo asking */ continue; } if (choice == '\r' && num == 1) { choice = 'a'; } if (isalpha(choice)) { /* Note verify */ ask = (isupper(choice)); /* Lowercase */ if (ask) choice = tolower(choice); /* Extract request */ i = (islower(choice) ? A2I(choice) : -1); } else { ask = FALSE; /* Can't uppercase digits */ i = choice - '0' + 26; } /* Totally Illegal */ if ((i < 0) || (i >= num)) { bell(); continue; } /* Verify it */ if (ask) { char tmp_val[160]; /* Prompt */ (void)strnfmt(tmp_val, 78, "Use %s? ", power_desc[i].name); /* Belay that order */ if (!get_check(tmp_val)) continue; } /* Stop the loop */ flag = TRUE; } /* Restore the screen */ if (redraw) screen_load(); /* Abort if needed */ if (!flag) { p_ptr->energy_use = 0; return; } repeat_push(i); } if (power_desc[i].number == -1) { cmd_racial_power_aux(power_desc[i].power); } else { mutation_power_aux(power_desc[i].power); } /* Success */ return; }
/* Ask & execute a skill */ void do_cmd_activate_skill(s32b type) { s32b x_idx; bool push = TRUE; /* Get the skill, if available */ if (repeat_pull(&x_idx)) { push = FALSE; } else if (!command_arg) x_idx = do_cmd_activate_skill_aux(type); else { s32b i, j; x_idx = command_arg; /* Check validity */ for (i = 1; i < max_s_idx; i++) { if (get_skill(i) && (s_info[i].action_mkey[type] == x_idx)) break; } for (j = 0; j < max_ab_idx; j++) { if (ab_info[j].acquired && (ab_info[j].action_mkey[type] == x_idx)) break; } if ((j == max_ab_idx) && (i == max_s_idx)) { msg_print("Uh?"); return; } } if (x_idx == -1) return; if (push) repeat_push(x_idx); if (!x_idx) { choose_combat(); return; } if (type == ACTIVATE_SKILL) { switch (x_idx) { case MKEY_STEAL: do_cmd_steal(); break; case MKEY_SCHOOL: cast_school_spell(); break; case MKEY_COMPANION: if (get_skill(SKILL_LORE) >= 12) do_cmd_companion(); else msg_print("You need a skill level of at least 12."); break; default: process_hooks(HOOK_MKEY, "(d,d)", x_idx, type); break; } } else if (type == BROWSE_SKILL) { switch (x_idx) { case MKEY_SCHOOL: do_cmd_browse(); break; default: process_hooks(HOOK_MKEY, "(d,d)", x_idx, type); break; } } }
/*! * @brief 使用可能な青魔法を選択する / * Allow user to choose a imitation. * @param sn 選択したモンスター攻撃ID、キャンセルの場合-1、不正な選択の場合-2を返す * @return 発動可能な魔法を選択した場合TRUE、キャンセル処理か不正な選択が行われた場合FALSEを返す。 * @details * If a valid spell is chosen, saves it in '*sn' and returns TRUE\n * If the user hits escape, returns FALSE, and set '*sn' to -1\n * If there are no legal choices, returns FALSE, and sets '*sn' to -2\n *\n * The "prompt" should be "cast", "recite", or "study"\n * The "known" should be TRUE for cast/pray, FALSE for study\n *\n * nb: This function has a (trivial) display bug which will be obvious\n * when you run it. It's probably easy to fix but I haven't tried,\n * sorry.\n */ static int get_learned_power(int *sn) { int i = 0; int num = 0; int y = 1; int x = 18; int minfail = 0; int plev = p_ptr->lev; int chance = 0; int ask = TRUE, mode = 0; int spellnum[MAX_MONSPELLS]; char ch; char choice; char out_val[160]; char comment[80]; s32b f4 = 0, f5 = 0, f6 = 0; cptr p = _("魔法", "magic"); monster_power spell; bool flag, redraw; int menu_line = (use_menu ? 1 : 0); /* Assume cancelled */ *sn = (-1); /* Nothing chosen yet */ flag = FALSE; /* No redraw yet */ redraw = FALSE; #ifdef ALLOW_REPEAT /* TNB */ /* Get the spell, if available */ if (repeat_pull(sn)) { /* Success */ return (TRUE); } #endif /* ALLOW_REPEAT -- TNB */ if (use_menu) { screen_save(); while(!mode) { #ifdef JP prt(format(" %s ボルト", (menu_line == 1) ? "》" : " "), 2, 14); prt(format(" %s ボール", (menu_line == 2) ? "》" : " "), 3, 14); prt(format(" %s ブレス", (menu_line == 3) ? "》" : " "), 4, 14); prt(format(" %s 召喚", (menu_line == 4) ? "》" : " "), 5, 14); prt(format(" %s その他", (menu_line == 5) ? "》" : " "), 6, 14); prt("どの種類の魔法を使いますか?", 0, 0); #else prt(format(" %s bolt", (menu_line == 1) ? "> " : " "), 2, 14); prt(format(" %s ball", (menu_line == 2) ? "> " : " "), 3, 14); prt(format(" %s breath", (menu_line == 3) ? "> " : " "), 4, 14); prt(format(" %s sommoning", (menu_line == 4) ? "> " : " "), 5, 14); prt(format(" %s others", (menu_line == 5) ? "> " : " "), 6, 14); prt("use which type of magic? ", 0, 0); #endif choice = inkey(); switch(choice) { case ESCAPE: case 'z': case 'Z': screen_load(); return FALSE; case '2': case 'j': case 'J': menu_line++; break; case '8': case 'k': case 'K': menu_line+= 4; break; case '\r': case 'x': case 'X': mode = menu_line; break; } if (menu_line > 5) menu_line -= 5; } screen_load(); } else { sprintf(comment, _("[A]ボルト, [B]ボール, [C]ブレス, [D]召喚, [E]その他:", "[A] bolt, [B] ball, [C] breath, [D] summoning, [E] others:")); while (TRUE) { if (!get_com(comment, &ch, TRUE)) { return FALSE; } if (ch == 'A' || ch == 'a') { mode = 1; break; } if (ch == 'B' || ch == 'b') { mode = 2; break; } if (ch == 'C' || ch == 'c') { mode = 3; break; } if (ch == 'D' || ch == 'd') { mode = 4; break; } if (ch == 'E' || ch == 'e') { mode = 5; break; } } } set_rf_masks(&f4, &f5, &f6, mode); for (i = 0, num = 0; i < 32; i++) { if ((0x00000001 << i) & f4) spellnum[num++] = i; } for (; i < 64; i++) { if ((0x00000001 << (i - 32)) & f5) spellnum[num++] = i; } for (; i < 96; i++) { if ((0x00000001 << (i - 64)) & f6) spellnum[num++] = i; } for (i = 0; i < num; i++) { if (p_ptr->magic_num2[spellnum[i]]) { if (use_menu) menu_line = i+1; break; } } if (i == num) { msg_print(_("その種類の魔法は覚えていない!", "You don't know any spell of this type.")); return (FALSE); } /* Build a prompt (accept all spells) */ (void)strnfmt(out_val, 78, _("(%c-%c, '*'で一覧, ESC) どの%sを唱えますか?", "(%c-%c, *=List, ESC=exit) Use which %s? "), I2A(0), I2A(num - 1), p); if (use_menu) screen_save(); /* Get a spell from the user */ choice= (always_show_list || use_menu) ? ESCAPE:1 ; while (!flag) { if(choice==ESCAPE) choice = ' '; else if( !get_com(out_val, &choice, TRUE) )break; if (use_menu && choice != ' ') { switch(choice) { case '0': { screen_load(); return (FALSE); } case '8': case 'k': case 'K': { do { menu_line += (num-1); if (menu_line > num) menu_line -= num; } while(!p_ptr->magic_num2[spellnum[menu_line-1]]); break; } case '2': case 'j': case 'J': { do { menu_line++; if (menu_line > num) menu_line -= num; } while(!p_ptr->magic_num2[spellnum[menu_line-1]]); break; } case '6': case 'l': case 'L': { menu_line=num; while(!p_ptr->magic_num2[spellnum[menu_line-1]]) menu_line--; break; } case '4': case 'h': case 'H': { menu_line=1; while(!p_ptr->magic_num2[spellnum[menu_line-1]]) menu_line++; break; } case 'x': case 'X': case '\r': { i = menu_line - 1; ask = FALSE; break; } } } /* Request redraw */ if ((choice == ' ') || (choice == '*') || (choice == '?') || (use_menu && ask)) { /* Show the list */ if (!redraw || use_menu) { char psi_desc[80]; /* Show list */ redraw = TRUE; /* Save the screen */ if (!use_menu) screen_save(); /* Display a list of spells */ prt("", y, x); put_str(_("名前", "Name"), y, x + 5); put_str(_("MP 失率 効果", "SP Fail Info"), y, x + 33); /* Dump the spells */ for (i = 0; i < num; i++) { int need_mana; prt("", y + i + 1, x); if (!p_ptr->magic_num2[spellnum[i]]) continue; /* Access the spell */ spell = monster_powers[spellnum[i]]; chance = spell.fail; /* Reduce failure rate by "effective" level adjustment */ if (plev > spell.level) chance -= 3 * (plev - spell.level); else chance += (spell.level - plev); /* Reduce failure rate by INT/WIS adjustment */ chance -= 3 * (adj_mag_stat[p_ptr->stat_ind[A_INT]] - 1); chance = mod_spell_chance_1(chance); need_mana = mod_need_mana(monster_powers[spellnum[i]].smana, 0, REALM_NONE); /* Not enough mana to cast */ if (need_mana > p_ptr->csp) { chance += 5 * (need_mana - p_ptr->csp); } /* Extract the minimum failure rate */ minfail = adj_mag_fail[p_ptr->stat_ind[A_INT]]; /* Minimum failure rate */ if (chance < minfail) chance = minfail; /* Stunning makes spells harder */ if (p_ptr->stun > 50) chance += 25; else if (p_ptr->stun) chance += 15; /* Always a 5 percent chance of working */ if (chance > 95) chance = 95; chance = mod_spell_chance_2(chance); /* Get info */ learned_info(comment, spellnum[i]); if (use_menu) { if (i == (menu_line-1)) strcpy(psi_desc, _(" 》", " > ")); else strcpy(psi_desc, " "); } else sprintf(psi_desc, " %c)", I2A(i)); /* Dump the spell --(-- */ strcat(psi_desc, format(" %-26s %3d %3d%%%s", spell.name, need_mana, chance, comment)); prt(psi_desc, y + i + 1, x); } /* Clear the bottom line */ if (y < 22) prt("", y + i + 1, x); } /* Hide the list */ else { /* Hide list */ redraw = FALSE; /* Restore the screen */ screen_load(); } /* Redo asking */ continue; } if (!use_menu) { /* Note verify */ ask = isupper(choice); /* Lowercase */ if (ask) choice = tolower(choice); /* Extract request */ i = (islower(choice) ? A2I(choice) : -1); } /* Totally Illegal */ if ((i < 0) || (i >= num) || !p_ptr->magic_num2[spellnum[i]]) { bell(); continue; } /* Save the spell index */ spell = monster_powers[spellnum[i]]; /* Verify it */ if (ask) { char tmp_val[160]; /* Prompt */ (void) strnfmt(tmp_val, 78, _("%sの魔法を唱えますか?", "Use %s? "), monster_powers[spellnum[i]].name); /* Belay that order */ if (!get_check(tmp_val)) continue; } /* Stop the loop */ flag = TRUE; } /* Restore the screen */ if (redraw) screen_load(); /* Show choices */ p_ptr->window |= (PW_SPELL); /* Window stuff */ window_stuff(); /* Abort if needed */ if (!flag) return (FALSE); /* Save the choice */ (*sn) = spellnum[i]; #ifdef ALLOW_REPEAT /* TNB */ repeat_push(*sn); #endif /* ALLOW_REPEAT -- TNB */ /* Success */ return (TRUE); }