--- deliantra/server/common/recipe.C 2007/02/16 19:43:41 1.18
+++ deliantra/server/common/recipe.C 2007/11/08 19:43:23 1.24
@@ -1,3 +1,26 @@
+/*
+ * This file is part of Deliantra, the Roguelike Realtime MMORPG.
+ *
+ * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
+ * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
+ * Copyright (©) 1992,2007 Frank Tore Johansen
+ *
+ * Deliantra is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ * The authors can be reached via e-mail to
+ */
+
/* Basic stuff for use with the alchemy code. Clearly some of this stuff
* could go into server/alchemy, but I left it here just in case it proves
* more generally useful.
@@ -34,8 +57,9 @@
tl->total_chance = 0;
tl->number = 0;
- tl->items = NULL;
- tl->next = NULL;
+ tl->items = 0;
+ tl->next = 0;
+
return tl;
}
@@ -243,10 +267,10 @@
LOG (llevDebug, "Checking formulae lists...\n");
- for (fl = formulalist; fl != NULL; fl = fl->next)
+ for (fl = formulalist; fl; fl = fl->next)
{
- for (formula = fl->items; formula != NULL; formula = formula->next)
- for (check = formula->next; check != NULL; check = check->next)
+ for (formula = fl->items; formula; formula = formula->next)
+ for (check = formula->next; check; check = check->next)
if (check->index == formula->index)
{
LOG (llevError, " ERROR: On %d ingred list: ", numb);
@@ -275,7 +299,7 @@
{
fprintf (logfile, "\n Formulae with %d ingredient%s %d Formulae with total_chance=%d\n",
num_ingred, num_ingred > 1 ? "s." : ".", fl->number, fl->total_chance);
- for (formula = fl->items; formula != NULL; formula = formula->next)
+ for (formula = fl->items; formula; formula = formula->next)
{
artifact *art = NULL;
char buf[MAX_BUF];
@@ -338,9 +362,6 @@
archetype *
find_treasure_by_name (const treasure *t, const char *name, int depth)
{
- treasurelist *tl;
- archetype *at;
-
if (depth > 10)
return 0;
@@ -348,37 +369,28 @@
{
if (t->name)
{
- tl = find_treasurelist (t->name);
-
- if (tl)
- {
- at = find_treasure_by_name (tl->items, name, depth + 1);
-
- if (at)
+ if (treasurelist *tl = treasurelist::find (t->name))
+ if (tl->items)
+ if (archetype *at = find_treasure_by_name (tl->items, name, depth + 1))
return at;
- }
}
else
{
- if (t->item && !strcasecmp (t->item->clone.name, name))
+ if (t->item && !strcasecmp (t->item->object::name, name))
return t->item;
}
if (t->next_yes)
- {
- at = find_treasure_by_name (t->next_yes, name, depth);
- if (at)
- return at;
- }
+ if (archetype *at = find_treasure_by_name (t->next_yes, name, depth))
+ return at;
if (t->next_no)
- {
- at = find_treasure_by_name (t->next_no, name, depth);
- if (at)
- return at;
- }
+ if (archetype *at = find_treasure_by_name (t->next_no, name, depth))
+ return at;
+
t = t->next;
}
+
return 0;
}
@@ -393,7 +405,6 @@
long
find_ingred_cost (const char *name)
{
- archetype *at;
archetype *at2;
artifactlist *al;
artifact *art;
@@ -416,17 +427,17 @@
mult = 1;
/* first, try to match the name of an archetype */
- for (at = first_archetype; at != NULL; at = at->next)
+ for_all_archetypes (at)
{
- if (at->clone.title != NULL)
+ if (at->title != NULL)
{
/* inefficient, but who cares? */
- sprintf (part1, "%s %s", &at->clone.name, &at->clone.title);
+ sprintf (part1, "%s %s", &at->object::name, &at->title);
if (!strcasecmp (part1, name))
- return mult * at->clone.value;
+ return mult * at->value;
}
- if (!strcasecmp (at->clone.name, name))
- return mult * at->clone.value;
+ if (!strcasecmp (at->object::name, name))
+ return mult * at->value;
}
/* second, try to match an artifact ("arch of something") */
@@ -436,21 +447,20 @@
strcpy (part1, name);
part1[cp - name] = '\0';
strcpy (part2, cp + 4);
+
/* find the first archetype matching the first part of the name */
- for (at = first_archetype; at != NULL; at = at->next)
- if (!strcasecmp (at->clone.name, part1) && at->clone.title == NULL)
- break;
- if (at != NULL)
- {
- /* find the first artifact derived from that archetype (same type) */
- for (al = first_artifactlist; al != NULL; al = al->next)
- if (al->type == at->clone.type)
- {
- for (art = al->items; art != NULL; art = art->next)
- if (!strcasecmp (art->item->name, part2))
- return mult * at->clone.value * art->item->value;
- }
- }
+ for_all_archetypes (at)
+ if (!strcasecmp (at->object::name, part1) && at->title == NULL)
+ {
+ /* find the first artifact derived from that archetype (same type) */
+ for (al = first_artifactlist; al; al = al->next)
+ if (al->type == at->type)
+ {
+ for (art = al->items; art; art = art->next)
+ if (!strcasecmp (art->item->name, part2))
+ return mult * at->value * art->item->value;
+ }
+ }
}
/* third, try to match a body part ("arch's something") */
@@ -461,14 +471,14 @@
part1[cp - name] = '\0';
strcpy (part2, cp + 3);
/* examine all archetypes matching the first part of the name */
- for (at = first_archetype; at != NULL; at = at->next)
- if (!strcasecmp (at->clone.name, part1) && at->clone.title == NULL)
+ for_all_archetypes (at)
+ if (!strcasecmp (at->object::name, part1) && at->title == NULL)
{
- if (at->clone.randomitems != NULL)
+ if (at->randomitems)
{
- at2 = find_treasure_by_name (at->clone.randomitems->items, part2, 0);
+ at2 = find_treasure_by_name (at->randomitems->items, part2, 0);
if (at2)
- return mult * at2->clone.value * isqrt (at->clone.level * 2);
+ return mult * at2->value * isqrt (at->level * 2);
}
}
}
@@ -494,7 +504,7 @@
{
fprintf (logfile, "\n Formulae with %d ingredient%s %d Formulae with total_chance=%d\n",
num_ingred, num_ingred > 1 ? "s." : ".", fl->number, fl->total_chance);
- for (formula = fl->items; formula != NULL; formula = formula->next)
+ for (formula = fl->items; formula; formula = formula->next)
{
artifact *art = NULL;
archetype *at = NULL;
@@ -532,9 +542,9 @@
tcost += cost;
}
if (art != NULL && art->item != NULL)
- cost = at->clone.value * art->item->value;
+ cost = at->value * art->item->value;
else
- cost = at->clone.value;
+ cost = at->value;
fprintf (logfile, "\t\tBuying result costs: %5ld", cost);
if (formula->yield > 1)
{
@@ -605,7 +615,7 @@
archetype *at = archetype::find (rp->arch_name [idx]);
if (at)
- if (artifactlist *al = find_artifactlist (at->clone.type))
+ if (artifactlist *al = find_artifactlist (at->type))
for (artifact *art = al->items; art; art = art->next)
if (art->item->name == rp->title)
return art;