OSDN Git Service

[Refactor] #963 Separated PlayerAlignment class from player-status.h
authorHourier <grapefox.whitelucifer.0408@gmail.com>
Thu, 29 Apr 2021 05:40:19 +0000 (14:40 +0900)
committerHourier <grapefox.whitelucifer.0408@gmail.com>
Thu, 29 Apr 2021 09:39:44 +0000 (18:39 +0900)
Hengband/Hengband/Hengband.vcxproj
Hengband/Hengband/Hengband.vcxproj.filters
src/Makefile.am
src/io-dump/character-dump.cpp
src/knowledge/knowledge-self.cpp
src/player-info/alignment.cpp [new file with mode: 0644]
src/player-info/alignment.h [new file with mode: 0644]
src/player/player-status.cpp
src/player/player-status.h
src/view/display-player.cpp
src/view/display-self-info.cpp

index b586a60..afb2c0a 100644 (file)
     <ClCompile Include="..\..\src\cmd-action\cmd-tunnel.cpp" />\r
     <ClCompile Include="..\..\src\action\movement-execution.cpp" />\r
     <ClCompile Include="..\..\src\main-win\graphics-win.cpp" />\r
+    <ClCompile Include="..\..\src\player-info\alignment.cpp" />\r
     <ClCompile Include="..\..\src\player-status\player-energy.cpp" />\r
     <ClCompile Include="..\..\src\store\cmd-store.cpp" />\r
     <ClCompile Include="..\..\src\cmd-io\cmd-floor.cpp" />\r
     <ClInclude Include="..\..\src\action\movement-execution.h" />\r
     <ClInclude Include="..\..\src\main-win\graphics-win.h" />\r
     <ClInclude Include="..\..\src\main-win\string-win.h" />\r
+    <ClInclude Include="..\..\src\player-info\alignment.h" />\r
     <ClInclude Include="..\..\src\player-status\player-energy.h" />\r
     <ClInclude Include="..\..\src\player-status\player-hand-types.h" />\r
     <ClInclude Include="..\..\src\store\cmd-store.h" />\r
index 5c61858..3819848 100644 (file)
     <ClCompile Include="..\..\src\player-status\player-energy.cpp">\r
       <Filter>player-status</Filter>\r
     </ClCompile>\r
+    <ClCompile Include="..\..\src\player-info\alignment.cpp">\r
+      <Filter>player-info</Filter>\r
+    </ClCompile>\r
   </ItemGroup>\r
   <ItemGroup>\r
     <ClInclude Include="..\..\src\combat\shoot.h">\r
     <ClInclude Include="..\..\src\hpmp\hp-mp-regenerator.h">\r
       <Filter>hpmp</Filter>\r
     </ClInclude>\r
-    <ClInclude Include="..\..\src\main-win\tile-info.h" />\r
     <ClInclude Include="..\..\src\player-status\player-energy.h">\r
       <Filter>player-status</Filter>\r
     </ClInclude>\r
+    <ClInclude Include="..\..\src\player-info\alignment.h">\r
+      <Filter>player-info</Filter>\r
+    </ClInclude>\r
   </ItemGroup>\r
   <ItemGroup>\r
     <None Include="..\..\src\wall.bmp" />\r
index 8551f65..688135b 100644 (file)
@@ -647,6 +647,7 @@ hengband_SOURCES = \
        player-info/body-improvement-info.cpp player-info/body-improvement-info.h \
        player-info/class-ability-info.cpp player-info/class-ability-info.h \
        player-info/mutation-info.cpp player-info/mutation-info.h \
+       player-info/alignment.cpp player-info/alignment.h \
        player-info/race-ability-info.cpp player-info/race-ability-info.h \
        player-info/resistance-info.cpp player-info/resistance-info.h \
        player-info/self-info.cpp player-info/self-info.h \
index fb072ff..19a41f7 100644 (file)
@@ -27,9 +27,9 @@
 #include "object/object-info.h"
 #include "pet/pet-util.h"
 #include "player-info/avatar.h"
+#include "player-info/alignment.h"
 #include "player/player-status-flags.h"
 #include "player/player-status-table.h"
-#include "player/player-status.h"
 #include "player/race-info-table.h"
 #include "realm/realm-names-table.h"
 #include "store/store-util.h"
