… | |
… | |
300 | |
300 | |
301 | void |
301 | void |
302 | archetype::unlink () |
302 | archetype::unlink () |
303 | { |
303 | { |
304 | ht.erase (archname); |
304 | ht.erase (archname); |
305 | |
305 | if (!strcmp (&archname, "Gaea")) fprintf (stderr, "oI\n");//D |
306 | if (archetypes.contains (this)) |
306 | if (archetypes.contains (this)) |
307 | archetypes.erase (this); |
307 | archetypes.erase (this); |
308 | } |
308 | } |
309 | |
309 | |
310 | /* |
310 | /* |
… | |
… | |
334 | name = "(null)"; |
334 | name = "(null)"; |
335 | } |
335 | } |
336 | |
336 | |
337 | archetype *at = find (name); |
337 | archetype *at = find (name); |
338 | |
338 | |
339 | if (loading_arch && at && !at->stub) |
339 | if (!at) |
340 | { |
|
|
341 | at->unlink (); |
|
|
342 | at = 0; |
|
|
343 | } |
|
|
344 | |
|
|
345 | if (!at || (!at->stub && loading_arch)) |
|
|
346 | { |
340 | { |
347 | at = new archetype (name); |
341 | at = new archetype (name); |
348 | at->link (); |
342 | at->link (); |
349 | } |
343 | } |
350 | |
344 | |
… | |
… | |
415 | auto (at, parts.begin ()); |
409 | auto (at, parts.begin ()); |
416 | |
410 | |
417 | archetype *new_head = parts.front (); |
411 | archetype *new_head = parts.front (); |
418 | archetype *old_head = find (new_head->archname); |
412 | archetype *old_head = find (new_head->archname); |
419 | |
413 | |
420 | for (auto (at, parts.begin ()); at != parts.end (); ++at) |
414 | if (old_head && !old_head->is_head ()) |
421 | fprintf (stderr, "%d: %s\n", at - parts.begin(), &(*at)->archname);//D |
415 | { |
|
|
416 | LOG (llevError, "%s: unable to overwrite non-head archetype '%s' with head archetype, skipping.\n", |
|
|
417 | &new_head->archname, &old_head->archname); |
|
|
418 | goto fail; |
|
|
419 | } |
422 | |
420 | |
423 | // check that all archetypes belong to the same old object or are new |
421 | // check that all archetypes belong to the same old object or are new |
424 | for (auto (at, parts.begin ()); at != parts.end (); ++at) |
422 | for (auto (at, parts.begin ()); at != parts.end (); ++at) |
425 | { |
423 | { |
426 | archetype *new_part = *at; |
424 | archetype *new_part = *at; |
427 | archetype *old_part = find (new_part->archname); |
425 | archetype *old_part = find (new_part->archname); |
428 | |
426 | |
429 | if (old_part && old_part->head_ () != old_head) |
427 | if (old_part && old_part->head_ () != old_head) |
430 | { |
428 | { |
431 | fprintf (stderr, "nhn %s\n", &new_head->archname);//D |
|
|
432 | fprintf (stderr, "old_head %p,%p new_head %p,%p ph %p\n", old_head, old_part, new_head, new_part, old_part->head_()); |
|
|
433 | LOG (llevError, "%s: unable to overwrite archetype '%s' with archetype of different object, skipping.\n", |
429 | LOG (llevError, "%s: unable to overwrite archetype '%s' with archetype of different object, skipping.\n", |
434 | &new_part->archname, &((archetype *)old_part->head_ ())->archname); |
430 | &new_part->archname, &((archetype *)old_part->head_ ())->archname); |
435 | goto fail; |
431 | goto fail; |
436 | } |
432 | } |
437 | } |
433 | } |
438 | |
434 | |
439 | fprintf (stderr, "oh %p %s\n", old_head, &new_head->archname);//D |
|
|
440 | |
|
|
441 | // deactivate existing archetype |
435 | // deactivate existing archetype |
442 | for (archetype *at = old_head; at; at = (archetype *)at->more) |
436 | for (archetype *at = old_head; at; at = (archetype *)at->more) |
443 | at->unlink (); |
437 | at->unlink (); |
444 | |
438 | |
445 | // reassemble new chain |
439 | // assemble new chain |
446 | new_head->min_x = new_head->max_x = new_head->x; |
440 | new_head->min_x = new_head->max_x = new_head->x; |
447 | new_head->min_y = new_head->max_y = new_head->y; |
441 | new_head->min_y = new_head->max_y = new_head->y; |
448 | |
442 | |
449 | archetype *less = new_head; |
443 | archetype *less = new_head; |
450 | archetype *head = 0; |
|
|
451 | for (auto (p, parts.begin () + 1); p != parts.end (); ++p) |
444 | for (auto (p, parts.begin () + 1); p != parts.end (); ++p) |
452 | { |
445 | { |
453 | archetype *at = *p; |
446 | archetype *at = *p; |
454 | |
447 | |
455 | if (at->x < new_head->min_x) new_head->min_x = at->x; |
448 | if (at->x < new_head->min_x) new_head->min_x = at->x; |
456 | if (at->y < new_head->min_y) new_head->min_y = at->y; |
449 | if (at->y < new_head->min_y) new_head->min_y = at->y; |
457 | if (at->x > new_head->max_x) new_head->max_x = at->x; |
450 | if (at->x > new_head->max_x) new_head->max_x = at->x; |
458 | if (at->y > new_head->max_y) new_head->max_y = at->y; |
451 | if (at->y > new_head->max_y) new_head->max_y = at->y; |
459 | |
452 | |
460 | at->head = head; head = new_head; |
453 | at->head = new_head; |
461 | less->more = at; less = at; |
454 | less->more = at; |
|
|
455 | less = at; |
462 | } |
456 | } |
463 | |
457 | |
464 | // now activate it |
458 | // now activate it |
465 | for (auto (p, parts.begin ()); p != parts.end (); ++p) |
459 | for (auto (p, parts.begin ()); p != parts.end (); ++p) |
466 | { |
460 | { |