--- deliantra/server/common/treasure.C 2007/01/27 02:19:36 1.35 +++ deliantra/server/common/treasure.C 2007/03/01 12:28:16 1.39 @@ -435,12 +435,12 @@ void create_treasure (treasurelist *tl, object *op, int flag, int difficulty, int tries) { - if (tries++ > 100) { LOG (llevDebug, "createtreasure: tries exceeded 100, returning without making treasure\n"); return; } + if (tl->total_chance) create_one_treasure (tl, op, flag, difficulty, tries); else @@ -833,7 +833,6 @@ * a working object - don't change magic, value, etc, but set it material * type as appropriate, for objects that need spell objects, set those, etc */ - void fix_generated_item (object *op, object *creator, int difficulty, int max_magic, int flags) { @@ -1176,7 +1175,6 @@ /* * Allocate and return the pointer to an empty artifactlist structure. */ - static artifactlist * get_empty_artifactlist (void) { @@ -1193,7 +1191,6 @@ /* * Allocate and return the pointer to an empty artifact structure. */ - static artifact * get_empty_artifact (void) { @@ -1201,6 +1198,7 @@ if (a == NULL) fatal (OUT_OF_MEMORY); + a->item = NULL; a->next = NULL; a->chance = 0; @@ -1213,22 +1211,21 @@ * Searches the artifact lists and returns one that has the same type * of objects on it. */ - artifactlist * find_artifactlist (int type) { artifactlist *al; - for (al = first_artifactlist; al != NULL; al = al->next) + for (al = first_artifactlist; al; al = al->next) if (al->type == type) return al; - return NULL; + + return 0; } /* * For debugging purposes. Dumps all tables. */ - void dump_artifacts (void) { @@ -1245,7 +1242,7 @@ fprintf (logfile, "Artifact %-30s Difficulty %3d Chance %5d\n", &art->item->name, art->difficulty, art->chance); if (art->allowed != NULL) { - fprintf (logfile, "\tAllowed combinations:"); + fprintf (logfile, "\tallowed combinations:"); for (next = art->allowed; next != NULL; next = next->next) fprintf (logfile, "%s,", &next->name); fprintf (logfile, "\n"); @@ -1323,6 +1320,7 @@ found = 0; fprintf (logfile, "\n"); + for (at = first_archetype; at != NULL; at = at->next) if (!strcasecmp (at->clone.name, name) && at->clone.title == NULL) { @@ -1331,9 +1329,11 @@ dump_monster_treasure_rec (at->clone.name, at->clone.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); } @@ -1341,15 +1341,12 @@ /* * Builds up the lists of artifacts from the file in the libdir. */ - void init_artifacts (void) { static int has_been_inited = 0; - char filename[MAX_BUF], buf[HUGE_BUF], *cp, *next; + char filename[MAX_BUF]; artifact *art = NULL; - linked_char *tmp; - int value; artifactlist *al; if (has_been_inited) @@ -1358,78 +1355,94 @@ has_been_inited = 1; sprintf (filename, "%s/artifacts", settings.datadir); - object_thawer thawer (filename); + object_thawer f (filename); - if (!thawer) + if (!f) return; - while (fgets (buf, HUGE_BUF, thawer) != NULL) - { - if (*buf == '#') - continue; - if ((cp = strchr (buf, '\n')) != NULL) - *cp = '\0'; - cp = buf; - while (*cp == ' ') /* Skip blanks */ - cp++; - if (*cp == '\0') - continue; + f.next (); - if (!strncmp (cp, "Allowed", 7)) + for (;;) + { + switch (f.kw) { - if (art == NULL) - { - art = get_empty_artifact (); - nrofartifacts++; - } - cp = strchr (cp, ' ') + 1; - if (!strcmp (cp, "all")) - continue; + case KW_allowed: + if (!art) + { + art = get_empty_artifact (); + nrofartifacts++; + } - do { - nrofallowedstr++; - if ((next = strchr (cp, ',')) != NULL) - *(next++) = '\0'; - tmp = new linked_char; - - tmp->name = cp; - tmp->next = art->allowed; - art->allowed = tmp; + if (!strcmp (f.get_str (), "all")) + break; + + char *next, *cp = f.get_str (); + + do + { + nrofallowedstr++; + + if ((next = strchr (cp, ','))) + *next++ = '\0'; + + linked_char *tmp = new linked_char; + + tmp->name = cp; + tmp->next = art->allowed; + art->allowed = tmp; + } + while ((cp = next)); } - while ((cp = next) != NULL); - } - else if (sscanf (cp, "chance %d", &value)) - art->chance = (uint16) value; - else if (sscanf (cp, "difficulty %d", &value)) - art->difficulty = (uint8) value; - else if (!strncmp (cp, "Object", 6)) - { - art->item = object::create (); + break; + + case KW_chance: + f.get (art->chance); + break; - if (!load_object (thawer, art->item, 0)) - LOG (llevError, "Init_Artifacts: Could not load object.\n"); + case KW_difficulty: + f.get (art->difficulty); + break; - art->item->name = strchr (cp, ' ') + 1; - al = find_artifactlist (art->item->type); - if (al == NULL) + case KW_object: { - al = get_empty_artifactlist (); - al->type = art->item->type; - al->next = first_artifactlist; - first_artifactlist = al; + art->item = object::create (); + + if (!art->item->parse_kv (f)) + LOG (llevError, "Init_Artifacts: Could not load object.\n"); + + al = find_artifactlist (art->item->type); + + if (!al) + { + al = get_empty_artifactlist (); + al->type = art->item->type; + al->next = first_artifactlist; + first_artifactlist = al; + } + + art->next = al->items; + al->items = art; + art = 0; } - art->next = al->items; - al->items = art; - art = NULL; + continue; + + case KW_EOF: + goto done; + + default: + if (!f.parse_error ("artifacts file")) + cleanup ("artifacts file required"); + break; } - else - LOG (llevError, "Unknown input in artifact file: %s\n", buf); + + f.next (); } - for (al = first_artifactlist; al != NULL; al = al->next) +done: + for (al = first_artifactlist; al; al = al->next) { - for (art = al->items; art != NULL; art = art->next) + for (art = al->items; art; art = art->next) { if (!art->chance) LOG (llevError, "Warning: artifact with no chance: %s\n", &art->item->name); @@ -1621,8 +1634,8 @@ op->value *= change->value; - if (change->material) - op->material = change->material; + if (change->materials) + op->materials = change->materials; if (change->materialname) op->materialname = change->materialname;