@@ -452,7 +452,8 @@ static void dump_aux_virtues(player_type *creature_ptr, FILE *fff)
             fprintf(fff, "%s ???\n", stat_names[v_nr]);
     }
 
-    std::string alg = your_alignment(creature_ptr);
+    std::unique_ptr<PlayerAlignment> alignment(new PlayerAlignment(creature_ptr));
+    std::string alg = alignment->your_alignment();
     fprintf(fff, _("\n属性 : %s\n", "\nYour alignment : %s\n"), alg.c_str());
     fprintf(fff, "\n");
     dump_virtues(creature_ptr, fff);
index 403b279..2c66aa2 100644 (file)
@@ -4,6 +4,8 @@
  * @author Hourier
  */
 
+#include <cstdlib>
+
 #include "knowledge-self.h"
 #include "birth/birth-explanations-table.h"
 #include "core/show-file.h"
 #include "info-reader/fixed-map-parser.h"
 #include "io-dump/dump-util.h"
 #include "player-info/avatar.h"
+#include "player-info/alignment.h"
 #include "player/player-class.h"
 #include "player/player-status-table.h"
 #include "player/race-info-table.h"
-#include "player/player-status.h"
 #include "store/store-util.h"
 #include "system/object-type-definition.h"
 #include "system/player-type-definition.h"
@@ -36,7 +38,8 @@ void do_cmd_knowledge_virtues(player_type *creature_ptr)
     if (!open_temporary_file(&fff, file_name))
         return;
 
-    std::string alg = your_alignment(creature_ptr);
+    std::unique_ptr<PlayerAlignment> alignment(new PlayerAlignment(creature_ptr));
+    std::string alg = alignment->your_alignment();
     fprintf(fff, _("現在の属性 : %s\n\n", "Your alignment : %s\n\n"), alg.c_str());
     dump_virtues(creature_ptr, fff);
     angband_fclose(fff);
