OSDN Git Service

通常のセーブ/ロード時以外でc_ptr->mimicに0以外の値を代入する際に, 最
[hengband/hengband.git] / src / spells3.c
index c3dd8a4..87fd6f4 100644 (file)
@@ -140,9 +140,9 @@ bool teleport_away(int m_idx, int dis, bool dec_valour)
 
 
 /*
- * Teleport monster next to the player
+ * Teleport monster next to a grid near the given location
  */
-void teleport_to_player(int m_idx, int power)
+void teleport_monster_to(int m_idx, int ty, int tx, int power)
 {
        int ny, nx, oy, ox, d, i, min;
        int attempts = 500;
@@ -177,12 +177,14 @@ void teleport_to_player(int m_idx, int power)
                /* Try several locations */
                for (i = 0; i < 500; i++)
                {
+                       cave_type    *c_ptr;
+
                        /* Pick a (possibly illegal) location */
                        while (1)
                        {
-                               ny = rand_spread(py, dis);
-                               nx = rand_spread(px, dis);
-                               d = distance(py, px, ny, nx);
+                               ny = rand_spread(ty, dis);
+                               nx = rand_spread(tx, dis);
+                               d = distance(ty, tx, ny, nx);
                                if ((d >= min) && (d <= dis)) break;
                        }
 
@@ -192,16 +194,18 @@ void teleport_to_player(int m_idx, int power)
                        /* Require "empty" floor space */
                        if (!cave_empty_bold(ny, nx)) continue;
 
+                       c_ptr = &cave[ny][nx];
+
                        /* Hack -- no teleport onto glyph of warding */
-                       if (is_glyph_grid(&cave[ny][nx])) continue;
-                       if (is_explosive_rune_grid(&cave[ny][nx])) continue;
+                       if (is_glyph_grid(c_ptr)) continue;
+                       if (is_explosive_rune_grid(c_ptr)) continue;
 
                        /* ...nor onto the Pattern */
-                       if ((cave[ny][nx].feat >= FEAT_PATTERN_START) &&
-                           (cave[ny][nx].feat <= FEAT_PATTERN_XTRA2)) continue;
+                       if ((c_ptr->feat >= FEAT_PATTERN_START) &&
+                           (c_ptr->feat <= FEAT_PATTERN_XTRA2)) continue;
 
                        /* No teleporting into vaults and such */
-                       /* if (cave[ny][nx].info & (CAVE_ICKY)) continue; */
+                       /* if (c_ptr->info & (CAVE_ICKY)) continue; */
 
                        /* This grid looks good */
                        look = FALSE;
@@ -384,9 +388,9 @@ msg_print("
                                 * totally unkillable suckers...
                                 */
                                if ((r_ptr->flags6 & RF6_TPORT) &&
-                                   !(r_ptr->flags3 & RF3_RES_TELE))
+                                   !(r_ptr->flagsr & RFR_RES_TELE))
                                {
-                                       if (!m_ptr->csleep) teleport_to_player(tmp_m_idx, r_ptr->level);
+                                       if (!m_ptr->csleep) teleport_monster_to(tmp_m_idx, py, px, r_ptr->level);
                                }
                        }
                }
