OSDN Git Service

幻覚時にペットが敵モンスターを殴ると、バッファオーバランする可能性があるので修正。
[hengband/hengband.git] / src / melee2.c
index 4ee3b46..2666196 100644 (file)
@@ -1434,7 +1434,7 @@ static bool monst_attack_monst(int m_idx, int t_idx)
        int             ap_cnt;
        int             ac, rlev, pt;
        char            m_name[80], t_name[80];
-       char            temp[80];
+       char            temp[MAX_NLEN];
        bool            blinked;
        bool            explode = FALSE, touched = FALSE, fear = FALSE;
        int             y_saver = t_ptr->fy;
@@ -2169,6 +2169,14 @@ act = "%s
 }
 
 
+static bool check_hp_for_feat_destruction(feature_type *f_ptr, monster_type *m_ptr)
+{
+       return !have_flag(f_ptr->flags, FF_GLASS) ||
+              (r_info[m_ptr->r_idx].flags2 & RF2_STUPID) ||
+              (m_ptr->hp >= MAX(m_ptr->maxhp / 3, 200));
+}
+
+
 /*
  * Process a monster
  *
@@ -2282,6 +2290,14 @@ static void process_monster(int m_idx)
 #endif
                }
 
+               if (record_named_pet && is_pet(m_ptr) && m_ptr->nickname)
+               {
+                       char m_name[80];
+
+                       monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
+                       do_cmd_write_nikki(NIKKI_NAMED_PET, RECORD_NAMED_PET_LOSE_PARENT, m_name);
+               }
+
                /* Delete the monster */
                delete_monster_idx(m_idx);
 
@@ -2437,7 +2453,7 @@ static void process_monster(int m_idx)
                (void)set_monster_csleep(m_idx, 0);
 
                /* Notice the "waking up" */
-               if (see_m)
+               if (m_ptr->ml)
                {
                        char m_name[80];
 
@@ -2452,13 +2468,10 @@ static void process_monster(int m_idx)
 #endif
                }
 
-               if (m_ptr->ml)
+               /* Hack -- Count the wakings */
+               if (is_original_ap_and_seen(m_ptr) && (r_ptr->r_wake < MAX_UCHAR))
                {
-                       /* Hack -- Count the wakings */
-                       if ((r_ptr->r_wake < MAX_UCHAR) && is_original_ap(m_ptr))
-                       {
-                               r_ptr->r_wake++;
-                       }
+                       r_ptr->r_wake++;
                }
        }
 
@@ -2856,7 +2869,7 @@ msg_format("%^s%s", m_name, monmessage);
                else if ((r_ptr->flags2 & RF2_KILL_WALL) &&
                         (can_cross ? !have_flag(f_ptr->flags, FF_LOS) : !is_riding_mon) &&
                         have_flag(f_ptr->flags, FF_HURT_DISI) && !have_flag(f_ptr->flags, FF_PERMANENT) &&
-                        (!have_flag(f_ptr->flags, FF_GLASS) || (r_ptr->flags2 & RF2_STUPID) || (m_ptr->hp >= MAX(m_ptr->maxhp / 3, 200))))
+                        check_hp_for_feat_destruction(f_ptr, m_ptr))
                {
                        /* Eat through walls/doors/rubble */
                        do_move = TRUE;
@@ -2929,7 +2942,7 @@ msg_format("%^s%s", m_name, monmessage);
                                (!is_pet(m_ptr) || (p_ptr->pet_extra_flags & PF_OPEN_DOORS)))
                        {
                                /* Attempt to Bash XXX XXX XXX */
-                               if (randint0(m_ptr->hp / 10) > f_ptr->power)
+                               if (check_hp_for_feat_destruction(f_ptr, m_ptr) && (randint0(m_ptr->hp / 10) > f_ptr->power))
                                {
                                        /* Message */
                                        if (have_flag(f_ptr->flags, FF_GLASS))
@@ -3253,8 +3266,6 @@ msg_format("%^s%s", m_name, monmessage);
                /* Creature has been allowed move */
                if (do_move)
                {
-                       s16b this_o_idx, next_o_idx;
-
                        /* Take a turn */
                        do_turn = TRUE;
 
@@ -3310,7 +3321,7 @@ msg_format("%^s%s", m_name, monmessage);
                        /* Possible disturb */
                        if (m_ptr->ml &&
                            (disturb_move ||
-                            (disturb_near && (m_ptr->mflag & MFLAG_VIEW)) ||
+                            (disturb_near && (m_ptr->mflag & MFLAG_VIEW) && projectable(py, px, m_ptr->fy, m_ptr->fx)) ||
                             (disturb_high && ap_r_ptr->r_tkills && ap_r_ptr->level >= p_ptr->lev)))
                        {
                                /* Disturb */
@@ -3318,39 +3329,38 @@ msg_format("%^s%s", m_name, monmessage);
                                        disturb(0, 0);
                        }
 
-                       /* Scan all objects in the grid */
-                       for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
+                       /* Take or Kill objects on the floor */
+                       if (c_ptr->o_idx && (r_ptr->flags2 & (RF2_TAKE_ITEM | RF2_KILL_ITEM)) &&
+                           (!is_pet(m_ptr) || ((p_ptr->pet_extra_flags & PF_PICKUP_ITEMS) && (r_ptr->flags2 & RF2_TAKE_ITEM))))
                        {
-                               object_type *o_ptr;
-
-                               /* Acquire object */
-                               o_ptr = &o_list[this_o_idx];
-
-                               /* Acquire next object */
-                               next_o_idx = o_ptr->next_o_idx;
-
-                               /* Skip gold */
-                               if (o_ptr->tval == TV_GOLD) continue;
-
-                               /*
-                                * Skip "real" corpses and statues, to avoid extreme
-                                * silliness like a novice rogue pockets full of statues
-                                * and corpses.
-                                */
-                               if ((o_ptr->tval == TV_CORPSE) ||
-                                   (o_ptr->tval == TV_STATUE)) continue;
+                               s16b this_o_idx, next_o_idx;
+                               bool do_take = (r_ptr->flags2 & RF2_TAKE_ITEM) ? TRUE : FALSE;
 
-                               /* Take or Kill objects on the floor */
-                               if ((r_ptr->flags2 & (RF2_TAKE_ITEM | RF2_KILL_ITEM)) &&
-                                        (!is_pet(m_ptr) || (p_ptr->pet_extra_flags & PF_PICKUP_ITEMS)))
+                               /* Scan all objects in the grid */
+                               for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
                                {
-                                       u32b flgs[TR_FLAG_SIZE];
+                                       u32b flgs[TR_FLAG_SIZE], flg2 = 0L, flg3 = 0L, flgr = 0L;
+                                       char m_name[80], o_name[MAX_NLEN];
 
-                                       u32b flg2 = 0L;
-                                       u32b flg3 = 0L;
+                                       /* Acquire object */
+                                       object_type *o_ptr = &o_list[this_o_idx];
 
-                                       char m_name[80];
-                                       char o_name[MAX_NLEN];
+                                       /* Acquire next object */
+                                       next_o_idx = o_ptr->next_o_idx;
+
+                                       if (do_take)
+                                       {
+                                               /* Skip gold */
+                                               if (o_ptr->tval == TV_GOLD) continue;
+
+                                               /*
+                                                * Skip "real" corpses and statues, to avoid extreme
+                                                * silliness like a novice rogue pockets full of statues
+                                                * and corpses.
+                                                */
+                                               if ((o_ptr->tval == TV_CORPSE) ||
+                                                   (o_ptr->tval == TV_STATUE)) continue;
+                                       }
 
                                        /* Extract some flags */
                                        object_flags(o_ptr, flgs);
@@ -3362,12 +3372,12 @@ msg_format("%^s%s", m_name, monmessage);
                                        monster_desc(m_name, m_ptr, MD_INDEF_HIDDEN);
 
                                        /* React to objects that hurt the monster */
-                                       if (have_flag(flgs, TR_KILL_DRAGON)) flg3 |= (RF3_DRAGON);
                                        if (have_flag(flgs, TR_SLAY_DRAGON)) flg3 |= (RF3_DRAGON);
+                                       if (have_flag(flgs, TR_KILL_DRAGON)) flg3 |= (RF3_DRAGON);
                                        if (have_flag(flgs, TR_SLAY_TROLL))  flg3 |= (RF3_TROLL);
                                        if (have_flag(flgs, TR_KILL_TROLL))  flg3 |= (RF3_TROLL);
-                                       if (have_flag(flgs, TR_KILL_GIANT))  flg3 |= (RF3_GIANT);
                                        if (have_flag(flgs, TR_SLAY_GIANT))  flg3 |= (RF3_GIANT);
+                                       if (have_flag(flgs, TR_KILL_GIANT))  flg3 |= (RF3_GIANT);
                                        if (have_flag(flgs, TR_SLAY_ORC))    flg3 |= (RF3_ORC);
                                        if (have_flag(flgs, TR_KILL_ORC))    flg3 |= (RF3_ORC);
                                        if (have_flag(flgs, TR_SLAY_DEMON))  flg3 |= (RF3_DEMON);
@@ -3380,12 +3390,18 @@ msg_format("%^s%s", m_name, monmessage);
                                        if (have_flag(flgs, TR_KILL_EVIL))   flg3 |= (RF3_EVIL);
                                        if (have_flag(flgs, TR_SLAY_HUMAN))  flg2 |= (RF2_HUMAN);
                                        if (have_flag(flgs, TR_KILL_HUMAN))  flg2 |= (RF2_HUMAN);
+                                       if (have_flag(flgs, TR_BRAND_ACID))  flgr |= (RFR_IM_ACID);
+                                       if (have_flag(flgs, TR_BRAND_ELEC))  flgr |= (RFR_IM_ELEC);
+                                       if (have_flag(flgs, TR_BRAND_FIRE))  flgr |= (RFR_IM_FIRE);
+                                       if (have_flag(flgs, TR_BRAND_COLD))  flgr |= (RFR_IM_COLD);
+                                       if (have_flag(flgs, TR_BRAND_POIS))  flgr |= (RFR_IM_POIS);
 
                                        /* The object cannot be picked up by the monster */
-                                       if (object_is_artifact(o_ptr) || (r_ptr->flags3 & flg3) || (r_ptr->flags2 & flg2))
+                                       if (object_is_artifact(o_ptr) || (r_ptr->flags3 & flg3) || (r_ptr->flags2 & flg2) ||
+                                           ((~(r_ptr->flagsr) & flgr) && !(r_ptr->flagsr & RFR_RES_ALL)))
                                        {
                                                /* Only give a message for "take_item" */
-                                               if ((r_ptr->flags2 & (RF2_TAKE_ITEM)) && (r_ptr->flags2 & (RF2_STUPID)))
+                                               if (do_take && (r_ptr->flags2 & RF2_STUPID))
                                                {
                                                        /* Take note */
                                                        did_take_item = TRUE;
@@ -3404,7 +3420,7 @@ msg_format("%^s%s", m_name, monmessage);
                                        }
 
                                        /* Pick up the item */
-                                       else if (r_ptr->flags2 & RF2_TAKE_ITEM)
+                                       else if (do_take)
                                        {
                                                /* Take note */
                                                did_take_item = TRUE;
@@ -3424,7 +3440,7 @@ msg_format("%^s%s", m_name, monmessage);
                                                excise_object_idx(this_o_idx);
 
                                                /* Forget mark */
-                                               o_ptr->marked = 0;
+                                               o_ptr->marked &= OM_TOUCHED;
 
                                                /* Forget location */
                                                o_ptr->iy = o_ptr->ix = 0;
@@ -4227,7 +4243,7 @@ static void process_monsters_mtimed_aux(int m_idx, int mtimed_idx)
                                else
                                {
                                        /* Notice the "waking up" */
-                                       if (is_seen(m_ptr))
+                                       if (m_ptr->ml)
                                        {
                                                char m_name[80];
 
@@ -4605,14 +4621,33 @@ void monster_gain_exp(int m_idx, int s_idx)
                {
                        if (!ignore_unview || player_can_see_bold(m_ptr->fy, m_ptr->fx))
                        {
+                               if (p_ptr->image)
+                               {
+                                       monster_race *hallu_race;
+
+                                       do
+                                       {
+                                               hallu_race = &r_info[randint1(max_r_idx - 1)];
+                                       }
+                                       while (!hallu_race->name || (hallu_race->flags1 & RF1_UNIQUE));
+
 #ifdef JP
-                               msg_format("%s¤Ï%s¤Ë¿Ê²½¤·¤¿¡£", m_name, r_name + r_ptr->name);
+                                       msg_format("%s¤Ï%s¤Ë¿Ê²½¤·¤¿¡£", m_name, r_name + hallu_race->name);
 #else
-                               msg_format("%^s evolved into %s.", m_name, r_name + r_ptr->name);
+                                       msg_format("%^s evolved into %s.", m_name, r_name + hallu_race->name);
 #endif
+                               }
+                               else
+                               {
+#ifdef JP
+                                       msg_format("%s¤Ï%s¤Ë¿Ê²½¤·¤¿¡£", m_name, r_name + r_ptr->name);
+#else
+                                       msg_format("%^s evolved into %s.", m_name, r_name + r_ptr->name);
+#endif
+                               }
                        }
 
-                       r_info[old_r_idx].r_xtra1 |= MR1_SINKA;
+                       if (!p_ptr->image) r_info[old_r_idx].r_xtra1 |= MR1_SINKA;
 
                        /* Now you feel very close to this pet. */
                        m_ptr->parent_m_idx = 0;