From 1713fa1f28d62182f8f9856557340b30b21334ed Mon Sep 17 00:00:00 2001 From: Hourier Date: Sat, 11 Jan 2020 17:10:36 +0900 Subject: [PATCH] =?utf8?q?[Refactor]=20#38997=20is=5Fautopick=5Faux()=20?= =?utf8?q?=E3=81=ABplayer=5Ftype=20*=20=E5=BC=95=E6=95=B0=E3=82=92?= =?utf8?q?=E8=BF=BD=E5=8A=A0/=20Added=20player=5Ftype=20*=20argument=20to?= =?utf8?q?=20is=5Fautoppick=5Faux()?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/autopick.c | 38 +++++++++++++++++++------------------- src/autopick.h | 6 +++--- src/birth.c | 2 +- src/bldg.c | 17 +++++++++-------- src/cmd/cmd-item.c | 6 ++++-- src/cmd/cmd-smith.c | 3 ++- src/core.c | 9 +++++---- src/player-move.c | 4 ++-- src/spells-object.c | 6 +++--- src/spells1.c | 2 +- src/spells2.c | 2 +- src/spells3.c | 6 +++--- src/store.c | 4 ++-- src/view-mainwindow.c | 2 +- 14 files changed, 56 insertions(+), 51 deletions(-) diff --git a/src/autopick.c b/src/autopick.c index f31ee21f1..509b09f79 100644 --- a/src/autopick.c +++ b/src/autopick.c @@ -1041,7 +1041,7 @@ static concptr autopick_line_from_entry_kill(autopick_type *entry) * A function for Auto-picker/destroyer * Examine whether the object matches to the entry */ -static bool is_autopick_aux(object_type *o_ptr, autopick_type *entry, concptr o_name) +static bool is_autopick_aux(player_type *player_ptr, object_type *o_ptr, autopick_type *entry, concptr o_name) { int j; concptr ptr = entry->name; @@ -1289,15 +1289,15 @@ static bool is_autopick_aux(object_type *o_ptr, autopick_type *entry, concptr o_ /*** First realm spellbooks ***/ if (IS_FLG(FLG_REALM1) && (REALM1_BOOK != o_ptr->tval || - p_ptr->pclass == CLASS_SORCERER || - p_ptr->pclass == CLASS_RED_MAGE)) + player_ptr->pclass == CLASS_SORCERER || + player_ptr->pclass == CLASS_RED_MAGE)) return FALSE; /*** Second realm spellbooks ***/ if (IS_FLG(FLG_REALM2) && (REALM2_BOOK != o_ptr->tval || - p_ptr->pclass == CLASS_SORCERER || - p_ptr->pclass == CLASS_RED_MAGE)) + player_ptr->pclass == CLASS_SORCERER || + player_ptr->pclass == CLASS_RED_MAGE)) return FALSE; /*** First rank spellbooks ***/ @@ -1449,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 ((&p_ptr->inventory_list[j] != o_ptr) && - object_similar(&p_ptr->inventory_list[j], o_ptr)) + if ((&player_ptr->inventory_list[j] != o_ptr) && + object_similar(&player_ptr->inventory_list[j], o_ptr)) return TRUE; } @@ -1463,7 +1463,7 @@ static bool is_autopick_aux(object_type *o_ptr, autopick_type *entry, concptr o_ * A function for Auto-picker/destroyer * Examine whether the object matches to the list of keywords or not. */ -int is_autopick(object_type *o_ptr) +int is_autopick(player_type *player_ptr, object_type *o_ptr) { int i; GAME_TEXT o_name[MAX_NLEN]; @@ -1481,7 +1481,7 @@ int is_autopick(object_type *o_ptr) { autopick_type *entry = &autopick_list[i]; - if (is_autopick_aux(o_ptr, entry, o_name)) return i; + if (is_autopick_aux(player_ptr, o_ptr, entry, o_name)) return i; } /* No matching entry */ @@ -1694,15 +1694,15 @@ void autopick_delayed_alter(player_type *owner_ptr) * Auto-destroyer works only on inventory or on floor stack only when * requested. */ -void autopick_alter_item(INVENTORY_IDX item, bool destroy) +void autopick_alter_item(player_type *player_ptr, INVENTORY_IDX item, bool destroy) { object_type *o_ptr; int idx; - o_ptr = REF_ITEM(p_ptr, p_ptr->current_floor_ptr, item); + o_ptr = REF_ITEM(player_ptr, player_ptr->current_floor_ptr, item); /* Get the index in the auto-pick/destroy list */ - idx = is_autopick(o_ptr); + idx = is_autopick(player_ptr, o_ptr); /* Do auto-inscription */ auto_inscribe_item(o_ptr, idx); @@ -1716,7 +1716,7 @@ void autopick_alter_item(INVENTORY_IDX item, bool destroy) /* * Automatically pickup/destroy items in this grid. */ -void autopick_pickup_items(grid_type *g_ptr) +void autopick_pickup_items(player_type* player_ptr, grid_type *g_ptr) { OBJECT_IDX this_o_idx, next_o_idx = 0; @@ -1727,7 +1727,7 @@ void autopick_pickup_items(grid_type *g_ptr) 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); + idx = is_autopick(player_ptr, o_ptr); /* Item index for floor -1,-2,-3,... */ auto_inscribe_item(o_ptr, idx); @@ -1917,7 +1917,7 @@ bool autopick_autoregister(player_type *player_ptr, object_type *o_ptr) FILE *pref_fff; autopick_type an_entry, *entry = &an_entry; - int match_autopick = is_autopick(o_ptr); + int match_autopick = is_autopick(player_ptr, o_ptr); /* Already registered */ if (match_autopick != -1) @@ -3596,7 +3596,7 @@ static byte get_string_for_search(object_type **o_handle, concptr *search_strp) /* * Search next line matches for o_ptr */ -static void search_for_object(text_body_type *tb, object_type *o_ptr, bool forward) +static void search_for_object(player_type *player_ptr, text_body_type *tb, object_type *o_ptr, bool forward) { autopick_type an_entry, *entry = &an_entry; GAME_TEXT o_name[MAX_NLEN]; @@ -3629,7 +3629,7 @@ static void search_for_object(text_body_type *tb, object_type *o_ptr, bool forwa if (!autopick_new_entry(entry, tb->lines_list[i], FALSE)) continue; /* Does this line match to the object? */ - match = is_autopick_aux(o_ptr, entry, o_name); + match = is_autopick_aux(player_ptr, o_ptr, entry, o_name); autopick_free_entry(entry); if (!match) continue; @@ -5581,7 +5581,7 @@ static bool do_editor_command(player_type *player_ptr, text_body_type *tb, int c case EC_SEARCH_FORW: if (tb->search_o_ptr) { - search_for_object(tb, tb->search_o_ptr, TRUE); + search_for_object(player_ptr, tb, tb->search_o_ptr, TRUE); } else if (tb->search_str && tb->search_str[0]) { @@ -5596,7 +5596,7 @@ static bool do_editor_command(player_type *player_ptr, text_body_type *tb, int c case EC_SEARCH_BACK: if (tb->search_o_ptr) { - search_for_object(tb, tb->search_o_ptr, FALSE); + search_for_object(player_ptr, tb, tb->search_o_ptr, FALSE); } else if (tb->search_str && tb->search_str[0]) { diff --git a/src/autopick.h b/src/autopick.h index 8db055730..d0bbc817a 100644 --- a/src/autopick.h +++ b/src/autopick.h @@ -30,9 +30,9 @@ extern autopick_type *autopick_list; extern void autopick_load_pref(player_type *player_ptr, bool disp_mes); extern errr process_autopick_file_command(char *buf); extern concptr autopick_line_from_entry(autopick_type *entry); -extern int is_autopick(object_type *o_ptr); -extern void autopick_alter_item(INVENTORY_IDX item, bool destroy); +extern int is_autopick(player_type *player_ptr, object_type *o_ptr); +extern void autopick_alter_item(player_type *player_ptr, INVENTORY_IDX item, bool destroy); extern void autopick_delayed_alter(player_type *player_ptr); -extern void autopick_pickup_items(grid_type *g_ptr); +extern void autopick_pickup_items(player_type *player_ptr, grid_type *g_ptr); extern bool autopick_autoregister(player_type *player_ptr, object_type *o_ptr); extern void do_cmd_edit_autopick(player_type *player_ptr); diff --git a/src/birth.c b/src/birth.c index c1b6240e3..95861b6f9 100644 --- a/src/birth.c +++ b/src/birth.c @@ -2225,7 +2225,7 @@ static void add_outfit(player_type *creature_ptr, object_type *o_ptr) slot = inven_carry(creature_ptr, o_ptr); /* Auto-inscription */ - autopick_alter_item(slot, FALSE); + autopick_alter_item(creature_ptr, slot, FALSE); /* Now try wielding everything */ wield_all(creature_ptr); diff --git a/src/bldg.c b/src/bldg.c index 640b7e806..a3d86d84b 100644 --- a/src/bldg.c +++ b/src/bldg.c @@ -1965,7 +1965,7 @@ static bool kankin(player_type *player_ptr) msg_format(_("%s(%c)を貰った。", "You get %s (%c). "), o_name, index_to_label(item_new)); /* Auto-inscription */ - autopick_alter_item(item_new, FALSE); + autopick_alter_item(player_ptr, item_new, FALSE); handle_stuff(player_ptr); change = TRUE; @@ -3261,9 +3261,10 @@ static bool enchant_item(player_type *player_ptr, PRICE cost, HIT_PROB to_hit, H * The cost for rods depends on the level of the rod. The prices\n * for recharging wands and staves are dependent on the cost of\n * the base-item.\n + * @param player_ptr プレーヤーへの参照ポインタ * @return なし */ -static void building_recharge(void) +static void building_recharge(player_type *player_ptr) { OBJECT_IDX item; DEPTH lev; @@ -3313,7 +3314,7 @@ static void building_recharge(void) msg_format(_("%s です。", "You have: %s."), tmp_str); /* Auto-inscription */ - autopick_alter_item(item, FALSE); + autopick_alter_item(player_ptr, item, FALSE); /* Update the gold display */ building_prt_gold(); @@ -3470,9 +3471,10 @@ static void building_recharge(void) * The cost for rods depends on the level of the rod. The prices\n * for recharging wands and staves are dependent on the cost of\n * the base-item.\n + * @param player_ptr プレーヤーへの参照ポインタ * @return なし */ -static void building_recharge_all(void) +static void building_recharge_all(player_type *player_ptr) { INVENTORY_IDX i; DEPTH lev; @@ -3481,7 +3483,6 @@ static void building_recharge_all(void) PRICE price = 0; PRICE total_cost = 0; - /* Display some info */ msg_flag = FALSE; clear_bldg(4, 18); @@ -3565,7 +3566,7 @@ static void building_recharge_all(void) identify_item(p_ptr, o_ptr); /* Auto-inscription */ - autopick_alter_item(i, FALSE); + autopick_alter_item(player_ptr, i, FALSE); } /* Recharge */ @@ -3942,10 +3943,10 @@ static void bldg_process_command(player_type *player_ptr, building_type *bldg, i enchant_item(player_ptr, bcost, 0, 0, 1); break; case BACT_RECHARGE: - building_recharge(); + building_recharge(player_ptr); break; case BACT_RECHARGE_ALL: - building_recharge_all(); + building_recharge_all(player_ptr); break; case BACT_IDENTS: /* needs work */ if (!get_check(_("持ち物を全て鑑定してよろしいですか?", "Do you pay for identify all your possession? "))) break; diff --git a/src/cmd/cmd-item.c b/src/cmd/cmd-item.c index dda88fc88..882a8eebd 100644 --- a/src/cmd/cmd-item.c +++ b/src/cmd/cmd-item.c @@ -134,6 +134,7 @@ bool select_ring_slot = FALSE; /*! * @brief 装備するコマンドのメインルーチン / Wield or wear a single item from the pack or floor + * @param creature_ptr プレーヤーへの参照ポインタ * @return なし */ void do_cmd_wield(player_type *creature_ptr) @@ -324,7 +325,7 @@ void do_cmd_wield(player_type *creature_ptr) identify_item(creature_ptr, o_ptr); /* Auto-inscription */ - autopick_alter_item(item, FALSE); + autopick_alter_item(creature_ptr, item, FALSE); } take_turn(creature_ptr, 100); @@ -606,6 +607,7 @@ void do_cmd_drop(player_type *creature_ptr) /*! * @brief アイテムを破壊するコマンドのメインルーチン / Destroy an item + * @param creature_ptr プレーヤーへの参照ポインタ * @return なし */ void do_cmd_destroy(player_type *creature_ptr) @@ -682,7 +684,7 @@ void do_cmd_destroy(player_type *creature_ptr) if (autopick_autoregister(creature_ptr, o_ptr)) { /* Auto-destroy it */ - autopick_alter_item(item, TRUE); + autopick_alter_item(creature_ptr, item, TRUE); } /* The object is already destroyed. */ diff --git a/src/cmd/cmd-smith.c b/src/cmd/cmd-smith.c index 6eb2c7709..946e16458 100644 --- a/src/cmd/cmd-smith.c +++ b/src/cmd/cmd-smith.c @@ -511,6 +511,7 @@ static void display_essence(player_type *creature_ptr) /*! * @brief エッセンスの抽出処理 + * @param creature_ptr プレーヤーへの参照ポインタ * @return なし */ static void drain_essence(player_type *creature_ptr) @@ -731,7 +732,7 @@ static void drain_essence(player_type *creature_ptr) } /* Apply autodestroy/inscription to the drained item */ - autopick_alter_item(item, TRUE); + autopick_alter_item(creature_ptr, item, TRUE); creature_ptr->update |= (PU_COMBINE | PU_REORDER); creature_ptr->window |= (PW_INVEN); } diff --git a/src/core.c b/src/core.c index 1563f5af0..b016de4ae 100644 --- a/src/core.c +++ b/src/core.c @@ -130,10 +130,11 @@ int init_flags; /*! * @brief 擬似鑑定を実際に行い判定を反映する * @param slot 擬似鑑定を行うプレイヤーの所持リストID + * @param creature_ptr プレーヤーへの参照ポインタ * @param heavy 重度の擬似鑑定を行うならばTRUE * @return なし */ -static void sense_inventory_aux(INVENTORY_IDX slot, bool heavy) +static void sense_inventory_aux(player_type *creature_ptr, INVENTORY_IDX slot, bool heavy) { byte feel; object_type *o_ptr = &p_ptr->inventory_list[slot]; @@ -240,7 +241,7 @@ static void sense_inventory_aux(INVENTORY_IDX slot, bool heavy) o_ptr->feeling = feel; /* Auto-inscription/destroy */ - autopick_alter_item(slot, destroy_feeling); + autopick_alter_item(creature_ptr, slot, destroy_feeling); p_ptr->update |= (PU_COMBINE | PU_REORDER); p_ptr->window |= (PW_INVEN | PW_EQUIP); @@ -477,7 +478,7 @@ static void sense_inventory1(player_type *creature_ptr) heavy = TRUE; } - sense_inventory_aux(i, heavy); + sense_inventory_aux(creature_ptr, i, heavy); } } @@ -599,7 +600,7 @@ static void sense_inventory2(player_type *creature_ptr) /* Occasional failure on creature_ptr->inventory_list items */ if ((i < INVEN_RARM) && (0 != randint0(5))) continue; - sense_inventory_aux(i, TRUE); + sense_inventory_aux(creature_ptr, i, TRUE); } } diff --git a/src/player-move.c b/src/player-move.c index 28aaeedfa..99d662860 100644 --- a/src/player-move.c +++ b/src/player-move.c @@ -306,7 +306,7 @@ void py_pickup_aux(player_type *owner_ptr, OBJECT_IDX o_idx) bool old_known = identify_item(owner_ptr, o_ptr); /* Auto-inscription/destroy */ - autopick_alter_item(slot, (bool)(destroy_identify && !old_known)); + autopick_alter_item(owner_ptr, slot, (bool)(destroy_identify && !old_known)); /* If it is destroyed, don't pick it up */ if (o_ptr->marked & OM_AUTODESTROY) return; @@ -375,7 +375,7 @@ void carry(player_type *creature_ptr, bool pickup) handle_stuff(creature_ptr); /* Automatically pickup/destroy/inscribe items */ - autopick_pickup_items(g_ptr); + autopick_pickup_items(creature_ptr, g_ptr); if (easy_floor) { diff --git a/src/spells-object.c b/src/spells-object.c index 8eb69ce3f..24da9c5b9 100644 --- a/src/spells-object.c +++ b/src/spells-object.c @@ -169,7 +169,7 @@ bool create_ammo(player_type *creature_ptr) msg_format(_("%sを作った。", "You make some ammo."), o_name); /* Auto-inscription */ - if (slot >= 0) autopick_alter_item(slot, FALSE); + if (slot >= 0) autopick_alter_item(creature_ptr, slot, FALSE); /* Destroy the wall */ cave_alter_feat(creature_ptr, y, x, FF_HURT_ROCK); @@ -210,7 +210,7 @@ bool create_ammo(player_type *creature_ptr) slot = inven_carry(creature_ptr, q_ptr); /* Auto-inscription */ - if (slot >= 0) autopick_alter_item(slot, FALSE); + if (slot >= 0) autopick_alter_item(creature_ptr, slot, FALSE); return TRUE; } @@ -248,7 +248,7 @@ bool create_ammo(player_type *creature_ptr) slot = inven_carry(creature_ptr, q_ptr); /* Auto-inscription */ - if (slot >= 0) autopick_alter_item(slot, FALSE); + if (slot >= 0) autopick_alter_item(creature_ptr, slot, FALSE); } return TRUE; diff --git a/src/spells1.c b/src/spells1.c index cb28d88d4..94002c033 100644 --- a/src/spells1.c +++ b/src/spells1.c @@ -952,7 +952,7 @@ static bool project_o(player_type *caster_ptr, MONSTER_IDX who, POSITION r, POSI identify_item(caster_ptr, o_ptr); /* Auto-inscription */ - autopick_alter_item((-this_o_idx), FALSE); + autopick_alter_item(caster_ptr, (-this_o_idx), FALSE); break; } diff --git a/src/spells2.c b/src/spells2.c index 14971415a..6448ec4ac 100644 --- a/src/spells2.c +++ b/src/spells2.c @@ -4224,7 +4224,7 @@ bool psychometry(player_type *caster_ptr) } /* Auto-inscription/destroy */ - autopick_alter_item(item, (bool)(okay && destroy_feeling)); + autopick_alter_item(caster_ptr, item, (bool)(okay && destroy_feeling)); return TRUE; } diff --git a/src/spells3.c b/src/spells3.c index 3a191594a..ca5c3fb61 100644 --- a/src/spells3.c +++ b/src/spells3.c @@ -1369,7 +1369,7 @@ void identify_pack(player_type *target_ptr) identify_item(target_ptr, o_ptr); /* Auto-inscription */ - autopick_alter_item(i, FALSE); + autopick_alter_item(target_ptr, i, FALSE); } } @@ -1732,7 +1732,7 @@ bool ident_spell(player_type *caster_ptr, bool only_equip) msg_format(_("床上: %s。", "On the ground: %s."), o_name); } - autopick_alter_item(item, (bool)(destroy_identify && !old_known)); + autopick_alter_item(caster_ptr, item, (bool)(destroy_identify && !old_known)); return TRUE; } @@ -1844,7 +1844,7 @@ bool identify_fully(player_type *caster_ptr, bool only_equip) } (void)screen_object(o_ptr, 0L); - autopick_alter_item(item, (bool)(destroy_identify && !old_known)); + autopick_alter_item(caster_ptr, item, (bool)(destroy_identify && !old_known)); return TRUE; } diff --git a/src/store.c b/src/store.c index a9ee0789d..57aed2957 100644 --- a/src/store.c +++ b/src/store.c @@ -4758,7 +4758,7 @@ static void store_purchase(player_type *player_ptr) msg_format(_("%s(%c)を手に入れた。", "You have %s (%c)."), o_name, index_to_label(item_new)); /* Auto-inscription */ - autopick_alter_item(item_new, FALSE); + autopick_alter_item(player_ptr, item_new, FALSE); /* Now, reduce the original stack's pval. */ if ((o_ptr->tval == TV_ROD) || (o_ptr->tval == TV_WAND)) @@ -5093,7 +5093,7 @@ static void store_sell(player_type *owner_ptr) /* If items remain, auto-inscribe before optimizing */ if (o_ptr->number > 0) - autopick_alter_item(item, FALSE); + autopick_alter_item(owner_ptr, item, FALSE); inven_item_optimize(owner_ptr, item); handle_stuff(owner_ptr); diff --git a/src/view-mainwindow.c b/src/view-mainwindow.c index f551e41ab..cc9f5606a 100644 --- a/src/view-mainwindow.c +++ b/src/view-mainwindow.c @@ -3130,7 +3130,7 @@ void map_info(POSITION y, POSITION x, TERM_COLOR *ap, SYMBOL_CODE *cp, TERM_COLO { byte act; - match_autopick = is_autopick(o_ptr); + match_autopick = is_autopick(p_ptr, o_ptr); if (match_autopick == -1) continue; -- 2.11.0