@@ -452,7 +456,7 @@ msg_print("
                {
                        if (cave_naked_bold(y, x) || (((cave[y][x].feat == FEAT_DEEP_LAVA) || (cave[y][x].feat == FEAT_DEEP_WATER)) && !cave[y][x].m_idx)) break;
                }
-               else if (cave_empty_bold(y, x) || ((y == py) && (x == px))) break;
+               else if (cave_empty_bold(y, x) || player_bold(y, x)) break;
 
                /* Occasionally advance the distance */
                if (++ctr > (4 * dis * dis + 4 * dis + 1))
@@ -512,32 +516,51 @@ msg_print("
 
 /*
  * Teleport the player one level up or down (random when legal)
+ * Note: If m_idx <= 0, target is player.
  */
-void teleport_player_level(void)
+void teleport_level(int m_idx)
 {
-       bool go_up;
+       bool         go_up;
+       char         m_name[160];
+       bool         see_m = TRUE;
+
+       if (m_idx <= 0) /* To player */
+       {
+#ifdef JP
+               strcpy(m_name, "¤¢¤Ê¤¿");
+#else
+               strcpy(m_name, "you");
+#endif
+       }
+       else /* To monster */
+       {
+               monster_type *m_ptr = &m_list[m_idx];
+
+               /* Get the monster name (or "it") */
+               monster_desc(m_name, m_ptr, 0);
 
-       /* No effect in arena or quest */
-       if (p_ptr->inside_arena || (p_ptr->inside_quest && !random_quest_number(dun_level)) ||
-           (quest_number(dun_level) && (dun_level > 1) && ironman_downward))
+               see_m = m_ptr->ml;
+       }
+
+       /* No effect in some case */
+       if (TELE_LEVEL_IS_INEFF(m_idx))
        {
 #ifdef JP
-msg_print("¸ú²Ì¤¬¤Ê¤«¤Ã¤¿¡£");
+               if (see_m) msg_print("¸ú²Ì¤¬¤Ê¤«¤Ã¤¿¡£");
 #else
-               msg_print("There is no effect.");
+               if (see_m) msg_print("There is no effect.");
 #endif
 
                return;
        }
 
-       if (p_ptr->anti_tele)
+       if ((m_idx <= 0) && p_ptr->anti_tele) /* To player */
        {
 #ifdef JP
-msg_print("ÉԻ׵ĤÊÎϤ¬¥Æ¥ì¥Ý¡¼¥È¤òËɤ¤¤À¡ª");
+               msg_print("ÉԻ׵ĤÊÎϤ¬¥Æ¥ì¥Ý¡¼¥È¤òËɤ¤¤À¡ª");
 #else
                msg_print("A mysterious force prevents you from teleporting!");
 #endif
-
                return;
        }
 
@@ -545,104 +568,127 @@ msg_print("
        if (randint0(100) < 50) go_up = TRUE;
        else go_up = FALSE;
 
-       if (p_ptr->wizard)
+       if ((m_idx <= 0) && p_ptr->wizard)
        {
                if (get_check("Force to go up? ")) go_up = TRUE;
                else if (get_check("Force to go down? ")) go_up = FALSE;
        }
 
        /* Down only */ 
-       if (ironman_downward || (dun_level <= d_info[dungeon_type].mindepth))
+       if ((ironman_downward && (m_idx <= 0)) || (dun_level <= d_info[dungeon_type].mindepth))
        {
 #ifdef JP
-msg_print("¤¢¤Ê¤¿¤Ï¾²¤òÆͤ­ÇˤäÆÄÀ¤ó¤Ç¤¤¤¯¡£");
+               if (see_m) msg_format("%^s¤Ï¾²¤òÆͤ­ÇˤäÆÄÀ¤ó¤Ç¤¤¤¯¡£", m_name);
 #else
-               msg_print("You sink through the floor.");
+               if (see_m) msg_format("%^s sink%s through the floor.", m_name, (m_idx <= 0) ? "" : "s");
 #endif
-               if (!dun_level)
+               if (m_idx <= 0) /* To player */
                {
-                       dungeon_type = p_ptr->recall_dungeon;
-                       p_ptr->oldpy = py;
-                       p_ptr->oldpx = px;
-               }
+                       if (!dun_level)
+                       {
+                               dungeon_type = p_ptr->recall_dungeon;
+                               p_ptr->oldpy = py;
+                               p_ptr->oldpx = px;
+                       }
 
-               if (record_stair) do_cmd_write_nikki(NIKKI_TELE_LEV, 1, NULL);
+                       if (record_stair) do_cmd_write_nikki(NIKKI_TELE_LEV, 1, NULL);
 
-               if (autosave_l) do_cmd_save_game(TRUE);
+                       if (autosave_l) do_cmd_save_game(TRUE);
 
-               if (!dun_level)
-               {
-                       dun_level = d_info[dungeon_type].mindepth;
-                       prepare_change_floor_mode(CFM_RAND_PLACE | CFM_CLEAR_ALL);
-               }
-               else
-               {
-                       prepare_change_floor_mode(CFM_DOWN | CFM_RAND_PLACE | CFM_RAND_CONNECT);
-               }
+                       if (!dun_level)
+                       {
+                               dun_level = d_info[dungeon_type].mindepth;
+                               prepare_change_floor_mode(CFM_RAND_PLACE | CFM_CLEAR_ALL);
+                       }
+                       else
+                       {
+                               prepare_change_floor_mode(CFM_DOWN | CFM_RAND_PLACE | CFM_RAND_CONNECT);
+                       }
 
-               /* Leaving */
-               p_ptr->leaving = TRUE;
+                       /* Leaving */
+                       p_ptr->leaving = TRUE;
+               }
        }
 
        /* Up only */
        else if (quest_number(dun_level) || (dun_level >= d_info[dungeon_type].maxdepth))
        {
 #ifdef JP
-msg_print("¤¢¤Ê¤¿¤ÏÅ·°æ¤òÆͤ­ÇˤäÆÃè¤ØÉ⤤¤Æ¤¤¤¯¡£");
+               if (see_m) msg_format("%^s¤ÏÅ·°æ¤òÆͤ­ÇˤäÆÃè¤ØÉ⤤¤Æ¤¤¤¯¡£", m_name);
 #else
-               msg_print("You rise up through the ceiling.");
+               if (see_m) msg_format("%^s rise%s up through the ceiling.", m_name, (m_idx <= 0) ? "" : "s");
 #endif
 
 
-               if (record_stair) do_cmd_write_nikki(NIKKI_TELE_LEV, -1, NULL);
+               if (m_idx <= 0) /* To player */
+               {
+                       if (record_stair) do_cmd_write_nikki(NIKKI_TELE_LEV, -1, NULL);
 
-               if (autosave_l) do_cmd_save_game(TRUE);
+                       if (autosave_l) do_cmd_save_game(TRUE);
 
-               prepare_change_floor_mode(CFM_UP | CFM_RAND_PLACE | CFM_RAND_CONNECT);
+                       prepare_change_floor_mode(CFM_UP | CFM_RAND_PLACE | CFM_RAND_CONNECT);
 
-               leave_quest_check();
+                       leave_quest_check();
 
-               /* Leaving */
-               p_ptr->inside_quest = 0;
-               p_ptr->leaving = TRUE;
+                       /* Leaving */
+                       p_ptr->inside_quest = 0;
+                       p_ptr->leaving = TRUE;
+               }
        }
        else if (go_up)
        {
 #ifdef JP
-msg_print("¤¢¤Ê¤¿¤ÏÅ·°æ¤òÆͤ­ÇˤäÆÃè¤ØÉ⤤¤Æ¤¤¤¯¡£");
+               if (see_m) msg_format("%^s¤ÏÅ·°æ¤òÆͤ­ÇˤäÆÃè¤ØÉ⤤¤Æ¤¤¤¯¡£", m_name);
 #else
-               msg_print("You rise up through the ceiling.");
+               if (see_m) msg_format("%^s rise%s up through the ceiling.", m_name, (m_idx <= 0) ? "" : "s");
 #endif
 
 
-               if (record_stair) do_cmd_write_nikki(NIKKI_TELE_LEV, -1, NULL);
+               if (m_idx <= 0) /* To player */
+               {
+                       if (record_stair) do_cmd_write_nikki(NIKKI_TELE_LEV, -1, NULL);
 
-               if (autosave_l) do_cmd_save_game(TRUE);
+                       if (autosave_l) do_cmd_save_game(TRUE);
 
-               prepare_change_floor_mode(CFM_UP | CFM_RAND_PLACE | CFM_RAND_CONNECT);
+                       prepare_change_floor_mode(CFM_UP | CFM_RAND_PLACE | CFM_RAND_CONNECT);
 
-               /* Leaving */
-               p_ptr->leaving = TRUE;
+                       /* Leaving */
+                       p_ptr->leaving = TRUE;
+               }
        }
        else
        {
 #ifdef JP
-msg_print("¤¢¤Ê¤¿¤Ï¾²¤òÆͤ­ÇˤäÆÄÀ¤ó¤Ç¤¤¤¯¡£");
+               if (see_m) msg_format("%^s¤Ï¾²¤òÆͤ­ÇˤäÆÄÀ¤ó¤Ç¤¤¤¯¡£", m_name);
 #else
-               msg_print("You sink through the floor.");
+               if (see_m) msg_format("%^s sink%s through the floor.", m_name, (m_idx <= 0) ? "" : "s");
 #endif
 
-               /* Never reach this code on the surface */
-               /* if (!dun_level) dungeon_type = p_ptr->recall_dungeon; */
+               if (m_idx <= 0) /* To player */
+               {
+                       /* Never reach this code on the surface */
+                       /* if (!dun_level) dungeon_type = p_ptr->recall_dungeon; */
+
+                       if (record_stair) do_cmd_write_nikki(NIKKI_TELE_LEV, 1, NULL);
+
+                       if (autosave_l) do_cmd_save_game(TRUE);
+
+                       prepare_change_floor_mode(CFM_DOWN | CFM_RAND_PLACE | CFM_RAND_CONNECT);
 
-               if (record_stair) do_cmd_write_nikki(NIKKI_TELE_LEV, 1, NULL);
+                       /* Leaving */
+                       p_ptr->leaving = TRUE;
+               }
+       }
 
-               if (autosave_l) do_cmd_save_game(TRUE);
+       /* Monster level teleportation is simple deleting now */
+       if (m_idx > 0)
+       {
+               monster_type *m_ptr = &m_list[m_idx];
 
-               prepare_change_floor_mode(CFM_DOWN | CFM_RAND_PLACE | CFM_RAND_CONNECT);
+               /* Check for quest completion */
+               check_quest_completion(m_ptr);
 
-               /* Leaving */
-               p_ptr->leaving = TRUE;
+               delete_monster_idx(m_idx);
        }
 
        /* Sound */
@@ -809,6 +855,18 @@ bool reset_recall(void)
        select_dungeon = choose_dungeon("reset");
 #endif
 
+       /* Ironman option */
+       if (ironman_downward)
+       {
+#ifdef JP
+               msg_print("²¿¤âµ¯¤³¤é¤Ê¤«¤Ã¤¿¡£");
+#else
+               msg_print("Nothing happens.");
+#endif
+
+               return TRUE;
+       }
+
        if (!select_dungeon) return FALSE;
        /* Prompt */
 #ifdef JP
@@ -1035,7 +1093,7 @@ msg_print("
                        }
 
                        /* Teleport Level */
-                       teleport_player_level();
+                       teleport_level(0);
                        break;
                }
 
@@ -1418,40 +1476,193 @@ msg_print("°
 }
 
 
+/*
+ * Determine if a "feature" is a "vanishable"
+ * Non-permanent walls, trees, mountains, or doors
+ */
+#define vanishable_feat(F) \
+       ((!feat_floor(F) && (((F) < FEAT_PERM_EXTRA) || ((F) > FEAT_PERM_SOLID))) || \
+        ((F) == FEAT_OPEN) || ((F) == FEAT_BROKEN))
+
+/*
+ * Vanish all walls in this floor
+ */
+static bool vanish_dungeon(void)
+{
+       int          y, x;
+       cave_type    *c_ptr;
+       monster_type *m_ptr;
+       char         m_name[80];
+       byte         feat;
+
+       /* Prevent vasishing of quest levels and town */
+       if ((p_ptr->inside_quest && is_fixed_quest_idx(p_ptr->inside_quest)) || !dun_level)
+       {
+               return FALSE;
+       }
+
+       /* Scan all normal grids */
+       for (y = 1; y < cur_hgt - 1; y++)
+       {
+               for (x = 1; x < cur_wid - 1; x++)
+               {
+                       c_ptr = &cave[y][x];
+
+                       /* Seeing true feature code (ignore mimic) */
+                       feat = c_ptr->feat;
+
+                       /* Lose room and vault */
+                       c_ptr->info &= ~(CAVE_ROOM | CAVE_ICKY);
+
+                       /* Awake monster */
+                       if (c_ptr->m_idx)
+                       {
+                               m_ptr = &m_list[c_ptr->m_idx];
+
+                               /* Reset sleep counter */
+                               m_ptr->csleep = 0;
+
+                               if (r_info[m_ptr->r_idx].flags7 & RF7_HAS_LD_MASK) p_ptr->update |= (PU_MON_LITE);
+
+                               /* Notice the "waking up" */
+                               if (m_ptr->ml)
+                               {
+                                       /* Acquire the monster name */
+                                       monster_desc(m_name, m_ptr, 0);
+
+                                       /* Dump a message */
+#ifdef JP
+                                       msg_format("%^s¤¬Ìܤò³Ð¤Þ¤·¤¿¡£", m_name);
+#else
+                                       msg_format("%^s wakes up.", m_name);
+#endif
+
+                                       /* Redraw the health bar */
+                                       if (p_ptr->health_who == c_ptr->m_idx) p_ptr->redraw |= (PR_HEALTH);
+                                       if (p_ptr->riding == c_ptr->m_idx) p_ptr->redraw |= (PR_UHEALTH);
+                               }
+                       }
+
+                       /* Process all walls, doors and patterns */
+                       if (vanishable_feat(feat) || pattern_tile(y, x))
+                       {
+                               /* Create floor */
+                               cave_set_feat(y, x, floor_type[randint0(100)]);
+                       }
+               }
+       }
+
+       /* Special boundary walls -- Top and bottom */
+       for (x = 0; x < cur_wid; x++)
+       {
+               c_ptr = &cave[0][x];
+
+               /* Lose room and vault */
+               c_ptr->info &= ~(CAVE_ROOM | CAVE_ICKY);
+
+               /* Set boundary mimic if needed */
+               if (c_ptr->mimic && vanishable_feat(c_ptr->mimic)) c_ptr->mimic = f_info[floor_type[randint0(100)]].mimic;
+
+               c_ptr = &cave[cur_hgt - 1][x];
+
+               /* Lose room and vault */
+               c_ptr->info &= ~(CAVE_ROOM | CAVE_ICKY);
+
+               /* Set boundary mimic if needed */
+               if (c_ptr->mimic && vanishable_feat(c_ptr->mimic)) c_ptr->mimic = f_info[floor_type[randint0(100)]].mimic;
+       }
+
+       /* Special boundary walls -- Left and right */
+       for (y = 1; y < (cur_hgt - 1); y++)
+       {
+               c_ptr = &cave[y][0];
+
+               /* Lose room and vault */
+               c_ptr->info &= ~(CAVE_ROOM | CAVE_ICKY);
+
+               /* Set boundary mimic if needed */
+               if (c_ptr->mimic && vanishable_feat(c_ptr->mimic)) c_ptr->mimic = f_info[floor_type[randint0(100)]].mimic;
+
+               c_ptr = &cave[y][cur_wid - 1];
+
+               /* Lose room and vault */
+               c_ptr->info &= ~(CAVE_ROOM | CAVE_ICKY);
+
+               /* Set boundary mimic if needed */
+               if (c_ptr->mimic && vanishable_feat(c_ptr->mimic)) c_ptr->mimic = f_info[floor_type[randint0(100)]].mimic;
+       }
+
+       /* Mega-Hack -- Forget the view and lite */
+       p_ptr->update |= (PU_UN_VIEW | PU_UN_LITE);
+
+       /* Update stuff */
+       p_ptr->update |= (PU_VIEW | PU_LITE | PU_FLOW | PU_MON_LITE);
+
+       /* Update the monsters */
+       p_ptr->update |= (PU_MONSTERS);
+
+       /* Redraw map */
+       p_ptr->redraw |= (PR_MAP);
+
+       /* Window stuff */
+       p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
+
+       return TRUE;
+}
+
+
 void call_the_(void)
 {
        int i;
+       int y, x;
+       bool do_call = TRUE;
 
-       if (cave_floor_bold(py - 1, px - 1) &&
-           cave_floor_bold(py - 1, px    ) &&
-           cave_floor_bold(py - 1, px + 1) &&
-           cave_floor_bold(py    , px - 1) &&
-           cave_floor_bold(py    , px + 1) &&
-           cave_floor_bold(py + 1, px - 1) &&
-           cave_floor_bold(py + 1, px    ) &&
-           cave_floor_bold(py + 1, px + 1))
+       for (i = 0; i < 9; i++)
+       {
+               y = py + ddy_ddd[i];
+               x = px + ddx_ddd[i];
+
+               if (!cave_floor_bold(y, x) && !boundary_floor_bold(y, x))
+               {
+                       do_call = FALSE;
+                       break;
+               }
+       }
+
+       if (do_call)
        {
                for (i = 1; i < 10; i++)
                {
-                       if (i-5) fire_ball(GF_ROCKET, i, 175, 2);
+                       if (i - 5) fire_ball(GF_ROCKET, i, 175, 2);
                }
 
                for (i = 1; i < 10; i++)
                {
-                       if (i-5) fire_ball(GF_MANA, i, 175, 3);
+                       if (i - 5) fire_ball(GF_MANA, i, 175, 3);
                }
 
                for (i = 1; i < 10; i++)
                {
-                       if (i-5) fire_ball(GF_NUKE, i, 175, 4);
+                       if (i - 5) fire_ball(GF_NUKE, i, 175, 4);
                }
        }
+
+       /* Prevent destruction of quest levels and town */
+       else if ((p_ptr->inside_quest && is_fixed_quest_idx(p_ptr->inside_quest)) || !dun_level)
+       {
+#ifdef JP
+               msg_print("ÃÏÌ̤¬Íɤ줿¡£");
+#else
+               msg_print("The ground trembles.");
+#endif
+       }
+
        else
        {
 #ifdef JP
-msg_format("¤¢¤Ê¤¿¤Ï%s¤òÊɤ˶᤹¤®¤ë¾ì½ê¤Ç¾§¤¨¤Æ¤·¤Þ¤Ã¤¿¡ª",
-((mp_ptr->spell_book == TV_LIFE_BOOK) ? "µ§¤ê" : "¼öʸ"));
-msg_print("Â礭¤ÊÇúȯ²»¤¬¤¢¤Ã¤¿¡ª");
+               msg_format("¤¢¤Ê¤¿¤Ï%s¤òÊɤ˶᤹¤®¤ë¾ì½ê¤Ç¾§¤¨¤Æ¤·¤Þ¤Ã¤¿¡ª",
+                       ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "µ§¤ê" : "¼öʸ"));
+               msg_print("Â礭¤ÊÇúȯ²»¤¬¤¢¤Ã¤¿¡ª");
 #else
                msg_format("You %s the %s too close to a wall!",
                        ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "recite" : "cast"),
@@ -1459,28 +1670,36 @@ msg_print("
                msg_print("There is a loud explosion!");
 #endif
 
-
-               if (destroy_area(py, px, 15 + p_ptr->lev + randint0(11)))
+               if (one_in_(666))
+               {
 #ifdef JP
-msg_print("¥À¥ó¥¸¥ç¥ó¤¬Êø²õ¤·¤¿...");
+                       if (!vanish_dungeon()) msg_print("¥À¥ó¥¸¥ç¥ó¤Ï°ì½ÖÀŤޤêÊ֤ä¿¡£");
 #else
-                       msg_print("The dungeon collapses...");
+                       if (!vanish_dungeon()) msg_print("The dungeon silences a moment.");
 #endif
-
+               }
                else
+               {
+                       if (destroy_area(py, px, 15 + p_ptr->lev + randint0(11), FALSE))
 #ifdef JP
-msg_print("¥À¥ó¥¸¥ç¥ó¤ÏÂ礭¤¯Íɤ줿¡£");
+                               msg_print("¥À¥ó¥¸¥ç¥ó¤¬Êø²õ¤·¤¿...");
 #else
-                       msg_print("The dungeon trembles.");
+                               msg_print("The dungeon collapses...");
 #endif
 
+                       else
+#ifdef JP
+                               msg_print("¥À¥ó¥¸¥ç¥ó¤ÏÂ礭¤¯Íɤ줿¡£");
+#else
+                               msg_print("The dungeon trembles.");
+#endif
+               }
 
 #ifdef JP
-take_hit(DAMAGE_NOESCAPE, 100 + randint1(150), "¼«»¦Åª¤Êµõ̵¾·Íè", -1);
+               take_hit(DAMAGE_NOESCAPE, 100 + randint1(150), "¼«»¦Åª¤Êµõ̵¾·Íè", -1);
 #else
                take_hit(DAMAGE_NOESCAPE, 100 + randint1(150), "a suicidal Call the Void", -1);
 #endif
-
        }
 }
 
@@ -1674,7 +1893,7 @@ msg_print("
 
        /* Create a glyph */
        cave[py][px].info |= CAVE_OBJECT;
-       cave[py][px].mimic = FEAT_GLYPH;
+       cave[py][px].mimic = f_info[FEAT_GLYPH].mimic;
 
        /* Notice */
        note_spot(py, px);
@@ -1701,7 +1920,7 @@ msg_print("
 
        /* Create a mirror */
        cave[py][px].info |= CAVE_OBJECT;
-       cave[py][px].mimic = FEAT_MIRROR;
+       cave[py][px].mimic = f_info[FEAT_MIRROR].mimic;
 
        /* Turn on the light */
        cave[py][px].info |= CAVE_GLOW;
@@ -1735,7 +1954,7 @@ msg_print("
 
        /* Create a glyph */
        cave[py][px].info |= CAVE_OBJECT;
-       cave[py][px].mimic = FEAT_MINOR_GLYPH;
+       cave[py][px].mimic = f_info[FEAT_MINOR_GLYPH].mimic;
 
        /* Notice */
        note_spot(py, px);
@@ -2114,9 +2333,6 @@ bool item_tester_hook_weapon_armour(object_type *o_ptr)
  */
 static bool item_tester_hook_nameless_weapon_armour(object_type *o_ptr)
 {
-       if (o_ptr->name1 || o_ptr->art_name || o_ptr->name2 || o_ptr->xtra3)
-               return FALSE;
-
        switch (o_ptr->tval)
        {
                case TV_SWORD:
@@ -2136,12 +2352,14 @@ static bool item_tester_hook_nameless_weapon_armour(object_type *o_ptr)
                case TV_HELM:
                case TV_BOOTS:
                case TV_GLOVES:
-               {
-                       return (TRUE);
-               }
+                       if (o_ptr->name1 || o_ptr->art_name || o_ptr->name2 || o_ptr->xtra3)
+                       {
+                               if (object_known_p(o_ptr)) return FALSE;
+                       }
+                       return TRUE;
        }
 
-       return (FALSE);
+       return FALSE;
 }
 
 
@@ -2386,8 +2604,8 @@ bool artifact_scroll(void)
 
        /* Get an item */
 #ifdef JP
-q = "¤É¤Î¥¢¥¤¥Æ¥à¤ò¶¯²½¤·¤Þ¤¹¤«? ";
-s = "¶¯²½¤Ç¤­¤ë¥¢¥¤¥Æ¥à¤¬¤Ê¤¤¡£";
+       q = "¤É¤Î¥¢¥¤¥Æ¥à¤ò¶¯²½¤·¤Þ¤¹¤«? ";
+       s = "¶¯²½¤Ç¤­¤ë¥¢¥¤¥Æ¥à¤¬¤Ê¤¤¡£";
 #else
        q = "Enchant which item? ";
        s = "You have nothing to enchant.";
@@ -2413,7 +2631,7 @@ s = "
 
        /* Describe */
 #ifdef JP
-msg_format("%s ¤ÏâÁ¤¤¸÷¤òȯ¤·¤¿¡ª",o_name);
+       msg_format("%s ¤ÏâÁ¤¤¸÷¤òȯ¤·¤¿¡ª",o_name);
 #else
        msg_format("%s %s radiate%s a blinding light!",
                  ((item >= 0) ? "Your" : "The"), o_name,
@@ -2423,8 +2641,7 @@ msg_format("%s 
        if (o_ptr->name1 || o_ptr->art_name)
        {
 #ifdef JP
-msg_format("%s¤Ï´û¤ËÅÁÀâ¤Î¥¢¥¤¥Æ¥à¤Ç¤¹¡ª",
-    o_name  );
+               msg_format("%s¤Ï´û¤ËÅÁÀâ¤Î¥¢¥¤¥Æ¥à¤Ç¤¹¡ª", o_name  );
 #else
                msg_format("The %s %s already %s!",
                    o_name, ((o_ptr->number > 1) ? "are" : "is"),
@@ -2437,8 +2654,7 @@ msg_format("%s
        else if (o_ptr->name2)
        {
 #ifdef JP
-msg_format("%s¤Ï´û¤Ë̾¤Î¤¢¤ë¥¢¥¤¥Æ¥à¤Ç¤¹¡ª",
-    o_name );
+               msg_format("%s¤Ï´û¤Ë̾¤Î¤¢¤ë¥¢¥¤¥Æ¥à¤Ç¤¹¡ª", o_name );
 #else
                msg_format("The %s %s already %s!",
                    o_name, ((o_ptr->number > 1) ? "are" : "is"),
@@ -2451,12 +2667,11 @@ msg_format("%s
        else if (o_ptr->xtra3)
        {
 #ifdef JP
-msg_format("%s¤Ï´û¤Ë¶¯²½¤µ¤ì¤Æ¤¤¤Þ¤¹¡ª",
-    o_name );
+               msg_format("%s¤Ï´û¤Ë¶¯²½¤µ¤ì¤Æ¤¤¤Þ¤¹¡ª", o_name );
 #else
                msg_format("The %s %s already %s!",
                    o_name, ((o_ptr->number > 1) ? "are" : "is"),
-                   ((o_ptr->number > 1) ? "kaji items" : "an kaji item"));
+                   ((o_ptr->number > 1) ? "customized items" : "a customized item"));
 #endif
        }
 
@@ -2465,8 +2680,8 @@ msg_format("%s
                if (o_ptr->number > 1)
                {
 #ifdef JP
-msg_print("Ê£¿ô¤Î¥¢¥¤¥Æ¥à¤ËËâË¡¤ò¤«¤±¤ë¤À¤±¤Î¥¨¥Í¥ë¥®¡¼¤Ï¤¢¤ê¤Þ¤»¤ó¡ª");
-msg_format("%d ¸Ä¤Î%s¤¬²õ¤ì¤¿¡ª",(o_ptr->number)-1, o_name);
+                       msg_print("Ê£¿ô¤Î¥¢¥¤¥Æ¥à¤ËËâË¡¤ò¤«¤±¤ë¤À¤±¤Î¥¨¥Í¥ë¥®¡¼¤Ï¤¢¤ê¤Þ¤»¤ó¡ª");
+                       msg_format("%d ¸Ä¤Î%s¤¬²õ¤ì¤¿¡ª",(o_ptr->number)-1, o_name);
 #else
                        msg_print("Not enough enough energy to enchant more than one object!");
                        msg_format("%d of your %s %s destroyed!",(o_ptr->number)-1, o_name, (o_ptr->number>2?"were":"was"));
@@ -2492,7 +2707,7 @@ msg_format("%d 
 
                /* Message */
 #ifdef JP
-msg_print("¶¯²½¤Ë¼ºÇÔ¤·¤¿¡£");
+               msg_print("¶¯²½¤Ë¼ºÇÔ¤·¤¿¡£");
 #else
                msg_print("The enchantment failed.");
 #endif
@@ -2707,30 +2922,32 @@ s = "
 
        /* Oops */
 #ifdef JP
-msg_print("¤Þ¤Ð¤æ¤¤Á®¸÷¤¬Áö¤Ã¤¿¡ª");
+       msg_print("¤Þ¤Ð¤æ¤¤Á®¸÷¤¬Áö¤Ã¤¿¡ª");
 #else
        msg_print("There is a bright flash of light!");
 #endif
-{
-  byte iy = o_ptr->iy;                /* Y-position on map, or zero */
-  byte ix = o_ptr->ix;                /* X-position on map, or zero */
-  s16b next_o_idx= o_ptr->next_o_idx; /* Next object in stack (if any) */
-  byte marked=o_ptr->marked;          /* Object is marked */
-  s16b weight = (o_ptr->number*o_ptr->weight);
-
-   /* Wipe it clean */
-   object_prep(o_ptr, o_ptr->k_idx);
-
-  o_ptr->iy=iy;
-  o_ptr->ix=ix;
-  o_ptr->next_o_idx=next_o_idx;
-  o_ptr->marked=marked;
-  if (item >= 0) p_ptr->total_weight += (o_ptr->weight - weight);
-}
+       {
+               byte iy = o_ptr->iy;                 /* Y-position on map, or zero */
+               byte ix = o_ptr->ix;                 /* X-position on map, or zero */
+               s16b next_o_idx = o_ptr->next_o_idx; /* Next object in stack (if any) */
+               byte marked = o_ptr->marked;         /* Object is marked */
+               s16b weight = o_ptr->number * o_ptr->weight;
+               u16b inscription = o_ptr->inscription;
+
+               /* Wipe it clean */
+               object_prep(o_ptr, o_ptr->k_idx);
+
+               o_ptr->iy = iy;
+               o_ptr->ix = ix;
+               o_ptr->next_o_idx = next_o_idx;
+               o_ptr->marked = marked;
+               o_ptr->inscription = inscription;
+               if (item >= 0) p_ptr->total_weight += (o_ptr->weight - weight);
+       }
        calc_android_exp();
 
        /* Something happened */
-       return (TRUE);
+       return TRUE;
 }
 
 
@@ -3891,24 +4108,33 @@ s16b experience_of_spell(int spell, int use_realm)
  */
 int mod_need_mana(int need_mana, int spell, int realm)
 {
+#define MANA_CONST   2400
+#define MANA_DIV        4
+#define DEC_MANA_DIV    3
+
        /* Realm magic */
        if ((realm > REALM_NONE) && (realm <= MAX_REALM))
        {
-               need_mana = need_mana * (3800 - experience_of_spell(spell, realm)) + 2399;
-
-               if (p_ptr->dec_mana) need_mana *= 3;
-               else need_mana *= 4;
-
-               need_mana /= 9600;
+               /*
+                * need_mana defaults if spell exp equals SPELL_EXP_EXPERT and !p_ptr->dec_mana.
+                * MANA_CONST is used to calculate need_mana effected from spell proficiency.
+                */
+               need_mana = need_mana * (MANA_CONST + SPELL_EXP_EXPERT - experience_of_spell(spell, realm)) + (MANA_CONST - 1);
+               need_mana *= p_ptr->dec_mana ? DEC_MANA_DIV : MANA_DIV;
+               need_mana /= MANA_CONST * MANA_DIV;
                if (need_mana < 1) need_mana = 1;
        }
 
        /* Non-realm magic */
        else
        {
-               if (p_ptr->dec_mana) need_mana = (need_mana + 1) * 3 / 4;
+               if (p_ptr->dec_mana) need_mana = (need_mana + 1) * DEC_MANA_DIV / MANA_DIV;
        }
 
+#undef DEC_MANA_DIV
+#undef MANA_DIV
+#undef MANA_CONST
+
        return need_mana;
 }
 
@@ -5006,7 +5232,7 @@ int acid_dam(int dam, cptr kb_str, int monspell)
 {
        int get_damage;  
        int inv = (dam < 30) ? 1 : (dam < 60) ? 2 : 3;
-       bool double_resist = (p_ptr->oppose_acid  || music_singing(MUSIC_RESIST) || (p_ptr->special_defense & KATA_MUSOU));
+       bool double_resist = IS_OPPOSE_ACID();
 
        /* Total Immunity */
        if (p_ptr->immune_acid || (dam <= 0))
@@ -5047,7 +5273,7 @@ int elec_dam(int dam, cptr kb_str, int monspell)
 {
        int get_damage;  
        int inv = (dam < 30) ? 1 : (dam < 60) ? 2 : 3;
-       bool double_resist = (p_ptr->oppose_elec  || music_singing(MUSIC_RESIST) || (p_ptr->special_defense & KATA_MUSOU));
+       bool double_resist = IS_OPPOSE_ELEC();
 
        /* Total immunity */
        if (p_ptr->immune_elec || (dam <= 0))
@@ -5087,7 +5313,7 @@ int fire_dam(int dam, cptr kb_str, int monspell)
 {
        int get_damage;  
        int inv = (dam < 30) ? 1 : (dam < 60) ? 2 : 3;
-       bool double_resist = (p_ptr->oppose_fire  || music_singing(MUSIC_RESIST) || (p_ptr->special_defense & KATA_MUSOU));
+       bool double_resist = IS_OPPOSE_FIRE();
 
        /* Totally immune */
        if (p_ptr->immune_fire || (dam <= 0))
@@ -5127,7 +5353,7 @@ int cold_dam(int dam, cptr kb_str, int monspell)
 {
        int get_damage;  
        int inv = (dam < 30) ? 1 : (dam < 60) ? 2 : 3;
-       bool double_resist = (p_ptr->oppose_cold  || music_singing(MUSIC_RESIST) || (p_ptr->special_defense & KATA_MUSOU));
+       bool double_resist = IS_OPPOSE_COLD();
 
        /* Total immunity */
        if (p_ptr->immune_cold || (dam <= 0))
@@ -5512,7 +5738,7 @@ bool polymorph_monster(int y, int x)
 
        if (p_ptr->inside_arena || p_ptr->inside_battle) return (FALSE);
 
-       if ((p_ptr->riding == c_ptr->m_idx) || (m_ptr->mflag2 & MFLAG_KAGE)) return (FALSE);
+       if ((p_ptr->riding == c_ptr->m_idx) || (m_ptr->mflag2 & MFLAG2_KAGE)) return (FALSE);
 
        /* Memorize the monster before polymorphing */
        back_m = *m_ptr;
@@ -5528,7 +5754,7 @@ bool polymorph_monster(int y, int x)
                /* 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 & MFLAG_NOPET) mode |= PM_NO_PET;
+               if (m_ptr->mflag2 & MFLAG2_NOPET) mode |= PM_NO_PET;
 
                /* "Kill" the "old" monster */
                delete_monster_idx(c_ptr->m_idx);
@@ -5912,6 +6138,9 @@ msg_format("
                p_ptr->csp = p_ptr->msp;
        }
 
+       /* Redraw mana and hp */
+       p_ptr->redraw |= (PR_MANA);
+
        p_ptr->notice |= (PN_COMBINE | PN_REORDER);
        p_ptr->window |= (PW_INVEN);