OSDN Git Service

[Refactor] #38997 floor-save.c のplayer_type *引数が必要な全関数にこれを追加 (コールチェーンが非常に長いので途中経過は省略...
[hengband/hengband.git] / src / autopick.c
index e13f4ea..993207a 100644 (file)
  */
 
 #include "angband.h"
+#include "util.h"
+#include "term.h"
+#include "autopick.h"
+#include "core.h"
+
+#include "mind.h"
+
 #include "store.h"
+#include "player-status.h"
+#include "player-move.h"
+#include "player-class.h"
+#include "player-race.h"
+#include "player-inventory.h"
+#include "objectkind.h"
+#include "object-ego.h"
+#include "object-flavor.h"
+#include "object-hook.h"
+
+#include "files.h"
+#include "floor.h"
+#include "world.h"
+#include "monster.h"
+#include "monsterrace.h"
+#include "view-mainwindow.h"
 
 #define MAX_LINELEN 1024
 
@@ -134,7 +157,7 @@ static GAME_TEXT KEY_COLLECTING[] = "collecting";
 static GAME_TEXT KEY_ARTIFACT[] = "artifact";
 static GAME_TEXT KEY_EGO[] = "ego";
 static GAME_TEXT KEY_GOOD[] = "good";
-static GAME_TEXT KEY_nameLESS[] = "nameless";
+static GAME_TEXT KEY_NAMELESS[] = "nameless";
 static GAME_TEXT KEY_AVERAGE[] = "average";
 static GAME_TEXT KEY_WORTHLESS[] = "worthless";
 static GAME_TEXT KEY_RARE[] = "rare";
@@ -200,6 +223,13 @@ static GAME_TEXT KEY_BOOTS[] = "boots";
 
 
 /*
+ * 自動拾い/破壊設定のリストに関する変数 / List for auto-picker/destroyer entries
+ */
+int max_autopick = 0; /*!< 現在登録している自動拾い/破壊設定の数 */
+int max_max_autopick = 0; /*!< 自動拾い/破壊設定の限界数 */
+autopick_type *autopick_list = NULL; /*!< 自動拾い/破壊設定構造体のポインタ配列 */
+
+/*
  * A function to create new entry
  */
 static bool autopick_new_entry(autopick_type *entry, concptr str, bool allow_default)
@@ -575,7 +605,7 @@ static void autopick_entry_from_object(autopick_type *entry, object_type *o_ptr)
        }
 
        /* Wanted monster's corpse */
-       if (object_is_shoukinkubi(o_ptr))
+       if (object_is_bounty(o_ptr))
        {
                REM_FLG(FLG_WORTHLESS);
                ADD_FLG(FLG_WANTED);
@@ -741,7 +771,7 @@ static concptr pickpref_filename(int filename_mode)
                return format("%s.prf", namebase);
 
        case PT_WITH_PNAME:
-               return format("%s-%s.prf", namebase, player_base);
+               return format("%s-%s.prf", namebase, p_ptr->base_name);
 
        default:
                return NULL;
@@ -1235,7 +1265,7 @@ static bool is_autopick_aux(object_type *o_ptr, autopick_type *entry, concptr o_
                return FALSE;
 
        /*** Wanted monster's corpse/skeletons ***/
-       if (IS_FLG(FLG_WANTED) && !object_is_shoukinkubi(o_ptr))
+       if (IS_FLG(FLG_WANTED) && !object_is_bounty(o_ptr))
                return FALSE;
 
        /*** Unique monster's corpse/skeletons/statues ***/
@@ -1419,8 +1449,8 @@ static bool is_autopick_aux(object_type *o_ptr, autopick_type *entry, concptr o_
                 * into an inventory slot.
                 * But an item can not be absorbed into itself!
                 */
-               if ((&inventory[j] != o_ptr) &&
-                   object_similar(&inventory[j], o_ptr))
+               if ((&p_ptr->inventory_list[j] != o_ptr) &&
+                   object_similar(&p_ptr->inventory_list[j], o_ptr))
                        return TRUE;
        }
 
@@ -1497,7 +1527,7 @@ static bool is_opt_confirm_destroy(object_type *o_ptr)
 
        if (leave_wanted)
        {
-               if (object_is_shoukinkubi(o_ptr)) return FALSE;
+               if (object_is_bounty(o_ptr)) return FALSE;
        }
 
        if (leave_corpse)
@@ -1577,7 +1607,7 @@ static void auto_destroy_item(object_type *o_ptr, int autopick_idx)
 
        /* Now decided to destroy */
 
-       disturb(FALSE, FALSE);
+       disturb(p_ptr, FALSE, FALSE);
 
        /* Artifact? */
        if (!can_player_destroy_object(o_ptr))
@@ -1610,11 +1640,7 @@ static void autopick_delayed_alter_aux(INVENTORY_IDX item)
 {
        object_type *o_ptr;
 
-       /* Get the item (in the pack) */
-       if (item >= 0) o_ptr = &inventory[item];
-
-       /* Get the item (on the floor) */
-       else o_ptr = &o_list[0 - item];
+       o_ptr = REF_ITEM(p_ptr, p_ptr->current_floor_ptr, item);
 
        if (o_ptr->k_idx && (o_ptr->marked & OM_AUTODESTROY))
        {
@@ -1656,10 +1682,10 @@ void autopick_delayed_alter(void)
                autopick_delayed_alter_aux(item);
 
        /* Scan the pile of objects */
-       item = cave[p_ptr->y][p_ptr->x].o_idx;
+       item = p_ptr->current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].o_idx;
        while (item)
        {
-               OBJECT_IDX next = o_list[item].next_o_idx;
+               OBJECT_IDX next = p_ptr->current_floor_ptr->o_list[item].next_o_idx;
                autopick_delayed_alter_aux(-item);
                item = next;
        }
@@ -1677,11 +1703,7 @@ void autopick_alter_item(INVENTORY_IDX item, bool destroy)
        object_type *o_ptr;
        int idx;
 
-       /* Get the item (in the pack) */
-       if (item >= 0) o_ptr = &inventory[item];
-
-       /* Get the item (on the floor) */
-       else o_ptr = &o_list[0 - item];
+       o_ptr = REF_ITEM(p_ptr, p_ptr->current_floor_ptr, item);
 
        /* Get the index in the auto-pick/destroy list */
        idx = is_autopick(o_ptr);
@@ -1698,18 +1720,16 @@ void autopick_alter_item(INVENTORY_IDX item, bool destroy)
 /*
  * Automatically pickup/destroy items in this grid.
  */
-void autopick_pickup_items(cave_type *c_ptr)
+void autopick_pickup_items(grid_type *g_ptr)
 {
        OBJECT_IDX this_o_idx, next_o_idx = 0;
        
        /* Scan the pile of objects */
-       for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
+       for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
        {
                int idx;
-                       object_type *o_ptr = &o_list[this_o_idx];
-               
-               /* Acquire next object */
-               next_o_idx = o_ptr->next_o_idx;
+                       object_type *o_ptr = &p_ptr->current_floor_ptr->o_list[this_o_idx];
+                               next_o_idx = o_ptr->next_o_idx;
 
                idx = is_autopick(o_ptr);
 
@@ -1719,7 +1739,7 @@ void autopick_pickup_items(cave_type *c_ptr)
                if (idx >= 0 &&
                        (autopick_list[idx].action & (DO_AUTOPICK | DO_QUERY_AUTOPICK)))
                {
-                       disturb(FALSE, FALSE);
+                       disturb(p_ptr, FALSE, FALSE);
 
                        if (!inven_carry_okay(o_ptr))
                        {
@@ -2394,7 +2414,7 @@ static void describe_autopick(char *buff, autopick_type *entry)
        /*** Collecting items ***/
        /*** Which can be absorbed into a slot as a bundle ***/
        if (IS_FLG(FLG_COLLECTING))
-               which_str[which_n++] = "can be absorbed into an existing inventory slot";
+               which_str[which_n++] = "can be absorbed into an existing p_ptr->inventory_list slot";
        
        /*** Unaware items ***/
        if (IS_FLG(FLG_UNAWARE))
@@ -2740,9 +2760,7 @@ static concptr *read_text_lines(concptr filename)
        char buf[1024];
 
        path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
-       
-       /* Open the file */
-       fff = my_fopen(buf, "r");
+               fff = my_fopen(buf, "r");
 
        if (fff)
        {
@@ -2876,12 +2894,8 @@ static bool write_text_lines(concptr filename, concptr *lines_list)
 
        int lines = 0;
        char buf[1024];
-
-       /* Build the filename */
        path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
-       
-       /* Open the file */
-       fff = my_fopen(buf, "w");
+               fff = my_fopen(buf, "w");
        if (fff)
        {
                for (lines = 0; lines_list[lines]; lines++)
@@ -3244,7 +3258,7 @@ static bool entry_from_choosed_object(autopick_type *entry)
 
        q = _("どのアイテムを登録しますか? ", "Enter which item? ");
        s = _("アイテムを持っていない。", "You have nothing to enter.");
-       o_ptr = choose_object(NULL, q, s, USE_INVEN | USE_FLOOR | USE_EQUIP);
+       o_ptr = choose_object(p_ptr, NULL, q, s, USE_INVEN | USE_FLOOR | USE_EQUIP, 0);
        if (!o_ptr) return FALSE;
 
        autopick_entry_from_object(entry, o_ptr);
@@ -3263,7 +3277,7 @@ static byte get_object_for_search(object_type **o_handle, concptr *search_strp)
 
        q = _("どのアイテムを検索しますか? ", "Enter which item? ");
        s = _("アイテムを持っていない。", "You have nothing to enter.");
-       o_ptr = choose_object(NULL, q, s, USE_INVEN | USE_FLOOR | USE_EQUIP);
+       o_ptr = choose_object(p_ptr, NULL, q, s, USE_INVEN | USE_FLOOR | USE_EQUIP, 0);
        if (!o_ptr) return 0;
 
        *o_handle = o_ptr;
@@ -3942,7 +3956,7 @@ static GAME_TEXT MN_SEARCH[] = "Search";
 static GAME_TEXT MN_SEARCH_STR[] = "Search by string";
 static GAME_TEXT MN_SEARCH_FORW[] = "Search forward";
 static GAME_TEXT MN_SEARCH_BACK[] = "Search backward";
-static GAME_TEXT MN_SEARCH_OBJ[] = "Search by inventory object";
+static GAME_TEXT MN_SEARCH_OBJ[] = "Search by p_ptr->inventory_list object";
 static GAME_TEXT MN_SEARCH_DESTROYED[] = "Search by destroyed object";
 
 static GAME_TEXT MN_INSERT[] = "Insert...";
@@ -5957,8 +5971,9 @@ static int analyze_move_key(text_body_type *tb, int skey)
 
 /*
  * In-game editor of Object Auto-picker/Destoryer
+ * @param player_ptr プレーヤーへの参照ポインタ
  */
-void do_cmd_edit_autopick(void)
+void do_cmd_edit_autopick(player_type *player_ptr)
 {
        static int cx_save = 0;
        static int cy_save = 0;
@@ -5992,19 +6007,19 @@ void do_cmd_edit_autopick(void)
        tb->dirty_line = -1;
        tb->filename_mode = PT_DEFAULT;
 
-       if (turn < old_autosave_turn)
+       if (current_world_ptr->game_turn < old_autosave_turn)
        {
-               while (old_autosave_turn > turn) old_autosave_turn -= TURNS_PER_TICK * TOWN_DAWN;
+               while (old_autosave_turn > current_world_ptr->game_turn) old_autosave_turn -= TURNS_PER_TICK * TOWN_DAWN;
        }
 
        /* Autosave */
-       if (turn > old_autosave_turn + 100L)
+       if (current_world_ptr->game_turn > old_autosave_turn + 100L)
        {
-               do_cmd_save_game(TRUE);
-               old_autosave_turn = turn;
+               do_cmd_save_game(player_ptr, TRUE);
+               old_autosave_turn = current_world_ptr->game_turn;
        }
 
-       /* HACK -- Reset start_time to stop counting playtime while edit */
+       /* HACK -- Reset current_world_ptr->start_time to stop counting current_world_ptr->play_time while edit */
        update_playtime();
 
        /* Free old entries */
@@ -6130,8 +6145,8 @@ void do_cmd_edit_autopick(void)
        /* Reload autopick pref */
        process_autopick_file(buf);
 
-       /* HACK -- reset start_time so that playtime is not increase while edit */
-       start_time = (u32b)time(NULL);
+       /* HACK -- reset current_world_ptr->start_time so that current_world_ptr->play_time is not increase while edit */
+       current_world_ptr->start_time = (u32b)time(NULL);
 
        /* Save cursor location */
        cx_save = tb->cx;