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)
 Deletes a monster by index. More...
 
void delete_monster (int y, int x)
 Deletes the monster, if any, at the given location. 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)
 Returns the index of a "free" monster, or 0 if no slot is available. 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, int y, int x, struct monster *mon, byte origin)
 Attempts to place a copy of the given monster at the given position in the dungeon. More...
 
int mon_hp (const struct monster_race *race, aspect hp_aspect)
 Calculates hp for a monster. More...
 
bool place_new_monster (struct chunk *, int y, int x, struct monster_race *race, bool sleep, bool group_okay, byte origin)
 Attempts to place a monster of the given race at the given location. More...
 
bool pick_and_place_monster (struct chunk *c, int y, int x, 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, compact_monsters_aux(), delete_monster(), monster_race::flags, monster::fx, monster::fy, iter, monster_race::level, chunk::mon_max, msg, monster::race, randint0, rf_has, and RF_UNIQUE.

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

◆ delete_monster()

void delete_monster ( int  y,
int  x 
)

◆ 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/50) 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 "hardest" 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, NULL, one_in_, angband_constants::ood_monster_amount, angband_constants::ood_monster_chance, p, alloc_entry::prob3, r_info, randint0, rf_has, RF_UNIQUE, and z_info.

Referenced by build_nest(), build_pit(), get_chamber_monsters(), get_vault_monsters(), pick_and_place_monster(), place_new_monster(), poly_race(), 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(), place_new_monster(), 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)

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().

◆ 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(), chunk::height, msg, OPT, pick_and_place_monster(), player::px, player::py, 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,
int  y,
int  x,
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,
int  y,
int  x,
struct monster mon,
byte  origin 
)

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 monsters 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::fx, monster::fy, monster::midx, monster_race::mimic_kinds, square::mon, mon_create_drop(), mon_create_mimicked_object(), mon_pop(), num_repro, monster::race, rf_has, square_in_bounds(), square_monster(), chunk::squares, update_mon(), and void().

Referenced by place_new_monster_one(), and rd_monsters_aux().

◆ place_new_monster()

bool place_new_monster ( struct chunk c,
int  y,
int  x,
struct monster_race race,
bool  sleep,
bool  group_okay,
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_race::level, monster_friends::next, monster_friends_base::next, NULL, 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, and randint0.

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::fx, monster::fy, health_track(), monster::held_obj, object::known, square::mon, chunk::mon_cnt, chunk::mon_max, object::next, NULL, num_repro, object_pile_free(), monster::race, chunk::squares, target_set_monster(), and player::upkeep.

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