OSDN Git Service

[Refactor] #968 Separated select_spell_index() from get_mind_power()
authorHourier <grapefox.whitelucifer.0408@gmail.com>
Mon, 17 May 2021 13:26:39 +0000 (22:26 +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 dba90f7..60812d1 100644 (file)
@@ -33,6 +33,7 @@ MindPowerGetter::MindPowerGetter(player_type *caster_ptr)
     this->redraw = false;
     this->use_mind = 0;
     this->menu_line = (use_menu ? 1 : 0);
+    this->mind_ptr = NULL;
 }
 
 /*!
@@ -56,17 +57,8 @@ MindPowerGetter::MindPowerGetter(player_type *caster_ptr)
 bool MindPowerGetter::get_mind_power(SPELL_IDX *sn, bool only_browse)
 {
     select_mind_description();
-    COMMAND_CODE code;
-    const mind_power *mind_ptr = &mind_powers[this->use_mind];
-    *sn = -1;
-    if (repeat_pull(&code)) {
-        *sn = (SPELL_IDX)code;
-        if (*sn == INVEN_FORCE)
-            repeat_pull(&code);
-
-        *sn = (SPELL_IDX)code;
-        if (mind_ptr->info[*sn].min_lev <= this->caster_ptr->lev)
-            return true;
+    if (select_spell_index(sn)) {
+        return true;
     }
 
     for (this->index = 0; this->index < MAX_MIND_POWERS; this->index++)
@@ -291,3 +283,21 @@ void MindPowerGetter::select_mind_description()
         break;
     }
 }
+
+bool MindPowerGetter::select_spell_index(SPELL_IDX *sn)
+{
+    COMMAND_CODE code;
+    this->mind_ptr = &mind_powers[this->use_mind];
+    *sn = -1;
+    if (!repeat_pull(&code)) {
+        return false;    
+    }
+
+    *sn = (SPELL_IDX)code;
+    if (*sn == INVEN_FORCE) {
+        (void)repeat_pull(&code);
+    }
+    
+    *sn = (SPELL_IDX)code;
+    return mind_ptr->info[*sn].min_lev <= this->caster_ptr->lev;
+}
index da21259..81a839e 100644 (file)
@@ -2,6 +2,7 @@
 
 #include "system/angband.h"
 
+struct mind_power;
 struct mind_type;
 struct player_type;
 class MindPowerGetter {
@@ -24,6 +25,8 @@ private:
     bool redraw;
     int use_mind;
     int menu_line;
+    const mind_power *mind_ptr;
 
     void select_mind_description();
+    bool select_spell_index(SPELL_IDX *sn);
 };