53 #define num_resist_table 19 63 if (ring_arch == NULL)
196 if (strcmp(t->
name,
"NONE") && difficulty >= t->
magic)
199 while (tries < 100) {
237 LOG(
llevDebug,
"create_one_treasure: tries exceeded 100, returning without making treasure\n");
241 for (t = tl->
items; t != NULL; t = t->
next) {
247 if (!t || value >= 0) {
248 LOG(
llevError,
"create_one_treasure: got null object or not able to find treasure\n");
252 if (!strcmp(t->
name,
"NONE"))
254 if (difficulty >= t->
magic)
260 bool got_one =
false;
261 while (tries < 100) {
269 LOG(
llevError,
"create_one_treasure failed to create at least one treasure for item %s on list %s\n", t->
item->
name, tl->
name);
289 LOG(
llevDebug,
"createtreasure: tries exceeded 100, returning without making treasure\n");
329 LOG(
llevError,
"In generate treasure, created multiple objects.\n");
348 int level, mult, olevel;
370 olevel =
rndm(0, difficulty)+
rndm(0, difficulty);
376 else if (olevel < level)
442 { 70, 2, 7, 11, 10 },
443 { 70, 2, 7, 11, 10 },
444 { 70, 2, 7, 11, 10 },
445 { 70, 2, 7, 11, 10 },
446 { 70, 2, 7, 11, 10 },
447 { 70, 2, 5, 12, 11 },
448 { 70, 2, 5, 12, 11 },
449 { 70, 2, 5, 12, 11 },
450 { 70, 2, 5, 12, 11 },
451 { 70, 2, 5, 12, 11 },
452 { 70, 2, 3, 13, 12 },
453 { 70, 2, 3, 13, 12 },
454 { 70, 2, 3, 13, 12 },
455 { 70, 2, 3, 13, 12 },
456 { 70, 2, 3, 13, 12 },
457 { 70, 2, 3, 12, 13 },
458 { 70, 2, 3, 12, 13 },
459 { 70, 2, 3, 12, 13 },
460 { 70, 2, 3, 12, 13 },
461 { 70, 2, 3, 12, 13 },
462 { 70, 2, 3, 11, 14 },
463 { 70, 2, 3, 11, 14 },
464 { 70, 2, 3, 11, 14 },
465 { 70, 2, 3, 11, 14 },
466 { 70, 2, 3, 11, 14 },
467 { 70, 2, 3, 10, 15 },
468 { 70, 2, 3, 10, 15 },
469 { 70, 2, 3, 10, 15 },
470 { 70, 2, 3, 10, 15 },
471 { 70, 2, 3, 10, 15 },
614 for (loop = 0; loop < (
MAXMAGIC+1); ++loop) {
620 LOG(
llevError,
"Warning, table for difficulty %d bad.\n", difficulty);
624 return (
RANDOM()%3) ? loop : -loop;
643 int32_t base_weight, base_speed;
666 if (magic < 0 && !(
RANDOM()%3))
720 int r =
RANDOM()%(bonus > 0 ? 25 : 11);
832 op->
value *= 2*bonus;
869 for (i = 0; i < difficulty; i++)
885 #define DICE2 (dice2()) 892 return RANDOM() % uint32_t(b) < uint32_t(a);
896 return chance(2, 27) ? 2 : 1;
899 #define DICESPELL (RANDOM()%3+RANDOM()%3+RANDOM()%3+RANDOM()%3+RANDOM()%3) 928 int was_magic = op->
magic, num_enchantments = 0, save_item_power;
930 if (!creator || creator->
type == op->
type)
940 LOG(
llevDebug,
"fix_generated_item: Unable to generate treasure for %s\n", op->
name);
949 set_magic(difficulty > 25 ? 30 : difficulty+5, op, max_magic, flags);
953 if (!op->
magic && max_magic)
954 set_magic(difficulty, op, max_magic, flags);
958 || difficulty >= 999)
977 }
else if (save_item_power) {
1003 if (flags>_MINIMAL) {
1014 }
else if (!op->
title) {
1034 int too_many_tries = 0, is_special = 0;
1047 if (too_many_tries++ > 10)
1071 if (op->
arch == NULL) {
1119 if (op->
msg != NULL)
1139 LOG(
llevError,
"Generated a spellbook without a spell\n");
1147 if (!(flags>_ONLY_GOOD) &&
rndm(1, 100) <= 5) {
1148 if (
rndm(1, 6) <= 1)
1152 }
else if (
rndm(1, 100) <= 1) {
1192 LOG(
llevError,
"Generated a scroll without a spell\n");
1201 if (!(flags>_ONLY_GOOD) &&
rndm(1, 100) <= 20) {
1202 if (
rndm(1, 6) <= 1)
1206 }
else if (
rndm(1, 100) <= 2) {
1247 if (t->
name != NULL) {
1248 for (i = 0; i < depth; i++)
1253 for (i = 0; i < depth; i++)
1255 fprintf(
logfile,
"} (end of list: %s)\n", t->
name);
1257 for (i = 0; i < depth; i++)
1265 for (i = 0; i < depth; i++)
1267 fprintf(
logfile,
" (if yes)\n");
1271 for (i = 0; i < depth; i++)
1273 fprintf(
logfile,
" (if no)\n");
1290 if (!
strcasecmp(at->clone.name, name) && at->clone.title == NULL) {
1291 fprintf(logfile,
"treasures for %s (arch: %s)\n", at->clone.name, at->name);
1292 if (at->clone.randomitems != NULL)
1293 dump_monster_treasure_rec(at->clone.name, at->clone.randomitems->items, 1);
1295 fprintf(logfile,
"(nothing)\n");
1296 fprintf(logfile,
"\n");
1302 fprintf(
logfile,
"No objects have the name %s!\n\n", name);
1318 snprintf(tmpbuf,
sizeof(tmpbuf),
"%s's %s", donor->
name, item->
name);
1320 snprintf(tmpbuf,
sizeof(tmpbuf),
"%s's %s", donor->
name, item->
name_pl);
1340 LOG(
llevError,
"could not find original archetype %s for custom monster!\n", donor->
arch->
name);
1347 if ((item->
weight = (
signed long)(((
double)item->
weight/(
double)100.0)*(
double)donor->
weight)) == 0)
1372 if (item->
face != NULL) {
1373 snprintf(tmpbuf,
sizeof(tmpbuf),
"%s_%s", donor->
arch->
name, item->
face->
name);
1464 if (list->
items == NULL || position <= 0) {
1466 list->
items = added;
1471 while (position > 0 && prev->
next) {
1486 if (list->
items == 0 || position < 0) {
1489 if (position == 0) {
1498 while (prev && position > 0) {
static void set_ring_bonus(object *op, int bonus)
Randomly adds one magical ability to the given object.
#define FLAG_DAMNED
The object is very cursed.
void treasure_remove_item(treasurelist *list, int position)
Remove the treasure at the specified position from the list.
int8_t item_power
Power rating of the object.
int calc_item_power(const object *op)
This takes an object 'op' and figures out what its item_power rating should be.
struct archetype * arch
Pointer to archetype.
static const int difftomagic_list[DIFFLEVELS][MAXMAGIC+1]
Based upon the specified difficulty and upon the difftomagic_list array, a random magical bonus is re...
const char *const spell_mapping[SPELL_MAPPINGS]
This table is only necessary to convert objects that existed before the spell object conversion to th...
FILE * logfile
Used by server/daemon.c.
const char * name
If != NULL, copy this over the original arch name.
static int resist_table[]
Resistances which can show up on rings and amulets.
void LOG(LogLevel logLevel, const char *format,...)
Logs a message to stderr, or to file.
#define MAXMAGIC
Maximum magic for difficulty/magic mapping.
#define FABS(x)
Decstations have trouble with fabs()...
int rndm(int min, int max)
Returns a number between min and max.
void tailor_readable_ob(object *book, int msg_type)
The main routine.
archetype * find_archetype(const char *name)
void object_remove(object *op)
This function removes the object op from the linked list of objects which it is currently tied to...
void set_materialname(object *op)
Set the material name and type for an item, if not set.
sstring name
If non null, name of list to use instead.
#define SET_ANIMATION(ob, newanim)
sstring slaying
Which race to do double damage to.
sstring add_string(const char *str)
Share a string.
int32_t value
How much money it is worth (or contains)
int8_t list_magic_adjustment
Adjust difficulty when generating the list pointed by name, ignored if list_magic_value is non zero...
void generate_artifact(object *op, int difficulty)
Decides randomly which artifact the object should be turned into.
int16_t y
Position in the map for this object.
int8_t magic
Any magical bonuses to this item.
Do minimal adjustments, don't make artifacts, and so on.
#define FLAG_BLESSED
Item has a blessing, opposite of cursed/damned.
#define FREE_OBJ_NO_DESTROY_CALLBACK
Do not run the destroy callback.
int get_power_from_ench(int ench)
animal 'body parts' -b.t.
Global type definitions and header inclusions.
static archetype * crown_arch
static void fix_flesh_item(object *item, const object *donor)
Objects of type FLESH are similar to type FOOD, except they inherit properties (name, food value, etc).
void set_attr_value(living *stats, int attr, int8_t value)
Sets Str/Dex/con/Wis/Cha/Int/Pow in stats to value, depending on what attr is (STR to POW)...
treasure * treasure_insert(treasurelist *list, int position)
Insert a new treasure in the treasure list, at a specific position in the children list...
int32_t weight
Attributes of the object.
bool chance(int a, int b)
Return true with a probability of a/b.
void dump_monster_treasure(const char *name)
For debugging purposes.
AssetsManager * getManager()
const Face * try_find_face(const char *name, const Face *error)
void free_string(sstring str)
This will reduce the refcount, and if it has reached 0, str will be freed.
int16_t level
Level of creature or object.
static archetype * ring_arch
Arches for rings, amulets and crowns.
void object_free(object *ob, int flags)
Frees everything allocated by an object, removes it from the list of used objects, and puts it on the list of free objects.
int legal_artifact_combination(const object *op, const artifact *art)
Checks if op can be combined with art.
#define FREE_OBJ_FREE_INVENTORY
Free inventory objects; if not set, drop inventory.
#define FLAG_ALIVE
Object can fight (or be fought)
int armor_speed_improvement
Speed improvement.
static void create_one_treasure(treasurelist *tl, object *op, int flag, int difficulty, int tries)
Creates one treasure from the list.
int16_t resist[NROFATTACKS]
Resistance adjustments for attacks.
#define FLAG_REFL_SPELL
Spells (some) will reflect from object.
void create_treasure(treasurelist *t, object *op, int flag, int difficulty, int tries)
This calls the appropriate treasure creation function.
#define FLAG_OBJ_ORIGINAL
NEVER SET THIS.
The archetype structure is a set of rules on how to generate and manipulate objects which point to ar...
#define DIFFLEVELS
Maximum difficulty for difficulty/magic mapping.
sstring name
More definite name, like "generate_kobold".
#define FLAG_NO_STEAL
Item can't be stolen.
Defines for loader.l / loader.c.
Defines and variables used by the artifact generation routines.
object * arch_to_object(archetype *at)
Creates and returns a new object which is a copy of the given archetype.
object * create_archetype(const char *name)
Finds which archetype matches the given name, and returns a new object containing a copy of the arche...
#define CHANCE_FOR_ARTIFACT
Chance an item becomes an artifact if not magic is 1 in this value.
#define MAX_SPELLITEM_LEVEL
Highest level of rods/staves/scrolls to generate.
#define QUERY_FLAG(xyz, p)
const artifact * find_artifact(const object *op, const char *name)
Searches and returns a specific artifact compatible with an object, NULL if not found.
void give_artifact_abilities(object *op, const object *artifact)
Fixes the given object, giving it the abilities and titles it should have due to the second artifact-...
int strcasecmp(const char *s1, const char *s2)
uint8_t chance
Percent chance for this item.
static void set_magic(int difficulty, object *op, int max_magic, int flags)
Sets a random magical bonus in the given object based upon the given difficulty, and the given max po...
void object_free_drop_inventory(object *ob)
Frees everything allocated by an object, removes it from the list of used objects, and puts it on the list of free objects.
uint8_t armor_weight_linear
If 1, weight reduction is linear, else exponantiel.
sstring msg
If this is a book/sign/magic mouth/etc.
void set_abs_magic(object *op, int magic)
Sets magical bonus in an object, and recalculates the effect on the armour variable, and the effect on speed of armour.
static void dump_monster_treasure_rec(const char *name, treasure *t, int depth)
For debugging purposes.
const char * title
If != NULL, copy this over the original arch title.
uint8_t range_modifier
How going up in level affects range.
#define ARMOUR_SPEED(xyz)
Archetypes * archetypes()
Get archetypes.
#define INS_NO_WALK_ON
Don't call check_walk_on against the originator.
uint8_t armor_speed_linear
If 1, speed improvement is linear, else exponantiel.
const Face * face
Face with colors.
uint64_t shopmin
Minimum price a shop will trade for.
uint8_t dam_modifier
How going up in level affects damage.
struct Settings settings
Global settings.
int16_t total_chance
If non-zero, only 1 item on this list should be generated.
object * object_new(void)
Grabs an object from the list of unused objects, makes sure it is initialised, and returns it...
static int level_for_item(const object *op, int difficulty)
Calculate the appropriate level for wands staves and scrolls.
int16_t dam
How much damage this object does when hitting.
treasure * next_no
If this item was not generated, then continue here.
void fatal(enum fatal_error err)
fatal() is meant to be called whenever a fatal signal is intercepted.
int isqrt(int n)
Compute the square root.
living stats
Str, Con, Dex, etc.
#define MAX_BUF
Used for all kinds of things.
int16_t invisible
How much longer the object will be invis.
uint64_t price_base(const object *obj)
Price an item based on its value or archetype value, type, identification/BUC status, and other heuristics.
static bool do_single_item(treasure *t, object *op, int flag, int difficulty)
Creates the item for a treasure.
struct mapstruct * map
Pointer to the map in which this object is present.
#define num_resist_table
Number of items in resist_table.
#define FLAG_IS_THROWN
Object is designed to be thrown.
static const flag_definition flags[]
Flag mapping.
treasurelist represents one logical group of items to be generated together.
treasure * next_yes
If this item was generated, use this link instead of ->next.
#define FLAG_CURSED
The object is cursed.
struct archetype * other_arch
Pointer used for various things - mostly used for what this objects turns into or what this object cr...
struct treasurelist * randomitems
Items to be generated.
#define AT_POISON
Some damage each turn thereafter (1024)
sstring name_pl
The plural name of the object.
sstring artifact
If not null, the name of the artifact to apply to item.
#define INS_NO_MERGE
Don't try to merge with other items.
int armor_weight_reduction
Weight reduction per enchantment.
#define FREE_AND_COPY(sv, nv)
Release the shared string if not NULL, and make it a reference to nv.
treasure * next
Next treasure-item in a linked list.
#define NUM_ANIMATIONS(ob)
object * generate_treasure(treasurelist *t, int difficulty)
Generate a treasure from a list generating a single item.
struct _change_arch change_arch
Override default arch values if set in treasure list.
void fix_generated_item(object *op, object *creator, int difficulty, int max_magic, int flags)
fix_generated_item(): This is called after an item is generated, in order to set it up right...
sstring name
The name of the object, obviously...
int8_t get_attr_value(const living *stats, int attr)
Gets the value of a stat.
sstring title
Of foo, etc.
Only for debugging purposes.
uint32_t nrof
Number of objects.
sstring name
Usually monster-name/combination.
treasure * items
Items in this list, linked.
uint8_t type
PLAYER, BULLET, etc.
uint8_t list_magic_value
Set difficulty when generating the list pointed by name.
int8_t ac
Armor Class, lower AC increases probability of not getting hit.
uint16_t nrof
Random 1 to nrof items are generated.
int reference_count
How many times this temporary archetype is used.
treasure * get_empty_treasure(void)
Allocate and return the pointer to an empty treasure structure.
treasurelist * find_treasurelist(const char *name)
Search for the given treasurelist by name.
static int special_potion(object *op)
Check if object is a special potion.
object * inv
Pointer to the first object in the inventory.
#define FLAG_STARTEQUIP
Object was given to player at start.
treasure is one element in a linked list, which together consist of a complete treasure-list.
static void create_all_treasures(treasure *t, object *op, int flag, int difficulty, int tries)
Creates all the treasures.
static int magic_from_difficulty(int difficulty)
This is used when determining the magical bonus created on specific maps.
Don't generate bad/cursed items.
uint32_t attacktype
Bitmask of attacks this object does.
static void put_treasure(object *op, object *creator, int flags)
Inserts generated treasure where it should go.
const char * slaying
If != NULL, copy this over the original arch slaying.
#define FLAG_MONSTER
Will attack players.
static archetype * amulet_arch
C function wrappers to interact with assets.
uint8_t magic
Max magic bonus to item If the entry is a list transition, 'magic' contains the difficulty required t...
static void change_treasure(treasure *t, object *op)
if there are change_xxx commands in the treasure, we include the changes in the generated object ...
int32_t food
How much food in stomach.
struct archetype * item
Which item this link can be.
void rod_adjust(object *rod)
Adjusts rod attributes.
uint16_t difficulty
What level the player should be to play here.
void treasure_free(treasure *t)
Frees a treasure, including its yes, no and next items.
object * object_insert_in_ob(object *op, object *where)
This function inserts the object op in the linked list inside the object environment.
object * object_insert_in_map_at(object *op, mapstruct *m, object *originator, int flag, int x, int y)
Same as object_insert_in_map() except it handle separate coordinates and do a clean job preparing mul...
int8_t wc
Weapon Class, lower WC increases probability of hitting.
static void trap_adjust(object *trap, int difficulty)
Adjust trap difficulty to the map.
#define FLAG_NO_PICK
Object can't be picked up.
void init_archetype_pointers(void)
Initialize global archtype pointers:
#define FLAG_REFL_MISSILE
Arrows will reflect from object.
#define AT_ACID
Random equipped item might corrode when hit (64)
#define FLAG_INV_LOCKED
Item will not be dropped from inventory.
This is one artifact, ie one special item.
#define AT_DEATH
Chance of instant death, otherwise nothing (131072) peterm@soda.berkeley.edu.
sstring name
Face name, as used by archetypes and such.
object clone
An object from which to do object_copy()
uint8_t duration_modifier
how level modifies duration
#define ATNR_LIFE_STEALING
object * item
Special values of the artifact.
Generated items have the FLAG_STARTEQUIP.
void each(std::function< void(T *)> op)
Apply a function to each asset.