--- deliantra/server/common/treasure.C 2006/09/03 14:33:48 1.9 +++ deliantra/server/common/treasure.C 2006/09/07 09:37:12 1.14 @@ -1,7 +1,7 @@ /* * static char *rcs_treasure_c = - * "$Id: treasure.C,v 1.9 2006/09/03 14:33:48 elmex Exp $"; + * "$Id: treasure.C,v 1.14 2006/09/07 09:37:12 pippijn 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,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) @@ -1424,7 +1430,7 @@ void add_abilities (object * op, object * change) { - int i, j, tmp; + int i, tmp; if (change->face != blank_face) { @@ -1474,6 +1480,7 @@ /* so artifacts will join */ if (!QUERY_FLAG (op, FLAG_ALIVE)) op->speed = 0.0; + update_ob_speed (op); } @@ -1652,7 +1659,7 @@ */ void -give_artifact_abilities (object * op, object * artifct) +give_artifact_abilities (object *op, object *artifct) { char new_name[MAX_BUF];