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.90 by root, Fri Oct 16 00:30:19 2009 UTC vs.
Revision 1.96 by root, Sat Nov 7 18:30:05 2009 UTC

51// the vector of other_arch references to be resolved 51// the vector of other_arch references to be resolved
52static std::vector< std::pair<arch_ptr *, shstr> > postponed_arch_ref; 52static std::vector< std::pair<arch_ptr *, shstr> > postponed_arch_ref;
53// the vector of loaded but not yet committed archetypes 53// the vector of loaded but not yet committed archetypes
54static std::vector<archetype *> postponed_arch; 54static std::vector<archetype *> postponed_arch;
55 55
56//+GPL
57
58/*
59 * Creates an object. This function is called by get_archetype ()
60 * if it fails to find the appropriate archetype.
61 * Thus get_archetype() will be guaranteed to always return
62 * an object, and never NULL.
63 */
64static object *
65create_singularity (const char *name)
66{
67 LOG (llevError | logBacktrace, "FATAL: creating singularity for '%s'.\n", name);
68
69 if (!strcmp (name, "bug"))
70 abort ();
71
72 object *op = archetype::get (shstr_bug);
73 op->name = op->name_pl = format ("bug, please report (missing archetype %s)", name);
74
75 return op;
76}
77
56/** 78/**
57 * GROS - This function retrieves an archetype given the name that appears 79 * GROS - This function retrieves an archetype given the name that appears
58 * during the game (for example, "writing pen" instead of "stylus"). 80 * during the game (for example, "writing pen" instead of "stylus").
59 * It does not use the hashtable system, but browse the whole archlist each time. 81 * It does not use the hashtable system, but browse the whole archlist each time.
60 * I suggest not to use it unless you really need it because of performance issue. 82 * I suggest not to use it unless you really need it because of performance issue.
225 * is because of the 'else' handling - we don't want to match on 247 * is because of the 'else' handling - we don't want to match on
226 * something and set a low retval, even though it may match a higher retcal 248 * something and set a low retval, even though it may match a higher retcal
227 * later. So keep it in descending order here, so we try for the best 249 * later. So keep it in descending order here, so we try for the best
228 * match first, and work downward. 250 * match first, and work downward.
229 */ 251 */
252 const char *qbn0, *qbn1, *qsn; // query base name/short name caches
253
230 if (!strcasecmp (cp, query_name (op))) 254 if (!strcasecmp (cp, query_name (op)))
231 retval = 20; 255 retval = 20;
232 else if (!strcasecmp (cp, query_short_name (op))) 256 else if (!strcasecmp (cp, qsn = query_short_name (op)))
233 retval = 18; 257 retval = 18;
234 else if (!strcasecmp (cp, query_base_name (op, 0))) 258 else if (!strcasecmp (cp, qbn0 = query_base_name (op, 0)))
235 retval = 16; 259 retval = 16;
236 else if (!strcasecmp (cp, query_base_name (op, 1))) 260 else if (!strcasecmp (cp, qbn1 = query_base_name (op, 1)))
237 retval = 16; 261 retval = 16;
238 else if (op->custom_name && !strcasecmp (cp, op->custom_name)) 262 else if (op->custom_name && !strcasecmp (cp, op->custom_name))
239 retval = 15; 263 retval = 15;
240 else if (!strncasecmp (cp, query_base_name (op, 0), strlen (cp))) 264 else if (!strncasecmp (cp, qbn0, strlen (cp)))
241 retval = 14; 265 retval = 14;
242 else if (!strncasecmp (cp, query_base_name (op, 1), strlen (cp))) 266 else if (!strncasecmp (cp, qbn1, strlen (cp)))
243 retval = 14; 267 retval = 14;
244 /* Do substring checks, so things like 'Str+1' will match. 268 /* Do substring checks, so things like 'Str+1' will match.
245 * retval of these should perhaps be lower - they are lower 269 * retval of these should perhaps be lower - they are lower
246 * then the specific strcasecmp aboves, but still higher than 270 * then the specific strcasecmp aboves, but still higher than
247 * some other match criteria. 271 * some other match criteria.
248 */ 272 */
249 else if (strstr (query_base_name (op, 1), cp)) 273 else if (strstr (qbn1, cp))
250 retval = 12; 274 retval = 12;
251 else if (strstr (query_base_name (op, 0), cp)) 275 else if (strstr (qbn0, cp))
252 retval = 12; 276 retval = 12;
253 else if (strstr (query_short_name (op), cp)) 277 else if (strstr (qsn, cp))
254 retval = 12; 278 retval = 12;
255 /* Check against plural/non plural based on count. */ 279 /* Check against plural/non plural based on count. */
256 else if (count > 1 && !strcasecmp (cp, op->name_pl)) 280 else if (count > 1 && !strcasecmp (cp, op->name_pl))
257 retval = 6; 281 retval = 6;
258 else if (count == 1 && !strcasecmp (op->name, cp)) 282 else if (count == 1 && !strcasecmp (op->name, cp))
274 } 298 }
275 299
276 return 0; 300 return 0;
277} 301}
278 302
303//-GPL
304
279archetype::archetype (const char *name) 305archetype::archetype (const char *name)
280{ 306{
281 arch = this; 307 arch = this;
282 this->archname = this->name = this->name_pl = name; 308 this->archname = this->name = this->name_pl = name;
283} 309}
539 object *op = clone (); 565 object *op = clone ();
540 op->instantiate (); 566 op->instantiate ();
541 return op; 567 return op;
542} 568}
543 569
544/* 570//+GPL
545 * Creates an object. This function is called by get_archetype()
546 * if it fails to find the appropriate archetype.
547 * Thus get_archetype() will be guaranteed to always return
548 * an object, and never NULL.
549 */
550object *
551create_singularity (const char *name)
552{
553 LOG (llevError | logBacktrace, "FATAL: creating singularity for '%s'.\n", name);
554
555 if (!strcmp (name, "bug"))
556 abort ();
557
558 object *op = archetype::get (shstr_bug);
559 op->name = op->name_pl = format ("bug, please report (missing archetype %s)", name);
560
561 return op;
562}
563 571
564/* 572/*
565 * Finds which archetype matches the given name, and returns a new 573 * Finds which archetype matches the given name, and returns a new
566 * object containing a copy of the archetype. 574 * object containing a copy of the archetype.
567 */ 575 */
584 592
585/* 593/*
586 * Returns the first archetype using the given type. 594 * Returns the first archetype using the given type.
587 * Used in treasure-generation. 595 * Used in treasure-generation.
588 */ 596 */
589archetype * 597static archetype *
590type_to_archetype (int type) 598type_to_archetype (int type)
591{ 599{
592 for_all_archetypes (at) 600 for_all_archetypes (at)
593 if (at->type == type && at->head_ () != at) 601 if (at->type == type && at->head_ () != at)
594 return at; 602 return at;
641 } 649 }
642 650
643 return head; 651 return head;
644} 652}
645 653
654//-GPL
655

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines