--- deliantra/server/common/treasure.C 2009/10/15 16:00:37 1.87 +++ deliantra/server/common/treasure.C 2011/04/23 04:56:47 1.112 @@ -1,9 +1,9 @@ /* * This file is part of Deliantra, the Roguelike Realtime MMORPG. * - * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team - * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team - * Copyright (©) 1992,2007 Frank Tore Johansen + * Copyright (©) 2005,2006,2007,2008,2009,2010,2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team + * Copyright (©) 2002 Mark Wedel & Crossfire Development Team + * Copyright (©) 1992 Frank Tore Johansen * * Deliantra is free software: you can redistribute it and/or modify it under * the terms of the Affero GNU General Public License as published by the @@ -35,7 +35,6 @@ #include #include -#include extern char *spell_mapping[]; @@ -53,6 +52,20 @@ static tl_map_t tl_map; +//TODO: class method +static void free_treasurestruct (treasure *t); // bleh desu +static void +clear (treasurelist *tl) +{ + if (tl->items) + { + free_treasurestruct (tl->items); + tl->items = 0; + } + + tl->total_chance = 0; +} + /* * Searches for the given treasurelist */ @@ -93,19 +106,6 @@ return tl; } -//TODO: class method -void -clear (treasurelist *tl) -{ - if (tl->items) - { - free_treasurestruct (tl->items); - tl->items = 0; - } - - tl->total_chance = 0; -} - #ifdef TREASURE_DEBUG /* recursived checks the linked list. Treasurelist is passed only * so that the treasure name can be printed out @@ -257,11 +257,12 @@ op->expand_tail (); - if (!creator->is_on_map () || op->blocked (creator->map, creator->x, creator->y)) + if (!creator->is_on_map () + || (op->weight && op->blocked (creator->map, creator->x, creator->y))) op->destroy (); else { - SET_FLAG (op, FLAG_OBJ_ORIGINAL); + op->flag [FLAG_OBJ_ORIGINAL] = true; op->insert_at (creator, creator, INS_NO_MERGE | INS_NO_WALK_ON); } } @@ -269,7 +270,7 @@ { op = creator->insert (op); - if ((flags & GT_APPLY) && QUERY_FLAG (creator, FLAG_MONSTER)) + if ((flags & GT_APPLY) && creator->flag [FLAG_MONSTER]) monster_check_apply (creator, op); } } @@ -311,7 +312,7 @@ { if (t->item && (t->item->invisible != 0 || !(flag & GT_INVISIBLE))) { - object *tmp = arch_to_object (t->item); + object *tmp = t->item->instance (); if (t->nrof && tmp->nrof <= 1) tmp->nrof = rndm (t->nrof) + 1; @@ -368,7 +369,7 @@ } else if (t->item && (t->item->invisible != 0 || flag != GT_INVISIBLE)) { - if (object *tmp = arch_to_object (t->item)) + if (object *tmp = t->item->instance ()) { if (t->nrof && tmp->nrof <= 1) tmp->nrof = rndm (t->nrof) + 1; @@ -497,7 +498,7 @@ * elmex Wed Aug 9 17:44:59 CEST 2006: * Removed multiplicator, too many high-level items were generated on low-difficulty maps. */ -int +static int level_for_item (const object *op, int difficulty) { if (!op->inv) @@ -511,7 +512,7 @@ if (olevel <= 0) olevel = rndm (1, op->inv->level); - return min (olevel, MAXLEVEL); + return min (olevel, MAXLEVEL_TREASURE); } /* @@ -524,23 +525,16 @@ * weird integer between 1-31. * */ -int +static int magic_from_difficulty (int difficulty) { - int percent = 0, magic = 0; - int scaled_diff = (int) (((double) difficulty / settings.max_level) * DIFFLEVELS); - - scaled_diff--; - - if (scaled_diff < 0) - scaled_diff = 0; + int scaled_diff = lerp (difficulty, 0, settings.max_level, 0, DIFFLEVELS - 1); + scaled_diff = clamp (scaled_diff, 0, DIFFLEVELS - 1); - if (scaled_diff >= DIFFLEVELS) - scaled_diff = DIFFLEVELS - 1; + int percent = rndm (100); + int magic; - percent = rndm (100); - - for (magic = 0; magic < (MAXMAGIC + 1); magic++) + for (magic = 0; magic <= MAXMAGIC; magic++) { percent -= difftomagic_list[scaled_diff][magic]; @@ -548,7 +542,7 @@ break; } - if (magic == (MAXMAGIC + 1)) + if (magic > MAXMAGIC) { LOG (llevError, "Warning, table for difficulty (scaled %d) %d bad.\n", scaled_diff, difficulty); magic = 0; @@ -566,7 +560,6 @@ * This function doesn't work properly, should add use of archetypes * to make it truly absolute. */ - void set_abs_magic (object *op, int magic) { @@ -604,16 +597,16 @@ static void set_magic (int difficulty, object *op, int max_magic, int flags) { - int i; + int i = magic_from_difficulty (difficulty); - i = magic_from_difficulty (difficulty); if ((flags & GT_ONLY_GOOD) && i < 0) i = -i; - if (i > max_magic) - i = max_magic; + + i = min (i, max_magic); + set_abs_magic (op, i); if (i < 0) - SET_FLAG (op, FLAG_CURSED); + op->set_flag (FLAG_CURSED); } /* @@ -624,31 +617,25 @@ * other bonuses previously rolled and ones the item might natively have. * 2) Add code to deal with new PR method. */ -void +static void set_ring_bonus (object *op, int bonus) { - int r = rndm (bonus > 0 ? 25 : 11); if (op->type == AMULET) - { - if (!(rndm (21))) - r = 20 + rndm (2); - else - { - if (rndm (2)) - r = 10; - else - r = 11 + rndm (9); - } - } + if (!rndm (21)) + r = 20 + rndm (2); + else if (rndm (2)) + r = 10; + else + r = 11 + rndm (9); switch (r) { - /* Redone by MSW 2000-11-26 to have much less code. Also, - * bonuses and penalties will stack and add to existing values. - * of the item. - */ + /* Redone by MSW 2000-11-26 to have much less code. Also, + * bonuses and penalties will stack and add to existing values. + * of the item. + */ case 0: case 1: case 2: @@ -698,8 +685,9 @@ */ if (bonus < 0) val = 2 * -val - rndm (b); - if (val > 35) - val = 35; /* Upper limit */ + + val = min (35, val); /* Upper limit */ + b = 0; while (op->resist[resist_table[resist]] != 0 && b < 4) @@ -717,7 +705,7 @@ case 20: if (op->type == AMULET) { - SET_FLAG (op, FLAG_REFL_SPELL); + op->set_flag (FLAG_REFL_SPELL); op->value *= 11; } else @@ -730,7 +718,7 @@ case 21: if (op->type == AMULET) { - SET_FLAG (op, FLAG_REFL_MISSILE); + op->set_flag (FLAG_REFL_MISSILE); op->value *= 9; } else @@ -742,14 +730,14 @@ case 22: op->stats.exp += bonus; /* Speed! */ - op->value = (op->value * 2) / 3; + op->value = op->value * 2 / 3; break; } if (bonus > 0) - op->value *= 2 * bonus; + op->value = 2 * op->value * bonus; else - op->value = -(op->value * 2 * bonus) / 3; + op->value = -2 * op->value * bonus / 3; } /* @@ -760,22 +748,59 @@ * rings and amulets. * Another scheme is used to calculate the magic of weapons and armours. */ -int +static int get_magic (int diff) { - int i; - - if (diff < 3) - diff = 3; + diff = min (3, diff); - for (i = 0; i < 4; i++) + for (int i = 0; i < 4; i++) if (rndm (diff)) return i; return 4; } -#define DICE2 (get_magic(2)==2?2:1) +/* special_potion() - so that old potion code is still done right. */ +static int +special_potion (object *op) +{ + if (op->attacktype) + return 1; + + if (op->stats.Str || op->stats.Dex || op->stats.Con || op->stats.Pow || op->stats.Wis || op->stats.Int || op->stats.Cha) + return 1; + + for (int i = 0; i < NROFATTACKS; i++) + if (op->resist[i]) + return 1; + + return 0; +} + +static double +value_factor_from_spell_item (object *spell, object *item) +{ + double factor = + pow ((spell->value > 0 ? spell->value : 1) + * spell->level, 1.5); + + if (item) // this if for: wands/staffs/rods: + { + /* Old crossfire comment ahead: + * Add 50 to both level an divisor to keep prices a little more + * reasonable. Otherwise, a high level version of a low level + * spell can be worth tons a money (eg, level 20 rod, level 2 spell = + * 10 time multiplier). This way, the value are a bit more reasonable. + */ + + factor *= item->level + 50; + factor /= item->inv->level + 50; + } + + return factor; +} + +#define DICE2 (get_magic(2) == 2 ? 2 : 1) #define DICESPELL (rndm (3) + rndm (3) + rndm (3) + rndm (3) + rndm (3)) /* @@ -819,8 +844,7 @@ op->randomitems = 0; } - if (difficulty < 1) - difficulty = 1; + max_it (difficulty, 1); if (INVOKE_OBJECT (ADD_BONUS, op, ARG_OBJECT (creator != op ? creator : 0), @@ -889,7 +913,7 @@ } /* materialtype modifications. Note we allow this on artifacts. */ - set_materialname (op, difficulty, NULL); + select_material (op, difficulty); if (flags & GT_MINIMAL) { @@ -910,15 +934,15 @@ case SHIELD: case HELMET: case CLOAK: - if (QUERY_FLAG (op, FLAG_CURSED) && !(rndm (4))) + if (op->flag [FLAG_CURSED] && !(rndm (4))) set_ring_bonus (op, -DICE2); break; case BRACERS: - if (!rndm (QUERY_FLAG (op, FLAG_CURSED) ? 5 : 20)) + if (!rndm (op->flag [FLAG_CURSED] ? 5 : 20)) { - set_ring_bonus (op, QUERY_FLAG (op, FLAG_CURSED) ? -DICE2 : DICE2); - if (!QUERY_FLAG (op, FLAG_CURSED)) + set_ring_bonus (op, op->flag [FLAG_CURSED] ? -DICE2 : DICE2); + if (!op->flag [FLAG_CURSED]) op->value *= 3; } break; @@ -930,9 +954,7 @@ /* Handle healing and magic power potions */ if (op->stats.sp && !op->randomitems) { - object *tmp; - - tmp = get_archetype (spell_mapping[op->stats.sp]); + object *tmp = get_archetype (spell_mapping[op->stats.sp]); insert_ob_in_ob (tmp, op); op->stats.sp = 0; } @@ -950,17 +972,18 @@ if (op->inv && op->randomitems) { /* value multiplier is same as for scrolls */ - op->value = (op->value * op->inv->value); + op->value *= op->inv->value; op->level = op->inv->level / 2 + rndm (difficulty) + rndm (difficulty); } else { - op->name = "potion"; - op->name_pl = "potions"; + op->name = shstr_potion; + op->name_pl = shstr_potions; } if (!(flags & GT_ONLY_GOOD) && rndm (2)) - SET_FLAG (op, FLAG_CURSED); + op->set_flag (FLAG_CURSED); + break; } @@ -973,28 +996,29 @@ break; if (!(flags & GT_ONLY_GOOD) && !(rndm (3))) - SET_FLAG (op, FLAG_CURSED); + op->set_flag (FLAG_CURSED); - set_ring_bonus (op, QUERY_FLAG (op, FLAG_CURSED) ? -DICE2 : DICE2); + set_ring_bonus (op, op->flag [FLAG_CURSED] ? -DICE2 : DICE2); if (op->type != RING) /* Amulets have only one ability */ break; - if (!(rndm (4))) + if (!rndm (4)) { - int d = (rndm (2) || QUERY_FLAG (op, FLAG_CURSED)) ? -DICE2 : DICE2; + int d = (rndm (2) || op->flag [FLAG_CURSED]) ? -DICE2 : DICE2; if (d > 0) op->value *= 3; set_ring_bonus (op, d); - if (!(rndm (4))) + if (!rndm (4)) { - int d = (rndm (3) || QUERY_FLAG (op, FLAG_CURSED)) ? -DICE2 : DICE2; + int d = (rndm (3) || op->flag [FLAG_CURSED]) ? -DICE2 : DICE2; if (d > 0) op->value *= 5; + set_ring_bonus (op, d); } } @@ -1012,7 +1036,7 @@ if (!op->msg && rndm (10)) { /* set the book level properly */ - if (creator->level == 0 || QUERY_FLAG (creator, FLAG_ALIVE)) + if (creator->level == 0 || creator->flag [FLAG_ALIVE]) { if (op->map && op->map->difficulty) op->level = rndm (op->map->difficulty) + rndm (10) + 1; @@ -1035,14 +1059,15 @@ /* for library, chained books. Note that some monsters have no_pick * set - we don't want to set no pick in that case. */ - if (QUERY_FLAG (creator, FLAG_NO_PICK) && !QUERY_FLAG (creator, FLAG_MONSTER)) - SET_FLAG (op, FLAG_NO_PICK); + if (creator->flag [FLAG_NO_PICK] && !creator->flag [FLAG_MONSTER]) + op->set_flag (FLAG_NO_PICK); if (creator->slaying && !op->slaying) /* for check_inv floors */ op->slaying = creator->slaying; break; case SPELLBOOK: - op->value = op->value * op->inv->value; + op->value *= value_factor_from_spell_item (op->inv, 0); + /* add exp so learning gives xp */ op->level = op->inv->level; op->stats.exp = op->value; @@ -1056,42 +1081,34 @@ op->stats.food = op->inv->nrof; op->nrof = 1; /* If the spell changes by level, choose a random level - * for it, and adjust price. If the spell doesn't - * change by level, just set the wand to the level of - * the spell, and value calculation is simpler. + * for it. */ - if (op->inv->duration_modifier || op->inv->dam_modifier || op->inv->range_modifier) - { - op->level = level_for_item (op, difficulty); - op->value = op->value * op->inv->value * (op->level + 50) / (op->inv->level + 50); - } + if (op->inv->duration_modifier + || op->inv->dam_modifier + || op->inv->range_modifier) + op->level = level_for_item (op, difficulty); else - { - op->level = op->inv->level; - op->value = op->value * op->inv->value; - } + op->level = op->inv->level; + + op->value *= value_factor_from_spell_item (op->inv, op); break; case ROD: op->level = level_for_item (op, difficulty); - /* Add 50 to both level an divisor to keep prices a little more - * reasonable. Otherwise, a high level version of a low level - * spell can be worth tons a money (eg, level 20 rod, level 2 spell = - * 10 time multiplier). This way, the value are a bit more reasonable. - */ - op->value = op->value * op->inv->value * (op->level + 50) / (op->inv->level + 50); + op->value *= value_factor_from_spell_item (op->inv, op); + /* maxhp is used to denote how many 'charges' the rod holds before */ if (op->stats.maxhp) - op->stats.maxhp *= MAX (op->inv->stats.sp, op->inv->stats.grace); + op->stats.maxhp *= max (op->inv->stats.sp, op->inv->stats.grace); else - op->stats.maxhp = 2 * MAX (op->inv->stats.sp, op->inv->stats.grace); + op->stats.maxhp = 2 * max (op->inv->stats.sp, op->inv->stats.grace); op->stats.hp = op->stats.maxhp; break; case SCROLL: op->level = level_for_item (op, difficulty); - op->value = op->value * op->inv->value * (op->level + 50) / (op->inv->level + 50); + op->value *= value_factor_from_spell_item (op->inv, op); /* add exp so reading them properly gives xp */ op->stats.exp = op->value / 5; @@ -1109,8 +1126,8 @@ if (flags & GT_STARTEQUIP) { - if (op->nrof < 2 && op->type != CONTAINER && op->type != MONEY && !QUERY_FLAG (op, FLAG_IS_THROWN)) - SET_FLAG (op, FLAG_STARTEQUIP); + if (op->nrof < 2 && op->type != CONTAINER && op->type != MONEY && !op->flag [FLAG_IS_THROWN]) + op->set_flag (FLAG_STARTEQUIP); else if (op->type != MONEY) op->value = 0; } @@ -1131,7 +1148,7 @@ * Allocate and return the pointer to an empty artifactlist structure. */ static artifactlist * -get_empty_artifactlist (void) +get_empty_artifactlist () { return salloc0 (); } @@ -1140,7 +1157,7 @@ * Allocate and return the pointer to an empty artifact structure. */ static artifact * -get_empty_artifact (void) +get_empty_artifact () { return salloc0 (); } @@ -1163,10 +1180,9 @@ * Builds up the lists of artifacts from the file in the libdir. */ void -init_artifacts (void) +init_artifacts () { static int has_been_inited = 0; - char filename[MAX_BUF]; artifact *art = NULL; artifactlist *al; @@ -1175,8 +1191,7 @@ else has_been_inited = 1; - sprintf (filename, "%s/artifacts", settings.datadir); - object_thawer f (filename); + object_thawer f (settings.datadir, "artifacts"); if (!f) return; @@ -1193,11 +1208,11 @@ if (!strcmp (f.get_str (), "all")) break; - char *next, *cp = f.get_str (); - + const char *cp = f.get_str (); + char *next; do { - if ((next = strchr (cp, ','))) + if ((next = (char *)strchr (cp, ','))) *next++ = '\0'; linked_char *tmp = new linked_char; @@ -1271,8 +1286,6 @@ LOG (llevDebug, "Artifact list type %d has %d total chance\n", al->type, al->total_chance); #endif } - - LOG (llevDebug, "done.\n"); } /* @@ -1282,56 +1295,49 @@ void add_abilities (object *op, object *change) { - int i, tmp; - if (change->face != blank_face) - { -#ifdef TREASURE_VERBOSE - LOG (llevDebug, "add_abilities change face: %d\n", change->face); -#endif - op->face = change->face; - } + op->face = change->face; - for (i = 0; i < NUM_STATS; i++) + for (int i = 0; i < NUM_STATS; i++) change_attr_value (&(op->stats), i, change->stats.stat (i)); - op->attacktype |= change->attacktype; - op->path_attuned |= change->path_attuned; + op->attacktype |= change->attacktype; + op->path_attuned |= change->path_attuned; op->path_repelled |= change->path_repelled; - op->path_denied |= change->path_denied; - op->move_type |= change->move_type; - op->stats.luck += change->stats.luck; - - if (QUERY_FLAG (change, FLAG_CURSED)) - SET_FLAG (op, FLAG_CURSED); - if (QUERY_FLAG (change, FLAG_DAMNED)) - SET_FLAG (op, FLAG_DAMNED); - if ((QUERY_FLAG (change, FLAG_CURSED) || QUERY_FLAG (change, FLAG_DAMNED)) && op->magic > 0) - set_abs_magic (op, -op->magic); + op->path_denied |= change->path_denied; + op->move_type |= change->move_type; + op->stats.luck += change->stats.luck; - if (QUERY_FLAG (change, FLAG_LIFESAVE)) - SET_FLAG (op, FLAG_LIFESAVE); - if (QUERY_FLAG (change, FLAG_REFL_SPELL)) - SET_FLAG (op, FLAG_REFL_SPELL); - if (QUERY_FLAG (change, FLAG_STEALTH)) - SET_FLAG (op, FLAG_STEALTH); - if (QUERY_FLAG (change, FLAG_XRAYS)) - SET_FLAG (op, FLAG_XRAYS); - if (QUERY_FLAG (change, FLAG_BLIND)) - SET_FLAG (op, FLAG_BLIND); - if (QUERY_FLAG (change, FLAG_SEE_IN_DARK)) - SET_FLAG (op, FLAG_SEE_IN_DARK); - if (QUERY_FLAG (change, FLAG_REFL_MISSILE)) - SET_FLAG (op, FLAG_REFL_MISSILE); - if (QUERY_FLAG (change, FLAG_MAKE_INVIS)) - SET_FLAG (op, FLAG_MAKE_INVIS); + static const struct copyflags : object::flags_t + { + copyflags () + { + set (FLAG_CURSED); + set (FLAG_DAMNED); + set (FLAG_LIFESAVE); + set (FLAG_REFL_SPELL); + set (FLAG_STEALTH); + set (FLAG_XRAYS); + set (FLAG_BLIND); + set (FLAG_SEE_IN_DARK); + set (FLAG_REFL_MISSILE); + set (FLAG_MAKE_INVIS); + } + } copyflags; - if (QUERY_FLAG (change, FLAG_STAND_STILL)) + // we might want to just copy, but or'ing is what the original code did + op->flag |= change->flag & copyflags; + + if ((change->flag [FLAG_CURSED] || change->flag [FLAG_DAMNED]) && op->magic > 0) + set_abs_magic (op, -op->magic); + + if (change->flag [FLAG_STAND_STILL]) { - CLEAR_FLAG (op, FLAG_ANIMATE); + op->clr_flag (FLAG_ANIMATE); + /* so artifacts will join */ - if (!QUERY_FLAG (op, FLAG_ALIVE)) - op->speed = 0.0; + if (!op->flag [FLAG_ALIVE]) + op->speed = 0.; op->set_speed (op->speed); } @@ -1340,8 +1346,8 @@ op->nrof = rndm (change->nrof) + 1; op->stats.exp += change->stats.exp; /* Speed modifier */ - op->stats.wc += change->stats.wc; - op->stats.ac += change->stats.ac; + op->stats.wc += change->stats.wc; + op->stats.ac += change->stats.ac; if (change->other_arch) { @@ -1354,9 +1360,10 @@ /* Remove any spells this object currently has in it */ op->destroy_inv (false); - object *tmp = arch_to_object (change->other_arch); + object *tmp = change->other_arch->instance (); insert_ob_in_ob (tmp, op); } + /* No harm setting this for potions/horns */ op->other_arch = change->other_arch; } @@ -1382,33 +1389,33 @@ op->stats.maxsp += change->stats.maxsp; if (change->stats.food < 0) - op->stats.food = -(change->stats.food); + op->stats.food = -change->stats.food; else op->stats.food += change->stats.food; if (change->level < 0) - op->level = -(change->level); + op->level = -change->level; else op->level += change->level; if (change->gen_sp_armour < 0) - op->gen_sp_armour = -(change->gen_sp_armour); + op->gen_sp_armour = -change->gen_sp_armour; else - op->gen_sp_armour = (op->gen_sp_armour * (change->gen_sp_armour)) / 100; + op->gen_sp_armour = op->gen_sp_armour * (int)change->gen_sp_armour / 100; op->item_power = change->item_power; - for (i = 0; i < NROFATTACKS; i++) - if (change->resist[i]) - op->resist[i] += change->resist[i]; + for (int i = 0; i < NROFATTACKS; i++) + op->resist[i] += change->resist[i]; if (change->stats.dam) { if (change->stats.dam < 0) - op->stats.dam = (-change->stats.dam); + op->stats.dam = -change->stats.dam; else if (op->stats.dam) { - tmp = (signed char) (((int) op->stats.dam * (int) change->stats.dam) / 10); + int tmp = op->stats.dam * change->stats.dam / 10; + if (tmp == op->stats.dam) { if (change->stats.dam < 10) @@ -1424,25 +1431,25 @@ if (change->weight) { if (change->weight < 0) - op->weight = (-change->weight); + op->weight = -change->weight; else - op->weight = (op->weight * (change->weight)) / 100; + op->weight = op->weight * change->weight / 100; } if (change->last_sp) { if (change->last_sp < 0) - op->last_sp = (-change->last_sp); + op->last_sp = -change->last_sp; else - op->last_sp = (signed char) (((int) op->last_sp * (int) change->last_sp) / (int) 100); + op->last_sp = op->last_sp * (int)change->last_sp / 100; } if (change->gen_sp_armour) { if (change->gen_sp_armour < 0) - op->gen_sp_armour = (-change->gen_sp_armour); + op->gen_sp_armour = -change->gen_sp_armour; else - op->gen_sp_armour = (signed char) (((int) op->gen_sp_armour * ((int) change->gen_sp_armour)) / (int) 100); + op->gen_sp_armour = op->gen_sp_armour * (int)change->gen_sp_armour / 100; } op->value *= change->value; @@ -1450,8 +1457,8 @@ if (change->materials) op->materials = change->materials; - if (change->materialname) - op->materialname = change->materialname; + if (change->material != MATERIAL_NULL) + op->material = change->material; if (change->slaying) op->slaying = change->slaying; @@ -1484,7 +1491,7 @@ name = tmp->name, neg = 0; /* If we match name, then return the opposite of 'neg' */ - if (!strcmp (name, op->name) || (op->arch && !strcmp (name, op->arch->archname))) + if (!strcmp (name, op->arch->archname)) return !neg; /* Set success as true, since if the match was an inverse, it means @@ -1505,20 +1512,18 @@ void give_artifact_abilities (object *op, object *artifct) { - char new_name[MAX_BUF]; + op->title = format ("of %s", &artifct->name); - sprintf (new_name, "of %s", &artifct->name); - op->title = new_name; add_abilities (op, artifct); /* Give out the bonuses */ #if 0 /* Bit verbose, but keep it here until next time I need it... */ { - char identified = QUERY_FLAG (op, FLAG_IDENTIFIED); + char identified = op->flag [FLAG_IDENTIFIED]; - SET_FLAG (op, FLAG_IDENTIFIED); + op->set_flag (FLAG_IDENTIFIED); LOG (llevDebug, "Generated artifact %s %s [%s]\n", op->name, op->title, describe_item (op, NULL)); if (!identified) - CLEAR_FLAG (op, FLAG_IDENTIFIED); + op->clr_flag (FLAG_IDENTIFIED); } #endif return; @@ -1538,11 +1543,9 @@ void generate_artifact (object *op, int difficulty) { - artifactlist *al; artifact *art; - int i; - al = find_artifactlist (op->type); + artifactlist *al = find_artifactlist (op->type); if (al == NULL) { @@ -1552,7 +1555,7 @@ return; } - for (i = 0; i < ARTIFACT_TRIES; i++) + for (int i = 0; i < ARTIFACT_TRIES; i++) { int roll = rndm (al->total_chance); @@ -1602,31 +1605,25 @@ void fix_flesh_item (object *item, object *donor) { - char tmpbuf[MAX_BUF]; - int i; - if (item->type == FLESH && donor) { /* change the name */ - sprintf (tmpbuf, "%s's %s", &donor->name, &item->name); - item->name = tmpbuf; - sprintf (tmpbuf, "%s's %s", &donor->name, &item->name_pl); - item->name_pl = tmpbuf; + item->name = format ("%s's %s", &donor->name, &item->name); + item->name_pl = format ("%s's %s", &donor->name, &item->name_pl); /* weight is FLESH weight/100 * donor */ - if ((item->weight = (signed long) (((double) item->weight / (double) 100.0) * (double) donor->weight)) == 0) - item->weight = 1; + item->weight = max (1, item->weight * donor->weight / 100); /* value is multiplied by level of donor */ item->value *= isqrt (donor->level * 2); /* food value */ - item->stats.food += (donor->stats.hp / 100) + donor->stats.Con; + item->stats.food += donor->stats.hp / 100 + donor->stats.Con; /* flesh items inherit some abilities of donor, but not * full effect. */ - for (i = 0; i < NROFATTACKS; i++) + for (int i = 0; i < NROFATTACKS; i++) item->resist[i] = donor->resist[i] / 2; /* item inherits donor's level (important for quezals) */ @@ -1637,30 +1634,13 @@ item->type = POISON; if (donor->attacktype & AT_ACID) - item->stats.hp = -1 * item->stats.food; + item->stats.hp = -item->stats.food; - SET_FLAG (item, FLAG_NO_STEAL); + item->set_flag (FLAG_NO_STEAL); } } -/* special_potion() - so that old potion code is still done right. */ -int -special_potion (object *op) -{ - if (op->attacktype) - return 1; - - if (op->stats.Str || op->stats.Dex || op->stats.Con || op->stats.Pow || op->stats.Wis || op->stats.Int || op->stats.Cha) - return 1; - - for (int i = 0; i < NROFATTACKS; i++) - if (op->resist[i]) - return 1; - - return 0; -} - -void +static void free_treasurestruct (treasure *t) { if (t->next) free_treasurestruct (t->next); @@ -1670,7 +1650,7 @@ delete t; } -void +static void free_charlinks (linked_char *lc) { if (lc->next) @@ -1679,7 +1659,7 @@ delete lc; } -void +static void free_artifact (artifact *at) { if (at->next) free_artifact (at->next); @@ -1690,34 +1670,3 @@ sfree (at); } -void -free_artifactlist (artifactlist *al) -{ - artifactlist *nextal; - - for (al = first_artifactlist; al; al = nextal) - { - nextal = al->next; - - if (al->items) - free_artifact (al->items); - - sfree (al); - } -} - -void -free_all_treasures (void) -{ - treasurelist *tl, *next; - - for (tl = first_treasurelist; tl; tl = next) - { - clear (tl); - - next = tl->next; - delete tl; - } - - free_artifactlist (first_artifactlist); -}