OSDN Git Service

Leon氏の勧めに従って、Vanillaのコードと同様に各ソースファイルの頭の
[hengband/hengband.git] / src / cmd5.c
index 338e83d..860ff9f 100644 (file)
@@ -1,15 +1,15 @@
 /* File: cmd5.c */
 
-/* Purpose: Spell/Prayer commands */
-
 /*
- * Copyright (c) 1989 James E. Wilson, Robert A. Koeneke
+ * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
  *
- * This software may be copied and distributed for educational, research, and
- * not for profit purposes provided that this copyright and statement are
- * included in all such copies.
+ * This software may be copied and distributed for educational, research,
+ * and not for profit purposes provided that this copyright and statement
+ * are included in all such copies.  Other copyrights may also apply.
  */
 
+/* Purpose: Spell/Prayer commands */
+
 #include "angband.h"
 
 #include "spellstips.h"
@@ -51,7 +51,6 @@ cptr spell_categoly_name(int tval)
  * The "known" should be TRUE for cast/pray, FALSE for study
  */
 
-bool select_spellbook=FALSE;
 bool select_the_force=FALSE;
 
 static int get_spell(int *sn, cptr prompt, int sval, bool learned, int use_realm)
@@ -68,7 +67,7 @@ static int get_spell(int *sn, cptr prompt, int sval, bool learned, int use_realm
        char        out_val[160];
        cptr        p;
 #ifdef JP
-        char jverb_buf[128];
+       char jverb_buf[128];
 #endif
        int menu_line = (use_menu ? 1 : 0);
 
@@ -78,7 +77,7 @@ static int get_spell(int *sn, cptr prompt, int sval, bool learned, int use_realm
        if (repeat_pull(sn))
        {
                /* Verify the spell */
-               if (spell_okay(*sn, learned, FALSE, use_realm - 1))
+               if (spell_okay(*sn, learned, FALSE, use_realm))
                {
                        /* Success */
                        return (TRUE);
@@ -110,7 +109,7 @@ static int get_spell(int *sn, cptr prompt, int sval, bool learned, int use_realm
        for (i = 0; i < num; i++)
        {
                /* Look for "okay" spells */
-               if (spell_okay(spells[i], learned, FALSE, use_realm - 1)) okay = TRUE;
+               if (spell_okay(spells[i], learned, FALSE, use_realm)) okay = TRUE;
        }
 
        /* No "okay" spells */
@@ -142,7 +141,7 @@ static int get_spell(int *sn, cptr prompt, int sval, bool learned, int use_realm
 #ifdef JP
        jverb1( prompt, jverb_buf );
        (void) strnfmt(out_val, 78, "(%^s:%c-%c, '*'¤Ç°ìÍ÷, ESC¤ÇÃæÃÇ) ¤É¤Î%s¤ò%^s¤Þ¤¹¤«? ",
-               p, I2A(0), I2A(num - 1), p, jverb_buf );
+               p, I2A(0), I2A(num - 1), p, jverb_buf );
 #else
        (void)strnfmt(out_val, 78, "(%^ss %c-%c, *=List, ESC=exit) %^s which %s? ",
                p, I2A(0), I2A(num - 1), prompt, p);
@@ -150,9 +149,9 @@ static int get_spell(int *sn, cptr prompt, int sval, bool learned, int use_realm
 
        /* Get a spell from the user */
 
-        choice = (always_show_list || use_menu) ? ESCAPE:1;
-        while (!flag)
-        {
+       choice = (always_show_list || use_menu) ? ESCAPE:1;
+       while (!flag)
+       {
                if( choice==ESCAPE ) choice = ' '; 
                else if( !get_com(out_val, &choice, TRUE) )break; 
 
@@ -186,6 +185,7 @@ static int get_spell(int *sn, cptr prompt, int sval, bool learned, int use_realm
                                case 'x':
                                case 'X':
                                case '\r':
+                               case '\n':
                                {
                                        i = menu_line - 1;
                                        ask = FALSE;
@@ -194,7 +194,7 @@ static int get_spell(int *sn, cptr prompt, int sval, bool learned, int use_realm
                        }
                        if (menu_line > num) menu_line -= num;
                        /* Display a list of spells */
-                       print_spells(menu_line, spells, num, 1, 15, use_realm - 1);
+                       print_spells(menu_line, spells, num, 1, 15, use_realm);
                        if (ask) continue;
                }
                else
@@ -212,7 +212,7 @@ static int get_spell(int *sn, cptr prompt, int sval, bool learned, int use_realm
                                        screen_save();
 
                                        /* Display a list of spells */
-                                       print_spells(menu_line, spells, num, 1, 15, use_realm - 1);
+                                       print_spells(menu_line, spells, num, 1, 15, use_realm);
                                }
 
                                /* Hide the list */
@@ -253,11 +253,11 @@ static int get_spell(int *sn, cptr prompt, int sval, bool learned, int use_realm
                spell = spells[i];
 
                /* Require "okay" spells */
-               if (!spell_okay(spell, learned, FALSE, use_realm - 1))
+               if (!spell_okay(spell, learned, FALSE, use_realm))
                {
                        bell();
 #ifdef JP
-                        msg_format("¤½¤Î%s¤ò%s¤³¤È¤Ï¤Ç¤­¤Þ¤»¤ó¡£", p, prompt);
+                       msg_format("¤½¤Î%s¤ò%s¤³¤È¤Ï¤Ç¤­¤Þ¤»¤ó¡£", p, prompt);
 #else
                        msg_format("You may not %s that %s.", prompt, p);
 #endif
@@ -273,11 +273,11 @@ static int get_spell(int *sn, cptr prompt, int sval, bool learned, int use_realm
                        /* Access the spell */
                        if (!is_magic(use_realm))
                        {
-                               s_ptr = &technic_info[use_realm - MIN_TECHNIC - 1][spell];
+                               s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
                        }
                        else
                        {
-                               s_ptr = &mp_ptr->info[use_realm - 1][spell % 32];
+                               s_ptr = &mp_ptr->info[use_realm - 1][spell];
                        }
 
                        if (use_realm == REALM_HISSATSU)
@@ -286,12 +286,8 @@ static int get_spell(int *sn, cptr prompt, int sval, bool learned, int use_realm
                        }
                        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
-                                       shouhimana = (s_ptr->smana*(3800-spell_exp[spell])+2399);
+                               /* Extract mana consumption rate */
+                               shouhimana = s_ptr->smana*(3800 - experience_of_spell(spell, use_realm)) + 2399;
                                if(p_ptr->dec_mana)
                                        shouhimana *= 3;
                                else shouhimana *= 4;
@@ -302,14 +298,14 @@ static int get_spell(int *sn, cptr prompt, int sval, bool learned, int use_realm
                        /* Prompt */
 #ifdef JP
                        jverb1( prompt, jverb_buf );
-                        /* ±ÑÆüÀÚ¤êÂؤ¨µ¡Ç½¤ËÂбþ */
-                        (void) strnfmt(tmp_val, 78, "%s(MP%d, ¼ºÇÔΨ%d%%)¤ò%s¤Þ¤¹¤«? ",
-                                spell_names[technic2magic(use_realm)-1][spell % 32], shouhimana,
-                                      spell_chance(spell, use_realm -1),jverb_buf);
+                       /* ±ÑÆüÀÚ¤êÂؤ¨µ¡Ç½¤ËÂбþ */
+                       (void) strnfmt(tmp_val, 78, "%s(MP%d, ¼ºÇÔΨ%d%%)¤ò%s¤Þ¤¹¤«? ",
+                               spell_names[technic2magic(use_realm)-1][spell], shouhimana,
+                                      spell_chance(spell, use_realm),jverb_buf);
 #else
                        (void)strnfmt(tmp_val, 78, "%^s %s (%d mana, %d%% fail)? ",
-                               prompt, spell_names[technic2magic(use_realm)-1][spell % 32], shouhimana,
-                               spell_chance(spell, use_realm - 1));
+                               prompt, spell_names[technic2magic(use_realm)-1][spell], shouhimana,
+                               spell_chance(spell, use_realm));
 #endif
 
 
@@ -360,13 +356,13 @@ static bool item_tester_learn_spell(object_type *o_ptr)
 
        if (p_ptr->pclass == CLASS_PRIEST)
        {
-               if (p_ptr->realm1 == REALM_LIFE)
+               if (is_good_realm(p_ptr->realm1))
                {
                        choices &= ~(CH_DEATH | CH_DAEMON);
                }
-               else if ((p_ptr->realm1 == REALM_DEATH) || (p_ptr->realm1 == REALM_DAEMON))
+               else
                {
-                       choices &= ~(CH_LIFE);
+                       choices &= ~(CH_LIFE | CH_CRUSADE);
                }
        }
 
@@ -436,15 +432,12 @@ s = "
        s = "You have no books that you can read.";
 #endif
 
-        select_spellbook=TRUE;
        if (p_ptr->pclass == CLASS_FORCETRAINER)
                select_the_force = TRUE;
        if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))){
-            select_spellbook = FALSE;
            select_the_force = FALSE;
-            return;
-        }
-        select_spellbook = FALSE;
+           return;
+       }
        select_the_force = FALSE;
 
        if (item == 1111) { /* the_force */
@@ -463,10 +456,6 @@ s = "
                o_ptr = &o_list[0 - item];
        }
 
-#ifdef USE_SCRIPT
-       if (object_browse_callback(o_ptr)) return;
-#endif /* USE_SCRIPT */
-
        /* Access the item's sval */
        sval = o_ptr->sval;
 
@@ -516,7 +505,7 @@ s = "
                        if (spell == -1) break;
 
                        /* Display a list of spells */
-                       print_spells(0, spells, num, 1, 15, use_realm - 1);
+                       print_spells(0, spells, num, 1, 15, use_realm);
 
                        /* Notify that there's nothing to see, and wait. */
                        if (use_realm == REALM_HISSATSU)
@@ -549,14 +538,14 @@ s = "
                /* Access the spell */
                if (!is_magic(use_realm))
                {
-                       s_ptr = &technic_info[use_realm - MIN_TECHNIC - 1][spell];
+                       s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
                }
                else
                {
                        s_ptr = &mp_ptr->info[use_realm - 1][spell];
                }
 
-               roff_to_buf( spell_tips[technic2magic(use_realm)-1][spell] ,62,temp);
+               roff_to_buf(spell_tips[technic2magic(use_realm)-1][spell] ,62, temp, sizeof(temp));
                for(j=0, line = 11;temp[j];j+=(1+strlen(&temp[j])))
                {
                        prt(&temp[j], line, 15);
@@ -576,19 +565,19 @@ static void change_realm2(int next_realm)
 
        for (i = 0; i < 64; i++)
        {
-               spell_order[j] = spell_order[i];
-               if(spell_order[i] < 32) j++;
+               p_ptr->spell_order[j] = p_ptr->spell_order[i];
+               if(p_ptr->spell_order[i] < 32) j++;
        }
        for (; j < 64; j++)
-               spell_order[j] = 99;
+               p_ptr->spell_order[j] = 99;
 
        for (i = 32; i < 64; i++)
        {
-               spell_exp[i] = 0;
+               p_ptr->spell_exp[i] = 0;
        }
-       spell_learned2 = 0L;
-       spell_worked2 = 0L;
-       spell_forgotten2 = 0L;  
+       p_ptr->spell_learned2 = 0L;
+       p_ptr->spell_worked2 = 0L;
+       p_ptr->spell_forgotten2 = 0L;   
 
 #ifdef JP
        sprintf(tmp,"ËâË¡¤ÎÎΰè¤ò%s¤«¤é%s¤ËÊѹ¹¤·¤¿¡£", realm_names[p_ptr->realm2], realm_names[next_realm]);
@@ -705,9 +694,7 @@ s = "
        s = "You have no books that you can read.";
 #endif
 
-        select_spellbook=TRUE;
        if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
-        select_spellbook=FALSE;
 
        /* Get the item (in the pack) */
        if (item >= 0)
@@ -747,7 +734,7 @@ s = "
        {
                /* Ask for a spell, allow cancel */
 #ifdef JP
-                if (!get_spell(&spell, "³Ø¤Ö", sval, FALSE, o_ptr->tval - TV_LIFE_BOOK + 1)
+               if (!get_spell(&spell, "³Ø¤Ö", sval, FALSE, o_ptr->tval - TV_LIFE_BOOK + 1)
                        && (spell == -1)) return;
 #else
                if (!get_spell(&spell, "study", sval, FALSE, o_ptr->tval - TV_LIFE_BOOK + 1)
@@ -771,13 +758,13 @@ s = "
                        {
                                /* Skip non "okay" prayers */
                                if (!spell_okay(spell, FALSE, TRUE,
-                                       (increment ? p_ptr->realm2 - 1 : p_ptr->realm1 - 1))) continue;
+                                       (increment ? p_ptr->realm2 : p_ptr->realm1))) continue;
 
                                /* Hack -- Prepare the randomizer */
                                k++;
 
                                /* Hack -- Apply the randomizer */
-                               if (rand_int(k) == 0) gift = spell;
+                               if (one_in_(k)) gift = spell;
                        }
                }
 
@@ -806,19 +793,19 @@ msg_format("
        /* Learn the spell */
        if (spell < 32)
        {
-               if (spell_learned1 & (1L << spell)) learned = TRUE;
-               else spell_learned1 |= (1L << spell);
+               if (p_ptr->spell_learned1 & (1L << spell)) learned = TRUE;
+               else p_ptr->spell_learned1 |= (1L << spell);
        }
        else
        {
-               if (spell_learned2 & (1L << (spell - 32))) learned = TRUE;
-               else spell_learned2 |= (1L << (spell - 32));
+               if (p_ptr->spell_learned2 & (1L << (spell - 32))) learned = TRUE;
+               else p_ptr->spell_learned2 |= (1L << (spell - 32));
        }
 
        if (learned)
        {
                int max_exp = (spell < 32) ? 1600 : 1400;
-               int old_exp = spell_exp[spell];
+               int old_exp = p_ptr->spell_exp[spell];
                int new_rank = 0;
                cptr name = spell_names[technic2magic(increment ? p_ptr->realm2 : p_ptr->realm1)-1][spell%32];
 
@@ -841,23 +828,23 @@ msg_format("
                }
                else if (old_exp >= 1400)
                {
-                       spell_exp[spell] = 1600;
+                       p_ptr->spell_exp[spell] = 1600;
                        new_rank = 4;
                }
                else if (old_exp >= 1200)
                {
-                       if (spell >= 32) spell_exp[spell] = 1400;
-                       else spell_exp[spell] += 200;
+                       if (spell >= 32) p_ptr->spell_exp[spell] = 1400;
+                       else p_ptr->spell_exp[spell] += 200;
                        new_rank = 3;
                }
                else if (old_exp >= 900)
                {
-                       spell_exp[spell] = 1200+(old_exp-900)*2/3;
+                       p_ptr->spell_exp[spell] = 1200+(old_exp-900)*2/3;
                        new_rank = 2;
                }
                else
                {
-                       spell_exp[spell] = 900+(old_exp)/3;
+                       p_ptr->spell_exp[spell] = 900+(old_exp)/3;
                        new_rank = 1;
                }
 #ifdef JP
@@ -868,27 +855,27 @@ msg_format("
        }
        else
        {
-               /* Find the next open entry in "spell_order[]" */
+               /* Find the next open entry in "p_ptr->spell_order[]" */
                for (i = 0; i < 64; i++)
                {
                        /* Stop at the first empty space */
-                       if (spell_order[i] == 99) break;
+                       if (p_ptr->spell_order[i] == 99) break;
                }
 
                /* Add the spell to the known list */
-               spell_order[i++] = spell;
+               p_ptr->spell_order[i++] = spell;
 
                /* Mention the result */
 #ifdef JP
-               /* ±ÑÆüÀÚ¤êÂؤ¨µ¡Ç½¤ËÂбþ */
+               /* ±ÑÆüÀÚ¤êÂؤ¨µ¡Ç½¤ËÂбþ */
                if (mp_ptr->spell_book == TV_MUSIC_BOOK)
                {
-                       msg_format("%s¤ò³Ø¤ó¤À¡£",
+                       msg_format("%s¤ò³Ø¤ó¤À¡£",
                                    spell_names[technic2magic(increment ? p_ptr->realm2 : p_ptr->realm1)-1][spell % 32]);
                }
                else
                {
-                       msg_format("%s¤Î%s¤ò³Ø¤ó¤À¡£",
+                       msg_format("%s¤Î%s¤ò³Ø¤ó¤À¡£",
                                    spell_names[technic2magic(increment ? p_ptr->realm2 : p_ptr->realm1)-1][spell % 32] ,p);
                }
 #else
@@ -920,11 +907,11 @@ msg_format("
        {
                /* Message */
 #ifdef JP
-                        if( p_ptr->new_spells < 10 ){
-                                msg_format("¤¢¤È %d ¤Ä¤Î%s¤ò³Ø¤Ù¤ë¡£", p_ptr->new_spells, p);
-                        }else{
-                                msg_format("¤¢¤È %d ¸Ä¤Î%s¤ò³Ø¤Ù¤ë¡£", p_ptr->new_spells, p);
-                        }
+                       if( p_ptr->new_spells < 10 ){
+                               msg_format("¤¢¤È %d ¤Ä¤Î%s¤ò³Ø¤Ù¤ë¡£", p_ptr->new_spells, p);
+                       }else{
+                               msg_format("¤¢¤È %d ¸Ä¤Î%s¤ò³Ø¤Ù¤ë¡£", p_ptr->new_spells, p);
+                       }
 #else
                msg_format("You can learn %d more %s%s.",
                        p_ptr->new_spells, p,
@@ -937,18 +924,21 @@ msg_format("
        /* Update Study */
        p_ptr->update |= (PU_SPELLS);
        update_stuff();
+
+       /* Redraw object recall */
+       p_ptr->window |= (PW_OBJECT);
 }
 
 
-void wild_magic(int spell)
+static void wild_magic(int spell)
 {
        int counter = 0;
-       int type = SUMMON_BIZARRE1 + rand_int(6);
+       int type = SUMMON_BIZARRE1 + randint0(6);
 
        if (type < SUMMON_BIZARRE1) type = SUMMON_BIZARRE1;
        else if (type > SUMMON_BIZARRE6) type = SUMMON_BIZARRE6;
 
-       switch (randint(spell) + randint(8) + 1)
+       switch (randint1(spell) + randint1(8) + 1)
        {
        case 1:
        case 2:
@@ -1004,7 +994,7 @@ void wild_magic(int spell)
                break;
        case 29:
        case 30:
-               apply_disenchant(0);
+               apply_disenchant(1);
                break;
        case 31:
                lose_all_info();
@@ -1019,7 +1009,7 @@ void wild_magic(int spell)
        case 35:
                while (counter++ < 8)
                {
-                       (void)summon_specific(0, py, px, (dun_level * 3) / 2, type, TRUE, FALSE, FALSE, FALSE, TRUE);
+                       (void)summon_specific(0, py, px, (dun_level * 3) / 2, type, (PM_ALLOW_GROUP | PM_NO_PET));
                }
                break;
        case 36:
@@ -1048,31 +1038,32 @@ static bool cast_life_spell(int spell)
 
        switch (spell)
        {
-       case 0: /* Detect Evil */
-               (void)detect_monsters_evil(DETECT_RAD_DEFAULT);
-               break;
-       case 1: /* Cure Light Wounds */
+       case 0: /* Cure Light Wounds */
                (void)hp_player(damroll(2, 10));
                (void)set_cut(p_ptr->cut - 10);
                break;
-       case 2: /* Bless */
-               (void)set_blessed(randint(12) + 12, FALSE);
+       case 1: /* Bless */
+               (void)set_blessed(randint1(12) + 12, FALSE);
                break;
-       case 3: /* Remove Fear */
-               (void)set_afraid(0);
+       case 2: /* Make Light Wounds */
+               if (!get_aim_dir(&dir)) return FALSE;
+               fire_ball_hide(GF_WOUNDS, dir, damroll(3 + ((plev - 1) / 5), 4), 0);
                break;
-       case 4: /* Call Light */
+       case 3: /* Call Light */
                (void)lite_area(damroll(2, (plev / 2)), (plev / 10) + 1);
                break;
-       case 5: /* Detect Traps + Secret Doors */
-               (void)detect_traps(DETECT_RAD_DEFAULT);
+       case 4: /* Detect Traps + Secret Doors */
+               (void)detect_traps(DETECT_RAD_DEFAULT, TRUE);
                (void)detect_doors(DETECT_RAD_DEFAULT);
                (void)detect_stairs(DETECT_RAD_DEFAULT);
                break;
-       case 6: /* Cure Medium Wounds */
+       case 5: /* Cure Medium Wounds */
                (void)hp_player(damroll(4, 10));
                (void)set_cut((p_ptr->cut / 2) - 20);
                break;
+       case 6: /* Cure Poison */
+               (void)set_poisoned(0);
+               break;
        case 7: /* Satisfy Hunger */
                (void)set_food(PY_FOOD_MAX - 1);
                break;
@@ -1086,30 +1077,24 @@ static bool cast_life_spell(int spell)
 #endif
                }
                break;
-       case 9: /* Cure Poison */
-               (void)set_poisoned(0);
+       case 9: /* Make Medium Wounds */
+               if (!get_aim_dir(&dir)) return FALSE;
+               fire_ball_hide(GF_WOUNDS, dir, damroll(8 + ((plev - 5) / 4), 8), 0);
                break;
        case 10: /* Cure Critical Wounds */
                (void)hp_player(damroll(8, 10));
                (void)set_stun(0);
                (void)set_cut(0);
                break;
-       case 11: /* Sense Unseen */
-               (void)set_tim_invis(randint(24) + 24, FALSE);
+       case 11:
+               (void)set_oppose_cold(randint1(20) + 20, FALSE);
+               (void)set_oppose_fire(randint1(20) + 20, FALSE);
                break;
-       case 12: /* Holy Orb */
-               if (!get_aim_dir(&dir)) return FALSE;
-
-               fire_ball(GF_HOLY_FIRE, dir,
-                         (damroll(3, 6) + plev +
-                         (plev / ((p_ptr->pclass == CLASS_PRIEST ||
-                            p_ptr->pclass == CLASS_HIGH_MAGE ||
-                            p_ptr->pclass == CLASS_SORCERER) ? 2 : 4))),
-                         ((plev < 30) ? 2 : 3));
-
+       case 12:
+               map_area(DETECT_RAD_MAP);
                break;
-       case 13: /* Protection from Evil */
-               (void)set_protevil(randint(25) + 3 * p_ptr->lev, FALSE);
+       case 13:
+               (void)turn_undead();
                break;
        case 14: /* Healing */
                (void)hp_player(300);
@@ -1119,12 +1104,7 @@ static bool cast_life_spell(int spell)
        case 15: /* Glyph of Warding */
                warding_glyph();
                break;
-       case 16: /* Exorcism */
-               (void)dispel_undead(randint(plev));
-               (void)dispel_demons(randint(plev));
-               (void)turn_evil(plev);
-               break;
-       case 17: /* Dispel Curse */
+       case 16: /* Dispel Curse */
                if (remove_all_curse())
                {
 #ifdef JP
@@ -1134,51 +1114,41 @@ static bool cast_life_spell(int spell)
 #endif
                }
                break;
-       case 18: /* Dispel Undead + Demons */
-               (void)dispel_undead(randint(plev * 3));
-               (void)dispel_demons(randint(plev * 3));
+       case 17: /* Perception */
+               return ident_spell(FALSE);
+       case 18: /* Dispel Undead */
+               (void)dispel_undead(randint1(plev * 5));
                break;
        case 19: /* 'Day of the Dove' */
                charm_monsters(plev * 2);
                break;
-       case 20: /* Dispel Evil */
-               (void)dispel_evil(randint(plev * 4));
+       case 20: /* Make Critical Wounds */
+               if (!get_aim_dir(&dir)) return FALSE;
+               fire_ball_hide(GF_WOUNDS, dir, damroll(5+((plev - 5) / 3), 15), 0);
                break;
-       case 21: /* Banishment */
-               if (banish_evil(100))
-               {
-#ifdef JP
-msg_print("¿À¤Î¸æÎϤ¬¼Ù°­¤òÂǤÁʧ¤Ã¤¿¡ª");
-#else
-                       msg_print("The power of your god banishes evil!");
-#endif
-
-               }
+       case 21: /* Word of Recall */
+               if (!word_of_recall()) return FALSE;
                break;
-       case 22: /* Holy Word */
-               (void)dispel_evil(randint(plev * 4));
-               (void)hp_player(1000);
-               (void)set_afraid(0);
-               (void)set_poisoned(0);
-               (void)set_stun(0);
-               (void)set_cut(0);
+       case 22: /* Alter Reality */
+               alter_reality();
                break;
        case 23: /* Warding True */
                warding_glyph();
                glyph_creation();
                break;
-       case 24: /* Heroism */
-               (void)set_hero(randint(25) + 25, FALSE);
-               (void)hp_player(10);
-               (void)set_afraid(0);
+       case 24:
+               num_repro += MAX_REPRO;
                break;
-       case 25: /* Prayer */
-               (void)set_blessed(randint(48) + 48, FALSE);
+       case 25: /* Detection True */
+               (void)detect_all(DETECT_RAD_DEFAULT);
                break;
-       case 26: /* Turn Undead */
+       case 26: /* Genocide Undead */
                (void)mass_genocide_undead(plev+50,TRUE);
                break;
-       case 27: /* Restoration */
+       case 27: /* Clairvoyance */
+               wiz_lite(FALSE);
+               break;
+       case 28: /* Restoration */
                (void)do_res_stat(A_STR);
                (void)do_res_stat(A_INT);
                (void)do_res_stat(A_WIS);
@@ -1187,30 +1157,16 @@ msg_print("
                (void)do_res_stat(A_CHR);
                (void)restore_level();
                break;
-       case 28: /* Healing True */
+       case 29: /* Healing True */
                (void)hp_player(2000);
                (void)set_stun(0);
                (void)set_cut(0);
                break;
-       case 29: /* Holy Vision */
+       case 30: /* Holy Vision */
                return identify_fully(FALSE);
-       case 30: /* Divine Intervention */
-               project(0, 1, py, px, 500, GF_HOLY_FIRE, PROJECT_KILL, -1);
-               dispel_monsters(plev * 4);
-               slow_monsters();
-               stun_monsters(plev * 4);
-               confuse_monsters(plev * 4);
-               turn_monsters(plev * 4);
-               stasis_monsters(plev * 4);
-               summon_specific(-1, py, px, plev, SUMMON_ANGEL, TRUE, TRUE, TRUE, FALSE, FALSE);
-               (void)set_hero(randint(25) + 25, FALSE);
-               (void)hp_player(300);
-               (void)set_fast(randint(20 + plev) + plev, FALSE);
-               (void)set_afraid(0);
-               break;
        case 31: /* Ultimate resistance */
        {
-               int v = randint(plev/2)+plev/2;
+               int v = randint1(plev/2)+plev/2;
                (void)set_fast(v, FALSE);
                set_oppose_acid(v, FALSE);
                set_oppose_elec(v, FALSE);
@@ -1249,7 +1205,7 @@ static bool cast_sorcery_spell(int spell)
                teleport_player(10);
                break;
        case 2: /* Detect Doors and Traps */
-               (void)detect_traps(DETECT_RAD_DEFAULT);
+               (void)detect_traps(DETECT_RAD_DEFAULT, TRUE);
                (void)detect_doors(DETECT_RAD_DEFAULT);
                (void)detect_stairs(DETECT_RAD_DEFAULT);
                break;
@@ -1290,7 +1246,7 @@ static bool cast_sorcery_spell(int spell)
                (void)fire_beam(GF_AWAY_ALL, dir, plev);
                break;
        case 13: /* Haste Self */
-               (void)set_fast(randint(20 + plev) + plev, FALSE);
+               (void)set_fast(randint1(20 + plev) + plev, FALSE);
                break;
        case 14: /* Detection True */
                (void)detect_all(DETECT_RAD_DEFAULT);
@@ -1308,7 +1264,7 @@ static bool cast_sorcery_spell(int spell)
                (void)charm_monster(dir, plev);
                break;
        case 18: /* Sense Minds */
-               (void)set_tim_esp(randint(30) + 25, FALSE);
+               (void)set_tim_esp(randint1(30) + 25, FALSE);
                break;
        case 19: /* Teleport to town */
                return tele_town();
@@ -1350,10 +1306,10 @@ msg_print("
                chg_virtue(V_KNOWLEDGE, 1);
                chg_virtue(V_ENLIGHTEN, 1);
 
-               wiz_lite(FALSE, FALSE);
+               wiz_lite(FALSE);
                if (!(p_ptr->telepathy))
                {
-                       (void)set_tim_esp(randint(30) + 25, FALSE);
+                       (void)set_tim_esp(randint1(30) + 25, FALSE);
                }
                break;
        case 28: /* Charm Monsters */
@@ -1365,7 +1321,7 @@ msg_print("
                banish_monsters(plev * 4);
                break;
        case 31: /* Globe of Invulnerability */
-               (void)set_invuln(randint(4) + 4, FALSE);
+               (void)set_invuln(randint1(4) + 4, FALSE);
                break;
        default:
 #ifdef JP
@@ -1405,13 +1361,28 @@ static bool cast_nature_spell(int spell)
                        damroll(3 + ((plev - 1) / 5), 4));
                break;
        case 2: /* Detect Doors & Traps */
-               (void)detect_traps(DETECT_RAD_DEFAULT);
+               (void)detect_traps(DETECT_RAD_DEFAULT, TRUE);
                (void)detect_doors(DETECT_RAD_DEFAULT);
                (void)detect_stairs(DETECT_RAD_DEFAULT);
                break;
        case 3: /* Produce Food */
-               (void)set_food(PY_FOOD_MAX - 1);
+       {
+               object_type forge, *q_ptr = &forge;
+
+#ifdef JP
+               msg_print("¿©ÎÁ¤òÀ¸À®¤·¤¿¡£");
+#else
+               msg_print("A food ration is produced.");
+#endif
+
+               /* Create the food ration */
+               object_prep(q_ptr, lookup_kind(TV_FOOD, SV_FOOD_RATION));
+
+               /* Drop the object from heaven */
+               (void)drop_near(q_ptr, -1, py, px);
                break;
+
+       }
        case 4: /* Daylight */
                (void)lite_area(damroll(2, (plev / 2)), (plev / 10) + 1);
                if ((prace_is_(RACE_VAMPIRE) || (p_ptr->mimic_form == MIMIC_VAMPIRE)) && !p_ptr->resist_lite)
@@ -1436,9 +1407,9 @@ take_hit(DAMAGE_NOESCAPE, damroll(2, 2), "
                (void)charm_animal(dir, plev);
                break;
        case 6: /* Resist Environment */
-               (void)set_oppose_cold(randint(20) + 20, FALSE);
-               (void)set_oppose_fire(randint(20) + 20, FALSE);
-               (void)set_oppose_elec(randint(20) + 20, FALSE);
+               (void)set_oppose_cold(randint1(20) + 20, FALSE);
+               (void)set_oppose_fire(randint1(20) + 20, FALSE);
+               (void)set_oppose_elec(randint1(20) + 20, FALSE);
                break;
        case 7: /* Cure Wounds & Poison */
                (void)hp_player(damroll(2, 8));
@@ -1457,7 +1428,7 @@ take_hit(DAMAGE_NOESCAPE, damroll(2, 2), "
                break;
        case 10: /* Nature Awareness -- downgraded */
                map_area(DETECT_RAD_MAP);
-               (void)detect_traps(DETECT_RAD_DEFAULT);
+               (void)detect_traps(DETECT_RAD_DEFAULT, TRUE);
                (void)detect_doors(DETECT_RAD_DEFAULT);
                (void)detect_stairs(DETECT_RAD_DEFAULT);
                (void)detect_monsters_normal(DETECT_RAD_DEFAULT);
@@ -1481,7 +1452,7 @@ msg_print("
                slow_monsters();
                break;
        case 14: /* Summon Animals */
-               if (!(summon_specific(-1, py, px, plev, SUMMON_ANIMAL_RANGER, TRUE, TRUE, TRUE, FALSE, FALSE)))
+               if (!(summon_specific(-1, py, px, plev, SUMMON_ANIMAL_RANGER, (PM_ALLOW_GROUP | PM_FORCE_PET))))
                        no_trump = TRUE;
                break;
        case 15: /* Herbal Healing */
@@ -1494,14 +1465,14 @@ msg_print("
                (void)stair_creation();
                break;
        case 17: /* Stone Skin */
-               (void)set_shield(randint(20) + 30, FALSE);
+               (void)set_shield(randint1(20) + 30, FALSE);
                break;
        case 18: /* Resistance True */
-               (void)set_oppose_acid(randint(20) + 20, FALSE);
-               (void)set_oppose_elec(randint(20) + 20, FALSE);
-               (void)set_oppose_fire(randint(20) + 20, FALSE);
-               (void)set_oppose_cold(randint(20) + 20, FALSE);
-               (void)set_oppose_pois(randint(20) + 20, FALSE);
+               (void)set_oppose_acid(randint1(20) + 20, FALSE);
+               (void)set_oppose_elec(randint1(20) + 20, FALSE);
+               (void)set_oppose_fire(randint1(20) + 20, FALSE);
+               (void)set_oppose_cold(randint1(20) + 20, FALSE);
+               (void)set_oppose_pois(randint1(20) + 20, FALSE);
                break;
        case 19: /* Tree Creation */
                (void)tree_creation();
@@ -1557,7 +1528,7 @@ msg_print("
                fire_ball(GF_LITE, 0, 150, 8);
                chg_virtue(V_KNOWLEDGE, 1);
                chg_virtue(V_ENLIGHTEN, 1);
-               wiz_lite(FALSE, FALSE);
+               wiz_lite(FALSE);
                if ((prace_is_(RACE_VAMPIRE) || (p_ptr->mimic_form == MIMIC_VAMPIRE)) && !p_ptr->resist_lite)
                {
 #ifdef JP
@@ -1575,7 +1546,7 @@ take_hit(DAMAGE_NOESCAPE, 50, "
                }
                break;
        case 30: /* Elemental Branding */
-               brand_weapon(rand_int(2));
+               brand_weapon(randint0(2));
                break;
        case 31: /* Nature's Wrath */
                (void)dispel_monsters(plev * 4);
@@ -1677,17 +1648,17 @@ msg_print("
                keeping the results quite random.  It also allows
                        some potent effects only at high level. */
 
-                       int die = randint(100) + plev / 5;
+                       int die = randint1(100) + plev / 5;
                        int vir = virtue_number(V_CHANCE);
                        if (vir)
                        {
                                if (p_ptr->virtues[vir - 1] > 0)
                                {
-                                       while (randint(400) < p_ptr->virtues[vir - 1]) die++;
+                                       while (randint1(400) < p_ptr->virtues[vir - 1]) die++;
                                }
                                else
                                {
-                                       while (randint(400) < (0-p_ptr->virtues[vir - 1])) die--;
+                                       while (randint1(400) < (0-p_ptr->virtues[vir - 1])) die--;
                                }
                        }
 
@@ -1736,7 +1707,7 @@ msg_print("
                        }
                        else if (die < 106)
                        {
-                               destroy_area(py, px, 13+rand_int(5), TRUE);
+                               destroy_area(py, px, 13+randint0(5));
                        }
                        else if (die < 108)
                        {
@@ -1785,7 +1756,7 @@ msg_print("
                (void)fire_beam(GF_AWAY_ALL, dir, plev);
                break;
        case 14: /* Word of Destruction */
-               destroy_area(py, px, 13+rand_int(5), TRUE);
+               destroy_area(py, px, 13+randint0(5));
                break;
        case 15: /* Invoke Logrus */
                if (!get_aim_dir(&dir)) return FALSE;
@@ -1827,10 +1798,14 @@ msg_print("
                break;
        case 23: /* Summon monster, demon */
                {
-                       bool pet = (randint(3) == 1);
-                       bool group = !(pet && (plev < 50));
+                       u32b mode = 0L;
+                       bool pet = !one_in_(3);
+
+                       if (pet) mode |= PM_FORCE_PET;
+                       else mode |= PM_NO_PET;
+                       if (!(pet && (plev < 50))) mode |= PM_ALLOW_GROUP;
 
-                       if (summon_specific((pet ? -1 : 0), py, px, (plev * 3) / 2, SUMMON_DEMON, group, FALSE, pet, FALSE, (bool)(!pet)))
+                       if (summon_specific((pet ? -1 : 0), py, px, (plev * 3) / 2, SUMMON_DEMON, mode))
                        {
 #ifdef JP
 msg_print("ⲫ¤Î°­½­¤¬½¼Ëþ¤·¤¿¡£");
@@ -1864,7 +1839,7 @@ msg_print("
        case 25: /* Meteor Swarm  */
                {
                        int x, y, dx, dy;
-                       int b = 10 + randint(10);
+                       int b = 10 + randint1(10);
                        for (i = 0; i < b; i++)
                        {
                                int count = 0, d = 0;
@@ -1873,8 +1848,8 @@ msg_print("
                                {
                                        count++;
                                        if (count > 20) break;
-                                       x = px - 8 + rand_int(17);
-                                       y = py - 8 + rand_int(17);
+                                       x = px - 8 + randint0(17);
+                                       y = py - 8 + randint0(17);
 
                                        if (!in_bounds(y,x) || (!cave_floor_bold(y,x) && (cave[y][x].feat != FEAT_TREES)) || !player_has_los_bold(y, x)) continue;
 
@@ -1959,9 +1934,9 @@ static bool cast_death_spell(int spell)
                fire_ball(GF_HELL_FIRE, dir,
                        damroll(3 + ((plev - 1) / 5), 4), 0);
 
-               if (randint(5) == 1)
+               if (one_in_(5))
                {   /* Special effect first */
-                       dummy = randint(1000);
+                       dummy = randint1(1000);
                        if (dummy == 666)
                                fire_ball_hide(GF_DEATH_RAY, dir, plev * 200, 0);
                        else if (dummy < 500)
@@ -1986,7 +1961,7 @@ static bool cast_death_spell(int spell)
                (void)sleep_monster(dir);
                break;
        case 5: /* Resist Poison */
-               (void)set_oppose_pois(randint(20) + 20, FALSE);
+               (void)set_oppose_pois(randint1(20) + 20, FALSE);
                break;
        case 6: /* Horrify */
                if (!get_aim_dir(&dir)) return FALSE;
@@ -2030,7 +2005,7 @@ static bool cast_death_spell(int spell)
        case 13: /* Vampiric Drain */
                if (!get_aim_dir(&dir)) return FALSE;
 
-               dummy = plev * 2 + randint(plev * 2);   /* Dmg */
+               dummy = plev * 2 + randint1(plev * 2);   /* Dmg */
                if (drain_life(dir, dummy))
                {
                        chg_virtue(V_SACRIFICE, -1);
@@ -2053,23 +2028,23 @@ static bool cast_death_spell(int spell)
                (void)symbol_genocide(plev+50, TRUE);
                break;
        case 16: /* Berserk */
-               (void)set_shero(randint(25) + 25, FALSE);
+               (void)set_shero(randint1(25) + 25, FALSE);
                (void)hp_player(30);
                (void)set_afraid(0);
                break;
        case 17: /* Invoke Spirits */
                {
-                       int die = randint(100) + plev / 5;
+                       int die = randint1(100) + plev / 5;
                        int vir = virtue_number(V_CHANCE);
                        if (vir)
                        {
                                if (p_ptr->virtues[vir - 1] > 0)
                                {
-                                       while (randint(400) < p_ptr->virtues[vir - 1]) die++;
+                                       while (randint1(400) < p_ptr->virtues[vir - 1]) die++;
                                }
                                else
                                {
-                                       while (randint(400) < (0-p_ptr->virtues[vir - 1])) die--;
+                                       while (randint1(400) < (0-p_ptr->virtues[vir - 1])) die--;
                                }
                        }
 
@@ -2099,7 +2074,7 @@ msg_print("
                                msg_print("Oh no! Mouldering forms rise from the earth around you!");
 #endif
 
-                               (void)summon_specific(0, py, px, dun_level, SUMMON_UNDEAD, TRUE, FALSE, FALSE, TRUE, TRUE);
+                               (void)summon_specific(0, py, px, dun_level, SUMMON_UNDEAD, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
                                chg_virtue(V_UNLIFE, 1);
                        }
                        else if (die < 14)
@@ -2110,7 +2085,7 @@ msg_print("̾
                                msg_print("An unnamable evil brushes against your mind...");
 #endif
 
-                               set_afraid(p_ptr->afraid + randint(4) + 4);
+                               set_afraid(p_ptr->afraid + randint1(4) + 4);
                        }
                        else if (die < 26)
                        {
@@ -2120,7 +2095,7 @@ msg_print("
                                msg_print("Your head is invaded by a horde of gibbering spectral voices...");
 #endif
 
-                               set_confused(p_ptr->confused + randint(4) + 4);
+                               set_confused(p_ptr->confused + randint1(4) + 4);
                        }
                        else if (die < 31)
                        {
@@ -2193,7 +2168,7 @@ msg_print("
                        }
                        else if (die < 106)
                        {
-                               destroy_area(py, px, 13+rand_int(5), TRUE);
+                               destroy_area(py, px, 13+randint0(5));
                        }
                        else if (die < 108)
                        {
@@ -2227,10 +2202,10 @@ msg_print("
                        damroll(4 + ((plev - 5) / 4), 8));
                break;
        case 19: /* Battle Frenzy */
-               (void)set_shero(randint(25) + 25, FALSE);
+               (void)set_shero(randint1(25) + 25, FALSE);
                (void)hp_player(30);
                (void)set_afraid(0);
-               (void)set_fast(randint(20 + (plev / 2)) + (plev / 2), FALSE);
+               (void)set_fast(randint1(20 + (plev / 2)) + (plev / 2), FALSE);
                break;
        case 20: /* Vampiric Branding */
                brand_weapon(4);
@@ -2248,7 +2223,7 @@ msg_print("
                }
                break;
        case 22: /* Word of Death */
-               (void)dispel_living(randint(plev * 3));
+               (void)dispel_living(randint1(plev * 3));
                break;
        case 23: /* Darkness Storm */
                if (!get_aim_dir(&dir)) return FALSE;
@@ -2262,21 +2237,19 @@ msg_print("
                break;
        case 25: /* Raise the Dead */
                {
-                       bool pet = (randint(3) == 1);
-                       bool group;
                        int type;
+                       bool pet = one_in_(3);
+                       u32b mode = 0L;
 
                        type = (plev > 47 ? SUMMON_HI_UNDEAD : SUMMON_UNDEAD);
-                       if (pet)
-                       {
-                               group = (((plev > 24) && (randint(3) == 1)) ? TRUE : FALSE);
-                       }
-                       else
-                       {
-                               group = TRUE;
-                       }
 
-                       if (summon_specific((pet ? -1 : 0), py, px, (plev * 3) / 2, type, group, FALSE, pet, (bool)(!pet), (bool)(!pet)))
+                       if (!pet || (pet && (plev > 24) && one_in_(3)))
+                               mode |= PM_ALLOW_GROUP;
+
+                       if (pet) mode |= PM_FORCE_PET;
+                       else mode |= (PM_ALLOW_UNIQUE | PM_NO_PET);
+
+                       if (summon_specific((pet ? -1 : 0), py, px, (plev * 3) / 2, type, mode))
                        {
 #ifdef JP
 msg_print("Î䤿¤¤É÷¤¬¤¢¤Ê¤¿¤Î¼þ¤ê¤Ë¿á¤­»Ï¤á¤¿¡£¤½¤ì¤ÏÉåÇÔ½­¤ò±¿¤ó¤Ç¤¤¤ë...");
@@ -2305,13 +2278,13 @@ msg_print("
                        break;
                }
        case 26: /* Esoteria */
-               if (randint(50) > plev)
+               if (randint1(50) > plev)
                        return ident_spell(FALSE);
                else
                        return identify_fully(FALSE);
                break;
        case 27: /* Mimic vampire */
-               (void)set_mimic(10+plev/2 + randint(10+plev/2), MIMIC_VAMPIRE, FALSE);
+               (void)set_mimic(10+plev/2 + randint1(10+plev/2), MIMIC_VAMPIRE, FALSE);
                break;
        case 28: /* Restore Life */
                (void)restore_level();
@@ -2324,14 +2297,14 @@ msg_print("
 
                fire_ball(GF_HELL_FIRE, dir, 666, 3);
 #ifdef JP
-take_hit(DAMAGE_USELIFE, 20 + randint(30), "ÃϹö¤Î¹å²Ð¤Î¼öʸ¤ò¾§¤¨¤¿ÈèÏ«", -1);
+take_hit(DAMAGE_USELIFE, 20 + randint1(30), "ÃϹö¤Î¹å²Ð¤Î¼öʸ¤ò¾§¤¨¤¿ÈèÏ«", -1);
 #else
-               take_hit(DAMAGE_USELIFE, 20 + randint(30), "the strain of casting Hellfire", -1);
+               take_hit(DAMAGE_USELIFE, 20 + randint1(30), "the strain of casting Hellfire", -1);
 #endif
 
                break;
        case 31: /* Wraithform */
-               set_wraith_form(randint(plev / 2) + (plev / 2), FALSE);
+               set_wraith_form(randint1(plev / 2) + (plev / 2), FALSE);
                break;
        default:
                msg_format("You cast an unknown Death spell: %d.", spell);
@@ -2347,7 +2320,7 @@ static bool cast_trump_spell(int spell, bool success)
        int     dir;
        int     beam;
        int     plev = p_ptr->lev;
-       int     summon_lev = plev * 2 / 3 + randint(plev/2);
+       int     summon_lev = plev * 2 / 3 + randint1(plev/2);
        int     dummy = 0;
        bool    no_trump = FALSE;
        bool    unique_okay = FALSE;
@@ -2358,7 +2331,7 @@ static bool cast_trump_spell(int spell, bool success)
        else beam = plev / 2;
 
        if (summon_lev < 1) summon_lev = 1;
-       if (!success || (randint(50+plev) < plev/10)) unique_okay = TRUE;
+       if (!success || (randint1(50+plev) < plev/10)) unique_okay = TRUE;
        switch (spell)
        {
                case 0: /* Phase Door */
@@ -2369,7 +2342,11 @@ static bool cast_trump_spell(int spell, bool success)
                        break;
                case 1: /* Trump Spiders */
                {
-                       bool pet = success; /* (randint(5) > 2) */
+                       bool pet = success; /* (randint1(5) > 2) */
+                       u32b mode = PM_ALLOW_GROUP;
+
+                       if (pet) mode |= PM_FORCE_PET;
+                       else mode |= PM_NO_PET;
 
 #ifdef JP
 msg_print("¤¢¤Ê¤¿¤ÏÃØéá¤Î¥«¡¼¥É¤Ë½¸Ã椹¤ë...");
@@ -2377,8 +2354,7 @@ msg_print("
                        msg_print("You concentrate on the trump of an spider...");
 #endif
 
-
-                       if (summon_specific((pet ? -1 : 0), py, px, summon_lev, SUMMON_SPIDER, TRUE, FALSE, pet, FALSE, (bool)(!pet)))
+                       if (summon_specific((pet ? -1 : 0), py, px, summon_lev, SUMMON_SPIDER, mode))
                        {
                                if (!pet)
 #ifdef JP
@@ -2386,7 +2362,6 @@ msg_print("
 #else
                                        msg_print("The summoned spiders get angry!");
 #endif
-
                        }
                        else
                        {
@@ -2399,24 +2374,24 @@ msg_print("
                        if (success)
                        {
                                /* A limited power 'wonder' spell */
-                               int die = randint(120);
+                               int die = randint1(120);
                                int vir = virtue_number(V_CHANCE);
 
                                if ((p_ptr->pclass == CLASS_ROGUE) ||
                                        (p_ptr->pclass == CLASS_HIGH_MAGE) ||
-                                       (p_ptr->pclass == CLASS_SORCERER))
-                                       die = (randint(110)) + plev / 5;
+                                       (p_ptr->pclass == CLASS_SORCERER))
+                                       die = (randint1(110)) + plev / 5;
                                /* Card sharks and high mages get a level bonus */
 
                                if (vir)
                                {
                                        if (p_ptr->virtues[vir - 1] > 0)
                                        {
-                                               while (randint(400) < p_ptr->virtues[vir - 1]) die++;
+                                               while (randint1(400) < p_ptr->virtues[vir - 1]) die++;
                                        }
                                        else
                                        {
-                                               while (randint(400) < (0-p_ptr->virtues[vir - 1])) die--;
+                                               while (randint1(400) < (0-p_ptr->virtues[vir - 1])) die--;
                                        }
                                }
 
@@ -2437,7 +2412,7 @@ msg_print("
                                        msg_print("Oh no! It's Death!");
 #endif
 
-                                       for (dummy = 0; dummy < randint(3); dummy++)
+                                       for (dummy = 0; dummy < randint1(3); dummy++)
                                                (void)activate_hi_summon(py, px, FALSE);
                                }
                                else if (die < 14)
@@ -2448,7 +2423,7 @@ msg_print("
                                        msg_print("Oh no! It's the Devil!");
 #endif
 
-                                       (void)summon_specific(0, py, px, dun_level, SUMMON_DEMON, TRUE, FALSE, FALSE, TRUE, TRUE);
+                                       (void)summon_specific(0, py, px, dun_level, SUMMON_DEMON, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET));
                                }
                                else if (die < 18)
                                {
@@ -2490,7 +2465,7 @@ msg_print("
                                        msg_print("It's the picture of a strange monster.");
 #endif
 
-                                       if (!(summon_specific(0, py, px, (dun_level * 3) / 2, 32 + randint(6), TRUE, FALSE, FALSE, TRUE, TRUE)))
+                                       if (!(summon_specific(0, py, px, (dun_level * 3) / 2, 32 + randint1(6), (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET))))
                                                no_trump = TRUE;
                                }
                                else if (die < 33)
@@ -2511,7 +2486,7 @@ msg_print("
                                        msg_print("It's the Wheel of Fortune.");
 #endif
 
-                                       wild_magic(rand_int(32));
+                                       wild_magic(randint0(32));
                                }
                                else if (die < 40)
                                {
@@ -2591,7 +2566,7 @@ msg_print("ͧ
                                        msg_print("It's the picture of a friendly monster.");
 #endif
 
-                                       if (!(summon_specific(-1, py, px, (dun_level * 3) / 2, SUMMON_BIZARRE1, FALSE, TRUE, TRUE, FALSE, FALSE)))
+                                       if (!(summon_specific(-1, py, px, (dun_level * 3) / 2, SUMMON_BIZARRE1, PM_FORCE_PET)))
                                                no_trump = TRUE;
                                }
                                else if (die < 84)
@@ -2602,7 +2577,7 @@ msg_print("ͧ
                                        msg_print("It's the picture of a friendly monster.");
 #endif
 
-                                       if (!(summon_specific(-1, py, px, (dun_level * 3) / 2, SUMMON_BIZARRE2, FALSE, TRUE, TRUE, FALSE, FALSE)))
+                                       if (!(summon_specific(-1, py, px, (dun_level * 3) / 2, SUMMON_BIZARRE2, PM_FORCE_PET)))
                                                no_trump = TRUE;
                                }
                                else if (die < 86)
@@ -2613,7 +2588,7 @@ msg_print("ͧ
                                        msg_print("It's the picture of a friendly monster.");
 #endif
 
-                                       if (!(summon_specific(-1, py, px, (dun_level * 3) / 2, SUMMON_BIZARRE4, FALSE, TRUE, TRUE, FALSE, FALSE)))
+                                       if (!(summon_specific(-1, py, px, (dun_level * 3) / 2, SUMMON_BIZARRE4, PM_FORCE_PET)))
                                                no_trump = TRUE;
                                }
                                else if (die < 88)
@@ -2624,7 +2599,7 @@ msg_print("ͧ
                                        msg_print("It's the picture of a friendly monster.");
 #endif
 
-                                       if (!(summon_specific(-1, py, px, (dun_level * 3) / 2, SUMMON_BIZARRE5, FALSE, TRUE, TRUE, FALSE, FALSE)))
+                                       if (!(summon_specific(-1, py, px, (dun_level * 3) / 2, SUMMON_BIZARRE5, PM_FORCE_PET)))
                                                no_trump = TRUE;
                                }
                                else if (die < 96)
@@ -2680,7 +2655,7 @@ msg_print("
 
                                        chg_virtue(V_KNOWLEDGE, 1);
                                        chg_virtue(V_ENLIGHTEN, 1);
-                                       wiz_lite(FALSE, FALSE);
+                                       wiz_lite(FALSE);
                                }
                                else
                                {
@@ -2720,7 +2695,7 @@ msg_print("
                case 5: /* Trump Spying */
                        if (success)
                        {
-                               (void)set_tim_esp(randint(30) + 25, FALSE);
+                               (void)set_tim_esp(randint1(30) + 25, FALSE);
                        }
                        break;
                case 6: /* Teleport Away */
@@ -2732,9 +2707,12 @@ msg_print("
                        break;
                case 7: /* Trump Animals */
                {
-                       bool pet = success; /* was (randint(5) > 2) */
+                       bool pet = success; /* was (randint1(5) > 2) */
                        int type = (pet ? SUMMON_ANIMAL_RANGER : SUMMON_ANIMAL);
-                       bool group = (pet ? FALSE : TRUE);
+                       u32b mode = 0L;
+
+                       if (pet) mode |= PM_FORCE_PET;
+                       else mode |= (PM_ALLOW_GROUP | PM_NO_PET);
 
 #ifdef JP
 msg_print("¤¢¤Ê¤¿¤Ïưʪ¤Î¥«¡¼¥É¤Ë½¸Ã椹¤ë...");
@@ -2743,7 +2721,7 @@ msg_print("
 #endif
 
 
-                       if (summon_specific((pet ? -1 : 0), py, px, summon_lev, type, group, FALSE, pet, FALSE, (bool)(!pet)))
+                       if (summon_specific((pet ? -1 : 0), py, px, summon_lev, type, mode))
                        {
                                if (!pet)
 #ifdef JP
@@ -2785,12 +2763,15 @@ msg_print("
 #endif
 
 
-                       for (dummy = 2 + rand_int(plev / 7); dummy > 0; dummy--)
+                       for (dummy = 2 + randint0(plev / 7); dummy > 0; dummy--)
                        {
-                               bool pet = success; /* was (randint(10) > 3) */
-                               bool group = (pet ? FALSE : TRUE);
+                               bool pet = success; /* was (randint1(10) > 3) */
+                               u32b mode = 0L;
                                int type;
 
+                               if (pet) mode |= PM_FORCE_PET;
+                               else mode |= (PM_ALLOW_GROUP | PM_NO_PET);
+
                                if (p_ptr->pclass == CLASS_BEASTMASTER)
                                {
                                        type = SUMMON_KAMIKAZE_LIVING;
@@ -2800,7 +2781,7 @@ msg_print("
                                        type = SUMMON_KAMIKAZE;
                                }
 
-                               if (summon_specific((pet ? -1 : 0), y, x, summon_lev, type, group, FALSE, pet, FALSE, (bool)(!pet)))
+                               if (summon_specific((pet ? -1 : 0), y, x, summon_lev, type, mode))
                                {
                                        if (!pet)
 #ifdef JP
@@ -2817,7 +2798,7 @@ msg_print("
                case 10: /* Phantasmal Servant */
                        if (success)
                        {
-                               if (summon_specific(-1, py, px, (summon_lev * 3) / 2, SUMMON_PHANTOM, FALSE, TRUE, TRUE, FALSE, FALSE))
+                               if (summon_specific(-1, py, px, (summon_lev * 3) / 2, SUMMON_PHANTOM, PM_FORCE_PET))
                                {
 #ifdef JP
 msg_print("¸æÍѤǤ´¤¶¤¤¤Þ¤¹¤«¡¢¸æ¼ç¿ÍÍÍ¡©");
@@ -2899,8 +2880,11 @@ msg_print("
                }
                case 17: /* Trump Undead */
                {
-                       bool pet = success; /* (randint(10) > 3) */
-                       bool group = (pet ? FALSE : TRUE);
+                       bool pet = success; /* (randint1(10) > 3) */
+                       u32b mode = 0L;
+
+                       if (pet) mode |= PM_FORCE_PET;
+                       else mode |= (PM_ALLOW_GROUP | PM_NO_PET);
 
 #ifdef JP
 msg_print("¤¢¤Ê¤¿¤Ï¥¢¥ó¥Ç¥Ã¥É¤Î¥«¡¼¥É¤Ë½¸Ã椹¤ë...");
@@ -2909,7 +2893,7 @@ msg_print("
 #endif
 
 
-                       if (summon_specific((pet ? -1 : 0), py, px, summon_lev, SUMMON_UNDEAD, group, FALSE, pet, FALSE, (bool)(!pet)))
+                       if (summon_specific((pet ? -1 : 0), py, px, summon_lev, SUMMON_UNDEAD, mode))
                        {
                                if (!pet)
 #ifdef JP
@@ -2928,8 +2912,11 @@ msg_print("
                }
                case 18: /* Trump Reptiles */
                {
-                       bool pet = success; /* was (randint(5) > 2) */
-                       bool group = !pet;
+                       bool pet = success; /* was (randint1(5) > 2) */
+                       u32b mode = 0L;
+
+                       if (pet) mode |= PM_FORCE_PET;
+                       else mode |= (PM_ALLOW_GROUP | PM_NO_PET);
 
 #ifdef JP
 msg_print("¤¢¤Ê¤¿¤Ïà¨ÃîÎà¤Î¥«¡¼¥É¤Ë½¸Ã椹¤ë...");
@@ -2938,7 +2925,7 @@ msg_print("
 #endif
 
 
-                       if (summon_specific((pet ? -1 : 0), py, px, summon_lev, SUMMON_HYDRA, group, FALSE, pet, FALSE, (bool)(!pet)))
+                       if (summon_specific((pet ? -1 : 0), py, px, summon_lev, SUMMON_HYDRA, mode))
                        {
                                if (!pet)
 #ifdef JP
@@ -2968,9 +2955,14 @@ msg_print("
 
                        for (dummy = 0; dummy < 1 + ((plev - 15)/ 10); dummy++)
                        {
-                               bool pet = success; /* was (randint(10) > 3) */
-                               bool group = (pet ? FALSE : TRUE);
+                               bool pet = success; /* was (randint1(10) > 3) */
                                int type;
+                               u32b mode = 0L;
+
+                               if (pet) mode |= PM_FORCE_PET;
+                               else mode |= (PM_ALLOW_GROUP | PM_NO_PET);
+
+                               if (unique_okay) mode |= PM_ALLOW_UNIQUE;
 
                                if (p_ptr->pclass == CLASS_BEASTMASTER)
                                {
@@ -2981,7 +2973,7 @@ msg_print("
                                        type = 0;
                                }
 
-                               if (summon_specific((pet ? -1 : 0), py, px, summon_lev, type, group, FALSE, pet, unique_okay, (bool)(!pet)))
+                               if (summon_specific((pet ? -1 : 0), py, px, summon_lev, type, mode))
                                {
                                        if (!pet)
 #ifdef JP
@@ -2997,7 +2989,11 @@ msg_print("
                }
                case 20: /* Trump Hounds */
                {
-                       bool pet = success; /* was (randint(5) > 2) */
+                       bool pet = success; /* was (randint1(5) > 2) */
+                       u32b mode = PM_ALLOW_GROUP;
+
+                       if (pet) mode |= PM_FORCE_PET;
+                       else mode |= PM_NO_PET;
 
 #ifdef JP
 msg_print("¤¢¤Ê¤¿¤Ï¥Ï¥¦¥ó¥É¤Î¥«¡¼¥É¤Ë½¸Ã椹¤ë...");
@@ -3006,7 +3002,7 @@ msg_print("
 #endif
 
 
-                       if (summon_specific((pet ? -1 : 0), py, px, summon_lev, SUMMON_HOUND, TRUE, FALSE, pet, FALSE, (bool)(!pet)))
+                       if (summon_specific((pet ? -1 : 0), py, px, summon_lev, SUMMON_HOUND, mode))
                        {
                                if (!pet)
 #ifdef JP
@@ -3032,7 +3028,7 @@ msg_print("
                case 22: /* Living Trump */
                        if (success)
                        {
-                               if (randint(7) == 1)
+                               if (one_in_(7))
                                        /* Teleport control */
                                        dummy = 12;
                                else
@@ -3050,7 +3046,11 @@ msg_print("
                        break;
                case 23: /* Trump Cyberdemon */
                {
-                       bool pet = success; /* was (randint(10) > 3) */
+                       bool pet = success; /* was (randint1(10) > 3) */
+                       u32b mode = 0L;
+
+                       if (pet) mode |= PM_FORCE_PET;
+                       else mode |= PM_NO_PET;
 
 #ifdef JP
 msg_print("¤¢¤Ê¤¿¤Ï¥µ¥¤¥Ð¡¼¥Ç¡¼¥â¥ó¤Î¥«¡¼¥É¤Ë½¸Ã椹¤ë...");
@@ -3059,7 +3059,7 @@ msg_print("
 #endif
 
 
-                       if (summon_specific((pet ? -1 : 0), py, px, summon_lev, SUMMON_CYBER, FALSE, FALSE, pet, FALSE, (bool)(!pet)))
+                       if (summon_specific((pet ? -1 : 0), py, px, summon_lev, SUMMON_CYBER, mode))
                        {
                                if (!pet)
 #ifdef JP
@@ -3105,8 +3105,11 @@ msg_print("
                        break;
                case 27: /* Trump Dragon */
                {
-                       bool pet = success; /* was (randint(10) > 3) */
-                       bool group = (pet ? FALSE : TRUE);
+                       bool pet = success; /* was (randint1(10) > 3) */
+                       u32b mode = 0L;
+
+                       if (pet) mode |= PM_FORCE_PET;
+                       else mode |= (PM_ALLOW_GROUP | PM_NO_PET);
 
 #ifdef JP
 msg_print("¤¢¤Ê¤¿¤Ï¥É¥é¥´¥ó¤Î¥«¡¼¥É¤Ë½¸Ã椹¤ë...");
@@ -3115,7 +3118,7 @@ msg_print("
 #endif
 
 
-                       if (summon_specific((pet ? -1 : 0), py, px, summon_lev, SUMMON_DRAGON, group, FALSE, pet, FALSE, (bool)(!pet)))
+                       if (summon_specific((pet ? -1 : 0), py, px, summon_lev, SUMMON_DRAGON, mode))
                        {
                                if (!pet)
 #ifdef JP
@@ -3136,7 +3139,7 @@ msg_print("
                        if (success)
                        {
                                int x, y, dx, dy, i;
-                               int b = 10 + randint(10);
+                               int b = 10 + randint1(10);
                                for (i = 0; i < b; i++)
                                {
                                        int count = 0, d = 0;
@@ -3145,8 +3148,8 @@ msg_print("
                                        {
                                                count++;
                                                if (count > 20) break;
-                                               x = px - 8 + rand_int(17);
-                                               y = py - 8 + rand_int(17);
+                                               x = px - 8 + randint0(17);
+                                               y = py - 8 + randint0(17);
 
                                                if (!in_bounds(y,x) || (!cave_floor_bold(y,x) && (cave[y][x].feat != FEAT_TREES)) || !player_has_los_bold(y, x)) continue;
 
@@ -3166,8 +3169,11 @@ msg_print("
                        break;
                case 29: /* Trump Demon */
                {
-                       bool pet = success; /* was (randint(10) > 3) */
-                       bool group = (pet ? FALSE : TRUE);
+                       bool pet = success; /* was (randint1(10) > 3) */
+                       u32b mode = 0L;
+
+                       if (pet) mode |= PM_FORCE_PET;
+                       else mode |= (PM_ALLOW_GROUP | PM_NO_PET);
 
 #ifdef JP
 msg_print("¤¢¤Ê¤¿¤Ï¥Ç¡¼¥â¥ó¤Î¥«¡¼¥É¤Ë½¸Ã椹¤ë...");
@@ -3176,7 +3182,7 @@ msg_print("
 #endif
 
 
-                       if (summon_specific((pet ? -1 : 0), py, px, summon_lev, SUMMON_DEMON, group, FALSE, pet, FALSE, (bool)(!pet)))
+                       if (summon_specific((pet ? -1 : 0), py, px, summon_lev, SUMMON_DEMON, mode))
                        {
                                if (!pet)
 #ifdef JP
@@ -3195,8 +3201,13 @@ msg_print("
                }
                case 30: /* Trump Greater Undead */
                {
-                       bool pet = success; /* was (randint(10) > 3) */
-                       bool group = (pet ? FALSE : TRUE);
+                       bool pet = success; /* was (randint1(10) > 3) */
+                       u32b mode = 0L;
+
+                       if (pet) mode |= PM_FORCE_PET;
+                       else mode |= (PM_ALLOW_GROUP | PM_NO_PET);
+
+                       if (unique_okay) mode |= PM_ALLOW_UNIQUE;
 
 #ifdef JP
 msg_print("¤¢¤Ê¤¿¤Ï¶¯ÎϤʥ¢¥ó¥Ç¥Ã¥É¤Î¥«¡¼¥É¤Ë½¸Ã椹¤ë...");
@@ -3205,7 +3216,7 @@ msg_print("
 #endif
 
 
-                       if (summon_specific((pet ? -1 : 0), py, px, summon_lev, SUMMON_HI_UNDEAD, group, FALSE, pet, unique_okay, (bool)(!pet)))
+                       if (summon_specific((pet ? -1 : 0), py, px, summon_lev, SUMMON_HI_UNDEAD, mode))
                        {
                                if (!pet)
 #ifdef JP
@@ -3224,9 +3235,15 @@ msg_print("
                }
                case 31: /* Trump Ancient Dragon */
                {
-                       bool pet = success; /* was (randint(10) > 3) */
-                       bool group = (pet ? FALSE : TRUE);
+                       bool pet = success; /* was (randint1(10) > 3) */
                        int type;
+                       u32b mode = 0L;
+
+                       if (pet) mode |= PM_FORCE_PET;
+                       else mode |= (PM_ALLOW_GROUP | PM_NO_PET);
+
+                       if (unique_okay) mode |= PM_ALLOW_UNIQUE;
+
                        if (p_ptr->pclass == CLASS_BEASTMASTER)
                        {
                                type = SUMMON_HI_DRAGON_LIVING;
@@ -3243,7 +3260,7 @@ msg_print("
 #endif
 
 
-                       if (summon_specific((pet ? -1 : 0), py, px, summon_lev, type, group, FALSE, pet, unique_okay, (bool)(!pet)))
+                       if (summon_specific((pet ? -1 : 0), py, px, summon_lev, type, mode))
                        {
                                if (!pet)
 #ifdef JP
@@ -3331,7 +3348,7 @@ static bool cast_arcane_spell(int spell)
                (void)set_cut(p_ptr->cut - 10);
                break;
        case 8: /* Detect Doors & Traps */
-               (void)detect_traps(DETECT_RAD_DEFAULT);
+               (void)detect_traps(DETECT_RAD_DEFAULT, TRUE);
                (void)detect_doors(DETECT_RAD_DEFAULT);
                (void)detect_stairs(DETECT_RAD_DEFAULT);
                break;
@@ -3352,16 +3369,16 @@ static bool cast_arcane_spell(int spell)
                (void)set_poisoned(0);
                break;
        case 14: /* Resist Cold */
-               (void)set_oppose_cold(randint(20) + 20, FALSE);
+               (void)set_oppose_cold(randint1(20) + 20, FALSE);
                break;
        case 15: /* Resist Fire */
-               (void)set_oppose_fire(randint(20) + 20, FALSE);
+               (void)set_oppose_fire(randint1(20) + 20, FALSE);
                break;
        case 16: /* Resist Lightning */
-               (void)set_oppose_elec(randint(20) + 20, FALSE);
+               (void)set_oppose_elec(randint1(20) + 20, FALSE);
                break;
        case 17: /* Resist Acid */
-               (void)set_oppose_acid(randint(20) + 20, FALSE);
+               (void)set_oppose_acid(randint1(20) + 20, FALSE);
                break;
        case 18: /* Cure Medium Wounds */
                (void)hp_player(damroll(4, 8));
@@ -3392,10 +3409,10 @@ msg_print("
                (void)set_food(PY_FOOD_MAX - 1);
                break;
        case 24: /* See Invisible */
-               (void)set_tim_invis(randint(24) + 24, FALSE);
+               (void)set_tim_invis(randint1(24) + 24, FALSE);
                break;
        case 25: /* Conjure Elemental */
-               if (!summon_specific(-1, py, px, plev, SUMMON_ELEMENTAL, TRUE, TRUE, TRUE, FALSE, FALSE))
+               if (!summon_specific(-1, py, px, plev, SUMMON_ELEMENTAL, (PM_ALLOW_GROUP | PM_FORCE_PET)))
                        no_trump = TRUE;
                break;
        case 26: /* Teleport Level */
@@ -3414,7 +3431,7 @@ msg_print("
        case 28: /* Elemental Ball */
                if (!get_aim_dir(&dir)) return FALSE;
 
-               switch (randint(4))
+               switch (randint1(4))
                {
                        case 1:  dummy = GF_FIRE;break;
                        case 2:  dummy = GF_ELEC;break;
@@ -3432,10 +3449,10 @@ msg_print("
        case 31: /* Clairvoyance */
                chg_virtue(V_KNOWLEDGE, 1);
                chg_virtue(V_ENLIGHTEN, 1);
-               wiz_lite(FALSE, FALSE);
+               wiz_lite(FALSE);
                if (!p_ptr->telepathy)
                {
-                       (void)set_tim_esp(randint(30) + 25, FALSE);
+                       (void)set_tim_esp(randint1(30) + 25, FALSE);
                }
                break;
        default:
@@ -3463,33 +3480,33 @@ static bool cast_enchant_spell(int spell)
        switch (spell)
        {
        case 0: /* Infravision */
-               set_tim_infra(100 + randint(100), FALSE);
+               set_tim_infra(100 + randint1(100), FALSE);
                break;
        case 1: /* Regeneration */
-               set_tim_regen(80 + randint(80), FALSE);
+               set_tim_regen(80 + randint1(80), FALSE);
                break;
        case 2: /* Satisfy Hunger */
                (void)set_food(PY_FOOD_MAX - 1);
                break;
        case 3: /* Resist Cold */
-               (void)set_oppose_cold(randint(20) + 20, FALSE);
+               (void)set_oppose_cold(randint1(20) + 20, FALSE);
                break;
        case 4: /* Resist Fire */
-               (void)set_oppose_fire(randint(20) + 20, FALSE);
+               (void)set_oppose_fire(randint1(20) + 20, FALSE);
                break;
        case 5: /* Heroism */
-               (void)set_hero(randint(25) + 25, FALSE);
+               (void)set_hero(randint1(25) + 25, FALSE);
                (void)hp_player(10);
                (void)set_afraid(0);
                break;
        case 6: /* Resist Lightning */
-               (void)set_oppose_elec(randint(20) + 20, FALSE);
+               (void)set_oppose_elec(randint1(20) + 20, FALSE);
                break;
        case 7: /* Resist Acid */
-               (void)set_oppose_acid(randint(20) + 20, FALSE);
+               (void)set_oppose_acid(randint1(20) + 20, FALSE);
                break;
        case 8: /* See Invisibility */
-               (void)set_tim_invis(randint(24) + 24, FALSE);
+               (void)set_tim_invis(randint1(24) + 24, FALSE);
                break;
        case 9: /* Remove Curse */
                if (remove_curse())
@@ -3502,10 +3519,10 @@ static bool cast_enchant_spell(int spell)
                }
                break;
        case 10: /* Resist Poison */
-               (void)set_oppose_pois(randint(20) + 20, FALSE);
+               (void)set_oppose_pois(randint1(20) + 20, FALSE);
                break;
        case 11: /* Berserk */
-               (void)set_shero(randint(25) + 25, FALSE);
+               (void)set_shero(randint1(25) + 25, FALSE);
                (void)hp_player(30);
                (void)set_afraid(0);
                break;
@@ -3513,7 +3530,7 @@ static bool cast_enchant_spell(int spell)
                (void)self_knowledge();
                break;
        case 13: /* Protection from Evil */
-               (void)set_protevil(randint(25) + 3 * p_ptr->lev, FALSE);
+               (void)set_protevil(randint1(25) + 3 * p_ptr->lev, FALSE);
                break;
        case 14: /* Healing */
                set_poisoned(0);
@@ -3525,29 +3542,29 @@ static bool cast_enchant_spell(int spell)
                return choose_ele_attack();
                break;
        case 16: /* Telepathy */
-               (void)set_tim_esp(randint(30) + 25, FALSE);
+               (void)set_tim_esp(randint1(30) + 25, FALSE);
                break;
        case 17: /* Stone Skin */
-               (void)set_shield(randint(20) + 30, FALSE);
+               (void)set_shield(randint1(20) + 30, FALSE);
                break;
        case 18: /* Resistance */
-               (void)set_oppose_acid(randint(20) + 20, FALSE);
-               (void)set_oppose_elec(randint(20) + 20, FALSE);
-               (void)set_oppose_fire(randint(20) + 20, FALSE);
-               (void)set_oppose_cold(randint(20) + 20, FALSE);
-               (void)set_oppose_pois(randint(20) + 20, FALSE);
+               (void)set_oppose_acid(randint1(20) + 20, FALSE);
+               (void)set_oppose_elec(randint1(20) + 20, FALSE);
+               (void)set_oppose_fire(randint1(20) + 20, FALSE);
+               (void)set_oppose_cold(randint1(20) + 20, FALSE);
+               (void)set_oppose_pois(randint1(20) + 20, FALSE);
                break;
        case 19: /* Haste */
-               (void)set_fast(randint(20 + plev) + plev, FALSE);
+               (void)set_fast(randint1(20 + plev) + plev, FALSE);
                break;
        case 20: /* Walk through Wall */
-               (void)set_kabenuke(randint(plev/2) + plev/2, FALSE);
+               (void)set_kabenuke(randint1(plev/2) + plev/2, FALSE);
                break;
        case 21: /* Pulish Shield */
                (void)pulish_shield();
                break;
        case 22: /* Create Golem */
-               if (summon_specific(-1, py, px, plev, SUMMON_GOLEM, FALSE, TRUE, TRUE, FALSE, FALSE))
+               if (summon_specific(-1, py, px, plev, SUMMON_GOLEM, PM_FORCE_PET))
                {
 #ifdef JP
 msg_print("¥´¡¼¥ì¥à¤òºî¤Ã¤¿¡£");
@@ -3561,7 +3578,7 @@ msg_print("
                }
                break;
        case 23: /* Magic armor */
-               (void)set_magicdef(randint(20) + 20, FALSE);
+               (void)set_magicdef(randint1(20) + 20, FALSE);
                break;
        case 24: /* Remove Enchantment */
                if (!mundane_spell(TRUE)) return FALSE;
@@ -3580,16 +3597,16 @@ msg_print("
                return identify_fully(FALSE);
                break;
        case 27: /* Enchant Weapon */
-               return enchant_spell(rand_int(4) + 1, rand_int(4) + 1, 0);
+               return enchant_spell(randint0(4) + 1, randint0(4) + 1, 0);
                break;
        case 28: /* Enchant Armor */
-               return enchant_spell(0, 0, rand_int(3) + 2);
+               return enchant_spell(0, 0, randint0(3) + 2);
                break;
        case 29: /* Brand Weapon */
-               brand_weapon(rand_int(17));
+               brand_weapon(randint0(18));
                break;
        case 30: /* Living Trump */
-               if (randint(7) == 1)
+               if (one_in_(7))
                        /* Teleport control */
                        dummy = 12;
                else
@@ -3604,7 +3621,7 @@ msg_print("
 #endif
                break;
        case 31: /* Immune */
-               return (choose_ele_immune(13 + randint(13)));
+               return (choose_ele_immune(13 + randint1(13)));
                break;
        default:
                msg_format("You cast an unknown Craft spell: %d.", spell);
@@ -3660,10 +3677,10 @@ static bool cast_daemon_spell(int spell)
                (void)detect_monsters_nonliving(DETECT_RAD_DEFAULT);
                break;
        case 2: /* Bless */
-               (void)set_blessed(randint(12) + 12, FALSE);
+               (void)set_blessed(randint1(12) + 12, FALSE);
                break;
        case 3: /* Resist Fire */
-               (void)set_oppose_fire(randint(20) + 20, FALSE);
+               (void)set_oppose_fire(randint1(20) + 20, FALSE);
                break;
        case 4: /* Horrify */
                if (!get_aim_dir(&dir)) return FALSE;
@@ -3678,7 +3695,7 @@ static bool cast_daemon_spell(int spell)
                    damroll(6 + ((plev - 5) / 4), 8));
                break;
        case 6: /* Summon monster, demon */
-               if (!summon_specific(-1, py, px, (plev * 3) / 2, SUMMON_MANES, TRUE, FALSE, TRUE, FALSE, FALSE))
+               if (!summon_specific(-1, py, px, (plev * 3) / 2, SUMMON_MANES, (PM_ALLOW_GROUP | PM_FORCE_PET)))
                {
 #ifdef JP
 msg_print("¸ÅÂå¤Î»àÎî¤Ï¸½¤ì¤Ê¤«¤Ã¤¿¡£");
@@ -3706,7 +3723,7 @@ msg_print("
                map_area(DETECT_RAD_MAP);
                break;
        case 10: /* Resist Nether */
-               (void)set_tim_res_nether(randint(20) + 20, FALSE);
+               (void)set_tim_res_nether(randint1(20) + 20, FALSE);
                break;
        case 11: /* Plasma Bolt */
                if (!get_aim_dir(&dir)) return FALSE;
@@ -3729,10 +3746,14 @@ msg_print("
                break;
        case 15: /* Summon monster, demon */
        {
-               bool pet = (randint(3) != 1);
-               bool group = !(pet && (plev < 50));
+               bool pet = !one_in_(3);
+               u32b mode = 0L;
+
+               if (pet) mode |= PM_FORCE_PET;
+               else mode |= PM_NO_PET;
+               if (!(pet && (plev < 50))) mode |= PM_ALLOW_GROUP;
 
-               if (summon_specific((pet ? -1 : 0), py, px, plev*2/3+randint(plev/2), SUMMON_DEMON, group, FALSE, pet, FALSE, (bool)(!pet)))
+               if (summon_specific((pet ? -1 : 0), py, px, plev*2/3+randint1(plev/2), SUMMON_DEMON, mode))
                {
 #ifdef JP
 msg_print("ⲫ¤Î°­½­¤¬½¼Ëþ¤·¤¿¡£");
@@ -3767,11 +3788,11 @@ msg_print("
                break;
        }
        case 16: /* Telepathy */
-               (void)set_tim_esp(randint(30) + 25, FALSE);
+               (void)set_tim_esp(randint1(30) + 25, FALSE);
                break;
        case 17: /* Demoncloak */
        {
-               int dur=randint(20) + 20;
+               int dur=randint1(20) + 20;
                        
                set_oppose_fire(dur, FALSE);
                set_oppose_cold(dur, FALSE);
@@ -3781,7 +3802,7 @@ msg_print("
        }
        case 18: /* Rain of Lava */
                fire_ball(GF_FIRE, 0, (55 + plev)*2, 3);
-               fire_ball_hide(GF_LAVA_FLOW, 0, 2+randint(2), 3);
+               fire_ball_hide(GF_LAVA_FLOW, 0, 2+randint1(2), 3);
                break;
        case 19: /* Plasma ball */
                if (!get_aim_dir(&dir)) return FALSE;
@@ -3789,11 +3810,11 @@ msg_print("
                fire_ball(GF_PLASMA, dir, plev*3/2 + 80, 2 + plev/40);
                break;
        case 20: /* Mimic demon */
-               (void)set_mimic(10+plev/2 + randint(10+plev/2), MIMIC_DEMON, FALSE);
+               (void)set_mimic(10+plev/2 + randint1(10+plev/2), MIMIC_DEMON, FALSE);
                break;
        case 21: /* Nether Wave == Dispel Good */
-               (void)dispel_monsters(randint(plev * 2));
-               (void)dispel_good(randint(plev * 2));
+               (void)dispel_monsters(randint1(plev * 2));
+               (void)dispel_good(randint1(plev * 2));
                break;
        case 22: /*  */
                if (!get_aim_dir(&dir)) return FALSE;
@@ -3804,18 +3825,18 @@ msg_print("
 #ifdef JP
 else msg_print("<ÇËÌǤμê>¤òÊü¤Ã¤¿¡ª");
 #else
-               else msg_print("You invokes the Hand of Doom!");
+               else msg_print("You invoke the Hand of Doom!");
 #endif
 
                fire_ball_hide(GF_HAND_DOOM, dir, plev * 2, 0);
                break;
        case 24: /* Heroism */
-               (void)set_hero(randint(25) + 25, FALSE);
+               (void)set_hero(randint1(25) + 25, FALSE);
                (void)hp_player(10);
                (void)set_afraid(0);
                break;
        case 25: /* Tim resist time */
-               (void)set_tim_res_time(randint(20)+20, FALSE);
+               (void)set_tim_res_time(randint1(20)+20, FALSE);
                break;
        case 26: /* Circle of Madness */
                fire_ball(GF_CHAOS, 0, 50+plev, 3+plev/20);
@@ -3823,7 +3844,7 @@ else msg_print("<
                fire_ball(GF_CHARM, 0, 20+plev, 3+plev/20);
                break;
        case 27: /* True Discharge Minion */
-               discharge_minion(TRUE);
+               discharge_minion();
                break;
        case 28: /* Summon Greater Demon */
        {
@@ -3855,7 +3876,7 @@ else msg_print("<
                }
 
                summon_lev = p_ptr->lev * 2 / 3 + r_info[o_ptr->pval].level;
-               if (summon_specific(-1, py, px, summon_lev, SUMMON_HI_DEMON, TRUE, FALSE, TRUE, FALSE, FALSE))
+               if (summon_specific(-1, py, px, summon_lev, SUMMON_HI_DEMON, (PM_ALLOW_GROUP | PM_FORCE_PET)))
                {
 #ifdef JP
 msg_print("ⲫ¤Î°­½­¤¬½¼Ëþ¤·¤¿¡£");
@@ -3907,14 +3928,14 @@ msg_print("
 
                fire_ball_hide(GF_BLOOD_CURSE, dir, 600, 0);
 #ifdef JP
-take_hit(DAMAGE_USELIFE, 20 + randint(30), "·ì¤Î¼ö¤¤", -1);
+take_hit(DAMAGE_USELIFE, 20 + randint1(30), "·ì¤Î¼ö¤¤", -1);
 #else
-               take_hit(DAMAGE_USELIFE, 20 + randint(30), "Blood curse", -1);
+               take_hit(DAMAGE_USELIFE, 20 + randint1(30), "Blood curse", -1);
 #endif
                break;
        }
        case 31: /* Mimic Demon lord */
-               (void)set_mimic(15 + randint(15), MIMIC_DEMON_LORD, FALSE);
+               (void)set_mimic(15 + randint1(15), MIMIC_DEMON_LORD, FALSE);
                break;
        default:
                msg_format("You cast an unknown Daemon spell: %d.", spell);
@@ -3925,6 +3946,316 @@ take_hit(DAMAGE_USELIFE, 20 + randint(30), "
 }
 
 
+static bool cast_crusade_spell(int spell)
+{
+       int     dir;
+       int     beam;
+       int     plev = p_ptr->lev;
+
+       if (p_ptr->pclass == CLASS_MAGE) beam = plev;
+       else if (p_ptr->pclass == CLASS_HIGH_MAGE || p_ptr->pclass == CLASS_SORCERER) beam = plev + 10;
+       else beam = plev / 2;
+
+       switch (spell)
+       {
+       case 0:
+               if (!get_aim_dir(&dir)) return FALSE;
+
+               fire_bolt_or_beam(beam - 10, GF_ELEC, dir,
+                       damroll(3 + ((plev - 1) / 5), 4));
+               break;
+       case 1:
+               (void)detect_monsters_evil(DETECT_RAD_DEFAULT);
+               break;
+       case 2: /* Remove Fear */
+               (void)set_afraid(0);
+               break;
+       case 3:
+               if (!get_aim_dir(&dir)) return FALSE;
+
+               (void)fear_monster(dir, plev);
+               break;
+       case 4:
+               (void)sleep_monsters_touch();
+               break;
+       case 5:
+               teleport_player(25+plev/2);
+               break;
+       case 6:
+               if (!get_aim_dir(&dir)) return FALSE;
+               fire_blast(GF_LITE, dir, 3+((plev-1)/9), 2, 10, 3);
+               break;
+       case 7:
+               (void)set_cut(0);
+               (void)set_poisoned(0);
+               (void)set_stun(0);
+               break;
+       case 8:
+               if (!get_aim_dir(&dir)) return FALSE;
+               (void)fire_ball(GF_AWAY_EVIL, dir, MAX_SIGHT*5, 0);
+               break;
+       case 9: /* Holy Orb */
+               if (!get_aim_dir(&dir)) return FALSE;
+
+               fire_ball(GF_HOLY_FIRE, dir,
+                         (damroll(3, 6) + plev +
+                         (plev / ((p_ptr->pclass == CLASS_PRIEST ||
+                            p_ptr->pclass == CLASS_HIGH_MAGE ||
+                            p_ptr->pclass == CLASS_SORCERER) ? 2 : 4))),
+                         ((plev < 30) ? 2 : 3));
+
+               break;
+       case 10: /* Exorcism */
+               (void)dispel_undead(randint1(plev));
+               (void)dispel_demons(randint1(plev));
+               (void)turn_evil(plev);
+               break;
+       case 11: /* Remove Curse */
+               if (remove_curse())
+               {
+#ifdef JP
+                       msg_print("狼¤Ë¸«¼é¤é¤ì¤Æ¤¤¤ë¤è¤¦¤Êµ¤¤¬¤¹¤ë¡£");
+#else
+                       msg_print("You feel as if someone is watching over you.");
+#endif
+               }
+               break;
+       case 12: /* Sense Unseen */
+               (void)set_tim_invis(randint1(24) + 24, FALSE);
+               break;
+       case 13: /* Protection from Evil */
+               (void)set_protevil(randint1(25) + 3 * p_ptr->lev, FALSE);
+               break;
+       case 14:
+               if (!get_aim_dir(&dir)) return FALSE;
+               (void)fire_bolt(GF_ELEC, dir, plev*5);
+               break;
+       case 15: /* Holy Word */
+               (void)dispel_evil(randint1(plev * 6));
+               (void)hp_player(100);
+               (void)set_afraid(0);
+               (void)set_poisoned(0);
+               (void)set_stun(0);
+               (void)set_cut(0);
+               break;
+       case 16:
+               if (!get_aim_dir(&dir)) return FALSE;
+
+               (void)destroy_door(dir);
+               break;
+       case 17:
+               if (!get_aim_dir(&dir)) return FALSE;
+               (void)stasis_evil(dir);
+               break;
+       case 18:
+               set_tim_sh_holy(randint1(20)+20, FALSE);
+               break;
+       case 19: /* Dispel Undead + Demons */
+               (void)dispel_undead(randint1(plev * 4));
+               (void)dispel_demons(randint1(plev * 4));
+               break;
+       case 20: /* Dispel Evil */
+               (void)dispel_evil(randint1(plev * 4));
+               break;
+       case 21:
+               brand_weapon(13);
+               break;
+       case 22: /* Star Burst */
+               if (!get_aim_dir(&dir)) return FALSE;
+
+               fire_ball(GF_LITE, dir, 100+plev*2, 4);
+               break;
+       case 23: /* Summon monster, angel */
+               {
+                       bool pet = !one_in_(3);
+                       u32b mode = 0L;
+
+                       if (pet) mode |= PM_FORCE_PET;
+                       else mode |= PM_NO_PET;
+                       if (!(pet && (plev < 50))) mode |= PM_ALLOW_GROUP;
+
+                       if (summon_specific((pet ? -1 : 0), py, px, (plev * 3) / 2, SUMMON_ANGEL, mode))
+                       {
+                               if (pet)
+#ifdef JP
+msg_print("¡Ö¤´ÍѤǤ´¤¶¤¤¤Þ¤¹¤«¡¢¤´¼ç¿ÍÍÍ¡×");
+#else
+                                       msg_print("'What is thy bidding... Master?'");
+#endif
+
+                               else
+#ifdef JP
+msg_print("¡Ö²æ¤ÏÆò¤Î²¼Ëͤˤ¢¤é¤º¡ª °­¹Ô¼Ô¤è¡¢²ù¤¤²þ¤á¤è¡ª¡×");
+#else
+                                       msg_print("Mortal! Repent of thy impiousness.");
+#endif
+
+                       }
+                       break;
+               }
+       case 24: /* Heroism */
+               (void)set_hero(randint1(25) + 25, FALSE);
+               (void)hp_player(10);
+               (void)set_afraid(0);
+               break;
+       case 25: /* Remove All Curse */
+               if (remove_all_curse())
+               {
+#ifdef JP
+                       msg_print("狼¤Ë¸«¼é¤é¤ì¤Æ¤¤¤ë¤è¤¦¤Êµ¤¤¬¤¹¤ë¡£");
+#else
+                       msg_print("You feel as if someone is watching over you.");
+#endif
+               }
+               break;
+       case 26: /* Banishment */
+               if (banish_evil(100))
+               {
+#ifdef JP
+msg_print("¿ÀÀ»¤ÊÎϤ¬¼Ù°­¤òÂǤÁʧ¤Ã¤¿¡ª");
+#else
+                       msg_print("The holy power banishes evil!");
+#endif
+
+               }
+               break;
+       case 27: /* Word of Destruction */
+               destroy_area(py, px, 13+randint0(5));
+               break;
+       case 28: /* Eye for an Eye */
+               set_tim_eyeeye(randint1(10)+10, FALSE);
+               break;
+       case 29:
+               {
+                       int x, y, tx, ty;
+                       int nx, ny;
+                       int dir, i;
+                       int b = 10 + randint1(10);
+
+                       if (!get_aim_dir(&dir)) return FALSE;
+
+                       /* Use the given direction */
+                       tx = px + 99 * ddx[dir];
+                       ty = py + 99 * ddy[dir];
+
+                       /* Hack -- Use an actual "target" */
+                       if ((dir == 5) && target_okay())
+                       {
+                               tx = target_col;
+                               ty = target_row;
+                       }
+
+                       x = px;
+                       y = py;
+
+                       while(1)
+                       {
+                               /* Hack -- Stop at the target */
+                               if ((y == ty) && (x == tx)) break;
+
+                               ny = y;
+                               nx = x;
+                               mmove2(&ny, &nx, py, px, ty, tx);
+
+                               /* Stop at maximum range */
+                               if (MAX_SIGHT*2 < distance(py, px, ny, nx)) break;
+
+                               /* Stopped by walls/doors */
+                               if (!cave_floor_bold(ny, nx)) break;
+
+                               /* Stopped by monsters */
+                               if ((dir != 5) && cave[ny][nx].m_idx != 0) break;
+
+                               /* Save the new location */
+                               x = nx;
+                               y = ny;
+                       }
+                       tx = x;
+                       ty = y;
+
+                       for (i = 0; i < b; i++)
+                       {
+                               int count = 20, d = 0;
+
+                               while (count--)
+                               {
+                                       int dx, dy;
+
+                                       x = tx - 5 + randint0(11);
+                                       y = ty - 5 + randint0(11);
+
+                                       dx = (tx > x) ? (tx - x) : (x - tx);
+                                       dy = (ty > y) ? (ty - y) : (y - ty);
+
+                                       /* Approximate distance */
+                                       d = (dy > dx) ? (dy + (dx >> 1)) : (dx + (dy >> 1));
+                                       /* Within the radius */
+                                       if (d < 5) break;
+                               }
+
+                               if (count < 0) continue;
+
+                               /* Cannot penetrate perm walls */
+                               if (!in_bounds(y,x) ||
+                                   cave_stop_disintegration(y,x) ||
+                                   !in_disintegration_range(ty, tx, y, x))
+                                       continue;
+
+                               project(0, 2, y, x, plev * 3+25, GF_DISINTEGRATE, PROJECT_JUMP | PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL, -1);
+                       }
+               }
+               break;
+       case 30: /* Divine Intervention */
+               project(0, 1, py, px, plev*11, GF_HOLY_FIRE, PROJECT_KILL, -1);
+               dispel_monsters(plev * 4);
+               slow_monsters();
+               stun_monsters(plev * 4);
+               confuse_monsters(plev * 4);
+               turn_monsters(plev * 4);
+               stasis_monsters(plev * 4);
+               (void)hp_player(100);
+               break;
+       case 31:
+       {
+               int i;
+               (void)crusade();
+               for (i = 0; i < 12; i++)
+               {
+                       int attempt = 10;
+                       int my, mx;
+
+                       while (attempt--)
+                       {
+                               scatter(&my, &mx, py, px, 4, 0);
+
+                               /* Require empty grids */
+                               if (cave_empty_bold2(my, mx)) break;
+                       }
+                       if (attempt < 0) continue;
+                       summon_specific(-1, my, mx, plev, SUMMON_KNIGHTS, (PM_ALLOW_GROUP | PM_FORCE_PET | PM_HASTE));
+               }
+               (void)set_hero(randint1(25) + 25, FALSE);
+               (void)set_blessed(randint1(25) + 25, FALSE);
+               (void)set_fast(randint1(20 + plev) + plev, FALSE);
+               (void)set_protevil(randint1(25) + 25, FALSE);
+               (void)set_afraid(0);
+               break;
+       }
+       default:
+#ifdef JP
+msg_format("¤¢¤Ê¤¿¤ÏÉÔÌÀ¤ÊÇ˼٤μöʸ %d ¤ò¾§¤¨¤¿¡£", spell);
+#else
+               msg_format("You cast an unknown crusade spell: %d.", spell);
+#endif
+
+               msg_print(NULL);
+       }
+
+       return TRUE;
+}
+
+
+
 void stop_singing(void)
 {
        if (p_ptr->pclass != CLASS_BARD) return;
@@ -3938,18 +4269,18 @@ void stop_singing(void)
 
        set_action(ACTION_NONE);
 
-        switch(p_ptr->magic_num1[0])
-        {
-                case MUSIC_BLESS:
-                        if (!p_ptr->blessed)
+       switch(p_ptr->magic_num1[0])
+       {
+               case MUSIC_BLESS:
+                       if (!p_ptr->blessed)
 #ifdef JP
 msg_print("¹â·é¤Êµ¤Ê¬¤¬¾Ã¤¨¼º¤»¤¿¡£");
 #else
                                msg_print("The prayer has expired.");
 #endif
-                        break;
-                case MUSIC_HERO:
-                        if (!p_ptr->hero)
+                       break;
+               case MUSIC_HERO:
+                       if (!p_ptr->hero)
                        {
 #ifdef JP
 msg_print("¥Ò¡¼¥í¡¼¤Îµ¤Ê¬¤¬¾Ã¤¨¼º¤»¤¿¡£");
@@ -3959,9 +4290,9 @@ msg_print("
                                /* Recalculate hitpoints */
                                p_ptr->update |= (PU_HP);
                        }
-                        break;
-                case MUSIC_MIND:
-                        if (!p_ptr->tim_esp)
+                       break;
+               case MUSIC_MIND:
+                       if (!p_ptr->tim_esp)
                        {
 #ifdef JP
 msg_print("°Õ¼±¤Ï¸µ¤ËÌá¤Ã¤¿¡£");
@@ -3971,57 +4302,57 @@ msg_print("
                                /* Update the monsters */
                                p_ptr->update |= (PU_MONSTERS);
                        }
-                        break;
-                case MUSIC_STEALTH:
-                        if (!p_ptr->tim_stealth)
+                       break;
+               case MUSIC_STEALTH:
+                       if (!p_ptr->tim_stealth)
 #ifdef JP
 msg_print("»Ñ¤¬¤Ï¤Ã¤­¤ê¤È¸«¤¨¤ë¤è¤¦¤Ë¤Ê¤Ã¤¿¡£");
 #else
                                msg_print("You are no longer hided.");
 #endif
-                        break;
-                case MUSIC_RESIST:
-                        if (!p_ptr->oppose_acid)
+                       break;
+               case MUSIC_RESIST:
+                       if (!p_ptr->oppose_acid)
 #ifdef JP
 msg_print("»À¤Ø¤ÎÂÑÀ­¤¬Çö¤ì¤¿µ¤¤¬¤¹¤ë¡£");
 #else
                                msg_print("You feel less resistant to acid.");
 #endif
-                        if (!p_ptr->oppose_elec)
+                       if (!p_ptr->oppose_elec)
 #ifdef JP
 msg_print("ÅÅ·â¤Ø¤ÎÂÑÀ­¤¬Çö¤ì¤¿µ¤¤¬¤¹¤ë¡£");
 #else
                                msg_print("You feel less resistant to elec.");
 #endif
-                        if (!p_ptr->oppose_fire)
+                       if (!p_ptr->oppose_fire)
 #ifdef JP
 msg_print("²Ð¤Ø¤ÎÂÑÀ­¤¬Çö¤ì¤¿µ¤¤¬¤¹¤ë¡£");
 #else
                                msg_print("You feel less resistant to fire.");
 #endif
-                        if (!p_ptr->oppose_cold)
+                       if (!p_ptr->oppose_cold)
 #ifdef JP
 msg_print("Î䵤¤Ø¤ÎÂÑÀ­¤¬Çö¤ì¤¿µ¤¤¬¤¹¤ë¡£");
 #else
                                msg_print("You feel less resistant to cold.");
 #endif
-                        if (!p_ptr->oppose_pois)
+                       if (!p_ptr->oppose_pois)
 #ifdef JP
 msg_print("ÆǤؤÎÂÑÀ­¤¬Çö¤ì¤¿µ¤¤¬¤¹¤ë¡£");
 #else
                                msg_print("You feel less resistant to pois.");
 #endif
-                        break;
-                case MUSIC_SPEED:
-                        if (!p_ptr->fast)
+                       break;
+               case MUSIC_SPEED:
+                       if (!p_ptr->fast)
 #ifdef JP
 msg_print("Æ°¤­¤ÎÁÇÁᤵ¤¬¤Ê¤¯¤Ê¤Ã¤¿¤è¤¦¤À¡£");
 #else
                                msg_print("You feel yourself slow down.");
 #endif
-                        break;
-                case MUSIC_SHERO:
-                        if (!p_ptr->hero)
+                       break;
+               case MUSIC_SHERO:
+                       if (!p_ptr->hero)
                        {
 #ifdef JP
 msg_print("¥Ò¡¼¥í¡¼¤Îµ¤Ê¬¤¬¾Ã¤¨¼º¤»¤¿¡£");
@@ -4032,15 +4363,15 @@ msg_print("
                                p_ptr->update |= (PU_HP);
                        }
 
-                        if (!p_ptr->fast)
+                       if (!p_ptr->fast)
 #ifdef JP
 msg_print("Æ°¤­¤ÎÁÇÁᤵ¤¬¤Ê¤¯¤Ê¤Ã¤¿¤è¤¦¤À¡£");
 #else
                                msg_print("You feel yourself slow down.");
 #endif
-                        break;
-                case MUSIC_INVULN:
-                        if (!p_ptr->invuln)
+                       break;
+               case MUSIC_INVULN:
+                       if (!p_ptr->invuln)
                        {
 #ifdef JP
 msg_print("̵Ũ¤Ç¤Ï¤Ê¤¯¤Ê¤Ã¤¿¡£");
@@ -4056,8 +4387,8 @@ msg_print("̵Ũ
                                /* Window stuff */
                                p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
                        }
-                        break;
-        }
+                       break;
+       }
        p_ptr->magic_num1[0] = MUSIC_NONE;
        p_ptr->magic_num2[0] = 0;
 
@@ -4074,12 +4405,12 @@ static bool cast_music_spell(int spell)
        int     plev = p_ptr->lev;
        int dir;
 
-        if(p_ptr->magic_num1[0])
-        {
-                stop_singing();
-        }
+       if(p_ptr->magic_num1[0])
+       {
+               stop_singing();
+       }
 
-        p_ptr->magic_num2[0] = spell;
+       p_ptr->magic_num2[0] = spell;
 
        switch (spell)
        {
@@ -4374,9 +4705,6 @@ static bool cast_music_spell(int spell)
  */
 void do_cmd_cast(void)
 {
-#ifdef USE_SCRIPT
-       use_skill_callback();
-#else /* USE_SCRIPT */
        int     item, sval, spell, realm;
        int     chance;
        int     increment = 0;
@@ -4449,15 +4777,12 @@ s = "
        s = "You have no spell books!";
 #endif
 
-        select_spellbook=TRUE;
        if (p_ptr->pclass == CLASS_FORCETRAINER)
                select_the_force = TRUE;
        if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))){
-            select_spellbook = FALSE;
            select_the_force = FALSE;
-            return;
-        }
-        select_spellbook = FALSE;
+           return;
+       }
        select_the_force = FALSE;
 
        if (item == 1111) { /* the_force */
@@ -4476,10 +4801,6 @@ s = "
                o_ptr = &o_list[0 - item];
        }
 
-#ifdef USE_SCRIPT
-       if (object_cast_callback(o_ptr)) return;
-#endif /* USE_SCRIPT */
-
        /* Access the item's sval */
        sval = o_ptr->sval;
 
@@ -4499,13 +4820,13 @@ s = "
 
        /* Ask for a spell */
 #ifdef JP
-        if (!get_spell(&spell,  
-                               ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "±Ó¾§¤¹¤ë" : (mp_ptr->spell_book == TV_MUSIC_BOOK) ? "²Î¤¦" : "¾§¤¨¤ë"), 
+       if (!get_spell(&spell,  
+                               ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "±Ó¾§¤¹¤ë" : (mp_ptr->spell_book == TV_MUSIC_BOOK) ? "²Î¤¦" : "¾§¤¨¤ë"), 
                       sval, TRUE, realm))
-        {
-                if (spell == -2) msg_format("¤½¤ÎËܤˤÏÃΤäƤ¤¤ë%s¤¬¤Ê¤¤¡£", prayer);
-                return;
-        }
+       {
+               if (spell == -2) msg_format("¤½¤ÎËܤˤÏÃΤäƤ¤¤ë%s¤¬¤Ê¤¤¡£", prayer);
+               return;
+       }
 #else
        if (!get_spell(&spell, ((mp_ptr->spell_book == TV_LIFE_BOOK) ? "recite" : "cast"),
                sval, TRUE, realm))
@@ -4521,19 +4842,15 @@ s = "
 
        if (!is_magic(use_realm))
        {
-               s_ptr = &technic_info[use_realm - MIN_TECHNIC - 1][spell];
+               s_ptr = &technic_info[use_realm - MIN_TECHNIC][spell];
        }
        else
        {
                s_ptr = &mp_ptr->info[realm - 1][spell];
        }
 
-       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
-               shouhimana = (s_ptr->smana*(3800-spell_exp[(increment ? spell+32 : spell)])+2399);
+       /* 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;
@@ -4543,6 +4860,8 @@ s = "
        /* Verify "dangerous" spells */
        if (shouhimana > p_ptr->csp)
        {
+               if (flush_failure) flush();
+
                /* Warning */
 #ifdef JP
 msg_format("¤½¤Î%s¤ò%s¤Î¤Ë½½Ê¬¤Ê¥Þ¥¸¥Ã¥¯¥Ý¥¤¥ó¥È¤¬¤Ê¤¤¡£",prayer,
@@ -4558,19 +4877,19 @@ msg_format("
 
                /* Verify */
 #ifdef JP
-if (!get_check("¤½¤ì¤Ç¤âÄ©À路¤Þ¤¹¤«? ")) return;
+               if (!get_check_strict("¤½¤ì¤Ç¤âÄ©À路¤Þ¤¹¤«? ", CHECK_OKAY_CANCEL)) return;
 #else
-               if (!get_check("Attempt it anyway? ")) return;
+               if (!get_check_strict("Attempt it anyway? ", CHECK_OKAY_CANCEL)) return;
 #endif
 
        }
 
 
        /* Spell failure chance */
-       chance = spell_chance(spell, use_realm - 1);
+       chance = spell_chance(spell, use_realm);
 
        /* Failed spell */
-       if (rand_int(100) < chance)
+       if (randint0(100) < chance)
        {
                if (flush_failure) flush();
 
@@ -4584,25 +4903,30 @@ msg_format("%s
 
                if (realm == REALM_LIFE)
                {
-                       if (randint(100) < chance)
-                               chg_virtue(V_FAITH, -1);
+                       if (randint1(100) < chance)
+                               chg_virtue(V_VITALITY, -1);
                }
                else if (realm == REALM_DEATH)
                {
-                       if (randint(100) < chance)
+                       if (randint1(100) < chance)
                                chg_virtue(V_UNLIFE, -1);
                }
                else if (realm == REALM_NATURE)
                {
-                       if (randint(100) < chance)
+                       if (randint1(100) < chance)
                                chg_virtue(V_NATURE, -1);
                }
                else if (realm == REALM_DAEMON)
                {
-                       if (randint(100) < chance)
+                       if (randint1(100) < chance)
                                chg_virtue(V_JUSTICE, 1);
                }
-               else if (randint(100) < chance)
+               if (realm == REALM_CRUSADE)
+               {
+                       if (randint1(100) < chance)
+                               chg_virtue(V_JUSTICE, -1);
+               }
+               else if (randint1(100) < chance)
                {
                        chg_virtue(V_KNOWLEDGE, -1);
                }
@@ -4611,7 +4935,7 @@ msg_format("%s
                {
                        cast_trump_spell(spell, FALSE);
                }
-               else if ((o_ptr->tval == TV_CHAOS_BOOK) && (randint(100) < spell))
+               else if ((o_ptr->tval == TV_CHAOS_BOOK) && (randint1(100) < spell))
                {
 #ifdef JP
 msg_print("¥«¥ª¥¹Åª¤Ê¸ú²Ì¤òȯÀ¸¤·¤¿¡ª");
@@ -4621,9 +4945,9 @@ msg_print("
 
                        wild_magic(spell);
                }
-               else if ((o_ptr->tval == TV_DEATH_BOOK) && (randint(100) < spell))
+               else if ((o_ptr->tval == TV_DEATH_BOOK) && (randint1(100) < spell))
                {
-                       if ((sval == 3) && (randint(2) == 1))
+                       if ((sval == 3) && one_in_(2))
                        {
                                sanity_blast(0, TRUE);
                        }
@@ -4641,11 +4965,11 @@ msg_print("
                                take_hit(DAMAGE_LOSELIFE, damroll(o_ptr->sval + 1, 6), "a miscast Death spell", -1);
 #endif
 
-                               if ((spell > 15) && (randint(6) == 1) && !p_ptr->hold_life)
+                               if ((spell > 15) && one_in_(6) && !p_ptr->hold_life)
                                        lose_exp(spell * 250);
                        }
                }
-               else if ((o_ptr->tval == TV_MUSIC_BOOK) && (randint(200) < spell))
+               else if ((o_ptr->tval == TV_MUSIC_BOOK) && (randint1(200) < spell))
                {
 #ifdef JP
 msg_print("¤¤¤ä¤Ê²»¤¬¶Á¤¤¤¿");
@@ -4655,7 +4979,7 @@ msg_print("An infernal sound echoed.");
 
                        aggravate_monsters(0);
                }
-               if (randint(100) >= chance)
+               if (randint1(100) >= chance)
                        chg_virtue(V_CHANCE,-1);
        }
 
@@ -4692,6 +5016,9 @@ msg_print("An infernal sound echoed.");
                case REALM_DAEMON: /* DAEMON */
                        cast = cast_daemon_spell(spell);
                        break;
+               case REALM_CRUSADE: /* CRUSADE */
+                       cast = cast_crusade_spell(spell);
+                       break;
                case REALM_MUSIC: /* MUSIC */
                        cast = cast_music_spell(spell);
                        break;
@@ -4704,13 +5031,13 @@ msg_print("An infernal sound echoed.");
                /* Canceled spells cost neither a turn nor mana */
                if (!cast) return;
 
-               if (randint(100) < chance)
+               if (randint1(100) < chance)
                        chg_virtue(V_CHANCE,1);
 
                /* A spell was cast */
                if (!(increment ?
-                   (spell_worked2 & (1L << spell)) :
-                   (spell_worked1 & (1L << spell)))
+                   (p_ptr->spell_worked2 & (1L << spell)) :
+                   (p_ptr->spell_worked1 & (1L << spell)))
                    && (p_ptr->pclass != CLASS_SORCERER)
                    && (p_ptr->pclass != CLASS_RED_MAGE))
                {
@@ -4719,22 +5046,25 @@ msg_print("An infernal sound echoed.");
                        /* The spell worked */
                        if (realm == p_ptr->realm1)
                        {
-                               spell_worked1 |= (1L << spell);
+                               p_ptr->spell_worked1 |= (1L << spell);
                        }
                        else
                        {
-                               spell_worked2 |= (1L << spell);
+                               p_ptr->spell_worked2 |= (1L << spell);
                        }
 
                        /* Gain experience */
                        gain_exp(e * s_ptr->slevel);
 
+                       /* Redraw object recall */
+                       p_ptr->window |= (PW_OBJECT);
+
                        if (realm == REALM_LIFE)
                        {
-                               chg_virtue(V_FAITH, 1);
+                               chg_virtue(V_TEMPERANCE, 1);
                                chg_virtue(V_COMPASSION, 1);
                                chg_virtue(V_VITALITY, 1);
-                               chg_virtue(V_HONOUR, 1);
+                               chg_virtue(V_DILIGENCE, 1);
                        }
                        else if (realm == REALM_DEATH)
                        {
@@ -4750,6 +5080,13 @@ msg_print("An infernal sound echoed.");
                                chg_virtue(V_HONOUR, -1);
                                chg_virtue(V_TEMPERANCE, -1);
                        }
+                       else if (realm == REALM_CRUSADE)
+                       {
+                               chg_virtue(V_FAITH, 1);
+                               chg_virtue(V_JUSTICE, 1);
+                               chg_virtue(V_SACRIFICE, 1);
+                               chg_virtue(V_HONOUR, 1);
+                       }
                        else if (realm == REALM_NATURE)
                        {
                                chg_virtue(V_NATURE, 1);
@@ -4760,40 +5097,60 @@ msg_print("An infernal sound echoed.");
                }
                if (realm == REALM_LIFE)
                {
-                       if (randint(100 + p_ptr->lev) < shouhimana) chg_virtue(V_FAITH, 1);
-                       if (randint(100 + p_ptr->lev) < shouhimana) chg_virtue(V_COMPASSION, 1);
-                       if (randint(100 + p_ptr->lev) < shouhimana) chg_virtue(V_VITALITY, 1);
-                       if (randint(100 + p_ptr->lev) < shouhimana) chg_virtue(V_HONOUR, 1);
+                       if (randint1(100 + p_ptr->lev) < shouhimana) chg_virtue(V_TEMPERANCE, 1);
+                       if (randint1(100 + p_ptr->lev) < shouhimana) chg_virtue(V_COMPASSION, 1);
+                       if (randint1(100 + p_ptr->lev) < shouhimana) chg_virtue(V_VITALITY, 1);
+                       if (randint1(100 + p_ptr->lev) < shouhimana) chg_virtue(V_DILIGENCE, 1);
                }
                else if (realm == REALM_DEATH)
                {
-                       if (randint(100 + p_ptr->lev) < shouhimana) chg_virtue(V_UNLIFE, 1);
-                       if (randint(100 + p_ptr->lev) < shouhimana) chg_virtue(V_JUSTICE, -1);
-                       if (randint(100 + p_ptr->lev) < shouhimana) chg_virtue(V_FAITH, -1);
-                       if (randint(100 + p_ptr->lev) < shouhimana) chg_virtue(V_VITALITY, -1);
+                       if (randint1(100 + p_ptr->lev) < shouhimana) chg_virtue(V_UNLIFE, 1);
+                       if (randint1(100 + p_ptr->lev) < shouhimana) chg_virtue(V_JUSTICE, -1);
+                       if (randint1(100 + p_ptr->lev) < shouhimana) chg_virtue(V_FAITH, -1);
+                       if (randint1(100 + p_ptr->lev) < shouhimana) chg_virtue(V_VITALITY, -1);
                }
                else if (realm == REALM_DAEMON)
                {
-                       if (randint(100 + p_ptr->lev) < shouhimana) chg_virtue(V_JUSTICE, -1);
-                       if (randint(100 + p_ptr->lev) < shouhimana) chg_virtue(V_FAITH, -1);
-                       if (randint(100 + p_ptr->lev) < shouhimana) chg_virtue(V_HONOUR, -1);
-                       if (randint(100 + p_ptr->lev) < shouhimana) chg_virtue(V_TEMPERANCE, -1);
+                       if (randint1(100 + p_ptr->lev) < shouhimana) chg_virtue(V_JUSTICE, -1);
+                       if (randint1(100 + p_ptr->lev) < shouhimana) chg_virtue(V_FAITH, -1);
+                       if (randint1(100 + p_ptr->lev) < shouhimana) chg_virtue(V_HONOUR, -1);
+                       if (randint1(100 + p_ptr->lev) < shouhimana) chg_virtue(V_TEMPERANCE, -1);
+               }
+               else if (realm == REALM_CRUSADE)
+               {
+                       if (randint1(100 + p_ptr->lev) < shouhimana) chg_virtue(V_FAITH, 1);
+                       if (randint1(100 + p_ptr->lev) < shouhimana) chg_virtue(V_JUSTICE, 1);
+                       if (randint1(100 + p_ptr->lev) < shouhimana) chg_virtue(V_SACRIFICE, 1);
+                       if (randint1(100 + p_ptr->lev) < shouhimana) chg_virtue(V_HONOUR, 1);
                }
                else if (realm == REALM_NATURE)
                {
-                       if (randint(100 + p_ptr->lev) < shouhimana) chg_virtue(V_NATURE, 1);
-                       if (randint(100 + p_ptr->lev) < shouhimana) chg_virtue(V_HARMONY, 1);
+                       if (randint1(100 + p_ptr->lev) < shouhimana) chg_virtue(V_NATURE, 1);
+                       if (randint1(100 + p_ptr->lev) < shouhimana) chg_virtue(V_HARMONY, 1);
                }
                if (mp_ptr->spell_xtra & MAGIC_GAIN_EXP)
                {
-                       if (spell_exp[(increment ? 32 : 0)+spell] < 900)
-                               spell_exp[(increment ? 32 : 0)+spell]+=60;
-                       else if(spell_exp[(increment ? 32 : 0)+spell] < 1200)
-                               {if ((dun_level > 4) && ((dun_level + 10) > p_ptr->lev)) spell_exp[(increment ? 32 : 0)+spell]+=8;}
-                       else if(spell_exp[(increment ? 32 : 0)+spell] < 1400)
-                               {if (((dun_level + 5) > p_ptr->lev) && ((dun_level + 5) > s_ptr->slevel)) spell_exp[(increment ? 32 : 0)+spell]+=2;}
-                       else if((spell_exp[(increment ? 32 : 0)+spell] < 1600) && !increment)
-                               {if (((dun_level + 5) > p_ptr->lev) && (dun_level > s_ptr->slevel)) spell_exp[(increment ? 32 : 0)+spell]+=1;}
+                       s16b cur_exp = p_ptr->spell_exp[(increment ? 32 : 0)+spell];
+                       s16b exp_gain = 0;
+
+                       if (cur_exp < 900)
+                               exp_gain+=60;
+                       else if(cur_exp < 1200)
+                       {
+                               if ((dun_level > 4) && ((dun_level + 10) > p_ptr->lev))
+                                       exp_gain = 8;
+                       }
+                       else if(cur_exp < 1400)
+                       {
+                               if (((dun_level + 5) > p_ptr->lev) && ((dun_level + 5) > s_ptr->slevel))
+                                       exp_gain = 2;
+                       }
+                       else if((cur_exp < 1600) && !increment)
+                       {
+                               if (((dun_level + 5) > p_ptr->lev) && (dun_level > s_ptr->slevel))
+                                       exp_gain = 1;
+                       }
+                       p_ptr->spell_exp[(increment ? 32 : 0)+spell] += exp_gain;
                }
        }
 
@@ -4825,23 +5182,25 @@ msg_print("
 
 
                /* Hack -- Bypass free action */
-               (void)set_paralyzed(p_ptr->paralyzed + randint(5 * oops + 1));
+               (void)set_paralyzed(p_ptr->paralyzed + randint1(5 * oops + 1));
 
                if (realm == REALM_LIFE)
-                       chg_virtue(V_FAITH, -10);
+                       chg_virtue(V_VITALITY, -10);
                else if (realm == REALM_DEATH)
                        chg_virtue(V_UNLIFE, -10);
                else if (realm == REALM_DAEMON)
                        chg_virtue(V_JUSTICE, 10);
                else if (realm == REALM_NATURE)
                        chg_virtue(V_NATURE, -10);
+               else if (realm == REALM_CRUSADE)
+                       chg_virtue(V_JUSTICE, -10);
                else
                        chg_virtue(V_KNOWLEDGE, -10);
 
                /* Damage CON (possibly permanently) */
-               if (rand_int(100) < 50)
+               if (randint0(100) < 50)
                {
-                       bool perm = (rand_int(100) < 25);
+                       bool perm = (randint0(100) < 25);
 
                        /* Message */
 #ifdef JP
@@ -4852,7 +5211,7 @@ msg_print("
 
 
                        /* Reduce constitution */
-                       (void)dec_stat(A_CON, 15 + randint(10), perm);
+                       (void)dec_stat(A_CON, 15 + randint1(10), perm);
                }
        }
 
@@ -4862,7 +5221,6 @@ msg_print("
        /* Window stuff */
        p_ptr->window |= (PW_PLAYER);
        p_ptr->window |= (PW_SPELL);
-#endif /* USE_SCRIPT */
 }
 
 
@@ -4886,6 +5244,9 @@ static bool ang_sort_comp_pet_dismiss(vptr u, vptr v, int a, int b)
        monster_race *r_ptr1 = &r_info[m_ptr1->r_idx];
        monster_race *r_ptr2 = &r_info[m_ptr2->r_idx];
 
+       /* Unused */
+       (void)v;
+
        if (w1 == p_ptr->riding) return TRUE;
        if (w2 == p_ptr->riding) return FALSE;
 
@@ -5004,102 +5365,111 @@ void do_cmd_pet_dismiss(void)
        /* Process the monsters (backwards) */
        for (i = 0; i < max_pet; i++)
        {
+               bool delete_this;
+               char friend_name[80];
+               char buf[80];
+               bool kakunin;
+
                /* Access the monster */
                pet_ctr = who[i];
                m_ptr = &m_list[pet_ctr];
 
+               delete_this = FALSE;
+               kakunin = ((pet_ctr == p_ptr->riding) || (m_ptr->nickname));
+               monster_desc(friend_name, m_ptr, 0x80);
+               
+               if (!all_pets)
                {
-                       bool delete_this = FALSE;
-                       char friend_name[80];
-                       bool kakunin = ((pet_ctr == p_ptr->riding) || (m_ptr->nickname));
-                       monster_desc(friend_name, m_ptr, 0x80);
-
-                       if (all_pets && !kakunin)
-                               delete_this = TRUE;
-                       else
-                       {
-                               char ch;
-                               char check_friend[80];
-                               if (all_pets)
-                               {
-#ifdef JP
-sprintf(check_friend, "%s¤òÊü¤·¤Þ¤¹¤«¡© [Yes/No]", friend_name);
-#else
- sprintf(check_friend, "Dismiss %s? [Yes/No]", friend_name);
-#endif
-                               }
-                               else
-                               {
+                       /* Hack -- health bar for this monster */
+                       health_track(pet_ctr);
+                       
+                       /* Hack -- handle stuff */
+                       handle_stuff();
+                       
 #ifdef JP
-sprintf(check_friend, "%s¤òÊü¤·¤Þ¤¹¤«¡© [Yes/No/All(%dɤ)]", friend_name, max_pet-i);
+                       sprintf(buf, "%s¤òÊü¤·¤Þ¤¹¤«¡© [Yes/No/Unnamed (%dɤ)]", friend_name, max_pet-i);
 #else
sprintf(check_friend, "Dismiss %s? [Yes/No/All(%d remain)]", friend_name, max_pet-i);
                      sprintf(buf, "Dismiss %s? [Yes/No/Unnamed (%d remain)]", friend_name, max_pet-i);
 #endif
-                               }
-                               /* Hack -- health bar for this monster */
-                               health_track(pet_ctr);
-
-                               /* Hack -- handle stuff */
-                               handle_stuff();
-
-                               prt(check_friend, 0, 0);
-
-                               if (m_ptr->ml)
-                                       move_cursor_relative(m_ptr->fy, m_ptr->fx);
-                               while (TRUE)
-                               {
-                                       ch = inkey();
-                                       if (ch == ESCAPE) break;
-                                       if (strchr("YyNnAa", ch)) break;
-                                       bell();
-                               }
-
-                               if (ch == 'A' || ch == 'a') all_pets = TRUE;
+                       prt(buf, 0, 0);
+                       
+                       if (m_ptr->ml)
+                               move_cursor_relative(m_ptr->fy, m_ptr->fx);
+                       
+                       while (TRUE)
+                       {
+                               char ch = inkey();
 
-                               if (ch == 'Y' || ch == 'y' || ch == 'A' || ch == 'a')
+                               if (ch == 'Y' || ch == 'y')
                                {
+                                       delete_this = TRUE;
+                                       
                                        if (kakunin)
                                        {
 #ifdef JP
-                                               sprintf(check_friend, "ËÜÅö¤Ë¤è¤í¤·¤¤¤Ç¤¹¤«¡© (%s) ", friend_name);
+                                               sprintf(buf, "ËÜÅö¤Ë¤è¤í¤·¤¤¤Ç¤¹¤«¡© (%s) ", friend_name);
 #else
-                                               sprintf(check_friend, "Really? (%s) ", friend_name);
+                                               sprintf(buf, "Are you sure? (%s) ", friend_name);
 #endif
-                                               if (!get_check(check_friend)) continue;
-                                       }
-                                       if (record_named_pet && m_ptr->nickname)
-                                       {
-                                               char m_name[80];
-
-                                               monster_desc(m_name, m_ptr, 0x08);
-                                               do_cmd_write_nikki(NIKKI_NAMED_PET, 2, m_name);
+                                               if (!get_check(buf))
+                                                       delete_this = FALSE;
                                        }
-                                       delete_this = TRUE;
+                                       break;
                                }
+                               
+                               if (ch == 'U' || ch == 'u')
+                               {
+                                       all_pets = TRUE;
+                                       break;
+                               }
+                               
+                               if (ch == ESCAPE || ch == 'N' || ch == 'n')
+                                       break;
+                               
+                               bell();
                        }
-
-                       if (delete_this)
+               }
+               
+               if ((all_pets && !kakunin) || (!all_pets && delete_this))
+               {
+                       if (record_named_pet && m_ptr->nickname)
+                       {
+                               char m_name[80];
+                               
+                               monster_desc(m_name, m_ptr, 0x08);
+                               do_cmd_write_nikki(NIKKI_NAMED_PET, 2, m_name);
+                       }
+                       
+                       if (pet_ctr == p_ptr->riding)
                        {
-                               if (pet_ctr == p_ptr->riding)
-                               {
 #ifdef JP
-msg_format("%s¤«¤é¹ß¤ê¤¿¡£", friend_name);
+                               msg_format("%s¤«¤é¹ß¤ê¤¿¡£", friend_name);
 #else
-                                       msg_format("You have got off %s. ", friend_name);
+                               msg_format("You have got off %s. ", friend_name);
 #endif
+                               
+                               p_ptr->riding = 0;
+                               
+                               /* Update the monsters */
+                               p_ptr->update |= (PU_BONUS | PU_MONSTERS);
+                               p_ptr->redraw |= (PR_EXTRA);
+                       }
 
-                                       p_ptr->riding = 0;
+                       /* HACK : Add the line to message buffer */
+#ifdef JP
+                       sprintf(buf, "%s ¤òÊü¤·¤¿¡£", friend_name);
+#else
+                       sprintf(buf, "Dismissed %s.", friend_name);
+#endif
+                       message_add(buf);
+                       p_ptr->window |= (PW_MESSAGE);
+                       window_stuff();
 
-                                       /* Update the monsters */
-                                       p_ptr->update |= (PU_BONUS | PU_MONSTERS);
-                                       p_ptr->redraw |= (PR_EXTRA);
-                               }
-                               delete_monster_idx(pet_ctr);
-                               Dismissed++;
-                       }
+                       delete_monster_idx(pet_ctr);
+                       Dismissed++;
                }
        }
-
+       
        Term->scr->cu = cu;
        Term->scr->cv = cv;
        Term_fresh();
@@ -5107,10 +5477,16 @@ msg_format("%s
        C_KILL(who, max_m_idx, u16b);
 
 #ifdef JP
-msg_format("%d É¤¤Î¥Ú¥Ã¥È¤òÊü¤·¤Þ¤·¤¿¡£", Dismissed);
+       msg_format("%d É¤¤Î¥Ú¥Ã¥È¤òÊü¤·¤Þ¤·¤¿¡£", Dismissed);
 #else
        msg_format("You have dismissed %d pet%s.", Dismissed,
-               (Dismissed == 1 ? "" : "s"));
+                  (Dismissed == 1 ? "" : "s"));
+#endif
+       if (Dismissed == 0 && all_pets)
+#ifdef JP
+               msg_print("'U'nnamed ¤Ï¡¢¾èÇϰʳ°¤Î̾Á°¤Î¤Ê¤¤¥Ú¥Ã¥È¤À¤±¤òÁ´¤Æ²òÊü¤·¤Þ¤¹¡£");
+#else
+               msg_print("'U'nnamed means all your pets except named pets and your mount.");
 #endif
 
        p_ptr->update |= (PU_MON_LITE);
@@ -5133,16 +5509,16 @@ bool rakuba(int dam, bool force)
                {
                        int level = r_ptr->level;
                        if (p_ptr->riding_ryoute) level += 20;
-                       if ((dam/2 + r_ptr->level) > (skill_exp[GINOU_RIDING]/30+10))
+                       if ((dam/2 + r_ptr->level) > (p_ptr->skill_exp[GINOU_RIDING]/30+10))
                        {
-                               if((skill_exp[GINOU_RIDING] < skill_exp_settei[p_ptr->pclass][GINOU_RIDING][1]) && skill_exp_settei[p_ptr->pclass][GINOU_RIDING][1] > 1000)
+                               if((p_ptr->skill_exp[GINOU_RIDING] < s_info[p_ptr->pclass].s_max[GINOU_RIDING]) && s_info[p_ptr->pclass].s_max[GINOU_RIDING] > 1000)
                                {
-                                       if (r_ptr->level*100 > (skill_exp[GINOU_RIDING] + 1500))
-                                               skill_exp[GINOU_RIDING] += (1+(r_ptr->level - skill_exp[GINOU_RIDING]/100 - 15));
-                                       else skill_exp[GINOU_RIDING]++;
+                                       if (r_ptr->level*100 > (p_ptr->skill_exp[GINOU_RIDING] + 1500))
+                                               p_ptr->skill_exp[GINOU_RIDING] += (1+(r_ptr->level - p_ptr->skill_exp[GINOU_RIDING]/100 - 15));
+                                       else p_ptr->skill_exp[GINOU_RIDING]++;
                                }
                        }
-                       if (rand_int(dam/2 + level*2) < (skill_exp[GINOU_RIDING]/30+10))
+                       if (randint0(dam/2 + level*2) < (p_ptr->skill_exp[GINOU_RIDING]/30+10))
                        {
                                if ((((p_ptr->pclass == CLASS_BEASTMASTER) || (p_ptr->pclass == CLASS_CAVALRY)) && !p_ptr->riding_ryoute) || !one_in_(p_ptr->lev*(p_ptr->riding_ryoute ? 2 : 3)+30))
                                {
@@ -5171,7 +5547,7 @@ bool rakuba(int dam, bool force)
                        sn++;
 
                        /* Randomize choice */
-                       if (rand_int(sn) > 0) continue;
+                       if (randint0(sn) > 0) continue;
 
                        /* Save the safe location */
                        sy = y; sx = x;
@@ -5224,6 +5600,9 @@ msg_format("%s
 
        p_ptr->redraw |= (PR_EXTRA);
 
+       /* Update health track of mount */
+       p_ptr->redraw |= (PR_UHEALTH);
+
        if (p_ptr->ffall && !force)
        {
                monster_desc(m_name, m_ptr, 0);
@@ -5239,7 +5618,6 @@ msg_format("%s
 #else
        take_hit(DAMAGE_NOESCAPE, r_ptr->level+3, "Falling from riding", -1);
 #endif
-       p_ptr->redraw |= (PR_UHEALTH);
 
        return TRUE;
 }
@@ -5300,7 +5678,7 @@ msg_print("
 #ifdef JP
 msg_print("¤½¤Î¥â¥ó¥¹¥¿¡¼¤Ï¥Ú¥Ã¥È¤Ç¤Ï¤¢¤ê¤Þ¤»¤ó¡£");
 #else
-                       msg_print("That monster is no a pet.");
+                       msg_print("That monster is not a pet.");
 #endif
 
                        return FALSE;
@@ -5345,7 +5723,7 @@ msg_print("
 
                        return FALSE;
                }
-               if (r_info[m_ptr->r_idx].level > randint((skill_exp[GINOU_RIDING]/50 + p_ptr->lev/2 +20)))
+               if (r_info[m_ptr->r_idx].level > randint1((p_ptr->skill_exp[GINOU_RIDING]/50 + p_ptr->lev/2 +20)))
                {
 #ifdef JP
 msg_print("¤¦¤Þ¤¯¾è¤ì¤Ê¤«¤Ã¤¿¡£");
@@ -5370,6 +5748,9 @@ msg_format("%s
                }
 
                p_ptr->riding = c_ptr->m_idx;
+
+               /* Hack -- remove tracked monster */
+               if (p_ptr->riding == p_ptr->health_who) health_track(0);
        }
 
        /* Save the old location */
@@ -5415,7 +5796,7 @@ msg_format("%s
        return TRUE;
 }
 
-void do_name_pet(void)
+static void do_name_pet(void)
 {
        monster_type *m_ptr;
        char out_val[20];
@@ -5532,6 +5913,7 @@ void do_cmd_pet(void)
        byte y = 1, x = 0;
        int ctr = 0;
        char buf[160];
+       char target_buf[160];
 
        num = 0;
 
@@ -5554,13 +5936,13 @@ void do_cmd_pet(void)
        powers[num++] = PET_DISMISS;
 
 #ifdef JP
-       sprintf(buf,"¥Ú¥Ã¥È¤Î¥¿¡¼¥²¥Ã¥È¤ò»ØÄê (¸½ºß¡§%s)",
+       sprintf(target_buf,"¥Ú¥Ã¥È¤Î¥¿¡¼¥²¥Ã¥È¤ò»ØÄê (¸½ºß¡§%s)",
                (pet_t_m_idx ? r_name + r_info[m_list[pet_t_m_idx].r_idx].name : "»ØÄê¤Ê¤·"));
 #else
-       sprintf(buf,"specify a targert of pet (now:%s)",
+       sprintf(target_buf,"specify a targert of pet (now:%s)",
                (pet_t_m_idx ? r_name + r_info[m_list[pet_t_m_idx].r_idx].name : "nothing"));
 #endif
-       power_desc[num] = buf;
+       power_desc[num] = target_buf;
 
        powers[num++] = PET_TARGET;
 
@@ -5882,11 +6264,6 @@ strnfmt(out_val, 78, "(
                        continue;
                }
 
-               if (choice == '\r' && num == 1)
-               {
-                       choice = 'a';
-               }
-
                if (isalpha(choice))
                {
                        /* Note verify */