… | |
… | |
423 | goto fail; |
423 | goto fail; |
424 | } |
424 | } |
425 | } |
425 | } |
426 | |
426 | |
427 | { |
427 | { |
428 | auto (at, parts.begin ()); |
|
|
429 | |
|
|
430 | archetype *new_head = parts.front (); |
428 | archetype *new_head = parts.front (); |
431 | archetype *old_head = find (new_head->archname); |
429 | archetype *old_head = find (new_head->archname); |
432 | |
430 | |
433 | if (old_head && !old_head->is_head ()) |
431 | if (old_head && !old_head->is_head ()) |
434 | { |
432 | { |
… | |
… | |
436 | &new_head->archname, &old_head->archname); |
434 | &new_head->archname, &old_head->archname); |
437 | goto fail; |
435 | goto fail; |
438 | } |
436 | } |
439 | |
437 | |
440 | // check that all archetypes belong to the same old object or are new |
438 | // check that all archetypes belong to the same old object or are new |
441 | for (auto (at, parts.begin ()); at != parts.end (); ++at) |
439 | for (auto &&at : parts) |
442 | { |
440 | { |
443 | archetype *new_part = *at; |
441 | archetype *new_part = at; |
444 | archetype *old_part = find (new_part->archname); |
442 | archetype *old_part = find (new_part->archname); |
445 | |
443 | |
446 | if (old_part && old_part->head_ () != old_head) |
444 | if (old_part && old_part->head_ () != old_head) |
447 | { |
445 | { |
448 | LOG (llevError, "%s: unable to overwrite archetype '%s' with archetype of different object, skipping.\n", |
446 | LOG (llevError, "%s: unable to overwrite archetype '%s' with archetype of different object, skipping.\n", |
… | |
… | |
453 | |
451 | |
454 | // assemble new chain |
452 | // assemble new chain |
455 | new_head->max_x = new_head->x; |
453 | new_head->max_x = new_head->x; |
456 | |
454 | |
457 | archetype *less = new_head; |
455 | archetype *less = new_head; |
458 | for (auto (p, parts.begin () + 1); p != parts.end (); ++p) |
456 | for (auto &&p = parts.begin () + 1; p != parts.end (); ++p) |
459 | { |
457 | { |
460 | archetype *at = *p; |
458 | archetype *at = *p; |
461 | |
459 | |
462 | // some flags get inherited from the head (probably a lot more) |
460 | // some flags get inherited from the head (probably a lot more) |
463 | // doing it here doesn't feel too cozy, but it allows code |
461 | // doing it here doesn't feel too cozy, but it allows code |
… | |
… | |
478 | |
476 | |
479 | return new_head; |
477 | return new_head; |
480 | } |
478 | } |
481 | |
479 | |
482 | fail: |
480 | fail: |
483 | for (auto (p, parts.begin ()); p != parts.end (); ++p) |
481 | for (auto &&at : parts) |
484 | (*p)->destroy (); |
482 | at->destroy (); |
485 | |
483 | |
486 | return 0; |
484 | return 0; |
487 | } |
485 | } |
488 | |
486 | |
489 | void |
487 | void |
… | |
… | |
495 | |
493 | |
496 | void |
494 | void |
497 | archetype::commit_load () |
495 | archetype::commit_load () |
498 | { |
496 | { |
499 | // unlink old archetypes and link in new ones */ |
497 | // unlink old archetypes and link in new ones */ |
500 | for (auto (p, postponed_arch.begin ()); p != postponed_arch.end (); ++p) |
498 | for (auto &&at : postponed_arch) |
501 | { |
499 | { |
502 | archetype *at = *p; |
|
|
503 | |
|
|
504 | if (archetype *old = find (at->archname)) |
500 | if (archetype *old = find (at->archname)) |
505 | old->unlink (); |
501 | old->unlink (); |
506 | |
502 | |
507 | allarch.push_back (at); |
503 | allarch.push_back (at); |
508 | |
504 | |
… | |
… | |
511 | } |
507 | } |
512 | |
508 | |
513 | postponed_arch.clear (); |
509 | postponed_arch.clear (); |
514 | |
510 | |
515 | // now resolve arch references |
511 | // now resolve arch references |
516 | for (auto (p, postponed_arch_ref.begin ()); p != postponed_arch_ref.end (); ++p) |
512 | for (auto &&p : postponed_arch_ref) // not yet C++17 |
517 | { |
513 | { |
518 | arch_ptr *ap = p->first; |
514 | arch_ptr *ap = p.first; |
519 | archetype *at = find (p->second); |
515 | archetype *at = find (p.second); |
520 | |
516 | |
521 | if (!at) |
517 | if (!at) |
522 | LOG (llevError, "unable to resolve postponed arch reference to '%s'", &p->second); |
518 | LOG (llevError, "unable to resolve postponed arch reference to '%s'", &p.second); |
523 | |
519 | |
524 | *ap = at; |
520 | *ap = at; |
525 | } |
521 | } |
526 | |
522 | |
527 | postponed_arch_ref.clear (); |
523 | postponed_arch_ref.clear (); |