… | |
… | |
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 | |
… | |
… | |
543 | { |
543 | { |
544 | LOG (llevError, "Couldn't find archetype.\n"); |
544 | LOG (llevError, "Couldn't find archetype.\n"); |
545 | return 0; |
545 | return 0; |
546 | } |
546 | } |
547 | |
547 | |
|
|
548 | return at->instance (); |
|
|
549 | } |
|
|
550 | |
|
|
551 | object * |
|
|
552 | archetype::instance () |
|
|
553 | { |
548 | object *op = at->clone (); |
554 | object *op = clone (); |
549 | op->arch = at; |
|
|
550 | op->instantiate (); |
555 | op->instantiate (); |
551 | |
|
|
552 | return op; |
556 | return op; |
553 | } |
|
|
554 | |
|
|
555 | object * |
|
|
556 | archetype::instance () |
|
|
557 | { |
|
|
558 | return arch_to_object (this); |
|
|
559 | } |
557 | } |
560 | |
558 | |
561 | /* |
559 | /* |
562 | * Creates an object. This function is called by get_archetype() |
560 | * Creates an object. This function is called by get_archetype() |
563 | * if it fails to find the appropriate archetype. |
561 | * if it fails to find the appropriate archetype. |
… | |
… | |
570 | LOG (llevError | logBacktrace, "FATAL: creating singularity for '%s'.\n", name); |
568 | LOG (llevError | logBacktrace, "FATAL: creating singularity for '%s'.\n", name); |
571 | |
569 | |
572 | if (!strcmp (name, "bug")) |
570 | if (!strcmp (name, "bug")) |
573 | abort (); |
571 | abort (); |
574 | |
572 | |
575 | char buf[MAX_BUF]; |
|
|
576 | sprintf (buf, "bug, please report (%s)", name); |
|
|
577 | |
|
|
578 | object *op = get_archetype ("bug"); |
573 | object *op = archetype::get ("bug"); |
579 | op->name = op->name_pl = buf; |
574 | op->name = op->name_pl = format ("bug, please report (missing archetype %s)", name); |
580 | |
575 | |
581 | return op; |
576 | return op; |
582 | } |
577 | } |
583 | |
578 | |
584 | /* |
579 | /* |
… | |
… | |
586 | * object containing a copy of the archetype. |
581 | * object containing a copy of the archetype. |
587 | */ |
582 | */ |
588 | object * |
583 | object * |
589 | get_archetype (const char *name) |
584 | get_archetype (const char *name) |
590 | { |
585 | { |
|
|
586 | return archetype::get (name); |
|
|
587 | } |
|
|
588 | |
|
|
589 | object * |
|
|
590 | archetype::get (const char *name) |
|
|
591 | { |
591 | archetype *at = archetype::find (name); |
592 | archetype *at = find (name); |
592 | |
593 | |
593 | if (!at) |
594 | if (!at) |
594 | return create_singularity (name); |
595 | return create_singularity (name); |
595 | |
596 | |
596 | return arch_to_object (at); |
597 | return at->instance (); |
597 | } |
|
|
598 | |
|
|
599 | object * |
|
|
600 | archetype::get (const char *name) |
|
|
601 | { |
|
|
602 | return get_archetype (name); |
|
|
603 | } |
598 | } |
604 | |
599 | |
605 | /* |
600 | /* |
606 | * Returns the first archetype using the given type. |
601 | * Returns the first archetype using the given type. |
607 | * Used in treasure-generation. |
602 | * Used in treasure-generation. |
… | |
… | |
622 | * Used in treasure-generation. |
617 | * Used in treasure-generation. |
623 | */ |
618 | */ |
624 | object * |
619 | object * |
625 | clone_arch (int type) |
620 | clone_arch (int type) |
626 | { |
621 | { |
627 | archetype *at; |
622 | archetype *at = type_to_archetype (type); |
628 | |
623 | |
629 | if ((at = type_to_archetype (type)) == NULL) |
624 | if (!at) |
630 | { |
625 | { |
631 | LOG (llevError, "Can't clone archetype %d\n", type); |
626 | LOG (llevError, "Can't clone archetype %d\n", type); |
632 | return 0; |
627 | return 0; |
633 | } |
628 | } |
634 | |
629 | |
635 | object *op = at->clone (); |
630 | return at->instance (); |
636 | op->instantiate (); |
|
|
637 | return op; |
|
|
638 | } |
631 | } |
639 | |
632 | |
640 | /* |
633 | /* |
641 | * member: make instance from class |
634 | * member: make instance from class |
642 | */ |
635 | */ |
… | |
… | |
645 | { |
638 | { |
646 | object *op, *prev = 0, *head = 0; |
639 | object *op, *prev = 0, *head = 0; |
647 | |
640 | |
648 | while (at) |
641 | while (at) |
649 | { |
642 | { |
650 | op = arch_to_object (at); |
643 | op = at->instance (); |
651 | |
644 | |
652 | op->x = at->x; |
645 | op->x = at->x; |
653 | op->y = at->y; |
646 | op->y = at->y; |
654 | |
647 | |
655 | if (head) |
648 | if (head) |