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.26 by root, Fri Nov 17 19:40:53 2006 UTC vs.
Revision 1.35 by root, Wed Jan 3 20:32:13 2007 UTC

118 * If type is -1, ew don't match on type. 118 * If type is -1, ew don't match on type.
119 */ 119 */
120object * 120object *
121get_archetype_by_skill_name (const char *skill, int type) 121get_archetype_by_skill_name (const char *skill, int type)
122{ 122{
123 archetype * 123 archetype *at;
124 at;
125 124
126 if (skill == NULL) 125 if (skill)
127 return NULL;
128
129 for (at = first_archetype; at != NULL; at = at->next) 126 for (at = first_archetype; at; at = at->next)
130 {
131 if (((type == -1) || (type == at->clone.type)) && (!strcmp (at->clone.skill, skill))) 127 if (((type == -1) || (type == at->clone.type)) && (!strcmp (at->clone.skill, skill)))
132 return arch_to_object (at); 128 return arch_to_object (at);
133 } 129
134 return NULL; 130 return 0;
135} 131}
136 132
137/* similiar to above - this returns the first archetype 133/* similiar to above - this returns the first archetype
138 * that matches both the type and subtype. type and subtype 134 * that matches both the type and subtype. type and subtype
139 * can be -1 to say ignore, but in this case, the match it does 135 * can be -1 to say ignore, but in this case, the match it does
179 for (i = strlen (tmpname); i > 0; i--) 175 for (i = strlen (tmpname); i > 0; i--)
180 { 176 {
181 tmpname[i] = 0; 177 tmpname[i] = 0;
182 at = find_archetype_by_object_name (tmpname); 178 at = find_archetype_by_object_name (tmpname);
183 179
184 if (at != NULL) 180 if (at)
185 return arch_to_object (at); 181 return arch_to_object (at);
186 } 182 }
187 183
188 return create_singularity (name); 184 return create_singularity (name);
189} 185}
387 LOG (llevDebug, "Freed %d archetypes, %d faces\n", i, f); 383 LOG (llevDebug, "Freed %d archetypes, %d faces\n", i, f);
388} 384}
389 385
390archetype::archetype () 386archetype::archetype ()
391{ 387{
392 clear_object (&clone); /* to initial state other also */
393 CLEAR_FLAG (&clone, FLAG_FREED); /* This shouldn't matter, since copy_object() */ 388 CLEAR_FLAG (&clone, FLAG_FREED); /* This shouldn't matter, since copy_to */
394 SET_FLAG (&clone, FLAG_REMOVED); /* doesn't copy these flags... */ 389 SET_FLAG (&clone, FLAG_REMOVED); /* doesn't copy these flags... */
395} 390}
396 391
397archetype::~archetype () 392archetype::~archetype ()
398{ 393{
403 * of archetype-structures. 398 * of archetype-structures.
404 */ 399 */
405void 400void
406first_arch_pass (object_thawer & fp) 401first_arch_pass (object_thawer & fp)
407{ 402{
408 archetype *at, *head = NULL, *last_more = NULL; 403 archetype *head = 0, *last_more = 0;
409 404
405 archetype *at = new archetype;
410 at->clone.arch = first_archetype = at = new archetype; 406 at->clone.arch = first_archetype = at;
411 407
412 while (int i = load_object (fp, &at->clone, 0)) 408 while (int i = load_object (fp, &at->clone, 0))
413 { 409 {
414 at->clone.speed_left = (float) (-0.1); 410 at->clone.speed_left = (float) (-0.1);
415 /* copy the body_info to the body_used - this is only really 411 /* copy the body_info to the body_used - this is only really
575 object_thawer 571 object_thawer
576 thawer (filename); 572 thawer (filename);
577 573
578 LOG (llevDebug, " loading treasure...\n"); 574 LOG (llevDebug, " loading treasure...\n");
579 load_treasures (); 575 load_treasures ();
576 LOG (llevDebug, " done\n");
580 LOG (llevDebug, " done\n arch-pass 2...\n"); 577 LOG (llevDebug, " arch-pass 2...\n");
581 second_arch_pass (thawer); 578 second_arch_pass (thawer);
582 LOG (llevDebug, " done\n"); 579 LOG (llevDebug, " done\n");
583#ifdef DEBUG 580#ifdef DEBUG
584 check_generators (); 581 check_generators ();
585#endif 582#endif
589 586
590/* 587/*
591 * Creates and returns a new object which is a copy of the given archetype. 588 * Creates and returns a new object which is a copy of the given archetype.
592 * This function returns NULL on failure. 589 * This function returns NULL on failure.
593 */ 590 */
594
595object * 591object *
596arch_to_object (archetype *at) 592arch_to_object (archetype *at)
597{ 593{
598 object *op; 594 object *op;
599 595
603 LOG (llevError, "Couldn't find archetype.\n"); 599 LOG (llevError, "Couldn't find archetype.\n");
604 600
605 return NULL; 601 return NULL;
606 } 602 }
607 603
608 op = get_object (); 604 op = at->clone.clone ();
609 copy_object (&at->clone, op);
610 op->arch = at; 605 op->arch = at;
611 op->instantiate (); 606 op->instantiate ();
612 return op; 607 return op;
613} 608}
614 609
616 * Creates an object. This function is called by get_archetype() 611 * Creates an object. This function is called by get_archetype()
617 * if it fails to find the appropriate archetype. 612 * if it fails to find the appropriate archetype.
618 * Thus get_archetype() will be guaranteed to always return 613 * Thus get_archetype() will be guaranteed to always return
619 * an object, and never NULL. 614 * an object, and never NULL.
620 */ 615 */
621
622object * 616object *
623create_singularity (const char *name) 617create_singularity (const char *name)
624{ 618{
625 object *op; 619 object *op;
626 char buf[MAX_BUF]; 620 char buf[MAX_BUF];
627 621
628 sprintf (buf, "%s (%s)", ARCH_SINGULARITY, name); 622 sprintf (buf, "%s (%s)", ARCH_SINGULARITY, name);
629 op = get_object (); 623 op = object::create ();
630 op->name = op->name_pl = buf; 624 op->name = op->name_pl = buf;
631 SET_FLAG (op, FLAG_NO_PICK); 625 SET_FLAG (op, FLAG_NO_PICK);
632 return op; 626 return op;
633} 627}
634 628
635/* 629/*
636 * Finds which archetype matches the given name, and returns a new 630 * Finds which archetype matches the given name, and returns a new
637 * object containing a copy of the archetype. 631 * object containing a copy of the archetype.
638 */ 632 */
639
640object * 633object *
641get_archetype (const char *name) 634get_archetype (const char *name)
642{ 635{
643 archetype *at = archetype::find (name); 636 archetype *at = archetype::find (name);
644 637
805 798
806object * 799object *
807clone_arch (int type) 800clone_arch (int type)
808{ 801{
809 archetype *at; 802 archetype *at;
810 object *op = get_object ();
811 803
812 if ((at = type_to_archetype (type)) == NULL) 804 if ((at = type_to_archetype (type)) == NULL)
813 { 805 {
814 LOG (llevError, "Can't clone archetype %d\n", type); 806 LOG (llevError, "Can't clone archetype %d\n", type);
815 free_object (op);
816 return NULL; 807 return 0;
817 } 808 }
818 809
819 copy_object (&at->clone, op); 810 object *op = at->clone.clone ();
820 op->instantiate (); 811 op->instantiate ();
821 return op; 812 return op;
822} 813}
823 814
824/* 815/*

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines