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.78 by root, Fri May 2 16:16:02 2008 UTC vs.
Revision 1.83 by root, Mon Sep 29 10:20:48 2008 UTC

102{ 102{
103 shstr_cmp skill_cmp (skill); 103 shstr_cmp skill_cmp (skill);
104 104
105 for_all_archetypes (at) 105 for_all_archetypes (at)
106 if (at->skill == skill_cmp && (type == -1 || type == at->type)) 106 if (at->skill == skill_cmp && (type == -1 || type == at->type))
107 return arch_to_object (at); 107 return at->instance ();
108 108
109 return 0; 109 return 0;
110} 110}
111 111
112/* similiar to above - this returns the first archetype 112/* similiar to above - this returns the first archetype
149 for (i = strlen (tmpname); i > 0; i--) 149 for (i = strlen (tmpname); i > 0; i--)
150 { 150 {
151 tmpname[i] = 0; 151 tmpname[i] = 0;
152 152
153 if (archetype *at = find_archetype_by_object_name (tmpname)) 153 if (archetype *at = find_archetype_by_object_name (tmpname))
154 return arch_to_object (at); 154 return at->instance ();
155 } 155 }
156 156
157 return create_singularity (name); 157 return create_singularity (name);
158} 158}
159 159
511 if (at->refcnt_cnt () > 1) // all arches have ONE refcount from their object 511 if (at->refcnt_cnt () > 1) // all arches have ONE refcount from their object
512 ++idx; 512 ++idx;
513 else 513 else
514 { 514 {
515 LOG (llevDebug, "garbage collect arch %s", at->debug_desc ()); 515 LOG (llevDebug, "garbage collect arch %s", at->debug_desc ());
516 assert (at->arch == at); // verify that refcnt == 1 is truely valid 516 assert (at->arch == at); // verify that refcnt == 1 is truly valid
517 allarch.erase (idx); 517 allarch.erase (idx);
518 518
519 // break chain 519 // break chain
520 for (object *op = at->head_ (); op; ) 520 for (object *op = at->head_ (); op; )
521 { 521 {
523 op->head = 0; 523 op->head = 0;
524 op->more = 0; 524 op->more = 0;
525 op = next; 525 op = next;
526 } 526 }
527 527
528 op->destroy_inv (false);
528 at->destroy (); 529 at->destroy (true);
529 at->arch = 0; 530 at->arch = 0;
530 } 531 }
531 } 532 }
532 while (--cnt); 533 while (--cnt);
533} 534}
534 535
535/*
536 * Creates and returns a new object which is a copy of the given archetype.
537 * This function returns NULL on failure.
538 */
539object * 536object *
540arch_to_object (archetype *at) 537archetype::instance ()
541{ 538{
542 if (!at)
543 {
544 LOG (llevError, "Couldn't find archetype.\n");
545 return 0;
546 }
547
548 object *op = at->clone (); 539 object *op = clone ();
549 op->arch = at;
550 op->instantiate (); 540 op->instantiate ();
551
552 return op; 541 return op;
553}
554
555object *
556archetype::instance ()
557{
558 return arch_to_object (this);
559} 542}
560 543
561/* 544/*
562 * Creates an object. This function is called by get_archetype() 545 * Creates an object. This function is called by get_archetype()
563 * if it fails to find the appropriate archetype. 546 * if it fails to find the appropriate archetype.
570 LOG (llevError | logBacktrace, "FATAL: creating singularity for '%s'.\n", name); 553 LOG (llevError | logBacktrace, "FATAL: creating singularity for '%s'.\n", name);
571 554
572 if (!strcmp (name, "bug")) 555 if (!strcmp (name, "bug"))
573 abort (); 556 abort ();
574 557
575 char buf[MAX_BUF];
576 sprintf (buf, "bug, please report (%s)", name);
577
578 object *op = get_archetype ("bug"); 558 object *op = archetype::get (shstr_bug);
579 op->name = op->name_pl = buf; 559 op->name = op->name_pl = format ("bug, please report (missing archetype %s)", name);
580 560
581 return op; 561 return op;
582} 562}
583 563
584/* 564/*
586 * object containing a copy of the archetype. 566 * object containing a copy of the archetype.
587 */ 567 */
588object * 568object *
589get_archetype (const char *name) 569get_archetype (const char *name)
590{ 570{
571 return archetype::get (name);
572}
573
574object *
575archetype::get (const char *name)
576{
591 archetype *at = archetype::find (name); 577 archetype *at = find (name);
592 578
593 if (!at) 579 if (!at)
594 return create_singularity (name); 580 return create_singularity (name);
595 581
596 return arch_to_object (at); 582 return at->instance ();
597}
598
599object *
600archetype::get (const char *name)
601{
602 return get_archetype (name);
603} 583}
604 584
605/* 585/*
606 * Returns the first archetype using the given type. 586 * Returns the first archetype using the given type.
607 * Used in treasure-generation. 587 * Used in treasure-generation.
622 * Used in treasure-generation. 602 * Used in treasure-generation.
623 */ 603 */
624object * 604object *
625clone_arch (int type) 605clone_arch (int type)
626{ 606{
627 archetype *at; 607 archetype *at = type_to_archetype (type);
628 608
629 if ((at = type_to_archetype (type)) == NULL) 609 if (!at)
630 { 610 {
631 LOG (llevError, "Can't clone archetype %d\n", type); 611 LOG (llevError, "Can't clone archetype %d\n", type);
632 return 0; 612 return 0;
633 } 613 }
634 614
635 object *op = at->clone (); 615 return at->instance ();
636 op->instantiate ();
637 return op;
638} 616}
639 617
640/* 618/*
641 * member: make instance from class 619 * member: make instance from class
642 */ 620 */
645{ 623{
646 object *op, *prev = 0, *head = 0; 624 object *op, *prev = 0, *head = 0;
647 625
648 while (at) 626 while (at)
649 { 627 {
650 op = arch_to_object (at); 628 op = at->instance ();
651 629
652 op->x = at->x; 630 op->x = at->x;
653 op->y = at->y; 631 op->y = at->y;
654 632
655 if (head) 633 if (head)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines