OSDN Git Service

経験値を吸い取る能力(TRC_DRAIN_EXP)がアンドロイドの強化度も吸い取って不気味だったので、アンドロイドでは無効になるように修正。
[hengbandforosx/hengbandosx.git] / src / dungeon.c
index 4898a85..955eeea 100644 (file)
@@ -12,7 +12,7 @@
 
 #include "angband.h"
 
-#define TY_CURSE_CHANCE 100
+#define TY_CURSE_CHANCE 200
 #define CHAINSWORD_NOISE 100
 
 static bool load = TRUE;
@@ -96,6 +96,7 @@ static void sense_inventory_aux(int slot, bool heavy)
        byte        feel;
        object_type *o_ptr = &inventory[slot];
        char        o_name[MAX_NLEN];
+       int idx;
 
        /* We know about it already, do not tell us again */
        if (o_ptr->ident & (IDENT_SENSE))return;
@@ -110,7 +111,7 @@ static void sense_inventory_aux(int slot, bool heavy)
        if (!feel) return;
 
        /* Bad luck */
-       if ((p_ptr->muta3 & MUT3_BAD_LUCK) && !rand_int(13))
+       if ((p_ptr->muta3 & MUT3_BAD_LUCK) && !randint0(13))
        {
                switch (feel)
                {
@@ -126,17 +127,17 @@ static void sense_inventory_aux(int slot, bool heavy)
                        }
                        case FEEL_CURSED:
                        {
-                               feel = rand_int(3) ? FEEL_GOOD : FEEL_AVERAGE;
+                               feel = randint0(3) ? FEEL_GOOD : FEEL_AVERAGE;
                                break;
                        }
                        case FEEL_AVERAGE:
                        {
-                               feel = rand_int(2) ? FEEL_CURSED : FEEL_GOOD;
+                               feel = randint0(2) ? FEEL_CURSED : FEEL_GOOD;
                                break;
                        }
                        case FEEL_GOOD:
                        {
-                               feel = rand_int(3) ? FEEL_CURSED : FEEL_AVERAGE;
+                               feel = randint0(3) ? FEEL_CURSED : FEEL_AVERAGE;
                                break;
                        }
                        case FEEL_EXCELLENT:
@@ -194,6 +195,12 @@ o_name, index_to_label(slot),game_inscriptions[feel]);
        /* Set the "inscription" */
        o_ptr->feeling = feel;
 
+       /* Auto-inscription/destroy */
+       idx = is_autopick(o_ptr);
+       auto_inscribe_item(slot, idx);
+        if (destroy_feeling)
+                auto_destroy_item(slot, idx, FALSE);
+
        /* Combine / Reorder the pack (later) */
        p_ptr->notice |= (PN_COMBINE | PN_REORDER);
 
@@ -220,197 +227,180 @@ static void sense_inventory1(void)
        bool        heavy = FALSE;
        object_type *o_ptr;
 
-#ifdef USE_SCRIPT
-       int         result;
-#endif /* USE_SCRIPT */
-
 
        /*** Check for "sensing" ***/
 
        /* No sensing when confused */
        if (p_ptr->confused) return;
 
-#ifdef USE_SCRIPT
-
-       result = sense_inventory_callback();
-
-       if (result == -1)
-               heavy = TRUE;
-
-       if (!result)
-
-#endif /* USE_SCRIPT */
-
+       /* Analyze the class */
+       switch (p_ptr->pclass)
        {
-               /* Analyze the class */
-               switch (p_ptr->pclass)
+               case CLASS_WARRIOR:
+               case CLASS_ARCHER:
+               case CLASS_SAMURAI:
+               case CLASS_CAVALRY:
                {
-                       case CLASS_WARRIOR:
-                       case CLASS_ARCHER:
-                       case CLASS_SAMURAI:
-                       case CLASS_CAVALRY:
-                       {
-                               /* Good sensing */
-                               if (0 != rand_int(9000L / (plev * plev + 40))) return;
+                       /* Good sensing */
+                       if (0 != randint0(9000L / (plev * plev + 40))) return;
 
-                               /* Heavy sensing */
-                               heavy = TRUE;
+                       /* Heavy sensing */
+                       heavy = TRUE;
 
-                               /* Done */
-                               break;
-                       }
+                       /* Done */
+                       break;
+               }
 
-                       case CLASS_SMITH:
-                       {
-                               /* Good sensing */
-                               if (0 != rand_int(6000L / (plev * plev + 50))) return;
+               case CLASS_SMITH:
+               {
+                       /* Good sensing */
+                       if (0 != randint0(6000L / (plev * plev + 50))) return;
 
-                               /* Heavy sensing */
-                               heavy = TRUE;
+                       /* Heavy sensing */
+                       heavy = TRUE;
 
-                               /* Done */
-                               break;
-                       }
+                       /* Done */
+                       break;
+               }
 
-                       case CLASS_MAGE:
-                       case CLASS_HIGH_MAGE:
-                       case CLASS_SORCERER:
-                       case CLASS_MAGIC_EATER:
-                       {
-                               /* Very bad (light) sensing */
-                               if (0 != rand_int(240000L / (plev + 5))) return;
+               case CLASS_MAGE:
+               case CLASS_HIGH_MAGE:
+               case CLASS_SORCERER:
+               case CLASS_MAGIC_EATER:
+               {
+                       /* Very bad (light) sensing */
+                       if (0 != randint0(240000L / (plev + 5))) return;
 
-                               /* Done */
-                               break;
-                       }
+                       /* Done */
+                       break;
+               }
 
-                       case CLASS_PRIEST:
-                       case CLASS_BARD:
-                       {
-                               /* Good (light) sensing */
-                               if (0 != rand_int(10000L / (plev * plev + 40))) return;
+               case CLASS_PRIEST:
+               case CLASS_BARD:
+               {
+                       /* Good (light) sensing */
+                       if (0 != randint0(10000L / (plev * plev + 40))) return;
 
-                               /* Done */
-                               break;
-                       }
+                       /* Done */
+                       break;
+               }
 
-                       case CLASS_ROGUE:
-                       case CLASS_NINJA:
-                       {
-                               /* Okay sensing */
-                               if (0 != rand_int(20000L / (plev * plev + 40))) return;
+               case CLASS_ROGUE:
+               case CLASS_NINJA:
+               {
+                       /* Okay sensing */
+                       if (0 != randint0(20000L / (plev * plev + 40))) return;
 
-                               /* Heavy sensing */
-                               heavy = TRUE;
+                       /* Heavy sensing */
+                       heavy = TRUE;
 
-                               /* Done */
-                               break;
-                       }
+                       /* Done */
+                       break;
+               }
 
-                       case CLASS_RANGER:
-                       {
-                               /* Bad sensing */
-                               if (0 != rand_int(95000L / (plev * plev + 40))) return;
+               case CLASS_RANGER:
+               {
+                       /* Bad sensing */
+                       if (0 != randint0(95000L / (plev * plev + 40))) return;
 
-                               /* Changed! */
-                               heavy = TRUE;
+                       /* Changed! */
+                       heavy = TRUE;
 
-                               /* Done */
-                               break;
-                       }
+                       /* Done */
+                       break;
+               }
 
-                       case CLASS_PALADIN:
-                       {
-                               /* Bad sensing */
-                               if (0 != rand_int(77777L / (plev * plev + 40))) return;
+               case CLASS_PALADIN:
+               {
+                       /* Bad sensing */
+                       if (0 != randint0(77777L / (plev * plev + 40))) return;
 
-                               /* Heavy sensing */
-                               heavy = TRUE;
+                       /* Heavy sensing */
+                       heavy = TRUE;
 
-                               /* Done */
-                               break;
-                       }
+                       /* Done */
+                       break;
+               }
 
-                       case CLASS_WARRIOR_MAGE:
-                       case CLASS_RED_MAGE:
-                       {
-                               /* Bad sensing */
-                               if (0 != rand_int(75000L / (plev * plev + 40))) return;
+               case CLASS_WARRIOR_MAGE:
+               case CLASS_RED_MAGE:
+               {
+                       /* Bad sensing */
+                       if (0 != randint0(75000L / (plev * plev + 40))) return;
 
-                               /* Done */
-                               break;
-                       }
+                       /* Done */
+                       break;
+               }
 
-                       case CLASS_MINDCRAFTER:
-                       case CLASS_MIRROR_MASTER:
-                       {
-                               /* Bad sensing */
-                               if (0 != rand_int(55000L / (plev * plev + 40))) return;
+               case CLASS_MINDCRAFTER:
+               case CLASS_MIRROR_MASTER:
+               {
+                       /* Bad sensing */
+                       if (0 != randint0(55000L / (plev * plev + 40))) return;
 
-                               /* Done */
-                               break;
-                       }
+                       /* Done */
+                       break;
+               }
 
-                       case CLASS_CHAOS_WARRIOR:
-                       {
-                               /* Bad sensing */
-                               if (0 != rand_int(80000L / (plev * plev + 40))) return;
+               case CLASS_CHAOS_WARRIOR:
+               {
+                       /* Bad sensing */
+                       if (0 != randint0(80000L / (plev * plev + 40))) return;
 
-                               /* Changed! */
-                               heavy = TRUE;
+                       /* Changed! */
+                       heavy = TRUE;
 
-                               /* Done */
-                               break;
-                       }
+                       /* Done */
+                       break;
+               }
 
-                       case CLASS_MONK:
-                       case CLASS_FORCETRAINER:
-                       {
-                               /* Okay sensing */
-                               if (0 != rand_int(20000L / (plev * plev + 40))) return;
+               case CLASS_MONK:
+               case CLASS_FORCETRAINER:
+               {
+                       /* Okay sensing */
+                       if (0 != randint0(20000L / (plev * plev + 40))) return;
 
-                               /* Done */
-                               break;
-                       }
+                       /* Done */
+                       break;
+               }
 
-                       case CLASS_TOURIST:
-                       {
-                               /* Good sensing */
-                               if (0 != rand_int(20000L / ((plev+50)*(plev+50)))) return;
+               case CLASS_TOURIST:
+               {
+                       /* Good sensing */
+                       if (0 != randint0(20000L / ((plev+50)*(plev+50)))) return;
 
-                               /* Heavy sensing */
-                               heavy = TRUE;
+                       /* Heavy sensing */
+                       heavy = TRUE;
 
-                               /* Done */
-                               break;
-                       }
+                       /* Done */
+                       break;
+               }
 
-                       case CLASS_IMITATOR:
-                       case CLASS_BLUE_MAGE:
-                       {
-                               /* Bad sensing */
-                               if (0 != rand_int(55000L / (plev * plev + 40))) return;
+               case CLASS_IMITATOR:
+               case CLASS_BLUE_MAGE:
+               {
+                       /* Bad sensing */
+                       if (0 != randint0(55000L / (plev * plev + 40))) return;
 
-                               /* Done */
-                               break;
-                       }
+                       /* Done */
+                       break;
+               }
 
-                       case CLASS_BEASTMASTER:
-                       {
-                               /* Bad sensing */
-                               if (0 != rand_int(65000L / (plev * plev + 40))) return;
+               case CLASS_BEASTMASTER:
+               {
+                       /* Bad sensing */
+                       if (0 != randint0(65000L / (plev * plev + 40))) return;
 
-                               /* Done */
-                               break;
-                       }
-                       case CLASS_BERSERKER:
-                       {
-                               /* Heavy sensing */
-                               heavy = TRUE;
+                       /* Done */
+                       break;
+               }
+               case CLASS_BERSERKER:
+               {
+                       /* Heavy sensing */
+                       heavy = TRUE;
 
-                               /* Done */
-                               break;
-                       }
+                       /* Done */
+                       break;
                }
        }
 
@@ -458,10 +448,10 @@ static void sense_inventory1(void)
                if (!okay) continue;
 
                /* Occasional failure on inventory items */
-               if ((i < INVEN_RARM) && (0 != rand_int(5))) continue;
+               if ((i < INVEN_RARM) && (0 != randint0(5))) continue;
 
                /* Good luck */
-               if ((p_ptr->muta3 & MUT3_GOOD_LUCK) && !rand_int(13))
+               if ((p_ptr->muta3 & MUT3_GOOD_LUCK) && !randint0(13))
                {
                        heavy = TRUE;
                }
@@ -477,98 +467,84 @@ static void sense_inventory2(void)
        int         plev = p_ptr->lev;
        object_type *o_ptr;
 
-#ifdef USE_SCRIPT
-       int         result;
-#endif /* USE_SCRIPT */
-
 
        /*** Check for "sensing" ***/
 
        /* No sensing when confused */
        if (p_ptr->confused) return;
 
-#ifdef USE_SCRIPT
-
-       result = sense_inventory_callback();
-
-       if (!result)
-
-#endif /* USE_SCRIPT */
-
+       /* Analyze the class */
+       switch (p_ptr->pclass)
        {
-               /* Analyze the class */
-               switch (p_ptr->pclass)
+               case CLASS_WARRIOR:
+               case CLASS_ARCHER:
+               case CLASS_SAMURAI:
+               case CLASS_CAVALRY:
+               case CLASS_BERSERKER:
                {
-                       case CLASS_WARRIOR:
-                       case CLASS_ARCHER:
-                       case CLASS_SAMURAI:
-                       case CLASS_CAVALRY:
-                       case CLASS_BERSERKER:
-                       {
-                               return;
-                       }
+                       return;
+               }
 
-                       case CLASS_SMITH:
-                       case CLASS_PALADIN:
-                       case CLASS_CHAOS_WARRIOR:
-                       case CLASS_IMITATOR:
-                       case CLASS_BEASTMASTER:
-                       case CLASS_NINJA:
-                       {
-                               /* Very bad (light) sensing */
-                               if (0 != rand_int(240000L / (plev + 5))) return;
+               case CLASS_SMITH:
+               case CLASS_PALADIN:
+               case CLASS_CHAOS_WARRIOR:
+               case CLASS_IMITATOR:
+               case CLASS_BEASTMASTER:
+               case CLASS_NINJA:
+               {
+                       /* Very bad (light) sensing */
+                       if (0 != randint0(240000L / (plev + 5))) return;
 
-                               /* Done */
-                               break;
-                       }
+                       /* Done */
+                       break;
+               }
 
-                       case CLASS_RANGER:
-                       case CLASS_WARRIOR_MAGE:
-                       case CLASS_RED_MAGE:
-                       case CLASS_MONK:
-                       {
-                               /* Bad sensing */
-                               if (0 != rand_int(95000L / (plev * plev + 40))) return;
+               case CLASS_RANGER:
+               case CLASS_WARRIOR_MAGE:
+               case CLASS_RED_MAGE:
+               case CLASS_MONK:
+               {
+                       /* Bad sensing */
+                       if (0 != randint0(95000L / (plev * plev + 40))) return;
 
-                               /* Done */
-                               break;
-                       }
+                       /* Done */
+                       break;
+               }
 
-                       case CLASS_PRIEST:
-                       case CLASS_BARD:
-                       case CLASS_ROGUE:
-                       case CLASS_FORCETRAINER:
-                       case CLASS_MINDCRAFTER:
-                       {
-                               /* Good sensing */
-                               if (0 != rand_int(20000L / (plev * plev + 40))) return;
+               case CLASS_PRIEST:
+               case CLASS_BARD:
+               case CLASS_ROGUE:
+               case CLASS_FORCETRAINER:
+               case CLASS_MINDCRAFTER:
+               {
+                       /* Good sensing */
+                       if (0 != randint0(20000L / (plev * plev + 40))) return;
 
-                               /* Done */
-                               break;
-                       }
+                       /* Done */
+                       break;
+               }
 
-                       case CLASS_MAGE:
-                       case CLASS_HIGH_MAGE:
-                       case CLASS_SORCERER:
-                       case CLASS_MAGIC_EATER:
-                       case CLASS_MIRROR_MASTER:
-                       case CLASS_BLUE_MAGE:
-                       {
-                               /* Good sensing */
-                               if (0 != rand_int(9000L / (plev * plev + 40))) return;
+               case CLASS_MAGE:
+               case CLASS_HIGH_MAGE:
+               case CLASS_SORCERER:
+               case CLASS_MAGIC_EATER:
+               case CLASS_MIRROR_MASTER:
+               case CLASS_BLUE_MAGE:
+               {
+                       /* Good sensing */
+                       if (0 != randint0(9000L / (plev * plev + 40))) return;
 
-                               /* Done */
-                               break;
-                       }
+                       /* Done */
+                       break;
+               }
 
-                       case CLASS_TOURIST:
-                       {
-                               /* Good sensing */
-                               if (0 != rand_int(20000L / ((plev+50)*(plev+50)))) return;
+               case CLASS_TOURIST:
+               {
+                       /* Good sensing */
+                       if (0 != randint0(20000L / ((plev+50)*(plev+50)))) return;
 
-                               /* Done */
-                               break;
-                       }
+                       /* Done */
+                       break;
                }
        }
 
@@ -601,7 +577,7 @@ static void sense_inventory2(void)
                if (!okay) continue;
 
                /* Occasional failure on inventory items */
-               if ((i < INVEN_RARM) && (0 != rand_int(5))) continue;
+               if ((i < INVEN_RARM) && (0 != randint0(5))) continue;
 
                sense_inventory_aux(i, TRUE);
        }
@@ -640,7 +616,11 @@ if (get_check("¾
                        else if (dun_level == 100)
                                max_level = 100;
                }
-               else max_level = d_info[dungeon_type].maxdepth;
+               else
+                {
+                        max_level = d_info[dungeon_type].maxdepth;
+                        min_level = d_info[dungeon_type].mindepth;
+                }
 
                /* Prompt */
 #ifdef JP
@@ -693,6 +673,14 @@ msg_format("%d 
        /* Change level */
        dun_level = command_arg;
 
+       leave_quest_check();
+
+       if (record_stair) do_cmd_write_nikki(NIKKI_PAT_TELE,0,NULL);
+
+       p_ptr->inside_quest = 0;
+       p_ptr->leftbldg = FALSE;
+       energy_use = 0;
+
        /* Leaving */
        p_ptr->leaving = TRUE;
 }
@@ -725,7 +713,7 @@ take_hit(DAMAGE_NOESCAPE, damroll(10, 8), "
 #endif
 
 
-       to_ruin = randint(45) + 35;
+       to_ruin = randint1(45) + 35;
 
        while (to_ruin--)
        {
@@ -750,7 +738,7 @@ static bool pattern_effect(void)
                return FALSE;
 
        if ((prace_is_(RACE_AMBERITE)) &&
-           (p_ptr->cut > 0) && (randint(10) == 1))
+           (p_ptr->cut > 0) && one_in_(10))
        {
                wreck_the_pattern();
        }
@@ -808,7 +796,7 @@ take_hit(DAMAGE_NOESCAPE, 200, "
        }
        else
        {
-               if ((prace_is_(RACE_AMBERITE)) && (randint(2) != 1))
+               if ((prace_is_(RACE_AMBERITE)) && !one_in_(2))
                        return TRUE;
                else if (!p_ptr->invuln)
 #ifdef JP
@@ -894,10 +882,8 @@ static void regenmana(int percent)
        {
                new_mana *= 32;
                p_ptr->csp--;
-               p_ptr->csp_frac += 0x10000L;
-
                p_ptr->csp -= (s16b)(new_mana >> 16);   /* div 65536 */
-               new_mana_frac = p_ptr->csp_frac - (new_mana & 0xFFFF);
+               new_mana_frac = p_ptr->csp_frac + 0x10000L - (new_mana & 0xFFFF);
        }
        else
        {
@@ -954,7 +940,7 @@ static void regenmagic(int percent)
        s32b        new_mana;
        int i;
 
-       for (i = 0; i < 72; i++)
+       for (i = 0; i < EATER_EXT*2; i++)
        {
                if (!p_ptr->magic_num2[i]) continue;
                if (p_ptr->magic_num1[i] == ((long)p_ptr->magic_num2[i] << 16)) continue;
@@ -968,11 +954,11 @@ static void regenmagic(int percent)
                }
                wild_regen = 20;
        }
-       for (i = 72; i < 108; i++)
+       for (i = EATER_EXT*2; i < EATER_EXT*3; i++)
        {
                if (!p_ptr->magic_num1[i]) continue;
                if (!p_ptr->magic_num2[i]) continue;
-               p_ptr->magic_num1[i] -= (long)(p_ptr->magic_num2[i] * (adj_mag_mana[A_INT] + 10)) * 0x1000;
+               p_ptr->magic_num1[i] -= (long)(p_ptr->magic_num2[i] * (adj_mag_mana[A_INT] + 10)) * EATER_ROD_CHARGE/16;
                if (p_ptr->magic_num1[i] < 0) p_ptr->magic_num1[i] = 0;
                wild_regen = 20;
        }
@@ -1011,7 +997,7 @@ static void regen_monsters(void)
                        frac = m_ptr->maxhp / 100;
 
                        /* Hack -- Minimal regeneration rate */
-                       if (!frac) if (randint(2) == 1) frac = 1;
+                       if (!frac) if (one_in_(2)) frac = 1;
 
                        /* Hack -- Some monsters regenerate quickly */
                        if (r_ptr->flags2 & RF2_REGENERATE) frac *= 2;
@@ -1061,7 +1047,7 @@ static void regen_captured_monsters(void)
                        frac = o_ptr->xtra5 / 100;
 
                        /* Hack -- Minimal regeneration rate */
-                       if (!frac) if (randint(2) == 1) frac = 1;
+                       if (!frac) if (one_in_(2)) frac = 1;
 
                        /* Hack -- Some monsters regenerate quickly */
                        if (r_ptr->flags2 & RF2_REGENERATE) frac *= 2;
@@ -1118,7 +1104,8 @@ msg_print("
        /* The light is getting dim */
        else if (o_ptr->name2 == EGO_LITE_LONG)
        {
-               if ((o_ptr->xtra4 < 50) && (!(o_ptr->xtra4 % 5)) && (turn % 40))
+               if ((o_ptr->xtra4 < 50) && (!(o_ptr->xtra4 % 5))
+                   && (turn % (TURNS_PER_TICK*2)))
                {
                        if (disturb_minor) disturb(0, 0);
 #ifdef JP
@@ -1144,6 +1131,30 @@ msg_print("
 }
 
 
+void leave_quest_check(void)
+{
+       /* Save quset number for dungeon pref file ($LEAVING_QUEST) */
+       leaving_quest = p_ptr->inside_quest;
+
+       /* Leaving an 'only once' quest marks it as failed */
+       if (leaving_quest &&
+           ((quest[leaving_quest].flags & QUEST_FLAG_ONCE)  || (quest[leaving_quest].type == QUEST_TYPE_RANDOM)) &&
+           (quest[leaving_quest].status == QUEST_STATUS_TAKEN))
+       {
+               quest[leaving_quest].status = QUEST_STATUS_FAILED;
+               quest[leaving_quest].complev = (byte)p_ptr->lev;
+               if (quest[leaving_quest].type == QUEST_TYPE_RANDOM)
+               {
+                       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);
+               }
+               else if (record_fix_quest)
+                       do_cmd_write_nikki(NIKKI_FIX_QUEST_F, leaving_quest, NULL);
+       }
+}
+
+
 /*
  * Forcibly pseudo-identify an object in the inventory
  * (or on the floor)
@@ -1246,7 +1257,7 @@ msg_format("%s
 }
 
 
-static void gere_music(s16b music)
+static void gere_music(s32b music)
 {
         switch(music)
         {
@@ -1263,7 +1274,7 @@ static void gere_music(s16b music)
                         project_hack(GF_TURN_ALL, p_ptr->lev);
                         break;
                 case MUSIC_PSI:
-                        project_hack(GF_PSI, randint(p_ptr->lev * 3 / 2));
+                        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);
@@ -1282,8 +1293,8 @@ static void gere_music(s16b music)
                                0, GF_DISINTEGRATE, PROJECT_KILL | PROJECT_ITEM | PROJECT_HIDE, -1);
                         break;
                 case MUSIC_DISPEL:
-                        dispel_monsters(randint(p_ptr->lev * 3));
-                        dispel_evil(randint(p_ptr->lev * 3));
+                        dispel_monsters(randint1(p_ptr->lev * 3));
+                        dispel_evil(randint1(p_ptr->lev * 3));
                         break;
                 case MUSIC_SARUMAN:
                         slow_monsters();
@@ -1296,7 +1307,7 @@ static void gere_music(s16b music)
                         stasis_monsters(p_ptr->lev * 4);
                         break;
                 case MUSIC_SHERO:
-                        dispel_monsters(randint(p_ptr->lev * 3));
+                        dispel_monsters(randint1(p_ptr->lev * 3));
                         break;
                 case MUSIC_H_LIFE:
                         hp_player(damroll(15,10));
@@ -1333,7 +1344,7 @@ static void gere_music(s16b music)
                 case MUSIC_DETECT:
                 case MUSIC_DETECT+1:
                 case MUSIC_DETECT+2:
-                       detect_traps(DETECT_RAD_DEFAULT);
+                       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;
@@ -1387,46 +1398,53 @@ else msg_format("%s
 }
 
 
-static void check_music()
+static void check_music(void)
 {
         magic_type *s_ptr;
-       int shouhimana;
+       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 - 1][p_ptr->magic_num2[0]];
+        s_ptr = &technic_info[REALM_MUSIC - MIN_TECHNIC][p_ptr->magic_num2[0]];
 
-       shouhimana = (s_ptr->smana*(3800-spell_exp[p_ptr->magic_num2[0]])+2399);
+       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 ((p_ptr->csp < shouhimana / 0x10000) || (p_ptr->anti_magic))
+        if (((u16b)(p_ptr->csp) < (shouhimana / 0x10000)) || (p_ptr->anti_magic))
         {
                 stop_singing();
                return;
         }
         else
         {
-                p_ptr->csp -= shouhimana / 0x10000;
-               shouhimana = (shouhimana % 0x10000);
-               if (p_ptr->csp_frac < shouhimana)
+                       p_ptr->csp -= (u16b) (shouhimana / 0x10000);
+                       shouhimana = (shouhimana & 0xffff);
+                       if (p_ptr->csp_frac < shouhimana)
                {
                        p_ptr->csp--;
-                       p_ptr->csp_frac += 0x10000;
+                       p_ptr->csp_frac += (u16b)(0x10000L - shouhimana);
+               }
+               else
+               {
+                       p_ptr->csp_frac -= (u16b)shouhimana;
                }
-               p_ptr->csp_frac -= shouhimana;
 
                 p_ptr->redraw |= PR_MANA;
                if (p_ptr->magic_num1[1])
                {
                        p_ptr->magic_num1[0] = p_ptr->magic_num1[1];
                        p_ptr->magic_num1[1] = 0;
+#ifdef JP
                        msg_print("²Î¤òºÆ³«¤·¤¿¡£");
+#else
+                       msg_print("You restart singing.");
+#endif
                        p_ptr->action = ACTION_SING;
 
                        /* Recalculate bonuses */
@@ -1436,18 +1454,45 @@ static void check_music()
                        p_ptr->redraw |= (PR_STATUS);
                }
         }
-       if (spell_exp[p_ptr->magic_num2[0]] < 900)
-               spell_exp[p_ptr->magic_num2[0]]+=5;
-       else if(spell_exp[p_ptr->magic_num2[0]] < 1200)
-               {if (one_in_(2) && (dun_level > 4) && ((dun_level + 10) > p_ptr->lev)) spell_exp[p_ptr->magic_num2[0]]+=1;}
-       else if(spell_exp[p_ptr->magic_num2[0]] < 1400)
-               {if (one_in_(5) && ((dun_level + 5) > p_ptr->lev) && ((dun_level + 5) > s_ptr->slevel)) spell_exp[p_ptr->magic_num2[0]]+=1;}
-       else if(spell_exp[p_ptr->magic_num2[0]] < 1600)
-               {if (one_in_(5) && ((dun_level + 5) > p_ptr->lev) && (dun_level > s_ptr->slevel)) spell_exp[p_ptr->magic_num2[0]]+=1;}
+       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;}
 
         gere_music(p_ptr->magic_num1[0]);
 }
 
+/* Choose one of items that have cursed flag */
+static object_type *choose_cursed_obj_name(u32b flag)
+{
+       int i;
+       int choices[INVEN_TOTAL-INVEN_RARM];
+       int number = 0;
+
+       /* Paranoia -- Player has no warning-item */
+       if (!(p_ptr->cursed & flag)) return NULL;
+
+       /* Search Inventry */
+       for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
+       {
+               object_type *o_ptr = &inventory[i];
+
+               if (o_ptr->curse_flags & flag)
+               {
+                       choices[number] = i;
+                       number++;
+               }
+       }
+
+       /* Choice one of them */
+       return (&inventory[choices[randint0(number)]]);
+}
+
+
 /*
  * Handle certain things once every 10 game turns
  */
@@ -1459,20 +1504,20 @@ static void process_world(void)
        int upkeep_factor = 0;
        cave_type *c_ptr;
        object_type *o_ptr;
-       u32b f1 = 0 , f2 = 0 , f3 = 0;
        int temp;
        object_kind *k_ptr;
        const int dec_count = (easy_band ? 2 : 1);
 
-       int hour, min, prev_min;
-       s32b len = 20L * TOWN_DAWN;
+       int day, hour, min, prev_min;
+
+       s32b len = TURNS_PER_TICK * TOWN_DAWN;
        s32b tick = turn % len + len / 4;
 
-       hour = (24 * tick / len) % 24;
-       min = (1440 * tick / len) % 60;
-       prev_min = (1440 * (tick - 20) / len) % 60;
+       extract_day_hour_min(&day, &hour, &min);
+       prev_min = (1440 * (tick - TURNS_PER_TICK) / len) % 60;
 
-        if ((turn - old_turn == (3000 - dun_level*20)) && (dun_level) &&
+        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))
                do_cmd_feeling();
@@ -1501,7 +1546,7 @@ msg_print("
                        msg_print("They have kill each other at the same time.");
 #endif
                        msg_print(NULL);
-                       p_ptr->energy = 100;
+                       p_ptr->energy_need = 0;
                        battle_monsters();
                }
                else if ((number_mon-1) == 0)
@@ -1529,7 +1574,7 @@ msg_print("
 #ifdef JP
 msg_format("%d¡ð¤ò¼õ¤±¼è¤Ã¤¿¡£", battle_odds);
 #else
-                               msg_format("You recieved %d gold.", battle_odds);
+                               msg_format("You received %d gold.", battle_odds);
 #endif
                        p_ptr->au += battle_odds;
                        }
@@ -1542,10 +1587,10 @@ msg_print("
 #endif
                        }
                        msg_print(NULL);
-                       p_ptr->energy = 100;
+                       p_ptr->energy_need = 0;
                        battle_monsters();
                }
-               else if(turn - old_turn == 3000L)
+               else if(turn - old_turn == 150*TURNS_PER_TICK)
                {
 #ifdef JP
 msg_print("¿½¤·Ê¬¤±¤¢¤ê¤Þ¤»¤ó¤¬¡¢¤³¤Î¾¡Éé¤Ï°ú¤­Ê¬¤±¤È¤µ¤»¤Æ¤¤¤¿¤À¤­¤Þ¤¹¡£");
@@ -1554,17 +1599,17 @@ msg_print("
 #endif
                        p_ptr->au += kakekin;
                        msg_print(NULL);
-                       p_ptr->energy = 100;
+                       p_ptr->energy_need = 0;
                        battle_monsters();
                }
        }
 
        /* Every 20 game turns */
-       if (turn % 20) return;
+       if (turn % TURNS_PER_TICK) return;
 
        /*** Check the Time and Load ***/
 
-       if (!(turn % 1000))
+       if (!(turn % (50*TURNS_PER_TICK)))
        {
                /* Check time and load */
                if ((0 != check_time()) || (0 != check_load()))
@@ -1601,7 +1646,7 @@ msg_print("
 
 
                                /* Stop playing */
-                               alive = FALSE;
+                               p_ptr->playing = FALSE;
 
                                /* Leaving */
                                p_ptr->leaving = TRUE;
@@ -1612,7 +1657,7 @@ msg_print("
        /*** Attempt timed autosave ***/
        if (autosave_t && autosave_freq && !p_ptr->inside_battle)
        {
-               if (!(turn % ((s32b)autosave_freq * 20)))
+               if (!(turn % ((s32b)autosave_freq * TURNS_PER_TICK)))
                        do_cmd_save_game(TRUE);
        }
 
@@ -1631,12 +1676,12 @@ msg_print("
        if (!dun_level && !p_ptr->inside_quest && !p_ptr->inside_battle && !p_ptr->inside_arena && !p_ptr->wild_mode)
        {
                /* Hack -- Daybreak/Nighfall in town */
-               if (!(turn % ((20L * TOWN_DAWN) / 2)))
+               if (!(turn % ((TURNS_PER_TICK * TOWN_DAWN) / 2)))
                {
                        bool dawn;
 
                        /* Check for dawn */
-                       dawn = (!(turn % (20L * TOWN_DAWN)));
+                       dawn = (!(turn % (TURNS_PER_TICK * TOWN_DAWN)));
 
                        /* Day breaks */
                        if (dawn)
@@ -1691,11 +1736,13 @@ msg_print("
                                                /* Darken "boring" features */
                                                if ((c_ptr->feat <= FEAT_INVIS) ||
                                                    ((c_ptr->feat >= FEAT_DEEP_WATER) &&
-                                                       (c_ptr->feat <= FEAT_TREES) &&
-                                                   (c_ptr->feat != FEAT_MUSEUM)))
+                                                       (c_ptr->feat <= FEAT_MOUNTAIN) &&
+                                                    (c_ptr->feat != FEAT_MUSEUM)) ||
+                                                   (x == 0) || (x == cur_wid-1) ||
+                                                   (y == 0) || (y == cur_hgt-1))
                                                {
                                                        /* Forget the grid */
-                                                       c_ptr->info &= ~(CAVE_GLOW | CAVE_MARK);
+                                                       if (!(c_ptr->info & CAVE_IN_MIRROR)) c_ptr->info &= ~(CAVE_GLOW | CAVE_MARK);
 
                                                        /* Hack -- Notice spot */
                                                        note_spot(y, x);
@@ -1716,7 +1763,7 @@ msg_print("
        }
 
        /* Set back the rewards once a day */
-       if (!(turn % (200L * STORE_TURNS)))
+       if (!(turn % (TURNS_PER_TICK*10 * STORE_TURNS)))
        {
                int n;
 
@@ -1739,7 +1786,7 @@ if (cheat_xtra) msg_print("
        /*** Process the monsters ***/
 
        /* Check for creature generation. */
-       if ((rand_int(d_info[dungeon_type].max_m_alloc_chance) == 0) &&
+       if (one_in_(d_info[dungeon_type].max_m_alloc_chance) &&
            !p_ptr->inside_arena && !p_ptr->inside_quest && !p_ptr->inside_battle)
        {
                /* Make a new monster */
@@ -1747,8 +1794,8 @@ if (cheat_xtra) msg_print("
        }
 
        /* Hack -- Check for creature regeneration */
-       if (!(turn % 200) && !p_ptr->inside_battle) regen_monsters();
-       if (!(turn % 60)) regen_captured_monsters();
+       if (!(turn % (TURNS_PER_TICK*10)) && !p_ptr->inside_battle) regen_monsters();
+       if (!(turn % (TURNS_PER_TICK*3))) regen_captured_monsters();
 
 
        /*** Damage over Time ***/
@@ -1769,8 +1816,7 @@ 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 &&
-                   (!((turn / ((20L * TOWN_DAWN) / 2)) % 2)))
+               if (!dun_level && !p_ptr->resist_lite && !p_ptr->invuln && is_daytime())
                {
                        if (cave[py][px].info & CAVE_GLOW)
                        {
@@ -1822,13 +1868,13 @@ sprintf(ouch, "%s
        if ((cave[py][px].feat == FEAT_SHAL_LAVA) &&
                !p_ptr->invuln && !p_ptr->immune_fire && !p_ptr->ffall)
        {
-               int damage = 3000 + rand_int(2000);
+               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;
-               damage = damage / 100 + (rand_int(100) < (damage % 100));
+               damage = damage / 100 + (randint0(100) < (damage % 100));
 
                if (damage)
                {
@@ -1848,7 +1894,7 @@ take_hit(DAMAGE_NOESCAPE, damage, "
        else if ((cave[py][px].feat == FEAT_DEEP_LAVA) &&
                !p_ptr->invuln && !p_ptr->immune_fire)
        {
-               int damage = 6000 + rand_int(4000);
+               int damage = 6000 + randint0(4000);
 
                cptr message;
                cptr hit_from;
@@ -1881,7 +1927,7 @@ hit_from = "
 
                }
 
-               damage = damage / 100 + (rand_int(100) < (damage % 100));
+               damage = damage / 100 + (randint0(100) < (damage % 100));
                if (damage)
                {
                        /* Take damage */
@@ -1894,15 +1940,15 @@ hit_from = "
 
        else if ((cave[py][px].feat == FEAT_DEEP_WATER) && !p_ptr->ffall && !p_ptr->can_swim)
        {
-               if (p_ptr->total_weight > ((adj_str_wgt[p_ptr->stat_ind[A_STR]] * (p_ptr->pclass == CLASS_BERSERKER ? 150 : 100)) / 2))
+               if (p_ptr->total_weight > (((u32b)adj_str_wgt[p_ptr->stat_ind[A_STR]] * (p_ptr->pclass == CLASS_BERSERKER ? 150 : 100)) / 2))
                {
                        /* Take damage */
 #ifdef JP
 msg_print("Å®¤ì¤Æ¤¤¤ë¡ª");
-take_hit(DAMAGE_NOESCAPE, randint(p_ptr->lev), "Å®¤ì", -1);
+take_hit(DAMAGE_NOESCAPE, randint1(p_ptr->lev), "Å®¤ì", -1);
 #else
                        msg_print("You are drowning!");
-                       take_hit(DAMAGE_NOESCAPE, randint(p_ptr->lev), "drowning", -1);
+                       take_hit(DAMAGE_NOESCAPE, randint1(p_ptr->lev), "drowning", -1);
 #endif
 
                        cave_no_regen = TRUE;
@@ -2173,7 +2219,7 @@ take_hit(DAMAGE_NOESCAPE, i, "
                if (p_ptr->food < PY_FOOD_MAX)
                {
                        /* Every 100 game turns */
-                       if (!(turn % 100))
+                       if (!(turn % (TURNS_PER_TICK*5)))
                        {
                                /* Basic digestion rate based on speed */
                                i = /* extract_energy[p_ptr->pspeed] * 2;*/
@@ -2183,12 +2229,15 @@ take_hit(DAMAGE_NOESCAPE, i, "
                                /* Regeneration takes more food */
                                if (p_ptr->regenerate) i += 20;
                                if (p_ptr->special_defense & (KAMAE_MASK | KATA_MASK)) i+= 20;
+                               if (p_ptr->cursed & TRC_FAST_DIGEST) i += 30;
 
                                /* Slow digestion takes less food */
                                if (p_ptr->slow_digest) i -= 5;
 
                                /* Minimal digestion */
                                if (i < 1) i = 1;
+                               /* Maximal digestion */
+                               if (i > 100) i = 100;
 
                                /* Digest some food */
                                (void)set_food(p_ptr->food - i);
@@ -2242,7 +2291,7 @@ if (!p_ptr->invuln) take_hit(DAMAGE_LOSELIFE, i, "
                if ((p_ptr->food < PY_FOOD_FAINT) && !p_ptr->inside_battle)
                {
                        /* Faint occasionally */
-                       if (!p_ptr->paralyzed && (rand_int(100) < 10))
+                       if (!p_ptr->paralyzed && (randint0(100) < 10))
                        {
                                /* Message */
 #ifdef JP
@@ -2254,7 +2303,7 @@ msg_print("
                                disturb(1, 0);
 
                                /* Hack -- faint (bypass free action) */
-                               (void)set_paralyzed(p_ptr->paralyzed + 1 + rand_int(5));
+                               (void)set_paralyzed(p_ptr->paralyzed + 1 + randint0(5));
                        }
                }
        }
@@ -2276,6 +2325,10 @@ msg_print("
                {
                        regen_amount /= 2;
                }
+               if (p_ptr->cursed & TRC_SLOW_REGEN)
+               {
+                       regen_amount /= 5;
+               }
        }
 
 
@@ -2297,7 +2350,7 @@ msg_print("
                        regenmana(upkeep_regen/100);
 
 #ifdef TRACK_FRIENDS
-                       if (wizard)
+                       if (p_ptr->wizard)
                        {
 #ifdef JP
 msg_format("£Í£Ð²óÉü: %d/%d", upkeep_regen, regen_amount);
@@ -2328,6 +2381,7 @@ msg_print("
 #else
                        msg_print("Such much pets cannot be controled at once!");
 #endif
+                       msg_print(NULL);
                        do_cmd_pet_dismiss();
 
                        upkeep_factor = calculate_upkeep();
@@ -2450,6 +2504,18 @@ msg_print("
                (void)set_tim_sh_fire(p_ptr->tim_sh_fire - 1, TRUE);
        }
 
+       /* Timed sh_holy */
+       if (p_ptr->tim_sh_holy)
+       {
+               (void)set_tim_sh_holy(p_ptr->tim_sh_holy - 1, TRUE);
+       }
+
+       /* Timed eyeeye */
+       if (p_ptr->tim_eyeeye)
+       {
+               (void)set_tim_eyeeye(p_ptr->tim_eyeeye - 1, TRUE);
+       }
+
        /* Timed resist-magic */
        if (p_ptr->resist_magic)
        {
@@ -2671,7 +2737,7 @@ msg_print("
                        /* Decrease life-span */
                        if (o_ptr->name2 == EGO_LITE_LONG)
                        {
-                               if (turn % 40) o_ptr->xtra4--;
+                               if (turn % (TURNS_PER_TICK*2)) o_ptr->xtra4--;
                        }
                        else o_ptr->xtra4--;
 
@@ -2687,7 +2753,7 @@ msg_print("
        /*** Process mutation effects ***/
        if (p_ptr->muta2 && !p_ptr->inside_battle && !p_ptr->wild_mode)
        {
-               if ((p_ptr->muta2 & MUT2_BERS_RAGE) && (randint(3000) == 1))
+               if ((p_ptr->muta2 & MUT2_BERS_RAGE) && one_in_(3000))
                {
                        disturb(0, 0);
 #ifdef JP
@@ -2698,10 +2764,10 @@ msg_print("
                        msg_print("You feel a fit of rage coming over you!");
 #endif
 
-                       (void)set_shero(10 + randint(p_ptr->lev), FALSE);
+                       (void)set_shero(10 + randint1(p_ptr->lev), FALSE);
                }
 
-               if ((p_ptr->muta2 & MUT2_COWARDICE) && (randint(3000) == 13))
+               if ((p_ptr->muta2 & MUT2_COWARDICE) && (randint1(3000) == 13))
                {
                        if (!(p_ptr->resist_fear || p_ptr->hero || p_ptr->shero))
                        {
@@ -2712,11 +2778,11 @@ msg_print("
                                msg_print("It's so dark... so scary!");
 #endif
 
-                               set_afraid(p_ptr->afraid + 13 + randint(26));
+                               set_afraid(p_ptr->afraid + 13 + randint1(26));
                        }
                }
 
-               if ((p_ptr->muta2 & MUT2_RTELEPORT) && (randint(5000) == 88))
+               if ((p_ptr->muta2 & MUT2_RTELEPORT) && (randint1(5000) == 88))
                {
                        if (!p_ptr->resist_nexus && !(p_ptr->muta1 & MUT1_VTELEPORT) &&
                            !p_ptr->anti_tele)
@@ -2735,7 +2801,7 @@ msg_print("
                        }
                }
 
-               if ((p_ptr->muta2 & MUT2_ALCOHOL) && (randint(6400) == 321))
+               if ((p_ptr->muta2 & MUT2_ALCOHOL) && (randint1(6400) == 321))
                {
                        if (!p_ptr->resist_conf && !p_ptr->resist_chaos)
                        {
@@ -2751,7 +2817,7 @@ msg_print("
 
                        if (!p_ptr->resist_conf)
                        {
-                               (void)set_confused(p_ptr->confused + rand_int(20) + 15);
+                               (void)set_confused(p_ptr->confused + randint0(20) + 15);
                        }
 
                        if (!p_ptr->resist_chaos)
@@ -2782,23 +2848,23 @@ msg_print("
                                                msg_print("Thishcischs GooDSChtuff!");
 #endif
 
-                                               (void)set_image(p_ptr->image + rand_int(150) + 150);
+                                               (void)set_image(p_ptr->image + randint0(150) + 150);
                                        }
                                }
                        }
                }
 
-               if ((p_ptr->muta2 & MUT2_HALLU) && (randint(6400) == 42))
+               if ((p_ptr->muta2 & MUT2_HALLU) && (randint1(6400) == 42))
                {
                        if (!p_ptr->resist_chaos)
                        {
                                disturb(0, 0);
                                p_ptr->redraw |= PR_EXTRA;
-                               (void)set_image(p_ptr->image + rand_int(50) + 20);
+                               (void)set_image(p_ptr->image + randint0(50) + 20);
                        }
                }
 
-               if ((p_ptr->muta2 & MUT2_FLATULENT) && (randint(3000) == 13))
+               if ((p_ptr->muta2 & MUT2_FLATULENT) && (randint1(3000) == 13))
                {
                        disturb(0, 0);
 
@@ -2813,7 +2879,7 @@ msg_print("
                }
 
                if ((p_ptr->muta2 & MUT2_PROD_MANA) &&
-                   !p_ptr->anti_magic && (randint(9000) == 1))
+                   !p_ptr->anti_magic && one_in_(9000))
                {
                        int dire = 0;
                        disturb(0, 0);
@@ -2830,12 +2896,16 @@ msg_print("
                }
 
                if ((p_ptr->muta2 & MUT2_ATT_DEMON) &&
-                   !p_ptr->anti_magic && (randint(6666) == 666))
+                   !p_ptr->anti_magic && (randint1(6666) == 666))
                {
-                       bool pet = (randint(6) == 1);
+                       bool pet = one_in_(6);
+                       u32b mode = PM_ALLOW_GROUP;
+
+                       if (pet) mode |= PM_FORCE_PET;
+                       else mode |= (PM_ALLOW_UNIQUE | PM_NO_PET);
 
                        if (summon_specific((pet ? -1 : 0), py, px,
-                                   dun_level, SUMMON_DEMON, TRUE, FALSE, pet, !pet, !pet))
+                                   dun_level, SUMMON_DEMON, mode))
                        {
 #ifdef JP
 msg_print("¤¢¤Ê¤¿¤Ï¥Ç¡¼¥â¥ó¤ò°ú¤­´ó¤»¤¿¡ª");
@@ -2847,10 +2917,10 @@ msg_print("
                        }
                }
 
-               if ((p_ptr->muta2 & MUT2_SPEED_FLUX) && (randint(6000) == 1))
+               if ((p_ptr->muta2 & MUT2_SPEED_FLUX) && one_in_(6000))
                {
                        disturb(0, 0);
-                       if (randint(2) == 1)
+                       if (one_in_(2))
                        {
 #ifdef JP
 msg_print("ÀºÎÏŪ¤Ç¤Ê¤¯¤Ê¤Ã¤¿µ¤¤¬¤¹¤ë¡£");
@@ -2864,7 +2934,7 @@ msg_print("
                                }
                                else
                                {
-                                       set_slow(randint(30) + 10, FALSE);
+                                       set_slow(randint1(30) + 10, FALSE);
                                }
                        }
                        else
@@ -2881,12 +2951,12 @@ msg_print("
                                }
                                else
                                {
-                                       set_fast(randint(30) + 10, FALSE);
+                                       set_fast(randint1(30) + 10, FALSE);
                                }
                        }
                        msg_print(NULL);
                }
-               if ((p_ptr->muta2 & MUT2_BANISH_ALL) && (randint(9000) == 1))
+               if ((p_ptr->muta2 & MUT2_BANISH_ALL) && one_in_(9000))
                {
                        disturb(0, 0);
 #ifdef JP
@@ -2904,7 +2974,7 @@ msg_print("Ź
                                msg_print("You see one of the shopkeepers running for the hills!");
 #endif
 
-                               store_shuffle(rand_int(MAX_STORES));
+                               store_shuffle(randint0(MAX_STORES));
                        }
                        msg_print(NULL);
                }
@@ -2963,10 +3033,13 @@ msg_print("
                if ((p_ptr->muta2 & MUT2_ATT_ANIMAL) &&
                   !p_ptr->anti_magic && one_in_(7000))
                {
-                       bool pet = (randint(3) == 1);
+                       bool pet = one_in_(3);
+                       u32b mode = PM_ALLOW_GROUP;
+
+                       if (pet) mode |= PM_FORCE_PET;
+                       else mode |= (PM_ALLOW_UNIQUE | PM_NO_PET);
 
-                       if (summon_specific((pet ? -1 : 0), py, px, dun_level, SUMMON_ANIMAL,
-                           TRUE, FALSE, pet, !pet, !pet))
+                       if (summon_specific((pet ? -1 : 0), py, px, dun_level, SUMMON_ANIMAL, mode))
                        {
 #ifdef JP
 msg_print("ưʪ¤ò°ú¤­´ó¤»¤¿¡ª");
@@ -3011,7 +3084,7 @@ msg_print("
 #endif
 
                        msg_print(NULL);
-                       set_wraith_form(randint(p_ptr->lev / 2) + (p_ptr->lev / 2), FALSE);
+                       set_wraith_form(randint1(p_ptr->lev / 2) + (p_ptr->lev / 2), FALSE);
                }
                if ((p_ptr->muta2 & MUT2_POLY_WOUND) && one_in_(3000))
                {
@@ -3019,7 +3092,7 @@ msg_print("
                }
                if ((p_ptr->muta2 & MUT2_WASTING) && one_in_(3000))
                {
-                       int which_stat = rand_int(6);
+                       int which_stat = randint0(6);
                        int sustained = FALSE;
 
                        switch (which_stat)
@@ -3062,16 +3135,19 @@ msg_print("
 #endif
 
                                msg_print(NULL);
-                               (void)dec_stat(which_stat, randint(6) + 6, randint(3) == 1);
+                               (void)dec_stat(which_stat, randint1(6) + 6, one_in_(3));
                        }
                }
                if ((p_ptr->muta2 & MUT2_ATT_DRAGON) &&
                   !p_ptr->anti_magic && one_in_(3000))
                {
-                       bool pet = (randint(5) == 1);
+                       bool pet = one_in_(5);
+                       u32b mode = PM_ALLOW_GROUP;
 
-                       if (summon_specific((pet ? -1 : 0), py, px, dun_level, SUMMON_DRAGON,
-                           TRUE, FALSE, pet, !pet, !pet))
+                       if (pet) mode |= PM_FORCE_PET;
+                       else mode |= (PM_ALLOW_UNIQUE | PM_NO_PET);
+
+                       if (summon_specific((pet ? -1 : 0), py, px, dun_level, SUMMON_DRAGON, mode))
                        {
 #ifdef JP
 msg_print("¥É¥é¥´¥ó¤ò°ú¤­´ó¤»¤¿¡ª");
@@ -3199,7 +3275,7 @@ msg_print("̵Ũ
 #endif
 
                        msg_print(NULL);
-                       (void)set_invuln(randint(8) + 8, FALSE);
+                       (void)set_invuln(randint1(8) + 8, FALSE);
                }
                if ((p_ptr->muta2 & MUT2_SP_TO_HP) && one_in_(2000))
                {
@@ -3248,10 +3324,10 @@ take_hit(DAMAGE_LOSELIFE, healing, "Ƭ
                        disturb(0, 0);
 #ifdef JP
 msg_print("­¤¬¤â¤Ä¤ì¤Æž¤ó¤À¡ª");
-take_hit(DAMAGE_NOESCAPE, randint(p_ptr->wt / 6), "žÅÝ", -1);
+take_hit(DAMAGE_NOESCAPE, randint1(p_ptr->wt / 6), "žÅÝ", -1);
 #else
                        msg_print("You trip over your own feet!");
-                       take_hit(DAMAGE_NOESCAPE, randint(p_ptr->wt / 6), "tripping", -1);
+                       take_hit(DAMAGE_NOESCAPE, randint1(p_ptr->wt / 6), "tripping", -1);
 #endif
 
 
@@ -3282,10 +3358,45 @@ msg_print("
 
        /*** Process Inventory ***/
 
-       /* Handle experience draining */
-       if (p_ptr->exp_drain)
+       if ((p_ptr->cursed & TRC_P_FLAG_MASK) && !p_ptr->wild_mode)
        {
-               if (rand_int(100) < 25)
+               /*
+                * Hack: Uncursed teleporting items (e.g. Trump Weapons)
+                * can actually be useful!
+                */
+               if ((p_ptr->cursed & TRC_TELEPORT_SELF) && one_in_(200))
+               {
+#ifdef JP
+if (get_check_strict("¥Æ¥ì¥Ý¡¼¥È¤·¤Þ¤¹¤«¡©", CHECK_OKAY_CANCEL))
+#else
+                       if (get_check_strict("Teleport? ", CHECK_OKAY_CANCEL))
+#endif
+                       {
+                               disturb(0, 0);
+                               teleport_player(50);
+                       }
+               }
+               /* Make a chainsword noise */
+               if ((p_ptr->cursed & TRC_CHAINSWORD) && one_in_(CHAINSWORD_NOISE))
+               {
+                       char noise[1024];
+#ifdef JP
+if (!get_rnd_line("chainswd_j.txt", 0, noise))
+#else
+                       if (!get_rnd_line("chainswd.txt", 0, noise))
+#endif
+                               msg_print(noise);
+                       disturb(FALSE, FALSE);
+               }
+               /* TY Curse */
+               if ((p_ptr->cursed & TRC_TY_CURSE) && one_in_(TY_CURSE_CHANCE))
+               {
+                       int count = 0;
+                       (void)activate_ty_curse(FALSE, &count);
+               }
+               /* Handle experience draining */
+               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;
@@ -3293,95 +3404,195 @@ msg_print("
                        if (p_ptr->max_exp < 0) p_ptr->max_exp = 0;
                        check_experience();
                }
-       }
-
-       /* Rarely, take damage from the Jewel of Judgement */
-       if ((randint(999) == 1) && !p_ptr->anti_magic)
-       {
-               if ((inventory[INVEN_LITE].tval) &&
-                   (inventory[INVEN_LITE].sval == SV_LITE_THRAIN))
+               /* Add light curse (Later) */
+               if ((p_ptr->cursed & TRC_ADD_L_CURSE) && one_in_(2000))
                {
+                       u32b new_curse;
+                       object_type *o_ptr;
+
+                       o_ptr = choose_cursed_obj_name(TRC_ADD_L_CURSE);
+
+                       new_curse = get_curse(0, o_ptr);
+                       if (!(o_ptr->curse_flags & new_curse))
+                       {
+                               char o_name[MAX_NLEN];
+
+                               object_desc(o_name, o_ptr, FALSE, 0);
+
+                               o_ptr->curse_flags |= new_curse;
 #ifdef JP
-msg_print("¡Ø¿³È½¤ÎÊõÀС٤Ϥ¢¤Ê¤¿¤ÎÂÎÎϤòµÛ¼ý¤·¤¿¡ª");
-take_hit(DAMAGE_LOSELIFE, MIN(p_ptr->lev, 50), "¿³È½¤ÎÊõÀÐ", -1);
+msg_format("°­°Õ¤ËËþ¤Á¤¿¹õ¤¤¥ª¡¼¥é¤¬%s¤ò¤È¤ê¤Þ¤¤¤¿...", o_name);
 #else
-                       msg_print("The Jewel of Judgement drains life from you!");
-                       take_hit(DAMAGE_LOSELIFE, MIN(p_ptr->lev, 50), "the Jewel of Judgement", -1);
+                               msg_format("There is a malignant black aura surrounding %s...", o_name);
 #endif
 
+                               o_ptr->feeling = FEEL_NONE;
+
+                               p_ptr->update |= (PU_BONUS);
+                       }
                }
-       }
+               /* Add heavy curse (Later) */
+               if ((p_ptr->cursed & TRC_ADD_H_CURSE) && one_in_(2000))
+               {
+                       u32b new_curse;
+                       object_type *o_ptr;
 
+                       o_ptr = choose_cursed_obj_name(TRC_ADD_H_CURSE);
 
-       /* Process equipment */
-       for (j = 0, i = INVEN_RARM; i < INVEN_TOTAL; i++)
-       {
-               /* Get the object */
-               o_ptr = &inventory[i];
+                       new_curse = get_curse(1, o_ptr);
+                       if (!(o_ptr->curse_flags & new_curse))
+                       {
+                               char o_name[MAX_NLEN];
 
-               object_flags(o_ptr, &f1, &f2, &f3);
+                               object_desc(o_name, o_ptr, FALSE, 0);
 
-               /* Skip non-objects */
-               if (!o_ptr->k_idx) continue;
+                               o_ptr->curse_flags |= new_curse;
+#ifdef JP
+msg_format("°­°Õ¤ËËþ¤Á¤¿¹õ¤¤¥ª¡¼¥é¤¬%s¤ò¤È¤ê¤Þ¤¤¤¿...", o_name);
+#else
+                               msg_format("There is a malignant black aura surrounding %s...", o_name);
+#endif
+
+                               o_ptr->feeling = FEEL_NONE;
 
-               if (!p_ptr->inside_battle)
+                               p_ptr->update |= (PU_BONUS);
+                       }
+               }
+               /* Call animal */
+               if ((p_ptr->cursed & TRC_CALL_ANIMAL) && one_in_(2500))
                {
-                       /* TY Curse */
-                       if ((f3 & TR3_TY_CURSE) && (randint(TY_CURSE_CHANCE) == 1))
+                       if (summon_specific(0, py, px, dun_level, SUMMON_ANIMAL,
+                           (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET)))
                        {
-                               int count = 0;
+                               char o_name[MAX_NLEN];
 
-                               (void)activate_ty_curse(FALSE, &count);
-                       }
+                               object_desc(o_name, choose_cursed_obj_name(TRC_CALL_ANIMAL), FALSE, 0);
+#ifdef JP
+msg_format("%s¤¬Æ°Êª¤ò°ú¤­´ó¤»¤¿¡ª", o_name);
+#else
+                               msg_format("%s have attracted an animal!", o_name);
+#endif
 
-                       /* Make a chainsword noise */
-                       if ((o_ptr->name1 == ART_CHAINSWORD) && randint(CHAINSWORD_NOISE) == 1)
+                               disturb(0, 0);
+                       }
+               }
+               /* Call demon */
+               if ((p_ptr->cursed & TRC_CALL_DEMON) && one_in_(1111))
+               {
+                       if (summon_specific(0, py, px, dun_level, SUMMON_DEMON, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET)))
                        {
-                               char noise[1024];
+                               char o_name[MAX_NLEN];
+
+                               object_desc(o_name, choose_cursed_obj_name(TRC_CALL_DEMON), FALSE, 0);
 #ifdef JP
-if (!get_rnd_line("chainswd_j.txt", 0, noise))
+msg_format("%s¤¬°­Ëâ¤ò°ú¤­´ó¤»¤¿¡ª", o_name);
 #else
-                               if (!get_rnd_line("chainswd.txt", 0, noise))
+                               msg_format("%s have attracted a demon!", o_name);
 #endif
 
-                                       msg_print(noise);
-                               disturb(FALSE, FALSE);
+                               disturb(0, 0);
                        }
+               }
+               /* Call dragon */
+               if ((p_ptr->cursed & TRC_CALL_DRAGON) && one_in_(800))
+               {
+                       if (summon_specific(0, py, px, dun_level, SUMMON_DRAGON,
+                           (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET)))
+                       {
+                               char o_name[MAX_NLEN];
 
-                       /*
-                        * Hack: Uncursed teleporting items (e.g. Trump Weapons)
-                        * can actually be useful!
-                        */
-                       if ((f3 & TR3_TELEPORT) && (rand_int(100) < 1))
+                               object_desc(o_name, choose_cursed_obj_name(TRC_CALL_DRAGON), FALSE, 0);
+#ifdef JP
+msg_format("%s¤¬¥É¥é¥´¥ó¤ò°ú¤­´ó¤»¤¿¡ª", o_name);
+#else
+                               msg_format("%s have attracted an animal!", o_name);
+#endif
+
+                               disturb(0, 0);
+                       }
+               }
+               if ((p_ptr->cursed & TRC_COWARDICE) && one_in_(1500))
+               {
+                       if (!(p_ptr->resist_fear || p_ptr->hero || p_ptr->shero))
                        {
-                               if ((o_ptr->ident & IDENT_CURSED) && !p_ptr->anti_tele)
-                               {
-                                       disturb(0, 0);
+                               disturb(0, 0);
+#ifdef JP
+msg_print("¤È¤Æ¤â°Å¤¤... ¤È¤Æ¤â¶²¤¤¡ª");
+#else
+                               msg_print("It's so dark... so scary!");
+#endif
 
-                                       /* Teleport player */
-                                       teleport_player(40);
-                               }
-                               else
-                               {
-                                       if (p_ptr->wild_mode || (o_ptr->inscription &&
-                                           (strchr(quark_str(o_ptr->inscription),'.'))))
-                                       {
-                                               /* Do nothing */
-                                               /* msg_print("Teleport aborted.") */ ;
-                                       }
+                               set_afraid(p_ptr->afraid + 13 + randint1(26));
+                       }
+               }
+               /* Teleport player */
+               if ((p_ptr->cursed & TRC_TELEPORT) && one_in_(200) && !p_ptr->anti_tele)
+               {
+                       disturb(0, 0);
+
+                       /* Teleport player */
+                       teleport_player(40);
+               }
+               /* Handle HP draining */
+               if ((p_ptr->cursed & TRC_DRAIN_HP) && one_in_(666))
+               {
+                       char o_name[MAX_NLEN];
+
+                       object_desc(o_name, choose_cursed_obj_name(TRC_DRAIN_HP), FALSE, 0);
 #ifdef JP
-else if (get_check("¥Æ¥ì¥Ý¡¼¥È¤·¤Þ¤¹¤«¡©"))
+msg_format("%s¤Ï¤¢¤Ê¤¿¤ÎÂÎÎϤòµÛ¼ý¤·¤¿¡ª", o_name);
 #else
-                                       else if (get_check("Teleport? "))
+                       msg_format("%s drains HP from you!", o_name);
 #endif
+                       take_hit(DAMAGE_LOSELIFE, MIN(p_ptr->lev*2, 100), o_name, -1);
+               }
+               /* Handle mana draining */
+               if ((p_ptr->cursed & TRC_DRAIN_MANA) && one_in_(666))
+               {
+                       char o_name[MAX_NLEN];
 
-                                       {
-                                               disturb(0, 0);
-                                               teleport_player(50);
-                                       }
-                               }
+                       object_desc(o_name, choose_cursed_obj_name(TRC_DRAIN_MANA), FALSE, 0);
+#ifdef JP
+msg_format("%s¤Ï¤¢¤Ê¤¿¤ÎËâÎϤòµÛ¼ý¤·¤¿¡ª", o_name);
+#else
+                       msg_format("%s drains mana from you!", o_name);
+#endif
+                       p_ptr->csp -= MIN(p_ptr->lev, 50);
+                       if (p_ptr->csp < 0)
+                       {
+                               p_ptr->csp = 0;
+                               p_ptr->csp_frac = 0;
                        }
+                       p_ptr->redraw |= PR_MANA;
                }
+       }
+
+       /* 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))
+               {
+#ifdef JP
+msg_print("¡Ø¿³È½¤ÎÊõÀС٤Ϥ¢¤Ê¤¿¤ÎÂÎÎϤòµÛ¼ý¤·¤¿¡ª");
+take_hit(DAMAGE_LOSELIFE, MIN(p_ptr->lev, 50), "¿³È½¤ÎÊõÀÐ", -1);
+#else
+                       msg_print("The Jewel of Judgement drains life from you!");
+                       take_hit(DAMAGE_LOSELIFE, MIN(p_ptr->lev, 50), "the Jewel of Judgement", -1);
+#endif
+
+               }
+       }
+
+
+       /* Process equipment */
+       for (j = 0, i = INVEN_RARM; i < INVEN_TOTAL; i++)
+       {
+               /* Get the object */
+               o_ptr = &inventory[i];
+
+               /* Skip non-objects */
+               if (!o_ptr->k_idx) continue;
 
                /* Recharge activatable objects */
                if (o_ptr->timeout > 0)
@@ -3520,24 +3731,7 @@ msg_print("
                                dun_level = 0;
                                dungeon_type = 0;
 
-                               leaving_quest = p_ptr->inside_quest;
-
-                               /* Leaving an 'only once' quest marks it as failed */
-                               if (leaving_quest &&
-                                       ((quest[leaving_quest].flags & QUEST_FLAG_ONCE)  || (quest[leaving_quest].type == QUEST_TYPE_RANDOM)) &&
-                                       (quest[leaving_quest].status == QUEST_STATUS_TAKEN))
-                               {
-                                       quest[leaving_quest].status = QUEST_STATUS_FAILED;
-                                       quest[leaving_quest].complev = p_ptr->lev;
-                                       if (quest[leaving_quest].type == QUEST_TYPE_RANDOM)
-                                       {
-                                               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);
-                                       }
-                                       else if (record_fix_quest)
-                                               do_cmd_write_nikki(NIKKI_FIX_QUEST_F, leaving_quest, NULL);
-                               }
+                               leave_quest_check();
 
                                p_ptr->inside_quest = 0;
                                p_ptr->leaving = TRUE;
@@ -3560,7 +3754,7 @@ msg_print("
                                if (dun_level < 1) dun_level = 1;
 
                                /* Nightmare mode makes recall more dangerous */
-                               if (ironman_nightmare && !rand_int(666) && (dungeon_type == DUNGEON_ANGBAND))
+                               if (ironman_nightmare && !randint0(666) && (dungeon_type == DUNGEON_ANGBAND))
                                {
                                        if (dun_level < 50)
                                        {
@@ -3601,7 +3795,7 @@ msg_print("
                                                    (quest[i].level < dun_level))
                                                {
                                                        quest[i].status = QUEST_STATUS_FAILED;
-                                                       quest[i].complev = p_ptr->lev;
+                                                       quest[i].complev = (byte)p_ptr->lev;
                                                        r_info[quest[i].r_idx].flags1 &= ~(RF1_QUESTOR);
                                                }
                                        }
@@ -3622,7 +3816,7 @@ msg_print("
 static bool enter_wizard_mode(void)
 {
        /* Ask first time */
-       if (!noscore)
+       if (!p_ptr->noscore)
        {
                /* Mention effects */
 #ifdef JP
@@ -3647,7 +3841,7 @@ if (!get_check("
                }
 
                /* Mark savefile */
-               noscore |= 0x0002;
+               p_ptr->noscore |= 0x0002;
        }
 
        /* Success */
@@ -3663,7 +3857,7 @@ if (!get_check("
 static bool enter_debug_mode(void)
 {
        /* Ask first time */
-       if (!noscore)
+       if (!p_ptr->noscore)
        {
                /* Mention effects */
 #ifdef JP
@@ -3693,7 +3887,7 @@ if (!get_check("
                do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "give up sending score to use debug commands.");
 #endif
                /* Mark savefile */
-               noscore |= 0x0008;
+               p_ptr->noscore |= 0x0008;
        }
 
        /* Success */
@@ -3716,7 +3910,7 @@ extern void do_cmd_debug(void);
 static bool enter_borg_mode(void)
 {
        /* Ask first time */
-       if (!(noscore & 0x0010))
+       if (!(p_ptr->noscore & 0x0010))
        {
                /* Mention effects */
 #ifdef JP
@@ -3741,7 +3935,7 @@ if (!get_check("
                }
 
                /* Mark savefile */
-               noscore |= 0x0010;
+               p_ptr->noscore |= 0x0010;
        }
 
        /* Success */
@@ -3788,6 +3982,7 @@ static void process_command(void)
 
                /* Ignore return */
                case '\r':
+               case '\n':
                {
                        break;
                }
@@ -3797,9 +3992,9 @@ static void process_command(void)
                /* Toggle Wizard Mode */
                case KTRL('W'):
                {
-                       if (wizard)
+                       if (p_ptr->wizard)
                        {
-                               wizard = FALSE;
+                               p_ptr->wizard = FALSE;
 #ifdef JP
 msg_print("¥¦¥£¥¶¡¼¥É¥â¡¼¥É²ò½ü¡£");
 #else
@@ -3809,7 +4004,7 @@ msg_print("
                        }
                        else if (enter_wizard_mode())
                        {
-                               wizard = TRUE;
+                               p_ptr->wizard = TRUE;
 #ifdef JP
 msg_print("¥¦¥£¥¶¡¼¥É¥â¡¼¥ÉÆÍÆþ¡£");
 #else
@@ -4022,21 +4217,21 @@ msg_print("
                /*** Stairs and Doors and Chests and Traps ***/
 
                /* Enter store */
-               case '_':
+               case SPECIAL_KEY_STORE:
                {
                        if (!p_ptr->wild_mode) do_cmd_store();
                        break;
                }
 
                /* Enter building -KMW- */
-               case 254:
+               case SPECIAL_KEY_BUILDING:
                {
                        if (!p_ptr->wild_mode) do_cmd_bldg();
                        break;
                }
 
                /* Enter quest level -KMW- */
-               case 255:
+               case SPECIAL_KEY_QUEST:
                {
                        if (!p_ptr->wild_mode) do_cmd_quest();
                        break;
@@ -4159,6 +4354,8 @@ msg_print("
                             ) do_cmd_mind_browse();
                        else if (p_ptr->pclass == CLASS_SMITH)
                                do_cmd_kaji(TRUE);
+                       else if (p_ptr->pclass == CLASS_MAGIC_EATER)
+                               do_cmd_magic_eater(TRUE);
                        else do_cmd_browse();
                        break;
                }
@@ -4169,105 +4366,105 @@ msg_print("
                        /* -KMW- */
                        if (!p_ptr->wild_mode)
                        {
-                       if (dun_level && (d_info[dungeon_type].flags1 & DF1_NO_MAGIC) && (p_ptr->pclass != CLASS_BERSERKER) && (p_ptr->pclass != CLASS_SMITH))
-                       {
+                               if ((p_ptr->pclass == CLASS_WARRIOR) || (p_ptr->pclass == CLASS_ARCHER) || (p_ptr->pclass == CLASS_CAVALRY))
+                               {
 #ifdef JP
-msg_print("¥À¥ó¥¸¥ç¥ó¤¬ËâË¡¤òµÛ¼ý¤·¤¿¡ª");
+                                       msg_print("¼öʸ¤ò¾§¤¨¤é¤ì¤Ê¤¤¡ª");
 #else
-                               msg_print("The arena absorbs all attempted magic!");
+                                       msg_print("You cannot cast spells!");
 #endif
-
-                               msg_print(NULL);
-                       }
-                       else if (p_ptr->anti_magic && (p_ptr->pclass != CLASS_BERSERKER) && (p_ptr->pclass != CLASS_SMITH))
-                       {
+                               }
+                               else if (dun_level && (d_info[dungeon_type].flags1 & DF1_NO_MAGIC) && (p_ptr->pclass != CLASS_BERSERKER) && (p_ptr->pclass != CLASS_SMITH))
+                               {
 #ifdef JP
-cptr which_power = "ËâË¡";
+                                       msg_print("¥À¥ó¥¸¥ç¥ó¤¬ËâË¡¤òµÛ¼ý¤·¤¿¡ª");
 #else
-                               cptr which_power = "magic";
+                                       msg_print("The dungeon absorbs all attempted magic!");
 #endif
+                                       msg_print(NULL);
+                               }
+                               else if (p_ptr->anti_magic && (p_ptr->pclass != CLASS_BERSERKER) && (p_ptr->pclass != CLASS_SMITH))
+                               {
+#ifdef JP
 
-                               if (p_ptr->pclass == CLASS_MINDCRAFTER)
+                                       cptr which_power = "ËâË¡";
+#else
+                                       cptr which_power = "magic";
+#endif
+                                       if (p_ptr->pclass == CLASS_MINDCRAFTER)
 #ifdef JP
-which_power = "ĶǽÎÏ";
+                                               which_power = "ĶǽÎÏ";
 #else
-                                       which_power = "psionic powers";
+                                               which_power = "psionic powers";
 #endif
-
-                               else if (p_ptr->pclass == CLASS_IMITATOR)
+                                       else if (p_ptr->pclass == CLASS_IMITATOR)
 #ifdef JP
-which_power = "¤â¤Î¤Þ¤Í";
+                                               which_power = "¤â¤Î¤Þ¤Í";
 #else
-                                       which_power = "mane";
+                                               which_power = "imitation";
 #endif
-
-                               else if (p_ptr->pclass == CLASS_SAMURAI)
+                                       else if (p_ptr->pclass == CLASS_SAMURAI)
 #ifdef JP
-which_power = "ɬ»¦·õ";
+                                               which_power = "ɬ»¦·õ";
 #else
-                                       which_power = "hissatsu";
+                                               which_power = "hissatsu";
 #endif
-                               else if (p_ptr->pclass == CLASS_MIRROR_MASTER)
+                                       else if (p_ptr->pclass == CLASS_MIRROR_MASTER)
 #ifdef JP
-which_power = "¶ÀËâË¡";
+                                               which_power = "¶ÀËâË¡";
 #else
-                                       which_power = "mirror magic";
+                                               which_power = "mirror magic";
 #endif
-
-                               else if (p_ptr->pclass == CLASS_NINJA)
+                                       else if (p_ptr->pclass == CLASS_NINJA)
 #ifdef JP
-which_power = "Ǧ½Ñ";
+                                               which_power = "Ǧ½Ñ";
 #else
-                                       which_power = "ninjutsu";
+                                               which_power = "ninjutsu";
 #endif
-
-                               else if (mp_ptr->spell_book == TV_LIFE_BOOK)
+                                       else if (mp_ptr->spell_book == TV_LIFE_BOOK)
 #ifdef JP
-which_power = "µ§¤ê";
+                                               which_power = "µ§¤ê";
 #else
-                                       which_power = "prayer";
+                                               which_power = "prayer";
 #endif
 
-
 #ifdef JP
-msg_format("È¿ËâË¡¥Ð¥ê¥¢¤¬%s¤ò¼ÙË⤷¤¿¡ª", which_power);
+                                       msg_format("È¿ËâË¡¥Ð¥ê¥¢¤¬%s¤ò¼ÙË⤷¤¿¡ª", which_power);
 #else
-                               msg_format("An anti-magic shell disrupts your %s!", which_power);
+                                       msg_format("An anti-magic shell disrupts your %s!", which_power);
 #endif
-
-
-                               energy_use = 0;
-                       }
-                       else if (p_ptr->shero && (p_ptr->pclass != CLASS_BERSERKER))
-                       {
+                                       energy_use = 0;
+                               }
+                               else if (p_ptr->shero && (p_ptr->pclass != CLASS_BERSERKER))
+                               {
 #ifdef JP
-msg_format("¶¸Àï»Î²½¤·¤Æ¤¤¤ÆƬ¤¬²ó¤é¤Ê¤¤¡ª");
+                                       msg_format("¶¸Àï»Î²½¤·¤Æ¤¤¤ÆƬ¤¬²ó¤é¤Ê¤¤¡ª");
 #else
-                               msg_format("You cannot think directly!");
+                                       msg_format("You cannot think directly!");
 #endif
-                               energy_use = 0;
-                       }
-                       else
-                       {
-                               if ((p_ptr->pclass == CLASS_MINDCRAFTER) ||
-                                   (p_ptr->pclass == CLASS_BERSERKER) ||
-                                   (p_ptr->pclass == CLASS_NINJA) ||
-                                   (p_ptr->pclass == CLASS_MIRROR_MASTER) 
-                                   )
-                                       do_cmd_mind();
-                               else if (p_ptr->pclass == CLASS_IMITATOR)
-                                       do_cmd_mane(FALSE);
-                               else if (p_ptr->pclass == CLASS_MAGIC_EATER)
-                                       do_cmd_magic_eater();
-                               else if (p_ptr->pclass == CLASS_SAMURAI)
-                                       do_cmd_hissatsu();
-                               else if (p_ptr->pclass == CLASS_BLUE_MAGE)
-                                       do_cmd_cast_learned();
-                               else if (p_ptr->pclass == CLASS_SMITH)
-                                       do_cmd_kaji(FALSE);
+                                       energy_use = 0;
+                               }
                                else
-                                       do_cmd_cast();
-                       }
+                               {
+                                       if ((p_ptr->pclass == CLASS_MINDCRAFTER) ||
+                                           (p_ptr->pclass == CLASS_BERSERKER) ||
+                                           (p_ptr->pclass == CLASS_NINJA) ||
+                                           (p_ptr->pclass == CLASS_MIRROR_MASTER)
+                                           )
+                                               do_cmd_mind();
+                                       else if (p_ptr->pclass == CLASS_IMITATOR)
+                                               do_cmd_mane(FALSE);
+                                       else if (p_ptr->pclass == CLASS_MAGIC_EATER)
+                                               do_cmd_magic_eater(FALSE);
+                                       else if (p_ptr->pclass == CLASS_SAMURAI)
+                                               do_cmd_hissatsu();
+                                       else if (p_ptr->pclass == CLASS_BLUE_MAGE)
+                                               do_cmd_cast_learned();
+                                       else if (p_ptr->pclass == CLASS_SMITH)
+                                               do_cmd_kaji(FALSE);
+                                       else
+                                               do_cmd_cast();
+                               }
                        }
                        break;
                }
@@ -4342,18 +4539,7 @@ msg_print("
                {
                        if (!p_ptr->wild_mode)
                        {
-                       if (!p_ptr->inside_arena)
                                do_cmd_throw();
-                       else
-                       {
-#ifdef JP
-msg_print("¥¢¥ê¡¼¥Ê¤Ç¤Ï¥¢¥¤¥Æ¥à¤ò»È¤¨¤Ê¤¤¡ª");
-#else
-                               msg_print("You're in the arena now. This is hand-to-hand!");
-#endif
-
-                               msg_print(NULL);
-                       }
                        }
                        break;
                }
@@ -4559,6 +4745,12 @@ msg_print("
                        break;
                }
 
+               case '_':
+               {
+                       do_cmd_edit_autopick();
+                       break;
+               }
+
                /* Interact with macros */
                case '@':
                {
@@ -4661,6 +4853,7 @@ msg_print("
 
                /* Save and quit */
                case KTRL('X'):
+               case SPECIAL_KEY_QUIT:
                {
                        do_cmd_save_and_exit();
                        break;
@@ -4711,7 +4904,7 @@ msg_print("
                default:
                {
                        if (flush_failure) flush();
-                       if (randint(2) == 1)
+                       if (one_in_(2))
                        {
                                char error_m[1024];
                                sound(SOUND_ILLEGAL);
@@ -4740,7 +4933,7 @@ prt(" '?' 
 
 
 
-bool monster_tsuri(int r_idx)
+static bool monster_tsuri(int r_idx)
 {
        monster_race *r_ptr = &r_info[r_idx];
 
@@ -4794,11 +4987,13 @@ msg_print("
        }
 
        /* Give the player some energy */
-       else if((rand_int(60) < ((p_ptr->pspeed > 199) ? 49 : ((p_ptr->pspeed < 0) ? 1 : extract_energy[p_ptr->pspeed]))) && !(load && p_ptr->energy >= 100))
-               p_ptr->energy += gain_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]));
+       }
 
        /* No turn yet */
-       if (p_ptr->energy < 100) return;
+       if (p_ptr->energy_need > 0) return;
        if (!command_rep) prt_time();
 
        /*** Check for interupts ***/
@@ -4813,7 +5008,6 @@ msg_print("
                        if ((p_ptr->chp == p_ptr->mhp) &&
                            (p_ptr->csp >= p_ptr->msp))
                        {
-                               disturb(0, 0);
                                set_action(ACTION_NONE);
                        }
                }
@@ -4830,7 +5024,6 @@ msg_print("
                            !p_ptr->slow && !p_ptr->paralyzed &&
                            !p_ptr->image && !p_ptr->word_recall)
                        {
-                               disturb(0, 0);
                                set_action(ACTION_NONE);
                        }
                }
@@ -4852,7 +5045,7 @@ msg_print("
                                int y, x;
                                y = py+ddy[tsuri_dir];
                                x = px+ddx[tsuri_dir];
-                               if (place_monster_aux(y, x, r_idx, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE))
+                               if (place_monster_aux(0, y, x, r_idx, PM_NO_KAGE))
                                {
                                        char m_name[80];
                                        monster_desc(m_name, &m_list[cave[y][x].m_idx], 0);
@@ -4869,7 +5062,7 @@ msg_print("
 #ifdef JP
                                msg_print("±Â¤À¤±¿©¤ï¤ì¤Æ¤·¤Þ¤Ã¤¿¡ª¤¯¤Ã¤½¡Á¡ª");
 #else
-                               msg_print("Damn! The fish took a bait away!");
+                               msg_print("Damn!  The fish stole your bait!");
 #endif
                        }
                        disturb(0, 0);
@@ -4877,7 +5070,7 @@ msg_print("
        }
 
        /* Handle "abort" */
-       if (avoid_abort)
+       if (check_abort)
        {
                /* Check for "player abort" (semi-efficiently for resting) */
                if (running || command_rep || (p_ptr->action == ACTION_REST) || (p_ptr->action == ACTION_FISH))
@@ -4932,7 +5125,7 @@ msg_format("%^s
                        int d = 1;
 
                        /* Make a "saving throw" against stun */
-                       if (rand_int(r_info[m_ptr->r_idx].level) < skill_exp[GINOU_RIDING])
+                       if (randint0(r_info[m_ptr->r_idx].level) < p_ptr->skill_exp[GINOU_RIDING])
                        {
                                /* Recover fully */
                                d = m_ptr->stunned;
@@ -4972,7 +5165,7 @@ msg_format("%^s
                        int d = 1;
 
                        /* Make a "saving throw" against stun */
-                       if (rand_int(r_info[m_ptr->r_idx].level) < skill_exp[GINOU_RIDING])
+                       if (randint0(r_info[m_ptr->r_idx].level) < p_ptr->skill_exp[GINOU_RIDING])
                        {
                                /* Recover fully */
                                d = m_ptr->confused;
@@ -5012,7 +5205,7 @@ msg_format("%^s
                        int d = 1;
 
                        /* Make a "saving throw" against stun */
-                       if (rand_int(r_info[m_ptr->r_idx].level) < skill_exp[GINOU_RIDING])
+                       if (randint0(r_info[m_ptr->r_idx].level) < p_ptr->skill_exp[GINOU_RIDING])
                        {
                                /* Recover fully */
                                d = m_ptr->monfear;
@@ -5067,6 +5260,7 @@ msg_format("%^s
                        p_ptr->magic_num1[0] = 0;
                }
                else p_ptr->magic_num1[0] -= 40;
+               p_ptr->update |= (PU_BONUS);
        }
        if (p_ptr->action == ACTION_LEARN)
        {
@@ -5079,14 +5273,15 @@ msg_format("%^s
                }
                else
                {
-                       p_ptr->csp -= (hoge / 0x10000L);
+                       p_ptr->csp -= (s16b)(hoge >> 16);
                        hoge &= 0xFFFFL;
                        if (p_ptr->csp_frac < hoge)
                        {
-                               p_ptr->csp_frac += 0x10000L;
-                               p_ptr->csp --;
+                               p_ptr->csp_frac += 0x10000L - hoge;
+                               p_ptr->csp--;
                        }
-                       p_ptr->csp_frac -= hoge;
+                       else
+                               p_ptr->csp_frac -= hoge;
                }
                p_ptr->redraw |= PR_MANA;
        }
@@ -5110,7 +5305,7 @@ msg_format("%^s
        /*** Handle actual user input ***/
 
        /* Repeat until out of energy */
-       while (p_ptr->energy >= 100)
+       while (p_ptr->energy_need <= 0)
        {
                p_ptr->window |= PW_PLAYER;
                p_ptr->sutemi = FALSE;
@@ -5296,8 +5491,10 @@ msg_format("%s(%c)
                if (energy_use)
                {
                        /* Use some energy */
-                       p_ptr->energy -= energy_use;
-
+                       if (!world_player)
+                               p_ptr->energy_need += (s16b)((s32b)energy_use * ENERGY_NEED() / 100L);
+                       else
+                               p_ptr->energy_need += energy_use * TURNS_PER_TICK / 10;
 
                        /* Hack -- constant hallucination */
                        if (p_ptr->image) p_ptr->redraw |= (PR_MAP);
@@ -5396,13 +5593,13 @@ msg_format("%s(%c)
                        }
                        if (p_ptr->pclass == CLASS_IMITATOR)
                        {
-                               if (mane_num > (p_ptr->lev > 44 ? 3 : p_ptr->lev > 29 ? 2 : 1))
+                               if (p_ptr->mane_num > (p_ptr->lev > 44 ? 3 : p_ptr->lev > 29 ? 2 : 1))
                                {
-                                       mane_num--;
-                                       for (i = 0; i < mane_num; i++)
+                                       p_ptr->mane_num--;
+                                       for (i = 0; i < p_ptr->mane_num; i++)
                                        {
-                                               mane_spell[i] = mane_spell[i+1];
-                                               mane_dam[i] = mane_dam[i+1];
+                                               p_ptr->mane_spell[i] = p_ptr->mane_spell[i+1];
+                                               p_ptr->mane_dam[i] = p_ptr->mane_dam[i+1];
                                        }
                                }
                                new_mane = FALSE;
@@ -5414,7 +5611,7 @@ msg_format("%s(%c)
                                p_ptr->redraw |= (PR_STATE);
                        }
 
-                       if (world_player && (p_ptr->energy < 1000))
+                       if (world_player && (p_ptr->energy_need > - 1000))
                        {
                                /* Redraw map */
                                p_ptr->redraw |= (PR_MAP);
@@ -5432,14 +5629,14 @@ msg_format("%s(%c)
 #endif
                                msg_print(NULL);
                                world_player = FALSE;
-                               p_ptr->energy = 0;
+                               p_ptr->energy_need = ENERGY_NEED();
 
                                handle_stuff();
                        }
                }
 
                /* Hack -- notice death */
-               if (!alive || death)
+               if (!p_ptr->playing || p_ptr->is_dead)
                {
                        world_player = FALSE;
                        break;
@@ -5448,6 +5645,9 @@ msg_format("%s(%c)
                /* Handle "leaving" */
                if (p_ptr->leaving) break;
        }
+
+       /* Update scent trail */
+       update_smell();
 }
 
 
@@ -5562,21 +5762,12 @@ static void dungeon(bool load_game)
                create_down_stair = create_up_stair = 0;
        }
 
+       /* Validate the panel */
+       panel_bounds_center();
 
        /* Verify the panel */
        verify_panel();
 
-       /* Validate the panel */
-       if (center_player)
-       {
-               panel_bounds_center();
-       }
-       else
-       {
-       panel_bounds();
-       }
-
-
        /* Flush messages */
        msg_print(NULL);
 
@@ -5585,10 +5776,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);
@@ -5596,14 +5784,14 @@ 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 lite/view */
+       p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE | PU_TORCH);
+
+       /* Update monsters */
+       p_ptr->update |= (PU_MONSTERS | PU_DISTANCE | PU_FLOW);
 
        /* Update stuff */
        update_stuff();
@@ -5614,16 +5802,6 @@ static void dungeon(bool load_game)
        /* 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();
-
        /* Leave "xtra" mode */
        character_xtra = FALSE;
 
@@ -5654,7 +5832,7 @@ static void dungeon(bool load_game)
        {
                if (load_game)
                {
-                       p_ptr->energy = 100;
+                       p_ptr->energy_need = 0;
                        battle_monsters();
                }
                else
@@ -5673,7 +5851,7 @@ msg_print("
                p_ptr->magic_num1[0] = MUSIC_DETECT;
 
        /* Hack -- notice death or departure */
-       if (!alive || death) return;
+       if (!p_ptr->playing || p_ptr->is_dead) return;
 
        /* Print quest message if appropriate */
        if (!p_ptr->inside_quest && (dungeon_type == DUNGEON_ANGBAND))
@@ -5705,7 +5883,10 @@ msg_print("
 
        hack_mind = TRUE;
 
-       if (p_ptr->energy < 100 && !p_ptr->inside_battle && (dun_level || p_ptr->leaving_dungeon || p_ptr->inside_arena)) p_ptr->energy = 100;
+       if (p_ptr->energy_need > 0 && !p_ptr->inside_battle &&
+           (dun_level || p_ptr->leaving_dungeon || p_ptr->inside_arena))
+               p_ptr->energy_need = 0;
+
        /* Not leaving dungeon */
        p_ptr->leaving_dungeon = FALSE;
 
@@ -5761,7 +5942,7 @@ msg_print("
                if (fresh_after) Term_fresh();
 
                /* Hack -- Notice death or departure */
-               if (!alive || death) break;
+               if (!p_ptr->playing || p_ptr->is_dead) break;
 
                /* Process all of the monsters */
                process_monsters();
@@ -5785,7 +5966,7 @@ msg_print("
                if (fresh_after) Term_fresh();
 
                /* Hack -- Notice death or departure */
-               if (!alive || death) break;
+               if (!p_ptr->playing || p_ptr->is_dead) break;
 
 
                /* Process the world */
@@ -5810,7 +5991,7 @@ msg_print("
                if (fresh_after) Term_fresh();
 
                /* Hack -- Notice death or departure */
-               if (!alive || death) break;
+               if (!p_ptr->playing || p_ptr->is_dead) break;
 
                /* Handle "leaving" */
                if (p_ptr->leaving) break;
@@ -5829,26 +6010,27 @@ msg_print("
                r_info[quest[quest_num].r_idx].flags1 &= ~RF1_QUESTOR;
        }
 
-       if (alive) {
-               if (p_ptr->riding)
-               {
-                       COPY(&riding_mon, &m_list[p_ptr->riding], monster_type);
-               }
-               else
+       /* Not save-and-quit and not dead? */
+       if (p_ptr->playing && !p_ptr->is_dead)
+       {
+               for(num = 0; num < 21; num++)
                {
-                       riding_mon.r_idx = 0;
+                       party_mon[num].r_idx = 0;
                }
-               for(num = 0; num < 20; num++)
+
+               if (p_ptr->riding)
                {
-                       party_mon[num].r_idx = 0;
+                       COPY(&party_mon[0], &m_list[p_ptr->riding], monster_type);
                }
-               for(i = m_max - 1, num = 0; (i >= 1 && num < 20); i--)
+
+               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;
@@ -5858,6 +6040,7 @@ msg_print("
                                if (distance(py, px, m_ptr->fy, m_ptr->fx) > 1) continue;
                        }
                        if (m_ptr->confused || m_ptr->stunned || m_ptr->csleep) continue;
+
                        COPY(&party_mon[num], &m_list[i], monster_type);
                        delete_monster_idx(i);
                        num++;
@@ -5879,7 +6062,6 @@ msg_print("
                        }
                }
        }
-       if (p_ptr->riding) p_ptr->riding = -1;
 
        write_level = TRUE;
 }
@@ -5894,6 +6076,19 @@ msg_print("
 static void load_all_pref_files(void)
 {
        char buf[1024];
+       errr err;
+
+       /* Access the "user" pref file */
+       sprintf(buf, "user.prf");
+
+       /* Process that file */
+       process_pref_file(buf);
+
+       /* Access the "user" system pref file */
+       sprintf(buf, "user-%s.prf", ANGBAND_SYS);
+
+       /* Process that file */
+       process_pref_file(buf);
 
        /* Access the "race" pref file */
        sprintf(buf, "%s.prf", rp_ptr->title);
@@ -5913,17 +6108,26 @@ static void load_all_pref_files(void)
        /* Process that file */
        process_pref_file(buf);
 
+       /* Free old entries */
+       init_autopicker();
+
 #ifdef JP
         sprintf(buf, "picktype-%s.prf", player_base);
 #else
         sprintf(buf, "pickpref-%s.prf", player_base);
 #endif
-       process_pickpref_file(buf);
+
+       err = process_pickpref_file(buf);
+
+       /* Process 'pick????.prf' if 'pick????-<name>.prf' doesn't exist */
+       if (0 > err)
+       {
 #ifdef JP
-       process_pickpref_file("picktype.prf");
+               process_pickpref_file("picktype.prf");
 #else
-       process_pickpref_file("pickpref.prf");
+               process_pickpref_file("pickpref.prf");
 #endif
+       }
 
        /* Access the "realm 1" pref file */
        if (p_ptr->realm1 != REALM_NONE)
@@ -5970,6 +6174,22 @@ void play_game(bool new_game)
        /* Hack -- Character is "icky" */
        character_icky = TRUE;
 
+       /* Make sure main term is active */
+       Term_activate(angband_term[0]);
+
+       /* Initialise the resize hooks */
+       angband_term[0]->resize_hook = resize_map;
+       
+       for (i = 1; i < 8; i++)
+       {
+               /* Does the term exist? */
+               if (angband_term[i])
+               {
+                       /* Add the redraw on resize hook */
+                       angband_term[i]->resize_hook = redraw_window;
+               }
+       }
+
        /* Hack -- turn off the cursor */
        (void)Term_set_cursor(0);
 
@@ -6012,15 +6232,15 @@ quit("
        }
 
        /* Report waited score */
-       if (wait_report_score)
+       if (p_ptr->wait_report_score)
        {
                char buf[1024];
                bool success;
 
 #ifdef JP
-               if (!get_check("ÂÔµ¡¤·¤Æ¤¤¤¿¥¹¥³¥¢ÅÐÏ¿¤òº£¹Ô¤Ê¤¤¤Þ¤¹¤«¡©"))
+               if (!get_check_strict("ÂÔµ¡¤·¤Æ¤¤¤¿¥¹¥³¥¢ÅÐÏ¿¤òº£¹Ô¤Ê¤¤¤Þ¤¹¤«¡©", CHECK_NO_HISTORY))
 #else
-               if (!get_check("Do you register score now? "))
+               if (!get_check_strict("Do you register score now? ", CHECK_NO_HISTORY))
 #endif
                        quit(0);
 
@@ -6030,7 +6250,7 @@ quit("
                /* Update stuff */
                update_stuff();
 
-               death = TRUE;
+               p_ptr->is_dead = TRUE;
 
                start_time = time(NULL);
 
@@ -6041,7 +6261,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);
@@ -6050,9 +6270,9 @@ quit("
                success = send_world_score(TRUE);
 
 #ifdef JP
-               if (!success && !get_check("¥¹¥³¥¢ÅÐÏ¿¤òÄü¤á¤Þ¤¹¤«¡©"))
+               if (!success && !get_check_strict("¥¹¥³¥¢ÅÐÏ¿¤òÄü¤á¤Þ¤¹¤«¡©", CHECK_NO_HISTORY))
 #else
-               if (!success && !get_check("Do you give up score registration? "))
+               if (!success && !get_check_strict("Do you give up score registration? ", CHECK_NO_HISTORY))
 #endif
                {
 #ifdef JP
@@ -6064,7 +6284,7 @@ quit("
                }
                else
                {
-                       wait_report_score = FALSE;
+                       p_ptr->wait_report_score = FALSE;
                        top_twenty();
 #ifdef JP
                        if (!save_player()) msg_print("¥»¡¼¥Ö¼ºÇÔ¡ª");
@@ -6137,16 +6357,16 @@ quit("
                /* Start in town */
                dun_level = 0;
                p_ptr->inside_quest = 0;
-               p_ptr->inside_arena = 0;
+               p_ptr->inside_arena = FALSE;
                p_ptr->inside_battle = FALSE;
 
                write_level = TRUE;
 
                /* Hack -- seed for flavors */
-               seed_flavor = rand_int(0x10000000);
+               seed_flavor = randint0(0x10000000);
 
                /* Hack -- seed for town layout */
-               seed_town = rand_int(0x10000000);
+               seed_town = randint0(0x10000000);
 
                /* Roll up a new character */
                player_birth();
@@ -6223,7 +6443,11 @@ quit("
                do_cmd_write_nikki(NIKKI_GAMESTART, 1, "                            ---- Restart Game ----");
 #endif
 
-               if (p_ptr->riding)
+/*
+ * 1.0.9 °ÊÁ°¤Ï¥»¡¼¥ÖÁ°¤Ë p_ptr->riding = -1 ¤È¤·¤Æ¤¤¤¿¤Î¤Ç¡¢ºÆÀßÄ꤬ɬÍפÀ¤Ã¤¿¡£
+ * ¤â¤¦ÉÔÍפÀ¤¬¡¢°ÊÁ°¤Î¥»¡¼¥Ö¥Õ¥¡¥¤¥ë¤È¤Î¸ß´¹¤Î¤¿¤á¤Ë»Ä¤·¤Æ¤ª¤¯¡£
+ */
+               if (p_ptr->riding == -1)
                {
                        p_ptr->riding = 0;
                        for(i = m_max; i > 0; i--)
@@ -6242,9 +6466,17 @@ quit("
        world_monster = FALSE;
        now_damaged = FALSE;
        now_message = 0;
-       start_time = time(NULL);
+       start_time = time(NULL) - 1;
        record_o_name[0] = '\0';
 
+       /* Reset map panel */
+       panel_row_min = cur_hgt;
+       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++)
         {
@@ -6277,7 +6509,6 @@ quit("
        if (new_game)
        {
                wipe_o_list();
-               wipe_m_list();
                player_outfit();
        }
 
@@ -6294,7 +6525,11 @@ prt("
 
 
        /* Hack -- Enter wizard mode */
-       if (arg_wizard && enter_wizard_mode()) 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)
@@ -6331,7 +6566,7 @@ if (init_v_info()) quit("
 
 
        /* Start game */
-       alive = TRUE;
+       p_ptr->playing = TRUE;
 
        /* Reset the visual mappings */
        reset_visuals();
@@ -6346,7 +6581,7 @@ if (init_v_info()) quit("
        p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_SPELL | PW_PLAYER);
 
        /* Window stuff */
-       p_ptr->window |= (PW_MONSTER);
+       p_ptr->window |= (PW_MESSAGE | PW_OVERHEAD | PW_DUNGEON | PW_MONSTER | PW_OBJECT);
 
        /* Window stuff */
        window_stuff();
@@ -6357,7 +6592,7 @@ if (init_v_info()) quit("
        if (arg_force_roguelike) rogue_like_commands = TRUE;
 
        /* Hack -- Enforce "delayed death" */
-       if (p_ptr->chp < 0) death = TRUE;
+       if (p_ptr->chp < 0) p_ptr->is_dead = TRUE;
 
        if (p_ptr->prace == RACE_ANDROID) calc_android_exp();
 
@@ -6366,31 +6601,19 @@ if (init_v_info()) quit("
                monster_type *m_ptr;
                int pet_r_idx = ((p_ptr->pclass == CLASS_CAVALRY) ? MON_HORSE : MON_YASE_HORSE);
                monster_race *r_ptr = &r_info[pet_r_idx];
-               place_monster_aux(py, px - 1, pet_r_idx,
-                                 FALSE, FALSE, TRUE, TRUE, TRUE, FALSE);
+               place_monster_aux(0, py, px - 1, pet_r_idx,
+                                 (PM_FORCE_PET | PM_NO_KAGE));
                m_ptr = &m_list[hack_m_idx_ii];
                m_ptr->mspeed = r_ptr->speed;
                m_ptr->maxhp = r_ptr->hdice*(r_ptr->hside+1)/2;
                m_ptr->max_maxhp = m_ptr->maxhp;
                m_ptr->hp = r_ptr->hdice*(r_ptr->hside+1)/2;
-               m_ptr->energy = -100;
+               m_ptr->energy_need = ENERGY_NEED() + ENERGY_NEED();
        }
 
        /* Process */
        while (TRUE)
        {
-#ifdef USE_SCRIPT
-               /* Save the current coordinates */
-               s32b wild_y = p_ptr->wilderness_y;
-               s32b wild_x = p_ptr->wilderness_x;
-               s16b level = dun_level;
-
-               if (level == 0)
-                       enter_wilderness_callback(wild_y, wild_x);
-               else
-                       enter_level_callback(level);
-#endif /* USE_SCRIPT */
-
                /* Process the level */
                dungeon(load_game);
 
@@ -6424,11 +6647,11 @@ if (init_v_info()) quit("
                clear_mon_lite();
 
                /* Handle "quit and save" */
-               if (!alive && !death) break;
+               if (!p_ptr->playing && !p_ptr->is_dead) break;
 
                /* Erase the old cave */
                wipe_o_list();
-               if (!death) wipe_m_list();
+               if (!p_ptr->is_dead) wipe_m_list();
 
 
                /* XXX XXX XXX */
@@ -6436,15 +6659,8 @@ if (init_v_info()) quit("
 
                load_game = FALSE;
 
-#ifdef USE_SCRIPT
-               if (level == 0)
-                       leave_wilderness_callback(wild_y, wild_x);
-               else
-                       leave_level_callback(level);
-#endif /* USE_SCRIPT */
-
                /* Accidental Death */
-               if (alive && death)
+               if (p_ptr->playing && p_ptr->is_dead)
                {
                        if (p_ptr->inside_arena)
                        {
@@ -6453,7 +6669,7 @@ if (init_v_info()) quit("
                                        p_ptr->arena_number++;
                                else
                                        p_ptr->arena_number = 99;
-                               death = FALSE;
+                               p_ptr->is_dead = FALSE;
                                p_ptr->chp = 0;
                                p_ptr->chp_frac = 0;
                                p_ptr->exit_bldg = TRUE;
@@ -6463,9 +6679,9 @@ if (init_v_info()) quit("
                        {
                                /* Mega-Hack -- Allow player to cheat death */
 #ifdef JP
-if ((wizard || cheat_live) && !get_check("»à¤Ë¤Þ¤¹¤«? "))
+if ((p_ptr->wizard || cheat_live) && !get_check("»à¤Ë¤Þ¤¹¤«? "))
 #else
-                               if ((wizard || cheat_live) && !get_check("Die? "))
+                               if ((p_ptr->wizard || cheat_live) && !get_check("Die? "))
 #endif
 
                                {
@@ -6476,7 +6692,7 @@ if ((wizard || cheat_live) && !get_check("
                                        p_ptr->age++;
 
                                        /* Mark savefile */
-                                       noscore |= 0x0001;
+                                       p_ptr->noscore |= 0x0001;
 
                                        /* Message */
 #ifdef JP
@@ -6494,11 +6710,11 @@ msg_print("
 
                                        if (p_ptr->pclass == CLASS_MAGIC_EATER)
                                        {
-                                               for (i = 0; i < 72; i++)
+                                               for (i = 0; i < EATER_EXT*2; i++)
                                                {
-                                                       p_ptr->magic_num1[i] = p_ptr->magic_num2[i]*0x10000;
+                                                       p_ptr->magic_num1[i] = p_ptr->magic_num2[i]*EATER_CHARGE;
                                                }
-                                               for (; i < 108; i++)
+                                               for (; i < EATER_EXT*3; i++)
                                                {
                                                        p_ptr->magic_num1[i] = 0;
                                                }
@@ -6539,18 +6755,18 @@ msg_print("ĥ
 
                                        /* Note cause of death XXX XXX XXX */
 #ifdef JP
-(void)strcpy(died_from, "»à¤Îµ½¤­");
+(void)strcpy(p_ptr->died_from, "»à¤Îµ½¤­");
 #else
-                                       (void)strcpy(died_from, "Cheating death");
+                                       (void)strcpy(p_ptr->died_from, "Cheating death");
 #endif
 
 
                                        /* Do not die */
-                                       death = FALSE;
+                                       p_ptr->is_dead = FALSE;
 
                                        dun_level = 0;
-                                       p_ptr->inside_arena = 0;
-                                       p_ptr->inside_battle = 0;
+                                       p_ptr->inside_arena = FALSE;
+                                       p_ptr->inside_battle = FALSE;
                                        leaving_quest = 0;
                                        p_ptr->inside_quest = 0;
                                        p_ptr->recall_dungeon = dungeon_type;
@@ -6592,7 +6808,7 @@ msg_print("ĥ
                }
 
                /* Handle "death" */
-               if (death) break;
+               if (p_ptr->is_dead) break;
 
                /* Make a new level */
                generate_cave();
@@ -6611,7 +6827,7 @@ s32b turn_real(s32b hoge)
            (p_ptr->prace == RACE_SKELETON) ||
            (p_ptr->prace == RACE_ZOMBIE) ||
            (p_ptr->prace == RACE_SPECTRE))
-               return hoge-(60L * TOWN_DAWN) / 4;
+               return hoge-(TURNS_PER_TICK * TOWN_DAWN *3/ 4);
        else
                return hoge;
 }