OSDN Git Service

Leon氏の勧めに従って、Vanillaのコードと同様に各ソースファイルの頭の
[hengband/hengband.git] / src / dungeon.c
index f9c2abe..c987c6b 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,7 +204,8 @@ o_name, index_to_label(slot),game_inscriptions[feel]);
        /* Auto-inscription/destroy */
        idx = is_autopick(o_ptr);
        auto_inscribe_item(slot, idx);
-       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);
@@ -437,6 +444,7 @@ static void sense_inventory1(void)
                        case TV_SOFT_ARMOR:
                        case TV_HARD_ARMOR:
                        case TV_DRAG_ARMOR:
+                       case TV_CARD:
                        {
                                okay = TRUE;
                                break;
@@ -616,10 +624,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
@@ -671,6 +679,7 @@ msg_format("%d 
 
        /* Change level */
        dun_level = command_arg;
+       prepare_change_floor_mode(CFM_CLEAR_ALL);
 
        leave_quest_check();
 
@@ -1147,6 +1156,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);
@@ -1173,7 +1185,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 */
@@ -1251,6 +1264,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);
 }
@@ -1258,97 +1306,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;
-        }
+       }
 }
 
 /*
@@ -1377,15 +1426,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;
@@ -1399,14 +1449,14 @@ else msg_format("%s
 
 static void check_music(void)
 {
-        magic_type *s_ptr;
+       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;
+       /* 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]];
+       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)
@@ -1414,14 +1464,14 @@ static void check_music(void)
        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();
+       shouhimana *= 0x8000;
+       if (((u16b)(p_ptr->csp) < (shouhimana / 0x10000)) || (p_ptr->anti_magic))
+       {
+               stop_singing();
                return;
-        }
-        else
-        {
+       }
+       else
+       {
                        p_ptr->csp -= (u16b) (shouhimana / 0x10000);
                        shouhimana = (shouhimana & 0xffff);
                        if (p_ptr->csp_frac < shouhimana)
@@ -1434,7 +1484,7 @@ static void check_music(void)
                        p_ptr->csp_frac -= (u16b)shouhimana;
                }
 
-                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];
@@ -1452,7 +1502,7 @@ static void check_music(void)
                        /* Redraw status bar */
                        p_ptr->redraw |= (PR_STATUS);
                }
-        }
+       }
        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)
@@ -1462,7 +1512,7 @@ static void check_music(void)
        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;}
 
-        gere_music(p_ptr->magic_num1[0]);
+       gere_music(p_ptr->magic_num1[0]);
 }
 
 /* Choose one of items that have cursed flag */
@@ -1515,7 +1565,7 @@ static void process_world(void)
        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)
+       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))
@@ -1660,14 +1710,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) ***/
 
@@ -1741,7 +1791,7 @@ msg_print("
                                                    (y == 0) || (y == cur_hgt-1))
                                                {
                                                        /* Forget the grid */
-                                                       if (!(c_ptr->info & CAVE_IN_MIRROR)) c_ptr->info &= ~(CAVE_GLOW | CAVE_MARK);
+                                                       if (!is_mirror_grid(c_ptr)) c_ptr->info &= ~(CAVE_GLOW | CAVE_MARK);
 
                                                        /* Hack -- Notice spot */
                                                        note_spot(y, x);
@@ -1789,7 +1839,7 @@ 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 */
@@ -2222,8 +2272,8 @@ take_hit(DAMAGE_NOESCAPE, i, "
                        {
                                /* 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]));
+                               ((p_ptr->pspeed > 199) ? 49 : ((p_ptr->pspeed < 0) ?
+                               1 : extract_energy[p_ptr->pspeed]));
 
                                /* Regeneration takes more food */
                                if (p_ptr->regenerate) i += 20;
@@ -3357,7 +3407,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)
@@ -3394,7 +3444,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;
@@ -3711,7 +3762,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)
@@ -3722,12 +3773,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();
 
@@ -3742,7 +3794,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);
@@ -3781,6 +3833,8 @@ msg_print("
                                }
                                p_ptr->wild_mode = FALSE;
 
+                               prepare_change_floor_mode(CFM_CLEAR_ALL);
+
                                /* Leaving */
                                p_ptr->leaving = TRUE;
 
@@ -3804,6 +3858,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);
+               }
+       }
 }
 
 
@@ -3816,6 +3916,17 @@ 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("¥¦¥£¥¶¡¼¥É¥â¡¼¥É¤Ï¥Ç¥Ð¥°¤È¼Â¸³¤Î¤¿¤á¤Î¥â¡¼¥É¤Ç¤¹¡£ ");
@@ -3857,6 +3968,17 @@ 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("¥Ç¥Ð¥°¡¦¥³¥Þ¥ó¥É¤Ï¥Ç¥Ð¥°¤È¼Â¸³¤Î¤¿¤á¤Î¥³¥Þ¥ó¥É¤Ç¤¹¡£ ");
@@ -4238,37 +4360,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;
                }
@@ -4276,14 +4398,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 */
@@ -4907,7 +5029,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
@@ -5020,7 +5142,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);
                        }
@@ -5238,6 +5361,7 @@ msg_format("%^s
                        }
                }
 
+               /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
                handle_stuff();
        }
 
@@ -5310,18 +5434,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);
@@ -5372,17 +5489,11 @@ msg_format("%s(%c)
                        inven_item_describe(item);
                        inven_item_optimize(item);
 
-                       /* Notice stuff (if needed) */
-                       if (p_ptr->notice) notice_stuff();
-
-                       /* Update stuff (if needed) */
-                       if (p_ptr->update) update_stuff();
+                       /* Handle "p_ptr->notice" */
+                       notice_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();
                }
 
 
@@ -5399,7 +5510,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();
@@ -5489,10 +5600,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);
@@ -5629,6 +5746,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();
                        }
                }
@@ -5657,7 +5775,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;
@@ -5719,47 +5837,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();
 
@@ -5774,10 +5851,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);
@@ -5785,33 +5859,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();
+       /* Update lite/view */
+       p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE | PU_TORCH);
 
-       /* Redraw stuff */
-       redraw_stuff();
+       /* Update monsters */
+       p_ptr->update |= (PU_MONSTERS | PU_DISTANCE | PU_FLOW);
 
-       /* 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 stuff */
-       update_stuff();
-
-       /* Redraw stuff */
-       redraw_stuff();
+       /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
+       handle_stuff();
 
        /* Leave "xtra" mode */
        character_xtra = FALSE;
@@ -5822,17 +5880,11 @@ 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();
@@ -5904,8 +5956,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);
 
@@ -5923,28 +5973,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++;
-               }
+               /* Handle "p_ptr->notice" */
+               notice_stuff();
 
-               /* Update stuff */
-               if (p_ptr->update) update_stuff();
-
-               /* Redraw stuff */
-               if (p_ptr->redraw) redraw_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);
@@ -5958,17 +5991,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);
@@ -5983,17 +6010,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);
@@ -6024,56 +6045,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;
 }
 
@@ -6123,9 +6105,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);
@@ -6272,7 +6254,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);
@@ -6326,6 +6308,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 */
@@ -6488,32 +6480,8 @@ quit("
        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;
-        }
+       /* Fill the arrays of floors and walls in the good proportions */
+       set_floor_and_wall(dungeon_type);
 
        /* Flavor the objects */
        flavor_init();
@@ -6536,19 +6504,23 @@ prt("
 
 
        /* Hack -- Enter wizard mode */
-       if (arg_wizard && enter_wizard_mode()) p_ptr->wizard = TRUE;
+       if (arg_wizard)
+       {
+               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);
 
        }
 
@@ -6561,7 +6533,7 @@ if (init_v_info()) quit("
 #endif
 
        /* Generate a dungeon level if needed */
-       if (!character_dungeon) generate_cave();
+       if (!character_dungeon) change_floor();
 
 
        /* Character is now "complete" */
@@ -6624,18 +6596,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;
@@ -6760,6 +6725,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, "»à¤Îµ½¤­");
@@ -6818,7 +6791,7 @@ msg_print("ĥ
                if (p_ptr->is_dead) break;
 
                /* Make a new level */
-               generate_cave();
+               change_floor();
        }
 
        /* Close stuff */