SDK Question How to attach only unattched vessels

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,741
Reaction score
2,718
Points
203
Location
Dallas, TX
How can I make it only attach a vessel that isn't attach already?
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;
}
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.

Code:
if ((PADSel==1) && (APSel==0) && (!GetAttachmentStatus(LP1A)))
                          {
here if the pad was 1 and the apsel (direction) was 0 and the other point had a NO vessel then attach.
 

Donamy

Addon Developer
Addon Developer
Donator
Beta Tester
Joined
Oct 16, 2007
Messages
6,923
Reaction score
232
Points
138
Location
Cape
Funny, SC3 only attaches to unattached vessels. Both cases are needed in different situations.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,741
Reaction score
2,718
Points
203
Location
Dallas, TX
Agreed. But it seems odd. That you can have 1 attachment point and more than 1 vessels attached. Like you said the cranehead does it. But now I just want to attach unattached vessels.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,741
Reaction score
2,718
Points
203
Location
Dallas, TX
I think I got it fixed. But 1. Can you be attached and docked at the same time. and 2 Moveable docking points. Can you have them and how?

The reason why on both. If you had a pod vessel attached to the mother ship and want to put a Ummu into it. You have to be docked to transfer
 

BruceJohnJennerLawso

Dread Lord of the Idiots
Addon Developer
Joined
Apr 14, 2012
Messages
2,585
Reaction score
0
Points
36
I think I got it fixed. But 1. Can you be attached and docked at the same time. and 2 Moveable docking points. Can you have them and how?

The reason why on both. If you had a pod vessel attached to the mother ship and want to put a Ummu into it. You have to be docked to transfer

Not necessarily. I think you could transfer UMMU by getting the handle of an attached ship, then writing UMMU parameters straight to it. Ive never done it though, so you'll need to check with someone who has.
 

Donamy

Addon Developer
Addon Developer
Donator
Beta Tester
Joined
Oct 16, 2007
Messages
6,923
Reaction score
232
Points
138
Location
Cape
I believe, if a vessel is docked, it can have children, but a child can't be docked.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,741
Reaction score
2,718
Points
203
Location
Dallas, TX
So a mothership with a parent attachment point(s) and the pod vessel be the child. You should be able to dock the pod and attach to the mother ship?

Something Like a shuttle docked and attached to the shuttlebay of the enterprise? That may you could transfer crew.
 

Donamy

Addon Developer
Addon Developer
Donator
Beta Tester
Joined
Oct 16, 2007
Messages
6,923
Reaction score
232
Points
138
Location
Cape
The pod being a child can't be docked.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,741
Reaction score
2,718
Points
203
Location
Dallas, TX
The pod being a child can't be docked.

So it would be the parent? Or is it because of being attached?

Rather than attachment. I could use docking. But the docks would have to be able to be moved and rotated.
 

Donamy

Addon Developer
Addon Developer
Donator
Beta Tester
Joined
Oct 16, 2007
Messages
6,923
Reaction score
232
Points
138
Location
Cape
All vessels that are docked can only be parents.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,741
Reaction score
2,718
Points
203
Location
Dallas, TX
Confused. So if you have a space station and want to dock a shuttle to it. The station is the child and the shuttle the parent?

Can they be attached also?
 

Hlynkacg

Aspiring rocket scientist
Addon Developer
Tutorial Publisher
Donator
Joined
Dec 27, 2010
Messages
1,870
Reaction score
3
Points
0
Location
San Diego
No.

The shuttle may have an attached payload and the Station may have an attached payload but those payloads may not be attached or docked to anything other than their respective parents.

ETA: a parent point may have multiple children but a shild may only have one parent.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,741
Reaction score
2,718
Points
203
Location
Dallas, TX
So. You can be not attached and docked, right?

So then could you have a dock point so that a shuttle could dock to it and then be able to move the point
 

Hlynkacg

Aspiring rocket scientist
Addon Developer
Tutorial Publisher
Donator
Joined
Dec 27, 2010
Messages
1,870
Reaction score
3
Points
0
Location
San Diego
So. You can be not attached and docked, right?

So then could you have a dock point so that a shuttle could dock to it and then be able to move the point

Not as the "child" of another vessel no.

If you want a mobile docking point I recommend using clbkDockEvent to detect initial contact and then write a function that will transfer the vessel from the docking port to a parent attachment point.
 
Last edited:

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,741
Reaction score
2,718
Points
203
Location
Dallas, TX
It seems attachment is the way to go. I think a transponder can be set for it. But then you can't transfer crew as you need to be docked.
 

Hlynkacg

Aspiring rocket scientist
Addon Developer
Tutorial Publisher
Donator
Joined
Dec 27, 2010
Messages
1,870
Reaction score
3
Points
0
Location
San Diego
It seems attachment is the way to go. I think a transponder can be set for it. But then you can't transfer crew as you need to be docked.

What exactly are you trying to accomplish?
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,741
Reaction score
2,718
Points
203
Location
Dallas, TX
A moveable attachment point. That you fly a pod to. So a transponder is needed. Attach to the mothership. From the mothership you rotate 180 and are pulled in the ship. From there the Ummu can exit the pod and enter the mothership.
 

Donamy

Addon Developer
Addon Developer
Donator
Beta Tester
Joined
Oct 16, 2007
Messages
6,923
Reaction score
232
Points
138
Location
Cape
We do need a more robust attachment manager for Orbiter.
 

Hlynkacg

Aspiring rocket scientist
Addon Developer
Tutorial Publisher
Donator
Joined
Dec 27, 2010
Messages
1,870
Reaction score
3
Points
0
Location
San Diego
A moveable attachment point. That you fly a pod to. So a transponder is needed. Attach to the mothership. From the mothership you rotate 180 and are pulled in the ship. From there the Ummu can exit the pod and enter the mothership.

Why not use a docking port?
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,741
Reaction score
2,718
Points
203
Location
Dallas, TX
Top