OSDN Git Service

Add new option -- show_ammo_detail / show_ammo_no_crit
[hengband/hengband.git] / src / autopick.c
index 029ff41..cedf34c 100644 (file)
@@ -210,7 +210,7 @@ static bool autopick_new_entry(autopick_type *entry, cptr str, bool allow_defaul
        cptr prev_ptr, ptr, old_ptr;
        int prev_flg;
 
-       if (str[1] == ':') switch (str[0])
+       if (str[0] && str[1] == ':') switch (str[0])
        {
        case '?': case '%':
        case 'A': case 'P': case 'C':
@@ -219,6 +219,7 @@ static bool autopick_new_entry(autopick_type *entry, cptr str, bool allow_defaul
 
        entry->flag[0] = entry->flag[1] = 0L;
        entry->dice = 0;
+       entry->bonus = 0;
 
        act = DO_AUTOPICK | DO_DISPLAY;
        while (TRUE)
@@ -520,7 +521,6 @@ static void autopick_entry_from_object(autopick_type *entry, object_type *o_ptr)
        {
                /* Ego objects */
                if (object_is_ego(o_ptr))
-                   
                {
                        if (object_is_weapon_armour_ammo(o_ptr))
                        {
@@ -541,11 +541,8 @@ static void autopick_entry_from_object(autopick_type *entry, object_type *o_ptr)
                                /* Don't use the object description */
                                name = FALSE;
 
-                               if (object_is_weapon_armour_ammo(o_ptr))
-                               {
-                                       /* Restrict to 'common' equipments */
-                                       if (!object_is_rare(o_ptr)) ADD_FLG(FLG_COMMON);
-                               }
+                               /* Restrict to 'common' equipments */
+                               if (!object_is_rare(o_ptr)) ADD_FLG(FLG_COMMON);
                        }
 
                        ADD_FLG(FLG_EGO);
@@ -692,6 +689,8 @@ static void autopick_free_entry(autopick_type *entry)
 {
        string_free(entry->name);
        string_free(entry->insc);
+       entry->name = NULL;
+       entry->insc = NULL;
 }
 
 
@@ -745,7 +744,7 @@ static cptr pickpref_filename(int filename_mode)
                return format("%s.prf", namebase);
 
        case PT_WITH_PNAME:
-               return format("%s-%s.prf", namebase, player_name);
+               return format("%s-%s.prf", namebase, player_base);
 
        default:
                return NULL;
@@ -830,10 +829,10 @@ static void add_autopick_list(autopick_type *entry)
                C_MAKE(autopick_list, max_max_autopick, autopick_type);
 
                /* Copy from old list to new list */
-               C_COPY(autopick_list, old_autopick_list, old_max_max_autopick, autopick_type);
+               (void)C_COPY(autopick_list, old_autopick_list, old_max_max_autopick, autopick_type);
 
                /* Kill old list */
-               C_FREE(old_autopick_list, old_max_max_autopick, autopick_type);
+               C_KILL(old_autopick_list, old_max_max_autopick, autopick_type);
        }
 
        /* Add one line */
@@ -874,7 +873,11 @@ errr process_autopick_file_command(char *buf)
                   && entry->flag[0] == autopick_list[i].flag[0]
                   && entry->flag[1] == autopick_list[i].flag[1]
                   && entry->dice == autopick_list[i].dice
-                  && entry->bonus == autopick_list[i].bonus) return 0;
+                  && entry->bonus == autopick_list[i].bonus)
+               {
+                       autopick_free_entry(entry);
+                       return 0;
+               }
 
        add_autopick_list(entry);
        return 0;
@@ -1058,6 +1061,12 @@ static bool is_autopick_aux(object_type *o_ptr, autopick_type *entry, cptr o_nam
                /* Require boosted dice */
                if ((o_ptr->dd == k_ptr->dd) && (o_ptr->ds == k_ptr->ds))
                        return FALSE;
+               
+               /* In Vault Quest, Dice must be hide.*/
+               if(!object_is_known(o_ptr) && object_is_quest_target(o_ptr))
+               {
+                       return FALSE;
+               }
        }
 
        /*** Weapons which dd*ds is more than nn ***/
@@ -1494,21 +1503,21 @@ static bool is_opt_confirm_destroy(object_type *o_ptr)
        /* Known to be worthless? */
        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_shoukinkubi(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;
 
@@ -1531,20 +1540,20 @@ static bool is_opt_confirm_destroy(object_type *o_ptr)
                else if (p_ptr->pclass == CLASS_NINJA)
                {
                        if (o_ptr->tval == TV_LITE &&
-                           o_ptr->name2 == EGO_LITE_DARKNESS)
+                           o_ptr->name2 == EGO_LITE_DARKNESS && object_is_known(o_ptr))
                                return FALSE;
                }
                else if (p_ptr->pclass == CLASS_BEASTMASTER ||
                         p_ptr->pclass == CLASS_CAVALRY)
                {
                        if (o_ptr->tval == TV_WAND &&
-                           o_ptr->sval == SV_WAND_HEAL_MONSTER)
+                           o_ptr->sval == SV_WAND_HEAL_MONSTER && object_is_aware(o_ptr))
                                return FALSE;
                }
        }
-       
+
        if (o_ptr->tval == TV_GOLD) return FALSE;
-       
+
        return TRUE;
 }
 
@@ -1605,7 +1614,7 @@ static void auto_destroy_item(object_type *o_ptr, int autopick_idx)
        }
 
        /* Record name of destroyed item */
-       COPY(&autopick_last_destroyed_object, o_ptr, object_type);
+       (void)COPY(&autopick_last_destroyed_object, o_ptr, object_type);
 
        /* Destroy Later */
        o_ptr->marked |= OM_AUTODESTROY;
@@ -2980,7 +2989,7 @@ static void free_text_lines(cptr *lines_list)
                string_free(lines_list[lines]);
 
        /* free list of pointers */
-       C_FREE((char **)lines_list, MAX_LINES, char *);
+       C_KILL(lines_list, MAX_LINES, cptr);
 }
 
 
@@ -3711,6 +3720,8 @@ static void search_for_object(text_body_type *tb, object_type *o_ptr, bool forwa
 
        while (TRUE)
        {
+               bool match;
+
                /* End of list? */
                if (forward)
                {
@@ -3725,8 +3736,9 @@ 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? */
-               if (!is_autopick_aux(o_ptr, entry, o_name)) continue;
-
+               match = is_autopick_aux(o_ptr, entry, o_name);
+               autopick_free_entry(entry);
+               if (!match)     continue;
 
                /* Found a line but it's inactive */
                if (tb->states[i] & LSTAT_BYPASS)
@@ -4603,6 +4615,8 @@ static void draw_text_editor(text_body_type *tb)
                        char f;
                        cptr v;
                        cptr s = tb->lines_list[y];
+                       char *ss, *s_keep;
+                       int s_len;
 
                        /* Update this line's state */
                        tb->states[y] = state;
@@ -4614,13 +4628,20 @@ static void draw_text_editor(text_body_type *tb)
                        if (streq(s, "$AUTOREGISTER"))
                                state |= LSTAT_AUTOREGISTER;
 
+                       s_len = strlen(s);
+                       ss = (char *)string_make(s);
+                       s_keep = ss;
+
                        /* Parse the expr */
-                       v = process_pref_file_expr(&s, &f);
+                       v = process_pref_file_expr(&ss, &f);
 
                        /* Set flag */
                        if (streq(v, "0")) state |= LSTAT_BYPASS;
                        else state &= ~LSTAT_BYPASS;
 
+                       /* Cannot use string_free() because the string was "destroyed" */
+                       C_KILL(s_keep, s_len + 1, char);
+
                        /* Re-update this line's state */
                        tb->states[y] = state | LSTAT_EXPRESSION;
                }
@@ -4778,7 +4799,7 @@ static void draw_text_editor(text_body_type *tb)
                        str1 = "This line is a comment.";
 #endif
                }
-               else if (tb->lines_list[tb->cy][1] == ':')
+               else if (tb->lines_list[tb->cy][0] && tb->lines_list[tb->cy][1] == ':')
                {
                        switch(tb->lines_list[tb->cy][0])
                        {
@@ -6315,6 +6336,7 @@ void do_cmd_edit_autopick(void)
 
        free_text_lines(tb->lines_list);
 
+       string_free(tb->search_str);
        string_free(tb->last_destroyed);
 
        /* Destroy string chain */