ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/recipe.C
(Generate patch)

Comparing deliantra/server/common/recipe.C (file contents):
Revision 1.18 by root, Fri Feb 16 19:43:41 2007 UTC vs.
Revision 1.19 by root, Mon Apr 16 06:23:40 2007 UTC

32{ 32{
33 recipelist *tl = new recipelist; 33 recipelist *tl = new recipelist;
34 34
35 tl->total_chance = 0; 35 tl->total_chance = 0;
36 tl->number = 0; 36 tl->number = 0;
37 tl->items = NULL; 37 tl->items = 0;
38 tl->next = NULL; 38 tl->next = 0;
39
39 return tl; 40 return tl;
40} 41}
41 42
42static recipe * 43static recipe *
43get_empty_formula (void) 44get_empty_formula (void)
241 recipe *check, *formula; 242 recipe *check, *formula;
242 int numb = 1; 243 int numb = 1;
243 244
244 LOG (llevDebug, "Checking formulae lists...\n"); 245 LOG (llevDebug, "Checking formulae lists...\n");
245 246
246 for (fl = formulalist; fl != NULL; fl = fl->next) 247 for (fl = formulalist; fl; fl = fl->next)
247 { 248 {
248 for (formula = fl->items; formula != NULL; formula = formula->next) 249 for (formula = fl->items; formula; formula = formula->next)
249 for (check = formula->next; check != NULL; check = check->next) 250 for (check = formula->next; check; check = check->next)
250 if (check->index == formula->index) 251 if (check->index == formula->index)
251 { 252 {
252 LOG (llevError, " ERROR: On %d ingred list: ", numb); 253 LOG (llevError, " ERROR: On %d ingred list: ", numb);
253 LOG (llevError, "Formulae [%s] of %s and [%s] of %s have matching index id (%d)\n", 254 LOG (llevError, "Formulae [%s] of %s and [%s] of %s have matching index id (%d)\n",
254 formula->arch_name[0], &formula->title, check->arch_name[0], &check->title, formula->index); 255 formula->arch_name[0], &formula->title, check->arch_name[0], &check->title, formula->index);
273 fprintf (logfile, "\n"); 274 fprintf (logfile, "\n");
274 while (fl) 275 while (fl)
275 { 276 {
276 fprintf (logfile, "\n Formulae with %d ingredient%s %d Formulae with total_chance=%d\n", 277 fprintf (logfile, "\n Formulae with %d ingredient%s %d Formulae with total_chance=%d\n",
277 num_ingred, num_ingred > 1 ? "s." : ".", fl->number, fl->total_chance); 278 num_ingred, num_ingred > 1 ? "s." : ".", fl->number, fl->total_chance);
278 for (formula = fl->items; formula != NULL; formula = formula->next) 279 for (formula = fl->items; formula; formula = formula->next)
279 { 280 {
280 artifact *art = NULL; 281 artifact *art = NULL;
281 char buf[MAX_BUF]; 282 char buf[MAX_BUF];
282 size_t i; 283 size_t i;
283 284
336 * only there to prevent infinite loops in treasure lists (a list 337 * only there to prevent infinite loops in treasure lists (a list
337 * referencing another list pointing back to the first one). */ 338 * referencing another list pointing back to the first one). */
338archetype * 339archetype *
339find_treasure_by_name (const treasure *t, const char *name, int depth) 340find_treasure_by_name (const treasure *t, const char *name, int depth)
340{ 341{
341 treasurelist *tl;
342 archetype *at;
343
344 if (depth > 10) 342 if (depth > 10)
345 return 0; 343 return 0;
346 344
347 while (t) 345 while (t)
348 { 346 {
349 if (t->name) 347 if (t->name)
350 { 348 {
351 tl = find_treasurelist (t->name); 349 if (treasurelist *tl = treasurelist::find (t->name))
352
353 if (tl) 350 if (tl->items)
354 {
355 at = find_treasure_by_name (tl->items, name, depth + 1); 351 if (archetype *at = find_treasure_by_name (tl->items, name, depth + 1))
356
357 if (at)
358 return at; 352 return at;
359 }
360 } 353 }
361 else 354 else
362 { 355 {
363 if (t->item && !strcasecmp (t->item->clone.name, name)) 356 if (t->item && !strcasecmp (t->item->clone.name, name))
364 return t->item; 357 return t->item;
365 } 358 }
366 359
367 if (t->next_yes) 360 if (t->next_yes)
368 {
369 at = find_treasure_by_name (t->next_yes, name, depth); 361 if (archetype *at = find_treasure_by_name (t->next_yes, name, depth))
370 if (at)
371 return at; 362 return at;
372 }
373 363
374 if (t->next_no) 364 if (t->next_no)
375 {
376 at = find_treasure_by_name (t->next_no, name, depth); 365 if (archetype *at = find_treasure_by_name (t->next_no, name, depth))
377 if (at)
378 return at; 366 return at;
379 } 367
380 t = t->next; 368 t = t->next;
381 } 369 }
370
382 return 0; 371 return 0;
383} 372}
384 373
385/* If several archetypes have the same name, the value of the first 374/* If several archetypes have the same name, the value of the first
386 * one with that name will be returned. This happens for the 375 * one with that name will be returned. This happens for the
435 { 424 {
436 strcpy (part1, name); 425 strcpy (part1, name);
437 part1[cp - name] = '\0'; 426 part1[cp - name] = '\0';
438 strcpy (part2, cp + 4); 427 strcpy (part2, cp + 4);
439 /* find the first archetype matching the first part of the name */ 428 /* find the first archetype matching the first part of the name */
440 for (at = first_archetype; at != NULL; at = at->next) 429 for (at = first_archetype; at; at = at->next)
441 if (!strcasecmp (at->clone.name, part1) && at->clone.title == NULL) 430 if (!strcasecmp (at->clone.name, part1) && at->clone.title == NULL)
442 break; 431 break;
443 if (at != NULL) 432 if (at != NULL)
444 { 433 {
445 /* find the first artifact derived from that archetype (same type) */ 434 /* find the first artifact derived from that archetype (same type) */
446 for (al = first_artifactlist; al != NULL; al = al->next) 435 for (al = first_artifactlist; al; al = al->next)
447 if (al->type == at->clone.type) 436 if (al->type == at->clone.type)
448 { 437 {
449 for (art = al->items; art != NULL; art = art->next) 438 for (art = al->items; art; art = art->next)
450 if (!strcasecmp (art->item->name, part2)) 439 if (!strcasecmp (art->item->name, part2))
451 return mult * at->clone.value * art->item->value; 440 return mult * at->clone.value * art->item->value;
452 } 441 }
453 } 442 }
454 } 443 }
459 { 448 {
460 strcpy (part1, name); 449 strcpy (part1, name);
461 part1[cp - name] = '\0'; 450 part1[cp - name] = '\0';
462 strcpy (part2, cp + 3); 451 strcpy (part2, cp + 3);
463 /* examine all archetypes matching the first part of the name */ 452 /* examine all archetypes matching the first part of the name */
464 for (at = first_archetype; at != NULL; at = at->next) 453 for (at = first_archetype; at; at = at->next)
465 if (!strcasecmp (at->clone.name, part1) && at->clone.title == NULL) 454 if (!strcasecmp (at->clone.name, part1) && at->clone.title == NULL)
466 { 455 {
467 if (at->clone.randomitems != NULL) 456 if (at->clone.randomitems)
468 { 457 {
469 at2 = find_treasure_by_name (at->clone.randomitems->items, part2, 0); 458 at2 = find_treasure_by_name (at->clone.randomitems->items, part2, 0);
470 if (at2) 459 if (at2)
471 return mult * at2->clone.value * isqrt (at->clone.level * 2); 460 return mult * at2->clone.value * isqrt (at->clone.level * 2);
472 } 461 }
492 fprintf (logfile, "\n"); 481 fprintf (logfile, "\n");
493 while (fl) 482 while (fl)
494 { 483 {
495 fprintf (logfile, "\n Formulae with %d ingredient%s %d Formulae with total_chance=%d\n", 484 fprintf (logfile, "\n Formulae with %d ingredient%s %d Formulae with total_chance=%d\n",
496 num_ingred, num_ingred > 1 ? "s." : ".", fl->number, fl->total_chance); 485 num_ingred, num_ingred > 1 ? "s." : ".", fl->number, fl->total_chance);
497 for (formula = fl->items; formula != NULL; formula = formula->next) 486 for (formula = fl->items; formula; formula = formula->next)
498 { 487 {
499 artifact *art = NULL; 488 artifact *art = NULL;
500 archetype *at = NULL; 489 archetype *at = NULL;
501 char buf[MAX_BUF]; 490 char buf[MAX_BUF];
502 size_t i; 491 size_t i;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines