Angband
Data Structures | Functions | Variables
obj-make.c File Reference

Object generation functions. More...

#include "angband.h"
#include "alloc.h"
#include "cave.h"
#include "effects.h"
#include "init.h"
#include "obj-gear.h"
#include "obj-pile.h"
#include "obj-make.h"
#include "obj-power.h"
#include "obj-slays.h"
#include "obj-tval.h"
#include "obj-util.h"

Data Structures

struct  money

Functions

static void init_obj_make (void)
static void cleanup_obj_make (void)
static int get_new_attr (bitflag flags[OF_SIZE], bitflag newf[OF_SIZE])
 This is a safe way to choose a random new flag to add to an object.
static int random_high_resist (struct object *o_ptr, int *resist)
 Get a random new high resist on an item.
static struct ego_itemego_find_random (struct object *o_ptr, int level)
 Select an ego-item that fits the object's tval and sval.
void ego_apply_magic (struct object *o_ptr, int level)
 Apply generation magic to an ego-item.
static void ego_apply_minima (struct object *o_ptr)
 Apply minimum standards for ego-items.
static void make_ego_item (struct object *o_ptr, int level)
 Try to find an ego-item for an object, setting o_ptr->ego if successful and applying various bonuses.
void copy_artifact_data (struct object *o_ptr, const struct artifact *a_ptr)
 Copy artifact data to a normal object, and set various slightly hacky globals.
static struct objectmake_artifact_special (int level)
 Mega-Hack – Attempt to create one of the "Special Objects".
static bool make_artifact (struct object *obj)
 Attempt to change an object into an artifact.
bool make_fake_artifact (struct object *obj, struct artifact *artifact)
 Create a fake artifact directly from a blank object.
static void apply_magic_weapon (struct object *o_ptr, int level, int power)
 Apply magic to a weapon.
static void apply_magic_armour (struct object *o_ptr, int level, int power)
 Apply magic to armour.
void object_prep (struct object *o_ptr, struct object_kind *k, int lev, aspect rand_aspect)
 Wipe an object clean and make it a standard object of the specified kind.
int apply_magic (struct object *o_ptr, int lev, bool allow_artifacts, bool good, bool great, bool extra_roll)
 Applying magic to an object, which includes creating ego-items, and applying random bonuses,.
bool kind_is_good (const object_kind *kind)
 Hack – determine if a template is "good".
static struct object_kindget_obj_num_by_kind (int level, bool good, int tval)
 Choose an object kind of a given tval given a dungeon level.
struct object_kindget_obj_num (int level, bool good, int tval)
 Choose an object kind given a dungeon level to choose it for.
struct objectmake_object (struct chunk *c, int lev, bool good, bool great, bool extra_roll, s32b *value, int tval)
 Attempt to make an object.
void acquirement (int y1, int x1, int level, int num, bool great)
 Scatter some objects near the player.
struct object_kindmoney_kind (const char *name, int value)
 Get a money kind by name, or level-appropriate.
struct objectmake_gold (int lev, char *coin_type)
 Make a money object.

Variables

static u32bobj_total
 Arrays holding an index of objects to generate for a given level.
static byteobj_alloc
static u32bobj_total_great
static byteobj_alloc_great
static s16b alloc_ego_size = 0
static alloc_entryalloc_ego_table
static struct moneymoney_type
static int num_money_types
struct init_module obj_make_module

Detailed Description

Object generation functions.

Copyright (c) 1987-2007 Angband contributors

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

void acquirement ( int  y1,
int  x1,
int  level,
int  num,
bool  great 
)

Scatter some objects near the player.

References cave, player::depth, drop_near(), make_object(), object::origin, object::origin_depth, and TRUE.

Referenced by effect_handler_ACQUIRE(), and get_debug_command().

int apply_magic ( struct object o_ptr,
int  lev,
bool  allow_artifacts,
bool  good,
bool  great,
bool  extra_roll 
)

Applying magic to an object, which includes creating ego-items, and applying random bonuses,.

The good argument forces the item to be at least good, and the great argument does likewise. Setting allow_artifacts to TRUE allows artifacts to be created here.

If good or great are not set, then the lev argument controls the quality of item.

Returns 0 if a normal object, 1 if a good object, 2 if an ego item, 3 if an artifact.

References apply_magic_armour(), apply_magic_weapon(), ego_apply_minima(), i, object::kind, object_kind::level, lookup_sval(), make_artifact(), make_ego_item(), object::modifiers, one_in_, power, object::pval, randint0, randint1, object::sval, object::tval, tval_is_armor(), tval_is_chest(), tval_is_ring(), and tval_is_weapon().

Referenced by make_object(), mon_create_drop(), place_monster(), store_create_random(), wiz_create_item_subaction(), wiz_reroll_item(), and wiz_test_kind().

static void apply_magic_armour ( struct object o_ptr,
int  level,
int  power 
)
static

Apply magic to armour.

References m_bonus(), randint1, and object::to_a.

Referenced by apply_magic().

static void apply_magic_weapon ( struct object o_ptr,
int  level,
int  power 
)
static
static void cleanup_obj_make ( void  )
static
void copy_artifact_data ( struct object o_ptr,
const struct artifact a_ptr 
)
void ego_apply_magic ( struct object o_ptr,
int  level 
)
static void ego_apply_minima ( struct object o_ptr)
static
static struct ego_item* ego_find_random ( struct object o_ptr,
int  level 
)
staticread
static int get_new_attr ( bitflag  flags[OF_SIZE],
bitflag  newf[OF_SIZE] 
)
static

This is a safe way to choose a random new flag to add to an object.

It takes the existing flags and an array of new flags, and returns an entry from newf, or 0 if there are no new flags available.

References flag, FLAG_END, FLAG_START, flags, i, of_has, of_next, one_in_, and options.

Referenced by ego_apply_magic().

struct object_kind* get_obj_num ( int  level,
bool  good,
int  tval 
)
read

Choose an object kind given a dungeon level to choose it for.

If tval = 0, we can choose an object of any type. Otherwise we can only choose one of the given tval.

References get_obj_num_by_kind(), angband_constants::great_obj, angband_constants::k_max, MAX, angband_constants::max_obj_depth, MIN, obj_alloc, obj_alloc_great, obj_total, obj_total_great, objkind_byid(), one_in_, randint0, randint1, value, and z_info.

Referenced by make_object(), and store_create_random().

static struct object_kind* get_obj_num_by_kind ( int  level,
bool  good,
int  tval 
)
staticread

Choose an object kind of a given tval given a dungeon level.

References angband_constants::k_max, obj_alloc, obj_alloc_great, objkind_byid(), randint0, value, and z_info.

Referenced by get_obj_num().

static void init_obj_make ( void  )
static
bool kind_is_good ( const object_kind kind)

Hack – determine if a template is "good".

Note that this test only applies to the object kind, so it is possible to choose a kind which is "good", and then later cause the actual object to be cursed. We do explicitly forbid objects which are known to be boring or which start out somewhat damaged.

References FALSE, kf_has, object_kind::kind_flags, MINIMISE, randcalc(), object_kind::to_a, object_kind::to_d, object_kind::to_h, TRUE, and object_kind::tval.

Referenced by init_obj_make().

static bool make_artifact ( struct object obj)
static

Attempt to change an object into an artifact.

If the object is already set to be an artifact, use that, or otherwise use a suitable randomly- selected artifact.

This routine should only be called by "apply_magic()"

Note – see "make_artifact_special()" and "apply_magic()"

References a_info, angband_constants::a_max, artifact::alloc_max, artifact::alloc_min, artifact::alloc_prob, object::artifact, copy_artifact_data(), artifact::created, player::depth, FALSE, i, kf_has, object::kind, object_kind::kind_flags, lookup_kind(), artifact::name, object::number, OPT, randint0, randint1, artifact::sval, object::sval, TRUE, artifact::tval, object::tval, and z_info.

Referenced by apply_magic().

static struct object* make_artifact_special ( int  level)
staticread

Mega-Hack – Attempt to create one of the "Special Objects".

We are only called from "make_object()"

Note – see "make_artifact()" and "apply_magic()".

We prefer to create the special artifacts in order, but this is normally outweighed by the "rarity" rolls for those artifacts.

References a_info, angband_constants::a_max, artifact::alloc_max, artifact::alloc_min, artifact::alloc_prob, object::artifact, copy_artifact_data(), artifact::created, player::depth, i, kf_has, object_kind::kind_flags, object_kind::level, level, lookup_kind(), artifact::name, object_new(), object_prep(), OPT, randint0, randint1, RANDOMISE, artifact::sval, artifact::tval, and z_info.

Referenced by make_object().

static void make_ego_item ( struct object o_ptr,
int  level 
)
static

Try to find an ego-item for an object, setting o_ptr->ego if successful and applying various bonuses.

References object::artifact, object::ego, ego_apply_magic(), ego_find_random(), angband_constants::great_ego, object::id_flags, id_on, angband_constants::max_depth, one_in_, randint1, tval_is_light(), and z_info.

Referenced by apply_magic().

bool make_fake_artifact ( struct object obj,
struct artifact artifact 
)

Create a fake artifact directly from a blank object.

This function is used for describing artifacts, and for creating them for debugging.

Since this is now in no way marked as fake, we must make sure this function is never used to create an actual game object

References object::artifact, copy_artifact_data(), FALSE, lookup_kind(), MAXIMISE, object_prep(), artifact::sval, TRUE, and artifact::tval.

Referenced by artifact_power(), desc_art_fake(), get_artifact_display_name(), history_add_artifact(), and spoil_artifact().

struct object* make_gold ( int  lev,
char *  coin_type 
)
read

Make a money object.

Parameters
levthe dungeon level
coin_typethe name of the type of money object to make
Returns
a pointer to the newly minted cash (cannot fail)

References player::depth, MAX_SHORT, mem_zalloc(), MIN, money_kind(), object_prep(), one_in_, OPT, object::pval, rand_spread, RANDOMISE, and value.

Referenced by chest_death(), mon_create_drop(), place_gold(), place_monster(), wiz_create_item_subaction(), and wiz_test_kind().

struct object* make_object ( struct chunk c,
int  lev,
bool  good,
bool  great,
bool  extra_roll,
s32b value,
int  tval 
)
read

Attempt to make an object.

Parameters
cis the current dungeon level.
levis the creation level of the object (not necessarily == depth).
goodis whether the object is to be good
greatis whether the object is to be great
extra_rollis whether we get an extra roll in apply_magic()
valueis the value to be returned to the calling function
tvalis the desired tval, or 0 if we allow any tval
Returns
a pointer to the newly allocated object, or NULL on failure.

References object_kind::alloc_min, apply_magic(), cursed_p(), chunk::depth, FALSE, object::flags, object_kind::gen_mult_prob, get_obj_num(), object::kind, make_artifact_special(), object::number, object_new(), object_prep(), object_value_real(), one_in_, randcalc(), randint1, RANDOMISE, angband_constants::stack_size, object_kind::stack_size, TRUE, and z_info.

Referenced by acquirement(), chest_death(), mon_create_drop(), place_object(), and wiz_statistics().

struct object_kind* money_kind ( const char *  name,
int  value 
)
read

Get a money kind by name, or level-appropriate.

References lookup_kind(), angband_constants::max_depth, num_money_types, streq, type, and z_info.

Referenced by make_gold(), and melee_effect_handler_EAT_GOLD().

void object_prep ( struct object o_ptr,
struct object_kind k,
int  lev,
aspect  rand_aspect 
)

Wipe an object clean and make it a standard object of the specified kind.

References object_kind::ac, object::ac, object_kind::base, object_kind::brands, object::brands, object_kind::charge, copy_brand(), copy_slay(), object_kind::dd, object::dd, angband_constants::default_lamp, object_kind::ds, object::ds, object_kind::effect, object::effect, object_base::el_info, object_kind::el_info, object::el_info, EL_INFO_KNOWN, ELEM_HIGH_MAX, ELEM_MAX, element_info::flags, object_base::flags, object_kind::flags, object::flags, angband_constants::fuel_torch, i, object::id_flags, id_on, object::kind, object_kind::modifiers, object::modifiers, object::number, OBJ_MOD_MAX, of_copy, of_has, object_kind::pval, object::pval, randcalc(), element_info::res_level, object_kind::slays, object::slays, object_kind::sval, object::sval, object_kind::time, object::time, object::timeout, object_kind::to_a, object::to_a, object_kind::to_d, object::to_d, object_kind::to_h, object::to_h, object_kind::tval, object::tval, tval_can_have_charges(), tval_is_food(), tval_is_fuel(), tval_is_launcher(), tval_is_light(), tval_is_potion(), object_kind::weight, object::weight, and z_info.

Referenced by desc_obj_fake(), display_object_kind_recall(), get_art_name(), kind_info(), make_artifact_special(), make_fake_artifact(), make_gold(), make_object(), melee_effect_handler_EAT_GOLD(), mon_create_drop(), place_monster(), player_outfit(), store_create_item(), store_create_random(), test_breakage_chance(), test_obj_can_refill(), wiz_create_item_subaction(), wiz_reroll_item(), and wiz_test_kind().

static int random_high_resist ( struct object o_ptr,
int resist 
)
static

Get a random new high resist on an item.

References object::el_info, ELEM_HIGH_MAX, ELEM_HIGH_MIN, FALSE, i, randint0, element_info::res_level, and TRUE.

Referenced by ego_apply_magic().

Variable Documentation

s16b alloc_ego_size = 0
static

Referenced by ego_find_random(), and init_obj_make().

alloc_entry* alloc_ego_table
static

Referenced by ego_find_random(), and init_obj_make().

struct money* money_type
static
int num_money_types
static
byte* obj_alloc
static
byte* obj_alloc_great
static
struct init_module obj_make_module
Initial value:
{
.name = "object/obj-make",
.init = init_obj_make,
.cleanup = cleanup_obj_make
}
u32b* obj_total
static

Arrays holding an index of objects to generate for a given level.

Referenced by cleanup_obj_make(), get_obj_num(), and init_obj_make().

u32b* obj_total_great
static