… | |
… | |
374 | } |
374 | } |
375 | |
375 | |
376 | static void |
376 | static void |
377 | load_materials (void) |
377 | load_materials (void) |
378 | { |
378 | { |
379 | char buf[MAX_BUF], filename[MAX_BUF], *cp, *next; |
379 | char filename[MAX_BUF]; |
380 | FILE *fp; |
|
|
381 | materialtype_t *mt; |
380 | materialtype_t *mt; |
382 | int i, value; |
|
|
383 | |
381 | |
384 | sprintf (filename, "%s/materials", settings.datadir); |
382 | sprintf (filename, "%s/materials", settings.datadir); |
385 | LOG (llevDebug, "Reading material type data from %s...\n", filename); |
383 | LOG (llevDebug, "Reading material type data from %s...\n", filename); |
386 | if ((fp = fopen (filename, "r")) == NULL) |
384 | |
|
|
385 | object_thawer thawer (filename); |
|
|
386 | |
|
|
387 | if (!thawer) |
387 | { |
388 | { |
388 | LOG (llevError, "Cannot open %s for reading\n", filename); |
389 | LOG (llevError, "Cannot open %s for reading\n", filename); |
389 | mt = get_empty_mat (); |
390 | mt = get_empty_mat (); |
390 | mt->next = NULL; |
391 | mt->next = 0; |
391 | materialt = mt; |
392 | materialt = mt; |
392 | return; |
393 | return; |
393 | } |
394 | } |
|
|
395 | |
394 | mt = get_empty_mat (); |
396 | mt = get_empty_mat (); |
395 | materialt = mt; |
397 | materialt = mt; |
396 | while (fgets (buf, MAX_BUF, fp) != NULL) |
398 | |
|
|
399 | for (;;) |
397 | { |
400 | { |
398 | if (*buf == '#') |
401 | keyword kw = thawer.get_kv (); |
399 | continue; |
402 | |
400 | if ((cp = strchr (buf, '\n')) != NULL) |
403 | switch (kw) |
401 | *cp = '\0'; |
|
|
402 | cp = buf; |
|
|
403 | while (*cp == ' ') /* Skip blanks */ |
|
|
404 | cp++; |
|
|
405 | if (!strncmp (cp, "name", 4)) |
|
|
406 | { |
404 | { |
|
|
405 | case KW_name: |
407 | /* clean up the previous entry */ |
406 | /* clean up the previous entry */ |
408 | if (mt->next != NULL) |
407 | if (mt->next) |
409 | { |
408 | { |
410 | if (mt->description == NULL) |
409 | if (!mt->description) |
411 | mt->description = mt->name; |
410 | mt->description = mt->name; |
|
|
411 | |
412 | mt = mt->next; |
412 | mt = mt->next; |
413 | } |
413 | } |
|
|
414 | |
414 | mt->next = get_empty_mat (); |
415 | mt->next = get_empty_mat (); |
415 | mt->name = strchr (cp, ' ') + 1; |
416 | thawer.get (mt->name); |
416 | } |
417 | break; |
417 | else if (!strncmp (cp, "description", 11)) |
418 | |
|
|
419 | case KW_description: |
|
|
420 | thawer.get (mt->description); |
|
|
421 | break; |
|
|
422 | |
|
|
423 | case KW_material: |
|
|
424 | thawer.get (mt->material); |
|
|
425 | break; |
|
|
426 | |
|
|
427 | case KW_saves: |
418 | { |
428 | { |
419 | mt->description = strchr (cp, ' ') + 1; |
429 | const char *cp = thawer.get_str () - 1; |
420 | } |
430 | |
421 | else if (sscanf (cp, "material %d", &value)) |
|
|
422 | { |
|
|
423 | mt->material = value; |
|
|
424 | } |
|
|
425 | else if (!strncmp (cp, "saves", 5)) |
|
|
426 | { |
|
|
427 | cp = strchr (cp, ' ') + 1; |
|
|
428 | for (i = 0; i < NROFATTACKS; i++) |
431 | for (int i = 0; i < NROFATTACKS; i++) |
429 | { |
|
|
430 | if (cp == NULL) |
|
|
431 | { |
432 | { |
|
|
433 | if (!cp) |
|
|
434 | { |
432 | mt->save[i] = 0; |
435 | mt->save[i] = 0; |
433 | continue; |
436 | continue; |
|
|
437 | } |
|
|
438 | |
|
|
439 | int value; |
|
|
440 | ++cp; |
|
|
441 | sscanf (cp, "%d", &value); |
|
|
442 | mt->save[i] = (sint8) value; |
|
|
443 | cp = strchr (cp, ','); |
434 | } |
444 | } |
435 | if ((next = strchr (cp, ',')) != NULL) |
|
|
436 | *(next++) = '\0'; |
|
|
437 | sscanf (cp, "%d", &value); |
|
|
438 | mt->save[i] = (sint8) value; |
|
|
439 | cp = next; |
|
|
440 | } |
|
|
441 | } |
|
|
442 | else if (!strncmp (cp, "mods", 4)) |
|
|
443 | { |
|
|
444 | cp = strchr (cp, ' ') + 1; |
|
|
445 | for (i = 0; i < NROFATTACKS; i++) |
|
|
446 | { |
445 | } |
447 | if (cp == NULL) |
446 | break; |
|
|
447 | |
|
|
448 | case KW_mods: |
|
|
449 | { |
|
|
450 | const char *cp = thawer.get_str () - 1; |
|
|
451 | |
|
|
452 | for (int i = 0; i < NROFATTACKS; i++) |
448 | { |
453 | { |
|
|
454 | if (!cp) |
|
|
455 | { |
449 | mt->save[i] = 0; |
456 | mt->save[i] = 0; |
450 | continue; |
457 | continue; |
|
|
458 | } |
|
|
459 | |
|
|
460 | ++cp; |
|
|
461 | int value; |
|
|
462 | sscanf (cp, "%d", &value); |
|
|
463 | mt->mod[i] = (sint8) value; |
|
|
464 | cp = strchr (cp, ','); |
451 | } |
465 | } |
452 | if ((next = strchr (cp, ',')) != NULL) |
|
|
453 | *(next++) = '\0'; |
|
|
454 | sscanf (cp, "%d", &value); |
|
|
455 | mt->mod[i] = (sint8) value; |
|
|
456 | cp = next; |
|
|
457 | } |
|
|
458 | } |
466 | } |
459 | else if (sscanf (cp, "chance %d\n", &value)) |
467 | break; |
|
|
468 | |
|
|
469 | case KW_chance: thawer.get (mt->chance); break; |
|
|
470 | case KW_difficulty: // cf+ alias, not original cf |
|
|
471 | case KW_diff: thawer.get (mt->difficulty); break; |
|
|
472 | case KW_magic: thawer.get (mt->magic); break; |
|
|
473 | case KW_dam: // cf+ alias, not original cf |
|
|
474 | case KW_damage: thawer.get (mt->damage); break; |
|
|
475 | case KW_wc: thawer.get (mt->wc); break; |
|
|
476 | case KW_ac: thawer.get (mt->ac); break; |
|
|
477 | case KW_sp: thawer.get (mt->sp); break; |
|
|
478 | case KW_weight: thawer.get (mt->weight); break; |
|
|
479 | case KW_value: thawer.get (mt->value); break; |
|
|
480 | case KW_density: thawer.get (mt->density); break; |
|
|
481 | |
|
|
482 | case KW_EOF: |
|
|
483 | goto done; |
|
|
484 | |
|
|
485 | default: |
|
|
486 | if (!thawer.parse_error (kw, "materials file", "materials")) |
|
|
487 | goto done; |
|
|
488 | break; |
460 | { |
489 | } |
461 | mt->chance = (sint8) value; |
|
|
462 | } |
|
|
463 | else if (sscanf (cp, "diff %d\n", &value)) |
|
|
464 | { |
|
|
465 | mt->difficulty = (sint8) value; |
|
|
466 | } |
|
|
467 | else if (sscanf (cp, "magic %d\n", &value)) |
|
|
468 | { |
|
|
469 | mt->magic = (sint8) value; |
|
|
470 | } |
|
|
471 | else if (sscanf (cp, "damage %d\n", &value)) |
|
|
472 | { |
|
|
473 | mt->damage = (sint8) value; |
|
|
474 | } |
|
|
475 | else if (sscanf (cp, "wc %d\n", &value)) |
|
|
476 | { |
|
|
477 | mt->wc = (sint8) value; |
|
|
478 | } |
|
|
479 | else if (sscanf (cp, "ac %d\n", &value)) |
|
|
480 | { |
|
|
481 | mt->ac = (sint8) value; |
|
|
482 | } |
|
|
483 | else if (sscanf (cp, "sp %d\n", &value)) |
|
|
484 | { |
|
|
485 | mt->sp = (sint8) value; |
|
|
486 | } |
|
|
487 | else if (sscanf (cp, "weight %d\n", &value)) |
|
|
488 | { |
|
|
489 | mt->weight = value; |
|
|
490 | } |
|
|
491 | else if (sscanf (cp, "value %d\n", &value)) |
|
|
492 | { |
|
|
493 | mt->value = value; |
|
|
494 | } |
|
|
495 | } |
490 | } |
|
|
491 | |
|
|
492 | done: |
496 | if (mt->next) |
493 | if (mt->next) |
497 | { |
494 | { |
498 | delete mt->next; |
495 | delete mt->next; |
499 | |
496 | |
500 | mt->next = NULL; |
497 | mt->next = 0; |
501 | } |
498 | } |
|
|
499 | |
502 | LOG (llevDebug, "Done.\n"); |
500 | LOG (llevDebug, "Done.\n"); |
503 | fclose (fp); |
|
|
504 | } |
501 | } |
505 | |
502 | |
506 | /* This loads the settings file. There could be debate whether this should |
503 | /* This loads the settings file. There could be debate whether this should |
507 | * be here or in the common directory - but since only the server needs this |
504 | * be here or in the common directory - but since only the server needs this |
508 | * information, having it here probably makes more sense. |
505 | * information, having it here probably makes more sense. |