OSDN Git Service

[Refactor] #2886 再描画フラグの分かりにくい単語や名詞でない単語を分かりやすい名詞にした
[hengbandforosx/hengbandosx.git] / src / cmd-action / cmd-hissatsu.cpp
index aff2cbb..e6823ec 100644 (file)
@@ -9,8 +9,8 @@
  * 2014 Deskull rearranged comment for Doxygen.\n
  */
 
-#include "cmd-action/cmd-spell.h"
 #include "action/action-limited.h"
+#include "cmd-action/cmd-spell.h"
 #include "core/asking-player.h"
 #include "core/player-redraw-types.h"
 #include "core/player-update-types.h"
 #include "main/sound-definitions-table.h"
 #include "main/sound-of-music.h"
 #include "monster-race/monster-race-hook.h"
+#include "object/item-tester-hooker.h"
 #include "object/item-use-flags.h"
+#include "player-base/player-class.h"
+#include "player-info/equipment-info.h"
+#include "player-info/samurai-data-type.h"
+#include "player-status/player-energy.h"
 #include "player/attack-defense-types.h"
-#include "player/player-status.h"
 #include "player/special-defense-types.h"
 #include "spell/spells-execution.h"
 #include "spell/technic-info-table.h"
 #include "status/action-setter.h"
-#include "system/object-type-definition.h"
+#include "system/item-entity.h"
 #include "system/player-type-definition.h"
 #include "term/screen-processor.h"
+#include "term/z-form.h"
 #include "util/int-char-converter.h"
 #include "view/display-messages.h"
 
  * when you run it. It's probably easy to fix but I haven't tried,\n
  * sorry.\n
  */
-static int get_hissatsu_power(player_type *creature_ptr, SPELL_IDX *sn)
+static int get_hissatsu_power(PlayerType *player_ptr, SPELL_IDX *sn)
 {
     SPELL_IDX i;
     int j = 0;
     int num = 0;
     POSITION y = 1;
     POSITION x = 15;
-    PLAYER_LEVEL plev = creature_ptr->lev;
-    int ask = TRUE;
+    PLAYER_LEVEL plev = player_ptr->lev;
     char choice;
     char out_val[160];
     SPELL_IDX sentaku[32];
@@ -84,12 +88,12 @@ static int get_hissatsu_power(player_type *creature_ptr, SPELL_IDX *sn)
         /* Verify the spell */
         if (technic_info[TECHNIC_HISSATSU][*sn].slevel <= plev) {
             /* Success */
-            return TRUE;
+            return true;
         }
     }
 
-    flag = FALSE;
-    redraw = FALSE;
+    flag = false;
+    redraw = false;
 
     for (i = 0; i < 32; i++) {
         if (technic_info[TECHNIC_HISSATSU][i].slevel <= PY_MAX_LEVEL) {
@@ -99,24 +103,27 @@ static int get_hissatsu_power(player_type *creature_ptr, SPELL_IDX *sn)
     }
 
     /* Build a prompt (accept all spells) */
-    (void)strnfmt(out_val, 78, _("(%^s %c-%c, '*'で一覧, ESC) どの%sを使いますか?", "(%^ss %c-%c, *=List, ESC=exit) Use which %s? "), p, I2A(0),
+    (void)strnfmt(out_val, 78, _("(%s^ %c-%c, '*'で一覧, ESC) どの%sを使いますか?", "(%s^s %c-%c, *=List, ESC=exit) Use which %s? "), p, I2A(0),
         "abcdefghijklmnopqrstuvwxyz012345"[num - 1], p);
 
-    if (use_menu)
+    if (use_menu) {
         screen_save();
+    }
     choice = always_show_list ? ESCAPE : 1;
 
     while (!flag) {
-        if (choice == ESCAPE)
+        if (choice == ESCAPE) {
             choice = ' ';
-        else if (!get_com(out_val, &choice, FALSE))
+        } else if (!get_com(out_val, &choice, false)) {
             break;
+        }
 
+        auto should_redraw_cursor = true;
         if (use_menu && choice != ' ') {
             switch (choice) {
             case '0': {
                 screen_load();
-                return FALSE;
+                return false;
             }
 
             case '8':
@@ -124,9 +131,10 @@ static int get_hissatsu_power(player_type *creature_ptr, SPELL_IDX *sn)
             case 'K': {
                 do {
                     menu_line += 31;
-                    if (menu_line > 32)
+                    if (menu_line > 32) {
                         menu_line -= 32;
-                } while (!(creature_ptr->spell_learned1 & (1UL << (menu_line - 1))));
+                    }
+                } while (!(player_ptr->spell_learned1 & (1UL << (menu_line - 1))));
                 break;
             }
 
@@ -135,9 +143,10 @@ static int get_hissatsu_power(player_type *creature_ptr, SPELL_IDX *sn)
             case 'J': {
                 do {
                     menu_line++;
-                    if (menu_line > 32)
+                    if (menu_line > 32) {
                         menu_line -= 32;
-                } while (!(creature_ptr->spell_learned1 & (1UL << (menu_line - 1))));
+                    }
+                } while (!(player_ptr->spell_learned1 & (1UL << (menu_line - 1))));
                 break;
             }
 
@@ -147,23 +156,27 @@ static int get_hissatsu_power(player_type *creature_ptr, SPELL_IDX *sn)
             case '6':
             case 'l':
             case 'L': {
-                bool reverse = FALSE;
-                if ((choice == '4') || (choice == 'h') || (choice == 'H'))
-                    reverse = TRUE;
+                bool reverse = false;
+                if ((choice == '4') || (choice == 'h') || (choice == 'H')) {
+                    reverse = true;
+                }
                 if (menu_line > 16) {
                     menu_line -= 16;
-                    reverse = TRUE;
-                } else
+                    reverse = true;
+                } else {
                     menu_line += 16;
-                while (!(creature_ptr->spell_learned1 & (1UL << (menu_line - 1)))) {
+                }
+                while (!(player_ptr->spell_learned1 & (1UL << (menu_line - 1)))) {
                     if (reverse) {
                         menu_line--;
-                        if (menu_line < 2)
-                            reverse = FALSE;
+                        if (menu_line < 2) {
+                            reverse = false;
+                        }
                     } else {
                         menu_line++;
-                        if (menu_line > 31)
-                            reverse = TRUE;
+                        if (menu_line > 31) {
+                            reverse = true;
+                        }
                     }
                 }
                 break;
@@ -174,20 +187,20 @@ static int get_hissatsu_power(player_type *creature_ptr, SPELL_IDX *sn)
             case '\r':
             case '\n': {
                 i = menu_line - 1;
-                ask = FALSE;
+                should_redraw_cursor = false;
                 break;
             }
             }
         }
         /* Request redraw */
-        if ((choice == ' ') || (choice == '*') || (choice == '?') || (use_menu && ask)) {
+        if ((choice == ' ') || (choice == '*') || (choice == '?') || (use_menu && should_redraw_cursor)) {
             /* Show the list */
             if (!redraw || use_menu) {
-                char psi_desc[80];
                 int line;
-                redraw = TRUE;
-                if (!use_menu)
+                redraw = true;
+                if (!use_menu) {
                     screen_save();
+                }
 
                 /* Display a list of spells */
                 prt("", y, x);
@@ -197,34 +210,42 @@ static int get_hissatsu_power(player_type *creature_ptr, SPELL_IDX *sn)
                 for (i = 0, line = 0; i < 32; i++) {
                     spell = technic_info[TECHNIC_HISSATSU][i];
 
-                    if (spell.slevel > PY_MAX_LEVEL)
+                    if (spell.slevel > PY_MAX_LEVEL) {
                         continue;
+                    }
                     line++;
-                    if (!(creature_ptr->spell_learned1 >> i))
+                    if (!(player_ptr->spell_learned1 >> i)) {
                         break;
+                    }
 
                     /* Access the spell */
-                    if (spell.slevel > plev)
+                    if (spell.slevel > plev) {
                         continue;
-                    if (!(creature_ptr->spell_learned1 & (1UL << i)))
+                    }
+                    if (!(player_ptr->spell_learned1 & (1UL << i))) {
                         continue;
+                    }
+                    std::string psi_desc;
                     if (use_menu) {
-                        if (i == (menu_line - 1))
-                            strcpy(psi_desc, _("  》", "  > "));
-                        else
-                            strcpy(psi_desc, "    ");
+                        if (i == (menu_line - 1)) {
+                            psi_desc = _("  》", "  > ");
+                        } else {
+                            psi_desc = "    ";
+                        }
 
                     } else {
                         char letter;
-                        if (line <= 26)
+                        if (line <= 26) {
                             letter = I2A(line - 1);
-                        else
+                        } else {
                             letter = '0' + line - 27;
-                        sprintf(psi_desc, "  %c)", letter);
+                        }
+                        psi_desc = format("  %c)", letter);
                     }
 
                     /* Dump the spell --(-- */
-                    strcat(psi_desc, format(" %-18s%2d %3d", exe_spell(creature_ptr, REALM_HISSATSU, i, SPELL_NAME), spell.slevel, spell.smana));
+                    const auto spell_name = exe_spell(player_ptr, REALM_HISSATSU, i, SpellProcessType::NAME);
+                    psi_desc.append(format(" %-18s%2d %3d", spell_name->data(), spell.slevel, spell.smana));
                     prt(psi_desc, y + (line % 17) + (line >= 17), x + (line / 17) * 30);
                     prt("", y + (line % 17) + (line >= 17) + 1, x + (line / 17) * 30);
                 }
@@ -233,7 +254,7 @@ static int get_hissatsu_power(player_type *creature_ptr, SPELL_IDX *sn)
             /* Hide the list */
             else {
                 /* Hide list */
-                redraw = FALSE;
+                redraw = false;
                 screen_load();
             }
 
@@ -243,54 +264,34 @@ static int get_hissatsu_power(player_type *creature_ptr, SPELL_IDX *sn)
 
         if (!use_menu) {
             if (isalpha(choice)) {
-                /* Note verify */
-                ask = (isupper(choice));
-
-                /* Lowercase */
-                if (ask)
-                    choice = (char)tolower(choice);
-
-                /* Extract request */
-                i = (islower(choice) ? A2I(choice) : -1);
+                i = A2I(choice);
             } else {
-                ask = FALSE; /* Can't uppercase digits */
-
                 i = choice - '0' + 26;
             }
         }
 
         /* Totally Illegal */
-        if ((i < 0) || (i >= 32) || !(creature_ptr->spell_learned1 & (1U << sentaku[i]))) {
+        if ((i < 0) || (i >= 32) || !(player_ptr->spell_learned1 & (1U << sentaku[i]))) {
             bell();
             continue;
         }
 
         j = sentaku[i];
 
-        /* Verify it */
-        if (ask) {
-            char tmp_val[160];
-
-            /* Prompt */
-            (void)strnfmt(tmp_val, 78, _("%sを使いますか?", "Use %s? "), exe_spell(creature_ptr, REALM_HISSATSU, j, SPELL_NAME));
-
-            /* Belay that order */
-            if (!get_check(tmp_val))
-                continue;
-        }
-
         /* Stop the loop */
-        flag = TRUE;
+        flag = true;
     }
-    if (redraw)
+    if (redraw) {
         screen_load();
+    }
 
-    creature_ptr->window_flags |= (PW_SPELL);
-    handle_stuff(creature_ptr);
+    player_ptr->window_flags |= (PW_SPELL);
+    handle_stuff(player_ptr);
 
     /* Abort if needed */
-    if (!flag)
-        return FALSE;
+    if (!flag) {
+        return false;
+    }
 
     /* Save the choice */
     (*sn) = j;
@@ -298,131 +299,131 @@ static int get_hissatsu_power(player_type *creature_ptr, SPELL_IDX *sn)
     repeat_push((COMMAND_CODE)j);
 
     /* Success */
-    return TRUE;
+    return true;
 }
 
 /*!
  * @brief 剣術コマンドのメインルーチン
- * @return なし
  */
-void do_cmd_hissatsu(player_type *creature_ptr)
+void do_cmd_hissatsu(PlayerType *player_ptr)
 {
     SPELL_IDX n = 0;
     magic_type spell;
 
-    if (cmd_limit_confused(creature_ptr))
+    if (cmd_limit_confused(player_ptr)) {
         return;
-    if (!has_melee_weapon(creature_ptr, INVEN_MAIN_HAND) && !has_melee_weapon(creature_ptr, INVEN_SUB_HAND)) {
-        if (flush_failure)
+    }
+    if (!has_melee_weapon(player_ptr, INVEN_MAIN_HAND) && !has_melee_weapon(player_ptr, INVEN_SUB_HAND)) {
+        if (flush_failure) {
             flush();
+        }
         msg_print(_("武器を持たないと必殺技は使えない!", "You need to wield a weapon!"));
         return;
     }
-    if (!creature_ptr->spell_learned1) {
+    if (!player_ptr->spell_learned1) {
         msg_print(_("何も技を知らない。", "You don't know any special attacks."));
         return;
     }
 
-    if (creature_ptr->special_defense & KATA_MASK) {
-        set_action(creature_ptr, ACTION_NONE);
-    }
+    PlayerClass(player_ptr).break_samurai_stance({ SamuraiStanceType::MUSOU, SamuraiStanceType::IAI, SamuraiStanceType::FUUJIN, SamuraiStanceType::KOUKIJIN });
 
-    if (!get_hissatsu_power(creature_ptr, &n))
+    if (!get_hissatsu_power(player_ptr, &n)) {
         return;
+    }
 
     spell = technic_info[TECHNIC_HISSATSU][n];
 
     /* Verify "dangerous" spells */
-    if (spell.smana > creature_ptr->csp) {
-        if (flush_failure)
+    if (spell.smana > player_ptr->csp) {
+        if (flush_failure) {
             flush();
+        }
         /* Warning */
         msg_print(_("MPが足りません。", "You do not have enough mana to use this power."));
-        msg_print(NULL);
+        msg_print(nullptr);
         return;
     }
 
     sound(SOUND_ZAP);
 
-    if (!exe_spell(creature_ptr, REALM_HISSATSU, n, SPELL_CAST))
+    if (!exe_spell(player_ptr, REALM_HISSATSU, n, SpellProcessType::CAST)) {
         return;
+    }
 
-    take_turn(creature_ptr, 100);
+    PlayerEnergy(player_ptr).set_player_turn_energy(100);
 
     /* Use some mana */
-    creature_ptr->csp -= spell.smana;
+    player_ptr->csp -= spell.smana;
 
     /* Limit */
-    if (creature_ptr->csp < 0)
-        creature_ptr->csp = 0;
-    creature_ptr->redraw |= (PR_MANA);
-    creature_ptr->window_flags |= (PW_PLAYER | PW_SPELL);
+    if (player_ptr->csp < 0) {
+        player_ptr->csp = 0;
+    }
+    player_ptr->redraw |= (PR_MP);
+    player_ptr->window_flags |= (PW_PLAYER | PW_SPELL);
 }
 
 /*!
  * @brief 剣術コマンドの学習
- * @return なし
  */
-void do_cmd_gain_hissatsu(player_type *creature_ptr)
+void do_cmd_gain_hissatsu(PlayerType *player_ptr)
 {
-    OBJECT_IDX item;
-    int i, j;
-
-    object_type *o_ptr;
-    concptr q, s;
-
-    bool gain = FALSE;
-
-    if (creature_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN)) {
-        set_action(creature_ptr, ACTION_NONE);
-    }
-
-    if (cmd_limit_blind(creature_ptr))
-        return;
-    if (cmd_limit_confused(creature_ptr))
+    PlayerClass(player_ptr).break_samurai_stance({ SamuraiStanceType::MUSOU, SamuraiStanceType::KOUKIJIN });
+    if (cmd_limit_blind(player_ptr) || cmd_limit_confused(player_ptr)) {
         return;
+    }
 
-    if (!(creature_ptr->new_spells)) {
+    if (!(player_ptr->new_spells)) {
         msg_print(_("新しい必殺技を覚えることはできない!", "You cannot learn any new special attacks!"));
         return;
     }
 
 #ifdef JP
-    msg_format("あと %d 種の必殺技を学べる。", creature_ptr->new_spells);
+    msg_format("あと %d 種の必殺技を学べる。", player_ptr->new_spells);
 #else
-    msg_format("You can learn %d new special attack%s.", creature_ptr->new_spells, (creature_ptr->new_spells == 1 ? "" : "s"));
+    msg_format("You can learn %d new special attack%s.", player_ptr->new_spells, (player_ptr->new_spells == 1 ? "" : "s"));
 #endif
 
-    q = _("どの書から学びますか? ", "Study which book? ");
-    s = _("読める書がない。", "You have no books that you can read.");
-
-    o_ptr = choose_object(creature_ptr, &item, q, s, (USE_INVEN | USE_FLOOR), TV_HISSATSU_BOOK);
-    if (!o_ptr)
+    const auto q = _("どの書から学びますか? ", "Study which book? ");
+    const auto s = _("読める書がない。", "You have no books that you can read.");
+    short item;
+    const auto *o_ptr = choose_object(player_ptr, &item, q, s, (USE_INVEN | USE_FLOOR), TvalItemTester(ItemKindType::HISSATSU_BOOK));
+    if (o_ptr == nullptr) {
         return;
+    }
 
-    for (i = o_ptr->sval * 8; i < o_ptr->sval * 8 + 8; i++) {
-        if (creature_ptr->spell_learned1 & (1UL << i))
+    const auto sval = o_ptr->bi_key.sval().value();
+    auto gain = false;
+    for (auto i = sval * 8; i < sval * 8 + 8; i++) {
+        if (player_ptr->spell_learned1 & (1UL << i)) {
             continue;
-        if (technic_info[TECHNIC_HISSATSU][i].slevel > creature_ptr->lev)
+        }
+
+        if (technic_info[TECHNIC_HISSATSU][i].slevel > player_ptr->lev) {
             continue;
+        }
 
-        creature_ptr->spell_learned1 |= (1UL << i);
-        creature_ptr->spell_worked1 |= (1UL << i);
-        msg_format(_("%sの技を覚えた。", "You have learned the special attack of %s."), exe_spell(creature_ptr, REALM_HISSATSU, i, SPELL_NAME));
+        player_ptr->spell_learned1 |= (1UL << i);
+        player_ptr->spell_worked1 |= (1UL << i);
+        const auto spell_name = exe_spell(player_ptr, REALM_HISSATSU, i, SpellProcessType::NAME);
+        msg_format(_("%sの技を覚えた。", "You have learned the special attack of %s."), spell_name->data());
+        int j;
         for (j = 0; j < 64; j++) {
             /* Stop at the first empty space */
-            if (creature_ptr->spell_order[j] == 99)
+            if (player_ptr->spell_order[j] == 99) {
                 break;
+            }
         }
-        creature_ptr->spell_order[j] = i;
-        gain = TRUE;
+
+        player_ptr->spell_order[j] = i;
+        gain = true;
     }
 
     if (!gain) {
         msg_print(_("何も覚えられなかった。", "You were not able to learn any special attacks."));
     } else {
-        take_turn(creature_ptr, 100);
+        PlayerEnergy(player_ptr).set_player_turn_energy(100);
     }
 
-    creature_ptr->update |= (PU_SPELLS);
+    player_ptr->update |= (PU_SPELLS);
 }