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.36 by root, Sun Apr 4 04:58:46 2010 UTC vs.
Revision 1.37 by root, Thu Apr 15 03:34:30 2010 UTC

67static recipe * 67static recipe *
68get_empty_formula () 68get_empty_formula ()
69{ 69{
70 recipe *t = new recipe; 70 recipe *t = new recipe;
71 71
72 t->chance = 0; 72 t->chance = 0;
73 t->index = 0; 73 t->index = 0;
74 t->transmute = 0; 74 t->transmute = 0;
75 t->yield = 0; 75 t->yield = 0;
76 t->diff = 0; 76 t->diff = 0;
77 t->exp = 0; 77 t->exp = 0;
78 t->keycode = 0; 78 t->keycode = 0;
79 t->title = NULL; 79 t->title = 0;
80 t->arch_names = 0; 80 t->arch_names = 0;
81 t->arch_name = NULL; 81 t->arch_name = 0;
82 t->skill = NULL; 82 t->skill = 0;
83 t->cauldron = NULL; 83 t->cauldron = 0;
84 t->ingred = NULL; 84 t->ingred = 0;
85 t->next = NULL; 85 t->next = 0;
86
86 return t; 87 return t;
87} 88}
88 89
89/* get_formulalist() - returns pointer to the formula list */ 90/* get_formulalist() - returns pointer to the formula list */
90recipelist * 91recipelist *
174init_formulae () 175init_formulae ()
175{ 176{
176 static int has_been_done = 0; 177 static int has_been_done = 0;
177 FILE *fp; 178 FILE *fp;
178 char filename[MAX_BUF], buf[MAX_BUF], *cp, *next; 179 char filename[MAX_BUF], buf[MAX_BUF], *cp, *next;
179 recipe *formula = NULL;
180 recipelist *fl = init_recipelist (); 180 recipelist *fl = init_recipelist ();
181 linked_char *tmp; 181 linked_char *tmp;
182 int value, comp; 182 int value, comp;
183 183
184 if (!formulalist) 184 if (!formulalist)
189 else 189 else
190 has_been_done = 1; 190 has_been_done = 1;
191 191
192 sprintf (filename, "%s/formulae", settings.datadir); 192 sprintf (filename, "%s/formulae", settings.datadir);
193 LOG (llevDebug, "Reading alchemical formulae from %s...\n", filename); 193 LOG (llevDebug, "Reading alchemical formulae from %s...\n", filename);
194 if ((fp = open_and_uncompress (filename, 0, &comp)) == NULL) 194
195 object_thawer thawer (filename);
196
197 if (!thawer)
195 { 198 {
196 LOG (llevError, "Can't open %s.\n", filename); 199 LOG (llevError, "Can't open %s.\n", filename);
197 return; 200 return;
198 } 201 }
199 202
200 while (fgets (buf, MAX_BUF, fp) != NULL) 203 while (thawer.kw)
201 { 204 {
202 if (*buf == '#') 205 if (thawer.kw != KW_object)
203 continue; 206 if (!thawer.parse_error ("formulae file", "formulae"))
204 if ((cp = strchr (buf, '\n')) != NULL) 207 break;
205 *cp = '\0';
206 cp = buf;
207 while (*cp == ' ') /* Skip blanks */
208 cp++;
209 208
210 if (!strncmp (cp, "object", 6))
211 {
212 formula = get_empty_formula (); 209 recipe *formula = get_empty_formula ();
213 formula->title = strchr (cp, ' ') + 1; 210 thawer.get (formula->title);
211
212 for (;;)
214 } 213 {
215 else if (!strncmp (cp, "keycode", 7)) 214 thawer.next ();
216 formula->keycode = strchr (cp, ' ') + 1;
217 else if (sscanf (cp, "trans %d", &value))
218 formula->transmute = (uint16) value;
219 else if (sscanf (cp, "yield %d", &value))
220 formula->yield = (uint16) value;
221 else if (sscanf (cp, "chance %d", &value))
222 formula->chance = (uint16) value;
223 else if (sscanf (cp, "exp %d", &value))
224 formula->exp = (uint16) value;
225 else if (sscanf (cp, "diff %d", &value))
226 formula->diff = (uint16) value;
227 else if (!strncmp (cp, "ingred", 6))
228 {
229 int numb_ingred = 1;
230 215
231 cp = strchr (cp, ' ') + 1; 216 switch (thawer.kw)
232 do
233 { 217 {
234 if ((next = strchr (cp, ',')) != NULL) 218 case KW_keycode: thawer.get (formula->keycode ); break;
219 case KW_trans: thawer.get (formula->transmute); break;
220 case KW_yield: thawer.get (formula->yield ); break;
221 case KW_chance: thawer.get (formula->chance ); break;
222 case KW_exp: thawer.get (formula->exp ); break;
223 case KW_diff: thawer.get (formula->diff ); break;
224 case KW_skill: thawer.get (formula->skill ); break;
225 case KW_cauldron: thawer.get (formula->cauldron ); break;
226
227 case KW_arch:
235 { 228 {
236 *(next++) = '\0'; 229 build_stringlist (thawer.value_nn, &formula->arch_name, &formula->arch_names);
237 numb_ingred++; 230 check_recipe (formula);
238 } 231 }
232 break;
239 233
234 case KW_ingred:
235 if (thawer.value)
236 {
237 int numb_ingred = 1;
238 char *cp = thawer.value;
239
240 do
241 {
242 if ((next = strchr (cp, ',')))
243 {
244 *next++ = '\0';
245 ++numb_ingred;
246 }
247
240 tmp = new linked_char; 248 tmp = new linked_char;
241 249
242 tmp->name = cp; 250 tmp->name = cp;
243 tmp->next = formula->ingred; 251 tmp->next = formula->ingred;
244 formula->ingred = tmp; 252 formula->ingred = tmp;
245 /* each ingredient's ASCII value is coadded. Later on this 253 /* each ingredient's ASCII value is coadded. Later on this
246 * value will be used allow us to search the formula lists 254 * value will be used allow us to search the formula lists
247 * quickly for the right recipe. 255 * quickly for the right recipe.
248 */ 256 */
249 formula->index += strtoint (cp); 257 formula->index += strtoint (cp);
258 }
259 while ((cp = next));
260
261 /* now find the correct (# of ingred ordered) formulalist */
262 fl = formulalist;
263 while (numb_ingred != 1)
264 {
265 if (!fl->next)
266 fl->next = init_recipelist ();
267
268 fl = fl->next;
269 numb_ingred--;
270 }
271
272 fl->total_chance += formula->chance;
273 fl->number++;
274 formula->next = fl->items;
275 fl->items = formula;
276 }
277 break;
278
279 default:
280 goto next_object;
250 } 281 }
251 while ((cp = next) != NULL);
252
253 /* now find the correct (# of ingred ordered) formulalist */
254 fl = formulalist;
255 while (numb_ingred != 1)
256 {
257 if (!fl->next)
258 fl->next = init_recipelist ();
259
260 fl = fl->next;
261 numb_ingred--;
262 }
263
264 fl->total_chance += formula->chance;
265 fl->number++;
266 formula->next = fl->items;
267 fl->items = formula;
268 }
269 else if (!strncmp (cp, "arch", 4))
270 { 282 }
271 build_stringlist (strchr (cp, ' ') + 1, &formula->arch_name, &formula->arch_names); 283
272 check_recipe (formula); 284next_object: ;
273 }
274 else if (!strncmp (cp, "skill", 5))
275 formula->skill = strchr (cp, ' ') + 1;
276 else if (!strncmp (cp, "cauldron", 8))
277 formula->cauldron = strchr (cp, ' ') + 1;
278 else
279 LOG (llevError, "Unknown input in file %s: %s\n", filename, buf);
280 } 285 }
281 286
282 LOG (llevDebug, "done.\n"); 287 LOG (llevDebug, "done.\n");
283 close_and_delete (fp, comp);
284 /* Lastly, lets check for problems in formula we got */ 288 /* Lastly, lets check for problems in formula we got */
285 check_formulae (); 289 check_formulae ();
286} 290}
287 291
288/* Find a treasure with a matching name. The 'depth' parameter is 292/* Find a treasure with a matching name. The 'depth' parameter is

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines