From: Hourier Date: Tue, 10 Nov 2020 14:37:04 +0000 (+0900) Subject: [Refactor] #40945 Reshaped autopick.c automatically X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=febb827815752ff63b30cd48986c10f817f18aba;p=hengband%2Fhengband.git [Refactor] #40945 Reshaped autopick.c automatically --- diff --git a/src/autopick/autopick.c b/src/autopick/autopick.c index d4c69b8f9..a26c0298d 100644 --- a/src/autopick/autopick.c +++ b/src/autopick/autopick.c @@ -23,8 +23,8 @@ #include "inventory/inventory-object.h" #include "inventory/inventory-slot-types.h" #include "inventory/player-inventory.h" -#include "object/object-mark-types.h" #include "object/object-info.h" +#include "object/object-mark-types.h" #include "system/floor-type-definition.h" #include "term/screen-processor.h" #include "view/display-messages.h" @@ -34,52 +34,47 @@ */ static void autopick_delayed_alter_aux(player_type *player_ptr, INVENTORY_IDX item) { - object_type *o_ptr; - o_ptr = ref_item(player_ptr, item); - - if (o_ptr->k_idx == 0 || !(o_ptr->marked & OM_AUTODESTROY)) return; - - GAME_TEXT o_name[MAX_NLEN]; - describe_flavor(player_ptr, o_name, o_ptr, 0); - if (item >= 0) - { - inven_item_increase(player_ptr, item, -(o_ptr->number)); - inven_item_optimize(player_ptr, item); - } - else - { - delete_object_idx(player_ptr, 0 - item); - } - - msg_format(_("%sを自動破壊します。", "Auto-destroying %s."), o_name); + object_type *o_ptr; + o_ptr = ref_item(player_ptr, item); + + if (o_ptr->k_idx == 0 || !(o_ptr->marked & OM_AUTODESTROY)) + return; + + GAME_TEXT o_name[MAX_NLEN]; + describe_flavor(player_ptr, o_name, o_ptr, 0); + if (item >= 0) { + inven_item_increase(player_ptr, item, -(o_ptr->number)); + inven_item_optimize(player_ptr, item); + } else { + delete_object_idx(player_ptr, 0 - item); + } + + msg_format(_("%sを自動破壊します。", "Auto-destroying %s."), o_name); } - /* * Auto-destroy marked items in inventry and on floor */ void autopick_delayed_alter(player_type *owner_ptr) { - INVENTORY_IDX item; - - /* - * Scan inventry in reverse order to prevent - * skipping after inven_item_optimize() - */ - for (item = INVEN_TOTAL - 1; item >= 0; item--) - autopick_delayed_alter_aux(owner_ptr, item); - - floor_type *floor_ptr = owner_ptr->current_floor_ptr; - item = floor_ptr->grid_array[owner_ptr->y][owner_ptr->x].o_idx; - while (item) - { - OBJECT_IDX next = floor_ptr->o_list[item].next_o_idx; - autopick_delayed_alter_aux(owner_ptr, -item); - item = next; - } + INVENTORY_IDX item; + + /* + * Scan inventry in reverse order to prevent + * skipping after inven_item_optimize() + */ + for (item = INVEN_TOTAL - 1; item >= 0; item--) + autopick_delayed_alter_aux(owner_ptr, item); + + floor_type *floor_ptr = owner_ptr->current_floor_ptr; + item = floor_ptr->grid_array[owner_ptr->y][owner_ptr->x].o_idx; + while (item) { + OBJECT_IDX next = floor_ptr->o_list[item].next_o_idx; + autopick_delayed_alter_aux(owner_ptr, -item); + item = next; + } } - /* * Auto-inscription and/or destroy * @@ -88,66 +83,59 @@ void autopick_delayed_alter(player_type *owner_ptr) */ void autopick_alter_item(player_type *player_ptr, INVENTORY_IDX item, bool destroy) { - object_type *o_ptr; - o_ptr = ref_item(player_ptr, item); - int idx = find_autopick_list(player_ptr, o_ptr); - auto_inscribe_item(player_ptr, o_ptr, idx); - if (destroy && item <= INVEN_PACK) - auto_destroy_item(player_ptr, o_ptr, idx); + object_type *o_ptr; + o_ptr = ref_item(player_ptr, item); + int idx = find_autopick_list(player_ptr, o_ptr); + auto_inscribe_item(player_ptr, o_ptr, idx); + if (destroy && item <= INVEN_PACK) + auto_destroy_item(player_ptr, o_ptr, idx); } - /* * Automatically pickup/destroy items in this grid. */ -void autopick_pickup_items(player_type* player_ptr, 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; - for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx) - { - object_type *o_ptr = &player_ptr->current_floor_ptr->o_list[this_o_idx]; - next_o_idx = o_ptr->next_o_idx; - int idx = find_autopick_list(player_ptr, o_ptr); - auto_inscribe_item(player_ptr, o_ptr, idx); - bool is_auto_pickup = idx >= 0; - is_auto_pickup &= (autopick_list[idx].action & (DO_AUTOPICK | DO_QUERY_AUTOPICK)) != 0; - if (!is_auto_pickup) - { - auto_destroy_item(player_ptr, o_ptr, idx); - continue; - } - - disturb(player_ptr, FALSE, FALSE); - if (!check_store_item_to_inventory(player_ptr, o_ptr)) - { - GAME_TEXT o_name[MAX_NLEN]; - describe_flavor(player_ptr, o_name, o_ptr, 0); - msg_format(_("ザックには%sを入れる隙間がない。", "You have no room for %s."), o_name); - o_ptr->marked |= OM_NOMSG; - continue; - } - - if (!(autopick_list[idx].action & DO_QUERY_AUTOPICK)) - { - describe_pickup_item(player_ptr, this_o_idx); - continue; - } - - char out_val[MAX_NLEN + 20]; - GAME_TEXT o_name[MAX_NLEN]; - if (o_ptr->marked & OM_NO_QUERY) - { - continue; - } - - describe_flavor(player_ptr, o_name, o_ptr, 0); - sprintf(out_val, _("%sを拾いますか? ", "Pick up %s? "), o_name); - if (!get_check(out_val)) - { - o_ptr->marked |= OM_NOMSG | OM_NO_QUERY; - continue; - } - - describe_pickup_item(player_ptr, this_o_idx); - } + OBJECT_IDX this_o_idx, next_o_idx = 0; + for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx) { + object_type *o_ptr = &player_ptr->current_floor_ptr->o_list[this_o_idx]; + next_o_idx = o_ptr->next_o_idx; + int idx = find_autopick_list(player_ptr, o_ptr); + auto_inscribe_item(player_ptr, o_ptr, idx); + bool is_auto_pickup = idx >= 0; + is_auto_pickup &= (autopick_list[idx].action & (DO_AUTOPICK | DO_QUERY_AUTOPICK)) != 0; + if (!is_auto_pickup) { + auto_destroy_item(player_ptr, o_ptr, idx); + continue; + } + + disturb(player_ptr, FALSE, FALSE); + if (!check_store_item_to_inventory(player_ptr, o_ptr)) { + GAME_TEXT o_name[MAX_NLEN]; + describe_flavor(player_ptr, o_name, o_ptr, 0); + msg_format(_("ザックには%sを入れる隙間がない。", "You have no room for %s."), o_name); + o_ptr->marked |= OM_NOMSG; + continue; + } + + if (!(autopick_list[idx].action & DO_QUERY_AUTOPICK)) { + describe_pickup_item(player_ptr, this_o_idx); + continue; + } + + char out_val[MAX_NLEN + 20]; + GAME_TEXT o_name[MAX_NLEN]; + if (o_ptr->marked & OM_NO_QUERY) { + continue; + } + + describe_flavor(player_ptr, o_name, o_ptr, 0); + sprintf(out_val, _("%sを拾いますか? ", "Pick up %s? "), o_name); + if (!get_check(out_val)) { + o_ptr->marked |= OM_NOMSG | OM_NO_QUERY; + continue; + } + + describe_pickup_item(player_ptr, this_o_idx); + } }