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.22 by root, Mon Jun 4 13:04:00 2007 UTC vs.
Revision 1.26 by root, Tue May 6 16:55:25 2008 UTC

1/* 1/*
2 * This file is part of Crossfire TRT, the Multiplayer Online Role Playing Game. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * Crossfire TRT is free software; you can redistribute it and/or modify it 8 * Deliantra is free software: you can redistribute it and/or modify
9 * under the terms of the GNU General Public License as published by the Free 9 * it under the terms of the GNU General Public License as published by
10 * Software Foundation; either version 2 of the License, or (at your option) 10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version. 11 * (at your option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, but 13 * This program is distributed in the hope that it will be useful,
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License along 18 * You should have received a copy of the GNU General Public License
19 * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 * 20 *
22 * The authors can be reached via e-mail to <crossfire@schmorp.de> 21 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 22 */
24 23
25/* Basic stuff for use with the alchemy code. Clearly some of this stuff 24/* Basic stuff for use with the alchemy code. Clearly some of this stuff
26 * could go into server/alchemy, but I left it here just in case it proves 25 * could go into server/alchemy, but I left it here just in case it proves
27 * more generally useful. 26 * more generally useful.
283 282
284 LOG (llevDebug, "done.\n"); 283 LOG (llevDebug, "done.\n");
285 284
286} 285}
287 286
288/* Borrowed (again) from the artifacts code for this */
289
290void
291dump_alchemy (void)
292{
293 recipelist *fl = formulalist;
294 recipe *formula = NULL;
295 linked_char *next;
296 int num_ingred = 1;
297
298 fprintf (logfile, "\n");
299 while (fl)
300 {
301 fprintf (logfile, "\n Formulae with %d ingredient%s %d Formulae with total_chance=%d\n",
302 num_ingred, num_ingred > 1 ? "s." : ".", fl->number, fl->total_chance);
303 for (formula = fl->items; formula; formula = formula->next)
304 {
305 artifact *art = NULL;
306 char buf[MAX_BUF];
307 size_t i;
308
309 for (i = 0; i < formula->arch_names; i++)
310 {
311 const char *string = formula->arch_name[i];
312
313 if (archetype::find (string) != NULL)
314 {
315 art = locate_recipe_artifact (formula, i);
316 if (!art && strcmp (formula->title, "NONE"))
317 LOG (llevError, "Formula %s has no artifact!\n", &formula->title);
318 else
319 {
320 if (strcmp (formula->title, "NONE"))
321 sprintf (buf, "%s of %s", string, &formula->title);
322 else
323 sprintf (buf, "%s", string);
324 fprintf (logfile, "%-30s(%d) bookchance %3d ", buf, formula->index, formula->chance);
325 fprintf (logfile, "skill %s", &formula->skill);
326 fprintf (logfile, "\n");
327 if (formula->ingred != NULL)
328 {
329 int nval = 0, tval = 0;
330
331 fprintf (logfile, "\tIngred: ");
332 for (next = formula->ingred; next != NULL; next = next->next)
333 {
334 if (nval != 0)
335 fprintf (logfile, ",");
336 fprintf (logfile, "%s(%d)", &next->name, (nval = strtoint (next->name)));
337 tval += nval;
338 }
339 fprintf (logfile, "\n");
340 if (tval != formula->index)
341 fprintf (logfile, "WARNING:ingredient list and formula values not equal.\n");
342 }
343 if (formula->skill != NULL)
344 fprintf (logfile, "\tSkill Required: %s", &formula->skill);
345 if (formula->cauldron != NULL)
346 fprintf (logfile, "\tCauldron: %s\n", &formula->cauldron);
347 fprintf (logfile, "\tDifficulty: %d\t Exp: %d\n", formula->diff, formula->exp);
348 }
349 }
350 else
351 LOG (llevError, "Can't find archetype:%s for formula %s\n", string, &formula->title);
352 }
353 }
354 fprintf (logfile, "\n");
355 fl = fl->next;
356 num_ingred++;
357 }
358}
359
360/* Find a treasure with a matching name. The 'depth' parameter is 287/* Find a treasure with a matching name. The 'depth' parameter is
361 * only there to prevent infinite loops in treasure lists (a list 288 * only there to prevent infinite loops in treasure lists (a list
362 * referencing another list pointing back to the first one). */ 289 * referencing another list pointing back to the first one). */
363archetype * 290archetype *
364find_treasure_by_name (const treasure *t, const char *name, int depth) 291find_treasure_by_name (const treasure *t, const char *name, int depth)
486 413
487 /* failed to find any matching items -- formula should be checked */ 414 /* failed to find any matching items -- formula should be checked */
488 return -1; 415 return -1;
489} 416}
490 417
491/* code copied from dump_alchemy() and modified by Raphael Quinet */
492void
493dump_alchemy_costs (void)
494{
495 recipelist *fl = formulalist;
496 recipe *formula = NULL;
497 linked_char *next;
498 int num_ingred = 1;
499 int num_errors = 0;
500 long cost;
501 long tcost;
502
503 fprintf (logfile, "\n");
504 while (fl)
505 {
506 fprintf (logfile, "\n Formulae with %d ingredient%s %d Formulae with total_chance=%d\n",
507 num_ingred, num_ingred > 1 ? "s." : ".", fl->number, fl->total_chance);
508 for (formula = fl->items; formula; formula = formula->next)
509 {
510 artifact *art = NULL;
511 archetype *at = NULL;
512 char buf[MAX_BUF];
513 size_t i;
514
515 for (i = 0; i < formula->arch_names; i++)
516 {
517 const char *string = formula->arch_name[i];
518
519 if ((at = archetype::find (string)) != NULL)
520 {
521 art = locate_recipe_artifact (formula, i);
522 if (!art && strcmp (formula->title, "NONE"))
523 LOG (llevError, "Formula %s has no artifact\n", &formula->title);
524 else
525 {
526 if (!strcmp (formula->title, "NONE"))
527 sprintf (buf, "%s", string);
528 else
529 sprintf (buf, "%s of %s", string, &formula->title);
530 fprintf (logfile, "\n%-40s bookchance %3d skill %s\n", buf, formula->chance, &(formula->skill));
531 if (formula->ingred != NULL)
532 {
533 tcost = 0;
534 for (next = formula->ingred; next != NULL; next = next->next)
535 {
536 cost = find_ingred_cost (next->name);
537 if (cost < 0)
538 num_errors++;
539 fprintf (logfile, "\t%-33s%5ld\n", &next->name, cost);
540 if (cost < 0 || tcost < 0)
541 tcost = -1;
542 else
543 tcost += cost;
544 }
545 if (art != NULL && art->item != NULL)
546 cost = at->value * art->item->value;
547 else
548 cost = at->value;
549 fprintf (logfile, "\t\tBuying result costs: %5ld", cost);
550 if (formula->yield > 1)
551 {
552 fprintf (logfile, " to %ld (max %d items)\n", cost * formula->yield, formula->yield);
553 cost = cost * (formula->yield + 1L) / 2L;
554 }
555 else
556 fprintf (logfile, "\n");
557 fprintf (logfile, "\t\tIngredients cost: %5ld\n\t\tComment: ", tcost);
558 if (tcost < 0)
559 fprintf (logfile, "Could not find some ingredients. Check the formula!\n");
560 else if (tcost > cost)
561 fprintf (logfile, "Ingredients are much too expensive. Useless formula.\n");
562 else if (tcost * 2L > cost)
563 fprintf (logfile, "Ingredients are too expensive.\n");
564 else if (tcost * 10L < cost)
565 fprintf (logfile, "Ingredients are too cheap.\n");
566 else
567 fprintf (logfile, "OK.\n");
568 }
569 }
570 }
571 else
572 LOG (llevError, "Can't find archetype:%s for formula %s\n", string, &formula->title);
573 }
574 }
575 fprintf (logfile, "\n");
576 fl = fl->next;
577 num_ingred++;
578 }
579 if (num_errors > 0)
580 fprintf (logfile, "WARNING: %d objects required by the formulae do not exist in the game.\n", num_errors);
581}
582
583const char * 418const char *
584ingred_name (const char *name) 419ingred_name (const char *name)
585{ 420{
586 const char *cp = name; 421 const char *cp = name;
587 422
588 if (atoi (cp)) 423 if (atoi (cp))
589 cp = strchr (cp, ' ') + 1; 424 cp = strchr (cp, ' ') + 1;
425
590 return cp; 426 return cp;
591} 427}
592 428
593/* strtoint() - we use this to convert buf into an integer 429/* strtoint() - we use this to convert buf into an integer
594 * equal to the coadded sum of the (lowercase) character 430 * equal to the coadded sum of the (lowercase) character

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines