--- deliantra/server/common/treasure.C 2006/09/10 16:00:23 1.16 +++ deliantra/server/common/treasure.C 2006/12/14 00:08:52 1.26 @@ -1,9 +1,3 @@ - -/* - * static char *rcs_treasure_c = - * "$Id: treasure.C,v 1.16 2006/09/10 16:00:23 root Exp $"; - */ - /* CrossFire, A Multiplayer game for X-windows @@ -24,7 +18,7 @@ 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 crossfire-devel@real-time.com + The authors can be reached via e-mail at */ #define ALLOWED_COMBINATION @@ -60,13 +54,13 @@ warn_archetypes = 1; if (ring_arch == NULL) - ring_arch = find_archetype ("ring"); + ring_arch = archetype::find ("ring"); if (amulet_arch == NULL) - amulet_arch = find_archetype ("amulet"); + amulet_arch = archetype::find ("amulet"); if (staff_arch == NULL) - staff_arch = find_archetype ("staff"); + staff_arch = archetype::find ("staff"); if (crown_arch == NULL) - crown_arch = find_archetype ("crown"); + crown_arch = archetype::find ("crown"); warn_archetypes = prev_warn; } @@ -121,7 +115,7 @@ if (sscanf (cp, "arch %s", variable)) { - if ((t->item = find_archetype (variable)) == NULL) + if ((t->item = archetype::find (variable)) == NULL) LOG (llevError, "Treasure lacks archetype: %s\n", variable); } else if (sscanf (cp, "list %s", variable)) @@ -261,18 +255,14 @@ treasurelist * find_treasurelist (const char *name) { - /* Special cases - randomitems of NULL is to override default. If - * first_treasurelist is null, it means we are on the first pass of - * of loading archetypes, so for now, just return - second pass will - * init these values. - */ - if (!name) + shstr_cmp name_ (name); + + if (!name_) return 0; - if (const char *tmp = shstr::find (name)) - for (treasurelist * tl = first_treasurelist; tl != 0; tl = tl->next) - if (tmp == tl->name) - return tl; + for (treasurelist *tl = first_treasurelist; tl != 0; tl = tl->next) + if (name_ == tl->name) + return tl; if (first_treasurelist) LOG (llevError, "Couldn't find treasurelist %s\n", name); @@ -351,7 +341,11 @@ if (t->name) { if (strcmp (t->name, "NONE") && difficulty >= t->magic) - create_treasure (find_treasurelist (t->name), op, flag, difficulty, tries); + { + treasurelist *tl = find_treasurelist (t->name); + if (tl) + create_treasure (tl, op, flag, difficulty, tries); + } } else { @@ -409,7 +403,11 @@ return; if (difficulty >= t->magic) - create_treasure (find_treasurelist (t->name), op, flag, difficulty, tries); + { + treasurelist *tl = find_treasurelist (t->name); + if (tl) + create_treasure (tl, op, flag, difficulty, tries); + } else if (t->nrof) create_one_treasure (tl, op, flag, difficulty, tries); @@ -460,21 +458,23 @@ * inserted into, and then return that treausre */ object * -generate_treasure (treasurelist * t, int difficulty) +generate_treasure (treasurelist *t, int difficulty) { - object *ob = get_object (), *tmp; + difficulty = clamp (difficulty, 1, settings.max_level); + + object *ob = object::create (), *tmp; create_treasure (t, ob, 0, difficulty, 0); /* Don't want to free the object we are about to return */ tmp = ob->inv; if (tmp != NULL) - remove_ob (tmp); + tmp->remove (); + if (ob->inv) - { - LOG (llevError, "In generate treasure, created multiple objects.\n"); - } - free_object (ob); + LOG (llevError, "In generate treasure, created multiple objects.\n"); + + ob->destroy (); return tmp; } @@ -861,6 +861,12 @@ if (difficulty < 1) difficulty = 1; + if (INVOKE_OBJECT (ADD_BONUS, op, + ARG_OBJECT (creator != op ? creator : 0), + ARG_INT (difficulty), ARG_INT (max_magic), + ARG_INT (flags))) + return; + if (!(flags & GT_MINIMAL)) { if (op->arch == crown_arch) @@ -1005,9 +1011,8 @@ case RING: if (op->arch == NULL) { - remove_ob (op); - free_object (op); - op = NULL; + op->destroy (); + op = 0; break; } @@ -1269,7 +1274,8 @@ fprintf (logfile, " "); fprintf (logfile, "{ (list: %s)\n", &t->name); tl = find_treasurelist (t->name); - dump_monster_treasure_rec (name, tl->items, depth + 2); + 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); @@ -1396,7 +1402,7 @@ art->difficulty = (uint8) value; else if (!strncmp (cp, "Object", 6)) { - art->item = get_object (); + art->item = object::create (); if (!load_object (thawer, art->item, 0)) LOG (llevError, "Init_Artifacts: Could not load object.\n"); @@ -1517,11 +1523,7 @@ /* Remove any spells this object currently has in it */ while (op->inv) - { - tmp_obj = op->inv; - remove_ob (tmp_obj); - free_object (tmp_obj); - } + op->inv->destroy (); tmp_obj = arch_to_object (change->other_arch); insert_ob_in_ob (tmp_obj, op); @@ -1568,12 +1570,8 @@ op->item_power = change->item_power; for (i = 0; i < NROFATTACKS; i++) - { - if (change->resist[i]) - { - op->resist[i] += change->resist[i]; - } - } + if (change->resist[i]) + op->resist[i] += change->resist[i]; if (change->stats.dam) { @@ -1861,7 +1859,7 @@ if (at->allowed) free_charlinks (at->allowed); - at->item->free (1); + at->item->destroy (1); delete at; } @@ -1871,7 +1869,7 @@ { artifactlist *nextal; - for (al = first_artifactlist; al != NULL; al = nextal) + for (al = first_artifactlist; al; al = nextal) { nextal = al->next;