OSDN Git Service

Vanillaにならって、キャラクターの状態を表わすグローバル変数の多くを
[hengband/hengband.git] / src / spells3.c
index ab6b0ff..789741d 100644 (file)
@@ -49,7 +49,7 @@ bool teleport_away(int m_idx, int dis, bool dec_valour)
 
        if (dec_valour &&
            (((p_ptr->chp * 10) / p_ptr->mhp) > 5) &&
-               (4+randint(5) < ((p_ptr->chp * 10) / p_ptr->mhp)))
+               (4+randint1(5) < ((p_ptr->chp * 10) / p_ptr->mhp)))
        {       
                chg_virtue(V_VALOUR, -1);
        }
@@ -155,7 +155,7 @@ void teleport_to_player(int m_idx, int power)
        if (!m_ptr->r_idx) return;
 
        /* "Skill" test */
-       if (randint(100) > power) return;
+       if (randint1(100) > power) return;
 
        /* Initialize */
        ny = m_ptr->fy;
@@ -592,29 +592,13 @@ msg_print("
 
                if (!dun_level) dungeon_type = 0;
 
-               leaving_quest = p_ptr->inside_quest;
-
-               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();
 
                /* Leaving */
                p_ptr->inside_quest = 0;
                p_ptr->leaving = TRUE;
        }
