{
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;
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)
{
if(dam > 0)
{
dam /= 100;
- if((dam == 0) && (randint(3) == 1)) dam = 1;
+ if((dam == 0) && one_in_(3)) dam = 1;
}
if (dam==0)
{
/* 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)
* 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)));
}
/*
+ * 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",
/* 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);
int i, k;
/* Percentile dice */
- k = rand_int(100);
+ k = randint0(100);
if (stun && one_in_(2)) return FALSE;
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);
/* break; */
}
+ if (method == RBM_SHOOT) continue;
+
/* Extract the attack "power" */
switch (effect)
{
{
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
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;
case RBE_EAT_GOLD:
{
pt = damage = 0;
- if (randint(2) == 1) blinked = TRUE;
+ if (one_in_(2)) blinked = TRUE;
break;
}
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;
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;
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;
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)
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)
}
/* 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)))
{
/* 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);
/* 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];
/* 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);
/* 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);
/* 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;
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];
/* Monster destroyed a wall */
did_kill_wall = TRUE;
- if (randint(GRINDNOISE) == 1)
+ if (one_in_(GRINDNOISE))
{
#ifdef JP
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;
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);
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
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);
}
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)
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;
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)
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);
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) &&
/* We can "smell" the player */
test = TRUE;
}
+#endif
else if (m_ptr->target_y) test = TRUE;
/* Do nothing */
e = extract_energy[speed];
/* Give this monster some energy */
- if(rand_int(60) < e)
+ if(randint0(60) < e)
m_ptr->energy += gain_energy();
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
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();
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("¡Ö»þ¤ÏÆ°¤¤À¤¹¡Ä¡×");
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);
}