OSDN Git Service

既に忘れた何かの理由によって、長い事tabをスペース8文字にする設定で
[hengband/hengband.git] / src / monster2.c
index b549d0d..8b3e895 100644 (file)
@@ -16,7 +16,6 @@
 #define HORDE_NOEVIL 0x02
 
 bool is_kage = FALSE;
-u16b horde_align = 0;
 
 cptr horror_desc[MAX_SAN_HORROR] =
 {
@@ -645,8 +644,8 @@ static bool summon_specific_aux(int r_idx)
                case SUMMON_HI_UNDEAD:
                {
                        okay = ((r_ptr->d_char == 'L') ||
-                               (r_ptr->d_char == 'V') ||
-                               (r_ptr->d_char == 'W'));
+                               (r_ptr->d_char == 'V') ||
+                               (r_ptr->d_char == 'W'));
                        break;
                }
 
@@ -708,10 +707,10 @@ static bool summon_specific_aux(int r_idx)
                case SUMMON_BIZARRE6:
                {
                        okay = ((r_ptr->d_char == '!') ||
-                                (r_ptr->d_char == '?') ||
-                                (r_ptr->d_char == '=') ||
-                                (r_ptr->d_char == '$') ||
-                                (r_ptr->d_char == '|'));
+                                (r_ptr->d_char == '?') ||
+                                (r_ptr->d_char == '=') ||
+                                (r_ptr->d_char == '$') ||
+                                (r_ptr->d_char == '|'));
                        break;
                }
 
@@ -724,7 +723,7 @@ static bool summon_specific_aux(int r_idx)
                case SUMMON_CYBER:
                {
                        okay = ((r_ptr->d_char == 'U') &&
-                               (r_ptr->flags4 & RF4_ROCKET));
+                               (r_ptr->flags4 & RF4_ROCKET));
                        break;
                }
 
@@ -855,6 +854,18 @@ static bool summon_specific_aux(int r_idx)
                                (r_idx == MON_KNI_TEMPLAR));
                        break;
                }
+               case SUMMON_EAGLES:
+               {
+                       okay = (r_ptr->d_char == 'B' &&
+                               (r_ptr->flags8 & RF8_WILD_MOUNTAIN) &&
+                               (r_ptr->flags8 & RF8_WILD_ONLY));
+                       break;
+               }
+               case SUMMON_PIRANHAS:
+               {
+                       okay = (r_idx == MON_PIRANHA);
+                       break;
+               }
        }
 
        /* Result */
@@ -863,7 +874,7 @@ static bool summon_specific_aux(int r_idx)
 }
 
 
-static bool chameleon_change = FALSE;
+static int chameleon_change_m_idx = 0;
 
 
 /*
@@ -874,18 +885,20 @@ static bool restrict_monster_to_dungeon(int r_idx)
 {
        dungeon_info_type *d_ptr = &d_info[dungeon_type];
        monster_race *r_ptr = &r_info[r_idx];
-        byte a;
+       byte a;
 
        if (d_ptr->flags1 & DF1_CHAMELEON)
        {
-               if (chameleon_change) return TRUE;
+               if (chameleon_change_m_idx) return TRUE;
        }
        if (d_ptr->flags1 & DF1_NO_MAGIC)
        {
-               if (r_idx == MON_CHAMELEON) return TRUE;
-               if (r_ptr->freq_spell && !(r_ptr->flags4 & RF4_NOMAGIC_MASK) && !(r_ptr->flags5 & RF5_NOMAGIC_MASK) && !(r_ptr->flags6 & RF6_NOMAGIC_MASK))
+               if (r_idx != MON_CHAMELEON &&
+                   r_ptr->freq_spell && 
+                   !(r_ptr->flags4 & RF4_NOMAGIC_MASK) &&
+                   !(r_ptr->flags5 & RF5_NOMAGIC_MASK) &&
+                   !(r_ptr->flags6 & RF6_NOMAGIC_MASK))
                        return FALSE;
-               else return TRUE;
        }
        if (d_ptr->flags1 & DF1_NO_MELEE)
        {
@@ -894,219 +907,217 @@ static bool restrict_monster_to_dungeon(int r_idx)
                    !(r_ptr->flags5 & (RF5_BOLT_MASK | RF5_BEAM_MASK | RF5_BALL_MASK | RF5_CAUSE_1 | RF5_CAUSE_2 | RF5_CAUSE_3 | RF5_CAUSE_4 | RF5_MIND_BLAST | RF5_BRAIN_SMASH)) &&
                    !(r_ptr->flags6 & (RF6_BOLT_MASK | RF6_BEAM_MASK | RF6_BALL_MASK)))
                        return FALSE;
-               else return TRUE;
        }
        if (d_ptr->flags1 & DF1_BEGINNER)
        {
                if (r_ptr->level > dun_level)
                        return FALSE;
-               else return TRUE;
        }
 
        if (d_ptr->special_div == 64) return TRUE;
        if (summon_specific_type && !(d_ptr->flags1 & DF1_CHAMELEON)) return TRUE;
 
-        if(d_ptr->mode == DUNGEON_MODE_AND)
-        {
-                if (d_ptr->mflags1)
+       if(d_ptr->mode == DUNGEON_MODE_AND)
+       {
+               if (d_ptr->mflags1)
                {
-                        if((d_ptr->mflags1 & r_ptr->flags1) != d_ptr->mflags1)
-                                return FALSE;
+                       if((d_ptr->mflags1 & r_ptr->flags1) != d_ptr->mflags1)
+                               return FALSE;
                }
-                if (d_ptr->mflags2)
+               if (d_ptr->mflags2)
                {
-                        if((d_ptr->mflags2 & r_ptr->flags2) != d_ptr->mflags2)
-                                return FALSE;
+                       if((d_ptr->mflags2 & r_ptr->flags2) != d_ptr->mflags2)
+                               return FALSE;
                }
-                if (d_ptr->mflags3)
+               if (d_ptr->mflags3)
                {
-                        if((d_ptr->mflags3 & r_ptr->flags3) != d_ptr->mflags3)
-                                return FALSE;
+                       if((d_ptr->mflags3 & r_ptr->flags3) != d_ptr->mflags3)
+                               return FALSE;
                }
-                if (d_ptr->mflags4)
+               if (d_ptr->mflags4)
                {
-                        if((d_ptr->mflags4 & r_ptr->flags4) != d_ptr->mflags4)
-                                return FALSE;
+                       if((d_ptr->mflags4 & r_ptr->flags4) != d_ptr->mflags4)
+                               return FALSE;
                }
-                if (d_ptr->mflags5)
+               if (d_ptr->mflags5)
                {
-                        if((d_ptr->mflags5 & r_ptr->flags5) != d_ptr->mflags5)
-                                return FALSE;
+                       if((d_ptr->mflags5 & r_ptr->flags5) != d_ptr->mflags5)
+                               return FALSE;
                }
-                if (d_ptr->mflags6)
+               if (d_ptr->mflags6)
                {
-                        if((d_ptr->mflags6 & r_ptr->flags6) != d_ptr->mflags6)
-                                return FALSE;
+                       if((d_ptr->mflags6 & r_ptr->flags6) != d_ptr->mflags6)
+                               return FALSE;
                }
-                if (d_ptr->mflags7)
+               if (d_ptr->mflags7)
                {
-                        if((d_ptr->mflags7 & r_ptr->flags7) != d_ptr->mflags7)
-                                return FALSE;
+                       if((d_ptr->mflags7 & r_ptr->flags7) != d_ptr->mflags7)
+                               return FALSE;
                }
-                if (d_ptr->mflags8)
+               if (d_ptr->mflags8)
                {
-                        if((d_ptr->mflags8 & r_ptr->flags8) != d_ptr->mflags8)
-                                return FALSE;
+                       if((d_ptr->mflags8 & r_ptr->flags8) != d_ptr->mflags8)
+                               return FALSE;
                }
-                if (d_ptr->mflags9)
+               if (d_ptr->mflags9)
                {
-                        if((d_ptr->mflags9 & r_ptr->flags9) != d_ptr->mflags9)
-                                return FALSE;
+                       if((d_ptr->mflags9 & r_ptr->flags9) != d_ptr->mflags9)
+                               return FALSE;
                }
-                for(a = 0; a < 5; a++)
-                        if(d_ptr->r_char[a] && (d_ptr->r_char[a] != r_ptr->d_char)) return FALSE;
-        }
-        else if(d_ptr->mode == DUNGEON_MODE_NAND)
-        {
-                byte ok[9 + 5], i = 0, j = 0;
+               for(a = 0; a < 5; a++)
+                       if(d_ptr->r_char[a] && (d_ptr->r_char[a] != r_ptr->d_char)) return FALSE;
+       }
+       else if(d_ptr->mode == DUNGEON_MODE_NAND)
+       {
+               byte ok[9 + 5], i = 0, j = 0;
 
-                if (d_ptr->mflags1)
+               if (d_ptr->mflags1)
                {
-                        i++;
-                        if(d_ptr->mflags1 & r_ptr->flags1)
-                                ok[0] = 1;
+                       i++;
+                       if(d_ptr->mflags1 & r_ptr->flags1)
+                               ok[0] = 1;
                }
-                if (d_ptr->mflags2)
+               if (d_ptr->mflags2)
                {
-                        i++;
-                        if(d_ptr->mflags2 & r_ptr->flags2)
-                                ok[1] = 1;
+                       i++;
+                       if(d_ptr->mflags2 & r_ptr->flags2)
+                               ok[1] = 1;
                }
-                if (d_ptr->mflags3)
+               if (d_ptr->mflags3)
                {
-                        i++;
-                        if(d_ptr->mflags3 & r_ptr->flags3)
-                                ok[2] = 1;
+                       i++;
+                       if(d_ptr->mflags3 & r_ptr->flags3)
+                               ok[2] = 1;
                }
-                if (d_ptr->mflags4)
+               if (d_ptr->mflags4)
                {
-                        i++;
-                        if(d_ptr->mflags4 & r_ptr->flags4)
-                                ok[3] = 1;
+                       i++;
+                       if(d_ptr->mflags4 & r_ptr->flags4)
+                               ok[3] = 1;
                }
-                if (d_ptr->mflags5)
+               if (d_ptr->mflags5)
                {
-                        i++;
-                        if(d_ptr->mflags5 & r_ptr->flags5)
-                                ok[4] = 1;
+                       i++;
+                       if(d_ptr->mflags5 & r_ptr->flags5)
+                               ok[4] = 1;
                }
-                if (d_ptr->mflags6)
+               if (d_ptr->mflags6)
                {
-                        i++;
-                        if(d_ptr->mflags6 & r_ptr->flags6)
-                                ok[5] = 1;
+                       i++;
+                       if(d_ptr->mflags6 & r_ptr->flags6)
+                               ok[5] = 1;
                }
-                if (d_ptr->mflags7)
+               if (d_ptr->mflags7)
                {
-                        i++;
-                        if(d_ptr->mflags7 & r_ptr->flags7)
-                                ok[6] = 1;
+                       i++;
+                       if(d_ptr->mflags7 & r_ptr->flags7)
+                               ok[6] = 1;
                }
-                if (d_ptr->mflags8)
+               if (d_ptr->mflags8)
                {
-                        i++;
-                        if(d_ptr->mflags8 & r_ptr->flags8)
-                                ok[7] = 1;
+                       i++;
+                       if(d_ptr->mflags8 & r_ptr->flags8)
+                               ok[7] = 1;
                }
-                if (d_ptr->mflags9)
+               if (d_ptr->mflags9)
                {
-                        i++;
-                        if(d_ptr->mflags9 & r_ptr->flags9)
-                                ok[8] = 1;
+                       i++;
+                       if(d_ptr->mflags9 & r_ptr->flags9)
+                               ok[8] = 1;
                }
 
-                for(a = 0; a < 5; a++)
-                {
-                        if(d_ptr->r_char[a])
-                        {
-                                i++;
-                                if (d_ptr->r_char[a] != r_ptr->d_char) ok[9 + a] = 1;
-                        }
-                }
+               for(a = 0; a < 5; a++)
+               {
+                       if(d_ptr->r_char[a])
+                       {
+                               i++;
+                               if (d_ptr->r_char[a] != r_ptr->d_char) ok[9 + a] = 1;
+                       }
+               }
 
-                j = ok[0] + ok[1] + ok[2] + ok[3] + ok[4] + ok[5] + ok[6] + ok[7] + ok[8] + ok[9] + ok[10] + ok[11] + ok[12] + ok[13];
+               j = ok[0] + ok[1] + ok[2] + ok[3] + ok[4] + ok[5] + ok[6] + ok[7] + ok[8] + ok[9] + ok[10] + ok[11] + ok[12] + ok[13];
 
-                if(i == j) return FALSE;
-        }
-        else if(d_ptr->mode == DUNGEON_MODE_OR)
-        {
-                byte ok = FALSE, i;
-                s32b flag;
+               if(i == j) return FALSE;
+       }
+       else if(d_ptr->mode == DUNGEON_MODE_OR)
+       {
+               byte ok = FALSE, i;
+               s32b flag;
 
-                for(i = 0; i < 32; i++)
-                {
-                        flag = d_ptr->mflags1 & (1 << i);
-                        if(r_ptr->flags1 & flag) ok = TRUE;
+               for(i = 0; i < 32; i++)
+               {
+                       flag = d_ptr->mflags1 & (1 << i);
+                       if(r_ptr->flags1 & flag) ok = TRUE;
 
-                        flag = d_ptr->mflags2 & (1 << i);
-                        if(r_ptr->flags2 & flag) ok = TRUE;
+                       flag = d_ptr->mflags2 & (1 << i);
+                       if(r_ptr->flags2 & flag) ok = TRUE;
 
-                        flag = d_ptr->mflags3 & (1 << i);
-                        if(r_ptr->flags3 & flag) ok = TRUE;
+                       flag = d_ptr->mflags3 & (1 << i);
+                       if(r_ptr->flags3 & flag) ok = TRUE;
 
-                        flag = d_ptr->mflags4 & (1 << i);
-                        if(r_ptr->flags4 & flag) ok = TRUE;
+                       flag = d_ptr->mflags4 & (1 << i);
+                       if(r_ptr->flags4 & flag) ok = TRUE;
 
-                        flag = d_ptr->mflags5 & (1 << i);
-                        if(r_ptr->flags5 & flag) ok = TRUE;
+                       flag = d_ptr->mflags5 & (1 << i);
+                       if(r_ptr->flags5 & flag) ok = TRUE;
 
-                        flag = d_ptr->mflags6 & (1 << i);
-                        if(r_ptr->flags6 & flag) ok = TRUE;
+                       flag = d_ptr->mflags6 & (1 << i);
+                       if(r_ptr->flags6 & flag) ok = TRUE;
 
-                        flag = d_ptr->mflags7 & (1 << i);
-                        if(r_ptr->flags7 & flag) ok = TRUE;
+                       flag = d_ptr->mflags7 & (1 << i);
+                       if(r_ptr->flags7 & flag) ok = TRUE;
 
-                        flag = d_ptr->mflags8 & (1 << i);
-                        if(r_ptr->flags8 & flag) ok = TRUE;
+                       flag = d_ptr->mflags8 & (1 << i);
+                       if(r_ptr->flags8 & flag) ok = TRUE;
 
-                        flag = d_ptr->mflags9 & (1 << i);
-                        if(r_ptr->flags9 & flag) ok = TRUE;
-                }
-                for(a = 0; a < 5; a++)
-                        if(d_ptr->r_char[a] == r_ptr->d_char) ok = TRUE;
+                       flag = d_ptr->mflags9 & (1 << i);
+                       if(r_ptr->flags9 & flag) ok = TRUE;
+               }
+               for(a = 0; a < 5; a++)
+                       if(d_ptr->r_char[a] == r_ptr->d_char) ok = TRUE;
 
-                return ok;
-        }
-        else if(d_ptr->mode == DUNGEON_MODE_NOR)
-        {
-                byte ok = TRUE, i;
-                s32b flag;
+               return ok;
+       }
+       else if(d_ptr->mode == DUNGEON_MODE_NOR)
+       {
+               byte ok = TRUE, i;
+               s32b flag;
 
-                for(i = 0; i < 32; i++)
-                {
-                        flag = d_ptr->mflags1 & (1 << i);
-                        if(r_ptr->flags1 & flag) ok = FALSE;
+               for(i = 0; i < 32; i++)
+               {
+                       flag = d_ptr->mflags1 & (1 << i);
+                       if(r_ptr->flags1 & flag) ok = FALSE;
 
-                        flag = d_ptr->mflags2 & (1 << i);
-                        if(r_ptr->flags2 & flag) ok = FALSE;
+                       flag = d_ptr->mflags2 & (1 << i);
+                       if(r_ptr->flags2 & flag) ok = FALSE;
 
-                        flag = d_ptr->mflags3 & (1 << i);
-                        if(r_ptr->flags3 & flag) ok = FALSE;
+                       flag = d_ptr->mflags3 & (1 << i);
+                       if(r_ptr->flags3 & flag) ok = FALSE;
 
-                        flag = d_ptr->mflags4 & (1 << i);
-                        if(r_ptr->flags4 & flag) ok = FALSE;
+                       flag = d_ptr->mflags4 & (1 << i);
+                       if(r_ptr->flags4 & flag) ok = FALSE;
 
-                        flag = d_ptr->mflags5 & (1 << i);
-                        if(r_ptr->flags5 & flag) ok = FALSE;
+                       flag = d_ptr->mflags5 & (1 << i);
+                       if(r_ptr->flags5 & flag) ok = FALSE;
 
-                        flag = d_ptr->mflags6 & (1 << i);
-                        if(r_ptr->flags6 & flag) ok = FALSE;
+                       flag = d_ptr->mflags6 & (1 << i);
+                       if(r_ptr->flags6 & flag) ok = FALSE;
 
-                        flag = d_ptr->mflags7 & (1 << i);
-                        if(r_ptr->flags7 & flag) ok = FALSE;
+                       flag = d_ptr->mflags7 & (1 << i);
+                       if(r_ptr->flags7 & flag) ok = FALSE;
 
-                        flag = d_ptr->mflags8 & (1 << i);
-                        if(r_ptr->flags8 & flag) ok = FALSE;
+                       flag = d_ptr->mflags8 & (1 << i);
+                       if(r_ptr->flags8 & flag) ok = FALSE;
 
-                        flag = d_ptr->mflags9 & (1 << i);
-                        if(r_ptr->flags9 & flag) ok = FALSE;
-                }
-                for(a = 0; a < 5; a++)
-                        if(d_ptr->r_char[a] == r_ptr->d_char) ok = FALSE;
-                return ok;
-        }
+                       flag = d_ptr->mflags9 & (1 << i);
+                       if(r_ptr->flags9 & flag) ok = FALSE;
+               }
+               for(a = 0; a < 5; a++)
+                       if(d_ptr->r_char[a] == r_ptr->d_char) ok = FALSE;
+               return ok;
+       }
 
-        return TRUE;
+       return TRUE;
 }
 
 /*
@@ -1139,7 +1150,7 @@ errr get_mon_num_prep(monster_hook_type monster_hook,
                    (get_mon_num2_hook && !((*get_mon_num2_hook)(entry->index))))
                        continue;
 
-               if (!p_ptr->inside_battle && !chameleon_change &&
+               if (!p_ptr->inside_battle && !chameleon_change_m_idx &&
                    summon_specific_type != SUMMON_GUARDIANS)
                {
                        /* Hack -- don't create questors */
@@ -1318,7 +1329,7 @@ s16b get_mon_num(int level)
                /* Access the actual race */
                r_ptr = &r_info[r_idx];
 
-               if (!p_ptr->inside_battle && !chameleon_change)
+               if (!p_ptr->inside_battle && !chameleon_change_m_idx)
                {
                        /* Hack -- "unique" monsters must be "unique" */
                        if (((r_ptr->flags1 & (RF1_UNIQUE)) ||
@@ -1630,9 +1641,9 @@ if (!get_rnd_line("silly_j.txt", m_ptr->r_idx, silly_name))
        {
                /* The monster is visible, so use its gender */
 #ifdef JP
-                if (r_ptr->flags1 & (RF1_FEMALE)) strcpy(desc, "Èà½÷¼«¿È");
-                else if (r_ptr->flags1 & (RF1_MALE)) strcpy(desc, "È༫¿È");
-                else strcpy(desc, "¤½¤ì¼«¿È");
+               if (r_ptr->flags1 & (RF1_FEMALE)) strcpy(desc, "Èà½÷¼«¿È");
+               else if (r_ptr->flags1 & (RF1_MALE)) strcpy(desc, "È༫¿È");
+               else strcpy(desc, "¤½¤ì¼«¿È");
 #else
                if (r_ptr->flags1 & RF1_FEMALE) strcpy(desc, "herself");
                else if (r_ptr->flags1 & RF1_MALE) strcpy(desc, "himself");
@@ -1934,7 +1945,7 @@ msg_format("%s%s
 
                /* Demon characters are unaffected */
                if ((p_ptr->prace == RACE_IMP) || (p_ptr->prace == RACE_DEMON) || (mimic_info[p_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_DEMON)) return;
-               if (wizard) return;
+               if (p_ptr->wizard) return;
 
                /* Undead characters are 50% likely to be unaffected */
                if ((p_ptr->prace == RACE_SKELETON) || (p_ptr->prace == RACE_ZOMBIE)
@@ -2203,6 +2214,8 @@ void update_mon(int m_idx, bool full)
 
        monster_race *r_ptr = &r_info[m_ptr->r_idx];
 
+       bool do_disturb = disturb_move;
+
        int d;
 
        /* Current location */
@@ -2215,6 +2228,14 @@ void update_mon(int m_idx, bool full)
        /* Seen by vision */
        bool easy = FALSE;
 
+       /* Do disturb? */
+       if (disturb_high)
+       {
+               monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
+
+               if (ap_r_ptr->r_tkills && ap_r_ptr->level >= p_ptr->lev)
+                       do_disturb = TRUE;
+       }
 
        /* Compute distance */
        if (full)
@@ -2301,6 +2322,105 @@ void update_mon(int m_idx, bool full)
                                        if (r_ptr->flags2 & (RF2_STUPID)) r_ptr->r_flags2 |= (RF2_STUPID);
                                }
                        }
+
+                       /* Magical sensing */
+                       if ((p_ptr->esp_animal) && (r_ptr->flags3 & (RF3_ANIMAL)))
+                       {
+                               flag = TRUE;
+                               r_ptr->r_flags3 |= (RF3_ANIMAL);
+
+                       }
+
+                       /* Magical sensing */
+                       if ((p_ptr->esp_undead) && (r_ptr->flags3 & (RF3_UNDEAD)))
+                       {
+                               flag = TRUE;
+                               r_ptr->r_flags3 |= (RF3_UNDEAD);
+
+                       }
+
+                       /* Magical sensing */
+                       if ((p_ptr->esp_demon) && (r_ptr->flags3 & (RF3_DEMON)))
+                       {
+                               flag = TRUE;
+                               r_ptr->r_flags3 |= (RF3_DEMON);
+
+                       }
+
+                       /* Magical sensing */
+                       if ((p_ptr->esp_orc) && (r_ptr->flags3 & (RF3_ORC)))
+                       {
+                               flag = TRUE;
+                               r_ptr->r_flags3 |= (RF3_ORC);
+
+                       }
+
+                       /* Magical sensing */
+                       if ((p_ptr->esp_troll) && (r_ptr->flags3 & (RF3_TROLL)))
+                       {
+                               flag = TRUE;
+                               r_ptr->r_flags3 |= (RF3_TROLL);
+
+                       }
+
+                       /* Magical sensing */
+                       if ((p_ptr->esp_giant) && (r_ptr->flags3 & (RF3_GIANT)))
+                       {
+                               flag = TRUE;
+                               r_ptr->r_flags3 |= (RF3_GIANT);
+
+                       }
+
+                       /* Magical sensing */
+                       if ((p_ptr->esp_dragon) && (r_ptr->flags3 & (RF3_DRAGON)))
+                       {
+                               flag = TRUE;
+                               r_ptr->r_flags3 |= (RF3_DRAGON);
+
+                       }
+
+                       /* Magical sensing */
+                       if ((p_ptr->esp_human) && (r_ptr->flags2 & (RF2_HUMAN)))
+                       {
+                               flag = TRUE;
+                               r_ptr->r_flags2 |= (RF2_HUMAN);
+
+                       }
+
+                       /* Magical sensing */
+                       if ((p_ptr->esp_evil) && (r_ptr->flags3 & (RF3_EVIL)))
+                       {
+                               flag = TRUE;
+                               r_ptr->r_flags3 |= (RF3_EVIL);
+
+                       }
+
+                       /* Magical sensing */
+                       if ((p_ptr->esp_good) && (r_ptr->flags3 & (RF3_GOOD)))
+                       {
+                               flag = TRUE;
+                               r_ptr->r_flags3 |= (RF3_GOOD);
+
+                       }
+
+                       /* Magical sensing */
+                       if ((p_ptr->esp_nonliving) && 
+                           (r_ptr->flags3 & (RF3_NONLIVING)) &&
+                           !(r_ptr->flags3 & (RF3_DEMON)) &&
+                           !(r_ptr->flags3 & (RF3_UNDEAD)))
+                       {
+                               flag = TRUE;
+                               r_ptr->r_flags3 |= (RF3_NONLIVING);
+
+                       }
+
+                       /* Magical sensing */
+                       if ((p_ptr->esp_unique) && (r_ptr->flags1 & (RF1_UNIQUE)))
+                       {
+                               flag = TRUE;
+                               r_ptr->r_flags1 |= (RF1_UNIQUE);
+
+                       }
                }
 
                /* Normal line of sight, and not blind */
@@ -2417,7 +2537,7 @@ void update_mon(int m_idx, bool full)
                        if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
 
                        /* Disturb on disappearance */
-                       if (disturb_move)
+                       if (do_disturb)
                        {
                                if (disturb_pets || is_hostile(m_ptr))
                                        disturb(1, 0);
@@ -2436,7 +2556,7 @@ void update_mon(int m_idx, bool full)
                        m_ptr->mflag |= (MFLAG_VIEW);
 
                        /* Disturb on appearance */
-                       if (disturb_move)
+                       if (do_disturb)
                        {
                                if (disturb_pets || is_hostile(m_ptr))
                                        disturb(1, 0);
@@ -2454,7 +2574,7 @@ void update_mon(int m_idx, bool full)
                        m_ptr->mflag &= ~(MFLAG_VIEW);
 
                        /* Disturb on disappearance */
-                       if (disturb_move)
+                       if (do_disturb)
                        {
                                if (disturb_pets || is_hostile(m_ptr))
                                        disturb(1, 0);
@@ -2488,11 +2608,11 @@ void update_monsters(bool full)
 /*
  * Hack -- the index of the summoning monster
  */
-static int summon_specific_who_for_chameleons = 0;
-
 static bool monster_hook_chameleon_lord(int r_idx)
 {
        monster_race *r_ptr = &r_info[r_idx];
+       monster_type *m_ptr = &m_list[chameleon_change_m_idx];
+       monster_race *old_r_ptr = &r_info[m_ptr->r_idx];
 
        if (!(r_ptr->flags1 & (RF1_UNIQUE))) return FALSE;
        if (r_ptr->flags7 & (RF7_FRIENDLY | RF7_CHAMELEON)) return FALSE;
@@ -2502,12 +2622,32 @@ static bool monster_hook_chameleon_lord(int r_idx)
        if ((r_ptr->blow[0].method == RBM_EXPLODE) || (r_ptr->blow[1].method == RBM_EXPLODE) || (r_ptr->blow[2].method == RBM_EXPLODE) || (r_ptr->blow[3].method == RBM_EXPLODE))
                return FALSE;
 
+       if (!monster_can_cross_terrain(cave[m_ptr->fy][m_ptr->fx].feat, r_ptr)) return FALSE;
+
+       /* Not born */
+       if (!(old_r_ptr->flags7 & RF7_CHAMELEON))
+       {
+               if ((m_ptr->sub_align & SUB_ALIGN_EVIL) && (r_ptr->flags3 & RF3_GOOD)) return FALSE;
+               if ((m_ptr->sub_align & SUB_ALIGN_GOOD) && (r_ptr->flags3 & RF3_EVIL)) return FALSE;
+       }
+
+       /* Born now */
+       else if (summon_specific_who > 0)
+       {
+               monster_type *sm_ptr = &m_list[summon_specific_who];
+
+               if ((sm_ptr->sub_align & SUB_ALIGN_EVIL) && (r_ptr->flags3 & RF3_GOOD)) return FALSE;
+               if ((sm_ptr->sub_align & SUB_ALIGN_GOOD) && (r_ptr->flags3 & RF3_EVIL)) return FALSE;
+       }
+
        return TRUE;
 }
 
 static bool monster_hook_chameleon(int r_idx)
 {
        monster_race *r_ptr = &r_info[r_idx];
+       monster_type *m_ptr = &m_list[chameleon_change_m_idx];
+       monster_race *old_r_ptr = &r_info[m_ptr->r_idx];
 
        if (r_ptr->flags1 & (RF1_UNIQUE)) return FALSE;
        if (r_ptr->flags2 & RF2_MULTIPLY) return FALSE;
@@ -2516,13 +2656,31 @@ static bool monster_hook_chameleon(int r_idx)
        if ((r_ptr->blow[0].method == RBM_EXPLODE) || (r_ptr->blow[1].method == RBM_EXPLODE) || (r_ptr->blow[2].method == RBM_EXPLODE) || (r_ptr->blow[3].method == RBM_EXPLODE))
                return FALSE;
 
+       if (!monster_can_cross_terrain(cave[m_ptr->fy][m_ptr->fx].feat, r_ptr)) return FALSE;
+
+       /* Not born */
+       if (!(old_r_ptr->flags7 & RF7_CHAMELEON))
+       {
+               if ((old_r_ptr->flags3 & RF3_GOOD) && !(r_ptr->flags3 & RF3_GOOD)) return FALSE;
+               if ((old_r_ptr->flags3 & RF3_EVIL) && !(r_ptr->flags3 & RF3_EVIL)) return FALSE;
+               if (!(old_r_ptr->flags3 & (RF3_GOOD | RF3_EVIL)) && (r_ptr->flags3 & (RF3_GOOD | RF3_EVIL))) return FALSE;
+       }
+
+       /* Born now */
+       else if (summon_specific_who > 0)
+       {
+               monster_type *sm_ptr = &m_list[summon_specific_who];
+
+               if ((sm_ptr->sub_align & SUB_ALIGN_EVIL) && (r_ptr->flags3 & RF3_GOOD)) return FALSE;
+               if ((sm_ptr->sub_align & SUB_ALIGN_GOOD) && (r_ptr->flags3 & RF3_EVIL)) return FALSE;
+       }
+
        return (*(get_monster_hook()))(r_idx);
 }
 
 
 void choose_new_monster(int m_idx, bool born, int r_idx)
 {
-       int attempt = 5000;
        int oldmaxhp, i;
        monster_type *m_ptr = &m_list[m_idx];
        monster_race *r_ptr;
@@ -2539,53 +2697,30 @@ void choose_new_monster(int m_idx, bool born, int r_idx)
 
        if (!r_idx)
        {
-               chameleon_change = TRUE;
+               int level;
+
+               chameleon_change_m_idx = m_idx;
                if (old_unique)
                        get_mon_num_prep(monster_hook_chameleon_lord, NULL);
                else
                        get_mon_num_prep(monster_hook_chameleon, NULL);
 
-               while (attempt--)
-               {
-                       int level;
+               if (old_unique)
+                       level = r_info[MON_CHAMELEON_K].level;
+               else if (!dun_level)
+                       level = wilderness[p_ptr->wilderness_y][p_ptr->wilderness_x].level;
+               else
+                       level = dun_level;
 
-                       if (old_unique)
-                               level = r_info[MON_CHAMELEON_K].level;
-                       else if (!dun_level)
-                               level = wilderness[p_ptr->wilderness_y][p_ptr->wilderness_x].level;
-                       else
-                               level = dun_level;
+               if (d_info[dungeon_type].flags1 & DF1_CHAMELEON) level+= 2+randint1(3);
 
-                       if (d_info[dungeon_type].flags1 & DF1_CHAMELEON) level+= 2+randint1(3);
-                       r_idx = get_mon_num(level);
-                       r_ptr = &r_info[r_idx];
+               r_idx = get_mon_num(level);
+               r_ptr = &r_info[r_idx];
 
-                       if (!monster_can_cross_terrain(cave[m_ptr->fy][m_ptr->fx].feat, r_ptr)) continue;
-                       if (!born)
-                       {
-                               if (!old_unique)
-                               {
-                                       if ((r_info[old_r_idx].flags3 & RF3_GOOD) && !(r_ptr->flags3 & RF3_GOOD)) continue;
-                                       if ((r_info[old_r_idx].flags3 & RF3_EVIL) && !(r_ptr->flags3 & RF3_EVIL)) continue;
-                                       if (!(r_info[old_r_idx].flags3 & (RF3_GOOD | RF3_EVIL)) && (r_ptr->flags3 & (RF3_GOOD | RF3_EVIL))) continue;
-                               }
-                               else
-                               {
-                                       if ((m_ptr->sub_align & SUB_ALIGN_EVIL) && (r_ptr->flags3 & RF3_GOOD)) continue;
-                                       if ((m_ptr->sub_align & SUB_ALIGN_GOOD) && (r_ptr->flags3 & RF3_EVIL)) continue;
-                               }
-                       }
-                       else if (summon_specific_who_for_chameleons > 0)
-                       {
-                               monster_type *sm_ptr = &m_list[summon_specific_who_for_chameleons];
+               chameleon_change_m_idx = 0;
 
-                               if ((sm_ptr->sub_align & SUB_ALIGN_EVIL) && (r_ptr->flags3 & RF3_GOOD)) continue;
-                               if ((sm_ptr->sub_align & SUB_ALIGN_GOOD) && (r_ptr->flags3 & RF3_EVIL)) continue;
-                       }
-                       break;
-               }
-               chameleon_change = FALSE;
-               if (!attempt) return;
+               /* Paranoia */
+               if (!r_idx) return;
        }
 
        m_ptr->r_idx = r_idx;
@@ -2648,26 +2783,48 @@ void choose_new_monster(int m_idx, bool born, int r_idx)
        m_ptr->hp = (long)(m_ptr->hp * m_ptr->max_maxhp) / oldmaxhp;
 }
 
+
+/*
+ *  Hook for Tanuki
+ */
+static bool monster_hook_tanuki(int r_idx)
+{
+       monster_race *r_ptr = &r_info[r_idx];
+
+       if (r_ptr->flags1 & (RF1_UNIQUE)) return FALSE;
+       if (r_ptr->flags2 & RF2_MULTIPLY) return FALSE;
+       if (r_ptr->flags7 & (RF7_FRIENDLY | RF7_CHAMELEON)) return FALSE;
+       if (r_ptr->flags7 & RF7_AQUATIC) return FALSE;
+       
+       if ((r_ptr->blow[0].method == RBM_EXPLODE) || (r_ptr->blow[1].method == RBM_EXPLODE) || (r_ptr->blow[2].method == RBM_EXPLODE) || (r_ptr->blow[3].method == RBM_EXPLODE))
+               return FALSE;
+
+       return (*(get_monster_hook()))(r_idx);
+}
+
+
 /*
  *  Set initial racial appearance of a monster
  */
 static int initial_r_appearance(int r_idx)
 {
+       int attempts = 1000;
+
        int ap_r_idx;
        int min = MIN(base_level-5, 50);
 
        if (!(r_info[r_idx].flags7 & RF7_TANUKI))
                return r_idx;
 
-       get_mon_num_prep(monster_hook_chameleon, NULL);
+       get_mon_num_prep(monster_hook_tanuki, NULL);
 
-       while (1)
+       while (--attempts)
        {
                ap_r_idx = get_mon_num(base_level + 10);
-               if (r_info[ap_r_idx].flags7 & RF7_AQUATIC) continue;
-               if (r_info[ap_r_idx].level >= min) break;
+               if (r_info[ap_r_idx].level >= min) return ap_r_idx;
        }
-       return ap_r_idx;
+
+       return r_idx;
 }
 
 
@@ -2690,7 +2847,6 @@ static int initial_r_appearance(int r_idx)
  * This is the only function which may place a monster in the dungeon,
  * except for the savefile loading code.
  */
-//bool place_monster_one(int who, int y, int x, int r_idx, bool slp, bool friendly, bool pet, bool no_pet)
 bool place_monster_one(int who, int y, int x, int r_idx, u32b mode)
 {
        int                     i;
@@ -2704,18 +2860,18 @@ bool place_monster_one(int who, int y, int x, int r_idx, u32b mode)
 
        cptr            name = (r_name + r_ptr->name);
 
-        /* DO NOT PLACE A MONSTER IN THE SMALL SCALE WILDERNESS !!! */
-        if(p_ptr->wild_mode) return FALSE;
+       /* DO NOT PLACE A MONSTER IN THE SMALL SCALE WILDERNESS !!! */
+       if(p_ptr->wild_mode) return FALSE;
 
        /* Verify location */
        if (!in_bounds(y, x)) return (FALSE);
 
        /* Require empty space (if not ghostly) */
        if (!(!dun_level && (cave[y][x].feat == FEAT_MOUNTAIN) && ((r_ptr->flags8 & RF8_WILD_MOUNTAIN) || (r_ptr->flags7 & RF7_CAN_FLY))) &&
-           !cave_empty_bold2(y, x) &&
+           !(cave_empty_bold2(y, x) || (mode & PM_IGNORE_TERRAIN)) &&
            !((r_ptr->flags2 & RF2_PASS_WALL) &&
-           !(cave_perma_bold(y, x) || cave[y][x].m_idx ||
-           ((y == py) && (x == px))))) return (FALSE);
+             !(cave_perma_bold(y, x) || cave[y][x].m_idx ||
+               ((y == py) && (x == px))))) return (FALSE);
 
        /* Paranoia */
        if (!r_idx) return (FALSE);
@@ -2723,18 +2879,12 @@ bool place_monster_one(int who, int y, int x, int r_idx, u32b mode)
        /* Paranoia */
        if (!r_ptr->name) return (FALSE);
 
-#if 0
-       /* Hack -- no creation on glyph of warding */
-       if (cave[y][x].feat == FEAT_GLYPH) return (FALSE);
-       if (cave[y][x].feat == FEAT_MINOR_GLYPH) return (FALSE);
-#endif
-
        /* Nor on the Pattern */
        if ((cave[y][x].feat >= FEAT_PATTERN_START)
         && (cave[y][x].feat <= FEAT_PATTERN_XTRA2))
                return (FALSE);
 
-       if (monster_terrain_sensitive &&
+       if (!(mode & PM_IGNORE_TERRAIN) &&
            !monster_can_cross_terrain(cave[y][x].feat, r_ptr))
        {
                return FALSE;
@@ -2797,7 +2947,7 @@ bool place_monster_one(int who, int y, int x, int r_idx, u32b mode)
        /* Access the location */
        c_ptr = &cave[y][x];
 
-       if (c_ptr->feat == FEAT_GLYPH)
+       if (is_glyph_grid(c_ptr))
        {
                if (randint1(BREAK_GLYPH) < (r_ptr->level+20))
                {
@@ -2816,7 +2966,8 @@ msg_print("
                        c_ptr->info &= ~(CAVE_MARK);
 
                        /* Break the rune */
-                       c_ptr->feat = floor_type[randint0(100)];
+                       c_ptr->info &= ~(CAVE_OBJECT);
+                       c_ptr->mimic = 0;
 
                        /* Notice */
                        note_spot(y, x);
@@ -2923,9 +3074,6 @@ msg_print("
 
        if (r_ptr->flags7 & RF7_CHAMELEON)
        {
-               if (who > 0) summon_specific_who_for_chameleons = who;
-               else summon_specific_who_for_chameleons = 0;
-
                choose_new_monster(c_ptr->m_idx, TRUE, 0);
                r_ptr = &r_info[m_ptr->r_idx];
                m_ptr->mflag2 |= MFLAG_CHAMELEON;
@@ -2934,8 +3082,6 @@ msg_print("
                /* Hack - Set sub_align to neutral when the Chameleon Lord is generated as "GUARDIAN" */
                if ((r_ptr->flags1 & RF1_UNIQUE) && (who <= 0))
                        m_ptr->sub_align = SUB_ALIGN_NEUTRAL;
-
-               summon_specific_who_for_chameleons = 0;
        }
        else if (is_kage)
        {
@@ -3017,7 +3163,7 @@ msg_print("
          }
        }
 
-       if (summon_specific_type == SUMMON_KNIGHTS) m_ptr->fast = 100;
+       if (mode & PM_HASTE) m_ptr->fast = 100;
 
        if (m_ptr->mspeed > 199) m_ptr->mspeed = 199;
 
@@ -3086,7 +3232,7 @@ msg_print("
 #ifdef JP
                                color = "»ç¿§¤Ë";
 #else
-                               color = "perple";
+                               color = "purple";
 #endif
                        else if (r_ptr->level > p_ptr->lev + 5)
 #ifdef JP
@@ -3123,7 +3269,7 @@ msg_print("
                }
        }
 
-       if (c_ptr->feat == FEAT_MINOR_GLYPH)
+       if (is_explosive_rune_grid(c_ptr))
        {
                /* Break the ward */
                if (randint1(BREAK_MINOR_GLYPH) > r_ptr->level)
@@ -3137,7 +3283,7 @@ msg_print("
                                msg_print("The rune explodes!");
 #endif
 
-                               project(0, 2, y, x, 2 * (p_ptr->lev + damroll(7, 7)), GF_MANA, (PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_JUMP | PROJECT_NO_REF | PROJECT_NO_HANGEKI), -1);
+                               project(0, 2, y, x, 2 * (p_ptr->lev + damroll(7, 7)), GF_MANA, (PROJECT_GRID | PROJECT_ITEM | PROJECT_KILL | PROJECT_JUMP | PROJECT_NO_HANGEKI), -1);
                        }
                }
                else
@@ -3153,7 +3299,9 @@ msg_print("
                c_ptr->info &= ~(CAVE_MARK);
 
                /* Break the rune */
-               c_ptr->feat = floor_type[randint0(100)];
+               c_ptr->info &= ~(CAVE_OBJECT);
+               c_ptr->mimic = 0;
+
                note_spot(y, x);
                lite_spot(y, x);
        }
@@ -3196,13 +3344,7 @@ static bool mon_scatter(int *yp, int *xp, int y, int x, int max_dist)
                        if (!cave_empty_bold2(ny, nx)) continue;
                        if (cave[ny][nx].m_idx) continue;
                        if ((ny == py) && (nx == px)) continue;
-                       
-#if 0
-                       /* Hack -- no summon on glyph of warding */
-                       if (cave[ny][nx].feat == FEAT_GLYPH) continue;
-                       if (cave[ny][nx].feat == FEAT_MINOR_GLYPH) continue;
-#endif
-                       
+                                               
                        /* ... nor on the Pattern */
                        if ((cave[ny][nx].feat >= FEAT_PATTERN_START) &&
                            (cave[ny][nx].feat <= FEAT_PATTERN_XTRA2))
@@ -3246,7 +3388,6 @@ static bool mon_scatter(int *yp, int *xp, int y, int x, int max_dist)
 /*
  * Attempt to place a "group" of monsters around the given location
  */
-//static bool place_monster_group(int who, int y, int x, int r_idx, bool slp, bool friendly, bool pet, bool no_pet)
 static bool place_monster_group(int who, int y, int x, int r_idx, u32b mode)
 {
        monster_race *r_ptr = &r_info[r_idx];
@@ -3404,7 +3545,6 @@ static bool place_monster_okay(int r_idx)
  * Note the use of the new "monster allocation table" code to restrict
  * the "get_mon_num()" function to "legal" escort types.
  */
-//bool place_monster_aux(int who, int y, int x, int r_idx, bool slp, bool grp, bool friendly, bool pet, bool no_kage, bool no_pet)
 bool place_monster_aux(int who, int y, int x, int r_idx, u32b mode)
 {
        int             i;
@@ -3481,7 +3621,6 @@ bool place_monster_aux(int who, int y, int x, int r_idx, u32b mode)
  *
  * Attempt to find a monster appropriate to the "monster_level"
  */
-//bool place_monster(int y, int x, bool slp, bool grp)
 bool place_monster(int y, int x, u32b mode)
 {
        int r_idx;
@@ -3534,9 +3673,6 @@ bool alloc_horde(int y, int x)
        }
        if (attempts < 1) return FALSE;
 
-       if (r_ptr->flags3 & RF3_GOOD) horde_align |= HORDE_NOEVIL;
-       if (r_ptr->flags3 & RF3_EVIL) horde_align |= HORDE_NOGOOD;
-
        attempts = 1000;
 
        while (--attempts)
@@ -3545,7 +3681,7 @@ bool alloc_horde(int y, int x)
                if (place_monster_aux(0, y, x, r_idx, 0L)) break;
        }
 
-       if (attempts < 1) {horde_align = 0;return FALSE;}
+       if (attempts < 1) return FALSE;
 
        m_idx = cave[y][x].m_idx;
 
@@ -3562,7 +3698,6 @@ bool alloc_horde(int y, int x)
                x = cx;
        }
 
-       horde_align = 0;
        return TRUE;
 }
 
@@ -3579,36 +3714,35 @@ bool alloc_horde(int y, int x)
  *
  * Use "monster_level" for the monster level
  */
-//bool alloc_monster(int dis, bool slp)
 bool alloc_monster(int dis, u32b mode)
 {
        int                     y = 0, x = 0;
        int         attempts_left = 10000;
        int guardian = d_info[dungeon_type].final_guardian;
 
-        /* Put an Guardian */
-        if(guardian && d_info[dungeon_type].maxdepth == dun_level && r_info[guardian].cur_num < r_info[guardian].max_num )
-        {
-                int oy;
-                int ox;
-                int try = 4000;
-
-                /* Find a good position */
-                while(try)
-                {
-                        /* Get a random spot */
-                        oy = randint1(cur_hgt - 4) + 2;
-                        ox = randint1(cur_wid - 4) + 2;
-
-                        /* Is it a good spot ? */
-                        if (cave_empty_bold2(oy, ox) && monster_can_cross_terrain(cave[oy][ox].feat, &r_info[guardian]))
+       /* Put an Guardian */
+       if(guardian && d_info[dungeon_type].maxdepth == dun_level && r_info[guardian].cur_num < r_info[guardian].max_num )
+       {
+               int oy;
+               int ox;
+               int try = 4000;
+
+               /* Find a good position */
+               while(try)
+               {
+                       /* Get a random spot */
+                       oy = randint1(cur_hgt - 4) + 2;
+                       ox = randint1(cur_wid - 4) + 2;
+
+                       /* Is it a good spot ? */
+                       if (cave_empty_bold2(oy, ox) && monster_can_cross_terrain(cave[oy][ox].feat, &r_info[guardian]))
                        {
                                /* Place the guardian */
                                if (place_monster_aux(0, oy, ox, guardian, (PM_ALLOW_GROUP | PM_NO_KAGE | PM_NO_PET))) break;
                        }
-                        /* One less try */
-                        try--;
-                }
+                       /* One less try */
+                       try--;
+               }
        }
 
 
@@ -3738,9 +3872,6 @@ static bool summon_specific_okay(int r_idx)
             ((p_ptr->align < -9) && (r_ptr->flags3 & RF3_GOOD))))
                return FALSE;
 
-       if ((horde_align & HORDE_NOGOOD) && (r_ptr->flags3 & RF3_GOOD)) return FALSE;
-       if ((horde_align & HORDE_NOEVIL) && (r_ptr->flags3 & RF3_EVIL)) return FALSE;
-
        if ((r_ptr->flags7 & RF7_CHAMELEON) && (d_info[dungeon_type].flags1 & DF1_CHAMELEON)) return TRUE;
 
        return (summon_specific_aux(r_idx));
@@ -3771,7 +3902,6 @@ static bool summon_specific_okay(int r_idx)
  *
  * Note that this function may not succeed, though this is very rare.
  */
-//bool summon_specific(int who, int y1, int x1, int lev, int type, bool group, bool friendly, bool pet, bool unique_okay, bool no_pet)
 bool summon_specific(int who, int y1, int x1, int lev, int type, u32b mode)
 {
        int x, y, r_idx;
@@ -3819,7 +3949,6 @@ bool summon_specific(int who, int y1, int x1, int lev, int type, u32b mode)
 }
 
 /* A "dangerous" function, creates a pet of the specified type */
-//bool summon_named_creature (int who, int oy, int ox, int r_idx, bool slp, bool group_ok, bool friendly, bool pet)
 bool summon_named_creature (int who, int oy, int ox, int r_idx, u32b mode)
 {
        int x, y;
@@ -3844,7 +3973,6 @@ bool summon_named_creature (int who, int oy, int ox, int r_idx, u32b mode)
  *
  * Note that "reproduction" REQUIRES empty space.
  */
-//bool multiply_monster(int m_idx, bool clone, bool friendly, bool pet)
 bool multiply_monster(int m_idx, bool clone, u32b mode)
 {
        monster_type    *m_ptr = &m_list[m_idx];