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.52 by root, Tue Apr 17 10:06:32 2007 UTC vs.
Revision 1.53 by root, Tue Apr 17 18:40:31 2007 UTC

316 at->clone.inv = op->inv; op->inv = 0; 316 at->clone.inv = op->inv; op->inv = 0;
317 317
318 op->destroy (); 318 op->destroy ();
319} 319}
320 320
321bool 321archetype *
322archetype::load (object_thawer &f) 322archetype::read (object_thawer &f)
323{ 323{
324 assert (f.kw == KW_object); 324 assert (f.kw == KW_object);
325
326 loading_arch = true; // hack to tell parse_kv et al. to behave
325 327
326 typedef std::pair<archetype *, object *> part; 328 typedef std::pair<archetype *, object *> part;
327 std::vector<part> parts; 329 std::vector<part> parts;
328 330
329 coroapi::cede_to_tick_every (100); 331 coroapi::cede_to_tick_every (100);
403 prev->more = at; 405 prev->more = at;
404 prev->clone.more = &at->clone; 406 prev->clone.more = &at->clone;
405 407
406 prev = at; 408 prev = at;
407 } 409 }
410
411 loading_arch = false;
412 return head;
408 } 413 }
409
410 return true;
411 414
412fail: 415fail:
413 for (auto (p, parts.begin ()); p != parts.end (); ++p) 416 for (auto (p, parts.begin ()); p != parts.end (); ++p)
414 p->second->destroy (true); 417 p->second->destroy (true);
415 418
416 return false;
417}
418
419/*
420 * Reads/parses the archetype-file, and copies into a linked list
421 * of archetype-structures.
422 */
423static bool
424load_archetypes (object_thawer &f)
425{
426 for (;;)
427 {
428 switch (f.kw)
429 {
430 case KW_object:
431 loading_arch = true;
432 if (!archetype::load (f))
433 {
434 loading_arch = false;
435 return false;
436 }
437
438 loading_arch = false; 419 loading_arch = false;
439 continue; 420 return 0;
440
441 case KW_EOF:
442 return true;
443
444 default:
445 if (!f.parse_error ("archetypes file"))
446 return false;
447 }
448
449 f.next ();
450 }
451} 421}
452 422
453/* 423/*
454 * First initialises the archtype hash-table (init_archetable()). 424 * Initialize global archtype pointers:
455 * Reads and parses the archetype file (with the first and second-pass
456 * functions).
457 */ 425 */
458bool 426void
459load_archetype_file (const char *filename) 427init_archetype_pointers ()
460{ 428{
461 object_thawer f (filename); 429 ring_arch = archetype::find ("ring");
462 430 amulet_arch = archetype::find ("amulet");
463 f.next (); 431 staff_arch = archetype::find ("staff");
464 432 crown_arch = archetype::find ("crown");
465 if (!load_archetypes (f))
466 return false;
467
468 warn_archetypes = 1;
469
470 empty_archetype = archetype::find ("empty_archetype"); 433 empty_archetype = archetype::find ("empty_archetype");
471 if (!empty_archetype)
472 return false;
473
474 return true;
475} 434}
476 435
477/* 436/*
478 * Creates and returns a new object which is a copy of the given archetype. 437 * Creates and returns a new object which is a copy of the given archetype.
479 * This function returns NULL on failure. 438 * This function returns NULL on failure.
481object * 440object *
482arch_to_object (archetype *at) 441arch_to_object (archetype *at)
483{ 442{
484 if (!at) 443 if (!at)
485 { 444 {
486 if (warn_archetypes)
487 LOG (llevError, "Couldn't find archetype.\n"); 445 LOG (llevError, "Couldn't find archetype.\n");
488
489 return NULL; 446 return 0;
490 } 447 }
491 448
492 object *op = at->clone.clone (); 449 object *op = at->clone.clone ();
493 op->arch = at; 450 op->arch = at;
494 op->instantiate (); 451 op->instantiate ();
452
495 return op; 453 return op;
496} 454}
497 455
498/* 456/*
499 * Creates an object. This function is called by get_archetype() 457 * Creates an object. This function is called by get_archetype()

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines