--- deliantra/server/common/treasure.C 2007/04/16 11:09:30 1.43 +++ deliantra/server/common/treasure.C 2009/11/07 18:30:05 1.92 @@ -1,25 +1,25 @@ /* - * CrossFire, A Multiplayer game for X-windows + * This file is part of Deliantra, the Roguelike Realtime MMORPG. * - * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team - * Copyright (C) 2002 Mark Wedel & Crossfire Development Team - * Copyright (C) 1992 Frank Tore Johansen + * 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 * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * 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 + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * The authors can be reached via e-mail at + * You should have received a copy of the Affero GNU General Public License + * and the GNU General Public License along with this program. If not, see + * . + * + * The authors can be reached via e-mail to */ /* TREASURE_DEBUG does some checking on the treasurelists after loading. @@ -35,7 +35,6 @@ #include #include -#include #include extern char *spell_mapping[]; @@ -49,37 +48,27 @@ treasurelist *, str_hash, str_equal, - slice_allocator< std::pair >, - true + slice_allocator< std::pair > > tl_map_t; static tl_map_t tl_map; -/* - * Initialize global archtype pointers: - */ -void -init_archetype_pointers () +//TODO: class method +static void free_treasurestruct (treasure *t); // bleh desu +static void +clear (treasurelist *tl) { - int prev_warn = warn_archetypes; - - warn_archetypes = 1; - - if (ring_arch == NULL) - ring_arch = archetype::find ("ring"); - if (amulet_arch == NULL) - amulet_arch = archetype::find ("amulet"); - if (staff_arch == NULL) - staff_arch = archetype::find ("staff"); - if (crown_arch == NULL) - crown_arch = archetype::find ("crown"); + if (tl->items) + { + free_treasurestruct (tl->items); + tl->items = 0; + } - warn_archetypes = prev_warn; + tl->total_chance = 0; } /* - * Searches for the given treasurelist in the globally linked list - * of treasurelists which has been built by load_treasures(). + * Searches for the given treasurelist */ treasurelist * treasurelist::find (const char *name) @@ -87,7 +76,7 @@ if (!name) return 0; - AUTODECL (i, tl_map.find (name)); + auto (i, tl_map.find (name)); if (i == tl_map.end ()) return 0; @@ -118,40 +107,53 @@ return tl; } -//TODO: class method -void -clear (treasurelist *tl) +#ifdef TREASURE_DEBUG +/* recursived checks the linked list. Treasurelist is passed only + * so that the treasure name can be printed out + */ +static void +check_treasurelist (const treasure *t, const treasurelist * tl) { - if (tl->items) - { - free_treasurestruct (tl->items); - tl->items = 0; - } + if (t->chance >= 100 && t->next_yes && (t->next || t->next_no)) + LOG (llevError, "Treasurelist %s has element that has 100%% generation, next_yes field as well as next or next_no\n", &tl->name); + + if (t->next) + check_treasurelist (t->next, tl); + + if (t->next_yes) + check_treasurelist (t->next_yes, tl); + + if (t->next_no) + check_treasurelist (t->next_no, tl); } +#endif /* * Reads the lib/treasure file from disk, and parses the contents * into an internal treasure structure (very linked lists) */ static treasure * -load_treasure (object_thawer &f) +read_treasure (object_thawer &f) { treasure *t = new treasure; - int value; - nroftreasures++; + f.next (); for (;;) { - coroapi::cede_every (10); - - f.next (); + coroapi::cede_to_tick (); switch (f.kw) { case KW_arch: - if (!(t->item = archetype::find (f.get_str ()))) - LOG (llevError, "%s:%d treasure references unknown archetype '%s', skipping.\n", f.name, f.linenum, f.get_str ()); + t->item = archetype::find (f.get_str ()); + + if (!t->item) + { + f.parse_warn ("treasure references unknown archetype"); + t->item = archetype::empty; + } + break; case KW_list: f.get (t->name); break; @@ -162,124 +164,68 @@ case KW_nrof: f.get (t->nrof); break; case KW_magic: f.get (t->magic); break; - case KW_yes: t->next_yes = load_treasure (f); break; - case KW_no: t->next_no = load_treasure (f); break; + case KW_yes: t->next_yes = read_treasure (f); continue; + case KW_no: t->next_no = read_treasure (f); continue; case KW_end: + f.next (); return t; case KW_more: - t->next = load_treasure (f); + t->next = read_treasure (f); return t; default: - if (!f.parse_error ("treasure list")) - return t; // error + if (!f.parse_error ("treasurelist", t->name)) + goto error; return t; } - } -} - -#ifdef TREASURE_DEBUG -/* recursived checks the linked list. Treasurelist is passed only - * so that the treasure name can be printed out - */ -static void -check_treasurelist (const treasure *t, const treasurelist * tl) -{ - if (t->chance >= 100 && t->next_yes && (t->next || t->next_no)) - LOG (llevError, "Treasurelist %s has element that has 100%% generation, next_yes field as well as next or next_no\n", &tl->name); - if (t->next) - check_treasurelist (t->next, tl); + f.next (); + } - if (t->next_yes) - check_treasurelist (t->next_yes, tl); + // not reached - if (t->next_no) - check_treasurelist (t->next_no, tl); +error: + delete t; + return 0; } -#endif /* - * Opens LIBDIR/treasure and reads all treasure-declarations from it. * Each treasure is parsed with the help of load_treasure(). */ -bool -load_treasure_file (const char *filename) +treasurelist * +treasurelist::read (object_thawer &f) { - treasure *t; - int comp, line = 0; - - object_thawer f (filename); - - if (!f) - { - LOG (llevError, "Can't open treasure file.\n"); - return false; - } + assert (f.kw == KW_treasure || f.kw == KW_treasureone); - f.next (); + bool one = f.kw == KW_treasureone; + treasurelist *tl = treasurelist::get (f.get_str ()); + clear (tl); + tl->items = read_treasure (f); + if (!tl->items) + return 0; - for (;;) + /* This is a one of the many items on the list should be generated. + * Add up the chance total, and check to make sure the yes & no + * fields of the treasures are not being used. + */ + if (one) { - switch (f.kw) + for (treasure *t = tl->items; t; t = t->next) { - case KW_treasure: - case KW_treasureone: + if (t->next_yes || t->next_no) { - bool one = f.kw == KW_treasureone; - treasurelist *tl = treasurelist::get (f.get_str ()); - - clear (tl); - tl->items = load_treasure (f); - - if (!tl->items) - return false; - - /* This is a one of the many items on the list should be generated. - * Add up the chance total, and check to make sure the yes & no - * fields of the treasures are not being used. - */ - if (one) - { - for (t = tl->items; t; t = t->next) - { -#ifdef TREASURE_DEBUG - if (t->next_yes || t->next_no) - { - LOG (llevError, "Treasure %s is one item, but on treasure %s\n", &tl->name, t->item ? &t->item->name : &t->name); - LOG (llevError, " the next_yes or next_no field is set\n"); - } -#endif - tl->total_chance += t->chance; - } - } + LOG (llevError, "Treasure %s is one item, but on treasure %s\n", &tl->name, t->item ? &t->item->archname : &t->name); + LOG (llevError, " the next_yes or next_no field is set\n"); } - break; - - case KW_EOF: -#ifdef TREASURE_DEBUG - /* Perform some checks on how valid the treasure data actually is. - * verify that list transitions work (ie, the list that it is supposed - * to transition to exists). Also, verify that at least the name - * or archetype is set for each treasure element. - */ - for (treasurelist *tl = first_treasurelist; tl; tl = tl->next) - check_treasurelist (tl->items, tl); -#endif - return true; - default: - if (!f.parse_error ("treasure lists")) - return false; - - break; + tl->total_chance += t->chance; } - - f.next (); } + + return tl; } /* @@ -296,17 +242,29 @@ static void put_treasure (object *op, object *creator, int flags) { - object *tmp; - - /* Bit of a hack - spells should never be put onto the map. The entire - * treasure stuff is a problem - there is no clear idea of knowing - * this is the original object, or if this is an object that should be created - * by another object. - */ - if (flags & GT_ENVIRONMENT && op->type != SPELL) + if (flags & GT_ENVIRONMENT) { - SET_FLAG (op, FLAG_OBJ_ORIGINAL); - op->insert_at (creator, creator, INS_NO_MERGE | INS_NO_WALK_ON); + /* Bit of a hack - spells should never be put onto the map. The entire + * treasure stuff is a problem - there is no clear idea of knowing + * this is the original object, or if this is an object that should be created + * by another object. + */ + //TODO: flag such as objects... as such (no drop, anybody?) + if (op->type == SPELL) + { + op->destroy (); + return; + } + + op->expand_tail (); + + if (!creator->is_on_map () || op->blocked (creator->map, creator->x, creator->y)) + op->destroy (); + else + { + SET_FLAG (op, FLAG_OBJ_ORIGINAL); + op->insert_at (creator, creator, INS_NO_MERGE | INS_NO_WALK_ON); + } } else { @@ -314,9 +272,6 @@ if ((flags & GT_APPLY) && QUERY_FLAG (creator, FLAG_MONSTER)) monster_check_apply (creator, op); - - if ((flags & GT_UPDATE_INV) && (tmp = creator->in_player ())) - esrv_send_item (tmp, op); } } @@ -348,11 +303,14 @@ if (t->name) { if (difficulty >= t->magic) - create_treasure (treasurelist::find (t->name), op, flag, difficulty, tries); + if (treasurelist *tl = treasurelist::find (t->name)) + create_treasure (tl, op, flag, difficulty, tries); + else + LOG (llevError, "create_all_treasures: undefined reference to treasurelist '%s'.\n", &t->name); } else { - if (t->item && (t->item->clone.invisible != 0 || !(flag & GT_INVISIBLE))) + if (t->item && (t->item->invisible != 0 || !(flag & GT_INVISIBLE))) { object *tmp = arch_to_object (t->item); @@ -409,7 +367,7 @@ else if (t->nrof) create_one_treasure (tl, op, flag, difficulty, tries); } - else if (t->item && (t->item->clone.invisible != 0 || flag != GT_INVISIBLE)) + else if (t->item && (t->item->invisible != 0 || flag != GT_INVISIBLE)) { if (object *tmp = arch_to_object (t->item)) { @@ -423,6 +381,12 @@ } } +void +object::create_treasure (treasurelist *tl, int flags) +{ + ::create_treasure (tl, this, flags, map ? map->difficulty : 0); +} + /* This calls the appropriate treasure creation function. tries is passed * to determine how many list transitions or attempts to create treasure * have been made. It is really in place to prevent infinite loops with @@ -443,6 +407,15 @@ return; } + if (op->flag [FLAG_TREASURE_ENV]) + { + // do not generate items when there already is something above the object + if (op->flag [FLAG_IS_FLOOR] && op->above) + return; + + flag |= GT_ENVIRONMENT; + } + if (tl->total_chance) create_one_treasure (tl, op, flag, difficulty, tries); else @@ -459,19 +432,20 @@ { difficulty = clamp (difficulty, 1, settings.max_level); - object *ob = object::create (), *tmp; + object *ob = object::create (); create_treasure (tl, ob, 0, difficulty, 0); /* Don't want to free the object we are about to return */ - tmp = ob->inv; - if (tmp != NULL) + object *tmp = ob->inv; + if (tmp) tmp->remove (); if (ob->inv) LOG (llevError, "In generate treasure, created multiple objects.\n"); ob->destroy (); + return tmp; } @@ -483,7 +457,6 @@ */ static int difftomagic_list[DIFFLEVELS][MAXMAGIC + 1] = { - // chance of magic difficulty // +0 +1 +2 +3 +4 {95, 2, 2, 1, 0}, // 1 @@ -519,34 +492,27 @@ { 0, 0, 0, 0, 100}, // 31 }; - /* calculate the appropriate level for wands staves and scrolls. * This code presumes that op has had its spell object created (in op->inv) * * 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) { - int olevel = 0; - if (!op->inv) { LOG (llevError, "level_for_item: Object %s has no inventory!\n", &op->name); return 0; } - olevel = (int) (op->inv->level + (double) difficulty * (1 - drand48 () * drand48 () * 2)); + int olevel = op->inv->level + int (difficulty * (1. - rndm () * rndm () * 2.)); if (olevel <= 0) - olevel = rndm (1, MIN (op->inv->level, 1)); - - if (olevel > MAXLEVEL) - olevel = MAXLEVEL; + olevel = rndm (1, op->inv->level); - return olevel; + return min (olevel, MAXLEVEL); } /* @@ -559,7 +525,7 @@ * weird integer between 1-31. * */ -int +static int magic_from_difficulty (int difficulty) { int percent = 0, magic = 0; @@ -612,18 +578,21 @@ if (op->arch) { if (op->type == ARMOUR) - ARMOUR_SPEED (op) = (ARMOUR_SPEED (&op->arch->clone) * (100 + magic * 10)) / 100; + ARMOUR_SPEED (op) = (ARMOUR_SPEED (op->arch) * (100 + magic * 10)) / 100; if (magic < 0 && !(rndm (3))) /* You can't just check the weight always */ magic = (-magic); - op->weight = (op->arch->clone.weight * (100 - magic * 10)) / 100; + + op->weight = (op->arch->weight * (100 - magic * 10)) / 100; } else { if (op->type == ARMOUR) ARMOUR_SPEED (op) = (ARMOUR_SPEED (op) * (100 + magic * 10)) / 100; + if (magic < 0 && !(rndm (3))) /* You can't just check the weight always */ magic = (-magic); + op->weight = (op->weight * (100 - magic * 10)) / 100; } } @@ -656,10 +625,9 @@ * 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) @@ -688,7 +656,7 @@ case 4: case 5: case 6: - set_attr_value (&op->stats, r, (signed char) (bonus + get_attr_value (&op->stats, r))); + op->stats.stat (r) += bonus; break; case 7: @@ -792,7 +760,7 @@ * rings and amulets. * Another scheme is used to calculate the magic of weapons and armours. */ -int +static int get_magic (int diff) { int i; @@ -807,6 +775,23 @@ return 4; } +/* 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; +} + #define DICE2 (get_magic(2)==2?2:1) #define DICESPELL (rndm (3) + rndm (3) + rndm (3) + rndm (3) + rndm (3)) @@ -846,10 +831,7 @@ if (op->randomitems && op->type != SPELL) { - create_treasure (op->randomitems, op, flags, difficulty, 0); - if (!op->inv) - LOG (llevDebug, "fix_generated_item: Unable to generate treasure for %s\n", op->debug_desc ()); - + create_treasure (op->randomitems, op, flags & ~GT_ENVIRONMENT, difficulty, 0); /* So the treasure doesn't get created again */ op->randomitems = 0; } @@ -865,7 +847,7 @@ if (!(flags & GT_MINIMAL)) { - if (op->arch == crown_arch) + if (IS_ARCH (op->arch, crown)) { set_magic (difficulty, op, max_magic, flags); num_enchantments = calc_item_power (op, 1); @@ -880,8 +862,7 @@ if ((!was_magic && !rndm (CHANCE_FOR_ARTIFACT)) || op->type == HORN - || difficulty >= settings.max_level) /* high difficulties always generate an artifact, - * used for shop_floors or treasures */ + || difficulty >= settings.max_level) /* high difficulties always generate an artifact, used for shop_floors or treasures */ generate_artifact (op, difficulty); } @@ -933,9 +914,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; } @@ -1003,18 +982,11 @@ } case AMULET: - if (op->arch == amulet_arch) + if (IS_ARCH (op->arch, amulet)) op->value *= 5; /* Since it's not just decoration */ case RING: - if (op->arch == NULL) - { - op->destroy (); - op = 0; - break; - } - - if (op->arch != ring_arch && op->arch != amulet_arch) /* It's a special artifact! */ + if (!IS_ARCH (op->arch, ring) && !IS_ARCH (op->arch, amulet)) /* It's a special artifact! */ break; if (!(flags & GT_ONLY_GOOD) && !(rndm (3))) @@ -1044,8 +1016,8 @@ } } - if (GET_ANIM_ID (op)) - SET_ANIMATION (op, rndm (NUM_ANIMATIONS (op))); + if (op->animation_id) + op->set_anim_frame (rndm (op->anim_frames ())); break; @@ -1070,19 +1042,20 @@ tailor_readable_ob (op, (creator && creator->stats.sp) ? creator->stats.sp : -1); /* books w/ info are worth more! */ op->value *= ((op->level > 10 ? op->level : (op->level + 1) / 2) * ((strlen (op->msg) / 250) + 1)); - /* creator related stuff */ - - /* 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->slaying && !op->slaying) /* for check_inv floors */ - op->slaying = creator->slaying; /* add exp so reading it gives xp (once) */ op->stats.exp = op->value > 10000 ? op->value / 5 : op->value / 10; } + + /* creator related stuff */ + + /* 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->slaying && !op->slaying) /* for check_inv floors */ + op->slaying = creator->slaying; break; case SPELLBOOK: @@ -1126,9 +1099,9 @@ op->value = op->value * op->inv->value * (op->level + 50) / (op->inv->level + 50); /* 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; @@ -1177,7 +1150,7 @@ static artifactlist * get_empty_artifactlist (void) { - return salloc0 (); + return salloc0 (); } /* @@ -1186,7 +1159,7 @@ static artifact * get_empty_artifact (void) { - return salloc0 (); + return salloc0 (); } /* @@ -1204,128 +1177,6 @@ } /* - * For debugging purposes. Dumps all tables. - */ -void -dump_artifacts (void) -{ - artifactlist *al; - artifact *art; - linked_char *next; - - fprintf (logfile, "\n"); - for (al = first_artifactlist; al != NULL; al = al->next) - { - fprintf (logfile, "Artifact has type %d, total_chance=%d\n", al->type, al->total_chance); - for (art = al->items; art != NULL; art = art->next) - { - fprintf (logfile, "Artifact %-30s Difficulty %3d Chance %5d\n", &art->item->name, art->difficulty, art->chance); - if (art->allowed != NULL) - { - fprintf (logfile, "\tallowed combinations:"); - for (next = art->allowed; next != NULL; next = next->next) - fprintf (logfile, "%s,", &next->name); - fprintf (logfile, "\n"); - } - } - } - fprintf (logfile, "\n"); -} - -/* - * For debugging purposes. Dumps all treasures recursively (see below). - */ -void -dump_monster_treasure_rec (const char *name, treasure *t, int depth) -{ - treasurelist *tl; - int i; - - if (depth > 100) - return; - - while (t) - { - if (t->name) - { - for (i = 0; i < depth; i++) - fprintf (logfile, " "); - - fprintf (logfile, "{ (list: %s)\n", &t->name); - - tl = treasurelist::find (t->name); - if (tl) - dump_monster_treasure_rec (name, tl->items, depth + 2); - - for (i = 0; i < depth; i++) - fprintf (logfile, " "); - - fprintf (logfile, "} (end of list: %s)\n", &t->name); - } - else - { - for (i = 0; i < depth; i++) - fprintf (logfile, " "); - - if (t->item && t->item->clone.type == FLESH) - fprintf (logfile, "%s's %s\n", name, &t->item->clone.name); - else - fprintf (logfile, "%s\n", &t->item->clone.name); - } - - if (t->next_yes) - { - for (i = 0; i < depth; i++) - fprintf (logfile, " "); - - fprintf (logfile, " (if yes)\n"); - dump_monster_treasure_rec (name, t->next_yes, depth + 1); - } - - if (t->next_no) - { - for (i = 0; i < depth; i++) - fprintf (logfile, " "); - - fprintf (logfile, " (if no)\n"); - dump_monster_treasure_rec (name, t->next_no, depth + 1); - } - - t = t->next; - } -} - -/* - * For debugging purposes. Dumps all treasures for a given monster. - * Created originally by Raphael Quinet for debugging the alchemy code. - */ -void -dump_monster_treasure (const char *name) -{ - archetype *at; - int found; - - found = 0; - fprintf (logfile, "\n"); - - for (at = first_archetype; at != NULL; at = at->next) - if (!strcasecmp (at->clone.name, name) && at->clone.title == NULL) - { - fprintf (logfile, "treasures for %s (arch: %s)\n", &at->clone.name, &at->name); - if (at->clone.randomitems != NULL) - dump_monster_treasure_rec (at->clone.name, at->clone.randomitems->items, 1); - else - fprintf (logfile, "(nothing)\n"); - - fprintf (logfile, "\n"); - found++; - } - - if (found == 0) - fprintf (logfile, "No objects have the name %s!\n\n", name); -} - -/* * Builds up the lists of artifacts from the file in the libdir. */ void @@ -1347,18 +1198,13 @@ if (!f) return; - f.next (); - for (;;) { switch (f.kw) { case KW_allowed: if (!art) - { - art = get_empty_artifact (); - nrofartifacts++; - } + art = get_empty_artifact (); { if (!strcmp (f.get_str (), "all")) @@ -1368,8 +1214,6 @@ do { - nrofallowedstr++; - if ((next = strchr (cp, ','))) *next++ = '\0'; @@ -1394,6 +1238,8 @@ case KW_object: { art->item = object::create (); + f.get (art->item->name); + f.next (); if (!art->item->parse_kv (f)) LOG (llevError, "Init_Artifacts: Could not load object.\n"); @@ -1429,6 +1275,8 @@ done: for (al = first_artifactlist; al; al = al->next) { + al->total_chance = 0; + for (art = al->items; art; art = art->next) { if (!art->chance) @@ -1444,12 +1292,10 @@ LOG (llevDebug, "done.\n"); } - /* * Used in artifact generation. The bonuses of the first object * is modified by the bonuses of the second object. */ - void add_abilities (object *op, object *change) { @@ -1464,7 +1310,7 @@ } for (i = 0; i < NUM_STATS; i++) - change_attr_value (&(op->stats), i, get_attr_value (&(change->stats), i)); + change_attr_value (&(op->stats), i, change->stats.stat (i)); op->attacktype |= change->attacktype; op->path_attuned |= change->path_attuned; @@ -1522,14 +1368,11 @@ */ if (op->type == HORN || op->type == POTION) { - object *tmp_obj; - /* Remove any spells this object currently has in it */ - while (op->inv) - op->inv->destroy (); + op->destroy_inv (false); - tmp_obj = arch_to_object (change->other_arch); - insert_ob_in_ob (tmp_obj, op); + object *tmp = arch_to_object (change->other_arch); + insert_ob_in_ob (tmp, op); } /* No harm setting this for potions/horns */ op->other_arch = change->other_arch; @@ -1638,14 +1481,15 @@ } static int -legal_artifact_combination (object *op, artifact * art) +legal_artifact_combination (object *op, artifact *art) { int neg, success = 0; linked_char *tmp; const char *name; - if (art->allowed == (linked_char *) NULL) + if (!art->allowed) return 1; /* Ie, "all" */ + for (tmp = art->allowed; tmp; tmp = tmp->next) { #ifdef TREASURE_VERBOSE @@ -1657,7 +1501,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->name))) + if (!strcmp (name, op->name) || (op->arch && !strcmp (name, op->arch->archname))) return !neg; /* Set success as true, since if the match was an inverse, it means @@ -1666,6 +1510,7 @@ else if (neg) success = 1; } + return success; } @@ -1742,9 +1587,11 @@ #endif return; } - if (!strcmp (art->item->name, "NONE")) + + if (art->item->name == shstr_NONE) return; - if (FABS (op->magic) < art->item->magic) + + if (fabs (op->magic) < art->item->magic) continue; /* Not magic enough to be this item */ /* Map difficulty not high enough */ @@ -1805,31 +1652,15 @@ /* if donor has some attacktypes, the flesh is poisonous */ if (donor->attacktype & AT_POISON) item->type = POISON; + if (donor->attacktype & AT_ACID) item->stats.hp = -1 * item->stats.food; + SET_FLAG (item, 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); @@ -1839,7 +1670,7 @@ delete t; } -void +static void free_charlinks (linked_char *lc) { if (lc->next) @@ -1848,45 +1679,14 @@ delete lc; } -void +static void free_artifact (artifact *at) { if (at->next) free_artifact (at->next); if (at->allowed) free_charlinks (at->allowed); - at->item->destroy (1); + at->item->destroy (); 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); -}