void Atlantis::ToggleGrapple(void)
{
HWND hDlg;
OBJHANDLE hV = GetAttachmentStatus(rms_attach);
if (hV) { // release satellite
ATTACHMENTHANDLE hAtt = CanArrest();
DetachChild(rms_attach);
if (hDlg = oapiFindDialog(g_Param.hDLL, IDD_RMS)) {
SetWindowText(GetDlgItem(hDlg, IDC_GRAPPLE), "Grapple");
EnableWindow(GetDlgItem(hDlg, IDC_STOW), TRUE);
}
// check whether the object being ungrappled is ready to be clamped into the payload bay
// if (hAtt) {
// AttachChild(hV, sat_attach, hAtt);
// if (hDlg) {
// SetWindowText(GetDlgItem(hDlg, IDC_PAYLOAD), "Purge");
// EnableWindow(GetDlgItem(hDlg, IDC_PAYLOAD), TRUE);
// }
//}
#ifdef UNDEF
VECTOR3 pos, dir, rot, gbay, gpos;
GetAttachmentParams(sat_attach, pos, dir, rot);
Local2Global(pos, gbay);
VESSEL *v = oapiGetVesselInterface(hV);
DWORD nAttach = v->AttachmentCount(true);
for (DWORD j = 0; j < nAttach; j++) { // now scan all attachment points
ATTACHMENTHANDLE hAtt = v->GetAttachmentHandle(true, j);
v->GetAttachmentParams(hAtt, pos, dir, rot);
v->Local2Global(pos, gpos);
if (dist(gpos, gbay) < MAX_GRAPPLING_DIST) {
AttachChild(hV, sat_attach, hAtt);
return;
}
}
#endif
}
else { // grapple satellite
VECTOR3 gpos, grms, pos, dir, rot;
Local2Global(arm_tip[0], grms); // global position of RMS tip
// sprintf(oapiDebugString(), "dist %2.2f ", dist(gpos, grms));
// Search the complete vessel list for a grappling candidate.
// Not very scalable ...
for (DWORD i = 0; i < oapiGetVesselCount(); i++) {
OBJHANDLE hV = oapiGetVesselByIndex(i);
if (hV == GetHandle()) continue; // we don't want to grapple ourselves ...
oapiGetGlobalPos(hV, &gpos);
if (dist(gpos, grms) < oapiGetSize(hV)) { // in range
VESSEL *v = oapiGetVesselInterface(hV);
DWORD nAttach = v->AttachmentCount(true);
for (DWORD j = 0; j < nAttach;
j++) { // now scan all attachment points of the candidate
ATTACHMENTHANDLE hAtt = v->GetAttachmentHandle(true, j);
const char *id = v->GetAttachmentId(hAtt);
//sprintf(oapiDebugString(), "dist %2.2f ", dist(gpos, grms));
if (strncmp(id, "GS", 2)) continue; // attachment point compatible go to next step
v->GetAttachmentParams(hAtt, pos, dir, rot);
v->Local2Global(pos, gpos);
distattach = (dist(gpos, grms));
GRAB = 1;
//sprintf(oapiDebugString(), "dist %2.2f ", dist(gpos, grms));
if (dist(gpos, grms) < MAX_GRAPPLING_DIST) { // found one!
// check whether satellite is currently clamped into payload bay
//if (hV == GetAttachmentStatus(sat_attach))
// DetachChild(sat_attach);
AttachChild(hV, rms_attach, hAtt);
if (hDlg = oapiFindDialog(g_Param.hDLL, IDD_RMS)) {
SetWindowText(GetDlgItem(hDlg, IDC_GRAPPLE), "Release");
EnableWindow(GetDlgItem(hDlg, IDC_STOW), FALSE);
}
return;
}
}
}
}
}
}