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.58 by root, Sat Apr 21 11:55:36 2007 UTC

309// dire hack, need to rationalise 309// dire hack, need to rationalise
310void 310void
311overwrite (archetype *at, object *op) 311overwrite (archetype *at, object *op)
312{ 312{
313 at->clone = *op; 313 at->clone = *op;
314
315 at->clone.arch = at; 314 at->clone.arch = at;
315
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);
330 332
331 for (;;) 333 for (;;)
332 { 334 {
335 object *op = object::create ();
333 archetype *at = get (f.get_str ()); 336 archetype *at = get (f.get_str ());
334 object *op = object::create (); 337 f.get (op->name);
338 f.next ();
339
340#if 0
341 if (f.kw == KW_inherit)
342 {
343 if (archetype *at = find (f.get_str ()))
344 *op = at->clone;
345 else
346 LOG (llevError, "archetype '%s' tries to inherit from non-existent archetype '%s'.\n",
347 &at->name, f.get_str ());
348
349 f.next ();
350 }
351#endif
335 352
336 if (!op->parse_kv (f)) 353 if (!op->parse_kv (f))
337 goto fail; 354 goto fail;
338 355
339 parts.push_back (std::make_pair (at, op)); 356 parts.push_back (std::make_pair (at, op));
340 357
341 if (f.kw != KW_more) 358 if (f.kw != KW_more)
342 break; 359 break;
343 360
344 f.next (); 361 f.next ();
362
345 assert (f.kw == KW_object); 363 if (f.kw != KW_object)
364 {
365 f.parse_error ("more object");
366 goto fail;
367 }
346 } 368 }
347 369
348 { 370 {
349 archetype *head = parts.front ().first; 371 archetype *head = parts.front ().first;
350 372
403 prev->more = at; 425 prev->more = at;
404 prev->clone.more = &at->clone; 426 prev->clone.more = &at->clone;
405 427
406 prev = at; 428 prev = at;
407 } 429 }
430
431 loading_arch = false;
432 return head;
408 } 433 }
409
410 return true;
411 434
412fail: 435fail:
413 for (auto (p, parts.begin ()); p != parts.end (); ++p) 436 for (auto (p, parts.begin ()); p != parts.end (); ++p)
414 p->second->destroy (true); 437 p->second->destroy (true);
415 438
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; 439 loading_arch = false;
439 continue; 440 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} 441}
452 442
453/* 443/*
454 * First initialises the archtype hash-table (init_archetable()). 444 * Initialize global archtype pointers:
455 * Reads and parses the archetype file (with the first and second-pass
456 * functions).
457 */ 445 */
458bool 446void
459load_archetype_file (const char *filename) 447init_archetype_pointers ()
460{ 448{
461 object_thawer f (filename); 449 ring_arch = archetype::find ("ring");
462 450 amulet_arch = archetype::find ("amulet");
463 f.next (); 451 staff_arch = archetype::find ("staff");
464 452 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"); 453 empty_archetype = archetype::find ("empty_archetype");
471 if (!empty_archetype)
472 return false;
473
474 return true;
475} 454}
476 455
477/* 456/*
478 * Creates and returns a new object which is a copy of the given archetype. 457 * Creates and returns a new object which is a copy of the given archetype.
479 * This function returns NULL on failure. 458 * This function returns NULL on failure.
481object * 460object *
482arch_to_object (archetype *at) 461arch_to_object (archetype *at)
483{ 462{
484 if (!at) 463 if (!at)
485 { 464 {
486 if (warn_archetypes)
487 LOG (llevError, "Couldn't find archetype.\n"); 465 LOG (llevError, "Couldn't find archetype.\n");
488
489 return NULL; 466 return 0;
490 } 467 }
491 468
492 object *op = at->clone.clone (); 469 object *op = at->clone.clone ();
493 op->arch = at; 470 op->arch = at;
494 op->instantiate (); 471 op->instantiate ();
472
495 return op; 473 return op;
496} 474}
497 475
498/* 476/*
499 * Creates an object. This function is called by get_archetype() 477 * Creates an object. This function is called by get_archetype()
548} 526}
549 527
550archetype * 528archetype *
551archetype::get (const char *name) 529archetype::get (const char *name)
552{ 530{
531 if (!name)
532 {
533 LOG (llevError, "null archetype requested\n");
534 name = "(null)";
535 }
536
553 archetype *at = find (name); 537 archetype *at = find (name);
554 538
555 if (!at) 539 if (!at)
556 { 540 {
557 archetypes.push_back (at = new archetype); 541 archetypes.push_back (at = new archetype);
558 at->name = name; 542 at->name = at->clone.name = at->clone.name_pl = name;
559 at->hash_add (); 543 at->hash_add ();
560 } 544 }
561 545
562 return at; 546 return at;
563} 547}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines