--- deliantra/server/common/treasure.C 2006/09/03 22:45:55 1.10 +++ deliantra/server/common/treasure.C 2006/09/09 21:48:28 1.15 @@ -1,7 +1,7 @@ /* * static char *rcs_treasure_c = - * "$Id: treasure.C,v 1.10 2006/09/03 22:45:55 root Exp $"; + * "$Id: treasure.C,v 1.15 2006/09/09 21:48:28 root Exp $"; */ /* @@ -257,28 +257,23 @@ treasurelist * find_treasurelist (const char *name) { - const char *tmp = shstr::find (name); - treasurelist *tl; - - /* Special cases - randomitems of none is to override default. If + /* 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 archetyps, so for now, just return - second pass will + * of loading archetypes, so for now, just return - second pass will * init these values. */ - if (!name || !*name) - return NULL; + if (!name) + return 0; - if (tmp != NULL) - for (tl = first_treasurelist; tl != NULL; tl = tl->next) - { - if (tmp == tl->name) - return tl; - } + if (const char *tmp = shstr::find (name)) + for (treasurelist *tl = first_treasurelist; tl != 0; tl = tl->next) + if (tmp == tl->name) + return tl; if (first_treasurelist) - LOG (llevError, "Couldn't find treasurelist %s(%s)\n", name, tmp); + LOG (llevError, "Couldn't find treasurelist %s\n", name); - return NULL; + return 0; } @@ -326,7 +321,7 @@ * in the generated object */ static void -change_treasure (treasure * t, object * op) +change_treasure (treasure *t, object *op) { /* CMD: change_name xxxx */ if (t->change_arch.name) @@ -343,11 +338,10 @@ } void -create_all_treasures (treasure * t, object * op, int flag, int difficulty, int tries) +create_all_treasures (treasure *t, object *op, int flag, int difficulty, int tries) { object *tmp; - if ((int) t->chance >= 100 || (RANDOM () % 100 + 1) < (int) t->chance) { if (t->name) @@ -367,17 +361,19 @@ put_treasure (tmp, op, flag); } } + if (t->next_yes != NULL) create_all_treasures (t->next_yes, op, flag, difficulty, tries); } else if (t->next_no != NULL) create_all_treasures (t->next_no, op, flag, difficulty, tries); + if (t->next != NULL) create_all_treasures (t->next, op, flag, difficulty, tries); } void -create_one_treasure (treasurelist * tl, object * op, int flag, int difficulty, int tries) +create_one_treasure (treasurelist *tl, object * op, int flag, int difficulty, int tries) { int value = RANDOM () % tl->total_chance; treasure *t; @@ -387,9 +383,11 @@ LOG (llevDebug, "create_one_treasure: tries exceeded 100, returning without making treasure\n"); return; } + for (t = tl->items; t != NULL; t = t->next) { value -= t->chance; + if (value < 0) break; } @@ -400,23 +398,30 @@ abort (); return; } + if (t->name) { if (!strcmp (t->name, "NONE")) return; + if (difficulty >= t->magic) create_treasure (find_treasurelist (t->name), op, flag, difficulty, tries); else if (t->nrof) create_one_treasure (tl, op, flag, difficulty, tries); + return; } + if ((t->item && t->item->clone.invisible != 0) || flag != GT_INVISIBLE) { object *tmp = arch_to_object (t->item); + if (!tmp) return; + if (t->nrof && tmp->nrof <= 1) tmp->nrof = RANDOM () % ((int) t->nrof) + 1; + fix_generated_item (tmp, op, difficulty, t->magic, flag); change_treasure (t, tmp); put_treasure (tmp, op, flag); @@ -523,7 +528,7 @@ int level_for_item (const object * op, int difficulty) { - int mult = 0, olevel = 0; + int olevel = 0; if (!op->inv) { @@ -1322,7 +1327,7 @@ char filename[MAX_BUF], buf[HUGE_BUF], *cp, *next; artifact *art = NULL; linked_char *tmp; - int value, comp; + int value; artifactlist *al; if (has_been_inited) @@ -1377,8 +1382,7 @@ art->difficulty = (uint8) value; else if (!strncmp (cp, "Object", 6)) { - art->item = (object *) calloc (1, sizeof (object)); - reset_object (art->item); + art->item = get_object (); if (!load_object (thawer, art->item, 0)) LOG (llevError, "Init_Artifacts: Could not load object.\n"); @@ -1426,7 +1430,7 @@ void add_abilities (object * op, object * change) { - int i, j, tmp; + int i, tmp; if (change->face != blank_face) { @@ -1476,6 +1480,7 @@ /* so artifacts will join */ if (!QUERY_FLAG (op, FLAG_ALIVE)) op->speed = 0.0; + update_ob_speed (op); } @@ -1654,7 +1659,7 @@ */ void -give_artifact_abilities (object * op, object * artifct) +give_artifact_abilities (object *op, object *artifct) { char new_name[MAX_BUF]; @@ -1832,13 +1837,13 @@ void free_artifact (artifact * at) { - if (at->next) free_artifact (at->next); + if (at->allowed) free_charlinks (at->allowed); - delete at->item; + at->item->free (1); delete at; } @@ -1847,13 +1852,14 @@ free_artifactlist (artifactlist * al) { artifactlist *nextal; + for (al = first_artifactlist; al != NULL; al = nextal) { nextal = al->next; + if (al->items) - { - free_artifact (al->items); - } + free_artifact (al->items); + free (al); } }