Attaches 2 objects via attach points on each. The f_used_aligned allows for an aligned connection. NOTE: The child always moves to the parent
| 471 | // Attaches 2 objects via attach points on each. The f_used_aligned allows for an aligned connection. |
| 472 | // NOTE: The child always moves to the parent |
| 473 | bool AttachObject(object *parent, char parent_ap, object *child, char child_ap, bool f_use_aligned) { |
| 474 | ASSERT(parent); |
| 475 | ASSERT(child); |
| 476 | |
| 477 | poly_model *parent_pm = &Poly_models[parent->rtype.pobj_info.model_num]; |
| 478 | poly_model *child_pm = &Poly_models[child->rtype.pobj_info.model_num]; |
| 479 | |
| 480 | if (parent_ap < 0 || parent_ap >= parent_pm->n_attach) { |
| 481 | mprintf(0, "ATTACH: Parent AP invalid\n"); |
| 482 | return false; |
| 483 | } |
| 484 | |
| 485 | if (child->flags & OF_ATTACHED) { |
| 486 | mprintf(0, "ATTACH: Child already attached to someone\n"); |
| 487 | return false; |
| 488 | } |
| 489 | |
| 490 | if (child_ap >= 0 && child_ap < child_pm->n_attach) { |
| 491 | if (AttachDoPosOrient(parent, parent_ap, child, child_ap, false)) { |
| 492 | child->flags |= OF_ATTACHED; |
| 493 | child->attach_type = AT_ALIGNED; |
| 494 | child->attach_index = child_ap; |
| 495 | child->attach_parent_handle = parent->handle; |
| 496 | |
| 497 | parent->attach_children[parent_ap] = child->handle; |
| 498 | ComputeUltimateAttachParent(child); |
| 499 | ProprogateUltimateAttachParent(child, child->attach_ultimate_handle); |
| 500 | |
| 501 | AttachPropagateMass(child); |
| 502 | |
| 503 | AttachUpdateSubObjects(child); |
| 504 | if ((Game_mode & GM_MULTI) && (Netgame.local_role == LR_SERVER)) { |
| 505 | MultiSendAttach(parent, parent_ap, child, child_ap, f_use_aligned); |
| 506 | } |
| 507 | if (Demo_flags == DF_RECORDING) { |
| 508 | DemoWriteAttachObj(parent, parent_ap, child, child_ap, f_use_aligned); |
| 509 | } |
| 510 | |
| 511 | return true; |
| 512 | } |
| 513 | |
| 514 | mprintf(0, "ATTACH: AP attach failed\n"); |
| 515 | return false; |
| 516 | } |
| 517 | |
| 518 | mprintf(0, "ATTACH: Child AP (%d) - child only has %d attach points\n", child_ap, child_pm->n_attach); |
| 519 | return false; |
| 520 | } |
| 521 | |
| 522 | // Attaches a child object to a parent object by a percent of the radius of the child. |
| 523 | // NOTE: The child always moves to the parent and not the reverse |
no test coverage detected