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.35 by root, Fri Mar 26 01:04:44 2010 UTC vs.
Revision 1.44 by root, Tue Jan 3 11:25:31 2012 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992 Frank Tore Johansen 6 * Copyright (©) 1992 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify it under 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * the terms of the Affero GNU General Public License as published by the 9 * the terms of the Affero GNU General Public License as published by the
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 *
172 */ 173 */
173void 174void
174init_formulae () 175init_formulae ()
175{ 176{
176 static int has_been_done = 0; 177 static int has_been_done = 0;
177 FILE *fp; 178 char *next;
178 char filename[MAX_BUF], buf[MAX_BUF], *cp, *next;
179 recipe *formula = NULL;
180 recipelist *fl = init_recipelist (); 179 recipelist *fl = init_recipelist ();
181 linked_char *tmp; 180 linked_char *tmp;
182 int value, comp;
183 181
184 if (!formulalist) 182 if (!formulalist)
185 formulalist = fl; 183 formulalist = fl;
186 184
187 if (has_been_done) 185 if (has_been_done)
188 return; 186 return;
189 else 187 else
190 has_been_done = 1; 188 has_been_done = 1;
191 189
192 sprintf (filename, "%s/formulae", settings.datadir); 190 object_thawer thawer (settings.datadir, "formulae");
193 LOG (llevDebug, "Reading alchemical formulae from %s...\n", filename); 191
194 if ((fp = open_and_uncompress (filename, 0, &comp)) == NULL) 192 if (!thawer)
195 { 193 {
196 LOG (llevError, "Can't open %s.\n", filename); 194 LOG (llevError, "Can't open %s.\n", thawer.name);
197 return; 195 return;
198 } 196 }
199 197
200 while (fgets (buf, MAX_BUF, fp) != NULL) 198 while (thawer.kw)
201 { 199 {
202 if (*buf == '#') 200 if (thawer.kw != KW_object)
203 continue; 201 if (!thawer.parse_error ("formulae file"))
204 if ((cp = strchr (buf, '\n')) != NULL) 202 break;
205 *cp = '\0';
206 cp = buf;
207 while (*cp == ' ') /* Skip blanks */
208 cp++;
209 203
210 if (!strncmp (cp, "object", 6))
211 {
212 formula = get_empty_formula (); 204 recipe *formula = get_empty_formula ();
213 formula->title = strchr (cp, ' ') + 1; 205 thawer.get (formula->title);
206
207 for (;;)
214 } 208 {
215 else if (!strncmp (cp, "keycode", 7)) 209 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 210
231 cp = strchr (cp, ' ') + 1; 211 switch (thawer.kw)
232 do
233 { 212 {
234 if ((next = strchr (cp, ',')) != NULL) 213 case KW_keycode: thawer.get (formula->keycode ); break;
214 case KW_trans: thawer.get (formula->transmute); break;
215 case KW_yield: thawer.get (formula->yield ); break;
216 case KW_chance: thawer.get (formula->chance ); break;
217 case KW_exp: thawer.get (formula->exp ); break;
218 case KW_diff: thawer.get (formula->diff ); break;
219 case KW_skill: thawer.get (formula->skill ); break;
220 case KW_cauldron: thawer.get (formula->cauldron ); break;
221
222 case KW_arch:
235 { 223 {
236 *(next++) = '\0'; 224 build_stringlist (thawer.value_nn, &formula->arch_name, &formula->arch_names);
237 numb_ingred++; 225 check_recipe (formula);
238 } 226 }
227 break;
239 228
229 case KW_ingred:
230 if (thawer.value)
231 {
232 int numb_ingred = 1;
233 char *cp = thawer.value;
234
235 do
236 {
237 if ((next = strchr (cp, ',')))
238 {
239 *next++ = '\0';
240 ++numb_ingred;
241 }
242
240 tmp = new linked_char; 243 tmp = new linked_char;
241 244
242 tmp->name = cp; 245 tmp->name = cp;
243 tmp->next = formula->ingred; 246 tmp->next = formula->ingred;
244 formula->ingred = tmp; 247 formula->ingred = tmp;
245 /* each ingredient's ASCII value is coadded. Later on this 248 /* each ingredient's ASCII value is coadded. Later on this
246 * value will be used allow us to search the formula lists 249 * value will be used allow us to search the formula lists
247 * quickly for the right recipe. 250 * quickly for the right recipe.
248 */ 251 */
249 formula->index += strtoint (cp); 252 formula->index += strtoint (cp);
253 }
254 while ((cp = next));
255
256 /* now find the correct (# of ingred ordered) formulalist */
257 fl = formulalist;
258 while (numb_ingred != 1)
259 {
260 if (!fl->next)
261 fl->next = init_recipelist ();
262
263 fl = fl->next;
264 numb_ingred--;
265 }
266
267 fl->total_chance += formula->chance;
268 fl->number++;
269 formula->next = fl->items;
270 fl->items = formula;
271 }
272 break;
273
274 default:
275 delete formula;
276 case KW_EOF:
277 case KW_object:
278 goto next_object;
250 } 279 }
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 { 280 }
271 build_stringlist (strchr (cp, ' ') + 1, &formula->arch_name, &formula->arch_names);
272 check_recipe (formula);
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 }
281 281
282 LOG (llevDebug, "done.\n"); 282next_object: ;
283 close_and_delete (fp, comp); 283 }
284
284 /* Lastly, lets check for problems in formula we got */ 285 /* Lastly, lets check for problems in formula we got */
285 check_formulae (); 286 check_formulae ();
286} 287}
287 288
288/* Find a treasure with a matching name. The 'depth' parameter is 289/* Find a treasure with a matching name. The 'depth' parameter is
454 char *p; 455 char *p;
455 size_t size; 456 size_t size;
456 size_t i; 457 size_t i;
457 458
458 dup = strdup (str); 459 dup = strdup (str);
459 if (dup == NULL)
460 fatal (OUT_OF_MEMORY);
461 460
462 size = 0; 461 size = 0;
463 for (p = strtok (dup, ","); p != NULL; p = strtok (NULL, ",")) 462 for (p = strtok (dup, ","); p != NULL; p = strtok (NULL, ","))
464 size++; 463 size++;
465 464
466 *result_list = (char **) malloc (size * sizeof (*result_list)); 465 *result_list = (char **)malloc (size * sizeof (*result_list));
467 466
468 *result_size = size; 467 *result_size = size;
469 468
470 for (i = 0; i < size; i++) 469 for (i = 0; i < size; i++)
471 { 470 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines