ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/arch.C
(Generate patch)

Comparing deliantra/server/common/arch.C (file contents):
Revision 1.13 by pippijn, Thu Sep 7 09:37:11 2006 UTC vs.
Revision 1.14 by root, Fri Sep 8 17:14:07 2006 UTC

1/* 1/*
2 * static char *rcsid_arch_c = 2 * static char *rcsid_arch_c =
3 * "$Id: arch.C,v 1.13 2006/09/07 09:37:11 pippijn Exp $"; 3 * "$Id: arch.C,v 1.14 2006/09/08 17:14:07 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
419 i++; 419 i++;
420 } 420 }
421 LOG (llevDebug, "Freed %d archetypes, %d faces\n", i, f); 421 LOG (llevDebug, "Freed %d archetypes, %d faces\n", i, f);
422} 422}
423 423
424/* 424archetype::archetype ()
425 * Allocates, initialises and returns the pointer to an archetype structure.
426 */
427// TODO: should become constructor
428archetype *
429get_archetype_struct (void)
430{ 425{
431 archetype *
432 arch;
433
434 arch = new archetype;
435
436 clear_object (&arch->clone); /* to initial state other also */ 426 clear_object (&clone); /* to initial state other also */
437 CLEAR_FLAG (&arch->clone, FLAG_FREED); /* This shouldn't matter, since copy_object() */ 427 CLEAR_FLAG (&clone, FLAG_FREED); /* This shouldn't matter, since copy_object() */
438 SET_FLAG (&arch->clone, FLAG_REMOVED); /* doesn't copy these flags... */ 428 SET_FLAG (&clone, FLAG_REMOVED); /* doesn't copy these flags... */
429}
439 430
440 return arch; 431archetype::~archetype ()
432{
441} 433}
442 434
443/* 435/*
444 * Reads/parses the archetype-file, and copies into a linked list 436 * Reads/parses the archetype-file, and copies into a linked list
445 * of archetype-structures. 437 * of archetype-structures.
446 */ 438 */
447void 439void
448first_arch_pass (object_thawer & fp) 440first_arch_pass (object_thawer & fp)
449{ 441{
450 object *
451 op;
452 archetype *
453 at, *
454 head = NULL, *last_more = NULL; 442 archetype *at, *head = NULL, *last_more = NULL;
455 int
456 i;
457 443
458 op = get_object ();
459 op->arch = first_archetype = at = get_archetype_struct (); 444 at->clone.arch = first_archetype = at = new archetype;
460 445
461 while ((i = load_object (fp, op, 0))) 446 while (int i = load_object (fp, &at->clone, 0))
462 { 447 {
463 copy_object (op, &at->clone);
464 at->clone.speed_left = (float) (-0.1); 448 at->clone.speed_left = (float) (-0.1);
465 /* copy the body_info to the body_used - this is only really 449 /* copy the body_info to the body_used - this is only really
466 * need for monsters, but doesn't hurt to do it for everything. 450 * need for monsters, but doesn't hurt to do it for everything.
467 * by doing so, when a monster is created, it has good starting 451 * by doing so, when a monster is created, it has good starting
468 * values for the body_used info, so when items are created 452 * values for the body_used info, so when items are created
469 * for it, they can be properly equipped. 453 * for it, they can be properly equipped.
470 */ 454 */
471 memcpy (&at->clone.body_used, &op->body_info, sizeof (op->body_info)); 455 memcpy (&at->clone.body_used, &at->clone.body_info, sizeof (at->clone.body_info));
472 456
473 switch (i) 457 switch (i)
474 { 458 {
475 case LL_NORMAL: /* A new archetype, just link it with the previous */ 459 case LL_NORMAL: /* A new archetype, just link it with the previous */
476 if (last_more != NULL) 460 if (last_more != NULL)
516 } 500 }
517 break; 501 break;
518 502
519 } 503 }
520 504
521 at = get_archetype_struct (); 505 at = new archetype;
522 clear_object (op);
523 op->arch = at; 506 at->clone.arch = at;
524 } 507 }
525 508
526 delete 509 delete at;
527 at;
528 free_object (op);
529} 510}
530 511
531/* 512/*
532 * Reads the archetype file once more, and links all pointers between 513 * Reads the archetype file once more, and links all pointers between
533 * archetypes. 514 * archetypes.
534 */ 515 */
535 516
536void 517void
537second_arch_pass (object_thawer & thawer) 518second_arch_pass (object_thawer & thawer)
538{ 519{
539 char
540 buf[MAX_BUF], *
541 variable = buf, *argument, *cp; 520 char buf[MAX_BUF], *variable = buf, *argument, *cp;
542 archetype *
543 at = NULL, *other; 521 archetype *at = NULL, *other;
544 522
545 while (fgets (buf, MAX_BUF, thawer) != NULL) 523 while (fgets (buf, MAX_BUF, thawer) != NULL)
546 { 524 {
547 if (*buf == '#') 525 if (*buf == '#')
548 continue; 526 continue;
679 */ 657 */
680 658
681object * 659object *
682create_singularity (const char *name) 660create_singularity (const char *name)
683{ 661{
684 object * 662 object *op;
685 op;
686 char
687 buf[MAX_BUF]; 663 char buf[MAX_BUF];
688 sprintf (buf, "%s (%s)", ARCH_SINGULARITY, name); 664 sprintf (buf, "%s (%s)", ARCH_SINGULARITY, name);
689 op = get_object (); 665 op = get_object ();
690 op->name = op->name_pl = buf; 666 op->name = op->name_pl = buf;
691 SET_FLAG (op, FLAG_NO_PICK); 667 SET_FLAG (op, FLAG_NO_PICK);
692 return op; 668 return op;
698 */ 674 */
699 675
700object * 676object *
701get_archetype (const char *name) 677get_archetype (const char *name)
702{ 678{
703 archetype * 679 archetype *at;
704 at;
705 at = find_archetype (name); 680 at = find_archetype (name);
706 if (at == NULL) 681 if (at == NULL)
707 return create_singularity (name); 682 return create_singularity (name);
708 return arch_to_object (at); 683 return arch_to_object (at);
709} 684}
713 */ 688 */
714 689
715unsigned long 690unsigned long
716hasharch (const char *str, int tablesize) 691hasharch (const char *str, int tablesize)
717{ 692{
718 unsigned long 693 unsigned long hash = 0;
719 hash = 0;
720 unsigned int 694 unsigned int i = 0;
721 i = 0;
722 const char * 695 const char *p;
723 p;
724 696
725 /* use the one-at-a-time hash function, which supposedly is 697 /* use the one-at-a-time hash function, which supposedly is
726 * better than the djb2-like one used by perl5.005, but 698 * better than the djb2-like one used by perl5.005, but
727 * certainly is better then the bug used here before. 699 * certainly is better then the bug used here before.
728 * see http://burtleburtle.net/bob/hash/doobs.html 700 * see http://burtleburtle.net/bob/hash/doobs.html

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines