OSDN Git Service

モンスターの移動処理で常にFLASEになる場所があった。削除してしまうのはためらわれるのでコメントアウトしておいた。
[hengbandforosx/hengbandosx.git] / src / melee2.c
index de49829..b7fab78 100644 (file)
@@ -53,8 +53,8 @@ static bool get_enemy_dir(int m_idx, int *mm)
        {
                if (p_ptr->inside_battle)
                {
-                       start = randint(m_max-1)+m_max;
-                       if(rand_int(2)) plus = -1;
+                       start = randint1(m_max-1)+m_max;
+                       if(randint0(2)) plus = -1;
                }
                else start = m_max + 1;
 
@@ -217,7 +217,7 @@ void mon_take_hit_mon(bool is_psy_spear, int m_idx, int dam, bool *fear, cptr no
 
        if (p_ptr->riding && (m_idx == p_ptr->riding)) disturb(1, 0);
 
-       if (m_ptr->invulner && rand_int(PENETRATE_INVULNERABILITY))
+       if (m_ptr->invulner && randint0(PENETRATE_INVULNERABILITY))
        {
                if (seen)
                {
@@ -237,7 +237,7 @@ msg_format("%^s
                if(dam > 0)
                {
                        dam /= 100;
-                       if((dam == 0) && (randint(3) == 1)) dam = 1;
+                       if((dam == 0) && one_in_(3)) dam = 1;
                }
                if (dam==0)
                {
@@ -340,7 +340,7 @@ msg_format("%^s
        /* Mega-Hack -- Pain cancels fear */
        if (m_ptr->monfear && (dam > 0))
        {
-               int tmp = randint(dam / 4);
+               int tmp = randint1(dam / 4);
 
                /* Cure a little fear */
                if (tmp < m_ptr->monfear)
@@ -372,14 +372,14 @@ msg_format("%^s
                * Run (sometimes) if at 10% or less of max hit points,
                * or (usually) when hit for half its current hit points
                 */
-               if (((percentage <= 10) && (rand_int(10) < percentage)) ||
-                       ((dam >= m_ptr->hp) && (rand_int(100) < 80)))
+               if (((percentage <= 10) && (randint0(10) < percentage)) ||
+                       ((dam >= m_ptr->hp) && (randint0(100) < 80)))
                {
                        /* Hack -- note fear */
                        (*fear) = TRUE;
 
                        /* XXX XXX XXX Hack -- Add some timed fear */
-                       m_ptr->monfear += (randint(10) +
+                       m_ptr->monfear += (randint1(10) +
                                (((dam >= m_ptr->hp) && (percentage > 7)) ?
                                20 : ((11 - percentage) * 5)));
                }
@@ -500,6 +500,86 @@ static int mon_will_run(int m_idx)
 
 
 /*
+ * Search spell castable grid
+ */
+static bool get_moves_aux2(int m_idx, int *yp, int *xp)
+{
+       int i, y, x, y1, x1, best = 999;
+
+       cave_type *c_ptr;
+       bool can_open_door = FALSE;
+       int now_cost;
+
+       monster_type *m_ptr = &m_list[m_idx];
+       monster_race *r_ptr = &r_info[m_ptr->r_idx];
+
+       /* Monster location */
+       y1 = m_ptr->fy;
+       x1 = m_ptr->fx;
+
+       /* Monster can already cast spell to player */
+       if (projectable(y1, x1, py, px)) return (FALSE);
+
+       /* Set current grid cost */
+       now_cost = cave[y1][x1].cost;
+       if (now_cost == 0) now_cost = 999;
+
+       /* Can monster bash or open doors? */
+       if (r_ptr->flags2 & (RF2_BASH_DOOR | RF2_OPEN_DOOR))
+       {
+               can_open_door = TRUE;
+       }
+
+       /* Check nearby grids, diagonals first */
+       for (i = 7; i >= 0; i--)
+       {
+               int cost;
+
+               /* Get the location */
+               y = y1 + ddy_ddd[i];
+               x = x1 + ddx_ddd[i];
+
+               /* Ignore locations off of edge */
+               if (!in_bounds2(y, x)) continue;
+
+               /* Simply move to player */
+               if ((y == py) && (x == px)) return (FALSE);
+
+               c_ptr = &cave[y][x];
+
+               cost = c_ptr->cost;
+
+               /* Monster cannot kill or pass walls */
+               if (!(((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != p_ptr->riding) || p_ptr->pass_wall)) || (r_ptr->flags2 & RF2_KILL_WALL)))
+               {
+                       if (cost == 0) continue;
+                       if (!can_open_door && (c_ptr->feat >= FEAT_DOOR_HEAD && c_ptr->feat <= FEAT_SECRET)) continue;
+               }
+
+               /* Hack -- for kill or pass wall monster.. */
+               if (cost == 0) cost = 998;
+
+               if (now_cost < cost) continue;
+
+               if (!projectable(y, x, py, px)) continue;
+
+               /* Accept louder sounds */
+               if (best < cost) continue;
+               best = cost;
+
+               (*yp) = y1 + ddy_ddd[i];
+               (*xp) = x1 + ddx_ddd[i];
+       }
+
+       /* No legal move (?) */
+       if (best == 999) return (FALSE);
+
+       /* Success */
+       return (TRUE);
+}
+
+
+/*
  * Choose the "best" direction for "flowing"
  *
  * Note that ghosts and rock-eaters are never allowed to "flow",
@@ -535,6 +615,15 @@ static bool get_moves_aux(int m_idx, int *yp, int *xp)
        /* Monster flowing disabled */
        if (stupid_monsters) return (FALSE);
 
+       /* Can monster cast attack spell? */
+       if (r_ptr->flags4 & (RF4_ATTACK_MASK) ||
+           r_ptr->flags5 & (RF5_ATTACK_MASK) ||
+           r_ptr->flags6 & (RF6_ATTACK_MASK))
+       {
+               /* Can move spell castable grid? */
+               if (get_moves_aux2(m_idx, yp, xp)) return (TRUE);
+       }
+
        /* Monster can go through rocks */
        if ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != p_ptr->riding) || (p_ptr->pass_wall))) return (FALSE);
        if (r_ptr->flags2 & RF2_KILL_WALL) return (FALSE);
@@ -1343,7 +1432,7 @@ static int check_hit2(int power, int level, int ac, int stun)
        int i, k;
 
        /* Percentile dice */
-       k = rand_int(100);
+       k = randint0(100);
 
        if (stun && one_in_(2)) return FALSE;
 
@@ -1354,7 +1443,7 @@ static int check_hit2(int power, int level, int ac, int stun)
        i = (power + (level * 3));
 
        /* Power and Level compete against Armor */
-       if ((i > 0) && (randint(i) > ((ac * 3) / 4))) return (TRUE);
+       if ((i > 0) && (randint1(i) > ((ac * 3) / 4))) return (TRUE);
 
        /* Assume miss */
        return (FALSE);
@@ -1453,6 +1542,8 @@ static bool monst_attack_monst(int m_idx, int t_idx)
                        /* break; */
                }
 
+               if (method == RBM_SHOOT) continue;
+
                /* Extract the attack "power" */
                switch (effect)
                {
@@ -1793,7 +1884,7 @@ act = "%s
                        {
                                if (do_silly_attack)
                                {
-                                       act = silly_attacks[rand_int(MAX_SILLY_ATTACK)];
+                                       act = silly_attacks[randint0(MAX_SILLY_ATTACK)];
                                }
                                strfmt(temp, act, t_name);
 #ifdef JP
@@ -1827,7 +1918,7 @@ act = "%s
 
                        case RBE_SUPERHURT:
                                {
-                                       if ((randint(rlev*2+250) > (ac+200)) || one_in_(13)) {
+                                       if ((randint1(rlev*2+250) > (ac+200)) || one_in_(13)) {
                                                int tmp_damage = damage-(damage*((ac < 150) ? ac : 150)/250);
                                                damage = MAX(damage, tmp_damage*2);
                                                break;
@@ -1865,7 +1956,7 @@ act = "%s
                        case RBE_EAT_GOLD:
                                {
                                        pt = damage = 0;
-                                       if (randint(2) == 1) blinked = TRUE;
+                                       if (one_in_(2)) blinked = TRUE;
                                        break;
                                }
 
@@ -2258,17 +2349,17 @@ static void process_monster(int m_idx)
                if (p_ptr->aggravate) tmp /= 2;
                if (r_ptr->level > (p_ptr->lev*p_ptr->lev/20+10)) tmp /= 3;
                /* Low-level monsters will find it difficult to locate the player. */
-               if (rand_int(tmp) > (r_ptr->level+20)) aware = FALSE;
+               if (randint0(tmp) > (r_ptr->level+20)) aware = FALSE;
        }
 
        /* Quantum monsters are odd */
        if (r_ptr->flags2 & (RF2_QUANTUM))
        {
                /* Sometimes skip move */
-               if (!rand_int(2)) return;
+               if (!randint0(2)) return;
 
                /* Sometimes die */
-               if (!rand_int((m_idx % 100) + 10) && !(r_ptr->flags1 & RF1_QUESTOR))
+               if (!randint0((m_idx % 100) + 10) && !(r_ptr->flags1 & RF1_QUESTOR))
                {
                        bool sad = FALSE;
 
@@ -2398,7 +2489,7 @@ msg_print("
                u32b notice = 0;
 
                /* Hack -- handle non-aggravation */
-               if (!p_ptr->aggravate) notice = rand_int(1024);
+               if (!p_ptr->aggravate) notice = randint0(1024);
 
                /* Nightmare monsters are more alert */
                if (ironman_nightmare) notice /= 2;
@@ -2481,7 +2572,7 @@ msg_format("%^s
                int d = 1;
 
                /* Make a "saving throw" against stun */
-               if (rand_int(10000) <= r_ptr->level * r_ptr->level)
+               if (randint0(10000) <= r_ptr->level * r_ptr->level)
                {
                        /* Recover fully */
                        d = m_ptr->stunned;
@@ -2529,7 +2620,7 @@ msg_format("%^s
        if (m_ptr->confused)
        {
                /* Amount of "boldness" */
-               int d = randint(r_ptr->level / 20 + 1);
+               int d = randint1(r_ptr->level / 20 + 1);
 
                /* Still confused */
                if (m_ptr->confused > d)
@@ -2679,7 +2770,7 @@ msg_format("%^s
        if (m_ptr->monfear)
        {
                /* Amount of "boldness" */
-               int d = randint(r_ptr->level / 20 + 1);
+               int d = randint1(r_ptr->level / 20 + 1);
 
                /* Still afraid */
                if (m_ptr->monfear > d)
@@ -2739,7 +2830,7 @@ msg_format("%^s
                }
 
                /* Hack -- multiply slower in crowded areas */
-               if ((k < 4) && (!k || !rand_int(k * MON_MULT_ADJ)))
+               if ((k < 4) && (!k || !randint0(k * MON_MULT_ADJ)))
                {
                        /* Try to multiply */
                        if (multiply_monster(m_idx, FALSE, is_friendly(m_ptr), is_pet(m_ptr)))
@@ -2761,7 +2852,7 @@ msg_format("%^s
        {
                /* Hack! "Cyber" monster makes noise... */
                if (m_ptr->r_idx == MON_CYBER &&
-                   (randint(CYBERNOISE) == 1) &&
+                   one_in_(CYBERNOISE) &&
                    !m_ptr->ml && (m_ptr->cdis <= MAX_SIGHT))
                {
                        if (disturb_minor) disturb(FALSE, FALSE);
@@ -2775,7 +2866,7 @@ msg_print("
 
                /* Some monsters can speak */
                if ((r_ptr->flags2 & RF2_CAN_SPEAK) && aware &&
-                       (randint(SPEAK_CHANCE) == 1) &&
+                       one_in_(SPEAK_CHANCE) &&
                        player_has_los_bold(oy, ox))
                {
                        char m_name[80];
@@ -2863,7 +2954,7 @@ msg_format("%^s%s", m_name, monmessage);
        /* 75% random movement */
        else if ((r_ptr->flags1 & RF1_RAND_50) &&
                                (r_ptr->flags1 & RF1_RAND_25) &&
-                (rand_int(100) < 75))
+                (randint0(100) < 75))
        {
                /* Memorize flags */
                if (m_ptr->ml) r_ptr->r_flags1 |= (RF1_RAND_50);
@@ -2875,7 +2966,7 @@ msg_format("%^s%s", m_name, monmessage);
 
        /* 50% random movement */
        else if ((r_ptr->flags1 & RF1_RAND_50) &&
-                               (rand_int(100) < 50))
+                               (randint0(100) < 50))
        {
                /* Memorize flags */
                if (m_ptr->ml) r_ptr->r_flags1 |= (RF1_RAND_50);
@@ -2886,7 +2977,7 @@ msg_format("%^s%s", m_name, monmessage);
 
        /* 25% random movement */
        else if ((r_ptr->flags1 & RF1_RAND_25) &&
-                               (rand_int(100) < 25))
+                               (randint0(100) < 25))
        {
                /* Memorize flags */
                if (m_ptr->ml) r_ptr->r_flags1 |= RF1_RAND_25;
@@ -2990,7 +3081,7 @@ msg_format("%^s%s", m_name, monmessage);
                d = mm[i];
 
                /* Hack -- allow "randomized" motion */
-               if (d == 5) d = ddd[rand_int(8)];
+               if (d == 5) d = ddd[randint0(8)];
 
                /* Get the destination */
                ny = oy + ddy[d];
@@ -3063,7 +3154,7 @@ msg_format("%^s%s", m_name, monmessage);
                        /* Monster destroyed a wall */
                        did_kill_wall = TRUE;
 
-                       if (randint(GRINDNOISE) == 1)
+                       if (one_in_(GRINDNOISE))
                        {
 #ifdef JP
 msg_print("¥®¥·¥®¥·¤¤¤¦²»¤¬Ê¹¤³¤¨¤ë¡£");
@@ -3077,7 +3168,7 @@ msg_print("
                        c_ptr->info &= ~(CAVE_MARK);
 
                        /* Notice */
-                       c_ptr->feat = floor_type[rand_int(100)];
+                       c_ptr->feat = floor_type[randint0(100)];
                        c_ptr->info &= ~(CAVE_MASK);
                        c_ptr->info |= CAVE_FLOOR;
 
@@ -3122,7 +3213,7 @@ msg_print("
                                        k = ((c_ptr->feat - FEAT_DOOR_HEAD) & 0x07);
 
                                        /* Try to unlock it XXX XXX XXX */
-                                       if (rand_int(m_ptr->hp / 10) > k)
+                                       if (randint0(m_ptr->hp / 10) > k)
                                        {
                                                /* Unlock the door */
                                                cave_set_feat(ny, nx, FEAT_DOOR_HEAD + 0x00);
@@ -3143,7 +3234,7 @@ msg_print("
                                k = ((c_ptr->feat - FEAT_DOOR_HEAD) & 0x07);
 
                                /* Attempt to Bash XXX XXX XXX */
-                               if (rand_int(m_ptr->hp / 10) > k)
+                               if (randint0(m_ptr->hp / 10) > k)
                                {
                                        /* Message */
 #ifdef JP
@@ -3169,7 +3260,7 @@ msg_print("
                        if (did_open_door || did_bash_door)
                        {
                                /* Break down the door */
-                               if (did_bash_door && (rand_int(100) < 50))
+                               if (did_bash_door && (randint0(100) < 50))
                                {
                                        cave_set_feat(ny, nx, FEAT_BROKEN);
                                }
@@ -3193,7 +3284,7 @@ msg_print("
                        do_move = FALSE;
 
                        /* Break the ward */
-                       if (!is_pet(m_ptr) && (randint(BREAK_GLYPH) < r_ptr->level))
+                       if (!is_pet(m_ptr) && (randint1(BREAK_GLYPH) < r_ptr->level))
                        {
                                /* Describe observable breakage */
                                if (c_ptr->info & CAVE_MARK)
@@ -3210,7 +3301,7 @@ msg_print("
                                c_ptr->info &= ~(CAVE_MARK);
 
                                /* Break the rune */
-                               c_ptr->feat = floor_type[rand_int(100)];
+                               c_ptr->feat = floor_type[randint0(100)];
                                c_ptr->info &= ~(CAVE_MASK);
                                c_ptr->info |= CAVE_FLOOR;
 
@@ -3231,7 +3322,7 @@ msg_print("
                        if (!is_pet(m_ptr))
                        {
                                /* Break the ward */
-                               if (randint(BREAK_MINOR_GLYPH) > r_ptr->level)
+                               if (randint1(BREAK_MINOR_GLYPH) > r_ptr->level)
                                {
                                        /* Describe observable breakage */
                                        if (c_ptr->info & CAVE_MARK)
@@ -3258,7 +3349,7 @@ msg_print("
                                c_ptr->info &= ~(CAVE_MARK);
 
                                /* Break the rune */
-                               c_ptr->feat = floor_type[rand_int(100)];
+                               c_ptr->feat = floor_type[randint0(100)];
                                c_ptr->info &= ~(CAVE_MASK);
                                c_ptr->info |= CAVE_FLOOR;
                                note_spot(ny, nx);
@@ -3845,6 +3936,7 @@ void process_monsters(void)
                        test = TRUE;
                }
 
+#if 0 /* (cave[py][px].when == cave[fy][fx].when) is always FALSE... */
                /* Hack -- Monsters can "smell" the player from far away */
                /* Note that most monsters have "aaf" of "20" or so */
                else if (!stupid_monsters && !(m_ptr->mflag2 & MFLAG_NOFLOW) &&
@@ -3856,6 +3948,7 @@ void process_monsters(void)
                        /* We can "smell" the player */
                        test = TRUE;
                }
+#endif
                else if (m_ptr->target_y) test = TRUE;
 
                /* Do nothing */
@@ -3881,7 +3974,7 @@ void process_monsters(void)
                e = extract_energy[speed];
 
                /* Give this monster some energy */
-               if(rand_int(60) < e)
+               if(randint0(60) < e)
                m_ptr->energy += gain_energy();
 
 
@@ -3945,12 +4038,14 @@ void process_monsters(void)
 
 bool process_the_world(int num, int who, bool vs_player)
 {
+       monster_type *m_ptr = &m_list[hack_m_idx];  /* the world monster */
+
        if(world_monster) return (FALSE);
 
        if(vs_player)
        {
                char m_name[80];
-               monster_desc(m_name, &m_list[hack_m_idx], 0);
+               monster_desc(m_name, m_ptr, 0);
 
                if (who == 1)
 #ifdef JP
@@ -3975,10 +4070,10 @@ bool process_the_world(int num, int who, bool vs_player)
 
        while(num--)
        {
-               if(!m_list[hack_m_idx].r_idx) return (TRUE);
+               if(!m_ptr->r_idx) break;
                process_monster(hack_m_idx);
 
-               reset_target(&m_list[hack_m_idx]);
+               reset_target(m_ptr);
 
                /* Notice stuff */
                if (p_ptr->notice) notice_stuff();
@@ -4006,7 +4101,7 @@ bool process_the_world(int num, int who, bool vs_player)
        p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
 
        world_monster = FALSE;
-       if (vs_player || los(py, px, m_list[hack_m_idx].fy, m_list[hack_m_idx].fx))
+       if (vs_player || los(py, px, m_ptr->fy, m_ptr->fx))
        {
 #ifdef JP
                msg_print("¡Ö»þ¤ÏÆ°¤­¤À¤¹¡Ä¡×");
@@ -4074,7 +4169,7 @@ void monster_gain_exp(int m_idx, int s_idx)
                if (!(r_ptr->flags1 & RF1_UNIQUE) && !p_ptr->inside_arena)
                {
                        /* Allow some small variation per monster */
-                 if(rand_int(4) == 1){
+                 if(one_in_(4)){
                        i = extract_energy[r_ptr->speed] / 3;
                        if (i) m_ptr->mspeed += rand_spread(0, i);
                  }