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.37 by pippijn, Mon Jan 15 21:06:18 2007 UTC

1/* 1/*
2 CrossFire, A Multiplayer game for X-windows 2 * CrossFire, A Multiplayer game for X-windows
3 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (C) 1992 Frank Tore Johansen
6 7 *
7 This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version. 11 * (at your option) any later version.
11 12 *
12 This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 16 * GNU General Public License for more details.
16 17 *
17 You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software 19 * along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 21 *
21 The authors can be reached via e-mail at <crossfire@schmorp.de> 22 * The authors can be reached via e-mail at <crossfire@schmorp.de>
22*/ 23 */
23 24
24#include <cassert> 25#include <cassert>
25 26
26#include <global.h> 27#include <global.h>
27#include <funcpoint.h> 28#include <funcpoint.h>
118 * If type is -1, ew don't match on type. 119 * If type is -1, ew don't match on type.
119 */ 120 */
120object * 121object *
121get_archetype_by_skill_name (const char *skill, int type) 122get_archetype_by_skill_name (const char *skill, int type)
122{ 123{
123 archetype * 124 archetype *at;
124 at;
125 125
126 if (skill == NULL) 126 if (skill)
127 return NULL;
128
129 for (at = first_archetype; at != NULL; at = at->next) 127 for (at = first_archetype; at; at = at->next)
130 {
131 if (((type == -1) || (type == at->clone.type)) && (!strcmp (at->clone.skill, skill))) 128 if (((type == -1) || (type == at->clone.type)) && (!strcmp (at->clone.skill, skill)))
132 return arch_to_object (at); 129 return arch_to_object (at);
133 } 130
134 return NULL; 131 return 0;
135} 132}
136 133
137/* similiar to above - this returns the first archetype 134/* similiar to above - this returns the first archetype
138 * that matches both the type and subtype. type and subtype 135 * 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 136 * can be -1 to say ignore, but in this case, the match it does
179 for (i = strlen (tmpname); i > 0; i--) 176 for (i = strlen (tmpname); i > 0; i--)
180 { 177 {
181 tmpname[i] = 0; 178 tmpname[i] = 0;
182 at = find_archetype_by_object_name (tmpname); 179 at = find_archetype_by_object_name (tmpname);
183 180
184 if (at != NULL) 181 if (at)
185 return arch_to_object (at); 182 return arch_to_object (at);
186 } 183 }
187 184
188 return create_singularity (name); 185 return create_singularity (name);
189} 186}
387 LOG (llevDebug, "Freed %d archetypes, %d faces\n", i, f); 384 LOG (llevDebug, "Freed %d archetypes, %d faces\n", i, f);
388} 385}
389 386
390archetype::archetype () 387archetype::archetype ()
391{ 388{
392 clear_object (&clone); /* to initial state other also */
393 CLEAR_FLAG (&clone, FLAG_FREED); /* This shouldn't matter, since copy_object() */ 389 CLEAR_FLAG (&clone, FLAG_FREED); /* This shouldn't matter, since copy_to */
394 SET_FLAG (&clone, FLAG_REMOVED); /* doesn't copy these flags... */ 390 SET_FLAG (&clone, FLAG_REMOVED); /* doesn't copy these flags... */
395} 391}
396 392
397archetype::~archetype () 393archetype::~archetype ()
398{ 394{
403 * of archetype-structures. 399 * of archetype-structures.
404 */ 400 */
405void 401void
406first_arch_pass (object_thawer & fp) 402first_arch_pass (object_thawer & fp)
407{ 403{
408 archetype *at, *head = NULL, *last_more = NULL; 404 archetype *head = 0, *last_more = 0;
409 405
406 archetype *at = new archetype;
410 at->clone.arch = first_archetype = at = new archetype; 407 at->clone.arch = first_archetype = at;
411 408
412 while (int i = load_object (fp, &at->clone, 0)) 409 while (int i = load_object (fp, &at->clone, 0))
413 { 410 {
414 at->clone.speed_left = (float) (-0.1); 411 at->clone.speed_left = (float) (-0.1);
415 /* copy the body_info to the body_used - this is only really 412 /* copy the body_info to the body_used - this is only really
575 object_thawer 572 object_thawer
576 thawer (filename); 573 thawer (filename);
577 574
578 LOG (llevDebug, " loading treasure...\n"); 575 LOG (llevDebug, " loading treasure...\n");
579 load_treasures (); 576 load_treasures ();
577 LOG (llevDebug, " done\n");
580 LOG (llevDebug, " done\n arch-pass 2...\n"); 578 LOG (llevDebug, " arch-pass 2...\n");
581 second_arch_pass (thawer); 579 second_arch_pass (thawer);
582 LOG (llevDebug, " done\n"); 580 LOG (llevDebug, " done\n");
583#ifdef DEBUG 581#ifdef DEBUG
584 check_generators (); 582 check_generators ();
585#endif 583#endif
589 587
590/* 588/*
591 * Creates and returns a new object which is a copy of the given archetype. 589 * Creates and returns a new object which is a copy of the given archetype.
592 * This function returns NULL on failure. 590 * This function returns NULL on failure.
593 */ 591 */
594
595object * 592object *
596arch_to_object (archetype *at) 593arch_to_object (archetype *at)
597{ 594{
598 object *op; 595 object *op;
599 596
603 LOG (llevError, "Couldn't find archetype.\n"); 600 LOG (llevError, "Couldn't find archetype.\n");
604 601
605 return NULL; 602 return NULL;
606 } 603 }
607 604
608 op = get_object (); 605 op = at->clone.clone ();
609 copy_object (&at->clone, op);
610 op->arch = at; 606 op->arch = at;
611 op->instantiate (); 607 op->instantiate ();
612 return op; 608 return op;
613} 609}
614 610
616 * Creates an object. This function is called by get_archetype() 612 * Creates an object. This function is called by get_archetype()
617 * if it fails to find the appropriate archetype. 613 * if it fails to find the appropriate archetype.
618 * Thus get_archetype() will be guaranteed to always return 614 * Thus get_archetype() will be guaranteed to always return
619 * an object, and never NULL. 615 * an object, and never NULL.
620 */ 616 */
621
622object * 617object *
623create_singularity (const char *name) 618create_singularity (const char *name)
624{ 619{
625 object *op; 620 object *op;
626 char buf[MAX_BUF]; 621 char buf[MAX_BUF];
627 622
628 sprintf (buf, "%s (%s)", ARCH_SINGULARITY, name); 623 sprintf (buf, "%s (%s)", ARCH_SINGULARITY, name);
629 op = get_object (); 624 op = object::create ();
630 op->name = op->name_pl = buf; 625 op->name = op->name_pl = buf;
631 SET_FLAG (op, FLAG_NO_PICK); 626 SET_FLAG (op, FLAG_NO_PICK);
632 return op; 627 return op;
633} 628}
634 629
635/* 630/*
636 * Finds which archetype matches the given name, and returns a new 631 * Finds which archetype matches the given name, and returns a new
637 * object containing a copy of the archetype. 632 * object containing a copy of the archetype.
638 */ 633 */
639
640object * 634object *
641get_archetype (const char *name) 635get_archetype (const char *name)
642{ 636{
643 archetype *at = archetype::find (name); 637 archetype *at = archetype::find (name);
644 638
805 799
806object * 800object *
807clone_arch (int type) 801clone_arch (int type)
808{ 802{
809 archetype *at; 803 archetype *at;
810 object *op = get_object ();
811 804
812 if ((at = type_to_archetype (type)) == NULL) 805 if ((at = type_to_archetype (type)) == NULL)
813 { 806 {
814 LOG (llevError, "Can't clone archetype %d\n", type); 807 LOG (llevError, "Can't clone archetype %d\n", type);
815 free_object (op);
816 return NULL; 808 return 0;
817 } 809 }
818 810
819 copy_object (&at->clone, op); 811 object *op = at->clone.clone ();
820 op->instantiate (); 812 op->instantiate ();
821 return op; 813 return op;
822} 814}
823 815
824/* 816/*

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines