… | |
… | |
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 | switch (thawer.get_kv ()) |
399 | continue; |
|
|
400 | if ((cp = strchr (buf, '\n')) != NULL) |
|
|
401 | *cp = '\0'; |
|
|
402 | cp = buf; |
|
|
403 | while (*cp == ' ') /* Skip blanks */ |
|
|
404 | cp++; |
|
|
405 | if (!strncmp (cp, "name", 4)) |
|
|
406 | { |
402 | { |
|
|
403 | case KW_name: |
407 | /* clean up the previous entry */ |
404 | /* clean up the previous entry */ |
408 | if (mt->next != NULL) |
405 | if (mt->next) |
409 | { |
406 | { |
410 | if (mt->description == NULL) |
407 | if (!mt->description) |
411 | mt->description = mt->name; |
408 | mt->description = mt->name; |
|
|
409 | |
412 | mt = mt->next; |
410 | mt = mt->next; |
413 | } |
411 | } |
|
|
412 | |
414 | mt->next = get_empty_mat (); |
413 | mt->next = get_empty_mat (); |
415 | mt->name = strchr (cp, ' ') + 1; |
414 | thawer.get (mt->name); |
416 | } |
415 | break; |
417 | else if (!strncmp (cp, "description", 11)) |
416 | |
|
|
417 | case KW_description: |
|
|
418 | thawer.get (mt->description); |
|
|
419 | break; |
|
|
420 | |
|
|
421 | case KW_material: |
|
|
422 | thawer.get (mt->material); |
|
|
423 | break; |
|
|
424 | |
|
|
425 | case KW_saves: |
418 | { |
426 | { |
419 | mt->description = strchr (cp, ' ') + 1; |
427 | const char *cp = thawer.get_str () - 1; |
420 | } |
428 | |
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++) |
429 | for (int i = 0; i < NROFATTACKS; i++) |
429 | { |
|
|
430 | if (cp == NULL) |
|
|
431 | { |
430 | { |
|
|
431 | if (!cp) |
|
|
432 | { |
432 | mt->save[i] = 0; |
433 | mt->save[i] = 0; |
433 | continue; |
434 | continue; |
|
|
435 | } |
|
|
436 | |
|
|
437 | int value; |
|
|
438 | ++cp; |
|
|
439 | sscanf (cp, "%d", &value); |
|
|
440 | mt->save[i] = (sint8) value; |
|
|
441 | cp = strchr (cp, ','); |
434 | } |
442 | } |
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 | { |
443 | } |
447 | if (cp == NULL) |
444 | break; |
|
|
445 | |
|
|
446 | case KW_mods: |
|
|
447 | { |
|
|
448 | const char *cp = thawer.get_str () - 1; |
|
|
449 | |
|
|
450 | for (int i = 0; i < NROFATTACKS; i++) |
448 | { |
451 | { |
|
|
452 | if (!cp) |
|
|
453 | { |
449 | mt->save[i] = 0; |
454 | mt->save[i] = 0; |
450 | continue; |
455 | continue; |
|
|
456 | } |
|
|
457 | |
|
|
458 | ++cp; |
|
|
459 | int value; |
|
|
460 | sscanf (cp, "%d", &value); |
|
|
461 | mt->mod[i] = (sint8) value; |
|
|
462 | cp = strchr (cp, ','); |
451 | } |
463 | } |
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 | } |
464 | } |
459 | else if (sscanf (cp, "chance %d\n", &value)) |
465 | break; |
|
|
466 | |
|
|
467 | case KW_chance: thawer.get (mt->chance); break; |
|
|
468 | case KW_difficulty: // cf+ alias, not original cf |
|
|
469 | case KW_diff: thawer.get (mt->difficulty); break; |
|
|
470 | case KW_magic: thawer.get (mt->magic); break; |
|
|
471 | case KW_dam: // cf+ alias, not original cf |
|
|
472 | case KW_damage: thawer.get (mt->damage); break; |
|
|
473 | case KW_wc: thawer.get (mt->wc); break; |
|
|
474 | case KW_ac: thawer.get (mt->ac); break; |
|
|
475 | case KW_sp: thawer.get (mt->sp); break; |
|
|
476 | case KW_weight: thawer.get (mt->weight); break; |
|
|
477 | case KW_value: thawer.get (mt->value); break; |
|
|
478 | case KW_density: thawer.get (mt->density); break; |
|
|
479 | |
|
|
480 | case KW_EOF: |
|
|
481 | goto done; |
|
|
482 | |
|
|
483 | default: |
|
|
484 | if (!thawer.parse_error ("materials file", "materials")) |
|
|
485 | goto done; |
|
|
486 | break; |
460 | { |
487 | } |
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 | } |
488 | } |
|
|
489 | |
|
|
490 | done: |
496 | if (mt->next) |
491 | if (mt->next) |
497 | { |
492 | { |
498 | delete mt->next; |
493 | delete mt->next; |
499 | |
494 | |
500 | mt->next = NULL; |
495 | mt->next = 0; |
501 | } |
496 | } |
|
|
497 | |
502 | LOG (llevDebug, "Done.\n"); |
498 | LOG (llevDebug, "Done.\n"); |
503 | fclose (fp); |
|
|
504 | } |
499 | } |
505 | |
500 | |
506 | /* This loads the settings file. There could be debate whether this should |
501 | /* 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 |
502 | * be here or in the common directory - but since only the server needs this |
508 | * information, having it here probably makes more sense. |
503 | * information, having it here probably makes more sense. |
… | |
… | |
518 | |
513 | |
519 | /* We don't require a settings file at current time, but down the road, |
514 | /* We don't require a settings file at current time, but down the road, |
520 | * there will probably be so many values that not having a settings file |
515 | * there will probably be so many values that not having a settings file |
521 | * will not be a good thing. |
516 | * will not be a good thing. |
522 | */ |
517 | */ |
523 | if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL) |
518 | if (!(fp = open_and_uncompress (buf, 0, &comp))) |
524 | { |
519 | { |
525 | LOG (llevError, "Warning: No settings file found\n"); |
520 | LOG (llevError, "Error: No settings file found\n"); |
526 | return; |
521 | exit (1); |
527 | } |
522 | } |
|
|
523 | |
528 | while (fgets (buf, MAX_BUF - 1, fp) != NULL) |
524 | while (fgets (buf, MAX_BUF - 1, fp) != NULL) |
529 | { |
525 | { |
530 | if (buf[0] == '#') |
526 | if (buf[0] == '#') |
531 | continue; |
527 | continue; |
532 | /* eliminate newline */ |
528 | /* eliminate newline */ |
… | |
… | |
990 | { |
986 | { |
991 | init_done = 0; /* Must be done before init_signal() */ |
987 | init_done = 0; /* Must be done before init_signal() */ |
992 | rndm.seed (time (0)); |
988 | rndm.seed (time (0)); |
993 | |
989 | |
994 | logfile = stderr; |
990 | logfile = stderr; |
|
|
991 | init_environ (); |
995 | parse_args (argc, argv, 1); /* First arg pass - right now it does |
992 | parse_args (argc, argv, 1); /* First arg pass - right now it does |
996 | * nothing, but in future specifying the |
993 | * nothing, but in future specifying the |
997 | * LibDir in this pass would be reasonable*/ |
994 | * LibDir in this pass would be reasonable*/ |
998 | |
995 | |
999 | cfperl_init (); |
996 | cfperl_init (); |
… | |
… | |
1320 | set_list = 0; |
1317 | set_list = 0; |
1321 | cp++; |
1318 | cp++; |
1322 | } |
1319 | } |
1323 | |
1320 | |
1324 | if (sscanf (cp, "RACE %s", variable)) |
1321 | if (sscanf (cp, "RACE %s", variable)) |
1325 | { /* set new race value */ |
1322 | /* set new race value */ |
1326 | strcpy (race, variable); |
1323 | strcpy (race, variable); |
1327 | } |
|
|
1328 | else |
1324 | else |
1329 | { |
1325 | { |
1330 | char *cp1; |
1326 | char *cp1; |
1331 | |
1327 | |
1332 | /* Take out beginning spaces */ |
1328 | /* Take out beginning spaces */ |