OSDN Git Service

階の雰囲気計算で, 判明した薬や上位魔法書などが雰囲気に反映されないと
[hengband/hengband.git] / src / object2.c
index 9fdef21..2a4f121 100644 (file)
@@ -1556,7 +1556,7 @@ void reduce_charges(object_type *o_ptr, int amt)
  *  Determine if an item can partly absorb a second item.
  *  Return maximum number of stack.
  */
-static int object_similar_part(object_type *o_ptr, object_type *j_ptr)
+int object_similar_part(object_type *o_ptr, object_type *j_ptr)
 {
        int i;
 
@@ -2933,6 +2933,7 @@ static void a_m_aux_2(object_type *o_ptr, int level, int power)
                                        case EGO_WISDOM:
                                        case EGO_BEAUTY:
                                        case EGO_LITE:
+                                       case EGO_DARK:
                                        case EGO_INFRAVISION:
                                                break;
                                        case EGO_SEEING:
@@ -4347,7 +4348,7 @@ void apply_magic(object_type *o_ptr, int lev, u32b mode)
        }
 
        /* Hack -- analyze ego-items */
-       else if (object_is_ego(o_ptr))
+       if (object_is_ego(o_ptr))
        {
                ego_item_type *e_ptr = &e_info[o_ptr->name2];
 
@@ -4851,7 +4852,7 @@ s16b drop_near(object_type *j_ptr, int chance, int y, int x)
        int bs, bn;
        int by, bx;
        int dy, dx;
-       int ty, tx;
+       int ty, tx = 0;
 
        s16b o_idx = 0;
 
@@ -5695,6 +5696,87 @@ bool inven_carry_okay(object_type *o_ptr)
 }
 
 
+bool object_sort_comp(object_type *o_ptr, s32b o_value, object_type *j_ptr)
+{
+       int o_type, j_type;
+
+       /* Use empty slots */
+       if (!j_ptr->k_idx) return TRUE;
+
+       /* Hack -- readable books always come first */
+       if ((o_ptr->tval == REALM1_BOOK) &&
+           (j_ptr->tval != REALM1_BOOK)) return TRUE;
+       if ((j_ptr->tval == REALM1_BOOK) &&
+           (o_ptr->tval != REALM1_BOOK)) return FALSE;
+
+       if ((o_ptr->tval == REALM2_BOOK) &&
+           (j_ptr->tval != REALM2_BOOK)) return TRUE;
+       if ((j_ptr->tval == REALM2_BOOK) &&
+           (o_ptr->tval != REALM2_BOOK)) return FALSE;
+
+       /* Objects sort by decreasing type */
+       if (o_ptr->tval > j_ptr->tval) return TRUE;
+       if (o_ptr->tval < j_ptr->tval) return FALSE;
+
+       /* Non-aware (flavored) items always come last */
+       /* Can happen in the home */
+       if (!object_is_aware(o_ptr)) return FALSE;
+       if (!object_is_aware(j_ptr)) return TRUE;
+
+       /* Objects sort by increasing sval */
+       if (o_ptr->sval < j_ptr->sval) return TRUE;
+       if (o_ptr->sval > j_ptr->sval) return FALSE;
+
+       /* Unidentified objects always come last */
+       /* Objects in the home can be unknown */
+       if (!object_is_known(o_ptr)) return FALSE;
+       if (!object_is_known(j_ptr)) return TRUE;
+
+       /* Fixed artifacts, random artifacts and ego items */
+       if (object_is_fixed_artifact(o_ptr)) o_type = 3;
+       else if (o_ptr->art_name) o_type = 2;
+       else if (object_is_ego(o_ptr)) o_type = 1;
+       else o_type = 0;
+
+       if (object_is_fixed_artifact(j_ptr)) j_type = 3;
+       else if (j_ptr->art_name) j_type = 2;
+       else if (object_is_ego(j_ptr)) j_type = 1;
+       else j_type = 0;
+
+       if (o_type < j_type) return TRUE;
+       if (o_type > j_type) return FALSE;
+
+       switch (o_ptr->tval)
+       {
+       case TV_FIGURINE:
+       case TV_STATUE:
+       case TV_CORPSE:
+       case TV_CAPTURE:
+               if (r_info[o_ptr->pval].level < r_info[j_ptr->pval].level) return TRUE;
+               if ((r_info[o_ptr->pval].level == r_info[j_ptr->pval].level) && (o_ptr->pval < j_ptr->pval)) return TRUE;
+               return FALSE;
+
+       case TV_SHOT:
+       case TV_ARROW:
+       case TV_BOLT:
+               /* Objects sort by increasing hit/damage bonuses */
+               if (o_ptr->to_h + o_ptr->to_d < j_ptr->to_h + j_ptr->to_d) return TRUE;
+               if (o_ptr->to_h + o_ptr->to_d > j_ptr->to_h + j_ptr->to_d) return FALSE;
+               break;
+
+       /* Hack:  otherwise identical rods sort by
+       increasing recharge time --dsb */
+       case TV_ROD:
+               if (o_ptr->pval < j_ptr->pval) return TRUE;
+               if (o_ptr->pval > j_ptr->pval) return FALSE;
+               break;
+       }
+
+       /* Objects sort by decreasing value */
+       return o_value > object_value(j_ptr);
+}
+
+
 /*
  * Add an item to the players inventory, and return the slot used.
  *
@@ -5771,60 +5853,13 @@ s16b inven_carry(object_type *o_ptr)
        /* Reorder the pack */
        if (i < INVEN_PACK)
        {
-               s32b o_value, j_value;
-
                /* Get the "value" of the item */
-               o_value = object_value(o_ptr);
+               s32b o_value = object_value(o_ptr);
 
                /* Scan every occupied slot */
                for (j = 0; j < INVEN_PACK; j++)
                {
-                       j_ptr = &inventory[j];
-
-                       /* Use empty slots */
-                       if (!j_ptr->k_idx) break;
-
-                       /* Hack -- readable books always come first */
-                       if ((o_ptr->tval == REALM1_BOOK) &&
-                           (j_ptr->tval != REALM1_BOOK)) break;
-                       if ((j_ptr->tval == REALM1_BOOK) &&
-                           (o_ptr->tval != REALM1_BOOK)) continue;
-
-                       if ((o_ptr->tval == REALM2_BOOK) &&
-                           (j_ptr->tval != REALM2_BOOK)) break;
-                       if ((j_ptr->tval == REALM2_BOOK) &&
-                           (o_ptr->tval != REALM2_BOOK)) continue;
-
-                       /* Objects sort by decreasing type */
-                       if (o_ptr->tval > j_ptr->tval) break;
-                       if (o_ptr->tval < j_ptr->tval) continue;
-
-                       /* Non-aware (flavored) items always come last */
-                       if (!object_is_aware(o_ptr)) continue;
-                       if (!object_is_aware(j_ptr)) break;
-
-                       /* Objects sort by increasing sval */
-                       if (o_ptr->sval < j_ptr->sval) break;
-                       if (o_ptr->sval > j_ptr->sval) continue;
-
-                       /* Unidentified objects always come last */
-                       if (!object_is_known(o_ptr)) continue;
-                       if (!object_is_known(j_ptr)) break;
-
-                       /* Hack:  otherwise identical rods sort by
-                       increasing recharge time --dsb */
-                       if (o_ptr->tval == TV_ROD)
-                       {
-                               if (o_ptr->pval < j_ptr->pval) break;
-                               if (o_ptr->pval > j_ptr->pval) continue;
-                       }
-
-                       /* Determine the "value" of the pack item */
-                       j_value = object_value(j_ptr);
-
-                       /* Objects sort by decreasing value */
-                       if (o_value > j_value) break;
-                       if (o_value < j_value) continue;
+                       if (object_sort_comp(o_ptr, o_value, &inventory[j])) break;
                }
 
                /* Use that slot */
@@ -5857,8 +5892,8 @@ s16b inven_carry(object_type *o_ptr)
        /* Forget location */
        j_ptr->iy = j_ptr->ix = 0;
 
-       /* No longer marked */
-       j_ptr->marked = 0;
+       /* Player touches it, and no longer marked */
+       j_ptr->marked = OM_TOUCHED;
 
        /* Increase the weight */
        p_ptr->total_weight += (j_ptr->number * j_ptr->weight);
@@ -6069,93 +6104,101 @@ void combine_pack(void)
        int             i, j, k;
        object_type     *o_ptr;
        object_type     *j_ptr;
-       bool            flag = FALSE;
-
+       bool            flag = FALSE, combined;
 
-       /* Combine the pack (backwards) */
-       for (i = INVEN_PACK; i > 0; i--)
+       do
        {
-               /* Get the item */
-               o_ptr = &inventory[i];
+               combined = FALSE;
 
-               /* Skip empty items */
-               if (!o_ptr->k_idx) continue;
-
-               /* Scan the items above that item */
-               for (j = 0; j < i; j++)
+               /* Combine the pack (backwards) */
+               for (i = INVEN_PACK; i > 0; i--)
                {
-                       int max_num;
-
                        /* Get the item */
-                       j_ptr = &inventory[j];
+                       o_ptr = &inventory[i];
 
                        /* Skip empty items */
-                       if (!j_ptr->k_idx) continue;
-
-                       /*
-                        * Get maximum number of the stack if these
-                        * are similar, get zero otherwise.
-                        */
-                       max_num = object_similar_part(j_ptr, o_ptr);
+                       if (!o_ptr->k_idx) continue;
 
-                       /* Can we (partialy) drop "o_ptr" onto "j_ptr"? */
-                       if (max_num && j_ptr->number < max_num)
+                       /* Scan the items above that item */
+                       for (j = 0; j < i; j++)
                        {
-                               if (o_ptr->number + j_ptr->number <= max_num)
-                               {
-                                       /* Take note */
-                                       flag = TRUE;
+                               int max_num;
 
-                                       /* Add together the item counts */
-                                       object_absorb(j_ptr, o_ptr);
+                               /* Get the item */
+                               j_ptr = &inventory[j];
 
-                                       /* One object is gone */
-                                       inven_cnt--;
+                               /* Skip empty items */
+                               if (!j_ptr->k_idx) continue;
 
-                                       /* Slide everything down */
-                                       for (k = i; k < INVEN_PACK; k++)
+                               /*
+                                * Get maximum number of the stack if these
+                                * are similar, get zero otherwise.
+                                */
+                               max_num = object_similar_part(j_ptr, o_ptr);
+
+                               /* Can we (partialy) drop "o_ptr" onto "j_ptr"? */
+                               if (max_num && j_ptr->number < max_num)
+                               {
+                                       if (o_ptr->number + j_ptr->number <= max_num)
                                        {
-                                               /* Structure copy */
-                                               inventory[k] = inventory[k+1];
+                                               /* Take note */
+                                               flag = TRUE;
+
+                                               /* Add together the item counts */
+                                               object_absorb(j_ptr, o_ptr);
+
+                                               /* One object is gone */
+                                               inven_cnt--;
+
+                                               /* Slide everything down */
+                                               for (k = i; k < INVEN_PACK; k++)
+                                               {
+                                                       /* Structure copy */
+                                                       inventory[k] = inventory[k+1];
+                                               }
+
+                                               /* Erase the "final" slot */
+                                               object_wipe(&inventory[k]);
                                        }
-                                       
-                                       /* Erase the "final" slot */
-                                       object_wipe(&inventory[k]);
-                               }
-                               else
-                               {
-                                       int old_num = o_ptr->number;
-                                       int remain = j_ptr->number + o_ptr->number - max_num;
+                                       else
+                                       {
+                                               int old_num = o_ptr->number;
+                                               int remain = j_ptr->number + o_ptr->number - max_num;
 #if 0
-                                       o_ptr->number -= remain;
+                                               o_ptr->number -= remain;
 #endif
-                                       /* Add together the item counts */
-                                       object_absorb(j_ptr, o_ptr);
+                                               /* Add together the item counts */
+                                               object_absorb(j_ptr, o_ptr);
 
-                                       o_ptr->number = remain;
+                                               o_ptr->number = remain;
 
-                                       /* Hack -- if rods are stacking, add the pvals (maximum timeouts) and current timeouts together. -LM- */
-                                       if (o_ptr->tval == TV_ROD)
-                                       {
-                                               o_ptr->pval =  o_ptr->pval * remain / old_num;
-                                               o_ptr->timeout = o_ptr->timeout * remain / old_num;
-                                       }
+                                               /* Hack -- if rods are stacking, add the pvals (maximum timeouts) and current timeouts together. -LM- */
+                                               if (o_ptr->tval == TV_ROD)
+                                               {
+                                                       o_ptr->pval =  o_ptr->pval * remain / old_num;
+                                                       o_ptr->timeout = o_ptr->timeout * remain / old_num;
+                                               }
 
-                                       /* Hack -- if wands are stacking, combine the charges. -LM- */
-                                       if (o_ptr->tval == TV_WAND)
-                                       {
-                                               o_ptr->pval = o_ptr->pval * remain / old_num;
+                                               /* Hack -- if wands are stacking, combine the charges. -LM- */
+                                               if (o_ptr->tval == TV_WAND)
+                                               {
+                                                       o_ptr->pval = o_ptr->pval * remain / old_num;
+                                               }
                                        }
-                               }
 
-                               /* Window stuff */
-                               p_ptr->window |= (PW_INVEN);
-                               
-                               /* Done */
-                               break;
+                                       /* Window stuff */
+                                       p_ptr->window |= (PW_INVEN);
+
+                                       /* Take note */
+                                       combined = TRUE;
+
+                                       /* Done */
+                                       break;
+                               }
                        }
                }
        }
+       while (combined);
 
        /* Message */
 #ifdef JP
@@ -6175,10 +6218,8 @@ void reorder_pack(void)
 {
        int             i, j, k;
        s32b            o_value;
-       s32b            j_value;
        object_type     forge;
        object_type     *q_ptr;
-       object_type     *j_ptr;
        object_type     *o_ptr;
        bool            flag = FALSE;
 
@@ -6201,55 +6242,7 @@ void reorder_pack(void)
                /* Scan every occupied slot */
                for (j = 0; j < INVEN_PACK; j++)
                {
-                       /* Get the item already there */
-                       j_ptr = &inventory[j];
-
-                       /* Use empty slots */
-                       if (!j_ptr->k_idx) break;
-
-                       /* Hack -- readable books always come first */
-                       if ((o_ptr->tval == REALM1_BOOK) &&
-                           (j_ptr->tval != REALM1_BOOK)) break;
-                       if ((j_ptr->tval == REALM1_BOOK) &&
-                           (o_ptr->tval != REALM1_BOOK)) continue;
-
-                       if ((o_ptr->tval == REALM2_BOOK) &&
-                           (j_ptr->tval != REALM2_BOOK)) break;
-                       if ((j_ptr->tval == REALM2_BOOK) &&
-                           (o_ptr->tval != REALM2_BOOK)) continue;
-
-                       /* Objects sort by decreasing type */
-                       if (o_ptr->tval > j_ptr->tval) break;
-                       if (o_ptr->tval < j_ptr->tval) continue;
-
-                       /* Non-aware (flavored) items always come last */
-                       if (!object_is_aware(o_ptr)) continue;
-                       if (!object_is_aware(j_ptr)) break;
-
-                       /* Objects sort by increasing sval */
-                       if (o_ptr->sval < j_ptr->sval) break;
-                       if (o_ptr->sval > j_ptr->sval) continue;
-
-                       /* Unidentified objects always come last */
-                       if (!object_is_known(o_ptr)) continue;
-                       if (!object_is_known(j_ptr)) break;
-
-                       /* Hack:  otherwise identical rods sort by
-                       increasing recharge time --dsb */
-                       if (o_ptr->tval == TV_ROD)
-                       {
-                               if (o_ptr->pval < j_ptr->pval) break;
-                               if (o_ptr->pval > j_ptr->pval) continue;
-                       }
-
-                       /* Determine the "value" of the pack item */
-                       j_value = object_value(j_ptr);
-
-
-
-                       /* Objects sort by decreasing value */
-                       if (o_value > j_value) break;
-                       if (o_value < j_value) continue;
+                       if (object_sort_comp(o_ptr, o_value, &inventory[j])) break;
                }
 
                /* Never move down */