diff --git a/src/player-info/alignment.cpp b/src/player-info/alignment.cpp
new file mode 100644 (file)
index 0000000..2bd4210
--- /dev/null
@@ -0,0 +1,45 @@
+#include "player-info/alignment.h"
+#include "game-option/text-display-options.h"
+#include "system/player-type-definition.h"
+
+PlayerAlignment::PlayerAlignment(player_type *creature_ptr)
+{
+    this->creature_ptr = creature_ptr;
+}
+
+/*!
+ * @brief クリーチャーの抽象的善悪アライメントの表記名のみを返す。 / Return only alignment title
+ * @param creature_ptr 算出するクリーチャーの参照ポインタ。
+ * @return アライメントの表記名
+ */
+concptr PlayerAlignment::alignment_label()
+{
+    if (this->creature_ptr->align > 150)
+        return _("大善", "Lawful");
+    else if (this->creature_ptr->align > 50)
+        return _("中善", "Good");
+    else if (this->creature_ptr->align > 10)
+        return _("小善", "Neutral Good");
+    else if (this->creature_ptr->align > -11)
+        return _("中立", "Neutral");
+    else if (this->creature_ptr->align > -51)
+        return _("小悪", "Neutral Evil");
+    else if (this->creature_ptr->align > -151)
+        return _("中悪", "Evil");
+    else
+        return _("大悪", "Chaotic");
+}
+
+/*!
+ * @brief クリーチャーの抽象的善悪アライメントの表記を返す。 / Return alignment title
+ * @param creature_ptr 算出するクリーチャーの参照ポインタ。
+ * @return アライメントの表記を返す。
+ */
+concptr PlayerAlignment::your_alignment(bool with_value)
+{
+    auto s = alignment_label();
+    if (with_value || show_actual_value)
+        return format(_("%s(%ld)", "%s (%ld)"), s, static_cast<long>(this->creature_ptr->align));
+
+    return s;
+}
diff --git a/src/player-info/alignment.h b/src/player-info/alignment.h
new file mode 100644 (file)
index 0000000..a1cb98c
--- /dev/null
@@ -0,0 +1,15 @@
+#pragma once
+
+#include "system/angband.h"
+
+struct player_type;
+class PlayerAlignment {
+public:
+    PlayerAlignment(player_type *creature_ptr);
+    PlayerAlignment() = delete;
+    virtual ~PlayerAlignment() = default;
+    concptr your_alignment(bool with_value = false);
+private:
+    player_type *creature_ptr;
+    concptr alignment_label();
+};
index cccdbd1..ff97344 100644 (file)
@@ -149,43 +149,6 @@ static player_hand main_attack_hand(player_type *creature_ptr);
 /*** Player information ***/
 
 /*!
- * @brief クリーチャーの抽象的善悪アライメントの表記名のみを返す。 / Return only alignment title
- * @param creature_ptr 算出するクリーチャーの参照ポインタ。
- * @return アライメントの表記名
- */
-concptr alignment_label(player_type *creature_ptr)
-{
-    if (creature_ptr->align > 150)
-        return _("大善", "Lawful");
-    else if (creature_ptr->align > 50)
-        return _("中善", "Good");
-    else if (creature_ptr->align > 10)
-        return _("小善", "Neutral Good");
-    else if (creature_ptr->align > -11)
-        return _("中立", "Neutral");
-    else if (creature_ptr->align > -51)
-        return _("小悪", "Neutral Evil");
-    else if (creature_ptr->align > -151)
-        return _("中悪", "Evil");
-    else
-        return _("大悪", "Chaotic");
-}
-
-/*!
- * @brief クリーチャーの抽象的善悪アライメントの表記を返す。 / Return alignment title
- * @param creature_ptr 算出するクリーチャーの参照ポインタ。
- * @return アライメントの表記を返す。
- */
-concptr your_alignment(player_type *creature_ptr, bool with_value)
-{
-    auto s = alignment_label(creature_ptr);
-    if (with_value || show_actual_value)
-        return format(_("%s(%ld)", "%s (%ld)"), s, static_cast<long>(creature_ptr->align));
-
-    return s;
-}
-
-/*!
  * @brief 武器や各種スキル(騎乗以外)の抽象的表現ランクを返す。 /  Return proficiency level of weapons and misc. skills (except riding)
  * @param weapon_exp 経験値
  * @return ランク値
index 947f945..2347590 100644 (file)
@@ -9,7 +9,6 @@
 
 typedef struct object_type object_type;
 typedef struct player_type player_type;
-concptr your_alignment(player_type *creature_ptr, bool with_value = false);
 int weapon_exp_level(int weapon_exp);
 int riding_exp_level(int riding_exp);
 int spell_exp_level(int spell_exp);
index 0032cca..a75ea42 100644 (file)
@@ -17,6 +17,7 @@
 #include "mutation/mutation-flag-types.h"
 #include "object/object-info.h"
 #include "object/object-kind.h"
+#include "player-info/alignment.h"
 #include "player/mimic-info-table.h"
 #include "player/patron.h"
 #include "player/player-class.h"
@@ -133,7 +134,8 @@ static void display_phisique(player_type *creature_ptr)
     display_player_one_line(ENTRY_WEIGHT, format("%d", (int)creature_ptr->wt), TERM_L_BLUE);
     display_player_one_line(ENTRY_SOCIAL, format("%d", (int)creature_ptr->sc), TERM_L_BLUE);
 #endif
-    std::string alg = your_alignment(creature_ptr);
+    std::unique_ptr<PlayerAlignment> alignment(new PlayerAlignment(creature_ptr));
+    std::string alg = alignment->your_alignment();
     display_player_one_line(ENTRY_ALIGN, format("%s", alg.c_str()), TERM_L_BLUE);
 }
 
index 0f51640..34bc24d 100644 (file)
@@ -1,5 +1,6 @@
 #include "view/display-self-info.h"
 #include "io/input-key-acceptor.h"
+#include "player-info/alignment.h"
 #include "player-info/avatar.h"
 #include "player-info/self-info-util.h"
 #include "player/player-race.h"
@@ -35,7 +36,8 @@ void display_max_base_status(player_type *creature_ptr, self_info_type *self_ptr
 void display_virtue(player_type *creature_ptr, self_info_type *self_ptr)
 {
     self_ptr->info[self_ptr->line++] = "";
-    std::string alg = your_alignment(creature_ptr, true);
+    std::unique_ptr<PlayerAlignment> alignment(new PlayerAlignment(creature_ptr));
+    std::string alg = alignment->your_alignment(true);
     sprintf(self_ptr->plev_buf, _("現在の属性 : %s", "Your alignment : %s"), alg.c_str());
     strcpy(self_ptr->buf[1], self_ptr->plev_buf);
     self_ptr->info[self_ptr->line++] = self_ptr->buf[1];