1 | /* |
1 | /* |
2 | * static char *rcsid_arch_c = |
2 | * static char *rcsid_arch_c = |
3 | * "$Id: arch.C,v 1.7 2006/08/29 08:01:35 root Exp $"; |
3 | * "$Id: arch.C,v 1.8 2006/08/30 06:06:26 root Exp $"; |
4 | */ |
4 | */ |
5 | |
5 | |
6 | /* |
6 | /* |
7 | CrossFire, A Multiplayer game for X-windows |
7 | CrossFire, A Multiplayer game for X-windows |
8 | |
8 | |
… | |
… | |
507 | * Reads and parses the archetype file (with the first and second-pass |
507 | * Reads and parses the archetype file (with the first and second-pass |
508 | * functions). |
508 | * functions). |
509 | * Then initialises treasures by calling load_treasures(). |
509 | * Then initialises treasures by calling load_treasures(). |
510 | */ |
510 | */ |
511 | |
511 | |
|
|
512 | void |
512 | void load_archetypes(void) { |
513 | load_archetypes (void) |
513 | FILE *fp; |
514 | { |
514 | char filename[MAX_BUF]; |
515 | char filename[MAX_BUF]; |
515 | int comp; |
516 | int comp; |
516 | #if TIME_ARCH_LOAD |
517 | #if TIME_ARCH_LOAD |
517 | struct timeval tv1,tv2; |
518 | struct timeval tv1, tv2; |
518 | #endif |
519 | #endif |
519 | |
520 | |
520 | sprintf(filename,"%s/%s",settings.datadir,settings.archetypes); |
521 | sprintf (filename, "%s/%s", settings.datadir, settings.archetypes); |
521 | LOG(llevDebug,"Reading archetypes from %s...\n",filename); |
522 | LOG (llevDebug, "Reading archetypes from %s:\n", filename); |
522 | if((fp=open_and_uncompress(filename,0,&comp))==NULL) { |
523 | |
523 | LOG(llevError," Can't open archetype file.\n"); |
524 | { |
524 | return; |
525 | object_thawer thawer (filename); |
525 | } |
526 | |
526 | clear_archetable(); |
527 | clear_archetable (); |
527 | LOG(llevDebug," arch-pass 1...\n"); |
528 | LOG (llevDebug, " arch-pass 1...\n"); |
528 | #if TIME_ARCH_LOAD |
529 | first_arch_pass (thawer); |
529 | GETTIMEOFDAY(&tv1); |
530 | LOG (llevDebug, " done\n"); |
|
|
531 | |
|
|
532 | init_archetable (); |
|
|
533 | warn_archetypes = 1; |
|
|
534 | } |
|
|
535 | |
|
|
536 | { |
|
|
537 | object_thawer thawer (filename); |
|
|
538 | |
|
|
539 | LOG (llevDebug, " loading treasure...\n"); |
|
|
540 | load_treasures (); |
|
|
541 | LOG (llevDebug, " done\n arch-pass 2...\n"); |
|
|
542 | second_arch_pass (thawer); |
|
|
543 | LOG (llevDebug, " done\n"); |
|
|
544 | #ifdef DEBUG |
|
|
545 | check_generators (); |
530 | #endif |
546 | #endif |
531 | { |
|
|
532 | object_thawer thawer (fp); |
|
|
533 | first_arch_pass (thawer); |
|
|
534 | } |
547 | } |
535 | #if TIME_ARCH_LOAD |
|
|
536 | { int sec, usec; |
|
|
537 | GETTIMEOFDAY(&tv2); |
|
|
538 | sec = tv2.tv_sec - tv1.tv_sec; |
|
|
539 | usec = tv2.tv_usec - tv1.tv_usec; |
|
|
540 | if (usec<0) { usec +=1000000; sec--;} |
|
|
541 | LOG(llevDebug,"Load took %d.%06d seconds\n", sec, usec); |
|
|
542 | } |
|
|
543 | #endif |
|
|
544 | |
|
|
545 | LOG(llevDebug," done\n"); |
548 | LOG (llevDebug, " done\n"); |
546 | init_archetable(); |
|
|
547 | warn_archetypes=1; |
|
|
548 | |
|
|
549 | /* do a close and reopen instead of a rewind - necessary in case the |
|
|
550 | * file has been compressed. |
|
|
551 | */ |
|
|
552 | close_and_delete(fp, comp); |
|
|
553 | fp=open_and_uncompress(filename,0,&comp); |
|
|
554 | |
|
|
555 | LOG(llevDebug," loading treasure...\n"); |
|
|
556 | load_treasures(); |
|
|
557 | LOG(llevDebug," done\n arch-pass 2...\n"); |
|
|
558 | second_arch_pass(fp); |
|
|
559 | LOG(llevDebug," done\n"); |
|
|
560 | #ifdef DEBUG |
|
|
561 | check_generators(); |
|
|
562 | #endif |
|
|
563 | close_and_delete(fp, comp); |
|
|
564 | LOG(llevDebug," done\n"); |
|
|
565 | } |
549 | } |
566 | |
550 | |
567 | /* |
551 | /* |
568 | * Creates and returns a new object which is a copy of the given archetype. |
552 | * Creates and returns a new object which is a copy of the given archetype. |
569 | * This function returns NULL on failure. |
553 | * This function returns NULL on failure. |