Angband
Functions
mon-make.h File Reference

Structures and functions for monster creation / deletion. More...

#include "monster.h"

Go to the source code of this file.

Functions

void delete_monster_idx (int m_idx)
 

Deleting of monsters and monster list handling

More...
 
void delete_monster (struct loc grid)
 Deletes the monster, if any, at the given location. More...
 
void monster_index_move (int i1, int i2)
 Move a monster from index i1 to index i2 in the monster list. More...
 
void compact_monsters (int num_to_compact)
 Compacts and reorders the monster list. More...
 
void wipe_mon_list (struct chunk *c, struct player *p)
 Deletes all the monsters when the player leaves the level. More...
 
s16b mon_pop (struct chunk *c)
 

Monster creation utilities: Getting a new monster index Creating objects for monsters to carry or mimic

Calculating hitpoints

More...
 
void get_mon_num_prep (bool(*get_mon_num_hook)(struct monster_race *race))
 Apply a monster restriction function to the monster allocation table. More...
 
struct monster_raceget_mon_num (int level)
 Chooses a monster race that seems appropriate to the given level. More...
 
int mon_create_drop_count (const struct monster_race *race, bool maximize)
 Return the number of things dropped by a monster. More...
 
void mon_create_mimicked_object (struct chunk *c, struct monster *mon, int index)
 Creates the onbject a mimic is imitating. More...
 
s16b place_monster (struct chunk *c, struct loc grid, struct monster *mon, byte origin)
 

Placement of a single monster

These are the functions that actually put the monster into the world

More...
 
int mon_hp (const struct monster_race *race, aspect hp_aspect)
 Calculates hp for a monster. More...
 
bool place_new_monster (struct chunk *c, struct loc grid, struct monster_race *race, bool sleep, bool group_ok, struct monster_group_info group_info, byte origin)
 Attempts to place a monster of the given race at the given location. More...
 
bool pick_and_place_monster (struct chunk *c, struct loc grid, int depth, bool sleep, bool group_okay, byte origin)
 Picks a monster race, makes a new monster of that race, then attempts to place it in the dungeon. More...
 
bool pick_and_place_distant_monster (struct chunk *c, struct player *p, int dis, bool sleep, int depth)
 Picks a monster race, makes a new monster of that race, then attempts to place it in the dungeon at least dis away from the player. More...
 

Detailed Description

Structures and functions for monster creation / deletion.

Copyright (c) 1997-2007 Ben Harrison, James E. Wilson, Robert A. Koeneke

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

◆ compact_monsters()

void compact_monsters ( int  num_to_compact)

Compacts and reorders the monster list.

This function can be very dangerous, use with caution!

When num_to_compact is 0, we just reorder the monsters into a more compact order, eliminating any "holes" left by dead monsters. If num_to_compact is positive, then we delete at least that many monsters and then reorder. We try not to delete monsters that are high level or close to the player. Each time we make a full pass through the monster list, if we haven't deleted enough monsters, we relax our bounds a little to accept monsters of a slightly higher level, and monsters slightly closer to the player.

References cave, cave_monster(), cave_monster_max(), monster::cdis, delete_monster(), monster_race::flags, monster::grid, monster_race::level, chunk::mon_max, monster_index_move(), msg, monster::race, randint0, and rf_has.

Referenced by prepare_next_level(), process_world(), and wr_dungeon().

◆ delete_monster()

void delete_monster ( struct loc  grid)

Deletes the monster, if any, at the given location.

References cave, delete_monster_idx(), square(), and square_in_bounds().

Referenced by compact_monsters(), effect_handler_DESTRUCTION(), effect_handler_EARTHQUAKE(), and monster_turn_try_push().

◆ delete_monster_idx()

void delete_monster_idx ( int  m_idx)

◆ get_mon_num()

struct monster_race* get_mon_num ( int  level)

Chooses a monster race that seems appropriate to the given level.

This function uses the "prob2" field of the monster allocation table, and various local information, to calculate the "prob3" field of the same table, which is then used to choose an appropriate monster, in a relatively efficient manner.

Note that town monsters will only be created in the town, and "normal" monsters will never be created in the town, unless the level is modified, for example, by polymorph or summoning.

There is a small chance (1/25) of boosting the given depth by a small amount (up to four levels), except in the town.

It is (slightly) more likely to acquire a monster of the given level than one of a lower level. This is done by choosing several monsters appropriate to the given level and keeping the deepest one.

Note that if no monsters are appropriate, then this function will fail, and return zero, but this should almost never happen.

References alloc_race_size, alloc_race_table, monster_race::cur_num, player::depth, monster_race::flags, get_mon_race_aux(), i, alloc_entry::index, monster_race::level, monster_race::max_num, MIN, one_in_, angband_constants::ood_monster_amount, angband_constants::ood_monster_chance, p, alloc_entry::prob3, r_info, randint0, rf_has, and z_info.

Referenced by build_nest(), build_pit(), get_chamber_monsters(), get_vault_monsters(), monster_change_shape(), pick_and_place_monster(), place_new_monster(), poly_race(), select_shape(), spread_monsters(), and summon_specific().

◆ get_mon_num_prep()

void get_mon_num_prep ( bool(*)(struct monster_race *race)  get_mon_num_hook)

Apply a monster restriction function to the monster allocation table.

This way, we can use get_mon_num() to get a level-appropriate monster that satisfies certain conditions (such as belonging to a particular monster family).

References alloc_race_size, i, alloc_entry::index, alloc_entry::prob1, alloc_entry::prob2, and r_info.

Referenced by build_nest(), build_pit(), get_vault_monsters(), mon_restrict(), monster_change_shape(), place_new_monster(), select_shape(), and summon_specific().

◆ mon_create_drop_count()

int mon_create_drop_count ( const struct monster_race race,
bool  maximize 
)

Return the number of things dropped by a monster.

Parameters
raceis the monster race.
maximizeshould be set to false for a random number, true to find out the maximum count.

References monster_race::flags, rand_range(), randint0, and rf_has.

Referenced by lore_append_drop(), and mon_create_drop().

◆ mon_create_mimicked_object()

void mon_create_mimicked_object ( struct chunk c,
struct monster mon,
int  index 
)

◆ mon_hp()

int mon_hp ( const struct monster_race race,
aspect  hp_aspect 
)

Calculates hp for a monster.

This function assumes that the Rand_normal function has limits of +/- 4x std_dev. If that changes, this function will become inaccurate.

Parameters
raceis the race of the monster in question.
hp_aspectis the hp calc we want (min, max, avg, random).

References AVERAGE, monster_race::avg_hp, EXTREMIFY, MAXIMISE, MINIMISE, Rand_normal(), and RANDOMISE.

Referenced by place_new_monster_one().

◆ mon_pop()

s16b mon_pop ( struct chunk c)


Monster creation utilities: Getting a new monster index Creating objects for monsters to carry or mimic

Calculating hitpoints

Returns the index of a "free" monster, or 0 if no slot is available.

This routine should almost never fail, but it can happen. The calling code must check for and handle a 0 return.

References cave_monster(), cave_monster_max(), character_dungeon, angband_constants::level_monster_max, chunk::mon_cnt, chunk::mon_max, msg, monster::race, and z_info.

Referenced by chunk_copy(), and place_monster().

◆ monster_index_move()

void monster_index_move ( int  i1,
int  i2 
)

◆ pick_and_place_distant_monster()

bool pick_and_place_distant_monster ( struct chunk c,
struct player p,
int  dis,
bool  sleep,
int  depth 
)

Picks a monster race, makes a new monster of that race, then attempts to place it in the dungeon at least dis away from the player.

The monster race chosen will be appropriate for dungeon level equal to depth.

If sleep is true, the monster is placed with its default sleep value, which is given in monster.txt.

Returns true if we successfully place a monster.

References character_dungeon, distance(), player::grid, chunk::height, loc(), msg, OPT, pick_and_place_monster(), randint0, square_isempty(), square_ismon_restrict(), and chunk::width.

Referenced by cavern_gen(), classic_gen(), gauntlet_gen(), hard_centre_gen(), labyrinth_gen(), lair_gen(), modified_gen(), moria_gen(), process_world(), and town_gen().

◆ pick_and_place_monster()

bool pick_and_place_monster ( struct chunk c,
struct loc  grid,
int  depth,
bool  sleep,
bool  group_okay,
byte  origin 
)

Picks a monster race, makes a new monster of that race, then attempts to place it in the dungeon.

The monster race chosen will be appropriate for dungeon level equal to depth.

If sleep is true, the monster is placed with its default sleep value, which is given in monster.txt.

If group_okay is true, we allow the placing of a group, if the chosen monster appears with friends or an escort.

origin is the item origin to use for any monster drops (e.g. ORIGIN_DROP, ORIGIN_DROP_PIT, etc.)

Returns true if we successfully place a monster.

References get_mon_num(), and place_new_monster().

Referenced by build_vault(), get_chamber_monsters(), get_vault_monsters(), pick_and_place_distant_monster(), spread_monsters(), and vault_monsters().

◆ place_monster()

s16b place_monster ( struct chunk c,
struct loc  grid,
struct monster mon,
byte  origin 
)


Placement of a single monster

These are the functions that actually put the monster into the world

Attempts to place a copy of the given monster at the given position in the dungeon.

All of the monster placement routines eventually call this function. This is what actually puts the monster in the dungeon (i.e., it notifies the cave and sets the monster's position). The dungeon loading code also calls this function directly.

origin is the item origin to use for any monster drops (e.g. ORIGIN_DROP, ORIGIN_DROP_PIT, etc.) The dungeon loading code calls this with origin = 0, which prevents the monster's drops from being generated again.

Returns the m_idx of the newly copied monster, or 0 if the placement fails.

References cave_monster(), monster_race::cur_num, monster_race::flags, monster::grid, monster::group_info, monster::midx, monster_race::mimic_kinds, chunk::mon_cnt, mon_create_drop(), mon_create_mimicked_object(), chunk::mon_max, mon_pop(), monster_group_assign(), chunk::num_repro, monster::race, rf_has, square_in_bounds(), square_monster(), square_set_mon(), update_mon(), and void().

Referenced by place_new_monster_one(), and rd_monsters_aux().

◆ place_new_monster()

bool place_new_monster ( struct chunk c,
struct loc  grid,
struct monster_race race,
bool  sleep,
bool  group_ok,
struct monster_group_info  group_info,
byte  origin 
)

Attempts to place a monster of the given race at the given location.

Note that certain monsters are placed with a large group of identical or similar monsters. However, if group_okay is false, then such monsters are placed by themselves.

If sleep is true, the monster is placed with its default sleep value, which is given in monster.txt.

origin is the item origin to use for any monster drops (e.g. ORIGIN_DROP, ORIGIN_DROP_PIT, etc.)

References monster_friends_base::base, damroll(), monster_race::friends, monster_race::friends_base, get_mon_num(), get_mon_num_prep(), monster_group_info::index, monster_race::level, monster_group_index_new(), monster_friends::next, monster_friends_base::next, monster_friends::number_dice, monster_friends_base::number_dice, monster_friends::number_side, monster_friends_base::number_side, monster_friends::percent_chance, monster_friends_base::percent_chance, place_friends(), place_monster_base_okay(), place_new_monster_one(), monster_friends::race, randint0, monster_friends::role, monster_friends_base::role, and monster_group_info::role.

Referenced by build_nest(), build_pit(), cave_generate(), do_cmd_wiz_named(), multiply_monster(), pick_and_place_monster(), project_m_apply_side_effects(), and summon_specific().

◆ wipe_mon_list()

void wipe_mon_list ( struct chunk c,
struct player p 
)

Deletes all the monsters when the player leaves the level.

This is an efficient method of simulating multiple calls to the "delete_monster()" function, with no visual effects.

Note that we must delete the objects the monsters are carrying, but we do nothing with mimicked objects.

References object::artifact, cave_monster(), cave_monster_max(), artifact::created, monster_race::cur_num, monster::grid, health_track(), monster::held_obj, i, object::known, angband_constants::level_monster_max, chunk::mon_cnt, chunk::mon_max, monster_group_free(), chunk::monster_groups, object::next, chunk::num_repro, object_pile_free(), monster::race, square_set_mon(), target_set_monster(), player::upkeep, and z_info.

Referenced by cave_clear(), close_game(), and teardown_tests().