Angband
Functions | Variables
mon-move.c File Reference

Monster movement. More...

#include "angband.h"
#include "cave.h"
#include "game-world.h"
#include "init.h"
#include "monster.h"
#include "mon-attack.h"
#include "mon-desc.h"
#include "mon-lore.h"
#include "mon-make.h"
#include "mon-spell.h"
#include "mon-util.h"
#include "obj-desc.h"
#include "obj-ignore.h"
#include "obj-pile.h"
#include "obj-slays.h"
#include "obj-tval.h"
#include "obj-util.h"
#include "player-util.h"
#include "project.h"
#include "trap.h"

Functions

static void find_range (monster_type *m_ptr)
 Calculate minimum and desired combat ranges.
bool multiply_monster (const monster_type *m_ptr)
 Lets the given monster attempt to reproduce.
static bool near_permwall (const monster_type *m_ptr, struct chunk *c)
static bool get_moves_flow (struct chunk *c, struct monster *m_ptr)
static bool get_moves_fear (struct chunk *c, struct monster *m_ptr)
static bool find_safety (struct chunk *c, struct monster *m_ptr)
static bool find_hiding (struct monster *m_ptr)
static int choose_direction (int dy, int dx)
 Choose the basic direction of movement, and whether to bias left or right if the main direction is blocked.
static bool get_moves (struct chunk *c, struct monster *m_ptr, int *dir)
static bool monster_can_flow (struct chunk *c, struct monster *mon)
static bool monster_check_active (struct chunk *c, struct monster *mon)
 Determine whether a monster is active or passive.
static bool process_monster_timed (struct chunk *c, struct monster *m_ptr)
 Process a monster's timed effects, e.g.
static bool process_monster_multiply (struct chunk *c, struct monster *m_ptr)
 Attempt to reproduce, if possible.
static bool process_monster_should_stagger (struct monster *m_ptr)
 Check if a monster should stagger or not.
static bool process_monster_can_move (struct chunk *c, struct monster *m_ptr, const char *m_name, int nx, int ny, bool *did_something)
 Work out if a monster can move through the grid, if necessary bashing down doors in the way.
static bool process_monster_glyph (struct chunk *c, struct monster *m_ptr, int nx, int ny)
 Try to break a glyph.
static int compare_monsters (const struct monster *m_ptr, const struct monster *n_ptr)
static bool process_monster_try_push (struct chunk *c, struct monster *m_ptr, const char *m_name, int nx, int ny)
 Try to push past / kill another monster.
void process_monster_grab_objects (struct chunk *c, struct monster *m_ptr, const char *m_name, int nx, int ny)
 Grab all objects from the grid.
static void process_monster (struct chunk *c, struct monster *m_ptr)
static void regen_monster (monster_type *m_ptr)
 Monster regeneration of HPs.
void process_monsters (struct chunk *c, int minimum_energy)
 Process all the "live" monsters, once per game turn.
void reset_monsters (void)
 Clear 'moved' status from all monsters.

Variables

static byte side_dirs [20][8]
 Given a central direction at position [dir #][0], return a series of directions radiating out on both sides from the central direction all the way back to its rear.
static const int d_off_y_0 []
static const int d_off_x_0 []
static const int d_off_y_1 []
static const int d_off_x_1 []
static const int d_off_y_2 []
static const int d_off_x_2 []
static const int d_off_y_3 []
static const int d_off_x_3 []
static const int d_off_y_4 []
static const int d_off_x_4 []
static const int d_off_y_5 []
static const int d_off_x_5 []
static const int d_off_y_6 []
static const int d_off_x_6 []
static const int d_off_y_7 []
static const int d_off_x_7 []
static const int d_off_y_8 []
static const int d_off_x_8 []
static const int d_off_y_9 []
static const int d_off_x_9 []
static const intdist_offsets_y [10]
static const intdist_offsets_x [10]

Detailed Description

Monster movement.

Monster AI affecting movement and spells, process a monster (with spells and actions of all kinds, reproduction, effects of any terrain on monster movement, picking up and destroying objects), process all monsters.

Copyright (c) 1997 Ben Harrison, David Reeve Sward, Keldon Jones.

This work is free software; you can redistribute it and/or modify it under the terms of either:

a) the GNU General Public License as published by the Free Software Foundation, version 2, or

b) the "Angband licence": This software may be copied and distributed for educational, research, and not for profit purposes provided that this copyright and statement are included in all such copies. Other copyrights may also apply.

Function Documentation

static int choose_direction ( int  dy,
int  dx 
)
static

Choose the basic direction of movement, and whether to bias left or right if the main direction is blocked.

Note that this direction is intended as an index into the side_dirs array.

References ABS, and turn.

Referenced by get_moves().

static int compare_monsters ( const struct monster m_ptr,
const struct monster n_ptr 
)
static
static bool find_hiding ( struct monster m_ptr)
static
static void find_range ( monster_type m_ptr)
static
static bool find_safety ( struct chunk c,
struct monster m_ptr 
)
static
static bool get_moves ( struct chunk c,
struct monster m_ptr,
int dir 
)
static
static bool get_moves_fear ( struct chunk c,
struct monster m_ptr 
)
static
static bool get_moves_flow ( struct chunk c,
struct monster m_ptr 
)
static
static bool monster_can_flow ( struct chunk c,
struct monster mon 
)
static
static bool monster_check_active ( struct chunk c,
struct monster mon 
)
static
bool multiply_monster ( const monster_type m_ptr)

Lets the given monster attempt to reproduce.

Note that "reproduction" REQUIRES empty space.

Returns TRUE if the monster successfully reproduced.

References cave, FALSE, monster::fx, monster::fy, i, place_new_monster(), monster::race, scatter(), square_isempty(), and TRUE.

Referenced by process_monster_multiply(), and project_monster_handler_OLD_CLONE().

static bool near_permwall ( const monster_type m_ptr,
struct chunk c 
)
static
static void process_monster ( struct chunk c,
struct monster m_ptr 
)
static
static bool process_monster_can_move ( struct chunk c,
struct monster m_ptr,
const char *  m_name,
int  nx,
int  ny,
bool did_something 
)
static
static bool process_monster_glyph ( struct chunk c,
struct monster m_ptr,
int  nx,
int  ny 
)
static
void process_monster_grab_objects ( struct chunk c,
struct monster m_ptr,
const char *  m_name,
int  nx,
int  ny 
)
static bool process_monster_multiply ( struct chunk c,
struct monster m_ptr 
)
static
static bool process_monster_should_stagger ( struct monster m_ptr)
static

Check if a monster should stagger or not.

Always stagger when confused, but also deal with random movement for RAND_25 and _50 monsters.

References monster_lore::flags, monster_race::flags, get_lore(), monster::m_timed, monster::mflag, mflag_has, monster::race, randint0, rf_has, rf_on, and TRUE.

Referenced by process_monster().

static bool process_monster_timed ( struct chunk c,
struct monster m_ptr 
)
static
static bool process_monster_try_push ( struct chunk c,
struct monster m_ptr,
const char *  m_name,
int  nx,
int  ny 
)
static
void process_monsters ( struct chunk c,
int  minimum_energy 
)

Process all the "live" monsters, once per game turn.

During each game turn, we scan through the list of all the "live" monsters, (backwards, so we can excise any "freshly dead" monsters), energizing each monster, and allowing fully energized monsters to move, attack, pass, etc.

This function and its children are responsible for a considerable fraction of the processor time in normal situations, greater if the character is resting.

References cave, cave_monster(), cave_monster_max(), monster::energy, FALSE, player_upkeep::generate_level, i, player::is_dead, is_mimicking(), monster::m_timed, monster::mflag, mflag_has, mflag_on, chunk::mon_current, monster_check_active(), angband_constants::move_energy, monster::mspeed, process_monster(), process_monster_timed(), PU_MONSTERS, monster::race, regen_monster(), TRUE, turn, turn_energy(), player_upkeep::update, player::upkeep, and z_info.

Referenced by run_game_loop().

static void regen_monster ( monster_type m_ptr)
static
void reset_monsters ( void  )

Clear 'moved' status from all monsters.

Clear noise if appropriate.

References cave, cave_monster(), cave_monster_max(), i, monster::mflag, and mflag_off.

Referenced by run_game_loop().

Variable Documentation

const int d_off_x_0[]
static
Initial value:
{ 0 }
const int d_off_x_1[]
static
Initial value:
{ -1, 0, 1, -1, 1, -1, 0, 1, 0 }
const int d_off_x_2[]
static
Initial value:
{ -2, 2, -1, 0, 1, -2, 2, -2, 2, -1, 0, 1, 0 }
const int d_off_x_3[]
static
Initial value:
{ -3, 3, -2, 2, -1, 0, 1, -3, 3, -3, 3, -2, 2,
-1, 0, 1, 0 }
const int d_off_x_4[]
static
Initial value:
{ -4, 4, -3, 3, -2, -3, 2, 3, -1, 0, 1, -4, 4,
-4, 4, -3, 3, -2, -3, 2, 3, -1, 0, 1, 0 }
const int d_off_x_5[]
static
Initial value:
{ -5, 5, -4, 4, -4, 4, -2, -3, 2, 3, -1, 0, 1,
-5, 5, -5, 5, -4, 4, -4, 4, -2, -3, 2, 3, -1,
0, 1, 0 }
const int d_off_x_6[]
static
Initial value:
{ -6, 6, -5, 5, -5, 5, -4, 4, -2, -3, 2, 3, -1,
0, 1, -6, 6, -6, 6, -5, 5, -5, 5, -4, 4, -2,
-3, 2, 3, -1, 0, 1, 0 }
const int d_off_x_7[]
static
Initial value:
{ -7, 7, -6, 6, -6, 6, -5, 5, -4, -5, 4, 5, -2,
-3, 2, 3, -1, 0, 1, -7, 7, -7, 7, -6, 6, -6,
6, -5, 5, -4, -5, 4, 5, -2, -3, 2, 3, -1, 0,
1, 0 }
const int d_off_x_8[]
static
Initial value:
{ -8, 8, -7, 7, -7, 7, -6, 6, -6, 6, -4, -5, 4,
5, -2, -3, 2, 3, -1, 0, 1, -8, 8, -8, 8, -7,
7, -7, 7, -6, 6, -6, 6, -4, -5, 4, 5, -2, -3,
2, 3, -1, 0, 1, 0 }
const int d_off_x_9[]
static
Initial value:
{ -9, 9, -8, 8, -8, 8, -7, 7, -7, 7, -6, 6, -4,
-5, 4, 5, -2, -3, 2, 3, -1, 0, 1, -9, 9, -9,
9, -8, 8, -8, 8, -7, 7, -7, 7, -6, 6, -4, -5,
4, 5, -2, -3, 2, 3, -1, 0, 1, 0 }
const int d_off_y_0[]
static
Initial value:
{ 0 }
const int d_off_y_1[]
static
Initial value:
{ -1, -1, -1, 0, 0, 1, 1, 1, 0 }
const int d_off_y_2[]
static
Initial value:
{ -1, -1, -2, -2, -2, 0, 0, 1, 1, 2, 2, 2, 0 }
const int d_off_y_3[]
static
Initial value:
{ -1, -1, -2, -2, -3, -3, -3, 0, 0, 1, 1, 2, 2,
3, 3, 3, 0 }
const int d_off_y_4[]
static
Initial value:
{ -1, -1, -2, -2, -3, -3, -3, -3, -4, -4, -4, 0,
0, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 0 }
const int d_off_y_5[]
static
Initial value:
{ -1, -1, -2, -2, -3, -3, -4, -4, -4, -4, -5, -5,
-5, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5,
5, 0 }
const int d_off_y_6[]
static
Initial value:
{ -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -5, -5,
-6, -6, -6, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5,
5, 5, 6, 6, 6, 0 }
const int d_off_y_7[]
static
Initial value:
{ -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -5, -5,
-6, -6, -6, -6, -7, -7, -7, 0, 0, 1, 1, 2, 2, 3,
3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 0 }
const int d_off_y_8[]
static
Initial value:
{ -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6,
-6, -6, -7, -7, -7, -7, -8, -8, -8, 0, 0, 1, 1,
2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7,
8, 8, 8, 0 }
const int d_off_y_9[]
static
Initial value:
{ -1, -1, -2, -2, -3, -3, -4, -4, -5, -5, -6, -6,
-7, -7, -7, -7, -8, -8, -8, -8, -9, -9, -9, 0,
0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 7,
7, 8, 8, 8, 8, 9, 9, 9, 0 }
const int* dist_offsets_x[10]
static
const int* dist_offsets_y[10]
static
byte side_dirs[20][8]
static
Initial value:
{
{0, 0, 0, 0, 0, 0, 0, 0},
{1, 4, 2, 7, 3, 8, 6, 9},
{2, 1, 3, 4, 6, 7, 9, 8},
{3, 2, 6, 1, 9, 4, 8, 7},
{4, 7, 1, 8, 2, 9, 3, 6},
{5, 5, 5, 5, 5, 5, 5, 5},
{6, 3, 9, 2, 8, 1, 7, 4},
{7, 8, 4, 9, 1, 6, 2, 3},
{8, 9, 7, 6, 4, 3, 1, 2},
{9, 6, 8, 3, 7, 2, 4, 1},
{0, 0, 0, 0, 0, 0, 0, 0},
{1, 2, 4, 3, 7, 6, 8, 9},
{2, 3, 1, 6, 4, 9, 7, 8},
{3, 6, 2, 9, 1, 8, 4, 7},
{4, 1, 7, 2, 8, 3, 9, 6},
{5, 5, 5, 5, 5, 5, 5, 5},
{6, 9, 3, 8, 2, 7, 1, 4},
{7, 4, 8, 1, 9, 2, 6, 3},
{8, 7, 9, 4, 6, 1, 3, 2},
{9, 8, 6, 7, 3, 4, 2, 1}
}

Given a central direction at position [dir #][0], return a series of directions radiating out on both sides from the central direction all the way back to its rear.

Side directions come in pairs; for example, directions '1' and '3' flank direction '2'. The code should know which side to consider first. If the left, it must add 10 to the central direction to access the second part of the table.

Referenced by process_monster().