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.2 by root, Tue Aug 29 08:01:36 2006 UTC vs.
Revision 1.3 by root, Sun Sep 3 00:18:40 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;
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)) {
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.
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);
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 }
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;
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 }
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);
616 free(lchar); 608 delete lchar;
617 } 609 }
618 free(formula); 610 delete formula;
619 } 611 }
620 free(fl); 612
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