OSDN Git Service

階の雰囲気計算で, 判明した薬や上位魔法書などが雰囲気に反映されないと
[hengband/hengband.git] / src / spells3.c
index 6c98221..c918dd3 100644 (file)
@@ -19,7 +19,7 @@
 #define HURT_CHANCE 16
 
 
-static bool cave_monster_teleportable_bold(int m_idx, int y, int x, bool passive)
+static bool cave_monster_teleportable_bold(int m_idx, int y, int x, u32b mode)
 {
        monster_type *m_ptr = &m_list[m_idx];
        cave_type    *c_ptr = &cave[y][x];
@@ -35,7 +35,7 @@ static bool cave_monster_teleportable_bold(int m_idx, int y, int x, bool passive
        if (is_glyph_grid(c_ptr)) return FALSE;
        if (is_explosive_rune_grid(c_ptr)) return FALSE;
 
-       if (!passive)
+       if (!(mode & TELEPORT_PASSIVE))
        {
                if (!monster_can_cross_terrain(c_ptr->feat, &r_info[m_ptr->r_idx], 0)) return FALSE;
        }
@@ -51,7 +51,7 @@ static bool cave_monster_teleportable_bold(int m_idx, int y, int x, bool passive
  *
  * But allow variation to prevent infinite loops.
  */
-bool teleport_away(int m_idx, int dis, bool dec_valour, bool passive)
+bool teleport_away(int m_idx, int dis, u32b mode)
 {
        int oy, ox, d, i, min;
        int tries = 0;
@@ -71,7 +71,7 @@ bool teleport_away(int m_idx, int dis, bool dec_valour, bool passive)
        /* Minimum distance */
        min = dis / 2;
 
-       if (dec_valour &&
+       if ((mode & TELEPORT_DEC_VALOUR) &&
            (((p_ptr->chp * 10) / p_ptr->mhp) > 5) &&
                (4+randint1(5) < ((p_ptr->chp * 10) / p_ptr->mhp)))
        {
@@ -101,7 +101,7 @@ bool teleport_away(int m_idx, int dis, bool dec_valour, bool passive)
                        /* Ignore illegal locations */
                        if (!in_bounds(ny, nx)) continue;
 
-                       if (!cave_monster_teleportable_bold(m_idx, ny, nx, passive)) continue;
+                       if (!cave_monster_teleportable_bold(m_idx, ny, nx, mode)) continue;
 
                        /* No teleporting into vaults and such */
                        if (!(p_ptr->inside_quest || p_ptr->inside_arena))
@@ -160,7 +160,7 @@ bool teleport_away(int m_idx, int dis, bool dec_valour, bool passive)
 /*
  * Teleport monster next to a grid near the given location
  */
-void teleport_monster_to(int m_idx, int ty, int tx, int power, bool passive)
+void teleport_monster_to(int m_idx, int ty, int tx, int power, u32b mode)
 {
        int ny, nx, oy, ox, d, i, min;
        int attempts = 500;
@@ -206,7 +206,7 @@ void teleport_monster_to(int m_idx, int ty, int tx, int power, bool passive)
                        /* Ignore illegal locations */
                        if (!in_bounds(ny, nx)) continue;
 
-                       if (!cave_monster_teleportable_bold(m_idx, ny, nx, passive)) continue;
+                       if (!cave_monster_teleportable_bold(m_idx, ny, nx, mode)) continue;
 
                        /* No teleporting into vaults and such */
                        /* if (cave[ny][nx].info & (CAVE_ICKY)) continue; */
@@ -254,7 +254,7 @@ void teleport_monster_to(int m_idx, int ty, int tx, int power, bool passive)
 }
 
 
-bool cave_player_teleportable_bold(int y, int x, bool passive, bool nonmagical)
+bool cave_player_teleportable_bold(int y, int x, u32b mode)
 {
        cave_type    *c_ptr = &cave[y][x];
        feature_type *f_ptr = &f_info[c_ptr->feat];
@@ -263,11 +263,11 @@ bool cave_player_teleportable_bold(int y, int x, bool passive, bool nonmagical)
        if (!have_flag(f_ptr->flags, FF_TELEPORTABLE)) return FALSE;
 
        /* No magical teleporting into vaults and such */
-       if (!nonmagical && (c_ptr->info & CAVE_ICKY)) return FALSE;
+       if (!(mode & TELEPORT_NONMAGICAL) && (c_ptr->info & CAVE_ICKY)) return FALSE;
 
        if (c_ptr->m_idx && (c_ptr->m_idx != p_ptr->riding)) return FALSE;
 
-       if (!passive)
+       if (!(mode & TELEPORT_PASSIVE))
        {
                if (!player_can_enter(c_ptr->feat, 0)) return FALSE;
 
@@ -314,7 +314,7 @@ bool cave_player_teleportable_bold(int y, int x, bool passive, bool nonmagical)
 
 #define MAX_TELEPORT_DISTANCE 200
 
-bool teleport_player_aux(int dis, bool passive, bool nonmagical)
+bool teleport_player_aux(int dis, u32b mode)
 {
        int candidates_at[MAX_TELEPORT_DISTANCE + 1];
        int total_candidates, cur_candidates;
@@ -327,7 +327,7 @@ bool teleport_player_aux(int dis, bool passive, bool nonmagical)
 
        if (p_ptr->wild_mode) return FALSE;
 
-       if (p_ptr->anti_tele && !nonmagical)
+       if (p_ptr->anti_tele && !(mode & TELEPORT_NONMAGICAL))
        {
 #ifdef JP
                msg_print("ÉԻ׵ĤÊÎϤ¬¥Æ¥ì¥Ý¡¼¥È¤òËɤ¤¤À¡ª");
@@ -354,7 +354,7 @@ bool teleport_player_aux(int dis, bool passive, bool nonmagical)
                        int d;
 
                        /* Skip illegal locations */
-                       if (!cave_player_teleportable_bold(y, x, passive, nonmagical)) continue;
+                       if (!cave_player_teleportable_bold(y, x, mode)) continue;
 
                        /* Calculate distance */
                        d = distance(py, px, y, x);
@@ -393,7 +393,7 @@ bool teleport_player_aux(int dis, bool passive, bool nonmagical)
                        int d;
 
                        /* Skip illegal locations */
-                       if (!cave_player_teleportable_bold(y, x, passive, nonmagical)) continue;
+                       if (!cave_player_teleportable_bold(y, x, mode)) continue;
 
                        /* Calculate distance */
                        d = distance(py, px, y, x);
@@ -429,7 +429,7 @@ bool teleport_player_aux(int dis, bool passive, bool nonmagical)
        return TRUE;
 }
 
-void teleport_player(int dis, bool passive)
+void teleport_player(int dis, u32b mode)
 {
        int yy, xx;
 
@@ -437,7 +437,7 @@ void teleport_player(int dis, bool passive)
        int oy = py;
        int ox = px;
 
-       if (!teleport_player_aux(dis, passive, FALSE)) return;
+       if (!teleport_player_aux(dis, mode)) return;
 
        /* Monsters with teleport ability may follow the player */
        for (xx = -1; xx < 2; xx++)
@@ -459,7 +459,7 @@ void teleport_player(int dis, bool passive)
                                if ((r_ptr->flags6 & RF6_TPORT) &&
                                    !(r_ptr->flagsr & RFR_RES_TELE))
                                {
-                                       if (!MON_CSLEEP(m_ptr)) teleport_monster_to(tmp_m_idx, py, px, r_ptr->level, FALSE);
+                                       if (!MON_CSLEEP(m_ptr)) teleport_monster_to(tmp_m_idx, py, px, r_ptr->level, 0L);
                                }
                        }
                }
@@ -475,7 +475,7 @@ void teleport_player_away(int m_idx, int dis)
        int oy = py;
        int ox = px;
 
-       if (!teleport_player_aux(dis, TRUE, FALSE)) return;
+       if (!teleport_player_aux(dis, TELEPORT_PASSIVE)) return;
 
        /* Monsters with teleport ability may follow the player */
        for (xx = -1; xx < 2; xx++)
@@ -497,7 +497,7 @@ void teleport_player_away(int m_idx, int dis)
                                if ((r_ptr->flags6 & RF6_TPORT) &&
                                    !(r_ptr->flagsr & RFR_RES_TELE))
                                {
-                                       if (!MON_CSLEEP(m_ptr)) teleport_monster_to(tmp_m_idx, py, px, r_ptr->level, FALSE);
+                                       if (!MON_CSLEEP(m_ptr)) teleport_monster_to(tmp_m_idx, py, px, r_ptr->level, 0L);
                                }
                        }
                }
@@ -511,11 +511,11 @@ void teleport_player_away(int m_idx, int dis)
  * This function is slightly obsessive about correctness.
  * This function allows teleporting into vaults (!)
  */
-void teleport_player_to(int ny, int nx, bool no_tele, bool passive)
+void teleport_player_to(int ny, int nx, u32b mode)
 {
        int y, x, dis = 0, ctr = 0;
 
-       if (p_ptr->anti_tele && no_tele)
+       if (p_ptr->anti_tele && !(mode & TELEPORT_NONMAGICAL))
        {
 #ifdef JP
                msg_print("ÉԻ׵ĤÊÎϤ¬¥Æ¥ì¥Ý¡¼¥È¤òËɤ¤¤À¡ª");
@@ -538,10 +538,10 @@ void teleport_player_to(int ny, int nx, bool no_tele, bool passive)
                }
 
                /* Accept any grid when wizard mode */
-               if (p_ptr->wizard && !passive && (!cave[y][x].m_idx || (cave[y][x].m_idx == p_ptr->riding))) break;
+               if (p_ptr->wizard && !(mode & TELEPORT_PASSIVE) && (!cave[y][x].m_idx || (cave[y][x].m_idx == p_ptr->riding))) break;
 
                /* Accept teleportable floor grids */
-               if (cave_player_teleportable_bold(y, x, passive, !no_tele)) break;
+               if (cave_player_teleportable_bold(y, x, mode)) break;
 
                /* Occasionally advance the distance */
                if (++ctr > (4 * dis * dis + 4 * dis + 1))
@@ -567,9 +567,9 @@ void teleport_away_followable(int m_idx)
        bool         old_ml = m_ptr->ml;
        int          old_cdis = m_ptr->cdis;
 
-       teleport_away(m_idx, MAX_SIGHT * 2 + 5, FALSE, FALSE);
+       teleport_away(m_idx, MAX_SIGHT * 2 + 5, 0L);
 
-       if (old_ml && (old_cdis <= MAX_SIGHT) && !world_monster && los(py, px, oldfy, oldfx))
+       if (old_ml && (old_cdis <= MAX_SIGHT) && !world_monster && !p_ptr->inside_battle && los(py, px, oldfy, oldfx))
        {
                bool follow = FALSE;
 
@@ -605,14 +605,14 @@ void teleport_away_followable(int m_idx)
                        {
                                if (one_in_(3))
                                {
-                                       teleport_player(200, TRUE);
+                                       teleport_player(200, TELEPORT_PASSIVE);
 #ifdef JP
                                        msg_print("¼ºÇÔ¡ª");
 #else
                                        msg_print("Failed!");
 #endif
                                }
-                               else teleport_player_to(m_ptr->fy, m_ptr->fx, TRUE, FALSE);
+                               else teleport_player_to(m_ptr->fy, m_ptr->fx, 0L);
                                p_ptr->energy_need += ENERGY_NEED();
                        }
                }
@@ -794,6 +794,14 @@ void teleport_level(int m_idx)
                /* Check for quest completion */
                check_quest_completion(m_ptr);
 
+               if (record_named_pet && is_pet(m_ptr) && m_ptr->nickname)
+               {
+                       char m2_name[80];
+
+                       monster_desc(m2_name, m_ptr, MD_INDEF_VISIBLE);
+                       do_cmd_write_nikki(NIKKI_NAMED_PET, RECORD_NAMED_PET_TELE_LEVEL, m2_name);
+               }
+
                delete_monster_idx(m_idx);
        }
 
@@ -1204,13 +1212,13 @@ void apply_nexus(monster_type *m_ptr)
        {
                case 1: case 2: case 3:
                {
-                       teleport_player(200, TRUE);
+                       teleport_player(200, TELEPORT_PASSIVE);
                        break;
                }
 
                case 4: case 5:
                {
-                       teleport_player_to(m_ptr->fy, m_ptr->fx, TRUE, TRUE);
+                       teleport_player_to(m_ptr->fy, m_ptr->fx, TELEPORT_PASSIVE);
                        break;
                }
 
@@ -1634,7 +1642,7 @@ static bool vanish_dungeon(void)
                                (void)set_monster_csleep(c_ptr->m_idx, 0);
 
                                /* Notice the "waking up" */
-                               if (is_seen(m_ptr))
+                               if (m_ptr->ml)
                                {
                                        /* Acquire the monster name */
                                        monster_desc(m_name, m_ptr, 0);
@@ -2038,7 +2046,7 @@ msg_print("
 
        /* Create a glyph */
        cave[py][px].info |= CAVE_OBJECT;
-       cave[py][px].mimic = FEAT_GLYPH;
+       cave[py][px].mimic = feat_glyph;
 
        /* Notice */
        note_spot(py, px);
@@ -2065,7 +2073,7 @@ msg_print("
 
        /* Create a mirror */
        cave[py][px].info |= CAVE_OBJECT;
-       cave[py][px].mimic = FEAT_MIRROR;
+       cave[py][px].mimic = feat_mirror;
 
        /* Turn on the light */
        cave[py][px].info |= CAVE_GLOW;
@@ -2101,7 +2109,7 @@ msg_print("
 
        /* Create a glyph */
        cave[py][px].info |= CAVE_OBJECT;
-       cave[py][px].mimic = FEAT_MINOR_GLYPH;
+       cave[py][px].mimic = feat_explosive_rune;
 
        /* Notice */
        note_spot(py, px);
@@ -2774,6 +2782,9 @@ bool identify_item(object_type *o_ptr)
        object_aware(o_ptr);
        object_known(o_ptr);
 
+       /* Player touches it */
+       o_ptr->marked |= OM_TOUCHED;
+
        /* Recalculate bonuses */
        p_ptr->update |= (PU_BONUS);
 
@@ -2830,24 +2841,32 @@ bool ident_spell(bool only_equip)
        else
                item_tester_hook = item_tester_hook_identify;
 
-       if (!can_get_item())
+       if (can_get_item())
+       {
+#ifdef JP
+               q = "¤É¤Î¥¢¥¤¥Æ¥à¤ò´ÕÄꤷ¤Þ¤¹¤«? ";
+#else
+               q = "Identify which item? ";
+#endif
+       }
+       else
        {
                if (only_equip)
-               {
                        item_tester_hook = object_is_weapon_armour_ammo;
-               }
                else
-               {
                        item_tester_hook = NULL;
-               }
+
+#ifdef JP
+               q = "¤¹¤Ù¤Æ´ÕÄêºÑ¤ß¤Ç¤¹¡£ ";
+#else
+               q = "All items are identified. ";
+#endif
        }
 
        /* Get an item */
 #ifdef JP
-q = "¤É¤Î¥¢¥¤¥Æ¥à¤ò´ÕÄꤷ¤Þ¤¹¤«? ";
-s = "´ÕÄꤹ¤ë¤Ù¤­¥¢¥¤¥Æ¥à¤¬¤Ê¤¤¡£";
+       s = "´ÕÄꤹ¤ë¤Ù¤­¥¢¥¤¥Æ¥à¤¬¤Ê¤¤¡£";
 #else
-       q = "Identify which item? ";
        s = "You have nothing to identify.";
 #endif
 
@@ -3004,21 +3023,33 @@ bool identify_fully(bool only_equip)
        else
                item_tester_hook = item_tester_hook_identify_fully;
 
-       if (!can_get_item())
+       if (can_get_item())
+       {
+#ifdef JP
+               q = "¤É¤Î¥¢¥¤¥Æ¥à¤ò*´ÕÄê*¤·¤Þ¤¹¤«? ";
+#else
+               q = "*Identify* which item? ";
+#endif
+       }
+       else
        {
                if (only_equip)
                        item_tester_hook = object_is_weapon_armour_ammo;
                else
                        item_tester_hook = NULL;
+
+#ifdef JP
+               q = "¤¹¤Ù¤Æ*´ÕÄê*ºÑ¤ß¤Ç¤¹¡£ ";
+#else
+               q = "All items are *identified*. ";
+#endif
        }
 
        /* Get an item */
 #ifdef JP
-q = "¤É¤Î¥¢¥¤¥Æ¥à¤ò´ÕÄꤷ¤Þ¤¹¤«? ";
-s = "´ÕÄꤹ¤ë¤Ù¤­¥¢¥¤¥Æ¥à¤¬¤Ê¤¤¡£";
+       s = "*´ÕÄê*¤¹¤ë¤Ù¤­¥¢¥¤¥Æ¥à¤¬¤Ê¤¤¡£";
 #else
-       q = "Identify which item? ";
-       s = "You have nothing to identify.";
+       s = "You have nothing to *identify*.";
 #endif
 
        if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return (FALSE);
@@ -4776,8 +4807,7 @@ int inven_damage(inven_func typ, int perc)
        object_type *o_ptr;
        char        o_name[MAX_NLEN];
 
-       /* Multishadow effects is determined by turn */
-       if( p_ptr->multishadow && (turn & 1) )return 0;
+       if (CHECK_MULTISHADOW()) return 0;
 
        if (p_ptr->inside_arena) return 0;
 
@@ -4961,15 +4991,18 @@ int acid_dam(int dam, cptr kb_str, int monspell)
        if (p_ptr->resist_acid) dam = (dam + 2) / 3;
        if (double_resist) dam = (dam + 2) / 3;
 
-       if ((!(double_resist || p_ptr->resist_acid)) &&
-           one_in_(HURT_CHANCE))
-               (void)do_dec_stat(A_CHR);
+       if (!CHECK_MULTISHADOW())
+       {
+               if ((!(double_resist || p_ptr->resist_acid)) &&
+                   one_in_(HURT_CHANCE))
+                       (void)do_dec_stat(A_CHR);
 
-       /* If any armor gets hit, defend the player */
-       if (minus_ac()) dam = (dam + 1) / 2;
+               /* If any armor gets hit, defend the player */
+               if (minus_ac()) dam = (dam + 1) / 2;
+       }
 
        /* Take damage */
-       get_damage=take_hit(DAMAGE_ATTACK, dam, kb_str, monspell);
+       get_damage = take_hit(DAMAGE_ATTACK, dam, kb_str, monspell);
 
        /* Inventory damage */
        if (!(double_resist && p_ptr->resist_acid))
@@ -5004,11 +5037,11 @@ int elec_dam(int dam, cptr kb_str, int monspell)
        if (double_resist) dam = (dam + 2) / 3;
 
        if ((!(double_resist || p_ptr->resist_elec)) &&
-           one_in_(HURT_CHANCE))
+           one_in_(HURT_CHANCE) && !CHECK_MULTISHADOW())
                (void)do_dec_stat(A_DEX);
 
        /* Take damage */
-       get_damage=take_hit(DAMAGE_ATTACK, dam, kb_str, monspell);
+       get_damage = take_hit(DAMAGE_ATTACK, dam, kb_str, monspell);
 
        /* Inventory damage */
        if (!(double_resist && p_ptr->resist_elec))
@@ -5044,11 +5077,11 @@ int fire_dam(int dam, cptr kb_str, int monspell)
        if (double_resist) dam = (dam + 2) / 3;
 
        if ((!(double_resist || p_ptr->resist_fire)) &&
-           one_in_(HURT_CHANCE))
+           one_in_(HURT_CHANCE) && !CHECK_MULTISHADOW())
                (void)do_dec_stat(A_STR);
 
        /* Take damage */
-       get_damage=take_hit(DAMAGE_ATTACK, dam, kb_str, monspell);
+       get_damage = take_hit(DAMAGE_ATTACK, dam, kb_str, monspell);
 
        /* Inventory damage */
        if (!(double_resist && p_ptr->resist_fire))
@@ -5083,11 +5116,11 @@ int cold_dam(int dam, cptr kb_str, int monspell)
        if (double_resist) dam = (dam + 2) / 3;
 
        if ((!(double_resist || p_ptr->resist_cold)) &&
-           one_in_(HURT_CHANCE))
+           one_in_(HURT_CHANCE) && !CHECK_MULTISHADOW())
                (void)do_dec_stat(A_STR);
 
        /* Take damage */
-       get_damage=take_hit(DAMAGE_ATTACK, dam, kb_str, monspell);
+       get_damage = take_hit(DAMAGE_ATTACK, dam, kb_str, monspell);
 
        /* Inventory damage */
        if (!(double_resist && p_ptr->resist_cold))
@@ -5462,18 +5495,27 @@ bool polymorph_monster(int y, int x)
        if (new_r_idx != old_r_idx)
        {
                u32b mode = 0L;
+               bool preserve_hold_objects = back_m.hold_o_idx ? TRUE : FALSE;
+               s16b this_o_idx, next_o_idx = 0;
 
                /* Get the monsters attitude */
                if (is_friendly(m_ptr)) mode |= PM_FORCE_FRIENDLY;
                if (is_pet(m_ptr)) mode |= PM_FORCE_PET;
                if (m_ptr->mflag2 & MFLAG2_NOPET) mode |= PM_NO_PET;
 
+               /* Mega-hack -- ignore held objects */
+               m_ptr->hold_o_idx = 0;
+
                /* "Kill" the "old" monster */
                delete_monster_idx(c_ptr->m_idx);
 
                /* Create a new monster (no groups) */
                if (place_monster_aux(0, y, x, new_r_idx, mode))
                {
+                       m_list[hack_m_idx_ii].nickname = back_m.nickname;
+                       m_list[hack_m_idx_ii].parent_m_idx = back_m.parent_m_idx;
+                       m_list[hack_m_idx_ii].hold_o_idx = back_m.hold_o_idx;
+
                        /* Success */
                        polymorphed = TRUE;
                }
@@ -5487,6 +5529,35 @@ bool polymorph_monster(int y, int x)
                                /* Re-initialize monster process */
                                mproc_init();
                        }
+                       else preserve_hold_objects = FALSE;
+               }
+
+               /* Mega-hack -- preserve held objects */
+               if (preserve_hold_objects)
+               {
+                       for (this_o_idx = back_m.hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
+                       {
+                               /* Acquire object */
+                               object_type *o_ptr = &o_list[this_o_idx];
+
+                               /* Acquire next object */
+                               next_o_idx = o_ptr->next_o_idx;
+
+                               /* Held by new monster */
+                               o_ptr->held_m_idx = hack_m_idx_ii;
+                       }
+               }
+               else if (back_m.hold_o_idx) /* Failed (paranoia) */
+               {
+                       /* Delete objects */
+                       for (this_o_idx = back_m.hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
+                       {
+                               /* Acquire next object */
+                               next_o_idx = o_list[this_o_idx].next_o_idx;
+
+                               /* Delete the object */
+                               delete_object_idx(this_o_idx);
+                       }
                }
 
                if (targeted) target_who = hack_m_idx_ii;
@@ -5506,19 +5577,19 @@ static bool dimension_door_aux(int x, int y)
 
        p_ptr->energy_need += (s16b)((s32b)(60 - plev) * ENERGY_NEED() / 100L);
 
-       if (!cave_player_teleportable_bold(y, x, FALSE, FALSE) ||
+       if (!cave_player_teleportable_bold(y, x, 0L) ||
            (distance(y, x, py, px) > plev / 2 + 10) ||
            (!randint0(plev / 10 + 10)))
        {
                p_ptr->energy_need += (s16b)((s32b)(60 - plev) * ENERGY_NEED() / 100L);
-               teleport_player((plev + 2) * 2, TRUE);
+               teleport_player((plev + 2) * 2, TELEPORT_PASSIVE);
 
                /* Failed */
                return FALSE;
        }
        else
        {
-               teleport_player_to(y, x, TRUE, FALSE);
+               teleport_player_to(y, x, 0L);
 
                /* Success */
                return TRUE;