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-curse.h"
#include "obj-gear.h"
#include "obj-knowledge.h"
#include "obj-make.h"
#include "obj-pile.h"
#include "obj-power.h"
#include "obj-slays.h"
#include "obj-tval.h"
#include "obj-util.h"

Data Structures

struct  money
 

Functions

static void alloc_init_objects (void)
 
static void alloc_init_egos (void)
 
static void init_money_svals (void)
 
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. More...
 
static int random_base_resist (struct object *obj, int *resist)
 Get a random new base resist on an item. More...
 
static int random_high_resist (struct object *obj, int *resist)
 Get a random new high resist on an item. More...
 
static struct ego_itemego_find_random (struct object *obj, int level)
 Select an ego-item that fits the object's tval and sval. More...
 
void ego_apply_magic (struct object *obj, int level)
 Apply generation magic to an ego-item. More...
 
static void ego_apply_minima (struct object *obj)
 Apply minimum standards for ego-items. More...
 
static void make_ego_item (struct object *obj, int level)
 Try to find an ego-item for an object, setting obj->ego if successful and applying various bonuses. More...
 
void copy_artifact_data (struct object *obj, const struct artifact *art)
 Copy artifact data to a normal object. More...
 
static struct objectmake_artifact_special (int level)
 Mega-Hack – Attempt to create one of the "Special Objects". More...
 
static bool make_artifact (struct object *obj)
 Attempt to change an object into an artifact. More...
 
bool make_fake_artifact (struct object *obj, const struct artifact *artifact)
 Create a fake artifact directly from a blank object. More...
 
static void apply_magic_weapon (struct object *obj, int level, int power)
 Apply magic to a weapon. More...
 
static void apply_magic_armour (struct object *obj, int level, int power)
 Apply magic to armour. More...
 
void object_prep (struct object *obj, struct object_kind *k, int lev, aspect rand_aspect)
 Wipe an object clean and make it a standard object of the specified kind. More...
 
static int apply_curse (struct object *obj, int lev)
 Attempt to apply curses to an object, with a corresponding increase in generation level of the object. More...
 
int apply_magic (struct object *obj, 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,. More...
 
bool kind_is_good (const struct object_kind *kind)
 Hack – determine if a template is "good". More...
 
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. More...
 
struct object_kindget_obj_num (int level, bool good, int tval)
 Choose an object kind given a dungeon level to choose it for. More...
 
struct objectmake_object (struct chunk *c, int lev, bool good, bool great, bool extra_roll, s32b *value, int tval)
 Attempt to make an object. More...
 
void acquirement (int y1, int x1, int level, int num, bool great)
 Scatter some objects near the player. More...
 
struct object_kindmoney_kind (const char *name, int value)
 Get a money kind by name, or level-appropriate. More...
 
struct objectmake_gold (int lev, char *coin_type)
 Make a money object. More...
 

Variables

static u32bobj_total
 Arrays holding an index of objects to generate for a given level. More...
 
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(), NULL, object::origin, and object::origin_depth.

Referenced by effect_handler_ACQUIRE(), and get_debug_command().

static void alloc_init_egos ( void  )
static
static void alloc_init_objects ( void  )
static
static int apply_curse ( struct object obj,
int  lev 
)
static

Attempt to apply curses to an object, with a corresponding increase in generation level of the object.

References append_object_curse(), angband_constants::curse_max, curses, m_bonus(), randint1, object::tval, and z_info.

Referenced by apply_magic().

int apply_magic ( struct object obj,
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_curse(), 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_, object::pval, randint0, randint1, object::sval, object::tval, tval_is_armor(), tval_is_chest(), tval_is_ring(), tval_is_weapon(), and tval_is_wearable().

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

static void apply_magic_armour ( struct object obj,
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 obj,
int  level,
int  power 
)
static
static void cleanup_obj_make ( void  )
static
void copy_artifact_data ( struct object obj,
const struct artifact art 
)
void ego_apply_magic ( struct object obj,
int  level 
)
static void ego_apply_minima ( struct object obj)
static
static struct ego_item* ego_find_random ( struct object obj,
int  level 
)
static
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 
)

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 
)
static

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

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

Referenced by get_obj_num().

static void init_money_svals ( void  )
static
static void init_obj_make ( void  )
static
bool kind_is_good ( const struct 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 kf_has, object_kind::kind_flags, MINIMISE, randcalc(), object_kind::to_a, object_kind::to_d, object_kind::to_h, and object_kind::tval.

Referenced by alloc_init_objects().

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, i, kf_has, object_kind::kind_flags, lookup_kind(), artifact::name, object::number, OPT, randint0, randint1, artifact::sval, object::sval, artifact::tval, object::tval, and z_info.

Referenced by apply_magic().

static struct object* make_artifact_special ( int  level)
static

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, level, object_kind::level, lookup_kind(), artifact::name, NULL, 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 obj,
int  level 
)
static

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

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

Referenced by apply_magic().

bool make_fake_artifact ( struct object obj,
const 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(), lookup_kind(), MAXIMISE, object_prep(), artifact::sval, and artifact::tval.

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

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

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, mem_zalloc(), MIN, money_kind(), object_prep(), one_in_, OPT, object::pval, rand_spread, randint0, RANDOMISE, and value.

Referenced by mon_create_drop(), place_gold(), place_monster(), wiz_create_item_object_from_kind(), and wiz_test_kind().

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

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(), object_kind::base, object::curses, chunk::depth, object_kind::gen_mult_prob, get_obj_num(), object::kind, make_artifact_special(), object_base::max_stack, NULL, object::number, object_new(), object_prep(), object_value_real(), one_in_, randcalc(), randint1, RANDOMISE, and object_kind::stack_size.

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

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

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 obj,
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_brands(), copy_curses(), copy_slays(), object_kind::curses, 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, ELEM_MAX, element_info::flags, object_base::flags, object_kind::flags, object::flags, angband_constants::fuel_torch, i, 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_edible(), 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_object_from_artifact(), wiz_create_item_object_from_kind(), wiz_reroll_item(), and wiz_test_kind().

static int random_base_resist ( struct object obj,
int resist 
)
static

Get a random new base resist on an item.

References object::el_info, ELEM_BASE_MIN, ELEM_HIGH_MIN, i, randint0, and element_info::res_level.

Referenced by ego_apply_magic().

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

Get a random new high resist on an item.

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

Referenced by ego_apply_magic().

Variable Documentation

s16b alloc_ego_size = 0
static

Referenced by alloc_init_egos(), and ego_find_random().

alloc_entry* alloc_ego_table
static

Referenced by ego_find_random().

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
}
static void cleanup_obj_make(void)
Definition: obj-make.c:184
static void init_obj_make(void)
Definition: obj-make.c:178
u32b* obj_total
static

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

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

u32b* obj_total_great
static