1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
|
|
4 | * Copyright (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
8 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * Deliantra is free software: you can redistribute it and/or modify it under |
… | |
… | |
422 | goto fail; |
423 | goto fail; |
423 | } |
424 | } |
424 | } |
425 | } |
425 | |
426 | |
426 | { |
427 | { |
427 | auto (at, parts.begin ()); |
|
|
428 | |
|
|
429 | archetype *new_head = parts.front (); |
428 | archetype *new_head = parts.front (); |
430 | archetype *old_head = find (new_head->archname); |
429 | archetype *old_head = find (new_head->archname); |
431 | |
430 | |
432 | if (old_head && !old_head->is_head ()) |
431 | if (old_head && !old_head->is_head ()) |
433 | { |
432 | { |
… | |
… | |
435 | &new_head->archname, &old_head->archname); |
434 | &new_head->archname, &old_head->archname); |
436 | goto fail; |
435 | goto fail; |
437 | } |
436 | } |
438 | |
437 | |
439 | // 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 |
440 | for (auto (at, parts.begin ()); at != parts.end (); ++at) |
439 | for (auto &&at : parts) |
441 | { |
440 | { |
442 | archetype *new_part = *at; |
441 | archetype *new_part = at; |
443 | archetype *old_part = find (new_part->archname); |
442 | archetype *old_part = find (new_part->archname); |
444 | |
443 | |
445 | if (old_part && old_part->head_ () != old_head) |
444 | if (old_part && old_part->head_ () != old_head) |
446 | { |
445 | { |
447 | 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", |
… | |
… | |
452 | |
451 | |
453 | // assemble new chain |
452 | // assemble new chain |
454 | new_head->max_x = new_head->x; |
453 | new_head->max_x = new_head->x; |
455 | |
454 | |
456 | archetype *less = new_head; |
455 | archetype *less = new_head; |
457 | for (auto (p, parts.begin () + 1); p != parts.end (); ++p) |
456 | for (auto &&p = parts.begin () + 1; p != parts.end (); ++p) |
458 | { |
457 | { |
459 | archetype *at = *p; |
458 | archetype *at = *p; |
460 | |
459 | |
461 | // some flags get inherited from the head (probably a lot more) |
460 | // some flags get inherited from the head (probably a lot more) |
462 | // 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 |
… | |
… | |
477 | |
476 | |
478 | return new_head; |
477 | return new_head; |
479 | } |
478 | } |
480 | |
479 | |
481 | fail: |
480 | fail: |
482 | for (auto (p, parts.begin ()); p != parts.end (); ++p) |
481 | for (auto &&at : parts) |
483 | (*p)->destroy (); |
482 | at->destroy (); |
484 | |
483 | |
485 | return 0; |
484 | return 0; |
486 | } |
485 | } |
487 | |
486 | |
488 | void |
487 | void |
… | |
… | |
494 | |
493 | |
495 | void |
494 | void |
496 | archetype::commit_load () |
495 | archetype::commit_load () |
497 | { |
496 | { |
498 | // unlink old archetypes and link in new ones */ |
497 | // unlink old archetypes and link in new ones */ |
499 | for (auto (p, postponed_arch.begin ()); p != postponed_arch.end (); ++p) |
498 | for (auto &&at : postponed_arch) |
500 | { |
499 | { |
501 | archetype *at = *p; |
|
|
502 | |
|
|
503 | if (archetype *old = find (at->archname)) |
500 | if (archetype *old = find (at->archname)) |
504 | old->unlink (); |
501 | old->unlink (); |
505 | |
502 | |
506 | allarch.push_back (at); |
503 | allarch.push_back (at); |
507 | |
504 | |
… | |
… | |
510 | } |
507 | } |
511 | |
508 | |
512 | postponed_arch.clear (); |
509 | postponed_arch.clear (); |
513 | |
510 | |
514 | // now resolve arch references |
511 | // now resolve arch references |
515 | for (auto (p, postponed_arch_ref.begin ()); p != postponed_arch_ref.end (); ++p) |
512 | for (auto &&p : postponed_arch_ref) // not yet C++17 |
516 | { |
513 | { |
517 | arch_ptr *ap = p->first; |
514 | arch_ptr *ap = p.first; |
518 | archetype *at = find (p->second); |
515 | archetype *at = find (p.second); |
519 | |
516 | |
520 | if (!at) |
517 | if (!at) |
521 | 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); |
522 | |
519 | |
523 | *ap = at; |
520 | *ap = at; |
524 | } |
521 | } |
525 | |
522 | |
526 | postponed_arch_ref.clear (); |
523 | postponed_arch_ref.clear (); |