OSDN Git Service

山脈を2種類の地形に分けた。また山脈だけを特別扱いするコードをほとんど廃止。
[hengband/hengband.git] / src / monster1.c
index cb57e0b..573610b 100644 (file)
@@ -120,11 +120,6 @@ static void hooked_roff(cptr str)
 /*
  * Hack -- display monster information using "hooked_roff()"
  *
- * Note that there is now a compiler option to only read the monster
- * descriptions from the raw file when they are actually needed, which
- * saves about 60K of memory at the cost of disk access during monster
- * recall, which is optional to the user.
- *
  * This function should only be called with the cursor placed at the
  * left edge of the screen, on a cleared line, in which the recall is
  * to take place.  One extra blank line is left after the recall.
@@ -413,57 +408,12 @@ static void roff_aux(int r_idx, int mode)
 
        /* Descriptions */
        {
-               char buf[2048];
-
-#ifdef DELAY_LOAD_R_TEXT
-
-               int fd;
-
-               /* Build the filename */
-#ifdef JP
-path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, "r_info_j.raw");
-#else
-               path_build(buf, sizeof(buf), ANGBAND_DIR_DATA, "r_info.raw");
-#endif
-
+               cptr tmp = r_text + r_ptr->text;
 
-               /* Open the "raw" file */
-               fd = fd_open(buf, O_RDONLY);
-
-               /* Use file */
-               if (fd >= 0)
-               {
-                       huge pos;
-
-                       /* Starting position */
-                       pos = r_ptr->text;
-
-                       /* Additional offsets */
-                       pos += r_head->head_size;
-                       pos += r_head->info_size;
-                       pos += r_head->name_size;
-
-                       /* Seek */
-                       (void)fd_seek(fd, pos);
-
-                       /* Read a chunk of data */
-                       (void)fd_read(fd, buf, 2048);
-
-                       /* Close it */
-                       (void)fd_close(fd);
-               }
-
-#else
-
-               /* Simple method */
-               strcpy(buf, r_text + r_ptr->text);
-
-#endif
-
-               if (buf[0])
+               if (tmp[0])
                {
                        /* Dump it */
-                       hooked_roff(buf);
+                       hooked_roff(tmp);
 
                        /* Start a new line */
                        hooked_roff("\n");
@@ -3100,14 +3050,12 @@ void roff_top(int r_idx)
 
        /* Append the "standard" attr/char info */
        Term_addstr(-1, TERM_WHITE, " ('");
-       Term_addch(a1, c1);
-       if (use_bigtile && (a1 & 0x80)) Term_addch(255, -1);
+       Term_add_bigch(a1, c1);
        Term_addstr(-1, TERM_WHITE, "')");
 
        /* Append the "optional" attr/char info */
        Term_addstr(-1, TERM_WHITE, "/('");
-       Term_addch(a2, c2);
-       if (use_bigtile && (a2 & 0x80)) Term_addch(255, -1);
+       Term_add_bigch(a2, c2);
        Term_addstr(-1, TERM_WHITE, "'):");
 
        /* Wizards get extra info */
@@ -3188,27 +3136,7 @@ void output_monster_spoiler(int r_idx, void (*roff_func)(byte attr, cptr str))
 }
 
 
-bool monster_quest(int r_idx)
-{
-       monster_race *r_ptr = &r_info[r_idx];
-
-       /* Random quests are in the dungeon */
-       if (r_ptr->flags8 & RF8_WILD_ONLY) return FALSE;
-
-       /* No random quests for aquatic monsters */
-       if (r_ptr->flags7 & RF7_AQUATIC) return FALSE;
-
-       /* No random quests for multiplying monsters */
-       if (r_ptr->flags2 & RF2_MULTIPLY) return FALSE;
-
-       /* No quests to kill friendly monsters */
-       if (r_ptr->flags7 & RF7_FRIENDLY) return FALSE;
-
-       return TRUE;
-}
-
-
-bool monster_dungeon(int r_idx)
+bool mon_hook_dungeon(int r_idx)
 {
        monster_race *r_ptr = &r_info[r_idx];
 
@@ -3224,7 +3152,7 @@ bool monster_dungeon(int r_idx)
 }
 
 
-bool monster_ocean(int r_idx)
+static bool mon_hook_ocean(int r_idx)
 {
        monster_race *r_ptr = &r_info[r_idx];
 
@@ -3235,7 +3163,7 @@ bool monster_ocean(int r_idx)
 }
 
 
-bool monster_shore(int r_idx)
+static bool mon_hook_shore(int r_idx)
 {
        monster_race *r_ptr = &r_info[r_idx];
 
@@ -3246,7 +3174,7 @@ bool monster_shore(int r_idx)
 }
 
 
-static bool monster_waste(int r_idx)
+static bool mon_hook_waste(int r_idx)
 {
        monster_race *r_ptr = &r_info[r_idx];
 
@@ -3257,7 +3185,7 @@ static bool monster_waste(int r_idx)
 }
 
 
-bool monster_town(int r_idx)
+static bool mon_hook_town(int r_idx)
 {
        monster_race *r_ptr = &r_info[r_idx];
 
@@ -3268,7 +3196,7 @@ bool monster_town(int r_idx)
 }
 
 
-bool monster_wood(int r_idx)
+static bool mon_hook_wood(int r_idx)
 {
        monster_race *r_ptr = &r_info[r_idx];
 
@@ -3279,7 +3207,7 @@ bool monster_wood(int r_idx)
 }
 
 
-bool monster_volcano(int r_idx)
+static bool mon_hook_volcano(int r_idx)
 {
        monster_race *r_ptr = &r_info[r_idx];
 
@@ -3290,7 +3218,7 @@ bool monster_volcano(int r_idx)
 }
 
 
-bool monster_mountain(int r_idx)
+static bool mon_hook_mountain(int r_idx)
 {
        monster_race *r_ptr = &r_info[r_idx];
 
@@ -3301,7 +3229,7 @@ bool monster_mountain(int r_idx)
 }
 
 
-bool monster_grass(int r_idx)
+static bool mon_hook_grass(int r_idx)
 {
        monster_race *r_ptr = &r_info[r_idx];
 
@@ -3312,11 +3240,11 @@ bool monster_grass(int r_idx)
 }
 
 
-bool monster_deep_water(int r_idx)
+static bool mon_hook_deep_water(int r_idx)
 {
        monster_race *r_ptr = &r_info[r_idx];
 
-       if (!monster_dungeon(r_idx)) return FALSE;
+       if (!mon_hook_dungeon(r_idx)) return FALSE;
 
        if (r_ptr->flags7 & RF7_AQUATIC)
                return TRUE;
@@ -3325,11 +3253,11 @@ bool monster_deep_water(int r_idx)
 }
 
 
-bool monster_shallow_water(int r_idx)
+static bool mon_hook_shallow_water(int r_idx)
 {
        monster_race *r_ptr = &r_info[r_idx];
 
-       if (!monster_dungeon(r_idx)) return FALSE;
+       if (!mon_hook_dungeon(r_idx)) return FALSE;
 
        if (r_ptr->flags2 & RF2_AURA_FIRE)
                return FALSE;
@@ -3338,11 +3266,11 @@ bool monster_shallow_water(int r_idx)
 }
 
 
-bool monster_lava(int r_idx)
+static bool mon_hook_lava(int r_idx)
 {
        monster_race *r_ptr = &r_info[r_idx];
 
-       if (!monster_dungeon(r_idx)) return FALSE;
+       if (!mon_hook_dungeon(r_idx)) return FALSE;
 
        if (((r_ptr->flagsr & RFR_EFF_IM_FIRE_MASK) ||
             (r_ptr->flags7 & RF7_CAN_FLY)) &&
@@ -3353,6 +3281,18 @@ bool monster_lava(int r_idx)
 }
 
 
+static bool mon_hook_floor(int r_idx)
+{
+       monster_race *r_ptr = &r_info[r_idx];
+
+       if (!(r_ptr->flags7 & RF7_AQUATIC) ||
+           (r_ptr->flags7 & RF7_CAN_FLY))
+               return TRUE;
+       else
+               return FALSE;
+}
+
+
 monster_hook_type get_monster_hook(void)
 {
        if (!dun_level && !p_ptr->inside_quest)
@@ -3360,50 +3300,64 @@ monster_hook_type get_monster_hook(void)
                switch (wilderness[p_ptr->wilderness_y][p_ptr->wilderness_x].terrain)
                {
                case TERRAIN_TOWN:
-                       return (monster_hook_type)monster_town;
+                       return (monster_hook_type)mon_hook_town;
                case TERRAIN_DEEP_WATER:
-                       return (monster_hook_type)monster_ocean;
+                       return (monster_hook_type)mon_hook_ocean;
                case TERRAIN_SHALLOW_WATER:
                case TERRAIN_SWAMP:
-                       return (monster_hook_type)monster_shore;
+                       return (monster_hook_type)mon_hook_shore;
                case TERRAIN_DIRT:
                case TERRAIN_DESERT:
-                       return (monster_hook_type)monster_waste;
+                       return (monster_hook_type)mon_hook_waste;
                case TERRAIN_GRASS:
-                       return (monster_hook_type)monster_grass;
+                       return (monster_hook_type)mon_hook_grass;
                case TERRAIN_TREES:
-                       return (monster_hook_type)monster_wood;
+                       return (monster_hook_type)mon_hook_wood;
                case TERRAIN_SHALLOW_LAVA:
                case TERRAIN_DEEP_LAVA:
-                       return (monster_hook_type)monster_volcano;
+                       return (monster_hook_type)mon_hook_volcano;
                case TERRAIN_MOUNTAIN:
-                       return (monster_hook_type)monster_mountain;
+                       return (monster_hook_type)mon_hook_mountain;
                default:
-                       return (monster_hook_type)monster_dungeon;
+                       return (monster_hook_type)mon_hook_dungeon;
                }
        }
        else
        {
-               return (monster_hook_type)monster_dungeon;
+               return (monster_hook_type)mon_hook_dungeon;
        }
 }
 
 
 monster_hook_type get_monster_hook2(int y, int x)
 {
+       feature_type *f_ptr = &f_info[cave[y][x].feat];
+
        /* Set the monster list */
-       switch (cave[y][x].feat)
-       {
-       case FEAT_SHAL_WATER:
-               return (monster_hook_type)monster_shallow_water;
-       case FEAT_DEEP_WATER:
-               return (monster_hook_type)monster_deep_water;
-       case FEAT_DEEP_LAVA:
-       case FEAT_SHAL_LAVA:
-               return (monster_hook_type)monster_lava;
-       default:
-               return NULL;
+
+       /* Water */
+       if (have_flag(f_ptr->flags, FF_WATER))
+       {
+               /* Deep water */
+               if (have_flag(f_ptr->flags, FF_DEEP))
+               {
+                       return (monster_hook_type)mon_hook_deep_water;
+               }
+
+               /* Shallow water */
+               else
+               {
+                       return (monster_hook_type)mon_hook_shallow_water;
+               }
        }
+
+       /* Lava */
+       else if (have_flag(f_ptr->flags, FF_LAVA))
+       {
+               return (monster_hook_type)mon_hook_lava;
+       }
+
+       else return (monster_hook_type)mon_hook_floor;
 }
 
 
@@ -3463,52 +3417,58 @@ msg_format("%^s
 /*
  * Check if monster can cross terrain
  */
-bool monster_can_cross_terrain(byte feat, monster_race *r_ptr)
+bool monster_can_cross_terrain(s16b feat, monster_race *r_ptr, u16b mode)
 {
-       /* Pit */
-       if (feat == FEAT_DARK_PIT)
-       {
-               if (r_ptr->flags7 & RF7_CAN_FLY)
-                       return TRUE;
-               else
-                       return FALSE;
-       }
-       /* Deep water */
-       if (feat == FEAT_DEEP_WATER)
+       feature_type *f_ptr = &f_info[feat];
+
+       /* Pattern */
+       if (have_flag(f_ptr->flags, FF_PATTERN))
        {
-               if ((r_ptr->flags7 & RF7_AQUATIC) ||
-                   (r_ptr->flags7 & RF7_CAN_FLY) ||
-                   (r_ptr->flags7 & RF7_CAN_SWIM))
-                       return TRUE;
+               if (!(mode & CEM_RIDING))
+               {
+                       if (!(r_ptr->flags7 & RF7_CAN_FLY)) return FALSE;
+               }
                else
-                       return FALSE;
+               {
+                       if (!(mode & CEM_P_CAN_ENTER_PATTERN)) return FALSE;
+               }
        }
-       /* Shallow water */
-       else if (feat == FEAT_SHAL_WATER)
+
+       /* "CAN" flags */
+       if (have_flag(f_ptr->flags, FF_CAN_FLY) && (r_ptr->flags7 & RF7_CAN_FLY)) return TRUE;
+       if (have_flag(f_ptr->flags, FF_CAN_SWIM) && (r_ptr->flags7 & RF7_CAN_SWIM)) return TRUE;
+       if (have_flag(f_ptr->flags, FF_CAN_PASS))
        {
-               if (!(r_ptr->flags2 & RF2_AURA_FIRE) ||
-                   (r_ptr->flags7 & RF7_AQUATIC) ||
-                   (r_ptr->flags7 & RF7_CAN_FLY) ||
-                   (r_ptr->flags7 & RF7_CAN_SWIM))
-                       return TRUE;
-               else
-                       return FALSE;
+               if ((r_ptr->flags2 & RF2_PASS_WALL) && (!(mode & CEM_RIDING) || p_ptr->pass_wall)) return TRUE;
        }
-       /* Aquatic monster */
-       else if ((r_ptr->flags7 & RF7_AQUATIC) &&
-                   !(r_ptr->flags7 & RF7_CAN_FLY))
+
+       if (!have_flag(f_ptr->flags, FF_MOVE)) return FALSE;
+
+       /* Some monsters can walk on mountains */
+       if (have_flag(f_ptr->flags, FF_MOUNTAIN) && (r_ptr->flags8 & RF8_WILD_MOUNTAIN)) return TRUE;
+
+       if (have_flag(f_ptr->flags, FF_MUST_FLY) && !(r_ptr->flags7 & RF7_CAN_FLY)) return FALSE;
+
+       /* Water */
+       if (have_flag(f_ptr->flags, FF_WATER))
        {
-               return FALSE;
+               if (!(r_ptr->flags7 & RF7_AQUATIC))
+               {
+                       /* Deep water */
+                       if (have_flag(f_ptr->flags, FF_DEEP)) return FALSE;
+
+                       /* Shallow water */
+                       else if (r_ptr->flags2 & RF2_AURA_FIRE) return FALSE;
+               }
        }
+
+       /* Aquatic monster into non-water? */
+       else if (r_ptr->flags7 & RF7_AQUATIC) return FALSE;
+
        /* Lava */
-       else if ((feat == FEAT_SHAL_LAVA) ||
-           (feat == FEAT_DEEP_LAVA))
+       if (have_flag(f_ptr->flags, FF_LAVA))
        {
-               if ((r_ptr->flagsr & RFR_EFF_IM_FIRE_MASK) ||
-                   (r_ptr->flags7 & RF7_CAN_FLY))
-                       return TRUE;
-               else
-                       return FALSE;
+               if (!(r_ptr->flagsr & RFR_EFF_IM_FIRE_MASK)) return FALSE;
        }
 
        return TRUE;
@@ -3518,92 +3478,15 @@ bool monster_can_cross_terrain(byte feat, monster_race *r_ptr)
 /*
  * Strictly check if monster can enter the grid
  */
-bool monster_can_enter(int y, int x, monster_race *r_ptr)
+bool monster_can_enter(int y, int x, monster_race *r_ptr, u16b mode)
 {
        cave_type *c_ptr = &cave[y][x];
-       byte feat = c_ptr->feat;
 
        /* Player or other monster */
        if (player_bold(y, x)) return FALSE;
        if (c_ptr->m_idx) return FALSE;
 
-       /* Permanent wall */
-       if ((c_ptr->feat >= FEAT_PERM_EXTRA) &&
-           (c_ptr->feat <= FEAT_PERM_SOLID))
-               return FALSE;
-
-       /* Can fly over the Pattern */
-       if ((c_ptr->feat >= FEAT_PATTERN_START) &&
-           (c_ptr->feat <= FEAT_PATTERN_XTRA2))
-       {
-           if (!(r_ptr->flags7 & RF7_CAN_FLY))
-                   return FALSE;
-           else
-                   return TRUE;
-       }
-
-       /* Can fly over mountain on the surface */
-       if (feat == FEAT_MOUNTAIN)
-       {
-           if (!dun_level && 
-               ((r_ptr->flags7 & RF7_CAN_FLY) ||
-                (r_ptr->flags8 & RF8_WILD_MOUNTAIN)))
-                   return TRUE;
-           else
-                   return FALSE;
-       }
-
-       /* Cannot enter wall without pass wall ability */
-       if (!cave_floor_grid(c_ptr) && !(r_ptr->flags2 & RF2_PASS_WALL))
-               return FALSE;
-
-       /* Pit */
-       if (feat == FEAT_DARK_PIT)
-       {
-               if (r_ptr->flags7 & RF7_CAN_FLY)
-                       return TRUE;
-               else
-                       return FALSE;
-       }
-       /* Deep water */
-       if (feat == FEAT_DEEP_WATER)
-       {
-               if ((r_ptr->flags7 & RF7_AQUATIC) ||
-                   (r_ptr->flags7 & RF7_CAN_FLY) ||
-                   (r_ptr->flags7 & RF7_CAN_SWIM))
-                       return TRUE;
-               else
-                       return FALSE;
-       }
-       /* Shallow water */
-       else if (feat == FEAT_SHAL_WATER)
-       {
-               if (!(r_ptr->flags2 & RF2_AURA_FIRE) ||
-                   (r_ptr->flags7 & RF7_AQUATIC) ||
-                   (r_ptr->flags7 & RF7_CAN_FLY) ||
-                   (r_ptr->flags7 & RF7_CAN_SWIM))
-                       return TRUE;
-               else
-                       return FALSE;
-       }
-       /* Aquatic monster */
-       else if ((r_ptr->flags7 & RF7_AQUATIC) &&
-                   !(r_ptr->flags7 & RF7_CAN_FLY))
-       {
-               return FALSE;
-       }
-       /* Lava */
-       else if ((feat == FEAT_SHAL_LAVA) ||
-           (feat == FEAT_DEEP_LAVA))
-       {
-               if ((r_ptr->flagsr & RFR_EFF_IM_FIRE_MASK) ||
-                   (r_ptr->flags7 & RF7_CAN_FLY))
-                       return TRUE;
-               else
-                       return FALSE;
-       }
-
-       return TRUE;
+       return monster_can_cross_terrain(c_ptr->feat, r_ptr, mode);
 }