--- deliantra/server/common/treasure.C 2008/04/02 11:13:52 1.70 +++ deliantra/server/common/treasure.C 2009/05/05 04:51:56 1.85 @@ -1,7 +1,7 @@ /* * This file is part of Deliantra, the Roguelike Realtime MMORPG. * - * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Deliantra team + * 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 * @@ -34,7 +34,6 @@ #include #include -#include #include extern char *spell_mapping[]; @@ -48,8 +47,7 @@ treasurelist *, str_hash, str_equal, - slice_allocator< std::pair >, - true + slice_allocator< std::pair > > tl_map_t; static tl_map_t tl_map; @@ -146,7 +144,14 @@ switch (f.kw) { case KW_arch: - t->item = archetype::get (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; @@ -170,13 +175,19 @@ default: if (!f.parse_error ("treasurelist", t->name)) - return 0; + goto error; return t; } f.next (); } + + // not reached + +error: + delete t; + return 0; } /* @@ -245,7 +256,7 @@ op->expand_tail (); - if (op->blocked (creator->map, creator->x, creator->y)) + if (!creator->is_on_map () || op->blocked (creator->map, creator->x, creator->y)) op->destroy (); else { @@ -259,10 +270,6 @@ if ((flags & GT_APPLY) && QUERY_FLAG (creator, FLAG_MONSTER)) monster_check_apply (creator, op); - - if (flags & GT_UPDATE_INV) - if (object *tmp = creator->in_player ()) - esrv_send_item (tmp, op); } } @@ -436,6 +443,7 @@ LOG (llevError, "In generate treasure, created multiple objects.\n"); ob->destroy (); + return tmp; } @@ -572,14 +580,17 @@ if (magic < 0 && !(rndm (3))) /* You can't just check the weight always */ magic = (-magic); + 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; } } @@ -818,7 +829,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); @@ -833,8 +844,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); } @@ -886,9 +896,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; } @@ -956,18 +964,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))) @@ -997,8 +998,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; @@ -1157,128 +1158,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->type == FLESH) - fprintf (logfile, "%s's %s\n", name, &t->item->object::name); - else - fprintf (logfile, "%s\n", &t->item->object::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_all_archetypes (at) - if (!strcasecmp (at->object::name, name) && at->title == NULL) - { - fprintf (logfile, "treasures for %s (arch: %s)\n", &at->object::name, &at->archname); - if (at->randomitems != NULL) - dump_monster_treasure_rec (at->object::name, at->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 @@ -1470,14 +1349,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; @@ -1692,9 +1568,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 */ @@ -1755,8 +1633,10 @@ /* 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); } } @@ -1803,7 +1683,7 @@ if (at->next) free_artifact (at->next); if (at->allowed) free_charlinks (at->allowed); - at->item->destroy (1); + at->item->destroy (); sfree (at); }