… | |
… | |
10 | * Ingredients are just comma delimited list of archetype (or object) |
10 | * Ingredients are just comma delimited list of archetype (or object) |
11 | * names. |
11 | * names. |
12 | */ |
12 | */ |
13 | |
13 | |
14 | /* Example 'formula' entry in libdir/formulae: |
14 | /* Example 'formula' entry in libdir/formulae: |
15 | * Object transparency |
15 | * object transparency |
16 | * chance 10 |
16 | * chance 10 |
17 | * ingred dust of beholdereye,gem |
17 | * ingred dust of beholdereye,gem |
18 | * arch potion_generic |
18 | * arch potion_generic |
19 | */ |
19 | */ |
20 | |
20 | |
… | |
… | |
60 | t->next = NULL; |
60 | t->next = NULL; |
61 | return t; |
61 | return t; |
62 | } |
62 | } |
63 | |
63 | |
64 | /* get_formulalist() - returns pointer to the formula list */ |
64 | /* get_formulalist() - returns pointer to the formula list */ |
65 | |
|
|
66 | recipelist * |
65 | recipelist * |
67 | get_formulalist (int i) |
66 | get_formulalist (int i) |
68 | { |
67 | { |
69 | recipelist *fl = formulalist; |
68 | recipelist *fl = formulalist; |
70 | int number = i; |
69 | int number = i; |
… | |
… | |
73 | { |
72 | { |
74 | if (!(fl = fl->next)) |
73 | if (!(fl = fl->next)) |
75 | break; |
74 | break; |
76 | number--; |
75 | number--; |
77 | } |
76 | } |
|
|
77 | |
78 | return fl; |
78 | return fl; |
79 | } |
79 | } |
80 | |
80 | |
81 | /* check_recipe() - makes sure we actually have the requested artifact |
81 | /* check_recipe() - makes sure we actually have the requested artifact |
82 | * and archetype. */ |
82 | * and archetype. */ |
83 | |
|
|
84 | static int |
83 | static int |
85 | check_recipe (const recipe *rp) |
84 | check_recipe (const recipe *rp) |
86 | { |
85 | { |
87 | size_t i; |
86 | size_t i; |
88 | int result; |
87 | int result = 1; |
89 | |
88 | |
90 | result = 1; |
|
|
91 | for (i = 0; i < rp->arch_names; i++) |
89 | for (i = 0; i < rp->arch_names; i++) |
92 | { |
90 | { |
93 | if (archetype::find (rp->arch_name[i]) != NULL) |
91 | if (archetype::find (rp->arch_name[i]) != NULL) |
94 | { |
92 | { |
95 | artifact *art = locate_recipe_artifact (rp, i); |
93 | artifact *art = locate_recipe_artifact (rp, i); |
… | |
… | |
108 | } |
106 | } |
109 | |
107 | |
110 | return result; |
108 | return result; |
111 | } |
109 | } |
112 | |
110 | |
113 | |
|
|
114 | /* |
111 | /* |
115 | * init_formulae() - Builds up the lists of formula from the file in |
112 | * init_formulae() - Builds up the lists of formula from the file in |
116 | * the libdir. -b.t. |
113 | * the libdir. -b.t. |
117 | */ |
114 | */ |
118 | |
|
|
119 | void |
115 | void |
120 | init_formulae (void) |
116 | init_formulae (void) |
121 | { |
117 | { |
122 | static int has_been_done = 0; |
118 | static int has_been_done = 0; |
123 | FILE *fp; |
119 | FILE *fp; |
… | |
… | |
151 | *cp = '\0'; |
147 | *cp = '\0'; |
152 | cp = buf; |
148 | cp = buf; |
153 | while (*cp == ' ') /* Skip blanks */ |
149 | while (*cp == ' ') /* Skip blanks */ |
154 | cp++; |
150 | cp++; |
155 | |
151 | |
156 | if (!strncmp (cp, "Object", 6)) |
152 | if (!strncmp (cp, "object", 6)) |
157 | { |
153 | { |
158 | formula = get_empty_formula (); |
154 | formula = get_empty_formula (); |
159 | formula->title = strchr (cp, ' ') + 1; |
155 | formula->title = strchr (cp, ' ') + 1; |
160 | } |
156 | } |
161 | else if (!strncmp (cp, "keycode", 7)) |
157 | else if (!strncmp (cp, "keycode", 7)) |
162 | { |
|
|
163 | formula->keycode = strchr (cp, ' ') + 1; |
158 | formula->keycode = strchr (cp, ' ') + 1; |
164 | } |
|
|
165 | else if (sscanf (cp, "trans %d", &value)) |
159 | else if (sscanf (cp, "trans %d", &value)) |
166 | { |
|
|
167 | formula->transmute = (uint16) value; |
160 | formula->transmute = (uint16) value; |
168 | } |
|
|
169 | else if (sscanf (cp, "yield %d", &value)) |
161 | else if (sscanf (cp, "yield %d", &value)) |
170 | { |
|
|
171 | formula->yield = (uint16) value; |
162 | formula->yield = (uint16) value; |
172 | } |
|
|
173 | else if (sscanf (cp, "chance %d", &value)) |
163 | else if (sscanf (cp, "chance %d", &value)) |
174 | { |
|
|
175 | formula->chance = (uint16) value; |
164 | formula->chance = (uint16) value; |
176 | } |
|
|
177 | else if (sscanf (cp, "exp %d", &value)) |
165 | else if (sscanf (cp, "exp %d", &value)) |
178 | { |
|
|
179 | formula->exp = (uint16) value; |
166 | formula->exp = (uint16) value; |
180 | } |
|
|
181 | else if (sscanf (cp, "diff %d", &value)) |
167 | else if (sscanf (cp, "diff %d", &value)) |
182 | { |
|
|
183 | formula->diff = (uint16) value; |
168 | formula->diff = (uint16) value; |
184 | } |
|
|
185 | else if (!strncmp (cp, "ingred", 6)) |
169 | else if (!strncmp (cp, "ingred", 6)) |
186 | { |
170 | { |
187 | int numb_ingred = 1; |
171 | int numb_ingred = 1; |
188 | |
172 | |
189 | cp = strchr (cp, ' ') + 1; |
173 | cp = strchr (cp, ' ') + 1; |
… | |
… | |
192 | if ((next = strchr (cp, ',')) != NULL) |
176 | if ((next = strchr (cp, ',')) != NULL) |
193 | { |
177 | { |
194 | *(next++) = '\0'; |
178 | *(next++) = '\0'; |
195 | numb_ingred++; |
179 | numb_ingred++; |
196 | } |
180 | } |
|
|
181 | |
197 | tmp = new linked_char; |
182 | tmp = new linked_char; |
198 | |
183 | |
199 | tmp->name = cp; |
184 | tmp->name = cp; |
200 | tmp->next = formula->ingred; |
185 | tmp->next = formula->ingred; |
201 | formula->ingred = tmp; |
186 | formula->ingred = tmp; |
… | |
… | |
204 | * quickly for the right recipe. |
189 | * quickly for the right recipe. |
205 | */ |
190 | */ |
206 | formula->index += strtoint (cp); |
191 | formula->index += strtoint (cp); |
207 | } |
192 | } |
208 | while ((cp = next) != NULL); |
193 | while ((cp = next) != NULL); |
|
|
194 | |
209 | /* now find the correct (# of ingred ordered) formulalist */ |
195 | /* now find the correct (# of ingred ordered) formulalist */ |
210 | fl = formulalist; |
196 | fl = formulalist; |
211 | while (numb_ingred != 1) |
197 | while (numb_ingred != 1) |
212 | { |
198 | { |
213 | if (!fl->next) |
199 | if (!fl->next) |
214 | fl->next = init_recipelist (); |
200 | fl->next = init_recipelist (); |
|
|
201 | |
215 | fl = fl->next; |
202 | fl = fl->next; |
216 | numb_ingred--; |
203 | numb_ingred--; |
217 | } |
204 | } |
|
|
205 | |
218 | fl->total_chance += formula->chance; |
206 | fl->total_chance += formula->chance; |
219 | fl->number++; |
207 | fl->number++; |
220 | formula->next = fl->items; |
208 | formula->next = fl->items; |
221 | fl->items = formula; |
209 | fl->items = formula; |
222 | } |
210 | } |
… | |
… | |
224 | { |
212 | { |
225 | build_stringlist (strchr (cp, ' ') + 1, &formula->arch_name, &formula->arch_names); |
213 | build_stringlist (strchr (cp, ' ') + 1, &formula->arch_name, &formula->arch_names); |
226 | check_recipe (formula); |
214 | check_recipe (formula); |
227 | } |
215 | } |
228 | else if (!strncmp (cp, "skill", 5)) |
216 | else if (!strncmp (cp, "skill", 5)) |
229 | { |
|
|
230 | formula->skill = strchr (cp, ' ') + 1; |
217 | formula->skill = strchr (cp, ' ') + 1; |
231 | } |
|
|
232 | else if (!strncmp (cp, "cauldron", 8)) |
218 | else if (!strncmp (cp, "cauldron", 8)) |
233 | { |
|
|
234 | formula->cauldron = strchr (cp, ' ') + 1; |
219 | formula->cauldron = strchr (cp, ' ') + 1; |
235 | } |
|
|
236 | else |
220 | else |
237 | LOG (llevError, "Unknown input in file %s: %s\n", filename, buf); |
221 | LOG (llevError, "Unknown input in file %s: %s\n", filename, buf); |
238 | } |
222 | } |
|
|
223 | |
239 | LOG (llevDebug, "done.\n"); |
224 | LOG (llevDebug, "done.\n"); |
240 | close_and_delete (fp, comp); |
225 | close_and_delete (fp, comp); |
241 | /* Lastly, lets check for problems in formula we got */ |
226 | /* Lastly, lets check for problems in formula we got */ |
242 | check_formulae (); |
227 | check_formulae (); |
243 | } |
228 | } |
… | |
… | |
302 | |
287 | |
303 | if (archetype::find (string) != NULL) |
288 | if (archetype::find (string) != NULL) |
304 | { |
289 | { |
305 | art = locate_recipe_artifact (formula, i); |
290 | art = locate_recipe_artifact (formula, i); |
306 | if (!art && strcmp (formula->title, "NONE")) |
291 | if (!art && strcmp (formula->title, "NONE")) |
307 | LOG (llevError, "Formula %s has no artifact\n", &formula->title); |
292 | LOG (llevError, "Formula %s has no artifact!\n", &formula->title); |
308 | else |
293 | else |
309 | { |
294 | { |
310 | if (strcmp (formula->title, "NONE")) |
295 | if (strcmp (formula->title, "NONE")) |
311 | sprintf (buf, "%s of %s", string, &formula->title); |
296 | sprintf (buf, "%s of %s", string, &formula->title); |
312 | else |
297 | else |
… | |
… | |
615 | } |
600 | } |
616 | |
601 | |
617 | artifact * |
602 | artifact * |
618 | locate_recipe_artifact (const recipe *rp, size_t idx) |
603 | locate_recipe_artifact (const recipe *rp, size_t idx) |
619 | { |
604 | { |
620 | object *item = get_archetype (rp->arch_name[idx]); |
605 | archetype *at = archetype::find (rp->arch_name [idx]); |
621 | artifactlist *at = NULL; |
|
|
622 | artifact *art = NULL; |
|
|
623 | |
606 | |
624 | if (!item) |
607 | if (at) |
625 | return (artifact *) NULL; |
608 | if (artifactlist *al = find_artifactlist (at->clone.type)) |
626 | |
|
|
627 | if ((at = find_artifactlist (item->type))) |
|
|
628 | for (art = at->items; art; art = art->next) |
609 | for (artifact *art = al->items; art; art = art->next) |
629 | if (!strcmp (art->item->name, rp->title)) |
610 | if (art->item->name == rp->title) |
630 | break; |
611 | return art; |
631 | |
612 | |
632 | item->destroy (); |
|
|
633 | |
|
|
634 | return art; |
613 | return 0; |
635 | } |
614 | } |
636 | |
615 | |
637 | int |
616 | int |
638 | numb_ingred (const char *buf) |
617 | numb_ingred (const char *buf) |
639 | { |
618 | { |