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.55 by root, Tue Apr 17 19:12:32 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 (f.kw == KW_inherit)
341 {
342 if (archetype *at = find (f.get_str ()))
343 *op = at->clone;
344 else
345 LOG (llevError, "archetype '%s' tries to inherit from non-existent archetype '%s'.\n",
346 &at->name, f.get_str ());
347
348 f.next ();
349 }
335 350
336 if (!op->parse_kv (f)) 351 if (!op->parse_kv (f))
337 goto fail; 352 goto fail;
338 353
339 parts.push_back (std::make_pair (at, op)); 354 parts.push_back (std::make_pair (at, op));
340 355
341 if (f.kw != KW_more) 356 if (f.kw != KW_more)
342 break; 357 break;
343 358
344 f.next (); 359 f.next ();
360
345 assert (f.kw == KW_object); 361 if (f.kw != KW_object)
362 {
363 f.parse_error ("more object");
364 goto fail;
365 }
346 } 366 }
347 367
348 { 368 {
349 archetype *head = parts.front ().first; 369 archetype *head = parts.front ().first;
350 370
403 prev->more = at; 423 prev->more = at;
404 prev->clone.more = &at->clone; 424 prev->clone.more = &at->clone;
405 425
406 prev = at; 426 prev = at;
407 } 427 }
428
429 loading_arch = false;
430 return head;
408 } 431 }
409
410 return true;
411 432
412fail: 433fail:
413 for (auto (p, parts.begin ()); p != parts.end (); ++p) 434 for (auto (p, parts.begin ()); p != parts.end (); ++p)
414 p->second->destroy (true); 435 p->second->destroy (true);
415 436
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; 437 loading_arch = false;
439 continue; 438 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} 439}
452 440
453/* 441/*
454 * First initialises the archtype hash-table (init_archetable()). 442 * Initialize global archtype pointers:
455 * Reads and parses the archetype file (with the first and second-pass
456 * functions).
457 */ 443 */
458bool 444void
459load_archetype_file (const char *filename) 445init_archetype_pointers ()
460{ 446{
461 object_thawer f (filename); 447 ring_arch = archetype::find ("ring");
462 448 amulet_arch = archetype::find ("amulet");
463 f.next (); 449 staff_arch = archetype::find ("staff");
464 450 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"); 451 empty_archetype = archetype::find ("empty_archetype");
471 if (!empty_archetype)
472 return false;
473
474 return true;
475} 452}
476 453
477/* 454/*
478 * Creates and returns a new object which is a copy of the given archetype. 455 * Creates and returns a new object which is a copy of the given archetype.
479 * This function returns NULL on failure. 456 * This function returns NULL on failure.
481object * 458object *
482arch_to_object (archetype *at) 459arch_to_object (archetype *at)
483{ 460{
484 if (!at) 461 if (!at)
485 { 462 {
486 if (warn_archetypes)
487 LOG (llevError, "Couldn't find archetype.\n"); 463 LOG (llevError, "Couldn't find archetype.\n");
488
489 return NULL; 464 return 0;
490 } 465 }
491 466
492 object *op = at->clone.clone (); 467 object *op = at->clone.clone ();
493 op->arch = at; 468 op->arch = at;
494 op->instantiate (); 469 op->instantiate ();
470
495 return op; 471 return op;
496} 472}
497 473
498/* 474/*
499 * Creates an object. This function is called by get_archetype() 475 * Creates an object. This function is called by get_archetype()

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines