OSDN Git Service

autopick.cの関数を外部から呼ぶ部分を簡略化。なるべくカプセル化する。
authormogami <mogami@0568b783-4c39-0410-ac80-bf13821ea2a2>
Wed, 22 Oct 2003 11:11:24 +0000 (11:11 +0000)
committermogami <mogami@0568b783-4c39-0410-ac80-bf13821ea2a2>
Wed, 22 Oct 2003 11:11:24 +0000 (11:11 +0000)
src/autopick.c
src/bldg.c
src/cmd1.c
src/cmd3.c
src/dungeon.c
src/externs.h
src/spells1.c
src/spells3.c
src/store.c

index 959abb7..534fbdd 100644 (file)
@@ -1312,36 +1312,19 @@ int is_autopick(object_type *o_ptr)
 /*
  *  Auto inscription
  */
-void auto_inscribe_item(int item, int idx)
+static void auto_inscribe_item(object_type *o_ptr, int idx)
 {
-       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];
-
-       /* Auto-inscription or Re-inscribe for resistances {%} */
-       if ((idx < 0 || !autopick_list[idx].insc) && !o_ptr->inscription)
-               return;
+       /* Are there auto-inscription? */
+       if (idx < 0 || !autopick_list[idx].insc) return;
 
        if (!o_ptr->inscription)
                o_ptr->inscription = quark_add(autopick_list[idx].insc);
 
-       if (item > INVEN_PACK)
-       {
-               /* Redraw inscription */
-               p_ptr->window |= (PW_EQUIP);
+       /* Redraw inscription */
+       p_ptr->window |= (PW_EQUIP | PW_INVEN);
 
-               /* {.} and {$} effect p_ptr->warning and TRC_TELEPORT_SELF */
-               p_ptr->update |= (PU_BONUS);
-       }
-       else if (item >= 0)
-       {
-               /* Redraw inscription */
-               p_ptr->window |= (PW_INVEN);
-       }
+       /* {.} and {$} effect p_ptr->warning and TRC_TELEPORT_SELF */
+       p_ptr->update |= (PU_BONUS);
 }
 
 
@@ -1413,41 +1396,35 @@ static bool is_opt_confirm_destroy(object_type *o_ptr)
 
 /*
  * 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;
 
-bool auto_destroy_item(int item, int autopick_idx)
+static void auto_destroy_item(object_type *o_ptr, int autopick_idx)
 {
        bool destroy = FALSE;
-       object_type *o_ptr;
-
-       /* Don't destroy equipped items */
-       if (item > INVEN_PACK) return FALSE;
-
-       /* 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];
-
-       /* Easy-Auto-Destroyer */
+       /* Easy-Auto-Destroyer (3rd priority) */
        if (is_opt_confirm_destroy(o_ptr)) destroy = TRUE;
 
-       /* Protected by auto-picker */
+       /* Protected by auto-picker (2nd priotity) */
        if (autopick_idx >= 0 &&
            !(autopick_list[autopick_idx].action & DO_AUTODESTROY))
                destroy = FALSE;
 
+       /* Auto-destroyer works only when !always_pickup */
        if (!always_pickup)
        {
-               /* Auto-picker/destroyer */
+               /* Auto-picker/destroyer (1st priority) */
                if (autopick_idx >= 0 &&
                    (autopick_list[autopick_idx].action & DO_AUTODESTROY))
                        destroy = TRUE;
        }
 
        /* Not to be destroyed */
-       if (!destroy) return FALSE;
+       if (!destroy) return;
 
        /* Now decided to destroy */
 
@@ -1469,7 +1446,7 @@ bool auto_destroy_item(int item, int autopick_idx)
 #endif
 
                /* Done */
-               return TRUE;
+               return;
        }
 
        /* Record name of destroyed item */
@@ -1479,7 +1456,7 @@ bool auto_destroy_item(int item, int autopick_idx)
        o_ptr->marked |= OM_AUTODESTROY;
        p_ptr->notice |= PN_AUTODESTROY;
 
-       return TRUE;
+       return;
 }
 
 
@@ -1527,7 +1504,7 @@ static void delayed_auto_destroy_aux(int item)
 
 
 /*
- *  Auto-destroy marked item in inventry and on floor
+ *  Auto-destroy marked items in inventry and on floor
  */
 void delayed_auto_destroy(void)
 {
@@ -1552,6 +1529,35 @@ void delayed_auto_destroy(void)
 
 
 /*
+ * Auto-inscription and/or destroy
+ *
+ * Auto-destroyer works only on inventory or on floor stack only when
+ * requested.
+ */
+void auto_do_item(int 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];
+
+       /* Get the index in the auto-pick/destroy list */
+       idx = is_autopick(o_ptr);
+
+       /* Do auto-inscription */
+       auto_inscribe_item(o_ptr, idx);
+
+       /* Do auto-destroy if needed */
+       if (destroy && item <= INVEN_PACK)
+               auto_destroy_item(o_ptr, idx);
+}
+
+
+/*
  * Automatically pickup/destroy items in this grid.
  */
 void auto_pickup_items(cave_type *c_ptr)
@@ -1569,78 +1575,84 @@ void auto_pickup_items(cave_type *c_ptr)
                /* Acquire next object */
                next_o_idx = o_ptr->next_o_idx;
 
+               /* Get the index of auto-picker list */
                idx = is_autopick(o_ptr);
 
-               /* Item index for floor -1,-2,-3,...  */
-               auto_inscribe_item((-this_o_idx), idx);
+               /* Nothing defined on auto-picker? */
+               if (idx < 0) continue;
 
-               if (idx >= 0 &&
-                       (autopick_list[idx].action & (DO_AUTOPICK | DO_QUERY_AUTOPICK)))
+               /* Always do auto-inscription first */
+               auto_inscribe_item(o_ptr, idx);
+
+               /* Do auto-destroy */
+               if (autopick_list[idx].action & DO_AUTODESTROY)
                {
-                       disturb(0,0);
+                       auto_destroy_item(o_ptr, idx);
+                       continue;
+               }
 
-                       if (!inven_carry_okay(o_ptr))
-                       {
-                               char o_name[MAX_NLEN];
+               /* Disturb on auto-pick */
+               disturb(0,0);
 
-                               /* Describe the object */
-                               object_desc(o_name, o_ptr, TRUE, 3);
+               /* Is there an inventory space? */
+               if (!inven_carry_okay(o_ptr))
+               {
+                       char o_name[MAX_NLEN];
 
-                               /* Message */
+                       /* Describe the object */
+                       object_desc(o_name, o_ptr, TRUE, 3);
+
+                       /* Message */
 #ifdef JP
-                               msg_format("¥¶¥Ã¥¯¤Ë¤Ï%s¤òÆþ¤ì¤ë·ä´Ö¤¬¤Ê¤¤¡£", o_name);
+                       msg_format("¥¶¥Ã¥¯¤Ë¤Ï%s¤òÆþ¤ì¤ë·ä´Ö¤¬¤Ê¤¤¡£", o_name);
 #else
-                               msg_format("You have no room for %s.", o_name);
+                       msg_format("You have no room for %s.", o_name);
 #endif
-                               /* Hack - remember that the item has given a message here. */
-                               o_ptr->marked |= OM_NOMSG;
+                       /*
+                        * Hack - No duplicate messages.
+                        * remember that a message is given for the item here.
+                        */
+                       o_ptr->marked |= OM_NOMSG;
 
+                       continue;
+               }
+
+               /* Ask if needed */
+               if (autopick_list[idx].action & DO_QUERY_AUTOPICK)
+               {
+                       char out_val[MAX_NLEN+20];
+                       char o_name[MAX_NLEN];
+
+                       if (o_ptr->marked & OM_NO_QUERY)
+                       {
+                               /* Already answered as 'No' */
                                continue;
                        }
-                       else if (autopick_list[idx].action & DO_QUERY_AUTOPICK)
-                       {
-                               char out_val[MAX_NLEN+20];
-                               char o_name[MAX_NLEN];
 
-                               if (o_ptr->marked & OM_NO_QUERY)
-                               {
-                                       /* Already answered as 'No' */
-                                       continue;
-                               }
-
-                               /* Describe the object */
-                               object_desc(o_name, o_ptr, TRUE, 3);
+                       /* Describe the object */
+                       object_desc(o_name, o_ptr, TRUE, 3);
 
 #ifdef JP
-                               sprintf(out_val, "%s¤ò½¦¤¤¤Þ¤¹¤«? ", o_name);
+                       sprintf(out_val, "%s¤ò½¦¤¤¤Þ¤¹¤«? ", o_name);
 #else
-                               sprintf(out_val, "Pick up %s? ", o_name);
+                       sprintf(out_val, "Pick up %s? ", o_name);
 #endif
 
-                               if (!get_check(out_val))
-                               {
-                                       /* Hack - remember that the item has given a message here. */
-                                       o_ptr->marked |= (OM_NOMSG | OM_NO_QUERY);
-                                       continue;
-                               }
-
+                       if (!get_check(out_val))
+                       {
+                               /*
+                                * Hack - No duplicate messages/questions.
+                                * remember that a message is given
+                                * for the item here.
+                                */
+                               o_ptr->marked |= (OM_NOMSG | OM_NO_QUERY);
+                               continue;
                        }
-                       py_pickup_aux(this_o_idx);
 
-                       continue;
-               }
-               
-               /*
-                * Do auto-destroy;
-                * When always_pickup is 'yes', we disable
-                * auto-destroyer from autopick function, and do only
-                * easy-auto-destroyer.
-                */
-               else
-               {
-                       if (auto_destroy_item((-this_o_idx), idx))
-                               continue;
                }
+
+               /* Pick it up! */
+               py_pickup_aux(this_o_idx);
        }
 }
 
index f538f29..9fdfbbb 100644 (file)
@@ -3841,7 +3841,7 @@ msg_format("%s 
 #endif
 
                        /* Auto-inscription */
-                       auto_inscribe_item(item, is_autopick(o_ptr));
+                       auto_do_item(item, FALSE);
 
                        /* Update the gold display */
                        building_prt_gold();
@@ -4142,7 +4142,7 @@ static void building_recharge_all(void)
                        identify_item(o_ptr);
 
                        /* Auto-inscription */
-                       auto_inscribe_item(i, is_autopick(o_ptr));
+                       auto_do_item(i, FALSE);
                }
 
                /* Recharge */
index 0839d28..ce3f7f9 100644 (file)
@@ -806,19 +806,13 @@ void py_pickup_aux(int o_idx)
 
        if (p_ptr->pseikaku == SEIKAKU_MUNCHKIN)
        {
-               int idx;
                bool old_known = identify_item(o_ptr);
 
                /* Auto-inscription/destroy */
-               idx = is_autopick(o_ptr);
-               auto_inscribe_item(slot, idx);
-               if (destroy_identify && !old_known)
-               {
-                       if (auto_destroy_item(slot, idx))
-                       {
-                               if (o_ptr->marked & OM_AUTODESTROY) return;
-                       }
-               }
+               auto_do_item(slot, (bool)(destroy_identify && !old_known));
+
+               /* If it is destroyed, don't pick it up */
+               if (o_ptr->marked & OM_AUTODESTROY) return;
        }
 
        /* Describe the object */
index c353498..ebee3d3 100644 (file)
@@ -434,7 +434,7 @@ msg_print("
                identify_item(o_ptr);
 
                /* Auto-inscription */
-               auto_inscribe_item(item, is_autopick(o_ptr));
+               auto_do_item(item, FALSE);
        }
 
        /* Take a turn */
@@ -971,14 +971,11 @@ void do_cmd_destroy(void)
                        }
                        if (i == 'a' || i == 'A')
                        {
-                               int idx;
-
                                /* Add an auto-destroy preference line */
                                if (add_auto_register(o_ptr))
                                {
                                        /* Auto-destroy it */
-                                       idx = is_autopick(o_ptr);
-                                       auto_destroy_item(item, idx);
+                                       auto_do_item(item, TRUE);
                                }
 
                                /* The object is already destroyed. */
index 7b7b202..99ee2fc 100644 (file)
@@ -96,7 +96,6 @@ static void sense_inventory_aux(int slot, bool heavy)
        byte        feel;
        object_type *o_ptr = &inventory[slot];
        char        o_name[MAX_NLEN];
-       int idx;
 
        /* We know about it already, do not tell us again */
        if (o_ptr->ident & (IDENT_SENSE))return;
@@ -202,10 +201,7 @@ o_name, index_to_label(slot),game_inscriptions[feel]);
        o_ptr->feeling = feel;
 
        /* Auto-inscription/destroy */
-       idx = is_autopick(o_ptr);
-       auto_inscribe_item(slot, idx);
-       if (destroy_feeling)
-               auto_destroy_item(slot, idx);
+       auto_do_item(slot, destroy_feeling);
 
        /* Combine / Reorder the pack (later) */
        p_ptr->notice |= (PN_COMBINE | PN_REORDER);
@@ -1524,7 +1520,6 @@ bool psychometry(void)
        byte            feel;
        cptr            q, s;
        bool okay = FALSE;
-       int idx;
 
        item_tester_no_ryoute = TRUE;
        /* Get an item */
@@ -1632,10 +1627,7 @@ msg_format("%s
        }
 
        /* Auto-inscription/destroy */
-       idx = is_autopick(o_ptr);
-       auto_inscribe_item(item, idx);
-       if (okay && destroy_feeling)
-               auto_destroy_item(item, idx);
+       auto_do_item(item, (bool)(okay && destroy_feeling));
 
        /* Something happened */
        return (TRUE);
index 5f95b99..13dda3b 100644 (file)
@@ -528,8 +528,7 @@ extern void init_autopicker(void);
 extern errr process_pickpref_file_line(char *buf);
 extern cptr autopick_line_from_entry(autopick_type *entry);
 extern int is_autopick(object_type *o_ptr);
-extern void auto_inscribe_item(int item, int idx);
-extern bool auto_destroy_item(int item, int autopick_idx);
+extern void auto_do_item(int item, bool destroy);
 extern void delayed_auto_destroy(void);
 extern void auto_pickup_items(cave_type *c_ptr);
 extern bool add_auto_register(object_type *o_ptr);
index 2ca71e2..8c0de46 100644 (file)
@@ -1543,7 +1543,7 @@ note_kill = "
                                identify_item(o_ptr);
 
                                /* Auto-inscription */
-                               auto_inscribe_item(-this_o_idx, is_autopick(o_ptr));
+                               auto_do_item((-this_o_idx), FALSE);
                                break;
                        }
 
index 0be999b..9cccbdd 100644 (file)
@@ -2012,7 +2012,7 @@ void identify_pack(void)
                identify_item(o_ptr);
 
                /* Auto-inscription */
-               auto_inscribe_item(i, is_autopick(o_ptr));
+               auto_do_item(i, FALSE);
        }
 }
 
@@ -2825,7 +2825,6 @@ bool ident_spell(bool only_equip)
        char            o_name[MAX_NLEN];
        cptr            q, s;
        bool old_known;
-       int idx;
 
        item_tester_no_ryoute = TRUE;
 
@@ -2902,10 +2901,7 @@ s = "
        }
 
        /* Auto-inscription/destroy */
-       idx = is_autopick(o_ptr);
-       auto_inscribe_item(item, idx);
-       if (destroy_identify && !old_known)
-               auto_destroy_item(item, idx);
+       auto_do_item(item, (bool)(destroy_identify && !old_known));
 
        /* Something happened */
        return (TRUE);
@@ -3004,7 +3000,6 @@ bool identify_fully(bool only_equip)
        char            o_name[MAX_NLEN];
        cptr            q, s;
        bool old_known;
-       int idx;
 
        item_tester_no_ryoute = TRUE;
        if (only_equip)
@@ -3087,10 +3082,7 @@ s = "
        (void)screen_object(o_ptr, TRUE);
 
        /* Auto-inscription/destroy */
-       idx = is_autopick(o_ptr);
-       auto_inscribe_item(item, idx);
-       if (destroy_identify && !old_known)
-               auto_destroy_item(item, idx);
+       auto_do_item(item, (bool)(destroy_identify && !old_known));
 
        /* Success */
        return (TRUE);
index 8c671af..5415e49 100644 (file)
@@ -3436,7 +3436,7 @@ msg_format("%s
 #endif
 
                                /* Auto-inscription */
-                               auto_inscribe_item(item_new, is_autopick(&inventory[item_new]));
+                               auto_do_item(item_new, FALSE);
 
                                /* Now, reduce the original stack's pval. */
                                if ((o_ptr->tval == TV_ROD) || (o_ptr->tval == TV_WAND))
@@ -3872,7 +3872,8 @@ msg_format("%s
                        inven_item_describe(item);
 
                        /* If items remain, auto-inscribe before optimizing */
-                       if (o_ptr->number > 0) auto_inscribe_item(item, is_autopick(o_ptr));
+                       if (o_ptr->number > 0)
+                               auto_do_item(item, FALSE);
 
                        inven_item_optimize(item);