--- deliantra/server/common/treasure.C 2006/09/03 00:18:40 1.7 +++ deliantra/server/common/treasure.C 2006/09/04 13:55:54 1.12 @@ -1,7 +1,7 @@ /* * static char *rcs_treasure_c = - * "$Id: treasure.C,v 1.7 2006/09/03 00:18:40 root Exp $"; + * "$Id: treasure.C,v 1.12 2006/09/04 13:55:54 root Exp $"; */ /* @@ -123,7 +123,7 @@ LOG (llevError, "Treasure lacks archetype: %s\n", variable); } else if (sscanf (cp, "list %s", variable)) - t->name = variable; + t->name = variable; else if (sscanf (cp, "change_name %s", variable)) t->change_arch.name = variable; else if (sscanf (cp, "change_title %s", variable)) @@ -257,24 +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 (const char *tmp = shstr::find (name)) + for (treasurelist *tl = first_treasurelist; tl != 0; tl = tl->next) if (tmp == tl->name) - return tl; + return tl; - LOG (llevError, "Couldn't find treasurelist %s\n", name); - return NULL; + if (first_treasurelist) + LOG (llevError, "Couldn't find treasurelist %s\n", name); + + return 0; } @@ -322,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) @@ -339,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) @@ -363,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; @@ -383,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; } @@ -396,25 +398,32 @@ 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); + +// fix_generated_item (tmp, op, difficulty, t->magic, flag); +// change_treasure (t, tmp); put_treasure (tmp, op, flag); } } @@ -1373,10 +1382,11 @@ art->difficulty = (uint8) value; else if (!strncmp (cp, "Object", 6)) { - art->item = (object *) calloc (1, sizeof (object)); - reset_object (art->item); - if (!load_object (thawer, art->item, LO_LINEMODE, 0)) + art->item = get_object (); + + if (!load_object (thawer, art->item, 0)) LOG (llevError, "Init_Artifacts: Could not load object.\n"); + art->item->name = strchr (cp, ' ') + 1; al = find_artifactlist (art->item->type); if (al == NULL) @@ -1470,6 +1480,7 @@ /* so artifacts will join */ if (!QUERY_FLAG (op, FLAG_ALIVE)) op->speed = 0.0; + update_ob_speed (op); } @@ -1648,7 +1659,7 @@ */ void -give_artifact_abilities (object * op, object * artifct) +give_artifact_abilities (object *op, object *artifct) { char new_name[MAX_BUF]; @@ -1810,7 +1821,8 @@ free_treasurestruct (t->next_yes); if (t->next_no) free_treasurestruct (t->next_no); - free (t); + + delete t; } void