OSDN Git Service

[Refactor] #968 MindPowerGetterクラスにフィールド変数を定義した / Defined private variables in MindPo...
authorHourier <grapefox.whitelucifer.0408@gmail.com>
Mon, 17 May 2021 13:11:44 +0000 (22:11 +0900)
committerHourier <grapefox.whitelucifer.0408@gmail.com>
Mon, 17 May 2021 14:45:29 +0000 (23:45 +0900)
src/mind/mind-power-getter.cpp
src/mind/mind-power-getter.h

index f472d21..0078e5b 100644 (file)
 MindPowerGetter::MindPowerGetter(player_type *caster_ptr)
 {
     this->caster_ptr = caster_ptr;
+    this->index = 0;
+    this->num = 0;
+    this->y = 1;
+    this->x = 10;
+    this->ask = true;
+    this->choice = 0;
+    this->mind_description = "";
+    this->spell = NULL;
+    this->flag = false;
+    this->redraw = false;
+    this->use_mind = 0;
+    this->menu_line = (use_menu ? 1 : 0);
 }
 
 /*!
  * @brief 使用可能な特殊技能を選択する /
  * Allow user to choose a mindcrafter power.
  * @param sn 選択した特殊技能ID、キャンセルの場合-1、不正な選択の場合-2を返す
- * @param only_browse 一覧を見るだけの場合TRUEを返す
- * @return 発動可能な魔法を選択した場合TRUE、キャンセル処理か不正な選択が行われた場合FALSEを返す。
+ * @param only_browse 一覧を見るだけの場合trueを返す
+ * @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
+ * 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
+ * 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
@@ -43,59 +55,41 @@ MindPowerGetter::MindPowerGetter(player_type *caster_ptr)
  */
 bool MindPowerGetter::get_mind_power(SPELL_IDX *sn, bool only_browse)
 {
-    SPELL_IDX i;
-    int num = 0;
-    TERM_LEN y = 1;
-    TERM_LEN x = 10;
-    PERCENTAGE minfail = 0;
-    PLAYER_LEVEL plev = this->caster_ptr->lev;
-    PERCENTAGE chance = 0;
-    int ask = TRUE;
-    char choice;
-    char out_val[160];
-    char comment[80];
-    concptr p;
-    COMMAND_CODE code;
-    mind_type spell;
-    const mind_power *mind_ptr;
-    bool flag, redraw;
-    int use_mind;
-    int menu_line = (use_menu ? 1 : 0);
-
     switch (this->caster_ptr->pclass) {
     case CLASS_MINDCRAFTER: {
-        use_mind = MIND_MINDCRAFTER;
-        p = _("超能力", "mindcraft");
+        this->use_mind = (int)MIND_MINDCRAFTER;
+        this->mind_description = _("超能力", "mindcraft");
         break;
     }
     case CLASS_FORCETRAINER: {
-        use_mind = MIND_KI;
-        p = _("練気術", "Force");
+        this->use_mind = (int)MIND_KI;
+        this->mind_description = _("練気術", "Force");
         break;
     }
     case CLASS_BERSERKER: {
-        use_mind = MIND_BERSERKER;
-        p = _("技", "brutal power");
+        this->use_mind = (int)MIND_BERSERKER;
+        this->mind_description = _("技", "brutal power");
         break;
     }
     case CLASS_MIRROR_MASTER: {
-        use_mind = MIND_MIRROR_MASTER;
-        p = _("鏡魔法", "magic");
+        this->use_mind = (int)MIND_MIRROR_MASTER;
+        this->mind_description = _("鏡魔法", "magic");
         break;
     }
     case CLASS_NINJA: {
-        use_mind = MIND_NINJUTSU;
-        p = _("忍術", "ninjutsu");
+        this->use_mind = (int)MIND_NINJUTSU;
+        this->mind_description = _("忍術", "ninjutsu");
         break;
     }
     default: {
-        use_mind = 0;
-        p = _("超能力", "mindcraft");
+        this->use_mind = 0;
+        this->mind_description = _("超能力", "mindcraft");
         break;
     }
     }
 
-    mind_ptr = &mind_powers[use_mind];
+    COMMAND_CODE code;
+    const mind_power *mind_ptr = &mind_powers[this->use_mind];
     *sn = -1;
     if (repeat_pull(&code)) {
         *sn = (SPELL_IDX)code;
@@ -103,94 +97,92 @@ bool MindPowerGetter::get_mind_power(SPELL_IDX *sn, bool only_browse)
             repeat_pull(&code);
 
         *sn = (SPELL_IDX)code;
-        if (mind_ptr->info[*sn].min_lev <= plev)
-            return TRUE;
+        if (mind_ptr->info[*sn].min_lev <= this->caster_ptr->lev)
+            return true;
     }
 
-    flag = FALSE;
-    redraw = FALSE;
-
-    for (i = 0; i < MAX_MIND_POWERS; i++)
-        if (mind_ptr->info[i].min_lev <= plev)
-            num++;
+    for (this->index = 0; this->index < MAX_MIND_POWERS; this->index++)
+        if (mind_ptr->info[this->index].min_lev <= this->caster_ptr->lev)
+            this->num++;
 
+    char out_val[160];
     if (only_browse)
-        (void)strnfmt(out_val, 78, _("(%^s %c-%c, '*'で一覧, ESC) どの%sについて知りますか?", "(%^ss %c-%c, *=List, ESC=exit) Use which %s? "), p, I2A(0),
-            I2A(num - 1), p);
+        (void)strnfmt(out_val, 78, _("(%^s %c-%c, '*'で一覧, ESC) どの%sについて知りますか?", "(%^ss %c-%c, *=List, ESC=exit) Use which %s? "), this->mind_description, I2A(0),
+            I2A(this->num - 1), this->mind_description);
     else
         (void)strnfmt(
-            out_val, 78, _("(%^s %c-%c, '*'で一覧, ESC) どの%sを使いますか?", "(%^ss %c-%c, *=List, ESC=exit) Use which %s? "), p, I2A(0), I2A(num - 1), p);
+            out_val, 78, _("(%^s %c-%c, '*'で一覧, ESC) どの%sを使いますか?", "(%^ss %c-%c, *=List, ESC=exit) Use which %s? "), this->mind_description, I2A(0), I2A(this->num - 1), this->mind_description);
 
     if (use_menu && !only_browse)
         screen_save();
 
-    choice = (always_show_list || use_menu) ? ESCAPE : 1;
-    while (!flag) {
-        if (choice == ESCAPE)
-            choice = ' ';
-        else if (!get_com(out_val, &choice, TRUE))
+    this->choice = (always_show_list || use_menu) ? ESCAPE : 1;
+    while (!this->flag) {
+        if (this->choice == ESCAPE)
+            this->choice = ' ';
+        else if (!get_com(out_val, &this->choice, true))
             break;
 
-        if (use_menu && choice != ' ') {
-            switch (choice) {
+        if (use_menu && this->choice != ' ') {
+            switch (this->choice) {
             case '0': {
                 if (!only_browse)
                     screen_load();
 
-                return FALSE;
+                return false;
             }
             case '8':
             case 'k':
             case 'K': {
-                menu_line += (num - 1);
+                this->menu_line += (this->num - 1);
                 break;
             }
             case '2':
             case 'j':
             case 'J': {
-                menu_line++;
+                this->menu_line++;
                 break;
             }
             case 'x':
             case 'X':
             case '\r':
             case '\n': {
-                i = menu_line - 1;
-                ask = FALSE;
+                this->index = this->menu_line - 1;
+                this->ask = false;
                 break;
             }
             }
 
-            if (menu_line > num)
-                menu_line -= num;
+            if (this->menu_line > this->num)
+                this->menu_line -= this->num;
         }
 
-        if ((choice == ' ') || (choice == '*') || (choice == '?') || (use_menu && ask)) {
-            if (!redraw || use_menu) {
+        if ((this->choice == ' ') || (this->choice == '*') || (this->choice == '?') || (use_menu && this->ask)) {
+            if (!this->redraw || use_menu) {
                 char psi_desc[80];
                 bool has_weapon[2];
-                redraw = TRUE;
+                this->redraw = true;
                 if (!only_browse && !use_menu)
                     screen_save();
 
                 prt("", y, x);
                 put_str(_("名前", "Name"), y, x + 5);
-                put_str(format(_("Lv   %s   失率 効果", "Lv   %s   Fail Info"), ((use_mind == MIND_BERSERKER) || (use_mind == MIND_NINJUTSU)) ? "HP" : "MP"), y,
+                put_str(format(_("Lv   %s   失率 効果", "Lv   %s   Fail Info"), ((this->use_mind == MIND_BERSERKER) || (this->use_mind == MIND_NINJUTSU)) ? "HP" : "MP"), y,
                     x + 35);
                 has_weapon[0] = has_melee_weapon(this->caster_ptr, INVEN_MAIN_HAND);
                 has_weapon[1] = has_melee_weapon(this->caster_ptr, INVEN_SUB_HAND);
-                for (i = 0; i < MAX_MIND_POWERS; i++) {
+                for (this->index = 0; this->index < MAX_MIND_POWERS; this->index++) {
                     int mana_cost;
-                    spell = mind_ptr->info[i];
-                    if (spell.min_lev > plev)
+                    this->spell = &mind_ptr->info[this->index];
+                    if (this->spell->min_lev > this->caster_ptr->lev)
                         break;
 
-                    chance = spell.fail;
-                    mana_cost = spell.mana_cost;
+                    PERCENTAGE chance = this->spell->fail;
+                    mana_cost = this->spell->mana_cost;
                     if (chance) {
-                        chance -= 3 * (plev - spell.min_lev);
+                        chance -= 3 * (this->caster_ptr->lev - this->spell->min_lev);
                         chance -= 3 * (adj_mag_stat[this->caster_ptr->stat_index[mp_ptr->spell_stat]] - 1);
-                        if (use_mind == MIND_KI) {
+                        if (this->use_mind == MIND_KI) {
                             if (heavy_armor(this->caster_ptr))
                                 chance += 20;
 
@@ -204,18 +196,18 @@ bool MindPowerGetter::get_mind_power(SPELL_IDX *sn, bool only_browse)
                             else if (has_weapon[1])
                                 chance += 10;
 
-                            if (i == 5) {
+                            if (this->index == 5) {
                                 int j;
                                 for (j = 0; j < get_current_ki(this->caster_ptr) / 50; j++)
                                     mana_cost += (j + 1) * 3 / 2;
                             }
                         }
 
-                        if ((use_mind != MIND_BERSERKER) && (use_mind != MIND_NINJUTSU) && (mana_cost > this->caster_ptr->csp))
+                        if ((this->use_mind != MIND_BERSERKER) && (this->use_mind != MIND_NINJUTSU) && (mana_cost > this->caster_ptr->csp))
                             chance += 5 * (mana_cost - this->caster_ptr->csp);
 
                         chance += this->caster_ptr->to_m_chance;
-                        minfail = adj_mag_fail[this->caster_ptr->stat_index[mp_ptr->spell_stat]];
+                        PERCENTAGE minfail = adj_mag_fail[this->caster_ptr->stat_index[mp_ptr->spell_stat]];
                         if (chance < minfail)
                             chance = minfail;
 
@@ -224,7 +216,7 @@ bool MindPowerGetter::get_mind_power(SPELL_IDX *sn, bool only_browse)
                         else if (this->caster_ptr->stun)
                             chance += 15;
 
-                        if (use_mind == MIND_KI) {
+                        if (this->use_mind == MIND_KI) {
                             if (heavy_armor(this->caster_ptr))
                                 chance += 5;
                             if (this->caster_ptr->icky_wield[0])
@@ -237,24 +229,25 @@ bool MindPowerGetter::get_mind_power(SPELL_IDX *sn, bool only_browse)
                             chance = 95;
                     }
 
-                    mindcraft_info(this->caster_ptr, comment, use_mind, i);
+                    char comment[80];
+                    mindcraft_info(this->caster_ptr, comment, this->use_mind, this->index);
                     if (use_menu) {
-                        if (i == (menu_line - 1))
+                        if (this->index == (this->menu_line - 1))
                             strcpy(psi_desc, _("  》 ", "  >  "));
                         else
                             strcpy(psi_desc, "     ");
                     } else
-                        sprintf(psi_desc, "  %c) ", I2A(i));
+                        sprintf(psi_desc, "  %c) ", I2A(this->index));
 
                     strcat(psi_desc,
-                        format("%-30s%2d %4d%s %3d%%%s", spell.name, spell.min_lev, mana_cost,
-                            (((use_mind == MIND_MINDCRAFTER) && (i == 13)) ? _("~", "~ ") : "  "), chance, comment));
-                    prt(psi_desc, y + i + 1, x);
+                        format("%-30s%2d %4d%s %3d%%%s", this->spell->name, this->spell->min_lev, mana_cost,
+                            (((this->use_mind == MIND_MINDCRAFTER) && (this->index == 13)) ? _("~", "~ ") : "  "), chance, comment));
+                    prt(psi_desc, y + this->index + 1, x);
                 }
 
-                prt("", y + i + 1, x);
+                prt("", y + this->index + 1, x);
             } else if (!only_browse) {
-                redraw = FALSE;
+                this->redraw = false;
                 screen_load();
             }
 
@@ -262,38 +255,38 @@ bool MindPowerGetter::get_mind_power(SPELL_IDX *sn, bool only_browse)
         }
 
         if (!use_menu) {
-            ask = isupper(choice);
-            if (ask)
-                choice = (char)tolower(choice);
+            this->ask = (bool)isupper(this->choice);
+            if (this->ask)
+                this->choice = (char)tolower(this->choice);
 
-            i = (islower(choice) ? A2I(choice) : -1);
+            this->index = (islower(this->choice) ? A2I(this->choice) : -1);
         }
 
-        if ((i < 0) || (i >= num)) {
+        if ((this->index < 0) || (this->index >= this->num)) {
             bell();
             continue;
         }
 
-        spell = mind_ptr->info[i];
-        if (ask) {
+        this->spell = &mind_ptr->info[this->index];
+        if (this->ask) {
             char tmp_val[160];
-            (void)strnfmt(tmp_val, 78, _("%sを使いますか?", "Use %s? "), spell.name);
+            (void)strnfmt(tmp_val, 78, _("%sを使いますか?", "Use %s? "), this->spell->name);
             if (!get_check(tmp_val))
                 continue;
         }
 
-        flag = TRUE;
+        this->flag = true;
     }
 
-    if (redraw && !only_browse)
+    if (this->redraw && !only_browse)
         screen_load();
 
     this->caster_ptr->window_flags |= PW_SPELL;
     handle_stuff(this->caster_ptr);
-    if (!flag)
-        return FALSE;
+    if (!this->flag)
+        return false;
 
-    *sn = i;
-    repeat_push((COMMAND_CODE)i);
-    return TRUE;
+    *sn = this->index;
+    repeat_push((COMMAND_CODE)this->index);
+    return true;
 }
index d26dae8..4606a36 100644 (file)
@@ -2,6 +2,7 @@
 
 #include "system/angband.h"
 
+struct mind_type;
 struct player_type;
 class MindPowerGetter {
 public:
@@ -11,4 +12,16 @@ public:
 
 private:
     player_type *caster_ptr;
+    SPELL_IDX index;
+    int num;
+    TERM_LEN y;
+    TERM_LEN x;
+    bool ask;
+    char choice;
+    concptr mind_description;
+    const mind_type *spell;
+    bool flag;
+    bool redraw;
+    int use_mind;
+    int menu_line;
 };