How can I make it only attach a vessel that isn't attach already?
I know this code looks the see if the child ID is pod and if the distance is within 2. But it will attach another vessel that was attached somewhere else.
On the Moonbase Alpha we had 2 attachment points at the same location just different directions. And we could attach a vessel that wasn't attached at the other point.
here if the pad was 1 and the apsel (direction) was 0 and the other point had a NO vessel then attach.
Code:
{
VECTOR3 aphpos, aphdir, aphrot, gaph;
VECTOR3 shippos, shipdir, shiprot, gpship;
// get attachment point positions based on selected point
{
if (PADSel==1){
GetAttachmentParams(PODA,aphpos, aphdir, aphrot);}
if (PADSel==2){
GetAttachmentParams(PODB,aphpos, aphdir, aphrot);}
if (PADSel==3){
GetAttachmentParams(PODC,aphpos, aphdir, aphrot);}
}
// change the position to a global one rather then a local one. This will allow me to offset it from the local center.
// the local position is stored in gaph
Local2Global (aphpos, gaph);
//I now know were the attach point is in the global world
//Now lets find out if there is a skid in range
// Search the complete vessel list for a grappling candidate.
// Not very scalable ...
for (DWORD i = 0; i < oapiGetVesselCount(); i++) {
OBJHANDLE hV = oapiGetVesselByIndex (i); //get handle for ship
// if (strncmp (hV->GetClassName(), "QJFFS", 5)!=0 ){ //restrict to only QuadJ ships to make it easy.
// Look for any ship with a child attach point. This allows the Mule to grap any object
if (hV == GetHandle()) continue; // If self then continue onward because we don't want to grapple ourselves ...
oapiGetGlobalPos (hV, &gpship); // get global postion of ship and put into gpship
VESSEL *v = oapiGetVesselInterface (hV);
// Only look for child attach point
DWORD nAttach = v->AttachmentCount (true); //Get attachment count. I do this so that I can grap any child point.
if (nAttach > 0){ // Only continue if ship has a child attach point
for (DWORD j = 0; j < nAttach; j++) { // now scan all attachment points of the candidate and check how far away from the attach point it is
ATTACHMENTHANDLE hAtt = v->GetAttachmentHandle (true, j);
//this would allow me to filter out all but QJ ships but I don't want to right now
//const char *id = v->GetAttachmentId (hAtt);
//if (strncmp (id, "POD", 3)) continue; // attachment point not compatible
v->GetAttachmentParams (hAtt, shippos, shipdir, shiprot); //lets get the attach point position
v->Local2Global (shippos, gpship); // and change it to a global position Recycle of gpship cause I can
if (dist (gpship, gaph) < 2) { // Is it close enough to grab?
apd = dist(gpship, gaph);
// Yes! Then lets grab the little bugger and get out of here
const char *id = v->GetAttachmentId (hAtt);
(do_attach=0);
if(!strncmp (id, "POD", 3))(do_attach=1);
if(do_attach > 0){
do_attach = 0;
if (PADSel==3)
{
//Free so do the attach
AttachChild (hV, PODA, hAtt);
}else{
//something already attached
}
if (PADSel==2)
//Free so do the attach
AttachChild (hV, PODB, hAtt);
}else{
//something already attached
}
if (PADSel==1)
{
//Free so do the attach
AttachChild (hV, PODC, hAtt);
}else{
//something already attached
}
return;
}
} // End of for j
}
}
return;
}
On the Moonbase Alpha we had 2 attachment points at the same location just different directions. And we could attach a vessel that wasn't attached at the other point.
Code:
if ((PADSel==1) && (APSel==0) && (!GetAttachmentStatus(LP1A)))
{