-       else if (rand_int(100) < 50)
+       else if (randint0(100) < 50)
        {
 #ifdef JP
 msg_print("¤¢¤Ê¤¿¤ÏÅ·°æ¤òÆͤ­ÇˤäÆÃè¤ØÉ⤤¤Æ¤¤¤¯¡£");
@@ -812,7 +796,7 @@ msg_print("ĥ
 
 bool word_of_recall(void)
 {
-       return(recall_player(rand_int(21) + 15));
+       return(recall_player(randint0(21) + 15));
 }
 
 
@@ -882,8 +866,6 @@ msg_format("%s
  *
  * XXX XXX XXX This function is also called from the "melee" code
  *
- * The "mode" is currently unused.
- *
  * Return "TRUE" if the player notices anything
  */
 bool apply_disenchant(int mode)
@@ -891,14 +873,10 @@ bool apply_disenchant(int mode)
        int             t = 0;
        object_type     *o_ptr;
        char            o_name[MAX_NLEN];
-
-
-       /* Unused */
-       mode = mode;
-
+       int to_h, to_d, to_a, pval;
 
        /* Pick a random slot */
-       switch (randint(8))
+       switch (randint1(8))
        {
                case 1: t = INVEN_RARM; break;
                case 2: t = INVEN_LARM; break;
@@ -918,7 +896,7 @@ bool apply_disenchant(int mode)
 
 
        /* Nothing to disenchant */
-       if ((o_ptr->to_h <= 0) && (o_ptr->to_d <= 0) && (o_ptr->to_a <= 0))
+       if ((o_ptr->to_h <= 0) && (o_ptr->to_d <= 0) && (o_ptr->to_a <= 0) && (o_ptr->pval <= 1))
        {
                /* Nothing to notice */
                return (FALSE);
@@ -930,7 +908,7 @@ bool apply_disenchant(int mode)
 
 
        /* Artifacts have 71% chance to resist */
-       if ((artifact_p(o_ptr) || o_ptr->art_name) && (rand_int(100) < 71))
+       if ((artifact_p(o_ptr) || o_ptr->art_name) && (randint0(100) < 71))
        {
                /* Message */
 #ifdef JP
@@ -947,38 +925,52 @@ msg_format("%s(%c)
        }
 
 
+       /* Memorize old value */
+       to_h = o_ptr->to_h;
+       to_d = o_ptr->to_d;
+       to_a = o_ptr->to_a;
+       pval = o_ptr->pval;
+
        /* Disenchant tohit */
        if (o_ptr->to_h > 0) o_ptr->to_h--;
-       if ((o_ptr->to_h > 5) && (rand_int(100) < 20)) o_ptr->to_h--;
+       if ((o_ptr->to_h > 5) && (randint0(100) < 20)) o_ptr->to_h--;
 
        /* Disenchant todam */
        if (o_ptr->to_d > 0) o_ptr->to_d--;
-       if ((o_ptr->to_d > 5) && (rand_int(100) < 20)) o_ptr->to_d--;
+       if ((o_ptr->to_d > 5) && (randint0(100) < 20)) o_ptr->to_d--;
 
        /* Disenchant toac */
        if (o_ptr->to_a > 0) o_ptr->to_a--;
-       if ((o_ptr->to_a > 5) && (rand_int(100) < 20)) o_ptr->to_a--;
+       if ((o_ptr->to_a > 5) && (randint0(100) < 20)) o_ptr->to_a--;
 
-       /* Message */
+       /* Disenchant pval (occasionally) */
+       /* Unless called from wild_magic() */
+       if ((o_ptr->pval > 1) && one_in_(13) && !(mode & 0x01)) o_ptr->pval--;
+
+       if ((to_h != o_ptr->to_h) || (to_d != o_ptr->to_d) ||
+           (to_a != o_ptr->to_a) || (pval != o_ptr->pval))
+       {
+               /* Message */
 #ifdef JP
-msg_format("%s(%c)¤ÏÎô²½¤·¤Æ¤·¤Þ¤Ã¤¿¡ª",
-                   o_name, index_to_label(t) );
+               msg_format("%s(%c)¤ÏÎô²½¤·¤Æ¤·¤Þ¤Ã¤¿¡ª",
+                          o_name, index_to_label(t) );
 #else
-       msg_format("Your %s (%c) %s disenchanted!",
-                  o_name, index_to_label(t),
-                  ((o_ptr->number != 1) ? "were" : "was"));
+               msg_format("Your %s (%c) %s disenchanted!",
+                          o_name, index_to_label(t),
+                          ((o_ptr->number != 1) ? "were" : "was"));
 #endif
 
-       chg_virtue(V_HARMONY, 1);
-       chg_virtue(V_ENCHANT, -2);
+               chg_virtue(V_HARMONY, 1);
+               chg_virtue(V_ENCHANT, -2);
 
-       /* Recalculate bonuses */
-       p_ptr->update |= (PU_BONUS);
+               /* Recalculate bonuses */
+               p_ptr->update |= (PU_BONUS);
 
-       /* Window stuff */
-       p_ptr->window |= (PW_EQUIP | PW_PLAYER);
+               /* Window stuff */
+               p_ptr->window |= (PW_EQUIP | PW_PLAYER);
 
-       calc_android_exp();
+               calc_android_exp();
+       }
 
        /* Notice */
        return (TRUE);
@@ -990,8 +982,8 @@ void mutate_player(void)
        int max1, cur1, max2, cur2, ii, jj, i;
 
        /* Pick a pair of stats */
-       ii = rand_int(6);
-       for (jj = ii; jj == ii; jj = rand_int(6)) /* loop */;
+       ii = randint0(6);
+       for (jj = ii; jj == ii; jj = randint0(6)) /* loop */;
 
        max1 = p_ptr->stat_max[ii];
        cur1 = p_ptr->stat_cur[ii];
@@ -1018,7 +1010,7 @@ void mutate_player(void)
  */
 void apply_nexus(monster_type *m_ptr)
 {
-       switch (randint(7))
+       switch (randint1(7))
        {
                case 1: case 2: case 3:
                {
@@ -1034,7 +1026,7 @@ void apply_nexus(monster_type *m_ptr)
 
                case 6:
                {
-                       if (rand_int(100) < p_ptr->skill_sav)
+                       if (randint0(100) < p_ptr->skill_sav)
                        {
 #ifdef JP
 msg_print("¤·¤«¤·¸úÎϤòÄ·¤ÍÊÖ¤·¤¿¡ª");
@@ -1052,7 +1044,7 @@ msg_print("
 
                case 7:
                {
-                       if (rand_int(100) < p_ptr->skill_sav)
+                       if (randint0(100) < p_ptr->skill_sav)
                        {
 #ifdef JP
 msg_print("¤·¤«¤·¸úÎϤòÄ·¤ÍÊÖ¤·¤¿¡ª");
@@ -1147,7 +1139,7 @@ msg_print("
 }
 
 
-bool item_tester_hook_weapon_nobow(object_type *o_ptr)
+static bool item_tester_hook_weapon_nobow(object_type *o_ptr)
 {
        switch (o_ptr->tval)
        {
@@ -1221,7 +1213,7 @@ s = "
 
                switch (brand_type)
                {
-               case 16:
+               case 17:
                        if (o_ptr->tval == TV_SWORD)
                        {
 #ifdef JP
@@ -1245,6 +1237,15 @@ act = "
                                o_ptr->pval = m_bonus(3, dun_level);
                        }
                        break;
+               case 16:
+#ifdef JP
+act = "¤Ï¿Í´Ö¤Î·ì¤òµá¤á¤Æ¤¤¤ë¡ª";
+#else
+                       act = "seems looking for human!";
+#endif
+
+                       o_ptr->name2 = EGO_SLAY_HUMAN;
+                       break;
                case 15:
 #ifdef JP
 act = "¤ÏÅÅ·â¤Ëʤ¤ï¤ì¤¿¡ª";
@@ -1343,7 +1344,7 @@ act = "
 #endif
 
                        o_ptr->name2 = EGO_TRUMP;
-                       o_ptr->pval = randint(2);
+                       o_ptr->pval = randint1(2);
                        break;
                case 4:
 #ifdef JP
@@ -1399,7 +1400,7 @@ msg_format("
 #endif
 
 
-               enchant(o_ptr, rand_int(3) + 4, ENCH_TOHIT | ENCH_TODAM);
+               enchant(o_ptr, randint0(3) + 4, ENCH_TOHIT | ENCH_TODAM);
 
                o_ptr->discount = 99;
                chg_virtue(V_ENCHANT, 2);
@@ -1462,7 +1463,7 @@ msg_print("
 #endif
 
 
-               if (destroy_area(py, px, 15 + p_ptr->lev + rand_int(11), TRUE))
+               if (destroy_area(py, px, 15 + p_ptr->lev + randint0(11), TRUE))
 #ifdef JP
 msg_print("¥À¥ó¥¸¥ç¥ó¤¬Êø²õ¤·¤¿...");
 #else
@@ -1478,9 +1479,9 @@ msg_print("
 
 
 #ifdef JP
-take_hit(DAMAGE_NOESCAPE, 100 + randint(150), "¼«»¦Åª¤Êµõ̵¾·Íè", -1);
+take_hit(DAMAGE_NOESCAPE, 100 + randint1(150), "¼«»¦Åª¤Êµõ̵¾·Íè", -1);
 #else
-               take_hit(DAMAGE_NOESCAPE, 100 + randint(150), "a suicidal Call the Void", -1);
+               take_hit(DAMAGE_NOESCAPE, 100 + randint1(150), "a suicidal Call the Void", -1);
 #endif
 
        }
@@ -1768,8 +1769,6 @@ static int remove_curse_aux(int all)
        /* Attempt to uncurse items being worn */
        for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
        {
-               u32b f1, f2, f3;
-
                object_type *o_ptr = &inventory[i];
 
                /* Skip non-objects */
@@ -1778,27 +1777,23 @@ static int remove_curse_aux(int all)
                /* Uncursed already */
                if (!cursed_p(o_ptr)) continue;
 
-               /* Extract the flags */
-               object_flags(o_ptr, &f1, &f2, &f3);
-
                /* Heavily Cursed Items need a special spell */
-               if (!all && (f3 & TR3_HEAVY_CURSE)) continue;
+               if (!all && (o_ptr->curse_flags & TRC_HEAVY_CURSE)) continue;
 
                /* Perma-Cursed Items can NEVER be uncursed */
-               if (f3 & TR3_PERMA_CURSE) continue;
+               if (o_ptr->curse_flags & TRC_PERMA_CURSE)
+               {
+                       /* Uncurse it */
+                       o_ptr->curse_flags &= (TRC_CURSED | TRC_HEAVY_CURSE | TRC_PERMA_CURSE);
+                       continue;
+               }
 
                /* Uncurse it */
-               o_ptr->ident &= ~(IDENT_CURSED);
+               o_ptr->curse_flags = 0L;
 
                /* Hack -- Assume felt */
                o_ptr->ident |= (IDENT_SENSE);
 
-               if (o_ptr->art_flags3 & TR3_CURSED)
-                       o_ptr->art_flags3 &= ~(TR3_CURSED);
-
-               if (o_ptr->art_flags3 & TR3_HEAVY_CURSE)
-                       o_ptr->art_flags3 &= ~(TR3_HEAVY_CURSE);
-
                /* Take note */
                o_ptr->feeling = FEEL_NONE;
 
@@ -1910,33 +1905,15 @@ sprintf(out_val, "
        }
 
        /* Artifacts cannot be destroyed */
-       if (artifact_p(o_ptr) || o_ptr->art_name)
+       if (!can_player_destroy_object(o_ptr))
        {
-               byte feel = FEEL_SPECIAL;
-
                /* Message */
 #ifdef JP
-msg_format("%s¤ò¶â¤ËÊѤ¨¤ë¤³¤È¤Ë¼ºÇÔ¤·¤¿¡£", o_name);
+               msg_format("%s¤ò¶â¤ËÊѤ¨¤ë¤³¤È¤Ë¼ºÇÔ¤·¤¿¡£", o_name);
 #else
                msg_format("You fail to turn %s to gold!", o_name);
 #endif
 
-
-               /* Hack -- Handle icky artifacts */
-               if (cursed_p(o_ptr) || broken_p(o_ptr)) feel = FEEL_TERRIBLE;
-
-               /* Hack -- inscribe the artifact */
-               o_ptr->feeling = feel;
-
-               /* We have "felt" it (again) */
-               o_ptr->ident |= (IDENT_SENSE);
-
-               /* Combine the pack */
-               p_ptr->notice |= (PN_COMBINE);
-
-               /* Window stuff */
-               p_ptr->window |= (PW_INVEN | PW_EQUIP);
-
                /* Done */
                return FALSE;
        }
@@ -2037,7 +2014,7 @@ msg_print("
                /* Quest level */
                cave_set_feat(py, px, FEAT_LESS);
        }
-       else if (rand_int(100) < 50)
+       else if (randint0(100) < 50)
        {
                cave_set_feat(py, px, FEAT_MORE);
        }
@@ -2074,7 +2051,7 @@ bool item_tester_hook_weapon(object_type *o_ptr)
        return (FALSE);
 }
 
-bool item_tester_hook_weapon2(object_type *o_ptr)
+static bool item_tester_hook_weapon2(object_type *o_ptr)
 {
        switch (o_ptr->tval)
        {
@@ -2120,7 +2097,7 @@ bool item_tester_hook_armour(object_type *o_ptr)
 }
 
 
-bool item_tester_hook_corpse(object_type *o_ptr)
+static bool item_tester_hook_corpse(object_type *o_ptr)
 {
        switch (o_ptr->tval)
        {
@@ -2170,7 +2147,7 @@ bool item_tester_hook_weapon_armour(object_type *o_ptr)
 /*
  * Check if an object is nameless weapon or armour
  */
-bool item_tester_hook_nameless_weapon_armour(object_type *o_ptr)
+static bool item_tester_hook_nameless_weapon_armour(object_type *o_ptr)
 {
        if (o_ptr->name1 || o_ptr->art_name || o_ptr->name2 || o_ptr->xtra3)
                return FALSE;
@@ -2208,12 +2185,7 @@ bool item_tester_hook_nameless_weapon_armour(object_type *o_ptr)
  */
 static void break_curse(object_type *o_ptr)
 {
-       u32b    f1, f2, f3;
-
-       /* Extract the flags */
-       object_flags(o_ptr, &f1, &f2, &f3);
-
-       if (cursed_p(o_ptr) && !(f3 & TR3_PERMA_CURSE) && !(f3 & TR3_HEAVY_CURSE) && (rand_int(100) < 25))
+       if (cursed_p(o_ptr) && !(o_ptr->curse_flags & TRC_PERMA_CURSE) && !(o_ptr->curse_flags & TRC_HEAVY_CURSE) && (randint0(100) < 25))
        {
 #ifdef JP
 msg_print("¤«¤±¤é¤ì¤Æ¤¤¤¿¼ö¤¤¤¬ÂǤÁÇˤé¤ì¤¿¡ª");
@@ -2221,13 +2193,10 @@ msg_print("
                msg_print("The curse is broken!");
 #endif
 
+               o_ptr->curse_flags = 0L;
 
-               o_ptr->ident &= ~(IDENT_CURSED);
                o_ptr->ident |= (IDENT_SENSE);
 
-               if (o_ptr->art_flags3 & TR3_CURSED)
-                       o_ptr->art_flags3 &= ~(TR3_CURSED);
-
                o_ptr->feeling = FEEL_NONE;
        }
 }
@@ -2271,7 +2240,7 @@ bool enchant(object_type *o_ptr, int n, int eflag)
        for (i = 0; i < n; i++)
        {
                /* Hack -- Roll for pile resistance */
-               if (!force && rand_int(prob) >= 100) continue;
+               if (!force && randint0(prob) >= 100) continue;
 
                /* Enchant to hit */
                if (eflag & ENCH_TOHIT)
@@ -2280,7 +2249,7 @@ bool enchant(object_type *o_ptr, int n, int eflag)
                        else if (o_ptr->to_h > 15) chance = 1000;
                        else chance = enchant_table[o_ptr->to_h];
 
-                       if (force || ((randint(1000) > chance) && (!a || (rand_int(100) < 50))))
+                       if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50))))
                        {
                                o_ptr->to_h++;
                                res = TRUE;
@@ -2298,7 +2267,7 @@ bool enchant(object_type *o_ptr, int n, int eflag)
                        else if (o_ptr->to_d > 15) chance = 1000;
                        else chance = enchant_table[o_ptr->to_d];
 
-                       if (force || ((randint(1000) > chance) && (!a || (rand_int(100) < 50))))
+                       if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50))))
                        {
                                o_ptr->to_d++;
                                res = TRUE;
@@ -2316,7 +2285,7 @@ bool enchant(object_type *o_ptr, int n, int eflag)
                        else if (o_ptr->to_a > 15) chance = 1000;
                        else chance = enchant_table[o_ptr->to_a];
 
-                       if (force || ((randint(1000) > chance) && (!a || (rand_int(100) < 50))))
+                       if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50))))
                        {
                                o_ptr->to_a++;
                                res = TRUE;
@@ -2425,7 +2394,7 @@ msg_print("
                msg_print("The enchantment failed.");
 #endif
 
-               if (randint(3)==1) chg_virtue(V_ENCHANT, -1);
+               if (one_in_(3)) chg_virtue(V_ENCHANT, -1);
        }
        else
                chg_virtue(V_ENCHANT, 1);
@@ -2563,7 +2532,7 @@ msg_print("
                msg_print("The enchantment failed.");
 #endif
 
-               if (randint(3)==1) chg_virtue(V_ENCHANT, -1);
+               if (one_in_(3)) chg_virtue(V_ENCHANT, -1);
        }
        else
                chg_virtue(V_ENCHANT, 1);
@@ -2578,16 +2547,16 @@ msg_print("
 /*
  * Identify an object
  */
-void identify_item(object_type *o_ptr)
+bool identify_item(object_type *o_ptr)
 {
-       bool motoart = TRUE;
+       bool old_known = FALSE;
        char o_name[MAX_NLEN];
 
        /* Description */
        object_desc(o_name, o_ptr, TRUE, 3);
 
-       if ((artifact_p(o_ptr) || o_ptr->art_name) && !(o_ptr->ident & IDENT_KNOWN))
-               motoart = FALSE;
+       if (o_ptr->ident & IDENT_KNOWN)
+               old_known = TRUE;
 
        if (!(o_ptr->ident & (IDENT_MENTAL)))
        {
@@ -2614,19 +2583,21 @@ void identify_item(object_type *o_ptr)
        /* Description */
        object_desc(o_name, o_ptr, TRUE, 0);
 
-       if(record_fix_art && !motoart && artifact_p(o_ptr))
+       if(record_fix_art && !old_known && artifact_p(o_ptr))
                do_cmd_write_nikki(NIKKI_ART, 0, o_name);
-       if(record_rand_art && !motoart && o_ptr->art_name)
+       if(record_rand_art && !old_known && o_ptr->art_name)
                do_cmd_write_nikki(NIKKI_ART, 0, o_name);
+
+       return old_known;
 }
 
 
-bool item_tester_hook_identify(object_type *o_ptr)
+static bool item_tester_hook_identify(object_type *o_ptr)
 {
        return (bool)!object_known_p(o_ptr);
 }
 
-bool item_tester_hook_identify_weapon_armour(object_type *o_ptr)
+static bool item_tester_hook_identify_weapon_armour(object_type *o_ptr)
 {
        if (object_known_p(o_ptr))
                return FALSE;
@@ -2638,12 +2609,14 @@ bool item_tester_hook_identify_weapon_armour(object_type *o_ptr)
  * This routine does *not* automatically combine objects.
  * Returns TRUE if something was identified, else FALSE.
  */
-bool ident_spell(bool only_equip)
+bool ident_spell(bool only_equip, bool wait_optimize)
 {
        int             item;
        object_type     *o_ptr;
        char            o_name[MAX_NLEN];
        cptr            q, s;
+       bool old_known;
+       int idx;
 
        item_tester_no_ryoute = TRUE;
 
@@ -2688,7 +2661,7 @@ s = "
        }
 
        /* Identify it */
-       identify_item(o_ptr);
+       old_known = identify_item(o_ptr);
 
        /* Description */
        object_desc(o_name, o_ptr, TRUE, 3);
@@ -2697,34 +2670,33 @@ s = "
        if (item >= INVEN_RARM)
        {
 #ifdef JP
-msg_format("%^s: %s(%c)¡£",
+               msg_format("%^s: %s(%c)¡£", describe_use(item), o_name, index_to_label(item));
 #else
-               msg_format("%^s: %s (%c).",
+               msg_format("%^s: %s (%c).", describe_use(item), o_name, index_to_label(item));
 #endif
-
-                          describe_use(item), o_name, index_to_label(item));
        }
        else if (item >= 0)
        {
 #ifdef JP
-msg_format("¥¶¥Ã¥¯Ãæ: %s(%c)¡£",
+               msg_format("¥¶¥Ã¥¯Ãæ: %s(%c)¡£", o_name, index_to_label(item));
 #else
-               msg_format("In your pack: %s (%c).",
+               msg_format("In your pack: %s (%c).", o_name, index_to_label(item));
 #endif
-
-                          o_name, index_to_label(item));
        }
        else
        {
 #ifdef JP
-msg_format("¾²¾å: %s¡£",
+               msg_format("¾²¾å: %s¡£", o_name);
 #else
-               msg_format("On the ground: %s.",
+               msg_format("On the ground: %s.", o_name);
 #endif
-
-                          o_name);
        }
 
+       /* Auto-inscription/destroy */
+       idx = is_autopick(o_ptr);
+       auto_inscribe_item(item, idx);
+       if (!old_known) auto_destroy_item(item, idx, wait_optimize);
+
        /* Something happened */
        return (TRUE);
 }
@@ -2797,12 +2769,12 @@ msg_print("
 
 
 
-bool item_tester_hook_identify_fully(object_type *o_ptr)
+static bool item_tester_hook_identify_fully(object_type *o_ptr)
 {
        return (bool)(!object_known_p(o_ptr) || !(o_ptr->ident & IDENT_MENTAL));
 }
 
-bool item_tester_hook_identify_fully_weapon_armour(object_type *o_ptr)
+static bool item_tester_hook_identify_fully_weapon_armour(object_type *o_ptr)
 {
        if (!item_tester_hook_identify_fully(o_ptr))
                return FALSE;
@@ -2813,12 +2785,14 @@ bool item_tester_hook_identify_fully_weapon_armour(object_type *o_ptr)
  * Fully "identify" an object in the inventory  -BEN-
  * This routine returns TRUE if an item was identified.
  */
-bool identify_fully(bool only_equip)
+bool identify_fully(bool only_equip, bool wait_optimize)
 {
        int             item;
        object_type     *o_ptr;
        char            o_name[MAX_NLEN];
        cptr            q, s;
+       bool old_known;
+       int idx;
 
        item_tester_no_ryoute = TRUE;
        if (only_equip)
@@ -2858,7 +2832,7 @@ s = "
        }
 
        /* Identify it */
-       identify_item(o_ptr);
+       old_known = identify_item(o_ptr);
 
        /* Mark the item as fully known */
        o_ptr->ident |= (IDENT_MENTAL);
@@ -2873,37 +2847,38 @@ s = "
        if (item >= INVEN_RARM)
        {
 #ifdef JP
-msg_format("%^s: %s(%c)¡£",
+               msg_format("%^s: %s(%c)¡£", describe_use(item), o_name, index_to_label(item));
 #else
-               msg_format("%^s: %s (%c).",
+               msg_format("%^s: %s (%c).", describe_use(item), o_name, index_to_label(item));
 #endif
 
-                          describe_use(item), o_name, index_to_label(item));
+
        }
        else if (item >= 0)
        {
 #ifdef JP
-msg_format("¥¶¥Ã¥¯Ãæ: %s(%c)¡£",
+               msg_format("¥¶¥Ã¥¯Ãæ: %s(%c)¡£", o_name, index_to_label(item));
 #else
-               msg_format("In your pack: %s (%c).",
+               msg_format("In your pack: %s (%c).", o_name, index_to_label(item));
 #endif
-
-                          o_name, index_to_label(item));
        }
        else
        {
 #ifdef JP
-msg_format("¾²¾å: %s¡£",
+               msg_format("¾²¾å: %s¡£", o_name);
 #else
-               msg_format("On the ground: %s.",
+               msg_format("On the ground: %s.", o_name);
 #endif
-
-                          o_name);
        }
 
        /* Describe it fully */
        (void)identify_fully_aux(o_ptr);
 
+       /* Auto-inscription/destroy */
+       idx = is_autopick(o_ptr);
+       auto_inscribe_item(item, idx);
+       if (!old_known) auto_destroy_item(item, idx, wait_optimize);
+
        /* Success */
        return (TRUE);
 }
@@ -3002,7 +2977,7 @@ s = "
 
 
                /* Back-fire */
-               if (rand_int(recharge_strength) == 0)
+               if (one_in_(recharge_strength))
                {
                        /* Activate the failure code. */
                        fail = TRUE;
@@ -3041,7 +3016,7 @@ s = "
                if (recharge_strength < 0) recharge_strength = 0;
 
                /* Back-fire */
-               if (rand_int(recharge_strength) == 0)
+               if (one_in_(recharge_strength))
                {
                        /* Activate the failure code. */
                        fail = TRUE;
@@ -3051,13 +3026,13 @@ s = "
                else
                {
                        /* Recharge based on the standard number of charges. */
-                       recharge_amount = randint(1 + k_ptr->pval / 2);
+                       recharge_amount = randint1(1 + k_ptr->pval / 2);
 
                        /* Multiple wands in a stack increase recharging somewhat. */
                        if ((o_ptr->tval == TV_WAND) && (o_ptr->number > 1))
                        {
                                recharge_amount +=
-                                       (randint(recharge_amount * (o_ptr->number - 1))) / 2;
+                                       (randint1(recharge_amount * (o_ptr->number - 1))) / 2;
                                if (recharge_amount < 1) recharge_amount = 1;
                                if (recharge_amount > 12) recharge_amount = 12;
                        }
@@ -3119,19 +3094,19 @@ msg_format("
                                /* 10% chance to blow up one rod, otherwise draining. */
                                if (o_ptr->tval == TV_ROD)
                                {
-                                       if (randint(10) == 1) fail_type = 2;
+                                       if (one_in_(10)) fail_type = 2;
                                        else fail_type = 1;
                                }
                                /* 75% chance to blow up one wand, otherwise draining. */
                                else if (o_ptr->tval == TV_WAND)
                                {
-                                       if (randint(3) != 1) fail_type = 2;
+                                       if (!one_in_(3)) fail_type = 2;
                                        else fail_type = 1;
                                }
                                /* 50% chance to blow up one staff, otherwise no effect. */
                                else if (o_ptr->tval == TV_STAFF)
                                {
-                                       if (randint(2) == 1) fail_type = 2;
+                                       if (one_in_(2)) fail_type = 2;
                                        else fail_type = 0;
                                }
                        }
@@ -3142,13 +3117,13 @@ msg_format("
                                /* 33% chance to blow up one rod, otherwise draining. */
                                if (o_ptr->tval == TV_ROD)
                                {
-                                       if (randint(3) == 1) fail_type = 2;
+                                       if (one_in_(3)) fail_type = 2;
                                        else fail_type = 1;
                                }
                                /* 20% chance of the entire stack, else destroy one wand. */
                                else if (o_ptr->tval == TV_WAND)
                                {
-                                       if (randint(5) == 1) fail_type = 3;
+                                       if (one_in_(5)) fail_type = 3;
                                        else fail_type = 2;
                                }
                                /* Blow up one staff. */
@@ -3166,9 +3141,9 @@ msg_format("
                                if (o_ptr->tval == TV_ROD)
                                {
 #ifdef JP
-msg_print("ËâÎϤòµÛ¤¤¼è¤ë¤Î¤Ë¼ºÇÔ¤·¤¿¡£¥í¥Ã¥É¤ÎËâÎϤÏÁ´¤Æȯ»¶¤·¤Æ¤·¤Þ¤Ã¤¿¡£");
+msg_print("ËâÎϤ¬µÕÊ®¼Í¤·¤Æ¡¢¥í¥Ã¥É¤«¤é¤µ¤é¤ËËâÎϤòµÛ¤¤¼è¤Ã¤Æ¤·¤Þ¤Ã¤¿¡ª");
 #else
-                                       msg_print("You failed to absorb magic power. All magic power of your rod had gone!");
+                                       msg_print("The recharge backfires, draining the rod further!");
 #endif
 
                                        if (o_ptr->timeout < 10000)
@@ -3321,10 +3296,10 @@ s = "
        /* Extract the flags */
        object_flags(o_ptr, &f1, &f2, &f3);
 
-       if (o_ptr->ident & IDENT_CURSED)
+       if (cursed_p(o_ptr))
        {
-               if (((f3 & TR3_HEAVY_CURSE) && (randint(100) < 33)) ||
-                   (f3 & TR3_PERMA_CURSE))
+               if (((o_ptr->curse_flags & TRC_HEAVY_CURSE) && (randint1(100) < 33)) ||
+                   (o_ptr->curse_flags & TRC_PERMA_CURSE))
                {
 #ifdef JP
 msg_format("%s¤òʤ¤¦¹õ¤¤¥ª¡¼¥é¤Ï½ËÊ¡¤òÄ·¤ÍÊÖ¤·¤¿¡ª",
@@ -3347,7 +3322,7 @@ msg_format("%s 
 
 
                /* Uncurse it */
-               o_ptr->ident &= ~(IDENT_CURSED);
+               o_ptr->curse_flags = 0L;
 
                /* Hack -- Assume felt */
                o_ptr->ident |= (IDENT_SENSE);
@@ -3384,7 +3359,7 @@ msg_format("%s 
                return TRUE;
        }
 
-       if (!(o_ptr->art_name || o_ptr->name1 || o_ptr->name2) || (randint(3) == 1))
+       if (!(o_ptr->art_name || o_ptr->name1 || o_ptr->name2) || one_in_(3))
        {
                /* Describe */
 #ifdef JP
@@ -3417,7 +3392,7 @@ msg_print("
                        dis_happened = TRUE;
                }
 
-               if ((o_ptr->to_h > 5) && (rand_int(100) < 33)) o_ptr->to_h--;
+               if ((o_ptr->to_h > 5) && (randint0(100) < 33)) o_ptr->to_h--;
 
                /* Disenchant todam */
                if (o_ptr->to_d > 0)
@@ -3426,7 +3401,7 @@ msg_print("
                        dis_happened = TRUE;
                }
 
-               if ((o_ptr->to_d > 5) && (rand_int(100) < 33)) o_ptr->to_d--;
+               if ((o_ptr->to_d > 5) && (randint0(100) < 33)) o_ptr->to_d--;
 
                /* Disenchant toac */
                if (o_ptr->to_a > 0)
@@ -3435,7 +3410,7 @@ msg_print("
                        dis_happened = TRUE;
                }
 
-               if ((o_ptr->to_a > 5) && (rand_int(100) < 33)) o_ptr->to_a--;
+               if ((o_ptr->to_a > 5) && (randint0(100) < 33)) o_ptr->to_a--;
 
                if (dis_happened)
                {
@@ -3526,7 +3501,7 @@ msg_format("%s
                    ((o_ptr->number > 1) ? "" : "s"));
 #endif
                o_ptr->name2 = EGO_REFLECTION;
-               enchant(o_ptr, rand_int(3) + 4, ENCH_TOAC);
+               enchant(o_ptr, randint0(3) + 4, ENCH_TOAC);
 
                o_ptr->discount = 99;
                chg_virtue(V_ENCHANT, 2);
@@ -3886,8 +3861,8 @@ strcpy(name, "(Ƚ
 
                        /* Forgotten */
                        else if ((j < 1) ?
-                               ((spell_forgotten1 & (1L << i))) :
-                               ((spell_forgotten2 & (1L << (i % 32)))))
+                               ((p_ptr->spell_forgotten1 & (1L << i))) :
+                               ((p_ptr->spell_forgotten2 & (1L << (i % 32)))))
                        {
                                /* Forgotten */
                                a = TERM_ORANGE;
@@ -3895,8 +3870,8 @@ strcpy(name, "(Ƚ
 
                        /* Unknown */
                        else if (!((j < 1) ?
-                               (spell_learned1 & (1L << i)) :
-                               (spell_learned2 & (1L << (i % 32)))))
+                               (p_ptr->spell_learned1 & (1L << i)) :
+                               (p_ptr->spell_learned2 & (1L << (i % 32)))))
                        {
                                /* Unknown */
                                a = TERM_RED;
@@ -3904,8 +3879,8 @@ strcpy(name, "(Ƚ
 
                        /* Untried */
                        else if (!((j < 1) ?
-                               (spell_worked1 & (1L << i)) :
-                               (spell_worked2 & (1L << (i % 32)))))
+                               (p_ptr->spell_worked1 & (1L << i)) :
+                               (p_ptr->spell_worked2 & (1L << (i % 32)))))
                        {
                                /* Untried */
                                a = TERM_YELLOW;
@@ -3928,6 +3903,18 @@ strcpy(name, "(Ƚ
 }
 
 
+/*
+ * Returns experience of a spell
+ */
+s16b experience_of_spell(int spell, int realm)
+{
+       if (p_ptr->pclass == CLASS_SORCERER) return 1600;
+       else if (p_ptr->pclass == CLASS_RED_MAGE) return 1200;
+       else if (realm+1 == p_ptr->realm1) return p_ptr->spell_exp[spell];
+       else if (realm+1 == p_ptr->realm2) return p_ptr->spell_exp[spell + 32];
+       else return 0;
+}
+
 
 /*
  * Returns spell chance of failure for spell -RAK-
@@ -3965,18 +3952,14 @@ s16b spell_chance(int spell, int realm)
        chance -= 3 * (adj_mag_stat[p_ptr->stat_ind[mp_ptr->spell_stat]] - 1);
 
        if (p_ptr->riding)
-               chance += (MAX(r_info[m_list[p_ptr->riding].r_idx].level-skill_exp[GINOU_RIDING]/100-10,0));
-
-       if (p_ptr->pclass == CLASS_SORCERER)
-               shouhimana = s_ptr->smana*2200 + 2399;
-       else if (p_ptr->pclass == CLASS_RED_MAGE)
-               shouhimana = s_ptr->smana*2600 + 2399;
-       else if ((realm+1 == p_ptr->realm1) || (realm+1 == p_ptr->realm2))
-               shouhimana = (s_ptr->smana*(3800-spell_exp[((p_ptr->realm1 == realm+1) ? spell: spell+32)])+2399);
-       else shouhimana = s_ptr->smana*3800;
-       if(p_ptr->dec_mana)
-               shouhimana *= 3;
+               chance += (MAX(r_info[m_list[p_ptr->riding].r_idx].level-p_ptr->skill_exp[GINOU_RIDING]/100-10,0));
+
+       /* Extract mana consumption rate */
+       shouhimana = s_ptr->smana*(3800 - experience_of_spell(spell, realm)) + 2399;
+
+       if(p_ptr->dec_mana) shouhimana *= 3;
        else shouhimana *= 4;
+
        shouhimana /= 9600;
        if(shouhimana < 1) shouhimana = 1;
 
@@ -3986,9 +3969,7 @@ s16b spell_chance(int spell, int realm)
                chance += 5 * (shouhimana - p_ptr->csp);
        }
 
-       if (p_ptr->pseikaku == SEIKAKU_NAMAKE) chance += 10;
-       if (p_ptr->pseikaku == SEIKAKU_KIREMONO) chance -= 3;
-       if ((p_ptr->pseikaku == SEIKAKU_GAMAN) || (p_ptr->pseikaku == SEIKAKU_CHIKARA)) chance++;
+       chance += p_ptr->to_m_chance;
        if (((realm + 1) != p_ptr->realm1) && ((p_ptr->pclass == CLASS_MAGE) || (p_ptr->pclass == CLASS_PRIEST))) chance += 5;
 
        /* Extract the minimum failure rate */
@@ -4013,7 +3994,7 @@ s16b spell_chance(int spell, int realm)
        else if (p_ptr->dec_mana) chance-=2;
 
        if ((realm+1 == REALM_NATURE) && ((p_ptr->align > 50) || (p_ptr->align < -50))) chance += penalty;
-       if ((realm+1 == REALM_LIFE) && (p_ptr->align < -20)) chance += penalty;
+       if (((realm+1 == REALM_LIFE) || (realm+1 == REALM_CRUSADE)) && (p_ptr->align < -20)) chance += penalty;
        if (((realm+1 == REALM_DEATH) || (realm+1 == REALM_DAEMON)) && (p_ptr->align > 20)) chance += penalty;
 
        /* Minimum failure rate */
@@ -4028,8 +4009,9 @@ s16b spell_chance(int spell, int realm)
 
        if ((realm+1 == p_ptr->realm1) || (realm+1 == p_ptr->realm2))
        {
-               if(spell_exp[((p_ptr->realm1 == realm+1) ? spell: spell+32)]>1399) chance--;
-               if(spell_exp[((p_ptr->realm1 == realm+1) ? spell: spell+32)]>1599) chance--;
+               s16b exp = experience_of_spell(spell, realm);
+               if(exp > 1399) chance--;
+               if(exp > 1599) chance--;
        }
        if(p_ptr->dec_mana) chance--;
        if (p_ptr->heavy_spell) chance += 5;
@@ -4066,8 +4048,8 @@ bool spell_okay(int spell, bool learned, bool study_pray, int realm)
 
        /* Spell is forgotten */
        if ((realm == p_ptr->realm2 - 1) ?
-           (spell_forgotten2 & (1L << spell)) :
-           (spell_forgotten1 & (1L << spell)))
+           (p_ptr->spell_forgotten2 & (1L << spell)) :
+           (p_ptr->spell_forgotten1 & (1L << spell)))
        {
                /* Never okay */
                return (FALSE);
@@ -4078,8 +4060,8 @@ bool spell_okay(int spell, bool learned, bool study_pray, int realm)
 
        /* Spell is learned */
        if ((realm == p_ptr->realm2 - 1) ?
-           (spell_learned2 & (1L << spell)) :
-           (spell_learned1 & (1L << spell)))
+           (p_ptr->spell_learned2 & (1L << spell)) :
+           (p_ptr->spell_learned1 & (1L << spell)))
        {
                /* Always true */
                return (!study_pray);
@@ -4135,31 +4117,19 @@ static void spell_info(char *p, int spell, int realm)
        case 0: /* Life */
                switch (spell)
                {
-               case  1: sprintf(p, " %s2d10", s_heal); break;
-               case  2: sprintf(p, " %s12+d12", s_dur); break;
-               case  4: sprintf(p, " %s%d", s_dam, 10 + (plev / 2)); break;
-               case  6: sprintf(p, " %s4d10", s_heal); break;
+               case  0: sprintf(p, " %s2d10", s_heal); break;
+               case  1: sprintf(p, " %s12+d12", s_dur); break;
+               case  2: sprintf(p, " %s%dd4", s_dam, 3 + ((plev - 1) / 5)); break;
+               case  3: sprintf(p, " %s%d", s_dam, 10 + (plev / 2)); break;
+               case  5: sprintf(p, " %s4d10", s_heal); break;
+               case  9: sprintf(p, " %s%dd8", s_dam, 8 + ((plev - 1) / 5)); break;
                case 10: sprintf(p, " %s8d10", s_heal); break;
-               case 11: sprintf(p, " %s24+d24", s_dur); break;
-               case 12: sprintf(p, " %s3d6+%d", s_dam, orb); break;
-               case 13: sprintf(p, " %sd25+%d", s_dur, 3 * plev); break;
+               case 11: sprintf(p, " %s20+d20", s_dur); break;
                case 14: sprintf(p, " %s300", s_heal); break;
-               case 16: sprintf(p, " %sd%d", s_dam, plev); break;
-               case 18: sprintf(p, " %sd%d", s_dam, 3 * plev); break;
-               case 20: sprintf(p, " %sd%d", s_dam, 4 * plev); break;
-#ifdef JP
-               case 22: sprintf(p, " Â»:d%d/²ó:1000", 4 * plev); break;
-#else
-               case 22: sprintf(p, " d %d/h 1000", 4 * plev); break;
-#endif
-               case 24: sprintf(p, " %s25+d25", s_dur); break;
-               case 25: sprintf(p, " %s48+d48", s_dur); break;
-               case 28: sprintf(p, " %s2000", s_heal); break;
-#ifdef JP
-               case 30: sprintf(p, " ²ó300/»%d+250", plev * 4); break;
-#else
-               case 30: sprintf(p, " h300/d%d+250", plev * 4); break;
-#endif
+               case 18: sprintf(p, " %sd%d", s_dam, 5 * plev); break;
+               case 20: sprintf(p, " %s%dd15", s_dam, 5 + ((plev - 1) / 3)); break;
+               case 21: sprintf(p, " %s15+d21", s_delay); break;
+               case 29: sprintf(p, " %s2000", s_heal); break;
                case 31: sprintf(p, " %s%d+d%d", s_dur,(plev/2), (plev/2)); break;
                }
                break;
@@ -4292,7 +4262,7 @@ static void spell_info(char *p, int spell, int realm)
 #ifdef JP
                case 28: sprintf(p, " %s³Æ%d", s_dam, plev * 2); break;
 #else
-               case 28: sprintf(p, " dam %d each", plev * 2); break;
+               case 28: sprintf(p, " %s%d each", s_dam, plev * 2); break;
 #endif
                }
                break;
@@ -4371,6 +4341,45 @@ static void spell_info(char *p, int spell, int realm)
                }
                break;
                
+       case 9: /* Crusade */
+               switch (spell)
+               {
+               case  0: sprintf(p, " %s%dd4", s_dam, 3 + ((plev - 1) / 5)); break;
+               case  5: sprintf(p, " %s%d", s_range, plev*3); break;
+#ifdef JP
+               case  6: sprintf(p, " %s³Æ%dd2", s_dam, 3+((plev-1)/9)); break;
+#else
+               case  6: sprintf(p, " %s%dd2 each", s_dam, 3+((plev-1)/9)); break;
+#endif
+               case  9: sprintf(p, " %s3d6+%d", s_dam, orb); break;
+               case 10: sprintf(p, " %sd%d", s_dam, plev); break;
+               case 12: sprintf(p, " %s24+d24", s_dur); break;
+               case 13: sprintf(p, " %sd25+%d", s_dur, 3 * plev); break;
+               case 14: sprintf(p, " %s%d", s_dam, plev*5); break;
+#ifdef JP
+               case 15: sprintf(p, " Â»:d%d/²ó:100", 6 * plev); break;
+#else
+               case 15: sprintf(p, " dam:d%d/h100", 6 * plev); break;
+#endif
+               case 18: sprintf(p, " %s18+d18", s_dur); break;
+               case 19: sprintf(p, " %sd%d", s_dam, 4 * plev); break;
+               case 20: sprintf(p, " %sd%d", s_dam, 4 * plev); break;
+               case 22: sprintf(p, " %s%d", s_dam, 2 * plev+100); break;
+               case 24: sprintf(p, " %s25+d25", s_dur); break;
+               case 28: sprintf(p, " %s10+d10", s_dur); break;
+#ifdef JP
+               case 29: sprintf(p, " %s³Æ%d", s_dam, plev*3+25); break;
+#else
+               case 29: sprintf(p, " %s%d each", s_dam, plev*3+25); break;
+#endif
+#ifdef JP
+               case 30: sprintf(p, " ²ó100/»%d+%d", plev * 4, plev*11/2); break;
+#else
+               case 30: sprintf(p, " h100/dm%d+%d", plev * 4, plev*11/2); break;
+#endif
+               }
+               break;
+
        case 15: /* Music */
                switch (spell)
                {
@@ -4412,7 +4421,7 @@ void print_spells(int target_spell, byte *spells, int num, int y, int x, int rea
        bool max = FALSE;
 
 
-       if (((realm < 0) || (realm > MAX_REALM - 1)) && wizard)
+       if (((realm < 0) || (realm > MAX_REALM - 1)) && p_ptr->wizard)
 #ifdef JP
 msg_print("·Ù¹ð¡ª print_spell ¤¬Îΰè¤Ê¤·¤Ë¸Æ¤Ð¤ì¤¿");
 #else
@@ -4467,36 +4476,34 @@ put_str(buf, y, x + 29);
                        shouhimana = s_ptr->smana;
                else
                {
-                       if (p_ptr->pclass == CLASS_SORCERER)
-                               shouhimana = s_ptr->smana*2200 + 2399;
-                       else if (p_ptr->pclass == CLASS_RED_MAGE)
-                               shouhimana = s_ptr->smana*2600 + 2399;
-                       else if ((realm+1 == p_ptr->realm1) || (realm+1 == p_ptr->realm2))
-                               shouhimana = (s_ptr->smana*(3800-spell_exp[(spell+increment)])+2399);
-                       else
-                               shouhimana = s_ptr->smana*3800+2399;
-                       if(p_ptr->dec_mana)
-                               shouhimana *= 3;
+                       s16b exp = experience_of_spell(spell, realm);
+
+                       /* Extract mana consumption rate */
+                       shouhimana = s_ptr->smana*(3800 - exp) + 2399;
+
+                       if(p_ptr->dec_mana) shouhimana *= 3;
                        else shouhimana *= 4;
+
                        shouhimana /= 9600;
                        if(shouhimana < 1) shouhimana = 1;
-               }
 
-               if ((increment == 64) || (s_ptr->slevel >= 99)) shougou = 0;
-               else if (spell_exp[spell+increment]<900) shougou = 0;
-               else if (spell_exp[spell+increment]<1200) shougou = 1;
-               else if (spell_exp[spell+increment]<1400) shougou = 2;
-               else if (spell_exp[spell+increment]<1600) shougou = 3;
-               else shougou = 4;
-               max = FALSE;
-               if (!increment && (shougou == 4)) max = TRUE;
-               else if ((increment == 32) && (shougou == 3)) max = TRUE;
-               else if (s_ptr->slevel >= 99) max = TRUE;
-               else if (p_ptr->pclass == CLASS_RED_MAGE) max = TRUE;
-
-               strncpy(ryakuji,shougou_moji[shougou],4);
-               ryakuji[3] = ']';
-               ryakuji[4] = '\0';
+                       if ((increment == 64) || (s_ptr->slevel >= 99)) shougou = 0;
+                       else if (exp < 900) shougou = 0;
+                       else if (exp < 1200) shougou = 1;
+                       else if (exp < 1400) shougou = 2;
+                       else if (exp < 1600) shougou = 3;
+                       else shougou = 4;
+
+                       max = FALSE;
+                       if (!increment && (shougou == 4)) max = TRUE;
+                       else if ((increment == 32) && (shougou == 3)) max = TRUE;
+                       else if (s_ptr->slevel >= 99) max = TRUE;
+                       else if (p_ptr->pclass == CLASS_RED_MAGE) max = TRUE;
+
+                       strncpy(ryakuji,shougou_moji[shougou],4);
+                       ryakuji[3] = ']';
+                       ryakuji[4] = '\0';
+               }
 
                if (use_menu && target_spell)
                {
@@ -4569,8 +4576,8 @@ comment = " ̤
                        line_attr = TERM_L_BLUE;
                }
                else if ((realm + 1 == p_ptr->realm1) ?
-                   ((spell_forgotten1 & (1L << spell))) :
-                   ((spell_forgotten2 & (1L << spell))))
+                   ((p_ptr->spell_forgotten1 & (1L << spell))) :
+                   ((p_ptr->spell_forgotten2 & (1L << spell))))
                {
 #ifdef JP
 comment = " ËºµÑ";
@@ -4581,8 +4588,8 @@ comment = " ˺
                        line_attr = TERM_YELLOW;
                }
                else if (!((realm + 1 == p_ptr->realm1) ?
-                   (spell_learned1 & (1L << spell)) :
-                   (spell_learned2 & (1L << spell))))
+                   (p_ptr->spell_learned1 & (1L << spell)) :
+                   (p_ptr->spell_learned2 & (1L << spell))))
                {
 #ifdef JP
 comment = " Ì¤ÃÎ";
@@ -4593,8 +4600,8 @@ comment = " ̤
                        line_attr = TERM_L_BLUE;
                }
                else if (!((realm + 1 == p_ptr->realm1) ?
-                   (spell_worked1 & (1L << spell)) :
-                   (spell_worked2 & (1L << spell))))
+                   (p_ptr->spell_worked1 & (1L << spell)) :
+                   (p_ptr->spell_worked2 & (1L << spell))))
                {
 #ifdef JP
 comment = " Ì¤·Ð¸³";
@@ -4740,6 +4747,7 @@ bool hates_fire(object_type *o_ptr)
                case TV_ARCANE_BOOK:
                case TV_ENCHANT_BOOK:
                case TV_DAEMON_BOOK:
+               case TV_CRUSADE_BOOK:
                case TV_MUSIC_BOOK:
                case TV_HISSATSU_BOOK:
                {
@@ -4873,7 +4881,7 @@ int inven_damage(inven_func typ, int perc)
                        /* Count the casualties */
                        for (amt = j = 0; j < o_ptr->number; ++j)
                        {
-                               if (rand_int(100) < perc) amt++;
+                               if (randint0(100) < perc) amt++;
                        }
 
                        /* Some casualities */
@@ -4946,7 +4954,7 @@ static int minus_ac(void)
 
 
        /* Pick a (possibly empty) inventory slot */
-       switch (randint(7))
+       switch (randint1(7))
        {
                case 1: o_ptr = &inventory[INVEN_RARM]; break;
                case 2: o_ptr = &inventory[INVEN_LARM]; break;
@@ -5033,7 +5041,7 @@ void acid_dam(int dam, cptr kb_str, int monspell)
        if (double_resist) dam = (dam + 2) / 3;
 
        if ((!(double_resist || p_ptr->resist_acid)) &&
-           randint(HURT_CHANCE) == 1)
+           one_in_(HURT_CHANCE))
                (void)do_dec_stat(A_CHR);
 
        /* If any armor gets hit, defend the player */
@@ -5073,7 +5081,7 @@ void elec_dam(int dam, cptr kb_str, int monspell)
        if (double_resist) dam = (dam + 2) / 3;
 
        if ((!(double_resist || p_ptr->resist_elec)) &&
-           randint(HURT_CHANCE) == 1)
+           one_in_(HURT_CHANCE))
                (void)do_dec_stat(A_DEX);
 
        /* Take damage */
@@ -5110,7 +5118,7 @@ void fire_dam(int dam, cptr kb_str, int monspell)
        if (double_resist) dam = (dam + 2) / 3;
 
        if ((!(double_resist || p_ptr->resist_fire)) &&
-           randint(HURT_CHANCE) == 1)
+           one_in_(HURT_CHANCE))
                (void)do_dec_stat(A_STR);
 
        /* Take damage */
@@ -5146,7 +5154,7 @@ void cold_dam(int dam, cptr kb_str, int monspell)
        if (double_resist) dam = (dam + 2) / 3;
 
        if ((!(double_resist || p_ptr->resist_cold)) &&
-           randint(HURT_CHANCE) == 1)
+           one_in_(HURT_CHANCE))
                (void)do_dec_stat(A_STR);
 
        /* Take damage */
@@ -5198,7 +5206,7 @@ s = "
 
        o_ptr->art_flags3 |= TR3_IGNORE_ACID;
 
-       if ((o_ptr->to_a < 0) && !(o_ptr->ident & IDENT_CURSED))
+       if ((o_ptr->to_a < 0) && !cursed_p(o_ptr))
        {
 #ifdef JP
 msg_format("%s¤Ï¿·ÉÊƱÍͤˤʤä¿¡ª",o_name);
@@ -5247,7 +5255,7 @@ bool curse_armor(void)
        object_desc(o_name, o_ptr, FALSE, 3);
 
        /* Attempt a saving throw for artifacts */
-       if ((o_ptr->art_name || artifact_p(o_ptr)) && (rand_int(100) < 50))
+       if ((o_ptr->art_name || artifact_p(o_ptr)) && (randint0(100) < 50))
        {
                /* Cool */
 #ifdef JP
@@ -5275,7 +5283,7 @@ msg_format("
                /* Blast the armor */
                o_ptr->name1 = 0;
                o_ptr->name2 = EGO_BLASTED;
-               o_ptr->to_a = 0 - randint(5) - randint(5);
+               o_ptr->to_a = 0 - randint1(5) - randint1(5);
                o_ptr->to_h = 0;
                o_ptr->to_d = 0;
                o_ptr->ac = 0;
@@ -5286,7 +5294,7 @@ msg_format("
                o_ptr->art_flags3 = 0;
 
                /* Curse it */
-               o_ptr->ident |= (IDENT_CURSED);
+               o_ptr->curse_flags = TRC_CURSED;
 
                /* Break it */
                o_ptr->ident |= (IDENT_BROKEN);
@@ -5326,7 +5334,7 @@ bool curse_weapon(bool force, int slot)
        object_desc(o_name, o_ptr, FALSE, 3);
 
        /* Attempt a saving throw */
-       if ((artifact_p(o_ptr) || o_ptr->art_name) && (rand_int(100) < 50) && !force)
+       if ((artifact_p(o_ptr) || o_ptr->art_name) && (randint0(100) < 50) && !force)
        {
                /* Cool */
 #ifdef JP
@@ -5354,8 +5362,8 @@ if (!force) msg_format("
                /* Shatter the weapon */
                o_ptr->name1 = 0;
                o_ptr->name2 = EGO_SHATTERED;
-               o_ptr->to_h = 0 - randint(5) - randint(5);
-               o_ptr->to_d = 0 - randint(5) - randint(5);
+               o_ptr->to_h = 0 - randint1(5) - randint1(5);
+               o_ptr->to_d = 0 - randint1(5) - randint1(5);
                o_ptr->to_a = 0;
                o_ptr->ac = 0;
                o_ptr->dd = 0;
@@ -5366,7 +5374,7 @@ if (!force) msg_format("
 
 
                /* Curse it */
-               o_ptr->ident |= (IDENT_CURSED);
+               o_ptr->curse_flags = TRC_CURSED;
 
                /* Break it */
                o_ptr->ident |= (IDENT_BROKEN);
@@ -5409,7 +5417,7 @@ bool brand_bolts(void)
                if (cursed_p(o_ptr) || broken_p(o_ptr)) continue;
 
                /* Randomize */
-               if (rand_int(100) < 75) continue;
+               if (randint0(100) < 75) continue;
 
                /* Message */
 #ifdef JP
@@ -5423,7 +5431,7 @@ msg_print("
                o_ptr->name2 = EGO_FLAME;
 
                /* Enchant */
-               enchant(o_ptr, rand_int(3) + 4, ENCH_TOHIT | ENCH_TODAM);
+               enchant(o_ptr, randint0(3) + 4, ENCH_TOHIT | ENCH_TODAM);
 
                /* Notice */
                return (TRUE);
@@ -5462,8 +5470,8 @@ static s16b poly_r_idx(int r_idx)
                return (r_idx);
 
        /* Allowable range of "levels" for resulting monster */
-       lev1 = r_ptr->level - ((randint(20) / randint(9)) + 1);
-       lev2 = r_ptr->level + ((randint(20) / randint(9)) + 1);
+       lev1 = r_ptr->level - ((randint1(20) / randint1(9)) + 1);
+       lev2 = r_ptr->level + ((randint1(20) / randint1(9)) + 1);
 
        /* Pick a (possibly new) non-unique race */
        for (i = 0; i < 1000; i++)
@@ -5499,18 +5507,19 @@ bool polymorph_monster(int y, int x)
 {
        cave_type *c_ptr = &cave[y][x];
        monster_type *m_ptr = &m_list[c_ptr->m_idx];
-       bool friendly, pet;
        bool polymorphed = FALSE;
        int new_r_idx;
        int old_r_idx = m_ptr->r_idx;
+       bool targeted = (target_who == c_ptr->m_idx) ? TRUE : FALSE;
+       bool health_tracked = (p_ptr->health_who == c_ptr->m_idx) ? TRUE : FALSE;
+       monster_type back_m;
 
        if (p_ptr->inside_arena || p_ptr->inside_battle) return (FALSE);
 
        if ((p_ptr->riding == c_ptr->m_idx) || (m_ptr->mflag2 & MFLAG_KAGE)) return (FALSE);
 
-       /* Get the monsters attitude */
-       friendly = is_friendly(m_ptr);
-       pet = is_pet(m_ptr);
+       /* Memorize the monster before polymorphing */
+       back_m = *m_ptr;
 
        /* Pick a "new" monster race */
        new_r_idx = poly_r_idx(old_r_idx);
@@ -5518,24 +5527,31 @@ bool polymorph_monster(int y, int x)
        /* Handle polymorph */
        if (new_r_idx != old_r_idx)
        {
+               u32b mode = 0L;
+
+               /* Get the monsters attitude */
+               if (is_friendly(m_ptr)) mode |= PM_FORCE_FRIENDLY;
+               if (is_pet(m_ptr)) mode |= PM_FORCE_PET;
+               if (m_ptr->mflag2 & MFLAG_NOPET) mode |= PM_NO_PET;
+
                /* "Kill" the "old" monster */
                delete_monster_idx(c_ptr->m_idx);
 
                /* Create a new monster (no groups) */
-               if (place_monster_aux(y, x, new_r_idx, FALSE, FALSE, friendly, pet, FALSE, (bool)(m_ptr->mflag2 & MFLAG_NOPET)))
+               if (place_monster_aux(0, y, x, new_r_idx, mode))
                {
                        /* Success */
                        polymorphed = TRUE;
                }
                else
                {
-                       monster_terrain_sensitive = FALSE;
-
                        /* Placing the new monster failed */
-                       place_monster_aux(y, x, old_r_idx, FALSE, FALSE, friendly, pet, TRUE, (bool)(m_ptr->mflag2 & MFLAG_NOPET));
-
-                       monster_terrain_sensitive = TRUE;
+                       place_monster_aux(0, y, x, old_r_idx, (mode | PM_NO_KAGE | PM_IGNORE_TERRAIN));
+                       m_list[hack_m_idx_ii] = back_m;
                }
+
+               if (targeted) target_who = hack_m_idx_ii;
+               if (health_tracked) health_track(hack_m_idx_ii);
        }
 
        return polymorphed;
@@ -5552,30 +5568,32 @@ bool dimension_door(void)
 
        if (!tgt_pt(&x, &y)) return FALSE;
 
-       p_ptr->energy -= 60 - plev;
+       p_ptr->energy_need += (s16b)((s32b)(60 - plev) * ENERGY_NEED() / 100L);
 
        if (!cave_empty_bold(y, x) || (cave[y][x].info & CAVE_ICKY) ||
                (distance(y, x, py, px) > plev / 2 + 10) ||
-               (!rand_int(plev / 10 + 10)))
+               (!randint0(plev / 10 + 10)))
        {
-         if( p_ptr->pclass != CLASS_MIRROR_MASTER ){
+               if( p_ptr->pclass != CLASS_MIRROR_MASTER ){
 #ifdef JP
-msg_print("ÀºÎ¤«¤éʪ¼Á³¦¤ËÌá¤ë»þ¤¦¤Þ¤¯¤¤¤«¤Ê¤«¤Ã¤¿¡ª");
+                       msg_print("ÀºÎ¤«¤éʪ¼Á³¦¤ËÌá¤ë»þ¤¦¤Þ¤¯¤¤¤«¤Ê¤«¤Ã¤¿¡ª");
 #else
-               msg_print("You fail to exit the astral plane correctly!");
+                       msg_print("You fail to exit the astral plane correctly!");
 #endif
-         }
-         else {
+               }
+               else
+               {
 #ifdef JP
-msg_print("¶À¤ÎÀ¤³¦¤ò¤¦¤Þ¤¯Ä̤ì¤Ê¤«¤Ã¤¿¡ª");
+                       msg_print("¶À¤ÎÀ¤³¦¤ò¤¦¤Þ¤¯Ä̤ì¤Ê¤«¤Ã¤¿¡ª");
 #else
-               msg_print("You fail to exit the astral plane correctly!");
+                       msg_print("You fail to exit the astral plane correctly!");
 #endif
-         }
-               p_ptr->energy -= 60 - plev;
+               }
+               p_ptr->energy_need += (s16b)((s32b)(60 - plev) * ENERGY_NEED() / 100L);
                teleport_player((plev+2)*2);
        }
-       else teleport_player_to(y, x, TRUE);
+       else
+               teleport_player_to(y, x, TRUE);
 
        return (TRUE);
 }
@@ -5624,7 +5642,7 @@ s = "
                recharge_strength = ((power > lev/2) ? (power - lev/2) : 0) / 5;
 
                /* Back-fire */
-               if (rand_int(recharge_strength) == 0)
+               if (one_in_(recharge_strength))
                {
                        /* Activate the failure code. */
                        fail = TRUE;
@@ -5656,7 +5674,7 @@ msg_print("
                if (recharge_strength < 0) recharge_strength = 0;
 
                /* Back-fire */
-               if (rand_int(recharge_strength) == 0)
+               if (one_in_(recharge_strength))
                {
                        /* Activate the failure code. */
                        fail = TRUE;
@@ -5748,19 +5766,19 @@ msg_format("
                                /* 10% chance to blow up one rod, otherwise draining. */
                                if (o_ptr->tval == TV_ROD)
                                {
-                                       if (randint(10) == 1) fail_type = 2;
+                                       if (one_in_(10)) fail_type = 2;
                                        else fail_type = 1;
                                }
                                /* 75% chance to blow up one wand, otherwise draining. */
                                else if (o_ptr->tval == TV_WAND)
                                {
-                                       if (randint(3) != 1) fail_type = 2;
+                                       if (!one_in_(3)) fail_type = 2;
                                        else fail_type = 1;
                                }
                                /* 50% chance to blow up one staff, otherwise no effect. */
                                else if (o_ptr->tval == TV_STAFF)
                                {
-                                       if (randint(2) == 1) fail_type = 2;
+                                       if (one_in_(2)) fail_type = 2;
                                        else fail_type = 0;
                                }
                        }
@@ -5771,13 +5789,13 @@ msg_format("
                                /* 33% chance to blow up one rod, otherwise draining. */
                                if (o_ptr->tval == TV_ROD)
                                {
-                                       if (randint(3) == 1) fail_type = 2;
+                                       if (one_in_(3)) fail_type = 2;
                                        else fail_type = 1;
                                }
                                /* 20% chance of the entire stack, else destroy one wand. */
                                else if (o_ptr->tval == TV_WAND)
                                {
-                                       if (randint(5) == 1) fail_type = 3;
+                                       if (one_in_(5)) fail_type = 3;
                                        else fail_type = 2;
                                }
                                /* Blow up one staff. */
@@ -5795,9 +5813,9 @@ msg_format("
                                if (o_ptr->tval == TV_ROD)
                                {
 #ifdef JP
-msg_print("ËâÎϤ¬µÕÊ®¼Í¤·¤Æ¡¢¥í¥Ã¥É¤«¤é¤µ¤é¤ËËâÎϤòµÛ¤¤¼è¤Ã¤Æ¤·¤Þ¤Ã¤¿¡ª");
+msg_print("¥í¥Ã¥É¤ÏÇË»¤òÌȤ줿¤¬¡¢ËâÎϤÏÁ´¤Æ¼º¤Ê¤ï¤ì¤¿¡£");
 #else
-                                       msg_print("The recharge backfires, draining the rod further!");
+                                       msg_format("You save your rod from destruction, but all charges are lost.", o_name);
 #endif
 
                                        o_ptr->timeout = k_ptr->pval * o_ptr->number;
@@ -5905,8 +5923,11 @@ msg_format("
 }
 
 
-bool summon_kin_player(bool pet, int level, int y, int x, bool group)
+bool summon_kin_player(int level, int y, int x, u32b mode)
 {
+       bool pet = (bool)(mode & PM_FORCE_PET);
+       if (!pet) mode |= PM_NO_PET;
+
        switch (p_ptr->mimic_form)
        {
        case MIMIC_NONE:
@@ -6007,5 +6028,5 @@ bool summon_kin_player(bool pet, int level, int y, int x, bool group)
                summon_kin_type = 'V';
                break;
        }       
-       return summon_specific((pet ? -1 : 0), y, x, level, SUMMON_KIN, group, FALSE, pet, FALSE, (bool)(!pet));
+       return summon_specific((pet ? -1 : 0), y, x, level, SUMMON_KIN, mode);
 }