MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / AttachObject

Function AttachObject

Descent3/attach.cpp:473–520  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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
473bool 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

Callers 10

osipf_AttachObjectAPFunction · 0.85
osipf_AttachObjectRadFunction · 0.85
MultiDoWorldStatesFunction · 0.85
MultiDoAttachFunction · 0.85
MultiDoAttachRadFunction · 0.85
dAttachObjectFunction · 0.85
dAttachObjectRadiusFunction · 0.85
ai_moveFunction · 0.85
DemoReadAttachObjRadFunction · 0.85
DemoReadAttachObjFunction · 0.85

Calls 12

AttachDoPosOrientFunction · 0.85
AttachPropagateMassFunction · 0.85
AttachUpdateSubObjectsFunction · 0.85
MultiSendAttachFunction · 0.85
DemoWriteAttachObjFunction · 0.85
AttachPointPosFunction · 0.85
GetTerrainRoomFromPosFunction · 0.85
ObjSetPosFunction · 0.85
MultiSendAttachRadFunction · 0.85
DemoWriteAttachObjRadFunction · 0.85

Tested by

no test coverage detected