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.1 by elmex, Sun Aug 13 17:16:00 2006 UTC vs.
Revision 1.4 by elmex, Sun Sep 3 14:33:48 2006 UTC

27static void build_stringlist(const char *str, char ***result_list, size_t *result_size); 27static void build_stringlist(const char *str, char ***result_list, size_t *result_size);
28 28
29static recipelist *formulalist; 29static recipelist *formulalist;
30 30
31static recipelist *init_recipelist(void) { 31static recipelist *init_recipelist(void) {
32 recipelist *tl = (recipelist *) malloc(sizeof(recipelist)); 32 recipelist *tl = new recipelist;
33 if(tl==NULL) 33
34 fatal(OUT_OF_MEMORY);
35 tl->total_chance=0; 34 tl->total_chance=0;
36 tl->number=0; 35 tl->number=0;
37 tl->items=NULL; 36 tl->items=NULL;
38 tl->next=NULL; 37 tl->next=NULL;
39 return tl; 38 return tl;
40} 39}
41 40
42static recipe *get_empty_formula(void) { 41static recipe *get_empty_formula(void) {
43 recipe *t = (recipe *) malloc(sizeof(recipe)); 42 recipe *t = new recipe;
44 if(t==NULL) 43
45 fatal(OUT_OF_MEMORY);
46 t->chance = 0; 44 t->chance = 0;
47 t->index = 0; 45 t->index = 0;
48 t->transmute = 0; 46 t->transmute = 0;
49 t->yield=0; 47 t->yield=0;
50 t->diff=0; 48 t->diff=0;
83 result = 1; 81 result = 1;
84 for (i = 0; i < rp->arch_names; i++) { 82 for (i = 0; i < rp->arch_names; i++) {
85 if (find_archetype(rp->arch_name[i]) != NULL) { 83 if (find_archetype(rp->arch_name[i]) != NULL) {
86 artifact *art = locate_recipe_artifact(rp, i); 84 artifact *art = locate_recipe_artifact(rp, i);
87 if (!art && strcmp(rp->title, "NONE") != 0) { 85 if (!art && strcmp(rp->title, "NONE") != 0) {
88 LOG(llevError,"\nWARNING: Formula %s of %s has no artifact.\n", rp->arch_name[i], rp->title); 86 LOG(llevError,"\nWARNING: Formula %s of %s has no artifact.\n", rp->arch_name[i], &rp->title);
89 result = 0; 87 result = 0;
90 } 88 }
91 } else { 89 } else {
92 LOG(llevError,"\nWARNING: Can't find archetype %s for formula %s\n", rp->arch_name[i], rp->title); 90 LOG(llevError,"\nWARNING: Can't find archetype %s for formula %s\n", rp->arch_name[i], &rp->title);
93 result = 0; 91 result = 0;
94 } 92 }
95 } 93 }
96 94
97 return result; 95 return result;
132 while(*cp==' ') /* Skip blanks */ 130 while(*cp==' ') /* Skip blanks */
133 cp++; 131 cp++;
134 132
135 if (!strncmp(cp, "Object", 6)) { 133 if (!strncmp(cp, "Object", 6)) {
136 formula=get_empty_formula(); 134 formula=get_empty_formula();
137 formula->title = add_string(strchr(cp,' ') + 1); 135 formula->title = strchr(cp,' ') + 1;
138 } else if (!strncmp(cp, "keycode", 7)) { 136 } else if (!strncmp(cp, "keycode", 7)) {
139 formula->keycode = add_string(strchr(cp,' ') + 1); 137 formula->keycode = strchr (cp,' ') + 1;
140 } else if (sscanf(cp, "trans %d", &value)) { 138 } else if (sscanf(cp, "trans %d", &value)) {
141 formula->transmute = (uint16)value; 139 formula->transmute = (uint16)value;
142 } else if (sscanf(cp, "yield %d", &value)) { 140 } else if (sscanf(cp, "yield %d", &value)) {
143 formula->yield = (uint16)value; 141 formula->yield = (uint16)value;
144 } else if (sscanf(cp, "chance %d", &value)) { 142 } else if (sscanf(cp, "chance %d", &value)) {
145 formula->chance = (uint16)value; 143 formula->chance = (uint16)value;
146 } else if (sscanf(cp, "exp %d", &value)) { 144 } else if (sscanf(cp, "exp %d", &value)) {
147 formula->exp = (uint16)value; 145 formula->exp = (uint16)value;
148 } else if (sscanf(cp, "diff %d", &value)) { 146 } else if (sscanf(cp, "diff %d", &value)) {
149 formula->diff = (uint16)value; 147 formula->diff = (uint16)value;
150 } else if (!strncmp(cp, "ingred",6)) { 148 } else if (!strncmp(cp, "ingred",6)) {
151 int numb_ingred = 1; 149 int numb_ingred = 1;
152 cp = strchr(cp,' ') + 1; 150 cp = strchr(cp,' ') + 1;
153 do { 151 do {
154 if ((next=strchr(cp,','))!=NULL) 152 if ((next=strchr(cp,','))!=NULL)
155 {*(next++) = '\0'; numb_ingred++;} 153 {*(next++) = '\0'; numb_ingred++;}
156 tmp = (linked_char*) malloc(sizeof(linked_char)); 154 tmp = new linked_char;
157 tmp->name = add_string(cp); 155 tmp->name = cp;
158 tmp->next = formula->ingred; 156 tmp->next = formula->ingred;
159 formula->ingred = tmp; 157 formula->ingred = tmp;
160 /* each ingredient's ASCII value is coadded. Later on this 158 /* each ingredient's ASCII value is coadded. Later on this
161 * value will be used allow us to search the formula lists 159 * value will be used allow us to search the formula lists
162 * quickly for the right recipe. 160 * quickly for the right recipe.
163 */ 161 */
164 formula->index += strtoint(cp); 162 formula->index += strtoint(cp);
165 } while ((cp=next)!=NULL); 163 } while ((cp=next)!=NULL);
166 /* now find the correct (# of ingred ordered) formulalist */ 164 /* now find the correct (# of ingred ordered) formulalist */
167 fl=formulalist; 165 fl=formulalist;
168 while(numb_ingred!=1) { 166 while(numb_ingred!=1) {
169 if(!fl->next) 167 if(!fl->next)
170 fl->next = init_recipelist(); 168 fl->next = init_recipelist();
171 fl = fl->next; 169 fl = fl->next;
172 numb_ingred--; 170 numb_ingred--;
173 } 171 }
174 fl->total_chance += formula->chance; 172 fl->total_chance += formula->chance;
175 fl->number++; 173 fl->number++;
176 formula->next = fl->items; 174 formula->next = fl->items;
177 fl->items = formula; 175 fl->items = formula;
178 } else if (!strncmp(cp, "arch",4)) { 176 } else if (!strncmp(cp, "arch",4)) {
179 build_stringlist(strchr(cp, ' ')+1, &formula->arch_name, &formula->arch_names); 177 build_stringlist(strchr(cp, ' ')+1, &formula->arch_name, &formula->arch_names);
180 (void) check_recipe(formula); 178 check_recipe(formula);
181 } else if (!strncmp(cp, "skill", 5)) { 179 } else if (!strncmp(cp, "skill", 5)) {
182 formula->skill = add_string(strchr(cp, ' ')+1); 180 formula->skill = strchr(cp, ' ') + 1;
183 } else if (!strncmp(cp, "cauldron", 8)) { 181 } else if (!strncmp(cp, "cauldron", 8)) {
184 formula->cauldron = add_string(strchr(cp, ' ')+1); 182 formula->cauldron = strchr(cp, ' ') + 1;
185 } else 183 } else
186 LOG(llevError,"Unknown input in file %s: %s\n", filename, buf); 184 LOG(llevError,"Unknown input in file %s: %s\n", filename, buf);
187 } 185 }
188 LOG(llevDebug,"done.\n"); 186 LOG(llevDebug,"done.\n");
189 close_and_delete(fp, comp); 187 close_and_delete(fp, comp);
209 for (formula=fl->items; formula!=NULL; formula=formula->next) 207 for (formula=fl->items; formula!=NULL; formula=formula->next)
210 for (check=formula->next; check!=NULL; check=check->next) 208 for (check=formula->next; check!=NULL; check=check->next)
211 if(check->index==formula->index) { 209 if(check->index==formula->index) {
212 LOG(llevError," ERROR: On %d ingred list: ", numb); 210 LOG(llevError," ERROR: On %d ingred list: ", numb);
213 LOG(llevError, "Formulae [%s] of %s and [%s] of %s have matching index id (%d)\n", 211 LOG(llevError, "Formulae [%s] of %s and [%s] of %s have matching index id (%d)\n",
214 formula->arch_name[0],formula->title,check->arch_name[0],check->title,formula->index); 212 formula->arch_name[0],&formula->title,check->arch_name[0],&check->title,formula->index);
215 } 213 }
216 numb++; 214 numb++;
217 } 215 }
218 216
219 LOG(llevDebug,"done.\n"); 217 LOG(llevDebug,"done.\n");
229 int num_ingred=1; 227 int num_ingred=1;
230 228
231 fprintf(logfile, "\n"); 229 fprintf(logfile, "\n");
232 while(fl) { 230 while(fl) {
233 fprintf(logfile, "\n Formulae with %d ingredient%s %d Formulae with total_chance=%d\n", 231 fprintf(logfile, "\n Formulae with %d ingredient%s %d Formulae with total_chance=%d\n",
234 num_ingred, num_ingred>1?"s.":".",fl->number,fl->total_chance); 232 num_ingred, num_ingred>1?"s.":".",fl->number,fl->total_chance);
235 for (formula=fl->items; formula!=NULL; formula=formula->next) { 233 for (formula=fl->items; formula!=NULL; formula=formula->next) {
236 artifact *art=NULL; 234 artifact *art=NULL;
237 char buf[MAX_BUF]; 235 char buf[MAX_BUF];
238 size_t i; 236 size_t i;
239 237
240 for (i = 0; i < formula->arch_names; i++) { 238 for (i = 0; i < formula->arch_names; i++) {
241 const char *string = formula->arch_name[i]; 239 const char *string = formula->arch_name[i];
242 if(find_archetype(string)!=NULL) { 240 if(find_archetype(string)!=NULL) {
243 art = locate_recipe_artifact(formula, i); 241 art = locate_recipe_artifact(formula, i);
244 if (!art && strcmp(formula->title,"NONE")) 242 if (!art && strcmp(formula->title,"NONE"))
245 LOG(llevError,"Formula %s has no artifact\n",formula->title); 243 LOG(llevError,"Formula %s has no artifact\n",&formula->title);
246 else { 244 else {
247 if(strcmp(formula->title,"NONE")) 245 if(strcmp(formula->title,"NONE"))
248 sprintf(buf,"%s of %s",string,formula->title); 246 sprintf(buf,"%s of %s",string,&formula->title);
249 else 247 else
250 sprintf(buf,"%s",string); 248 sprintf(buf,"%s",string);
251 fprintf(logfile,"%-30s(%d) bookchance %3d ",buf,formula->index, 249 fprintf(logfile,"%-30s(%d) bookchance %3d ",buf,formula->index,
252 formula->chance); 250 formula->chance);
253 fprintf(logfile,"skill %s",formula->skill); 251 fprintf(logfile,"skill %s",&formula->skill);
254 fprintf(logfile,"\n"); 252 fprintf(logfile,"\n");
255 if (formula->ingred !=NULL) { 253 if (formula->ingred !=NULL) {
256 int nval=0,tval=0; 254 int nval=0,tval=0;
257 fprintf(logfile,"\tIngred: "); 255 fprintf(logfile,"\tIngred: ");
258 for (next=formula->ingred; next!=NULL; next=next->next) { 256 for (next=formula->ingred; next!=NULL; next=next->next) {
259 if(nval!=0) fprintf(logfile,","); 257 if(nval!=0) fprintf(logfile,",");
260 fprintf(logfile,"%s(%d)",next->name,(nval=strtoint(next->name))); 258 fprintf(logfile,"%s(%d)",&next->name,(nval=strtoint(next->name)));
261 tval += nval; 259 tval += nval;
262 } 260 }
263 fprintf(logfile,"\n"); 261 fprintf(logfile,"\n");
264 if(tval!=formula->index) fprintf(logfile, "WARNING:ingredient list and formula values not equal.\n"); 262 if(tval!=formula->index) fprintf(logfile, "WARNING:ingredient list and formula values not equal.\n");
265 } 263 }
266 if (formula->skill != NULL) 264 if (formula->skill != NULL)
267 fprintf(logfile, "\tSkill Required: %s", formula->skill); 265 fprintf(logfile, "\tSkill Required: %s", &formula->skill);
268 if (formula->cauldron != NULL) 266 if (formula->cauldron != NULL)
269 fprintf(logfile, "\tCauldron: %s\n", formula->cauldron); 267 fprintf(logfile, "\tCauldron: %s\n", &formula->cauldron);
270 fprintf(logfile, "\tDifficulty: %d\t Exp: %d\n", formula->diff, 268 fprintf(logfile, "\tDifficulty: %d\t Exp: %d\n", formula->diff,
271 formula->exp); 269 formula->exp);
272 } 270 }
273 } else 271 } else
274 LOG(llevError,"Can't find archetype:%s for formula %s\n", string, 272 LOG(llevError,"Can't find archetype:%s for formula %s\n", string,
275 formula->title); 273 &formula->title);
276 } 274 }
277 } 275 }
278 fprintf(logfile,"\n"); 276 fprintf(logfile,"\n");
279 fl = fl->next; 277 fl = fl->next;
280 num_ingred++; 278 num_ingred++;
292 if (depth > 10) 290 if (depth > 10)
293 return NULL; 291 return NULL;
294 while (t != NULL) 292 while (t != NULL)
295 { 293 {
296 if (t->name != NULL) 294 if (t->name != NULL)
297 { 295 {
298 tl = find_treasurelist (t->name); 296 tl = find_treasurelist (t->name);
299 at = find_treasure_by_name (tl->items, name, depth + 1); 297 at = find_treasure_by_name (tl->items, name, depth + 1);
300 if (at != NULL) 298 if (at != NULL)
301 return at; 299 return at;
302 } 300 }
303 else 301 else
304 { 302 {
305 if (! strcasecmp (t->item->clone.name, name)) 303 if (! strcasecmp (t->item->clone.name, name))
306 return t->item; 304 return t->item;
307 } 305 }
308 if (t->next_yes != NULL) 306 if (t->next_yes != NULL)
309 { 307 {
310 at = find_treasure_by_name (t->next_yes, name, depth); 308 at = find_treasure_by_name (t->next_yes, name, depth);
311 if (at != NULL) 309 if (at != NULL)
312 return at; 310 return at;
313 } 311 }
314 if (t->next_no != NULL) 312 if (t->next_no != NULL)
315 { 313 {
316 at = find_treasure_by_name (t->next_no, name, depth); 314 at = find_treasure_by_name (t->next_no, name, depth);
317 if (at != NULL) 315 if (at != NULL)
318 return at; 316 return at;
319 } 317 }
320 t = t->next; 318 t = t->next;
321 } 319 }
322 return NULL; 320 return NULL;
323} 321}
324 322
354 mult = 1; 352 mult = 1;
355 /* first, try to match the name of an archetype */ 353 /* first, try to match the name of an archetype */
356 for (at = first_archetype; at != NULL; at = at->next) 354 for (at = first_archetype; at != NULL; at = at->next)
357 { 355 {
358 if (at->clone.title != NULL) 356 if (at->clone.title != NULL)
359 { 357 {
360 /* inefficient, but who cares? */ 358 /* inefficient, but who cares? */
361 sprintf (part1, "%s %s", at->clone.name, at->clone.title); 359 sprintf (part1, "%s %s", &at->clone.name, &at->clone.title);
362 if (! strcasecmp (part1, name)) 360 if (! strcasecmp (part1, name))
363 return mult * at->clone.value; 361 return mult * at->clone.value;
364 } 362 }
365 if (! strcasecmp (at->clone.name, name)) 363 if (! strcasecmp (at->clone.name, name))
366 return mult * at->clone.value; 364 return mult * at->clone.value;
367 } 365 }
368 /* second, try to match an artifact ("arch of something") */ 366 /* second, try to match an artifact ("arch of something") */
369 cp = strstr (name, " of "); 367 cp = strstr (name, " of ");
370 if (cp != NULL) 368 if (cp != NULL)
371 { 369 {
372 strcpy (part1, name); 370 strcpy (part1, name);
373 part1[cp - name] = '\0'; 371 part1[cp - name] = '\0';
374 strcpy (part2, cp + 4); 372 strcpy (part2, cp + 4);
375 /* find the first archetype matching the first part of the name */ 373 /* find the first archetype matching the first part of the name */
376 for (at = first_archetype; at != NULL; at = at->next) 374 for (at = first_archetype; at != NULL; at = at->next)
377 if (! strcasecmp (at->clone.name, part1) && at->clone.title == NULL) 375 if (! strcasecmp (at->clone.name, part1) && at->clone.title == NULL)
378 break; 376 break;
379 if (at != NULL) 377 if (at != NULL)
380 { 378 {
381 /* find the first artifact derived from that archetype (same type) */ 379 /* find the first artifact derived from that archetype (same type) */
382 for (al = first_artifactlist; al != NULL; al = al->next) 380 for (al = first_artifactlist; al != NULL; al = al->next)
383 if (al->type == at->clone.type) 381 if (al->type == at->clone.type)
384 { 382 {
385 for (art = al->items; art != NULL; art = art->next) 383 for (art = al->items; art != NULL; art = art->next)
386 if (! strcasecmp (art->item->name, part2)) 384 if (! strcasecmp (art->item->name, part2))
387 return mult * at->clone.value * art->item->value; 385 return mult * at->clone.value * art->item->value;
386 }
388 } 387 }
389 }
390 } 388 }
391 /* third, try to match a body part ("arch's something") */ 389 /* third, try to match a body part ("arch's something") */
392 cp = strstr (name, "'s "); 390 cp = strstr (name, "'s ");
393 if (cp != NULL) 391 if (cp != NULL)
394 { 392 {
395 strcpy (part1, name); 393 strcpy (part1, name);
396 part1[cp - name] = '\0'; 394 part1[cp - name] = '\0';
397 strcpy (part2, cp + 3); 395 strcpy (part2, cp + 3);
398 /* examine all archetypes matching the first part of the name */ 396 /* examine all archetypes matching the first part of the name */
399 for (at = first_archetype; at != NULL; at = at->next) 397 for (at = first_archetype; at != NULL; at = at->next)
400 if (! strcasecmp (at->clone.name, part1) && at->clone.title == NULL) 398 if (! strcasecmp (at->clone.name, part1) && at->clone.title == NULL)
401 { 399 {
402 if (at->clone.randomitems != NULL) 400 if (at->clone.randomitems != NULL)
403 { 401 {
404 at2 = find_treasure_by_name (at->clone.randomitems->items, 402 at2 = find_treasure_by_name (at->clone.randomitems->items,
405 part2, 0); 403 part2, 0);
406 if (at2 != NULL) 404 if (at2 != NULL)
407 return mult * at2->clone.value * isqrt (at->clone.level * 2); 405 return mult * at2->clone.value * isqrt (at->clone.level * 2);
408 } 406 }
409 } 407 }
410 } 408 }
411 /* failed to find any matching items -- formula should be checked */ 409 /* failed to find any matching items -- formula should be checked */
412 return -1; 410 return -1;
413} 411}
414 412
424 long tcost; 422 long tcost;
425 423
426 fprintf (logfile, "\n"); 424 fprintf (logfile, "\n");
427 while (fl) { 425 while (fl) {
428 fprintf(logfile, "\n Formulae with %d ingredient%s %d Formulae with total_chance=%d\n", 426 fprintf(logfile, "\n Formulae with %d ingredient%s %d Formulae with total_chance=%d\n",
429 num_ingred, num_ingred>1?"s.":".",fl->number,fl->total_chance); 427 num_ingred, num_ingred>1?"s.":".",fl->number,fl->total_chance);
430 for (formula = fl->items; formula != NULL; formula = formula->next) { 428 for (formula = fl->items; formula != NULL; formula = formula->next) {
431 artifact *art=NULL; 429 artifact *art=NULL;
432 archetype *at=NULL; 430 archetype *at=NULL;
433 char buf[MAX_BUF]; 431 char buf[MAX_BUF];
434 size_t i; 432 size_t i;
435 433
436 for (i = 0; i < formula->arch_names; i++) { 434 for (i = 0; i < formula->arch_names; i++) {
437 const char *string = formula->arch_name[i]; 435 const char *string = formula->arch_name[i];
438 if ((at = find_archetype (string)) != NULL) { 436 if ((at = find_archetype (string)) != NULL) {
439 art = locate_recipe_artifact (formula, i); 437 art = locate_recipe_artifact (formula, i);
440 if (!art && strcmp (formula->title,"NONE")) 438 if (!art && strcmp (formula->title,"NONE"))
441 LOG (llevError, "Formula %s has no artifact\n", formula->title); 439 LOG (llevError, "Formula %s has no artifact\n", &formula->title);
442 else 440 else
443 { 441 {
444 if (! strcmp (formula->title, "NONE")) 442 if (! strcmp (formula->title, "NONE"))
445 sprintf (buf, "%s", string); 443 sprintf (buf, "%s", string);
446 else 444 else
447 sprintf (buf, "%s of %s", string, formula->title); 445 sprintf (buf, "%s of %s", string, &formula->title);
448 fprintf (logfile, "\n%-40s bookchance %3d skill %s\n", 446 fprintf (logfile, "\n%-40s bookchance %3d skill %s\n",
449 buf, formula->chance, formula->skill); 447 buf, formula->chance, &(formula->skill));
450 if (formula->ingred !=NULL) 448 if (formula->ingred !=NULL)
451 { 449 {
452 tcost = 0; 450 tcost = 0;
453 for (next = formula->ingred; next != NULL; next = next->next) 451 for (next = formula->ingred; next != NULL; next = next->next)
454 { 452 {
455 cost = find_ingred_cost (next->name); 453 cost = find_ingred_cost (next->name);
456 if (cost < 0) 454 if (cost < 0)
457 num_errors++; 455 num_errors++;
458 fprintf (logfile,"\t%-33s%5ld\n", next->name, cost); 456 fprintf (logfile,"\t%-33s%5ld\n", &next->name, cost);
459 if (cost < 0 || tcost < 0) 457 if (cost < 0 || tcost < 0)
460 tcost = -1; 458 tcost = -1;
461 else 459 else
462 tcost += cost; 460 tcost += cost;
463 } 461 }
464 if (art != NULL && art->item != NULL) 462 if (art != NULL && art->item != NULL)
465 cost = at->clone.value * art->item->value; 463 cost = at->clone.value * art->item->value;
466 else 464 else
467 cost = at->clone.value; 465 cost = at->clone.value;
468 fprintf (logfile, "\t\tBuying result costs: %5ld", cost); 466 fprintf (logfile, "\t\tBuying result costs: %5ld", cost);
469 if (formula->yield > 1) 467 if (formula->yield > 1)
470 { 468 {
471 fprintf (logfile, " to %ld (max %d items)\n", 469 fprintf (logfile, " to %ld (max %d items)\n",
472 cost * formula->yield, formula->yield); 470 cost * formula->yield, formula->yield);
473 cost = cost * (formula->yield + 1L) / 2L; 471 cost = cost * (formula->yield + 1L) / 2L;
474 } 472 }
475 else 473 else
476 fprintf (logfile, "\n"); 474 fprintf (logfile, "\n");
477 fprintf (logfile, "\t\tIngredients cost: %5ld\n\t\tComment: ", tcost); 475 fprintf (logfile, "\t\tIngredients cost: %5ld\n\t\tComment: ", tcost);
478 if (tcost < 0) 476 if (tcost < 0)
479 fprintf (logfile, "Could not find some ingredients. Check the formula!\n"); 477 fprintf (logfile, "Could not find some ingredients. Check the formula!\n");
480 else if (tcost > cost) 478 else if (tcost > cost)
481 fprintf (logfile, "Ingredients are much too expensive. Useless formula.\n"); 479 fprintf (logfile, "Ingredients are much too expensive. Useless formula.\n");
482 else if (tcost * 2L > cost) 480 else if (tcost * 2L > cost)
483 fprintf (logfile, "Ingredients are too expensive.\n"); 481 fprintf (logfile, "Ingredients are too expensive.\n");
484 else if (tcost * 10L < cost) 482 else if (tcost * 10L < cost)
485 fprintf (logfile, "Ingredients are too cheap.\n"); 483 fprintf (logfile, "Ingredients are too cheap.\n");
486 else 484 else
487 fprintf (logfile, "OK.\n"); 485 fprintf (logfile, "OK.\n");
488 } 486 }
489 } 487 }
490 } 488 }
491 else 489 else
492 LOG(llevError, "Can't find archetype:%s for formula %s\n", string, 490 LOG(llevError, "Can't find archetype:%s for formula %s\n", string,
493 formula->title); 491 &formula->title);
494 } 492 }
495 } 493 }
496 fprintf (logfile,"\n"); 494 fprintf (logfile,"\n");
497 fl = fl->next; 495 fl = fl->next;
498 num_ingred++; 496 num_ingred++;
499 } 497 }
500 if (num_errors > 0) 498 if (num_errors > 0)
501 fprintf (logfile, "WARNING: %d objects required by the formulae do not exist in the game.\n", 499 fprintf (logfile, "WARNING: %d objects required by the formulae do not exist in the game.\n",
502 num_errors); 500 num_errors);
503} 501}
504 502
505const char * ingred_name (const char *name) { 503const char * ingred_name (const char *name) {
506 const char *cp=name; 504 const char *cp=name;
507 505
595 recipe *formula=NULL,*next; 593 recipe *formula=NULL,*next;
596 linked_char *lchar, *charnext; 594 linked_char *lchar, *charnext;
597 595
598 LOG(llevDebug,"Freeing all the recipes\n"); 596 LOG(llevDebug,"Freeing all the recipes\n");
599 for (fl=formulalist; fl!=NULL; fl=flnext) { 597 for (fl=formulalist; fl!=NULL; fl=flnext) {
600 flnext=fl->next; 598 flnext=fl->next;
601 599
602 for (formula=fl->items; formula!=NULL; formula=next) { 600 for (formula=fl->items; formula!=NULL; formula=next) {
603 next=formula->next; 601 next=formula->next;
604 602
605 free(formula->arch_name[0]); 603 free (formula->arch_name [0]);
606 free(formula->arch_name); 604 free (formula->arch_name);
607 if (formula->title) 605
608 free_string(formula->title);
609 if (formula->skill)
610 free_string(formula->skill);
611 if (formula->cauldron)
612 free_string(formula->cauldron);
613 for (lchar=formula->ingred; lchar; lchar=charnext) { 606 for (lchar=formula->ingred; lchar; lchar=charnext) {
614 charnext=lchar->next; 607 charnext=lchar->next;
615 free_string(lchar->name); 608 delete lchar;
616 free(lchar); 609 }
617 } 610 delete formula;
618 free(formula); 611 }
619 } 612
620 free(fl); 613 delete fl;
621 } 614 }
622} 615}
623 616
624/** 617/**
625 * Split a comma separated string list into words. 618 * Split a comma separated string list into words.
646 size = 0; 639 size = 0;
647 for (p = strtok(dup, ","); p != NULL; p = strtok(NULL, ",")) 640 for (p = strtok(dup, ","); p != NULL; p = strtok(NULL, ","))
648 size++; 641 size++;
649 642
650 *result_list = (char **) malloc(size*sizeof(*result_list)); 643 *result_list = (char **) malloc(size*sizeof(*result_list));
651 if (*result_list == NULL) 644
652 fatal(OUT_OF_MEMORY);
653 *result_size = size; 645 *result_size = size;
654 646
655 for (i = 0; i < size; i++) { 647 for (i = 0; i < size; i++) {
656 (*result_list)[i] = dup; 648 (*result_list)[i] = dup;
657 dup = dup+strlen(dup)+1; 649 dup = dup+strlen(dup)+1;
658 } 650 }
659} 651}
652

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines