OSDN Git Service

[Refactor] #39964 Separated autopick-destroyer.c/h from autpick.c
authorHourier <hourier@users.sourceforge.jp>
Sat, 25 Apr 2020 12:40:53 +0000 (21:40 +0900)
committerHourier <hourier@users.sourceforge.jp>
Sat, 25 Apr 2020 12:40:53 +0000 (21:40 +0900)
Hengband_vcs2017/Hengband/Hengband.vcxproj
Hengband_vcs2017/Hengband/Hengband.vcxproj.filters
src/Makefile.am
src/autopick/autopick-destroyer.c [new file with mode: 0644]
src/autopick/autopick-destroyer.h [new file with mode: 0644]
src/autopick/autopick-util.c
src/autopick/autopick-util.h
src/autopick/autopick.c

index 7b48886..7b8bf81 100644 (file)
   <ItemGroup>\r
     <ClCompile Include="..\..\src\artifact.c" />\r
     <ClCompile Include="..\..\src\autopick\autopick-describer.c" />\r
+    <ClCompile Include="..\..\src\autopick\autopick-destroyer.c" />\r
     <ClCompile Include="..\..\src\autopick\autopick-entry.c" />\r
     <ClCompile Include="..\..\src\autopick\autopick-initializer.c" />\r
     <ClCompile Include="..\..\src\autopick\autopick-matcher.c" />\r
     <ClInclude Include="..\..\src\artifact.h" />\r
     <ClInclude Include="..\..\src\autopick\autopick-commands-table.h" />\r
     <ClInclude Include="..\..\src\autopick\autopick-describer.h" />\r
+    <ClInclude Include="..\..\src\autopick\autopick-destroyer.h" />\r
     <ClInclude Include="..\..\src\autopick\autopick-dirty-flags.h" />\r
     <ClInclude Include="..\..\src\autopick\autopick-editor-table.h" />\r
     <ClInclude Include="..\..\src\autopick\autopick-entry.h" />\r
index c0e08bf..8cfebcf 100644 (file)
     <ClCompile Include="..\..\src\view\display-main-window.c">
       <Filter>view</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\src\autopick\autopick-destroyer.c">
+      <Filter>autopick</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\src\gamevalue.h" />
     <ClInclude Include="..\..\src\view\display-main-window.h">
       <Filter>view</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\src\autopick\autopick-destroyer.h">
+      <Filter>autopick</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="..\..\src\wall.bmp" />
index 5bc23be..899dff6 100644 (file)
@@ -20,6 +20,7 @@ hengband_SOURCES = \
        autopick/autopick-initializer.c autopick/autopick-initializer.h \
        autopick/autopick-matcher.c autopick/autopick-matcher.h \
        autopick-describer.c autopick-describer.h \
+       autopick-destroyer.c autopick-destroyer.h \
        \
        avatar.h avatar.c birth.c birth.h \
        \
diff --git a/src/autopick/autopick-destroyer.c b/src/autopick/autopick-destroyer.c
new file mode 100644 (file)
index 0000000..07e91fa
--- /dev/null
@@ -0,0 +1,105 @@
+#include "angband.h"
+#include "autopick/autopick-util.h"
+#include "autopick-methods-table.h"
+#include "autopick/autopick-destroyer.h"
+#include "object-ego.h"
+#include "object-hook.h"
+#include "object/object-kind.h"
+#include "object-flavor.h"
+#include "player-move.h"
+
+/*
+ * Automatically destroy items in this grid.
+ */
+static bool is_opt_confirm_destroy(player_type *player_ptr, object_type *o_ptr)
+{
+       if (!destroy_items) return FALSE;
+
+       if (leave_worth)
+               if (object_value(o_ptr) > 0) return FALSE;
+
+       if (leave_equip)
+               if (object_is_weapon_armour_ammo(o_ptr)) return FALSE;
+
+       if (leave_chest)
+               if ((o_ptr->tval == TV_CHEST) && o_ptr->pval) return FALSE;
+
+       if (leave_wanted)
+       {
+               if (object_is_bounty(o_ptr)) return FALSE;
+       }
+
+       if (leave_corpse)
+               if (o_ptr->tval == TV_CORPSE) return FALSE;
+
+       if (leave_junk)
+               if ((o_ptr->tval == TV_SKELETON) || (o_ptr->tval == TV_BOTTLE) || (o_ptr->tval == TV_JUNK) || (o_ptr->tval == TV_STATUE)) return FALSE;
+
+       if (leave_special)
+       {
+               if (player_ptr->prace == RACE_DEMON)
+               {
+                       if (o_ptr->tval == TV_CORPSE &&
+                               o_ptr->sval == SV_CORPSE &&
+                               my_strchr("pht", r_info[o_ptr->pval].d_char))
+                               return FALSE;
+               }
+
+               if (player_ptr->pclass == CLASS_ARCHER)
+               {
+                       if (o_ptr->tval == TV_SKELETON ||
+                               (o_ptr->tval == TV_CORPSE && o_ptr->sval == SV_SKELETON))
+                               return FALSE;
+               }
+               else if (player_ptr->pclass == CLASS_NINJA)
+               {
+                       if (o_ptr->tval == TV_LITE &&
+                               o_ptr->name2 == EGO_LITE_DARKNESS && object_is_known(o_ptr))
+                               return FALSE;
+               }
+               else if (player_ptr->pclass == CLASS_BEASTMASTER ||
+                       player_ptr->pclass == CLASS_CAVALRY)
+               {
+                       if (o_ptr->tval == TV_WAND &&
+                               o_ptr->sval == SV_WAND_HEAL_MONSTER && object_is_aware(o_ptr))
+                               return FALSE;
+               }
+       }
+
+       if (o_ptr->tval == TV_GOLD) return FALSE;
+
+       return TRUE;
+}
+
+
+void auto_destroy_item(player_type *player_ptr, object_type *o_ptr, int autopick_idx)
+{
+       bool destroy = FALSE;
+       if (is_opt_confirm_destroy(player_ptr, o_ptr)) destroy = TRUE;
+
+       if (autopick_idx >= 0 &&
+               !(autopick_list[autopick_idx].action & DO_AUTODESTROY))
+               destroy = FALSE;
+
+       if (!always_pickup)
+       {
+               if (autopick_idx >= 0 &&
+                       (autopick_list[autopick_idx].action & DO_AUTODESTROY))
+                       destroy = TRUE;
+       }
+
+       if (!destroy) return;
+
+       disturb(player_ptr, FALSE, FALSE);
+       if (!can_player_destroy_object(o_ptr))
+       {
+               GAME_TEXT o_name[MAX_NLEN];
+               object_desc(player_ptr, o_name, o_ptr, 0);
+               msg_format(_("%s\82Í\94j\89ó\95s\94\\82¾\81B", "You cannot auto-destroy %s."), o_name);
+               return;
+       }
+
+       (void)COPY(&autopick_last_destroyed_object, o_ptr, object_type);
+       o_ptr->marked |= OM_AUTODESTROY;
+       player_ptr->update |= PU_AUTODESTROY;
+}
diff --git a/src/autopick/autopick-destroyer.h b/src/autopick/autopick-destroyer.h
new file mode 100644 (file)
index 0000000..ace9807
--- /dev/null
@@ -0,0 +1,3 @@
+#pragma once
+
+void auto_destroy_item(player_type *player_ptr, object_type *o_ptr, int autopick_idx);
index 701e02e..789ec2a 100644 (file)
@@ -9,6 +9,14 @@ int max_max_autopick = 0; /*!< 自動拾い/破壊設定の限界数 */
 autopick_type *autopick_list = NULL; /*!< 自動拾い/破壊設定構造体のポインタ配列 */
 
 /*
+ * Automatically destroy an item if it is to be destroyed
+ *
+ * When always_pickup is 'yes', we disable auto-destroyer function of
+ * auto-picker/destroyer, and do only easy-auto-destroyer.
+ */
+object_type autopick_last_destroyed_object;
+
+/*
  * A function to delete entry
  */
 void autopick_free_entry(autopick_type *entry)
index 65da802..ba9ecaa 100644 (file)
@@ -87,5 +87,6 @@ typedef struct {
 extern int max_autopick;
 extern int max_max_autopick;
 extern autopick_type *autopick_list;
+extern object_type autopick_last_destroyed_object;
 
 void autopick_free_entry(autopick_type *entry);
index 1fb63d2..253ff08 100644 (file)
@@ -22,6 +22,7 @@
 #include "autopick/autopick-menu-data-table.h"
 #include "autopick/autopick-methods-table.h"
 #include "autopick/autopick-keys-table.h"
+#include "autopick/autopick-destroyer.h"
 #include "autopick/autopick-describer.h"
 #include "autopick/autopick-entry.h"
 #include "gameterm.h"
 #include "view/display-main-window.h" // 暫定。後で消す
 
 /*
- * Automatically destroy an item if it is to be destroyed
- *
- * When always_pickup is 'yes', we disable auto-destroyer function of
- * auto-picker/destroyer, and do only easy-auto-destroyer.
- */
-static object_type autopick_last_destroyed_object;
-
-/*
  *  Get file name for autopick preference
  */
 static concptr pickpref_filename(player_type *player_ptr, int filename_mode)
@@ -210,103 +203,6 @@ static void auto_inscribe_item(player_type *player_ptr, object_type *o_ptr, int
 
 
 /*
- * Automatically destroy items in this grid.
- */
-static bool is_opt_confirm_destroy(player_type *player_ptr, object_type *o_ptr)
-{
-       if (!destroy_items) return FALSE;
-
-       if (leave_worth)
-               if (object_value(o_ptr) > 0) return FALSE;
-
-       if (leave_equip)
-               if (object_is_weapon_armour_ammo(o_ptr)) return FALSE;
-
-       if (leave_chest)
-               if ((o_ptr->tval == TV_CHEST) && o_ptr->pval) return FALSE;
-
-       if (leave_wanted)
-       {
-               if (object_is_bounty(o_ptr)) return FALSE;
-       }
-
-       if (leave_corpse)
-               if (o_ptr->tval == TV_CORPSE) return FALSE;
-
-       if (leave_junk)
-               if ((o_ptr->tval == TV_SKELETON) || (o_ptr->tval == TV_BOTTLE) || (o_ptr->tval == TV_JUNK) || (o_ptr->tval == TV_STATUE)) return FALSE;
-
-       if (leave_special)
-       {
-               if (player_ptr->prace == RACE_DEMON)
-               {
-                       if (o_ptr->tval == TV_CORPSE &&
-                               o_ptr->sval == SV_CORPSE &&
-                               my_strchr("pht", r_info[o_ptr->pval].d_char))
-                               return FALSE;
-               }
-
-               if (player_ptr->pclass == CLASS_ARCHER)
-               {
-                       if (o_ptr->tval == TV_SKELETON ||
-                               (o_ptr->tval == TV_CORPSE && o_ptr->sval == SV_SKELETON))
-                               return FALSE;
-               }
-               else if (player_ptr->pclass == CLASS_NINJA)
-               {
-                       if (o_ptr->tval == TV_LITE &&
-                               o_ptr->name2 == EGO_LITE_DARKNESS && object_is_known(o_ptr))
-                               return FALSE;
-               }
-               else if (player_ptr->pclass == CLASS_BEASTMASTER ||
-                       player_ptr->pclass == CLASS_CAVALRY)
-               {
-                       if (o_ptr->tval == TV_WAND &&
-                               o_ptr->sval == SV_WAND_HEAL_MONSTER && object_is_aware(o_ptr))
-                               return FALSE;
-               }
-       }
-
-       if (o_ptr->tval == TV_GOLD) return FALSE;
-
-       return TRUE;
-}
-
-
-static void auto_destroy_item(player_type *player_ptr, object_type *o_ptr, int autopick_idx)
-{
-       bool destroy = FALSE;
-       if (is_opt_confirm_destroy(player_ptr, o_ptr)) destroy = TRUE;
-
-       if (autopick_idx >= 0 &&
-               !(autopick_list[autopick_idx].action & DO_AUTODESTROY))
-               destroy = FALSE;
-
-       if (!always_pickup)
-       {
-               if (autopick_idx >= 0 &&
-                       (autopick_list[autopick_idx].action & DO_AUTODESTROY))
-                       destroy = TRUE;
-       }
-
-       if (!destroy) return;
-
-       disturb(player_ptr, FALSE, FALSE);
-       if (!can_player_destroy_object(o_ptr))
-       {
-               GAME_TEXT o_name[MAX_NLEN];
-               object_desc(player_ptr, o_name, o_ptr, 0);
-               msg_format(_("%sは破壊不能だ。", "You cannot auto-destroy %s."), o_name);
-               return;
-       }
-
-       (void)COPY(&autopick_last_destroyed_object, o_ptr, object_type);
-       o_ptr->marked |= OM_AUTODESTROY;
-       player_ptr->update |= PU_AUTODESTROY;
-}
-
-
-/*
  *  Auto-destroy marked item
  */
 static void autopick_delayed_alter_aux(player_type *player_ptr, INVENTORY_IDX item)