OSDN Git Service

Vanillaにならって、キャラクターの状態を表わすグローバル変数の多くを
[hengband/hengband.git] / src / cmd2.c
index 0275afa..7471da3 100644 (file)
@@ -44,29 +44,9 @@ void do_cmd_go_up(void)
 #endif
 
 
-               leaving_quest = p_ptr->inside_quest;
-               p_ptr->inside_quest = c_ptr->special;
-
-               /* 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);
-               }
+               leave_quest_check();
 
-#ifdef USE_SCRIPT
-               if (cmd_go_up_callback()) return;
-#endif /* USE_SCRIPT */
+               p_ptr->inside_quest = c_ptr->special;
 
                /* Activate the quest */
                if (!quest[p_ptr->inside_quest].status)
@@ -120,31 +100,11 @@ if (get_check("
 
                        if (autosave_l) do_cmd_save_game(TRUE);
 
-#ifdef USE_SCRIPT
-                       if (cmd_go_up_callback()) return;
-#endif /* USE_SCRIPT */
-
                        if (p_ptr->inside_quest)
                        {
-                               leaving_quest = p_ptr->inside_quest;
-                               if (quest[leaving_quest].type != QUEST_TYPE_RANDOM) dun_level = 1;
+                               if (quest[p_ptr->inside_quest].type != QUEST_TYPE_RANDOM) dun_level = 1;
 
-                               /* 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);
-                               }
+                               leave_quest_check();
 
                                p_ptr->inside_quest = c_ptr->special;
                        }
@@ -258,24 +218,7 @@ void do_cmd_go_down(void)
 #endif
 
 
-               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);
-               }
+               leave_quest_check();
 
                p_ptr->inside_quest = c_ptr->special;
 
@@ -368,7 +311,7 @@ if (get_check("
                        /* Go down */
                        if (c_ptr->feat == FEAT_MORE_MORE) down_num += 2;
                        else down_num += 1;
-                       if (!quest_number(dun_level+down_num) && (dun_level < d_info[dungeon_type].maxdepth - 1 - down_num) && one_in_(13) && !fall_trap && dun_level)
+                       if (!quest_number(dun_level+down_num) && (dun_level < d_info[dungeon_type].maxdepth - 1 - down_num) && one_in_(13) && !fall_trap && dun_level && !ironman_downward)
                        {
                                down_num++;
 #ifdef JP
@@ -470,16 +413,6 @@ void do_cmd_search(void)
        /* Take a turn */
        energy_use = 100;
 
-#ifdef USE_SCRIPT
-       if (cmd_search_callback(py, px))
-       {
-               /* Disturb */
-               disturb(0, 0);
-
-               return;
-       }
-#endif /* USE_SCRIPT */
-
        /* Search */
        search();
 }
@@ -577,7 +510,7 @@ static void chest_death(bool scatter, int y, int x, s16b o_idx)
                object_wipe(q_ptr);
 
                /* Small chests often drop gold */
-               if (small && (rand_int(100) < 25))
+               if (small && (randint0(100) < 25))
                {
                        /* Make some gold */
                        if (!make_gold(q_ptr)) continue;
@@ -590,10 +523,6 @@ static void chest_death(bool scatter, int y, int x, s16b o_idx)
                        if (!make_object(q_ptr, TRUE, great)) continue;
                }
 
-#ifdef USE_SCRIPT
-               q_ptr->python = object_create_callback(q_ptr);
-#endif /* USE_SCRIPT */
-
                /* If chest scatters its contents, pick any floor square. */
                if (scatter)
                {
@@ -601,8 +530,8 @@ static void chest_death(bool scatter, int y, int x, s16b o_idx)
                        for (i = 0; i < 200; i++)
                        {
                                /* Pick a totally random spot. */
-                               y = rand_int(MAX_HGT);
-                               x = rand_int(MAX_WID);
+                               y = randint0(MAX_HGT);
+                               x = randint0(MAX_WID);
 
                                /* Must be an empty floor. */
                                if (!cave_empty_bold(y, x)) continue;
@@ -691,7 +620,7 @@ static void chest_trap(int y, int x, s16b o_idx)
 
                if (!(p_ptr->resist_pois || p_ptr->oppose_pois))
                {
-                       (void)set_poisoned(p_ptr->poisoned + 10 + randint(20));
+                       (void)set_poisoned(p_ptr->poisoned + 10 + randint1(20));
                }
        }
 
@@ -707,14 +636,14 @@ static void chest_trap(int y, int x, s16b o_idx)
 
                if (!p_ptr->free_act)
                {
-                       (void)set_paralyzed(p_ptr->paralyzed + 10 + randint(20));
+                       (void)set_paralyzed(p_ptr->paralyzed + 10 + randint1(20));
                }
        }
 
        /* Summon monsters */
        if (trap & (CHEST_SUMMON))
        {
-               int num = 2 + randint(3);
+               int num = 2 + randint1(3);
 #ifdef JP
                msg_print("ÆÍÇ¡¿á¤­½Ð¤·¤¿±ì¤ËÊñ¤ß¹þ¤Þ¤ì¤¿¡ª");
 #else
@@ -724,10 +653,10 @@ static void chest_trap(int y, int x, s16b o_idx)
 
                for (i = 0; i < num; i++)
                {
-                       if (randint(100)<dun_level)
+                       if (randint1(100)<dun_level)
                                activate_hi_summon(py, px, FALSE);
                        else
-                               (void)summon_specific(0, y, x, mon_level, 0, TRUE, FALSE, FALSE, TRUE, TRUE);
+                               (void)summon_specific(0, y, x, mon_level, 0, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
                }
        }
 
@@ -739,9 +668,9 @@ static void chest_trap(int y, int x, s16b o_idx)
 #else
                msg_print("Elemental beings appear to protect their treasures!");
 #endif
-               for (i = 0; i < randint(3) + 5; i++)
+               for (i = 0; i < randint1(3) + 5; i++)
                {
-                       (void)summon_specific(0, y, x, mon_level, SUMMON_ELEMENTAL, TRUE, FALSE, FALSE, TRUE, TRUE);
+                       (void)summon_specific(0, y, x, mon_level, SUMMON_ELEMENTAL, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
                }
        }
 
@@ -754,12 +683,12 @@ static void chest_trap(int y, int x, s16b o_idx)
                msg_print("A storm of birds swirls around you!");
 #endif
 
-               for (i = 0; i < randint(3) + 3; i++)
+               for (i = 0; i < randint1(3) + 3; i++)
                        (void)fire_meteor(-1, GF_FORCE, y, x, o_ptr->pval / 5, 7);
 
-               for (i = 0; i < randint(5) + o_ptr->pval / 5; i++)
+               for (i = 0; i < randint1(5) + o_ptr->pval / 5; i++)
                {
-                       (void)summon_specific(0, y, x, mon_level, SUMMON_BIRD, TRUE, FALSE, FALSE, TRUE, TRUE);
+                       (void)summon_specific(0, y, x, mon_level, SUMMON_BIRD, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
                }
        }
 
@@ -767,7 +696,7 @@ static void chest_trap(int y, int x, s16b o_idx)
        if (trap & (CHEST_H_SUMMON))
        {
                /* Summon demons. */
-               if (rand_int(4) == 0)
+               if (one_in_(4))
                {
 #ifdef JP
                        msg_print("±ê¤Èⲫ¤Î±À¤ÎÃæ¤Ë°­Ë⤬»Ñ¤ò¸½¤·¤¿¡ª");
@@ -775,15 +704,15 @@ static void chest_trap(int y, int x, s16b o_idx)
                        msg_print("Demons materialize in clouds of fire and brimstone!");
 #endif
 
-                       for (i = 0; i < randint(3) + 2; i++)
+                       for (i = 0; i < randint1(3) + 2; i++)
                        {
                                (void)fire_meteor(-1, GF_FIRE, y, x, 10, 5);
-                               (void)summon_specific(0, y, x, mon_level, SUMMON_DEMON, TRUE, FALSE, FALSE, TRUE, TRUE);
+                               (void)summon_specific(0, y, x, mon_level, SUMMON_DEMON, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
                        }
                }
 
                /* Summon dragons. */
-               else if (rand_int(3) == 0)
+               else if (one_in_(3))
                {
 #ifdef JP
                        msg_print("°Å°Ç¤Ë¥É¥é¥´¥ó¤Î±Æ¤¬¤Ü¤ó¤ä¤ê¤È¸½¤ì¤¿¡ª");
@@ -791,14 +720,14 @@ static void chest_trap(int y, int x, s16b o_idx)
                        msg_print("Draconic forms loom out of the darkness!");
 #endif
 
-                       for (i = 0; i < randint(3) + 2; i++)
+                       for (i = 0; i < randint1(3) + 2; i++)
                        {
-                               (void)summon_specific(0, y, x, mon_level, SUMMON_DRAGON, TRUE, FALSE, FALSE, TRUE, TRUE);
+                               (void)summon_specific(0, y, x, mon_level, SUMMON_DRAGON, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
                        }
                }
 
                /* Summon hybrids. */
-               else if (rand_int(2) == 0)
+               else if (one_in_(2))
                {
 #ifdef JP
                        msg_print("´ñ̯¤Ê»Ñ¤Î²øʪ¤¬½±¤Ã¤ÆÍ褿¡ª");
@@ -806,9 +735,9 @@ static void chest_trap(int y, int x, s16b o_idx)
                        msg_print("Creatures strange and twisted assault you!");
 #endif
 
-                       for (i = 0; i < randint(5) + 3; i++)
+                       for (i = 0; i < randint1(5) + 3; i++)
                        {
-                               (void)summon_specific(0, y, x, mon_level, SUMMON_HYBRID, TRUE, FALSE, FALSE, TRUE, TRUE);
+                               (void)summon_specific(0, y, x, mon_level, SUMMON_HYBRID, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
                        }
                }
 
@@ -821,9 +750,9 @@ static void chest_trap(int y, int x, s16b o_idx)
                        msg_print("Vortices coalesce and wreak destruction!");
 #endif
 
-                       for (i = 0; i < randint(3) + 2; i++)
+                       for (i = 0; i < randint1(3) + 2; i++)
                        {
-                               (void)summon_specific(0, y, x, mon_level, SUMMON_VORTEX, TRUE, FALSE, FALSE, TRUE, TRUE);
+                               (void)summon_specific(0, y, x, mon_level, SUMMON_VORTEX, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
                        }
                }
        }
@@ -832,7 +761,7 @@ static void chest_trap(int y, int x, s16b o_idx)
        if ((trap & (CHEST_RUNES_OF_EVIL)) && o_ptr->k_idx)
        {
                /* Determine how many nasty tricks can be played. */
-               int nasty_tricks_count = 4 + rand_int(3);
+               int nasty_tricks_count = 4 + randint0(3);
 
                /* Message. */
 #ifdef JP
@@ -845,25 +774,25 @@ static void chest_trap(int y, int x, s16b o_idx)
                for (; nasty_tricks_count > 0; nasty_tricks_count--)
                {
                        /* ...but a high saving throw does help a little. */
-                       if (randint(100+o_ptr->pval*2) > p_ptr->skill_sav)
+                       if (randint1(100+o_ptr->pval*2) > p_ptr->skill_sav)
                        {
 #ifdef JP
-                               if (rand_int(6) == 0) take_hit(DAMAGE_NOESCAPE, damroll(5, 20), "ÇËÌǤΥȥé¥Ã¥×¤ÎÊõÈ¢", -1);
+                               if (one_in_(6)) take_hit(DAMAGE_NOESCAPE, damroll(5, 20), "ÇËÌǤΥȥé¥Ã¥×¤ÎÊõÈ¢", -1);
 #else
-                               if (rand_int(6) == 0) take_hit(DAMAGE_NOESCAPE, damroll(5, 20), "a chest dispel-player trap", -1);
+                               if (one_in_(6)) take_hit(DAMAGE_NOESCAPE, damroll(5, 20), "a chest dispel-player trap", -1);
 #endif
-                               else if (rand_int(5) == 0) (void)set_cut(p_ptr->cut + 200);
-                               else if (rand_int(4) == 0)
+                               else if (one_in_(5)) (void)set_cut(p_ptr->cut + 200);
+                               else if (one_in_(4))
                                {
                                        if (!p_ptr->free_act) 
                                                (void)set_paralyzed(p_ptr->paralyzed + 2 + 
-                                               rand_int(6));
+                                               randint0(6));
                                        else 
                                                (void)set_stun(p_ptr->stun + 10 + 
-                                               rand_int(100));
+                                               randint0(100));
                                }
-                               else if (rand_int(3) == 0) apply_disenchant(0);
-                               else if (rand_int(2) == 0)
+                               else if (one_in_(3)) apply_disenchant(0);
+                               else if (one_in_(2))
                                {
                                        (void)do_dec_stat(A_STR);
                                        (void)do_dec_stat(A_DEX);
@@ -877,6 +806,17 @@ static void chest_trap(int y, int x, s16b o_idx)
                }
        }
 
+       /* Aggravate monsters. */
+       if (trap & (CHEST_ALARM))
+       {
+#ifdef JP
+               msg_print("¤±¤¿¤¿¤Þ¤·¤¤²»¤¬ÌĤê¶Á¤¤¤¿¡ª");
+#else
+               msg_print("An alarm sounds!");
+#endif
+               aggravate_monsters(0);
+       }
+
        /* Explode */
        if ((trap & (CHEST_EXPLODE)) && o_ptr->k_idx)
        {
@@ -952,7 +892,7 @@ static bool do_cmd_open_chest(int y, int x, s16b o_idx)
                if (j < 2) j = 2;
 
                /* Success -- May still have traps */
-               if (rand_int(100) < j)
+               if (randint0(100) < j)
                {
 #ifdef JP
                        msg_print("¸°¤ò¤Ï¤º¤·¤¿¡£");
@@ -1171,7 +1111,7 @@ static bool do_cmd_open_aux(int y, int x, int dir)
                if (j < 2) j = 2;
 
                /* Success */
-               if (rand_int(100) < j)
+               if (randint0(100) < j)
                {
                        /* Message */
 #ifdef JP
@@ -1296,15 +1236,6 @@ void do_cmd_open(void)
                y = py + ddy[dir];
                x = px + ddx[dir];
 
-#ifdef USE_SCRIPT
-               if (cmd_open_callback(y, x))
-               {
-                       /* Don't repeat the action */
-                       disturb(0, 0);
-                       return;
-               }
-#endif /* USE_SCRIPT */
-
                /* Get requested grid */
                c_ptr = &cave[y][x];
 
@@ -1326,7 +1257,7 @@ void do_cmd_open(void)
                }
 
                /* Monster in the way */
-               else if (c_ptr->m_idx)
+               else if (c_ptr->m_idx && p_ptr->riding != c_ptr->m_idx)
                {
                        /* Take a turn */
                        energy_use = 100;
@@ -1571,8 +1502,6 @@ static bool twall(int y, int x, byte feat)
 
        /* Forget the wall */
        c_ptr->info &= ~(CAVE_MARK);
-       c_ptr->info &= ~(CAVE_MASK);
-       c_ptr->info |= (CAVE_FLOOR);
 
        /* Remove the feature */
        cave_set_feat(y, x, feat);
@@ -1640,7 +1569,7 @@ static bool do_cmd_tunnel_aux(int y, int x, int dir)
        else if (c_ptr->feat == FEAT_TREES) /* -KMW- */
        {
                /* Chop Down */
-               if ((p_ptr->skill_dig > 10 + rand_int(400)) && twall(y, x, FEAT_GRASS))
+               if ((p_ptr->skill_dig > 10 + randint0(400)) && twall(y, x, FEAT_GRASS))
                {
 #ifdef JP
                        msg_print("ÌÚ¤òÀÚ¤êʧ¤Ã¤¿¡£");
@@ -1664,7 +1593,7 @@ static bool do_cmd_tunnel_aux(int y, int x, int dir)
                        more = TRUE;
 
                        /* Occasional Search XXX XXX */
-                       if (rand_int(100) < 25) search();
+                       if (randint0(100) < 25) search();
                }
        }
 
@@ -1674,7 +1603,7 @@ static bool do_cmd_tunnel_aux(int y, int x, int dir)
                 (c_ptr->feat <= FEAT_WALL_SOLID))
        {
                /* Tunnel */
-               if ((p_ptr->skill_dig > 40 + rand_int(1600)) && twall(y, x, floor_type[rand_int(100)]))
+               if ((p_ptr->skill_dig > 40 + randint0(1600)) && twall(y, x, floor_type[randint0(100)]))
                {
 #ifdef JP
                        msg_print("·ê¤ò·¡¤ê½ª¤¨¤¿¡£");
@@ -1717,17 +1646,17 @@ static bool do_cmd_tunnel_aux(int y, int x, int dir)
                /* Quartz */
                if (hard)
                {
-                       okay = (p_ptr->skill_dig > 20 + rand_int(800));
+                       okay = (p_ptr->skill_dig > 20 + randint0(800));
                }
 
                /* Magma */
                else
                {
-                       okay = (p_ptr->skill_dig > 10 + rand_int(400));
+                       okay = (p_ptr->skill_dig > 10 + randint0(400));
                }
 
                /* Success */
-               if (okay && twall(y, x, floor_type[rand_int(100)]))
+               if (okay && twall(y, x, floor_type[randint0(100)]))
                {
                        /* Found treasure */
                        if (gold)
@@ -1789,7 +1718,7 @@ static bool do_cmd_tunnel_aux(int y, int x, int dir)
        else if (c_ptr->feat == FEAT_RUBBLE)
        {
                /* Remove the rubble */
-               if ((p_ptr->skill_dig > rand_int(200)) && twall(y, x, floor_type[rand_int(100)]))
+               if ((p_ptr->skill_dig > randint0(200)) && twall(y, x, floor_type[randint0(100)]))
                {
                        /* Message */
 #ifdef JP
@@ -1799,7 +1728,7 @@ static bool do_cmd_tunnel_aux(int y, int x, int dir)
 #endif
 
                        /* Hack -- place an object */
-                       if (rand_int(100) < (15 - dun_level/2))
+                       if (randint0(100) < (15 - dun_level/2))
                        {
                                /* Create a simple object */
                                place_object(y, x, FALSE, FALSE);
@@ -1834,7 +1763,7 @@ static bool do_cmd_tunnel_aux(int y, int x, int dir)
        else if (c_ptr->feat >= FEAT_SECRET)
        {
                /* Tunnel */
-               if ((p_ptr->skill_dig > 30 + rand_int(1200)) && twall(y, x, floor_type[rand_int(100)]))
+               if ((p_ptr->skill_dig > 30 + randint0(1200)) && twall(y, x, floor_type[randint0(100)]))
                {
 #ifdef JP
                        msg_print("·ê¤ò·¡¤ê½ª¤¨¤¿¡£");
@@ -1857,7 +1786,7 @@ static bool do_cmd_tunnel_aux(int y, int x, int dir)
                        more = TRUE;
 
                        /* Occasional Search XXX XXX */
-                       if (rand_int(100) < 25) search();
+                       if (randint0(100) < 25) search();
                }
        }
 
@@ -1865,7 +1794,7 @@ static bool do_cmd_tunnel_aux(int y, int x, int dir)
        else
        {
                /* Tunnel */
-               if ((p_ptr->skill_dig > 30 + rand_int(1200)) && twall(y, x, floor_type[randint(100)]))
+               if ((p_ptr->skill_dig > 30 + randint0(1200)) && twall(y, x, floor_type[randint1(100)]))
                {
 #ifdef JP
                        msg_print("·ê¤ò·¡¤ê½ª¤¨¤¿¡£");
@@ -2075,7 +2004,7 @@ bool easy_open_door(int y, int x)
                if (j < 2) j = 2;
 
                /* Success */
-               if (rand_int(100) < j)
+               if (randint0(100) < j)
                {
                        /* Message */
 #ifdef JP
@@ -2202,7 +2131,7 @@ static bool do_cmd_disarm_chest(int y, int x, s16b o_idx)
        }
 
        /* Success (get a lot of experience) */
-       else if (rand_int(100) < j)
+       else if (randint0(100) < j)
        {
 #ifdef JP
                msg_print("È¢¤Ë»Å³Ý¤±¤é¤ì¤Æ¤¤¤¿¥È¥é¥Ã¥×¤ò²ò½ü¤·¤¿¡£");
@@ -2215,7 +2144,7 @@ static bool do_cmd_disarm_chest(int y, int x, s16b o_idx)
        }
 
        /* Failure -- Keep trying */
-       else if ((i > 5) && (randint(i) > 5))
+       else if ((i > 5) && (randint1(i) > 5))
        {
                /* We may keep trying */
                more = TRUE;
@@ -2302,7 +2231,7 @@ static bool do_cmd_disarm_aux(int y, int x, int dir)
        if (j < 2) j = 2;
 
        /* Success */
-       if (rand_int(100) < j)
+       if (randint0(100) < j)
        {
                /* Message */
 #ifdef JP
@@ -2319,9 +2248,7 @@ static bool do_cmd_disarm_aux(int y, int x, int dir)
                c_ptr->info &= ~(CAVE_MARK);
 
                /* Remove the trap */
-               c_ptr->feat = floor_type[rand_int(100)];
-               c_ptr->info &= ~(CAVE_MASK);
-               c_ptr->info |= CAVE_FLOOR;
+               c_ptr->feat = floor_type[randint0(100)];
                note_spot(y, x);
                lite_spot(y, x);
 
@@ -2339,7 +2266,7 @@ static bool do_cmd_disarm_aux(int y, int x, int dir)
        }
 
        /* Failure -- Keep trying */
-       else if ((i > 5) && (randint(i) > 5))
+       else if ((i > 5) && (randint1(i) > 5))
        {
                /* Failure */
                if (flush_failure) flush();
@@ -2466,7 +2393,7 @@ void do_cmd_disarm(void)
                }
 
                /* Monster in the way */
-               else if (c_ptr->m_idx)
+               else if (c_ptr->m_idx && p_ptr->riding != c_ptr->m_idx)
                {
                        /* Message */
 #ifdef JP
@@ -2548,7 +2475,7 @@ static bool do_cmd_bash_aux(int y, int x, int dir)
        if (temp < 1) temp = 1;
 
        /* Hack -- attempt to bash down the door */
-       if (rand_int(100) < temp)
+       if (randint0(100) < temp)
        {
                /* Message */
 #ifdef JP
@@ -2559,7 +2486,7 @@ static bool do_cmd_bash_aux(int y, int x, int dir)
 
 
                /* Break down the door */
-               if (rand_int(100) < 50)
+               if (randint0(100) < 50)
                {
                        cave_set_feat(y, x, FEAT_BROKEN);
                }
@@ -2582,7 +2509,7 @@ static bool do_cmd_bash_aux(int y, int x, int dir)
        }
 
        /* Saving throw against stun */
-       else if (rand_int(100) < adj_dex_safe[p_ptr->stat_ind[A_DEX]] +
+       else if (randint0(100) < adj_dex_safe[p_ptr->stat_ind[A_DEX]] +
                 p_ptr->lev)
        {
                /* Message */
@@ -2609,7 +2536,7 @@ static bool do_cmd_bash_aux(int y, int x, int dir)
 
 
                /* Hack -- Lose balance ala paralysis */
-               (void)set_paralyzed(p_ptr->paralyzed + 2 + rand_int(2));
+               (void)set_paralyzed(p_ptr->paralyzed + 2 + randint0(2));
        }
 
        /* Result */
@@ -3012,7 +2939,7 @@ void do_cmd_walk(int pickup)
                int tmp = 120 + p_ptr->lev*10 - wilderness[py][px].level + 5;
                if (tmp < 1) 
                        tmp = 1;
-               if (((wilderness[py][px].level + 5) > (p_ptr->lev / 2)) && rand_int(tmp) < (21-p_ptr->skill_stl))
+               if (((wilderness[py][px].level + 5) > (p_ptr->lev / 2)) && randint0(tmp) < (21-p_ptr->skill_stl))
                {
                        /* Inform the player of his horrible fate :=) */
 #ifdef JP
@@ -3024,8 +2951,8 @@ void do_cmd_walk(int pickup)
                        /* Go into large wilderness view */
                        p_ptr->wilderness_x = px;
                        p_ptr->wilderness_y = py;
-                       p_ptr->oldpy = randint(MAX_HGT-2);
-                       p_ptr->oldpx = randint(MAX_WID-2);
+                       p_ptr->oldpy = randint1(MAX_HGT-2);
+                       p_ptr->oldpx = randint1(MAX_WID-2);
                        energy_use = 100;
                        change_wild_mode();
 
@@ -3105,7 +3032,7 @@ void do_cmd_stay(int pickup)
 
 
        /* Spontaneous Searching */
-       if ((p_ptr->skill_fos >= 50) || (0 == rand_int(50 - p_ptr->skill_fos)))
+       if ((p_ptr->skill_fos >= 50) || (0 == randint0(50 - p_ptr->skill_fos)))
        {
                search();
        }
@@ -3131,7 +3058,7 @@ void do_cmd_stay(int pickup)
 
                energy_use = 0;
                /* Hack -- enter store */
-               command_new = 253;
+               command_new = SPECIAL_KEY_STORE;
        }
 
        /* Hack -- enter a building if we are on one -KMW- */
@@ -3143,7 +3070,7 @@ void do_cmd_stay(int pickup)
 
                energy_use = 0;
                /* Hack -- enter building */
-               command_new = 254;
+               command_new = SPECIAL_KEY_BUILDING;
        }
 
        /* Exit a quest if reach the quest exit */
@@ -3165,24 +3092,7 @@ void do_cmd_stay(int pickup)
                        msg_print(NULL);
                }
 
-               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);
-               }
+               leave_quest_check();
 
                p_ptr->inside_quest = cave[py][px].special;
                dun_level = 0;
@@ -3329,7 +3239,7 @@ static int breakage_chance(object_type *o_ptr)
 }
 
 
-s16b tot_dam_aux_shot(object_type *o_ptr, int tdam, monster_type *m_ptr)
+static s16b tot_dam_aux_shot(object_type *o_ptr, int tdam, monster_type *m_ptr)
 {
        int mult = 10;
 
@@ -3371,6 +3281,18 @@ s16b tot_dam_aux_shot(object_type *o_ptr, int tdam, monster_type *m_ptr)
                                if (mult < 15) mult = 15;
                        }
 
+                       /* Slay Human */
+                       if ((f3 & TR3_SLAY_HUMAN) &&
+                           (r_ptr->flags2 & RF2_HUMAN))
+                       {
+                               if (m_ptr->ml)
+                               {
+                                       r_ptr->r_flags2 |= RF2_HUMAN;
+                               }
+
+                               if (mult < 17) mult = 17;
+                       }
+
                        /* Slay Undead */
                        if ((f1 & TR1_SLAY_UNDEAD) &&
                            (r_ptr->flags3 & RF3_UNDEAD))
@@ -3554,7 +3476,7 @@ s16b tot_dam_aux_shot(object_type *o_ptr, int tdam, monster_type *m_ptr)
                                }
                        }
 
-                       if ((f1 & TR1_FORCE_WEPON) && (p_ptr->csp > (p_ptr->msp / 30)))
+                       if ((f1 & TR1_FORCE_WEAPON) && (p_ptr->csp > (p_ptr->msp / 30)))
                        {
                                p_ptr->csp -= (1+(p_ptr->msp / 30));
                                p_ptr->redraw |= (PR_MANA);
@@ -3644,7 +3566,10 @@ void do_cmd_fire_aux(int item, object_type *j_ptr)
 
        /* Actually "fire" the object */
        bonus = (p_ptr->to_h_b + o_ptr->to_h + j_ptr->to_h);
-       chance = (p_ptr->skill_thb + ((weapon_exp[0][j_ptr->sval]-4000)/200 + bonus) * BTH_PLUS_ADJ);
+       if ((j_ptr->sval == SV_LIGHT_XBOW) || (j_ptr->sval == SV_HEAVY_XBOW))
+               chance = (p_ptr->skill_thb + ((p_ptr->weapon_exp[0][j_ptr->sval])/400 + bonus) * BTH_PLUS_ADJ);
+       else
+               chance = (p_ptr->skill_thb + ((p_ptr->weapon_exp[0][j_ptr->sval]-4000)/200 + bonus) * BTH_PLUS_ADJ);
 
        energy_use = bow_energy(j_ptr->sval);
        tmul = bow_tmul(j_ptr->sval);
@@ -3661,7 +3586,7 @@ void do_cmd_fire_aux(int item, object_type *j_ptr)
        /* Base range */
        tdis = 10 + tmul/40;
        if ((j_ptr->sval == SV_LIGHT_XBOW) || (j_ptr->sval == SV_HEAVY_XBOW))
-               tdis += 5;
+               tdis -= 5;
 
        project_length = tdis + 1;
 
@@ -3796,24 +3721,24 @@ void do_cmd_fire_aux(int item, object_type *j_ptr)
 
                        if ((r_ptr->level + 10) > p_ptr->lev)
                        {
-                               if (weapon_exp[0][j_ptr->sval] < s_info[p_ptr->pclass].w_max[0][j_ptr->sval])
+                               int now_exp = p_ptr->weapon_exp[0][j_ptr->sval];
+                               if (now_exp < s_info[p_ptr->pclass].w_max[0][j_ptr->sval])
                                {
-                                       if (weapon_exp[0][j_ptr->sval] < 4000)
-                                               weapon_exp[0][j_ptr->sval]+=80;
-                                       else if ((weapon_exp[0][j_ptr->sval] < 6000))
-                                               weapon_exp[0][j_ptr->sval]+=25;
-                                       else if ((weapon_exp[0][j_ptr->sval] < 7000) && (p_ptr->lev > 19))
-                                               weapon_exp[0][j_ptr->sval]+=10;
-                                       else if ((weapon_exp[0][j_ptr->sval] < 8000) && (p_ptr->lev > 34))
-                                               weapon_exp[0][j_ptr->sval]+=2;
+                                       int amount = 0;
+                                       if (now_exp < 4000) amount = 80;
+                                       else if (now_exp <  6000) amount = 25;
+                                       else if ((now_exp < 7000) && (p_ptr->lev > 19)) amount = 10;
+                                       else if (p_ptr->lev > 34) amount = 2;
+                                       p_ptr->weapon_exp[0][j_ptr->sval] += amount;
+                                       p_ptr->update |= (PU_BONUS);
                                }
                        }
 
                        if (p_ptr->riding)
                        {
-                               if (skill_exp[GINOU_RIDING] < s_info[p_ptr->pclass].s_max[GINOU_RIDING] && ((skill_exp[GINOU_RIDING] - 1000) / 200 < r_info[m_list[p_ptr->riding].r_idx].level) && one_in_(2))
+                               if (p_ptr->skill_exp[GINOU_RIDING] < s_info[p_ptr->pclass].s_max[GINOU_RIDING] && ((p_ptr->skill_exp[GINOU_RIDING] - 1000) / 200 < r_info[m_list[p_ptr->riding].r_idx].level) && one_in_(2))
                                {
-                                       skill_exp[GINOU_RIDING]+=1;
+                                       p_ptr->skill_exp[GINOU_RIDING]+=1;
                                        p_ptr->update |= (PU_BONUS);
                                }
                        }
@@ -3886,7 +3811,7 @@ note_dies = "
 
 
                                        /* Hack -- Track this monster race */
-                                       if (m_ptr->ml) monster_race_track((bool)(m_ptr->mflag2 & MFLAG_KAGE), m_ptr->r_idx);
+                                       if (m_ptr->ml) monster_race_track(m_ptr->ap_r_idx);
 
                                        /* Hack -- Track this monster */
                                        if (m_ptr->ml) health_track(c_ptr->m_idx);
@@ -3903,7 +3828,7 @@ note_dies = "
                                tdam = mon_damage_mod(m_ptr, tdam, FALSE);
 
                                /* Complex message */
-                               if (wizard || cheat_xtra)
+                               if (p_ptr->wizard || cheat_xtra)
                                {
 #ifdef JP
                                        msg_format("%d/%d ¤Î¥À¥á¡¼¥¸¤òÍ¿¤¨¤¿¡£",
@@ -3966,8 +3891,7 @@ note_dies = "
                                        }
                                        if (!projectable(m_ptr->fy, m_ptr->fx, py, px))
                                        {
-                                               m_ptr->target_y = py;
-                                               m_ptr->target_x = px;
+                                               set_target(m_ptr, py, px);
                                        }
                                }
                        }
@@ -4205,11 +4129,25 @@ bool do_cmd_throw_aux(int mult, bool boomerang, int shuriken)
                msg_print("Hmmm, it seems to be cursed.");
 #endif
 
-
                /* Nope */
                return FALSE;
        }
 
+       if (p_ptr->inside_arena)
+       {
+               if (o_ptr->tval != 5)
+               {
+#ifdef JP
+                       msg_print("¥¢¥ê¡¼¥Ê¤Ç¤Ï¥¢¥¤¥Æ¥à¤ò»È¤¨¤Ê¤¤¡ª");
+#else
+                       msg_print("You're in the arena now. This is hand-to-hand!");
+#endif
+                       msg_print(NULL);
+
+                       /* Nope */
+                       return FALSE;
+               }
+       }
 
        /* Get local object */
        q_ptr = &forge;
@@ -4247,8 +4185,8 @@ bool do_cmd_throw_aux(int mult, bool boomerang, int shuriken)
 
        if (shuriken)
        {
-               ty = rand_int(101)-50+py;
-               tx = rand_int(101)-50+px;
+               ty = randint0(101)-50+py;
+               tx = randint0(101)-50+px;
        }
        else
        {
@@ -4453,7 +4391,7 @@ note_dies = "
 
 
                                        /* Hack -- Track this monster race */
-                                       if (m_ptr->ml) monster_race_track((bool)(m_ptr->mflag2 & MFLAG_KAGE), m_ptr->r_idx);
+                                       if (m_ptr->ml) monster_race_track(m_ptr->ap_r_idx);
 
                                        /* Hack -- Track this monster */
                                        if (m_ptr->ml) health_track(c_ptr->m_idx);
@@ -4464,7 +4402,10 @@ note_dies = "
                                /* Apply special damage XXX XXX XXX */
                                tdam = tot_dam_aux(q_ptr, tdam, m_ptr, 0);
                                tdam = critical_shot(q_ptr->weight, q_ptr->to_h, tdam);
-                               tdam += q_ptr->to_d;
+                               if (q_ptr->to_d > 0)
+                                       tdam += q_ptr->to_d;
+                               else
+                                       tdam += -q_ptr->to_d;
 
                                if (boomerang)
                                {
@@ -4492,7 +4433,7 @@ note_dies = "
                                tdam = mon_damage_mod(m_ptr, tdam, FALSE);
 
                                /* Complex message */
-                               if (wizard)
+                               if (p_ptr->wizard)
                                {
 #ifdef JP
                                        msg_format("%d/%d¤Î¥À¥á¡¼¥¸¤òÍ¿¤¨¤¿¡£",
@@ -4555,15 +4496,15 @@ note_dies = "
        {
                j = 100;
 
-               if (!(summon_named_creature(y, x, q_ptr->pval, FALSE, FALSE, FALSE,
-                     (bool)!(q_ptr->ident & IDENT_CURSED))))
+               if (!(summon_named_creature(0, y, x, q_ptr->pval,
+                                           !(cursed_p(q_ptr)) ? PM_FORCE_PET : 0L)))
 #ifdef JP
 msg_print("¿Í·Á¤ÏDZ¤¸¶Ê¤¬¤êºÕ¤±»¶¤Ã¤Æ¤·¤Þ¤Ã¤¿¡ª");
 #else
                        msg_print("The Figurine writhes and then shatters.");
 #endif
 
-               else if (q_ptr->ident & IDENT_CURSED)
+               else if (cursed_p(q_ptr))
 #ifdef JP
 msg_print("¤³¤ì¤Ï¤¢¤Þ¤êÎɤ¯¤Ê¤¤µ¤¤¬¤¹¤ë¡£");
 #else
@@ -4576,7 +4517,7 @@ msg_print("
        /* Potions smash open */
        if (object_is_potion(q_ptr))
        {
-               if (hit_body || hit_wall || (randint(100) < j))
+               if (hit_body || hit_wall || (randint1(100) < j))
                {
                        /* Message */
 #ifdef JP
@@ -4616,16 +4557,16 @@ msg_print("
 
        if (return_when_thrown)
        {
-               int back_chance = randint(30)+20+((int)(adj_dex_th[p_ptr->stat_ind[A_DEX]]) - 128);
+               int back_chance = randint1(30)+20+((int)(adj_dex_th[p_ptr->stat_ind[A_DEX]]) - 128);
                char o2_name[MAX_NLEN];
                bool super_boomerang = (((q_ptr->name1 == ART_MJOLLNIR) || (q_ptr->name1 == ART_AEGISFANG)) && boomerang);
 
                j = -1;
-               if (boomerang) back_chance += 4+randint(5);
+               if (boomerang) back_chance += 4+randint1(5);
                if (super_boomerang) back_chance += 100;
                object_desc(o2_name, q_ptr, FALSE, 0);
 
-               if((back_chance > 30) && ((randint(100) != 1) || super_boomerang))
+               if((back_chance > 30) && (!one_in_(100) || super_boomerang))
                {
                        for (i = cur_dis-1;i>0;i--)
                        {