OSDN Git Service

一般形のナズグルに与えられるフラグUNIQUE_7をNAZGULと置き換えた. この
[hengband/hengband.git] / src / dungeon.c
index e6122fe..35bb9cf 100644 (file)
@@ -1,15 +1,15 @@
 /* File: dungeonc */
 
-/* Purpose: Angband game engine */
-
 /*
- * Copyright (c) 1989 James E. Wilson, Robert A. Koeneke
+ * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
  *
- * This software may be copied and distributed for educational, research, and
- * not for profit purposes provided that this copyright and statement are
- * included in all such copies.
+ * This software may be copied and distributed for educational, research,
+ * and not for profit purposes provided that this copyright and statement
+ * are included in all such copies.  Other copyrights may also apply.
  */
 
+/* Purpose: Angband game engine */
+
 #include "angband.h"
 
 #define TY_CURSE_CHANCE 200
@@ -74,16 +74,16 @@ static byte value_check_aux2(object_type *o_ptr)
        if (broken_p(o_ptr)) return FEEL_BROKEN;
 
        /* Artifacts -- except cursed/broken ones */
-       if (artifact_p(o_ptr) || o_ptr->art_name) return FEEL_GOOD;
+       if (artifact_p(o_ptr) || o_ptr->art_name) return FEEL_UNCURSED;
 
        /* Ego-Items -- except cursed/broken ones */
-       if (ego_item_p(o_ptr)) return FEEL_GOOD;
+       if (ego_item_p(o_ptr)) return FEEL_UNCURSED;
 
        /* Good armor bonus */
-       if (o_ptr->to_a > 0) return FEEL_GOOD;
+       if (o_ptr->to_a > 0) return FEEL_UNCURSED;
 
        /* Good weapon bonuses */
-       if (o_ptr->to_h + o_ptr->to_d > 0) return FEEL_GOOD;
+       if (o_ptr->to_h + o_ptr->to_d > 0) return FEEL_UNCURSED;
 
        /* No feeling */
        return FEEL_NONE;
@@ -127,7 +127,10 @@ static void sense_inventory_aux(int slot, bool heavy)
                        }
                        case FEEL_CURSED:
                        {
-                               feel = randint0(3) ? FEEL_GOOD : FEEL_AVERAGE;
+                               if (heavy)
+                                       feel = randint0(3) ? FEEL_GOOD : FEEL_AVERAGE;
+                               else
+                                       feel = FEEL_UNCURSED;
                                break;
                        }
                        case FEEL_AVERAGE:
@@ -137,7 +140,10 @@ static void sense_inventory_aux(int slot, bool heavy)
                        }
                        case FEEL_GOOD:
                        {
-                               feel = randint0(3) ? FEEL_CURSED : FEEL_AVERAGE;
+                               if (heavy)
+                                       feel = randint0(3) ? FEEL_CURSED : FEEL_AVERAGE;
+                               else
+                                       feel = FEEL_CURSED;
                                break;
                        }
                        case FEEL_EXCELLENT:
@@ -167,8 +173,8 @@ msg_format("%s%s(%c)
 describe_use(slot),o_name, index_to_label(slot),game_inscriptions[feel]);
 #else
                msg_format("You feel the %s (%c) you are %s %s %s...",
-                          o_name, index_to_label(slot), describe_use(slot),
-                          ((o_ptr->number == 1) ? "is" : "are"),
+                          o_name, index_to_label(slot), describe_use(slot),
+                          ((o_ptr->number == 1) ? "is" : "are"),
                                   game_inscriptions[feel]);
 #endif
 
@@ -182,8 +188,8 @@ msg_format("
 o_name, index_to_label(slot),game_inscriptions[feel]);
 #else
                msg_format("You feel the %s (%c) in your pack %s %s...",
-                          o_name, index_to_label(slot),
-                          ((o_ptr->number == 1) ? "is" : "are"),
+                          o_name, index_to_label(slot),
+                          ((o_ptr->number == 1) ? "is" : "are"),
                                   game_inscriptions[feel]);
 #endif
 
@@ -198,8 +204,8 @@ o_name, index_to_label(slot),game_inscriptions[feel]);
        /* Auto-inscription/destroy */
        idx = is_autopick(o_ptr);
        auto_inscribe_item(slot, idx);
-        if (destroy_feeling)
-                auto_destroy_item(slot, idx, FALSE);
+       if (destroy_feeling)
+               auto_destroy_item(slot, idx);
 
        /* Combine / Reorder the pack (later) */
        p_ptr->notice |= (PN_COMBINE | PN_REORDER);
@@ -333,6 +339,8 @@ static void sense_inventory1(void)
                }
 
                case CLASS_MINDCRAFTER:
+               case CLASS_IMITATOR:
+               case CLASS_BLUE_MAGE:
                case CLASS_MIRROR_MASTER:
                {
                        /* Bad sensing */
@@ -376,16 +384,6 @@ static void sense_inventory1(void)
                        break;
                }
 
-               case CLASS_IMITATOR:
-               case CLASS_BLUE_MAGE:
-               {
-                       /* Bad sensing */
-                       if (0 != randint0(55000L / (plev * plev + 40))) return;
-
-                       /* Done */
-                       break;
-               }
-
                case CLASS_BEASTMASTER:
                {
                        /* Bad sensing */
@@ -438,6 +436,7 @@ static void sense_inventory1(void)
                        case TV_SOFT_ARMOR:
                        case TV_HARD_ARMOR:
                        case TV_DRAG_ARMOR:
+                       case TV_CARD:
                        {
                                okay = TRUE;
                                break;
@@ -617,10 +616,10 @@ if (get_check("¾
                                max_level = 100;
                }
                else
-                {
-                        max_level = d_info[dungeon_type].maxdepth;
-                        min_level = d_info[dungeon_type].mindepth;
-                }
+               {
+                       max_level = d_info[dungeon_type].maxdepth;
+                       min_level = d_info[dungeon_type].mindepth;
+               }
 
                /* Prompt */
 #ifdef JP
@@ -672,6 +671,7 @@ msg_format("%d 
 
        /* Change level */
        dun_level = command_arg;
+       prepare_change_floor_mode(CFM_CLEAR_ALL);
 
        leave_quest_check();
 
@@ -705,9 +705,9 @@ msg_print("
 #endif
 
 
-       if (!p_ptr->invuln)
+       if (!IS_INVULN())
 #ifdef JP
-take_hit(DAMAGE_NOESCAPE, damroll(10, 8), "¥Ñ¥¿¡¼¥ó»²õ", -1);
+               take_hit(DAMAGE_NOESCAPE, damroll(10, 8), "¥Ñ¥¿¡¼¥ó»²õ", -1);
 #else
                take_hit(DAMAGE_NOESCAPE, damroll(10, 8), "corrupting the Pattern", -1);
 #endif
@@ -786,11 +786,11 @@ msg_print("
        }
        else if (cave[py][px].feat == FEAT_PATTERN_XTRA2)
        {
-               if (!p_ptr->invuln)
+               if (!IS_INVULN())
 #ifdef JP
-take_hit(DAMAGE_NOESCAPE, 200, "²õ¤ì¤¿¡Ö¥Ñ¥¿¡¼¥ó¡×¤òÊ⤤¤¿¥À¥á¡¼¥¸", -1);
+                       take_hit(DAMAGE_NOESCAPE, 200, "²õ¤ì¤¿¡Ö¥Ñ¥¿¡¼¥ó¡×¤òÊ⤤¤¿¥À¥á¡¼¥¸", -1);
 #else
-               take_hit(DAMAGE_NOESCAPE, 200, "walking the corrupted Pattern", -1);
+                       take_hit(DAMAGE_NOESCAPE, 200, "walking the corrupted Pattern", -1);
 #endif
 
        }
@@ -798,9 +798,9 @@ take_hit(DAMAGE_NOESCAPE, 200, "
        {
                if ((prace_is_(RACE_AMBERITE)) && !one_in_(2))
                        return TRUE;
-               else if (!p_ptr->invuln)
+               else if (!IS_INVULN())
 #ifdef JP
-take_hit(DAMAGE_NOESCAPE, damroll(1,3), "¡Ö¥Ñ¥¿¡¼¥ó¡×¤òÊ⤤¤¿¥À¥á¡¼¥¸", -1);
+                       take_hit(DAMAGE_NOESCAPE, damroll(1, 3), "¡Ö¥Ñ¥¿¡¼¥ó¡×¤òÊ⤤¤¿¥À¥á¡¼¥¸", -1);
 #else
                        take_hit(DAMAGE_NOESCAPE, damroll(1, 3), "walking the Pattern", -1);
 #endif
@@ -1017,7 +1017,7 @@ static void regen_monsters(void)
 
 
 /*
- * Regenerate the monsters (once per 100 game turns)
+ * Regenerate the captured monsters (once per 30 game turns)
  *
  * XXX XXX XXX Should probably be done during monster turns.
  */
@@ -1073,6 +1073,354 @@ static void regen_captured_monsters(void)
 }
 
 
+/*
+ * Process the counters of monsters (once per 10 game turns)
+ *
+ * This function is to process monsters' counters same as player's.
+ */
+static void process_monsters_counters(void)
+{
+       int          m_idx;
+       monster_type *m_ptr;
+       monster_race *r_ptr;
+
+       u32b noise; /* Hack -- local "player stealth" value */
+
+       /* Handle "leaving" */
+       if (p_ptr->leaving) return;
+
+       /* Hack -- calculate the "player noise" */
+       noise = (1L << (30 - p_ptr->skill_stl));
+
+       /* Process the monsters (backwards) */
+       for (m_idx = m_max - 1; m_idx >= 1; m_idx--)
+       {
+               /* Access the monster */
+               m_ptr = &m_list[m_idx];
+               r_ptr = &r_info[m_ptr->r_idx];
+
+               /* Ignore "dead" monsters */
+               if (!m_ptr->r_idx) continue;
+
+               /* Handle Invulnerability */
+               if (m_ptr->invulner)
+               {
+                       /* Reduce by one, note if expires */
+                       m_ptr->invulner--;
+
+                       if (!m_ptr->invulner)
+                       {
+                               if (m_ptr->ml)
+                               {
+                                       char m_name[80];
+
+                                       /* 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 is no longer invulnerable.", m_name);
+#endif
+
+                                       if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
+                                       if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
+                               }
+                               if (!p_ptr->wild_mode) m_ptr->energy_need += ENERGY_NEED();
+                       }
+               }
+
+               /* Handle fast */
+               if (m_ptr->fast)
+               {
+                       /* Reduce by one, note if expires */
+                       m_ptr->fast--;
+
+                       if (!m_ptr->fast && m_ptr->ml)
+                       {
+                               char m_name[80];
+
+                               /* 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 is no longer fast.", m_name);
+#endif
+
+                               if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
+                               if (p_ptr->riding == m_idx)
+                               {
+                                       p_ptr->redraw |= (PR_UHEALTH);
+                                       p_ptr->update |= (PU_BONUS);
+                               }
+                       }
+               }
+
+               /* Handle slow */
+               if (m_ptr->slow)
+               {
+                       /* Reduce by one, note if expires */
+                       m_ptr->slow--;
+
+                       if (!m_ptr->slow && m_ptr->ml)
+                       {
+                               char m_name[80];
+
+                               /* 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 is no longer slow.", m_name);
+#endif
+
+                               if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
+                               if (p_ptr->riding == m_idx)
+                               {
+                                       p_ptr->redraw |= (PR_UHEALTH);
+                                       p_ptr->update |= (PU_BONUS);
+                               }
+                       }
+               }
+
+               /* Handle "sleep" */
+               if (m_ptr->csleep)
+               {
+                       /* Assume does not wake up */
+                       bool test = FALSE;
+
+                       /* Hack -- Require proximity */
+                       if (m_ptr->cdis < AAF_LIMIT)
+                       {
+                               /* Handle "sensing radius" */
+                               if (m_ptr->cdis <= (is_pet(m_ptr) ? ((r_ptr->aaf > MAX_SIGHT) ? MAX_SIGHT : r_ptr->aaf) : r_ptr->aaf))
+                               {
+                                       /* We may wake up */
+                                       test = TRUE;
+                               }
+
+                               /* Handle "sight" and "aggravation" */
+                               else if ((m_ptr->cdis <= MAX_SIGHT) && (player_has_los_bold(m_ptr->fy, m_ptr->fx)))
+                               {
+                                       /* We may wake up */
+                                       test = TRUE;
+                               }
+                       }
+
+                       if (test)
+                       {
+                               u32b notice = randint0(1024);
+
+                               /* Nightmare monsters are more alert */
+                               if (ironman_nightmare) notice /= 2;
+
+                               /* Hack -- See if monster "notices" player */
+                               if ((notice * notice * notice) <= noise)
+                               {
+                                       /* Hack -- amount of "waking" */
+                                       /* Wake up faster near the player */
+                                       int d = (m_ptr->cdis < AAF_LIMIT / 2) ? (AAF_LIMIT / m_ptr->cdis) : 1;
+
+                                       /* Hack -- amount of "waking" is affected by speed of player */
+                                       d = (d * SPEED_TO_ENERGY(p_ptr->pspeed)) / 10;
+                                       if (d < 0) d = 1;
+
+                                       /* Still asleep */
+                                       if (m_ptr->csleep > d)
+                                       {
+                                               /* Monster wakes up "a little bit" */
+                                               m_ptr->csleep -= d;
+
+                                               /* Notice the "not waking up" */
+                                               if (m_ptr->ml)
+                                               {
+                                                       /* Hack -- Count the ignores */
+                                                       if (r_ptr->r_ignore < MAX_UCHAR)
+                                                       {
+                                                               r_ptr->r_ignore++;
+                                                       }
+                                               }
+                                       }
+
+                                       /* Just woke up */
+                                       else
+                                       {
+                                               /* Reset sleep counter */
+                                               m_ptr->csleep = 0;
+
+                                               if (r_ptr->flags7 & RF7_HAS_LD_MASK) p_ptr->update |= (PU_MON_LITE);
+
+                                               /* Notice the "waking up" */
+                                               if (m_ptr->ml)
+                                               {
+                                                       char m_name[80];
+
+                                                       /* 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 == m_idx) p_ptr->redraw |= (PR_HEALTH);
+                                                       if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
+
+                                                       /* Hack -- Count the wakings */
+                                                       if (r_ptr->r_wake < MAX_UCHAR)
+                                                       {
+                                                               r_ptr->r_wake++;
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+               }
+
+               /* Handle "stun" */
+               if (m_ptr->stunned)
+               {
+                       int d = 1;
+
+                       /* Make a "saving throw" against stun */
+                       if (randint0(10000) <= r_ptr->level * r_ptr->level)
+                       {
+                               /* Recover fully */
+                               d = m_ptr->stunned;
+                       }
+
+                       /* Hack -- Recover from stun */
+                       if (m_ptr->stunned > d)
+                       {
+                               /* Recover somewhat */
+                               m_ptr->stunned -= d;
+                       }
+
+                       /* Fully recover */
+                       else
+                       {
+                               /* Recover fully */
+                               m_ptr->stunned = 0;
+
+                               /* Message if visible */
+                               if (m_ptr->ml)
+                               {
+                                       char m_name[80];
+
+                                       /* 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 is no longer stunned.", m_name);
+#endif
+
+                                       if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
+                                       if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
+                               }
+                       }
+               }
+
+               /* Handle confusion */
+               if (m_ptr->confused)
+               {
+                       /* Amount of "boldness" */
+                       int d = randint1(r_ptr->level / 20 + 1);
+
+                       /* Still confused */
+                       if (m_ptr->confused > d)
+                       {
+                               /* Reduce the confusion */
+                               m_ptr->confused -= d;
+                       }
+
+                       /* Recovered */
+                       else
+                       {
+                               /* No longer confused */
+                               m_ptr->confused = 0;
+
+                               /* Message if visible */
+                               if (m_ptr->ml)
+                               {
+                                       char m_name[80];
+
+                                       /* 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 is no longer confused.", m_name);
+#endif
+
+                                       if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
+                                       if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
+                               }
+                       }
+               }
+
+               /* Handle "fear" */
+               if (m_ptr->monfear)
+               {
+                       /* Amount of "boldness" */
+                       int d = randint1(r_ptr->level / 20 + 1);
+
+                       /* Still afraid */
+                       if (m_ptr->monfear > d)
+                       {
+                               /* Reduce the fear */
+                               m_ptr->monfear -= d;
+                       }
+
+                       /* Recover from fear, take note if seen */
+                       else
+                       {
+                               /* No longer afraid */
+                               m_ptr->monfear = 0;
+
+                               /* Visual note */
+                               if (m_ptr->ml)
+                               {
+                                       char m_name[80];
+#ifndef JP
+                                       char m_poss[80];
+
+                                       /* Acquire the monster possessive */
+                                       monster_desc(m_poss, m_ptr, MD_PRON_VISIBLE | MD_POSSESSIVE);
+#endif
+
+                                       /* 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 recovers %s courage.", m_name, m_poss);
+#endif
+
+                                       if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
+                                       if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
+                               }
+                       }
+               }
+       }
+}
+
+
 static void notice_lite_change(object_type *o_ptr)
 {
        /* Hack -- notice interesting fuel steps */
@@ -1133,7 +1481,7 @@ msg_print("
 
 void leave_quest_check(void)
 {
-       /* Save quset number for dungeon pref file ($LEAVING_QUEST) */
+       /* Save quest number for dungeon pref file ($LEAVING_QUEST) */
        leaving_quest = p_ptr->inside_quest;
 
        /* Leaving an 'only once' quest marks it as failed */
@@ -1148,6 +1496,9 @@ void leave_quest_check(void)
                        r_info[quest[leaving_quest].r_idx].flags1 &= ~(RF1_QUESTOR);
                        if (record_rand_quest)
                                do_cmd_write_nikki(NIKKI_RAND_QUEST_F, leaving_quest, NULL);
+
+                       /* Floor of random quest will be blocked */
+                       prepare_change_floor_mode(CFM_NO_RETURN);
                }
                else if (record_fix_quest)
                        do_cmd_write_nikki(NIKKI_FIX_QUEST_F, leaving_quest, NULL);
@@ -1174,7 +1525,8 @@ bool psychometry(void)
        char            o_name[MAX_NLEN];
        byte            feel;
        cptr            q, s;
-
+       bool okay = FALSE;
+       int idx;
 
        item_tester_no_ryoute = TRUE;
        /* Get an item */
@@ -1252,6 +1604,41 @@ msg_format("%s
        /* Window stuff */
        p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
 
+       /* Valid "tval" codes */
+       switch (o_ptr->tval)
+       {
+       case TV_SHOT:
+       case TV_ARROW:
+       case TV_BOLT:
+       case TV_BOW:
+       case TV_DIGGING:
+       case TV_HAFTED:
+       case TV_POLEARM:
+       case TV_SWORD:
+       case TV_BOOTS:
+       case TV_GLOVES:
+       case TV_HELM:
+       case TV_CROWN:
+       case TV_SHIELD:
+       case TV_CLOAK:
+       case TV_SOFT_ARMOR:
+       case TV_HARD_ARMOR:
+       case TV_DRAG_ARMOR:
+       case TV_CARD:
+       case TV_RING:
+       case TV_AMULET:
+       case TV_LITE:
+       case TV_FIGURINE:
+               okay = TRUE;
+               break;
+       }
+
+       /* Auto-inscription/destroy */
+       idx = is_autopick(o_ptr);
+       auto_inscribe_item(item, idx);
+       if (okay && destroy_feeling)
+               auto_destroy_item(item, idx);
+
        /* Something happened */
        return (TRUE);
 }
@@ -1259,97 +1646,98 @@ msg_format("%s
 
 static void gere_music(s32b music)
 {
-        switch(music)
-        {
-                case MUSIC_SLOW:
-                        slow_monsters();
-                        break;
-                case MUSIC_STUN:
-                        stun_monsters(damroll(p_ptr->lev/10,2));
-                        break;
-                case MUSIC_L_LIFE:
-                        hp_player(damroll(2,6));
-                        break;
-                case MUSIC_FEAR:
-                        project_hack(GF_TURN_ALL, p_ptr->lev);
-                        break;
-                case MUSIC_PSI:
-                        project_hack(GF_PSI, randint1(p_ptr->lev * 3 / 2));
-                        break;
-                case MUSIC_ID:
-                        project(0, 1, py, px, 0, GF_IDENTIFY, PROJECT_ITEM, -1);
-                        break;
-                case MUSIC_CONF:
-                        confuse_monsters(p_ptr->lev * 2);
-                        break;
-                case MUSIC_SOUND:
-                        project_hack(GF_SOUND, damroll(10 + p_ptr->lev/5,7));
-                        break;
-                case MUSIC_CHARM:
-                        charm_monsters(damroll(10 + p_ptr->lev/15,6));
-                        break;
-                case MUSIC_WALL:
+       switch(music)
+       {
+               case MUSIC_SLOW:
+                       slow_monsters();
+                       break;
+               case MUSIC_STUN:
+                       stun_monsters(damroll(p_ptr->lev/10,2));
+                       break;
+               case MUSIC_L_LIFE:
+                       hp_player(damroll(2,6));
+                       break;
+               case MUSIC_FEAR:
+                       project_hack(GF_TURN_ALL, p_ptr->lev);
+                       break;
+               case MUSIC_PSI:
+                       project_hack(GF_PSI, randint1(p_ptr->lev * 3 / 2));
+                       break;
+               case MUSIC_ID:
+                       project(0, 1, py, px, 0, GF_IDENTIFY, PROJECT_ITEM, -1);
+                       break;
+               case MUSIC_CONF:
+                       confuse_monsters(p_ptr->lev * 2);
+                       break;
+               case MUSIC_SOUND:
+                       project_hack(GF_SOUND, damroll(10 + p_ptr->lev/5,7));
+                       break;
+               case MUSIC_CHARM:
+                       charm_monsters(damroll(10 + p_ptr->lev/15,6));
+                       break;
+               case MUSIC_WALL:
                        project(0, 0, py, px,
                                0, GF_DISINTEGRATE, PROJECT_KILL | PROJECT_ITEM | PROJECT_HIDE, -1);
-                        break;
-                case MUSIC_DISPEL:
-                        dispel_monsters(randint1(p_ptr->lev * 3));
-                        dispel_evil(randint1(p_ptr->lev * 3));
-                        break;
-                case MUSIC_SARUMAN:
-                        slow_monsters();
-                        sleep_monsters();
-                        break;
-                case MUSIC_QUAKE:
-                        earthquake(py, px, 10);
-                        break;
-                case MUSIC_STASIS:
-                        stasis_monsters(p_ptr->lev * 4);
-                        break;
-                case MUSIC_SHERO:
-                        dispel_monsters(randint1(p_ptr->lev * 3));
-                        break;
-                case MUSIC_H_LIFE:
-                        hp_player(damroll(15,10));
+                       break;
+               case MUSIC_DISPEL:
+                       dispel_monsters(randint1(p_ptr->lev * 3));
+                       dispel_evil(randint1(p_ptr->lev * 3));
+                       break;
+               case MUSIC_SARUMAN:
+                       slow_monsters();
+                       sleep_monsters();
+                       break;
+               case MUSIC_QUAKE:
+                       earthquake(py, px, 10);
+                       break;
+               case MUSIC_STASIS:
+                       stasis_monsters(p_ptr->lev * 4);
+                       break;
+               case MUSIC_SHERO:
+                       dispel_monsters(randint1(p_ptr->lev * 3));
+                       break;
+               case MUSIC_H_LIFE:
+                       hp_player(damroll(15,10));
                        set_stun(0);
                        set_cut(0);
-                        break;
-                case MUSIC_DETECT+19:
-                       wiz_lite(FALSE, FALSE);
-                case MUSIC_DETECT+11:
-                case MUSIC_DETECT+12:
-                case MUSIC_DETECT+13:
-                case MUSIC_DETECT+14:
-                case MUSIC_DETECT+15:
-                case MUSIC_DETECT+16:
-                case MUSIC_DETECT+17:
-                case MUSIC_DETECT+18:
+                       break;
+               case MUSIC_DETECT+19:
+                       wiz_lite(FALSE);
+               case MUSIC_DETECT+11:
+               case MUSIC_DETECT+12:
+               case MUSIC_DETECT+13:
+               case MUSIC_DETECT+14:
+               case MUSIC_DETECT+15:
+               case MUSIC_DETECT+16:
+               case MUSIC_DETECT+17:
+               case MUSIC_DETECT+18:
                        map_area(DETECT_RAD_MAP);
                        if ((p_ptr->lev > 39) && (music < MUSIC_DETECT+19)) p_ptr->magic_num1[0] = music+1;
-                case MUSIC_DETECT+6:
-                case MUSIC_DETECT+7:
-                case MUSIC_DETECT+8:
-                case MUSIC_DETECT+9:
-                case MUSIC_DETECT+10:
-                       detect_treasure(DETECT_RAD_DEFAULT);
+               case MUSIC_DETECT+6:
+               case MUSIC_DETECT+7:
+               case MUSIC_DETECT+8:
+               case MUSIC_DETECT+9:
+               case MUSIC_DETECT+10:
+                       /* There are too many hidden treasure.  So... */
+                       /* detect_treasure(DETECT_RAD_DEFAULT); */
                        detect_objects_gold(DETECT_RAD_DEFAULT);
                        detect_objects_normal(DETECT_RAD_DEFAULT);
                        if ((p_ptr->lev > 24) && (music < MUSIC_DETECT+11)) p_ptr->magic_num1[0] = music+1;
-                case MUSIC_DETECT+3:
-                case MUSIC_DETECT+4:
-                case MUSIC_DETECT+5:
+               case MUSIC_DETECT+3:
+               case MUSIC_DETECT+4:
+               case MUSIC_DETECT+5:
                        detect_monsters_invis(DETECT_RAD_DEFAULT);
                        detect_monsters_normal(DETECT_RAD_DEFAULT);
                        if ((p_ptr->lev > 19) && (music < MUSIC_DETECT+6)) p_ptr->magic_num1[0] = music+1;
-                case MUSIC_DETECT:
-                case MUSIC_DETECT+1:
-                case MUSIC_DETECT+2:
-                       detect_traps(DETECT_RAD_DEFAULT);
+               case MUSIC_DETECT:
+               case MUSIC_DETECT+1:
+               case MUSIC_DETECT+2:
+                       detect_traps(DETECT_RAD_DEFAULT, TRUE);
                        detect_doors(DETECT_RAD_DEFAULT);
                        detect_stairs(DETECT_RAD_DEFAULT);
                        if ((p_ptr->lev > 14)  && (music  < MUSIC_DETECT+3)) p_ptr->magic_num1[0] = music+1;
                        break;
-        }
+       }
 }
 
 /*
@@ -1378,15 +1766,16 @@ static void recharged_notice(object_type *o_ptr)
                        object_desc(o_name, o_ptr, FALSE, 0);
 
                        /* Notify the player */
-                       if (o_ptr->number > 1)
 #ifdef JP
-msg_format("%s¤ÏºÆ½¼Å¶¤µ¤ì¤¿¡£", o_name);
-else msg_format("%s¤ÏºÆ½¼Å¶¤µ¤ì¤¿¡£", o_name);
+                       msg_format("%s¤ÏºÆ½¼Å¶¤µ¤ì¤¿¡£", o_name);
 #else
+                       if (o_ptr->number > 1)
                                msg_format("Your %s are recharged.", o_name);
-                       else msg_format("Your %s is recharged.", o_name);
+                       else
+                               msg_format("Your %s is recharged.", o_name);
 #endif
 
+                       disturb(0, 0);
 
                        /* Done. */
                        return;
@@ -1400,42 +1789,39 @@ else msg_format("%s
 
 static void check_music(void)
 {
-        magic_type *s_ptr;
-       u32b shouhimana;
-
-        /* Music singed by player */
-        if(p_ptr->pclass != CLASS_BARD) return;
-        if(!p_ptr->magic_num1[0] && !p_ptr->magic_num1[1]) return;
-
-        s_ptr = &technic_info[REALM_MUSIC - MIN_TECHNIC][p_ptr->magic_num2[0]];
-
-       shouhimana = (s_ptr->smana*(3800-p_ptr->spell_exp[p_ptr->magic_num2[0]])+2399);
-       if(p_ptr->dec_mana)
-               shouhimana *= 3;
-       else shouhimana *= 4;
-       shouhimana /= 9600;
-       if(shouhimana < 1) shouhimana = 1;
-        shouhimana *= 0x8000;
-        if (((u16b)(p_ptr->csp) < (shouhimana / 0x10000)) || (p_ptr->anti_magic))
-        {
-                stop_singing();
+       magic_type *s_ptr;
+       int spell;
+       u32b need_mana;
+
+       /* Music singed by player */
+       if (p_ptr->pclass != CLASS_BARD) return;
+       if (!p_ptr->magic_num1[0] && !p_ptr->magic_num1[1]) return;
+
+       spell = p_ptr->magic_num2[0];
+       s_ptr = &technic_info[REALM_MUSIC - MIN_TECHNIC][spell];
+
+       need_mana = mod_need_mana(s_ptr->smana, spell, REALM_MUSIC);
+       need_mana *= 0x8000;
+       if (((u32b)p_ptr->csp < (need_mana / 0x10000)) || (p_ptr->anti_magic))
+       {
+               stop_singing();
                return;
-        }
-        else
-        {
-                       p_ptr->csp -= (u16b) (shouhimana / 0x10000);
-                       shouhimana = (shouhimana & 0xffff);
-                       if (p_ptr->csp_frac < shouhimana)
+       }
+       else
+       {
+               p_ptr->csp -= (u16b) (need_mana / 0x10000);
+               need_mana = (need_mana & 0xffff);
+               if ((u32b)p_ptr->csp_frac < need_mana)
                {
                        p_ptr->csp--;
-                       p_ptr->csp_frac += (u16b)(0x10000L - shouhimana);
+                       p_ptr->csp_frac += (u16b)(0x10000L - need_mana);
                }
                else
                {
-                       p_ptr->csp_frac -= (u16b)shouhimana;
+                       p_ptr->csp_frac -= (u16b)need_mana;
                }
 
-                p_ptr->redraw |= PR_MANA;
+               p_ptr->redraw |= PR_MANA;
                if (p_ptr->magic_num1[1])
                {
                        p_ptr->magic_num1[0] = p_ptr->magic_num1[1];
@@ -1450,20 +1836,26 @@ static void check_music(void)
                        /* Recalculate bonuses */
                        p_ptr->update |= (PU_BONUS | PU_HP);
 
-                       /* Redraw status bar */
-                       p_ptr->redraw |= (PR_STATUS);
+                       /* Redraw map and status bar */
+                       p_ptr->redraw |= (PR_MAP | PR_STATUS | PR_STATE);
+
+                       /* Update monsters */
+                       p_ptr->update |= (PU_MONSTERS);
+
+                       /* Window stuff */
+                       p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
                }
-        }
-       if (p_ptr->spell_exp[p_ptr->magic_num2[0]] < 900)
-               p_ptr->spell_exp[p_ptr->magic_num2[0]]+=5;
-       else if(p_ptr->spell_exp[p_ptr->magic_num2[0]] < 1200)
-               {if (one_in_(2) && (dun_level > 4) && ((dun_level + 10) > p_ptr->lev)) p_ptr->spell_exp[p_ptr->magic_num2[0]]+=1;}
-       else if(p_ptr->spell_exp[p_ptr->magic_num2[0]] < 1400)
-               {if (one_in_(5) && ((dun_level + 5) > p_ptr->lev) && ((dun_level + 5) > s_ptr->slevel)) p_ptr->spell_exp[p_ptr->magic_num2[0]]+=1;}
-       else if(p_ptr->spell_exp[p_ptr->magic_num2[0]] < 1600)
-               {if (one_in_(5) && ((dun_level + 5) > p_ptr->lev) && (dun_level > s_ptr->slevel)) p_ptr->spell_exp[p_ptr->magic_num2[0]]+=1;}
+       }
+       if (p_ptr->spell_exp[spell] < SPELL_EXP_BEGINNER)
+               p_ptr->spell_exp[spell] += 5;
+       else if(p_ptr->spell_exp[spell] < SPELL_EXP_SKILLED)
+       { if (one_in_(2) && (dun_level > 4) && ((dun_level + 10) > p_ptr->lev)) p_ptr->spell_exp[spell] += 1; }
+       else if(p_ptr->spell_exp[spell] < SPELL_EXP_EXPERT)
+       { if (one_in_(5) && ((dun_level + 5) > p_ptr->lev) && ((dun_level + 5) > s_ptr->slevel)) p_ptr->spell_exp[spell] += 1; }
+       else if(p_ptr->spell_exp[spell] < SPELL_EXP_MASTER)
+       { if (one_in_(5) && ((dun_level + 5) > p_ptr->lev) && (dun_level > s_ptr->slevel)) p_ptr->spell_exp[spell] += 1; }
 
-        gere_music(p_ptr->magic_num1[0]);
+       gere_music(p_ptr->magic_num1[0]);
 }
 
 /* Choose one of items that have cursed flag */
@@ -1513,13 +1905,17 @@ static void process_world(void)
        s32b len = TURNS_PER_TICK * TOWN_DAWN;
        s32b tick = turn % len + len / 4;
 
+       int quest_num = quest_number(dun_level);
+
        extract_day_hour_min(&day, &hour, &min);
        prev_min = (1440 * (tick - TURNS_PER_TICK) / len) % 60;
 
-        if ((turn - old_turn == (150 - dun_level) * TURNS_PER_TICK)
-           && (dun_level) &&
-           !(quest_number(dun_level) && ((quest_number(dun_level) < MIN_RANDOM_QUEST) && !(quest_number(dun_level) == QUEST_OBERON || quest_number(dun_level) == QUEST_SERPENT || !(quest[quest_number(dun_level)].flags & QUEST_FLAG_PRESET)))) &&
-           !(p_ptr->inside_battle))
+       if ((turn - old_turn == (150 - dun_level) * TURNS_PER_TICK)
+           && dun_level &&
+           !(quest_num && (is_fixed_quest_idx(quest_num) &&
+           !((quest_num == QUEST_OBERON) || (quest_num == QUEST_SERPENT) ||
+             !(quest[quest_num].flags & QUEST_FLAG_PRESET)))) &&
+           !p_ptr->inside_battle)
                do_cmd_feeling();
 
        if (p_ptr->inside_battle && !p_ptr->leaving)
@@ -1604,7 +2000,7 @@ msg_print("
                }
        }
 
-       /* Every 20 game turns */
+       /* Every 10 game turns */
        if (turn % TURNS_PER_TICK) return;
 
        /*** Check the Time and Load ***/
@@ -1661,14 +2057,14 @@ msg_print("
                        do_cmd_save_game(TRUE);
        }
 
-        if (mon_fight)
-        {
+       if (mon_fight)
+       {
 #ifdef JP
-                msg_print("²¿¤«¤¬Ê¹¤³¤¨¤¿¡£");
+               msg_print("²¿¤«¤¬Ê¹¤³¤¨¤¿¡£");
 #else
-                msg_print("You hear noise.");
+               msg_print("You hear noise.");
 #endif
-        }
+       }
 
        /*** Handle the wilderness/town (sunshine) ***/
 
@@ -1688,12 +2084,11 @@ msg_print("
                        {
                                /* Message */
 #ifdef JP
-msg_print("Ì뤬ÌÀ¤±¤¿¡£");
+                               msg_print("Ì뤬ÌÀ¤±¤¿¡£");
 #else
                                msg_print("The sun has risen.");
 #endif
 
-
                                /* Hack -- Scan the town */
                                for (y = 0; y < cur_hgt; y++)
                                {
@@ -1717,14 +2112,15 @@ msg_print("
                        /* Night falls */
                        else
                        {
+                               byte feat;
+
                                /* Message */
 #ifdef JP
-msg_print("Æü¤¬ÄÀ¤ó¤À¡£");
+                               msg_print("Æü¤¬ÄÀ¤ó¤À¡£");
 #else
                                msg_print("The sun has fallen.");
 #endif
 
-
                                /* Hack -- Scan the town */
                                for (y = 0; y < cur_hgt; y++)
                                {
@@ -1733,21 +2129,27 @@ msg_print("
                                                /* Get the cave grid */
                                                c_ptr = &cave[y][x];
 
-                                               /* Darken "boring" features */
-                                               if ((c_ptr->feat <= FEAT_INVIS) ||
-                                                   ((c_ptr->feat >= FEAT_DEEP_WATER) &&
-                                                       (c_ptr->feat <= FEAT_MOUNTAIN) &&
-                                                    (c_ptr->feat != FEAT_MUSEUM)) ||
-                                                   (x == 0) || (x == cur_wid-1) ||
-                                                   (y == 0) || (y == cur_hgt-1))
+                                               /* Feature code (applying "mimic" field) */
+                                               feat = f_info[c_ptr->mimic ? c_ptr->mimic : c_ptr->feat].mimic;
+
+                                               if (!is_mirror_grid(c_ptr) && (feat != FEAT_QUEST_ENTER) && (feat != FEAT_ENTRANCE))
                                                {
-                                                       /* Forget the grid */
-                                                       if (!(c_ptr->info & CAVE_IN_MIRROR)) c_ptr->info &= ~(CAVE_GLOW | CAVE_MARK);
+                                                       /* Assume dark */
+                                                       c_ptr->info &= ~(CAVE_GLOW);
+
+                                                       if ((feat <= FEAT_INVIS) || (feat == FEAT_DIRT) || (feat == FEAT_GRASS))
+                                                       {
+                                                               /* Forget the normal floor grid */
+                                                               c_ptr->info &= ~(CAVE_MARK);
 
-                                                       /* Hack -- Notice spot */
-                                                       note_spot(y, x);
+                                                               /* Hack -- Notice spot */
+                                                               note_spot(y, x);
+                                                       }
                                                }
                                        }
+
+                                       /* Glow deep lava and building entrances */
+                                       glow_deep_lava_and_bldg();
                                }
                        }
 
@@ -1763,7 +2165,8 @@ msg_print("
        }
 
        /* Set back the rewards once a day */
-       if (!(turn % (TURNS_PER_TICK*10 * STORE_TURNS)))
+       /* Only used for reward in thief's guild for now */
+       if (!(turn % (TURNS_PER_TICK * TOWN_DAWN)))
        {
                int n;
 
@@ -1790,22 +2193,25 @@ if (cheat_xtra) msg_print("
            !p_ptr->inside_arena && !p_ptr->inside_quest && !p_ptr->inside_battle)
        {
                /* Make a new monster */
-               (void)alloc_monster(MAX_SIGHT + 5, FALSE);
+               (void)alloc_monster(MAX_SIGHT + 5, 0);
        }
 
        /* Hack -- Check for creature regeneration */
        if (!(turn % (TURNS_PER_TICK*10)) && !p_ptr->inside_battle) regen_monsters();
        if (!(turn % (TURNS_PER_TICK*3))) regen_captured_monsters();
 
+       /* Hack -- Process the counters of all monsters */
+       process_monsters_counters();
+
 
        /*** Damage over Time ***/
 
        /* Take damage from poison */
-       if (p_ptr->poisoned && !p_ptr->invuln)
+       if (p_ptr->poisoned && !IS_INVULN())
        {
                /* Take damage */
 #ifdef JP
-take_hit(DAMAGE_NOESCAPE, 1, "ÆÇ", -1);
+               take_hit(DAMAGE_NOESCAPE, 1, "ÆÇ", -1);
 #else
                take_hit(DAMAGE_NOESCAPE, 1, "poison", -1);
 #endif
@@ -1816,9 +2222,9 @@ take_hit(DAMAGE_NOESCAPE, 1, "
        /* (Vampires) Take damage from sunlight */
        if (prace_is_(RACE_VAMPIRE) || (p_ptr->mimic_form == MIMIC_VAMPIRE))
        {
-               if (!dun_level && !p_ptr->resist_lite && !p_ptr->invuln && is_daytime())
+               if (!dun_level && !p_ptr->resist_lite && !IS_INVULN() && is_daytime())
                {
-                       if (cave[py][px].info & CAVE_GLOW)
+                       if ((cave[py][px].info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW)
                        {
                                /* Take damage */
 #ifdef JP
@@ -1861,19 +2267,18 @@ sprintf(ouch, "%s
                        sprintf(ouch, "wielding %s", o_name);
 #endif
 
-                       if (!p_ptr->invuln) take_hit(DAMAGE_NOESCAPE, 1, ouch, -1);
+                       if (!IS_INVULN()) take_hit(DAMAGE_NOESCAPE, 1, ouch, -1);
                }
        }
 
        if ((cave[py][px].feat == FEAT_SHAL_LAVA) &&
-               !p_ptr->invuln && !p_ptr->immune_fire && !p_ptr->ffall)
+               !IS_INVULN() && !p_ptr->immune_fire && !p_ptr->ffall)
        {
                int damage = 3000 + randint0(2000);
 
                if (prace_is_(RACE_ENT)) damage += damage/3;
-
                if (p_ptr->resist_fire) damage = damage / 3;
-               if (p_ptr->oppose_fire) damage = damage / 3;
+               if (IS_OPPOSE_FIRE()) damage = damage / 3;
                damage = damage / 100 + (randint0(100) < (damage % 100));
 
                if (damage)
@@ -1892,7 +2297,7 @@ take_hit(DAMAGE_NOESCAPE, damage, "
        }
 
        else if ((cave[py][px].feat == FEAT_DEEP_LAVA) &&
-               !p_ptr->invuln && !p_ptr->immune_fire)
+               !IS_INVULN() && !p_ptr->immune_fire)
        {
                int damage = 6000 + randint0(4000);
 
@@ -1900,7 +2305,7 @@ take_hit(DAMAGE_NOESCAPE, damage, "
                cptr hit_from;
 
                if (p_ptr->resist_fire) damage = damage / 3;
-               if (p_ptr->oppose_fire) damage = damage / 3;
+               if (IS_OPPOSE_FIRE()) damage = damage / 3;
 
                if (p_ptr->ffall)
                {
@@ -1961,9 +2366,9 @@ take_hit(DAMAGE_NOESCAPE, randint1(p_ptr->lev), "Ů
                if ((r_info[m_list[p_ptr->riding].r_idx].flags2 & RF2_AURA_FIRE) && !p_ptr->immune_fire)
                {
                        damage = r_info[m_list[p_ptr->riding].r_idx].level / 2;
-                       if (prace_is_(RACE_ENT)) damage += damage/3;
+                       if (prace_is_(RACE_ENT)) damage += damage / 3;
                        if (p_ptr->resist_fire) damage = damage / 3;
-                       if (p_ptr->oppose_fire) damage = damage / 3;
+                       if (IS_OPPOSE_FIRE()) damage = damage / 3;
 #ifdef JP
 msg_print("Ç®¤¤¡ª");
 take_hit(DAMAGE_NOESCAPE, damage, "±ê¤Î¥ª¡¼¥é", -1);
@@ -1975,8 +2380,9 @@ take_hit(DAMAGE_NOESCAPE, damage, "
                if ((r_info[m_list[p_ptr->riding].r_idx].flags2 & RF2_AURA_ELEC) && !p_ptr->immune_elec)
                {
                        damage = r_info[m_list[p_ptr->riding].r_idx].level / 2;
+                       if (prace_is_(RACE_ANDROID)) damage += damage / 3;
                        if (p_ptr->resist_elec) damage = damage / 3;
-                       if (p_ptr->oppose_elec) damage = damage / 3;
+                       if (IS_OPPOSE_ELEC()) damage = damage / 3;
 #ifdef JP
 msg_print("Äˤ¤¡ª");
 take_hit(DAMAGE_NOESCAPE, damage, "Åŵ¤¤Î¥ª¡¼¥é", -1);
@@ -1989,7 +2395,7 @@ take_hit(DAMAGE_NOESCAPE, damage, "
                {
                        damage = r_info[m_list[p_ptr->riding].r_idx].level / 2;
                        if (p_ptr->resist_cold) damage = damage / 3;
-                       if (p_ptr->oppose_cold) damage = damage / 3;
+                       if (IS_OPPOSE_COLD()) damage = damage / 3;
 #ifdef JP
 msg_print("Î䤿¤¤¡ª");
 take_hit(DAMAGE_NOESCAPE, damage, "Î䵤¤Î¥ª¡¼¥é", -1);
@@ -2014,7 +2420,7 @@ take_hit(DAMAGE_NOESCAPE, damage, "
                {
                        /* Do nothing */
                }
-               else if (!p_ptr->invuln && !p_ptr->wraith_form && !p_ptr->kabenuke &&
+               else if (!IS_INVULN() && !p_ptr->wraith_form && !p_ptr->kabenuke &&
                    ((p_ptr->chp > (p_ptr->lev / 5)) || !p_ptr->pass_wall))
                {
                        cptr dam_desc;
@@ -2050,39 +2456,10 @@ dam_desc = "
 
        if (!hour && !min)
        {
-               monster_race *r_ptr;
-
                if (min != prev_min)
                {
-                       int max_dl = 3;
-                       bool old_inside_battle = p_ptr->inside_battle;
-
                        do_cmd_write_nikki(NIKKI_HIGAWARI, 0, NULL);
-
-                       p_ptr->inside_battle = TRUE;
-                       get_mon_num_prep(NULL,NULL);
-
-                       for (i = 0; i < max_d_idx; i++)
-                       {
-                               if (max_dlv[i] < d_info[i].mindepth) continue;
-                               if (max_dl < max_dlv[i]) max_dl = max_dlv[i];
-                       }
-                       while (1)
-                       {
-                               today_mon = get_mon_num(max_dl);
-                               r_ptr = &r_info[today_mon];
-
-                               if (r_ptr->flags1 & RF1_UNIQUE) continue;
-                               if (r_ptr->flags7 & (RF7_UNIQUE_7 | RF7_UNIQUE2)) continue;
-                               if (r_ptr->flags2 & (RF2_MULTIPLY)) continue;
-                               if (!(r_ptr->flags9 & RF9_DROP_CORPSE) || !(r_ptr->flags9 & RF9_DROP_SKELETON)) continue;
-                               if (r_ptr->level < MIN(max_dl/2, 40)) continue;
-                               if (r_ptr->rarity > 10) continue;
-                               if (r_ptr->level == 0) continue;
-                               break;
-                       }
-                       p_ptr->today_mon = 0;
-                       p_ptr->inside_battle = old_inside_battle;
+                       determine_today_mon(FALSE);
                }
        }
 
@@ -2161,7 +2538,7 @@ msg_print("
        }
 
        /* Take damage from cuts */
-       if (p_ptr->cut && !p_ptr->invuln)
+       if (p_ptr->cut && !IS_INVULN())
        {
                /* Mortal wound or Deep Gash */
                if (p_ptr->cut > 1000)
@@ -2218,13 +2595,11 @@ take_hit(DAMAGE_NOESCAPE, i, "
                /* Digest normally */
                if (p_ptr->food < PY_FOOD_MAX)
                {
-                       /* Every 100 game turns */
+                       /* Every 50 game turns */
                        if (!(turn % (TURNS_PER_TICK*5)))
                        {
                                /* Basic digestion rate based on speed */
-                               i = /* extract_energy[p_ptr->pspeed] * 2;*/
-                               ((p_ptr->pspeed > 199) ? 49 : ((p_ptr->pspeed < 0) ?
-                               1 : extract_energy[p_ptr->pspeed]));
+                               i = SPEED_TO_ENERGY(p_ptr->pspeed);
 
                                /* Regeneration takes more food */
                                if (p_ptr->regenerate) i += 20;
@@ -2260,9 +2635,9 @@ take_hit(DAMAGE_NOESCAPE, i, "
 
                /* Take damage */
 #ifdef JP
-if (!p_ptr->invuln) take_hit(DAMAGE_LOSELIFE, i, "¶õÊ¢", -1);
+               if (!IS_INVULN()) take_hit(DAMAGE_LOSELIFE, i, "¶õÊ¢", -1);
 #else
-               if (!p_ptr->invuln) take_hit(DAMAGE_LOSELIFE, i, "starvation", -1);
+               if (!IS_INVULN()) take_hit(DAMAGE_LOSELIFE, i, "starvation", -1);
 #endif
 
        }
@@ -2769,7 +3144,7 @@ msg_print("
 
                if ((p_ptr->muta2 & MUT2_COWARDICE) && (randint1(3000) == 13))
                {
-                       if (!(p_ptr->resist_fear || p_ptr->hero || p_ptr->shero))
+                       if (!p_ptr->resist_fear)
                        {
                                disturb(0, 0);
 #ifdef JP
@@ -2992,7 +3367,7 @@ msg_print("
                        msg_print(NULL);
 
                        /* Absorb light from the current possition */
-                       if (cave[py][px].info & CAVE_GLOW)
+                       if ((cave[py][px].info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW)
                        {
                                hp_player(10);
                        }
@@ -3292,6 +3667,9 @@ msg_print("̵Ũ
 
                                hp_player(healing);
                                p_ptr->csp -= healing;
+
+                               /* Redraw mana */
+                               p_ptr->redraw |= (PR_MANA);
                        }
                }
                if ((p_ptr->muta2 & MUT2_HP_TO_SP) && !p_ptr->anti_magic &&
@@ -3309,6 +3687,9 @@ msg_print("̵Ũ
                                }
 
                                p_ptr->csp += healing;
+
+                               /* Redraw mana */
+                               p_ptr->redraw |= (PR_MANA);
 #ifdef JP
 take_hit(DAMAGE_LOSELIFE, healing, "Ƭ¤Ë¾º¤Ã¤¿·ì", -1);
 #else
@@ -3358,7 +3739,7 @@ msg_print("
 
        /*** Process Inventory ***/
 
-       if ((p_ptr->cursed & TRC_P_FLAG_MASK) && !p_ptr->wild_mode)
+       if ((p_ptr->cursed & TRC_P_FLAG_MASK) && !p_ptr->inside_battle && !p_ptr->wild_mode)
        {
                /*
                 * Hack: Uncursed teleporting items (e.g. Trump Weapons)
@@ -3395,7 +3776,8 @@ if (!get_rnd_line("chainswd_j.txt", 0, noise))
                        (void)activate_ty_curse(FALSE, &count);
                }
                /* Handle experience draining */
-               if ((p_ptr->cursed & TRC_DRAIN_EXP) && one_in_(4))
+               if (p_ptr->prace != RACE_ANDROID && 
+                       ((p_ptr->cursed & TRC_DRAIN_EXP) && one_in_(4)))
                {
                        p_ptr->exp -= (p_ptr->lev+1)/2;
                        if (p_ptr->exp < 0) p_ptr->exp = 0;
@@ -3512,7 +3894,7 @@ msg_format("%s
                }
                if ((p_ptr->cursed & TRC_COWARDICE) && one_in_(1500))
                {
-                       if (!(p_ptr->resist_fear || p_ptr->hero || p_ptr->shero))
+                       if (!p_ptr->resist_fear)
                        {
                                disturb(0, 0);
 #ifdef JP
@@ -3569,17 +3951,23 @@ msg_format("%s
        /* Rarely, take damage from the Jewel of Judgement */
        if (one_in_(999) && !p_ptr->anti_magic)
        {
-               if ((inventory[INVEN_LITE].tval) &&
-                   (inventory[INVEN_LITE].sval == SV_LITE_THRAIN))
+               object_type *o_ptr = &inventory[INVEN_LITE];
+
+               if (o_ptr->name1 == ART_JUDGE)
                {
 #ifdef JP
-msg_print("¡Ø¿³È½¤ÎÊõÀС٤Ϥ¢¤Ê¤¿¤ÎÂÎÎϤòµÛ¼ý¤·¤¿¡ª");
-take_hit(DAMAGE_LOSELIFE, MIN(p_ptr->lev, 50), "¿³È½¤ÎÊõÀÐ", -1);
+                       if (object_known_p(o_ptr))
+                               msg_print("¡Ø¿³È½¤ÎÊõÀС٤Ϥ¢¤Ê¤¿¤ÎÂÎÎϤòµÛ¼ý¤·¤¿¡ª");
+                       else
+                               msg_print("¤Ê¤Ë¤«¤¬¤¢¤Ê¤¿¤ÎÂÎÎϤòµÛ¼ý¤·¤¿¡ª");
+                       take_hit(DAMAGE_LOSELIFE, MIN(p_ptr->lev, 50), "¿³È½¤ÎÊõÀÐ", -1);
 #else
-                       msg_print("The Jewel of Judgement drains life from you!");
+                       if (object_known_p(o_ptr))
+                               msg_print("The Jewel of Judgement drains life from you!");
+                       else
+                               msg_print("Something drains life from you!");
                        take_hit(DAMAGE_LOSELIFE, MIN(p_ptr->lev, 50), "the Jewel of Judgement", -1);
 #endif
-
                }
        }
 
@@ -3712,7 +4100,7 @@ take_hit(DAMAGE_LOSELIFE, MIN(p_ptr->lev, 50), "
                if (!p_ptr->word_recall)
                {
                        /* Disturbing! */
-                       disturb(0, 0);
+                       disturb(0, 0);
 
                        /* Determine the level */
                        if (dun_level || p_ptr->inside_quest)
@@ -3723,12 +4111,13 @@ msg_print("
                                msg_print("You feel yourself yanked upwards!");
 #endif
 
-                                p_ptr->recall_dungeon = dungeon_type;
+                               p_ptr->recall_dungeon = dungeon_type;
                                if (record_stair)
                                        do_cmd_write_nikki(NIKKI_RECALL, dun_level, NULL);
 
                                dun_level = 0;
                                dungeon_type = 0;
+                               prepare_change_floor_mode(CFM_CLEAR_ALL);
 
                                leave_quest_check();
 
@@ -3743,7 +4132,7 @@ msg_print("
                                msg_print("You feel yourself yanked downwards!");
 #endif
 
-                                dungeon_type = p_ptr->recall_dungeon;
+                               dungeon_type = p_ptr->recall_dungeon;
 
                                if (record_stair)
                                        do_cmd_write_nikki(NIKKI_RECALL, dun_level, NULL);
@@ -3782,6 +4171,8 @@ msg_print("
                                }
                                p_ptr->wild_mode = FALSE;
 
+                               prepare_change_floor_mode(CFM_CLEAR_ALL);
+
                                /* Leaving */
                                p_ptr->leaving = TRUE;
 
@@ -3805,6 +4196,52 @@ msg_print("
                        sound(SOUND_TPLEVEL);
                }
        }
+
+
+       /* Delayed Alter reality */
+       if (p_ptr->alter_reality)
+       {
+               if (autosave_l && (p_ptr->alter_reality == 1) && !p_ptr->inside_battle)
+                       do_cmd_save_game(TRUE);
+
+               /* Count down towards alter */
+               p_ptr->alter_reality--;
+
+               p_ptr->redraw |= (PR_STATUS);
+
+               /* Activate the alter reality */
+               if (!p_ptr->alter_reality)
+               {
+                       /* Disturbing! */
+                       disturb(0, 0);
+
+                       /* Determine the level */
+                       if (!quest_number(dun_level) && dun_level)
+                       {
+#ifdef JP
+                               msg_print("À¤³¦¤¬ÊѤï¤Ã¤¿¡ª");
+#else
+                               msg_print("The world changes!");
+#endif
+
+                               prepare_change_floor_mode(CFM_CLEAR_ALL);
+
+                               /* Leaving */
+                               p_ptr->leaving = TRUE;
+                       }
+                       else
+                       {
+#ifdef JP
+                               msg_print("À¤³¦¤¬¾¯¤·¤Î´ÖÊѲ½¤·¤¿¤è¤¦¤À¡£");
+#else
+                               msg_print("The world seems to change for a moment!");
+#endif
+                       }
+
+                       /* Sound */
+                       sound(SOUND_TPLEVEL);
+               }
+       }
 }
 
 
@@ -3817,10 +4254,21 @@ static bool enter_wizard_mode(void)
        /* Ask first time */
        if (!p_ptr->noscore)
        {
+               /* Wizard mode is not permitted */
+               if (!allow_debug_opts)
+               {
+#ifdef JP
+                       msg_print("¥¦¥£¥¶¡¼¥É¥â¡¼¥É¤Ïµö²Ä¤µ¤ì¤Æ¤¤¤Þ¤»¤ó¡£ ");
+#else
+                       msg_print("Wizard mode is not permitted.");
+#endif
+                       return FALSE;
+               }
+
                /* Mention effects */
 #ifdef JP
-msg_print("¥¦¥£¥¶¡¼¥É¥â¡¼¥É¤Ï¥Ç¥Ð¥°¤È¼Â¸³¤Î¤¿¤á¤Î¥â¡¼¥É¤Ç¤¹¡£ ");
-msg_print("°ìÅÙ¥¦¥£¥¶¡¼¥É¥â¡¼¥É¤ËÆþ¤ë¤È¥¹¥³¥¢¤Ïµ­Ï¿¤µ¤ì¤Þ¤»¤ó¡£");
+               msg_print("¥¦¥£¥¶¡¼¥É¥â¡¼¥É¤Ï¥Ç¥Ð¥Ã¥°¤È¼Â¸³¤Î¤¿¤á¤Î¥â¡¼¥É¤Ç¤¹¡£ ");
+               msg_print("°ìÅÙ¥¦¥£¥¶¡¼¥É¥â¡¼¥É¤ËÆþ¤ë¤È¥¹¥³¥¢¤Ïµ­Ï¿¤µ¤ì¤Þ¤»¤ó¡£");
 #else
                msg_print("Wizard mode is for debugging and experimenting.");
                msg_print("The game will not be scored if you enter wizard mode.");
@@ -3830,15 +4278,19 @@ msg_print("
 
                /* Verify request */
 #ifdef JP
-if (!get_check("ËÜÅö¤Ë¥¦¥£¥¶¡¼¥É¥â¡¼¥É¤ËÆþ¤ê¤¿¤¤¤Î¤Ç¤¹¤«? "))
+               if (!get_check("ËÜÅö¤Ë¥¦¥£¥¶¡¼¥É¥â¡¼¥É¤ËÆþ¤ê¤¿¤¤¤Î¤Ç¤¹¤«? "))
 #else
                if (!get_check("Are you sure you want to enter wizard mode? "))
 #endif
-
                {
                        return (FALSE);
                }
 
+#ifdef JP
+               do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "¥¦¥£¥¶¡¼¥É¥â¡¼¥É¤ËÆÍÆþ¤·¤Æ¥¹¥³¥¢¤ò»Ä¤»¤Ê¤¯¤Ê¤Ã¤¿¡£");
+#else
+               do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "give up recording score to enter wizard mode.");
+#endif
                /* Mark savefile */
                p_ptr->noscore |= 0x0002;
        }
@@ -3858,10 +4310,21 @@ static bool enter_debug_mode(void)
        /* Ask first time */
        if (!p_ptr->noscore)
        {
+               /* Debug mode is not permitted */
+               if (!allow_debug_opts)
+               {
+#ifdef JP
+                       msg_print("¥Ç¥Ð¥Ã¥°¥³¥Þ¥ó¥É¤Ïµö²Ä¤µ¤ì¤Æ¤¤¤Þ¤»¤ó¡£ ");
+#else
+                       msg_print("Use of debug command is not permitted.");
+#endif
+                       return FALSE;
+               }
+
                /* Mention effects */
 #ifdef JP
-msg_print("¥Ç¥Ð¥°¡¦¥³¥Þ¥ó¥É¤Ï¥Ç¥Ð¥°¤È¼Â¸³¤Î¤¿¤á¤Î¥³¥Þ¥ó¥É¤Ç¤¹¡£ ");
-msg_print("¥Ç¥Ð¥°¡¦¥³¥Þ¥ó¥É¤ò»È¤¦¤È¥¹¥³¥¢¤Ïµ­Ï¿¤µ¤ì¤Þ¤»¤ó¡£");
+               msg_print("¥Ç¥Ð¥Ã¥°¡¦¥³¥Þ¥ó¥É¤Ï¥Ç¥Ð¥Ã¥°¤È¼Â¸³¤Î¤¿¤á¤Î¥³¥Þ¥ó¥É¤Ç¤¹¡£ ");
+               msg_print("¥Ç¥Ð¥Ã¥°¡¦¥³¥Þ¥ó¥É¤ò»È¤¦¤È¥¹¥³¥¢¤Ïµ­Ï¿¤µ¤ì¤Þ¤»¤ó¡£");
 #else
                msg_print("The debug commands are for debugging and experimenting.");
                msg_print("The game will not be scored if you use debug commands.");
@@ -3871,11 +4334,10 @@ msg_print("
 
                /* Verify request */
 #ifdef JP
-if (!get_check("ËÜÅö¤Ë¥Ç¥Ð¥°¡¦¥³¥Þ¥ó¥É¤ò»È¤¤¤Þ¤¹¤«? "))
+               if (!get_check("ËÜÅö¤Ë¥Ç¥Ð¥Ã¥°¡¦¥³¥Þ¥ó¥É¤ò»È¤¤¤Þ¤¹¤«? "))
 #else
                if (!get_check("Are you sure you want to use debug commands? "))
 #endif
-
                {
                        return (FALSE);
                }
@@ -3913,8 +4375,8 @@ static bool enter_borg_mode(void)
        {
                /* Mention effects */
 #ifdef JP
-msg_print("¥Ü¡¼¥°¡¦¥³¥Þ¥ó¥É¤Ï¥Ç¥Ð¥°¤È¼Â¸³¤Î¤¿¤á¤Î¥³¥Þ¥ó¥É¤Ç¤¹¡£ ");
-msg_print("¥Ü¡¼¥°¡¦¥³¥Þ¥ó¥É¤ò»È¤¦¤È¥¹¥³¥¢¤Ïµ­Ï¿¤µ¤ì¤Þ¤»¤ó¡£");
+               msg_print("¥Ü¡¼¥°¡¦¥³¥Þ¥ó¥É¤Ï¥Ç¥Ð¥Ã¥°¤È¼Â¸³¤Î¤¿¤á¤Î¥³¥Þ¥ó¥É¤Ç¤¹¡£ ");
+               msg_print("¥Ü¡¼¥°¡¦¥³¥Þ¥ó¥É¤ò»È¤¦¤È¥¹¥³¥¢¤Ïµ­Ï¿¤µ¤ì¤Þ¤»¤ó¡£");
 #else
                msg_print("The borg commands are for debugging and experimenting.");
                msg_print("The game will not be scored if you use borg commands.");
@@ -3924,15 +4386,19 @@ msg_print("
 
                /* Verify request */
 #ifdef JP
-if (!get_check("ËÜÅö¤Ë¥Ü¡¼¥°¡¦¥³¥Þ¥ó¥É¤ò»È¤¤¤Þ¤¹¤«? "))
+               if (!get_check("ËÜÅö¤Ë¥Ü¡¼¥°¡¦¥³¥Þ¥ó¥É¤ò»È¤¤¤Þ¤¹¤«? "))
 #else
                if (!get_check("Are you sure you want to use borg commands? "))
 #endif
-
                {
                        return (FALSE);
                }
 
+#ifdef JP
+               do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "¥Ü¡¼¥°¡¦¥³¥Þ¥ó¥É¤ò»ÈÍѤ·¤Æ¥¹¥³¥¢¤ò»Ä¤»¤Ê¤¯¤Ê¤Ã¤¿¡£");
+#else
+               do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "give up recording score to use borg commands.");
+#endif
                /* Mark savefile */
                p_ptr->noscore |= 0x0010;
        }
@@ -4239,37 +4705,37 @@ msg_print("
                /* Go up staircase */
                case '<':
                {
-                        if(!p_ptr->wild_mode && !dun_level && !p_ptr->inside_arena && !p_ptr->inside_quest)
-                        {
-                                if (!vanilla_town)
-                                {
-                                        if(ambush_flag)
+                       if(!p_ptr->wild_mode && !dun_level && !p_ptr->inside_arena && !p_ptr->inside_quest)
+                       {
+                               if (!vanilla_town)
+                               {
+                                       if(ambush_flag)
                                        {
 #ifdef JP
-                                                msg_print("½±·â¤«¤éƨ¤²¤ë¤Ë¤Ï¥Þ¥Ã¥×¤Îü¤Þ¤Ç°ÜÆ°¤·¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£");
+                                               msg_print("½±·â¤«¤éƨ¤²¤ë¤Ë¤Ï¥Þ¥Ã¥×¤Îü¤Þ¤Ç°ÜÆ°¤·¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£");
 #else
-                                                msg_print("To flee the ambush you have to reach the edge of the map.");
+                                               msg_print("To flee the ambush you have to reach the edge of the map.");
 #endif
                                        }
                                        else if (p_ptr->food < PY_FOOD_WEAK)
                                        {
 #ifdef JP
-                                                msg_print("¤½¤ÎÁ°¤Ë¿©»ö¤ò¤È¤é¤Ê¤¤¤È¡£");
+                                               msg_print("¤½¤ÎÁ°¤Ë¿©»ö¤ò¤È¤é¤Ê¤¤¤È¡£");
 #else
-                                                msg_print("You must eat something here.");
+                                               msg_print("You must eat something here.");
 #endif
                                        }
-                                        else
-                                        {
+                                       else
+                                       {
                                                if (change_wild_mode())
                                                {
                                                        p_ptr->oldpx = px;
                                                        p_ptr->oldpy = py;
                                                }
-                                        }
-                                }
-                        }
-                        else
+                                       }
+                               }
+                       }
+                       else
                                do_cmd_go_up();
                        break;
                }
@@ -4277,14 +4743,14 @@ msg_print("
                /* Go down staircase */
                case '>':
                {
-                        if(!p_ptr->wild_mode) do_cmd_go_down();
-                        else
-                        {
+                       if(!p_ptr->wild_mode) do_cmd_go_down();
+                       else
+                       {
                                p_ptr->wilderness_x = px;
                                p_ptr->wilderness_y = py;
                                change_wild_mode();
-                        }
-                        break;
+                       }
+                       break;
                }
 
                /* Open a door or chest */
@@ -4908,7 +5374,7 @@ msg_print("
                                char error_m[1024];
                                sound(SOUND_ILLEGAL);
 #ifdef JP
-                                if (!get_rnd_line("error_j.txt", 0, error_m))
+                               if (!get_rnd_line("error_j.txt", 0, error_m))
 #else
                                if (!get_rnd_line("error.txt", 0, error_m))
 #endif
@@ -4977,7 +5443,7 @@ msg_print("
                        if (!m_ptr->r_idx) continue;
 
                        /* Hack -- Detect monster */
-                       m_ptr->mflag |= (MFLAG_MARK | MFLAG_SHOW);
+                       m_ptr->mflag2 |= (MFLAG2_MARK | MFLAG2_SHOW);
 
                        /* Update the monster */
                        update_mon(i, FALSE);
@@ -4988,7 +5454,7 @@ msg_print("
        /* Give the player some energy */
        else if (!(load && p_ptr->energy_need <= 0))
        {
-               p_ptr->energy_need -= (p_ptr->pspeed > 199 ? 49 : (p_ptr->pspeed < 0 ? 1 : extract_energy[p_ptr->pspeed]));
+               p_ptr->energy_need -= SPEED_TO_ENERGY(p_ptr->pspeed);
        }
 
        /* No turn yet */
@@ -5021,7 +5487,8 @@ msg_print("
                            !p_ptr->poisoned && !p_ptr->afraid &&
                            !p_ptr->stun && !p_ptr->cut &&
                            !p_ptr->slow && !p_ptr->paralyzed &&
-                           !p_ptr->image && !p_ptr->word_recall)
+                           !p_ptr->image && !p_ptr->word_recall &&
+                           !p_ptr->alter_reality)
                        {
                                set_action(ACTION_NONE);
                        }
@@ -5108,6 +5575,8 @@ msg_print("
                        /* Recover fully */
                        m_ptr->csleep = 0;
 
+                       if (r_info[m_ptr->r_idx].flags7 & RF7_HAS_LD_MASK) p_ptr->update |= (PU_MON_LITE);
+
                        /* Acquire the monster name */
                        monster_desc(m_name, m_ptr, 0);
 #ifdef JP
@@ -5239,6 +5708,7 @@ msg_format("%^s
                        }
                }
 
+               /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
                handle_stuff();
        }
 
@@ -5311,18 +5781,11 @@ msg_format("%^s
                p_ptr->counter = FALSE;
                now_damaged = FALSE;
 
-               /* Notice stuff (if needed) */
-               if (p_ptr->notice) notice_stuff();
-
-               /* Update stuff (if needed) */
-               if (p_ptr->update) update_stuff();
-
-               /* Redraw stuff (if needed) */
-               if (p_ptr->redraw) redraw_stuff();
-
-               /* Redraw stuff (if needed) */
-               if (p_ptr->window) window_stuff();
+               /* Handle "p_ptr->notice" */
+               notice_stuff();
 
+               /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
+               handle_stuff();
 
                /* Place the cursor on the player */
                move_cursor_relative(py, px);
@@ -5373,17 +5836,11 @@ msg_format("%s(%c)
                        inven_item_describe(item);
                        inven_item_optimize(item);
 
-                       /* Notice stuff (if needed) */
-                       if (p_ptr->notice) notice_stuff();
+                       /* Handle "p_ptr->notice" */
+                       notice_stuff();
 
-                       /* Update stuff (if needed) */
-                       if (p_ptr->update) update_stuff();
-
-                       /* Redraw stuff (if needed) */
-                       if (p_ptr->redraw) redraw_stuff();
-
-                       /* Redraw stuff (if needed) */
-                       if (p_ptr->window) window_stuff();
+                       /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
+                       handle_stuff();
                }
 
 
@@ -5400,7 +5857,7 @@ msg_format("%s(%c)
                        /* Place the cursor on the player */
                        move_cursor_relative(py, px);
 
-                       command_cmd = 254;
+                       command_cmd = SPECIAL_KEY_BUILDING;
 
                        /* Process the command */
                        process_command();
@@ -5490,10 +5947,16 @@ msg_format("%s(%c)
                if (energy_use)
                {
                        /* Use some energy */
-                       if (!world_player)
-                               p_ptr->energy_need += (s16b)((s32b)energy_use * ENERGY_NEED() / 100L);
-                       else
+                       if (world_player || energy_use > 400)
+                       {
+                               /* The Randomness is irrelevant */
                                p_ptr->energy_need += energy_use * TURNS_PER_TICK / 10;
+                       }
+                       else
+                       {
+                               /* There is some randomness of needed energy */
+                               p_ptr->energy_need += (s16b)((s32b)energy_use * ENERGY_NEED() / 100L);
+                       }
 
                        /* Hack -- constant hallucination */
                        if (p_ptr->image) p_ptr->redraw |= (PR_MAP);
@@ -5517,11 +5980,15 @@ msg_format("%s(%c)
                                        /* Skip dead monsters */
                                        if (!m_ptr->r_idx) continue;
 
+                                       /* Skip unseen monsters */
+                                       if (!m_ptr->ml) continue;
+
                                        /* Access the monster race */
-                                       r_ptr = &r_info[m_ptr->r_idx];
+                                       r_ptr = &r_info[m_ptr->ap_r_idx];
 
                                        /* Skip non-multi-hued monsters */
-                                       if (!(r_ptr->flags1 & RF1_ATTR_MULTI)) continue;
+                                       if (!(r_ptr->flags1 & (RF1_ATTR_MULTI | RF1_SHAPECHANGER)))
+                                               continue;
 
                                        /* Reset the flag */
                                        shimmer_monsters = TRUE;
@@ -5557,13 +6024,13 @@ msg_format("%s(%c)
                                        }
 
                                        /* Handle memorized monsters */
-                                       if (m_ptr->mflag & MFLAG_MARK)
+                                       if (m_ptr->mflag2 & MFLAG2_MARK)
                                        {
                                                /* Maintain detection */
-                                               if (m_ptr->mflag & MFLAG_SHOW)
+                                               if (m_ptr->mflag2 & MFLAG2_SHOW)
                                                {
                                                        /* Forget flag */
-                                                       m_ptr->mflag &= ~(MFLAG_SHOW);
+                                                       m_ptr->mflag2 &= ~(MFLAG2_SHOW);
 
                                                        /* Still need repairs */
                                                        repair_monsters = TRUE;
@@ -5573,7 +6040,7 @@ msg_format("%s(%c)
                                                else
                                                {
                                                        /* Forget flag */
-                                                       m_ptr->mflag &= ~(MFLAG_MARK);
+                                                       m_ptr->mflag2 &= ~(MFLAG2_MARK);
 
                                                        /* Assume invisible */
                                                        m_ptr->ml = FALSE;
@@ -5630,6 +6097,7 @@ msg_format("%s(%c)
                                world_player = FALSE;
                                p_ptr->energy_need = ENERGY_NEED();
 
+                               /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
                                handle_stuff();
                        }
                }
@@ -5658,7 +6126,7 @@ msg_format("%s(%c)
  */
 static void dungeon(bool load_game)
 {
-       int quest_num = 0, i, num;
+       int quest_num = 0;
 
        /* Set the base level */
        base_level = dun_level;
@@ -5720,47 +6188,6 @@ static void dungeon(bool load_game)
                if (record_maxdeapth) do_cmd_write_nikki(NIKKI_MAXDEAPTH, dun_level, NULL);
        }
 
-       /* No stairs down from Quest */
-       if (quest_number(dun_level))
-       {
-               create_down_stair = 0;
-       }
-
-       /* Paranoia -- no stairs from town or wilderness */
-       if (!dun_level) create_down_stair = create_up_stair = 0;
-
-       /* Option -- no connected stairs */
-       if (!dungeon_stair) create_down_stair = create_up_stair = 0;
-
-       /* Option -- no up stairs */
-       if (ironman_downward) create_down_stair = create_up_stair = 0;
-
-       /* Make a stairway. */
-       if (create_up_stair || create_down_stair)
-       {
-               /* Place a stairway */
-               if (cave_valid_bold(py, px))
-               {
-                       /* XXX XXX XXX */
-                       delete_object(py, px);
-
-                       /* Make stairs */
-                       if (create_down_stair)
-                       {
-                               if (create_down_stair == 2) cave_set_feat(py, px, FEAT_MORE_MORE);
-                               else cave_set_feat(py, px, FEAT_MORE);
-                       }
-                       else
-                       {
-                               if (create_up_stair == 2) cave_set_feat(py, px, FEAT_LESS_LESS);
-                               else cave_set_feat(py, px, FEAT_LESS);
-                       }
-               }
-
-               /* Cancel the stair request */
-               create_down_stair = create_up_stair = 0;
-       }
-
        /* Validate the panel */
        panel_bounds_center();
 
@@ -5775,10 +6202,7 @@ static void dungeon(bool load_game)
        character_xtra = TRUE;
 
        /* Window stuff */
-       p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_SPELL | PW_PLAYER);
-
-       /* Window stuff */
-       p_ptr->window |= (PW_MONSTER);
+       p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_SPELL | PW_PLAYER | PW_MONSTER | PW_OVERHEAD | PW_DUNGEON);
 
        /* Redraw dungeon */
        p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_EQUIPPY);
@@ -5786,33 +6210,17 @@ static void dungeon(bool load_game)
        /* Redraw map */
        p_ptr->redraw |= (PR_MAP);
 
-       /* Window stuff */
-       p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
-
        /* Update stuff */
        p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
 
-       /* Calculate torch radius */
-       p_ptr->update |= (PU_TORCH);
-
-       /* Update stuff */
-       update_stuff();
-
-       /* Redraw stuff */
-       redraw_stuff();
-
-       /* Redraw stuff */
-       window_stuff();
-
-       /* Update stuff */
-       p_ptr->update |= (PU_VIEW | PU_LITE | PU_FLOW | PU_DISTANCE | PU_MON_LITE);
-       p_ptr->update |= (PU_MONSTERS);/*¼«Ê¬¤Ç¸÷¤Ã¤Æ¤¤¤ë¥â¥ó¥¹¥¿¡¼¤Î°Ù */
+       /* Update lite/view */
+       p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE | PU_TORCH);
 
-       /* Update stuff */
-       update_stuff();
+       /* Update monsters */
+       p_ptr->update |= (PU_MONSTERS | PU_DISTANCE | PU_FLOW);
 
-       /* Redraw stuff */
-       redraw_stuff();
+       /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
+       handle_stuff();
 
        /* Leave "xtra" mode */
        character_xtra = FALSE;
@@ -5823,22 +6231,18 @@ static void dungeon(bool load_game)
        /* Combine / Reorder the pack */
        p_ptr->notice |= (PN_COMBINE | PN_REORDER);
 
-       /* Notice stuff */
+       /* Handle "p_ptr->notice" */
        notice_stuff();
 
-       /* Update stuff */
-       update_stuff();
-
-       /* Redraw stuff */
-       redraw_stuff();
-
-       /* Window stuff */
-       window_stuff();
+       /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
+       handle_stuff();
 
        /* Refresh */
        Term_fresh();
 
-       if (quest_number(dun_level) && ((quest_number(dun_level) < MIN_RANDOM_QUEST) && !(quest_number(dun_level) == QUEST_OBERON || quest_number(dun_level) == QUEST_SERPENT || !(quest[quest_number(dun_level)].flags & QUEST_FLAG_PRESET)))) do_cmd_feeling();
+       if (quest_num && (is_fixed_quest_idx(quest_num) &&
+           !((quest_num == QUEST_OBERON) || (quest_num == QUEST_SERPENT) ||
+           !(quest[quest_num].flags & QUEST_FLAG_PRESET)))) do_cmd_feeling();
 
        if (p_ptr->inside_battle)
        {
@@ -5849,7 +6253,6 @@ static void dungeon(bool load_game)
                }
                else
                {
-                       
 #ifdef JP
 msg_print("»î¹ç³«»Ï¡ª");
 #else
@@ -5879,9 +6282,9 @@ msg_print("
                                   d_name+d_info[dungeon_type].name, 
                                   r_name+r_info[d_info[dungeon_type].final_guardian].name);
 #else
-               msg_format("%^s lives in this level as the keeper of %s.",
-                                  r_name+r_info[d_info[dungeon_type].final_guardian].name, 
-                                  d_name+d_info[dungeon_type].name);
+                       msg_format("%^s lives in this level as the keeper of %s.",
+                                          r_name+r_info[d_info[dungeon_type].final_guardian].name, 
+                                          d_name+d_info[dungeon_type].name);
 #endif
        }
 
@@ -5905,8 +6308,6 @@ msg_print("
        /* Main loop */
        while (TRUE)
        {
-               int i, correct_inven_cnt = 0;
-
                /* Hack -- Compact the monster list occasionally */
                if ((m_cnt + 32 > max_m_idx) && !p_ptr->inside_battle) compact_monsters(64);
 
@@ -5924,28 +6325,11 @@ msg_print("
                /* Process the player */
                process_player();
 
-               /* Notice stuff */
-               if (p_ptr->notice) notice_stuff();
-
-               /* Similar slot? */
-               for (i = 0; i < INVEN_PACK; i++)
-               {
-                       object_type *j_ptr = &inventory[i];
-
-                       /* Skip non-objects */
-                       if (!j_ptr->k_idx) continue;
-
-                       correct_inven_cnt++;
-               }
-
-               /* Update stuff */
-               if (p_ptr->update) update_stuff();
-
-               /* Redraw stuff */
-               if (p_ptr->redraw) redraw_stuff();
+               /* Handle "p_ptr->notice" */
+               notice_stuff();
 
-               /* Redraw stuff */
-               if (p_ptr->window) window_stuff();
+               /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
+               handle_stuff();
 
                /* Hack -- Hilite the player */
                move_cursor_relative(py, px);
@@ -5959,17 +6343,11 @@ msg_print("
                /* Process all of the monsters */
                process_monsters();
 
-               /* Notice stuff */
-               if (p_ptr->notice) notice_stuff();
-
-               /* Update stuff */
-               if (p_ptr->update) update_stuff();
-
-               /* Redraw stuff */
-               if (p_ptr->redraw) redraw_stuff();
+               /* Handle "p_ptr->notice" */
+               notice_stuff();
 
-               /* Redraw stuff */
-               if (p_ptr->window) window_stuff();
+               /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
+               handle_stuff();
 
                /* Hack -- Hilite the player */
                move_cursor_relative(py, px);
@@ -5984,17 +6362,11 @@ msg_print("
                /* Process the world */
                process_world();
 
-               /* Notice stuff */
-               if (p_ptr->notice) notice_stuff();
-
-               /* Update stuff */
-               if (p_ptr->update) update_stuff();
-
-               /* Redraw stuff */
-               if (p_ptr->redraw) redraw_stuff();
+               /* Handle "p_ptr->notice" */
+               notice_stuff();
 
-               /* Window stuff */
-               if (p_ptr->window) window_stuff();
+               /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
+               handle_stuff();
 
                /* Hack -- Hilite the player */
                move_cursor_relative(py, px);
@@ -6025,56 +6397,17 @@ msg_print("
        /* Not save-and-quit and not dead? */
        if (p_ptr->playing && !p_ptr->is_dead)
        {
-               for(num = 0; num < 21; num++)
-               {
-                       party_mon[num].r_idx = 0;
-               }
-
-               if (p_ptr->riding)
-               {
-                       COPY(&party_mon[0], &m_list[p_ptr->riding], monster_type);
-               }
-
-               for(i = m_max - 1, num = 1; (i >= 1 && num < 21); i--)
-               {
-                       monster_type *m_ptr = &m_list[i];
-                       
-                       if (!m_ptr->r_idx) continue;
-                       if (!is_pet(m_ptr)) continue;
-                       if (i == p_ptr->riding) continue;
-
-                       if (m_ptr->nickname && (player_has_los_bold(m_ptr->fy, m_ptr->fx) || los(m_ptr->fy, m_ptr->fx, py, px)))
-                       {
-                               if (distance(py, px, m_ptr->fy, m_ptr->fx) > 3) continue;
-                       }
-                       else
-                       {
-                               if (distance(py, px, m_ptr->fy, m_ptr->fx) > 1) continue;
-                       }
-                       if (m_ptr->confused || m_ptr->stunned || m_ptr->csleep) continue;
+               /*
+                * Maintain Unique monsters and artifact, save current
+                * floor, then prepare next floor
+                */
+               leave_floor();
 
-                       COPY(&party_mon[num], &m_list[i], monster_type);
-                       delete_monster_idx(i);
-                       num++;
-               }
-               if (record_named_pet)
-               {
-                       for (i = m_max - 1; i >=1; i--)
-                       {
-                               monster_type *m_ptr = &m_list[i];
-                               char m_name[80];
-                               
-                               if (!m_ptr->r_idx) continue;
-                               if (!is_pet(m_ptr)) continue;
-                               if (!m_ptr->nickname) continue;
-                               if (p_ptr->riding == i) continue;
-                               
-                               monster_desc(m_name, m_ptr, 0x88);
-                               do_cmd_write_nikki(NIKKI_NAMED_PET, 4, m_name);
-                       }
-               }
+               /* Forget the flag */
+               reinit_wilderness = FALSE;
        }
 
+       /* Write about current level on the play record once per level */
        write_level = TRUE;
 }
 
@@ -6124,9 +6457,9 @@ static void load_all_pref_files(void)
        init_autopicker();
 
 #ifdef JP
-        sprintf(buf, "picktype-%s.prf", player_base);
+       sprintf(buf, "picktype-%s.prf", player_base);
 #else
-        sprintf(buf, "pickpref-%s.prf", player_base);
+       sprintf(buf, "pickpref-%s.prf", player_base);
 #endif
 
        err = process_pickpref_file(buf);
@@ -6162,6 +6495,128 @@ static void load_all_pref_files(void)
 
 
 /*
+ * Extract option variables from bit sets
+ */
+void extract_option_vars(void)
+{
+       int i;
+
+       for (i = 0; option_info[i].o_desc; i++)
+       {
+               int os = option_info[i].o_set;
+               int ob = option_info[i].o_bit;
+
+               /* Set the "default" options */
+               if (option_info[i].o_var)
+               {
+                       /* Set */
+                       if (option_flag[os] & (1L << ob))
+                       {
+                               /* Set */
+                               (*option_info[i].o_var) = TRUE;
+                       }
+
+                       /* Clear */
+                       else
+                       {
+                               /* Clear */
+                               (*option_info[i].o_var) = FALSE;
+                       }
+               }
+       }
+}
+
+
+/*
+ * Determine bounty uniques
+ */
+void determine_bounty_uniques(void)
+{
+       int          i, j, tmp;
+       monster_race *r_ptr;
+
+       get_mon_num_prep(NULL, NULL);
+       for (i = 0; i < MAX_KUBI; i++)
+       {
+               while (1)
+               {
+                       kubi_r_idx[i] = get_mon_num(MAX_DEPTH - 1);
+                       r_ptr = &r_info[kubi_r_idx[i]];
+
+                       if (!(r_ptr->flags1 & RF1_UNIQUE)) continue;
+
+                       if (!(r_ptr->flags9 & (RF9_DROP_CORPSE | RF9_DROP_SKELETON))) continue;
+
+                       if (r_ptr->rarity > 100) continue;
+
+                       if (no_questor_or_bounty_uniques(kubi_r_idx[i])) continue;
+
+                       for (j = 0; j < i; j++)
+                               if (kubi_r_idx[i] == kubi_r_idx[j]) break;
+
+                       if (j == i) break;
+               }
+       }
+
+       /* Sort them */
+       for (i = 0; i < MAX_KUBI - 1; i++)
+       {
+               for (j = i; j < MAX_KUBI; j++)
+               {
+                       if (r_info[kubi_r_idx[i]].level > r_info[kubi_r_idx[j]].level)
+                       {
+                               tmp = kubi_r_idx[i];
+                               kubi_r_idx[i] = kubi_r_idx[j];
+                               kubi_r_idx[j] = tmp;
+                       }
+               }
+       }
+}
+
+
+/*
+ * Determine today's bounty monster
+ * Note: conv_old is used if loaded 0.0.3 or older save file
+ */
+void determine_today_mon(bool conv_old)
+{
+       int max_dl = 3, i;
+       bool old_inside_battle = p_ptr->inside_battle;
+       monster_race *r_ptr;
+
+       if (!conv_old)
+       {
+               for (i = 0; i < max_d_idx; i++)
+               {
+                       if (max_dlv[i] < d_info[i].mindepth) continue;
+                       if (max_dl < max_dlv[i]) max_dl = max_dlv[i];
+               }
+       }
+       else max_dl = MAX(max_dlv[DUNGEON_ANGBAND], 3);
+
+       p_ptr->inside_battle = TRUE;
+       get_mon_num_prep(NULL, NULL);
+
+       while (1)
+       {
+               today_mon = get_mon_num(max_dl);
+               r_ptr = &r_info[today_mon];
+
+               if (r_ptr->flags1 & RF1_UNIQUE) continue;
+               if (r_ptr->flags7 & (RF7_NAZGUL | RF7_UNIQUE2)) continue;
+               if (r_ptr->flags2 & RF2_MULTIPLY) continue;
+               if ((r_ptr->flags9 & (RF9_DROP_CORPSE | RF9_DROP_SKELETON)) != (RF9_DROP_CORPSE | RF9_DROP_SKELETON)) continue;
+               if (r_ptr->level < MIN(max_dl / 2, 40)) continue;
+               if (r_ptr->rarity > 10) continue;
+               break;
+       }
+
+       p_ptr->today_mon = 0;
+       p_ptr->inside_battle = old_inside_battle;
+}
+
+
+/*
  * Actually play a game
  *
  * If the "new_game" parameter is true, then, after loading the
@@ -6191,7 +6646,7 @@ void play_game(bool new_game)
 
        /* Initialise the resize hooks */
        angband_term[0]->resize_hook = resize_map;
-       
+
        for (i = 1; i < 8; i++)
        {
                /* Does the term exist? */
@@ -6219,29 +6674,7 @@ quit("
        }
 
        /* Extract the options */
-       for (i = 0; option_info[i].o_desc; i++)
-       {
-               int os = option_info[i].o_set;
-               int ob = option_info[i].o_bit;
-
-               /* Set the "default" options */
-               if (option_info[i].o_var)
-               {
-                       /* Set */
-                       if (option_flag[os] & (1L << ob))
-                       {
-                               /* Set */
-                               (*option_info[i].o_var) = TRUE;
-                       }
-
-                       /* Clear */
-                       else
-                       {
-                               /* Clear */
-                               (*option_info[i].o_var) = FALSE;
-                       }
-               }
-       }
+       extract_option_vars();
 
        /* Report waited score */
        if (p_ptr->wait_report_score)
@@ -6273,7 +6706,7 @@ quit("
                character_icky = TRUE;
 
                /* Build the filename */
-               path_build(buf, 1024, ANGBAND_DIR_APEX, "scores.raw");
+               path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
 
                /* Open the high score file, for reading/writing */
                highscore_fd = fd_open(buf, O_RDWR);
@@ -6327,6 +6760,16 @@ quit("
 
                /* Prepare to init the RNG */
                Rand_quick = TRUE;
+
+               /* Initialize the saved floors data */
+               init_saved_floors();
+       }
+
+       /* Old game is loaded.  But new game is requested. */
+       else if (new_game)
+       {
+               /* Delete expanded temporal files */
+               clear_saved_floor_files();
        }
 
        /* Process old character */
@@ -6361,8 +6804,6 @@ quit("
        /* Roll new character */
        if (new_game)
        {
-               monster_race *r_ptr;
-
                /* The dungeon is not ready */
                character_dungeon = FALSE;
 
@@ -6393,57 +6834,9 @@ quit("
 #endif
 
                load = FALSE;
-               get_mon_num_prep(NULL, NULL);
-               for (i = 0; i < MAX_KUBI; i++)
-               {
-                       while (1)
-                       {
-                               int j;
-
-                               kubi_r_idx[i] = get_mon_num(MAX_DEPTH - 1);
-                               r_ptr = &r_info[kubi_r_idx[i]];
-
-                               if(!(r_ptr->flags1 & RF1_UNIQUE)) continue;
-
-                               if(!(r_ptr->flags9 & RF9_DROP_CORPSE)) continue;
-                               if (r_ptr->rarity > 100) continue;
-
-                               if(r_ptr->flags6 & RF6_SPECIAL) continue;
-
-                               for (j = 0; j < i; j++)
-                                       if (kubi_r_idx[i] == kubi_r_idx[j])break;
-
-                               if (j == i) break;
-                       }
-               }
-               for (i = 0; i < MAX_KUBI -1; i++)
-               {
-                       int j,tmp;
-                       for (j = i; j < MAX_KUBI; j++)
-                       {
-                               if (r_info[kubi_r_idx[i]].level > r_info[kubi_r_idx[j]].level)
-                               {
-                                       tmp = kubi_r_idx[i];
-                                       kubi_r_idx[i] = kubi_r_idx[j];
-                                       kubi_r_idx[j] = tmp;
-                               }
-                       }
-               }
-
-               p_ptr->inside_battle = TRUE;
-               while (1)
-               {
-                       today_mon = get_mon_num(3);
-                       r_ptr = &r_info[today_mon];
 
-                       if (r_ptr->flags1 & RF1_UNIQUE) continue;
-                       if (r_ptr->flags2 & (RF2_MULTIPLY)) continue;
-                       if (!(r_ptr->flags9 & RF9_DROP_CORPSE) || !(r_ptr->flags9 & RF9_DROP_SKELETON)) continue;
-                       if (r_ptr->rarity > 10) continue;
-                       if (r_ptr->level == 0) continue;
-                       break;
-               }
-               p_ptr->inside_battle = FALSE;
+               determine_bounty_uniques();
+               determine_today_mon(FALSE);
        }
        else
        {
@@ -6462,9 +6855,9 @@ quit("
                if (p_ptr->riding == -1)
                {
                        p_ptr->riding = 0;
-                       for(i = m_max; i > 0; i--)
+                       for (i = m_max; i > 0; i--)
                        {
-                               if ((m_list[i].fy == py) && (m_list[i].fx == px))
+                               if (player_bold(m_list[i].fy, m_list[i].fx))
                                {
                                        p_ptr->riding = i;
                                        break;
@@ -6486,35 +6879,11 @@ quit("
        panel_col_min = cur_wid;
 
        /* Sexy gal gets bonus to maximum weapon skill of whip */
-       if(p_ptr->pseikaku == SEIKAKU_SEXY)
-               s_info[p_ptr->pclass].w_max[TV_HAFTED-TV_BOW][SV_WHIP] = 8000;
-
-        /* Fill the arrays of floors and walls in the good proportions */
-        for (i = 0; i < 100; i++)
-        {
-                int lim1, lim2, lim3;
-
-                lim1 = d_info[dungeon_type].floor_percent1;
-                lim2 = lim1 + d_info[dungeon_type].floor_percent2;
-                lim3 = lim2 + d_info[dungeon_type].floor_percent3;
-
-               if (i < lim1)
-                       floor_type[i] = d_info[dungeon_type].floor1;
-               else if (i < lim2)
-                       floor_type[i] = d_info[dungeon_type].floor2;
-               else if (i < lim3)
-                       floor_type[i] = d_info[dungeon_type].floor3;
-
-               lim1 = d_info[dungeon_type].fill_percent1;
-               lim2 = lim1 + d_info[dungeon_type].fill_percent2;
-               lim3 = lim2 + d_info[dungeon_type].fill_percent3;
-               if (i < lim1)
-                       fill_type[i] = d_info[dungeon_type].fill_type1;
-               else if (i < lim2)
-                       fill_type[i] = d_info[dungeon_type].fill_type2;
-               else if (i < lim3)
-                       fill_type[i] = d_info[dungeon_type].fill_type3;
-        }
+       if (p_ptr->pseikaku == SEIKAKU_SEXY)
+               s_info[p_ptr->pclass].w_max[TV_HAFTED-TV_BOW][SV_WHIP] = WEAPON_EXP_MASTER;
+
+       /* Fill the arrays of floors and walls in the good proportions */
+       set_floor_and_wall(dungeon_type);
 
        /* Flavor the objects */
        flavor_init();
@@ -6538,35 +6907,28 @@ prt("
 
        /* Hack -- Enter wizard mode */
        if (arg_wizard)
-        {
-                if (enter_wizard_mode()) p_ptr->wizard = TRUE;
-                else if (p_ptr->is_dead) quit("Already dead.");
-        }
+       {
+               if (enter_wizard_mode()) p_ptr->wizard = TRUE;
+               else if (p_ptr->is_dead) quit("Already dead.");
+       }
 
        /* Initialize the town-buildings if necessary */
        if (!dun_level && !p_ptr->inside_quest)
        {
                /* Init the wilderness */
 
-process_dungeon_file("w_info_j.txt", 0, 0, max_wild_y, max_wild_x);
+               process_dungeon_file("w_info.txt", 0, 0, max_wild_y, max_wild_x);
 
                /* Init the town */
                init_flags = INIT_ONLY_BUILDINGS;
 
-process_dungeon_file("t_info_j.txt", 0, 0, MAX_HGT, MAX_WID);
+               process_dungeon_file("t_info.txt", 0, 0, MAX_HGT, MAX_WID);
 
        }
 
 
-       /* Initialize vault info */
-#ifdef JP
-if (init_v_info()) quit("·úÃÛʪ½é´ü²½ÉÔǽ");
-#else
-       if (init_v_info()) quit("Cannot initialize vaults");
-#endif
-
        /* Generate a dungeon level if needed */
-       if (!character_dungeon) generate_cave();
+       if (!character_dungeon) change_floor();
 
 
        /* Character is now "complete" */
@@ -6629,18 +6991,11 @@ if (init_v_info()) quit("
                /* Process the level */
                dungeon(load_game);
 
-               /* Notice stuff */
-               if (p_ptr->notice) notice_stuff();
-
-               /* Update stuff */
-               if (p_ptr->update) update_stuff();
-
-               /* Redraw stuff */
-               if (p_ptr->redraw) redraw_stuff();
-
-               /* Window stuff */
-               if (p_ptr->window) window_stuff();
+               /* Handle "p_ptr->notice" */
+               notice_stuff();
 
+               /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
+               handle_stuff();
 
                /* Cancel the target */
                target_who = 0;
@@ -6677,10 +7032,10 @@ if (init_v_info()) quit("
                        if (p_ptr->inside_arena)
                        {
                                p_ptr->inside_arena = FALSE;
-                               if(p_ptr->arena_number > MAX_ARENA_MONS)
+                               if (p_ptr->arena_number > MAX_ARENA_MONS)
                                        p_ptr->arena_number++;
                                else
-                                       p_ptr->arena_number = 99;
+                                       p_ptr->arena_number = -1 - p_ptr->arena_number;
                                p_ptr->is_dead = FALSE;
                                p_ptr->chp = 0;
                                p_ptr->chp_frac = 0;
@@ -6765,6 +7120,14 @@ msg_print("ĥ
                                                p_ptr->redraw |= (PR_STATUS);
                                        }
 
+                                       /* Hack -- cancel alter */
+                                       if (p_ptr->alter_reality)
+                                       {
+                                               /* Hack -- Prevent alter */
+                                               p_ptr->alter_reality = 0;
+                                               p_ptr->redraw |= (PR_STATUS);
+                                       }
+
                                        /* Note cause of death XXX XXX XXX */
 #ifdef JP
 (void)strcpy(p_ptr->died_from, "»à¤Îµ½¤­");
@@ -6823,7 +7186,7 @@ msg_print("ĥ
                if (p_ptr->is_dead) break;
 
                /* Make a new level */
-               generate_cave();
+               change_floor();
        }
 
        /* Close stuff */
@@ -6835,11 +7198,14 @@ msg_print("ĥ
 
 s32b turn_real(s32b hoge)
 {
-       if ((p_ptr->prace == RACE_VAMPIRE) ||
-           (p_ptr->prace == RACE_SKELETON) ||
-           (p_ptr->prace == RACE_ZOMBIE) ||
-           (p_ptr->prace == RACE_SPECTRE))
-               return hoge-(TURNS_PER_TICK * TOWN_DAWN *3/ 4);
-       else
+       switch (p_ptr->start_race)
+       {
+       case RACE_VAMPIRE:
+       case RACE_SKELETON:
+       case RACE_ZOMBIE:
+       case RACE_SPECTRE:
+               return hoge - (TURNS_PER_TICK * TOWN_DAWN * 3 / 4);
+       default:
                return hoge;
+       }
 }