SDK Question How to attach only unattched vessels

Hlynkacg

Aspiring rocket scientist
Addon Developer
Tutorial Publisher
Donator
Joined
Dec 27, 2010
Messages
1,870
Reaction score
3
Points
0
Location
San Diego
API documentation is your friend

bool VESSEL::Undock ( UINT n,
const OBJHANDLE exclude = 0
) const

Release a docked vessel from a docking port.


Parameters:
n docking port index (>= 0 or ALLDOCKS)
exclude optional handle of a vessel to be excluded from undocking

Returns:
true if at least one vessel was released from a port.
Note:
If n is set to ALLDOCKS, all docking ports are released simultaneously.
If exclude is nonzero, this vessel will not be undocked. This is useful for implementing remote undocking in combination with ALLDOCKS.

See also:
Dock, GetDockHandle, GetDockStatus, DockCount
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,724
Reaction score
2,690
Points
203
Location
Dallas, TX
Thanks. So if I want to undock Dock #1 if ramp1_proc>1 && ramp1_porc<0
Code:
bool myship::Undock ( 1,
const OBJHANDLE exclude = 0
)

right?
 

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's a sub-function of the VESSEL class, you don't need to declare it, just call it.

Code:
if (conditions met)
{
undock (argument here)
}

There was an example in the IMIS code sample I gave you.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,724
Reaction score
2,690
Points
203
Location
Dallas, TX
Thanks. I have this
Code:
if ((POD1RAMP_proc>0)&& (POD1RAMP_proc<1)){Undock (0);}
	if ((POD3RAMP_proc>0)&& (POD3RAMP_proc<1)){Undock (2);}
	if ((POD2RAMP_proc>0)&& (POD2RAMP_proc<1)){Undock (1);}

Works undock. But when I move back to where the dock is and the proc is 0 I don't redock.

Also I get a CTd when I try to read the handle of the dock.

Code:
TextOut(hdc,(tx+100),(ty2 + (yoff*1))+3,cbuf,strlen(cbuf) );
        {
           oapiGetObjectName (GetDockHandle(0), cbuf, 100);
        }

Looked at the API. Is there like in attachment if attached the do this but for docks?


With attachment
if(GetAttachmentStatus(LP2)){
oapiGetObjectName (GetAttachmentStatus(LP2), cbuf, 100);
}else{
sprintf (cbuf, " -----");
}

It displays the name of the attached ship if there is one
 
Last edited:

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,724
Reaction score
2,690
Points
203
Location
Dallas, TX
This goes back to my original question. I have an attachment point that Only want to attach a vessel THAT is NOT attachment else where?

I have it so the vessel detaches and then docks and then undocks. Then attaches again. But it pulls a vessel attached elsewhere. While the vessel I want attached to right at the point.
 

jedidia

shoemaker without legs
Addon Developer
Joined
Mar 19, 2008
Messages
10,882
Reaction score
2,133
Points
203
Location
between the planets
But 1. Can you be attached and docked at the same time.

Yes you can, unless you prevent it in your code. Orbiter doesn't care. IMS uses this regularly, but there's also problems that can arise from it if you don't watch yourself.
Usually I release the dock after attachment.

2 Moveable docking points. Can you have them and how?

A docking port that moves without your vessel docked, no problem. Iffy if you want to move it with the vessel docked. Simply updating the port position won't update the position of the vessel, if I remember correctly.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,724
Reaction score
2,690
Points
203
Location
Dallas, TX
Thanks. I solved the docking issue. What I have is the vessel move via robotic arm then the vessel detaches and because it is not attached it auto docks. Then when the arm moves it undocks and then attaches. But this is where i have an issue rather than attaching the nearest vessel it attaches another vessel further away. That vessel is attached elsewhere.
 

Donamy

Addon Developer
Addon Developer
Donator
Beta Tester
Joined
Oct 16, 2007
Messages
6,916
Reaction score
211
Points
138
Location
Cape
Aren't you able to specify a distance limit ?
 

jedidia

shoemaker without legs
Addon Developer
Joined
Mar 19, 2008
Messages
10,882
Reaction score
2,133
Points
203
Location
between the planets
But this is where i have an issue rather than attaching the nearest vessel it attaches another vessel further away. That vessel is attached elsewhere.

Just store the handle of the vessel when it docks, this way you should avoid any confusion.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,724
Reaction score
2,690
Points
203
Location
Dallas, TX
Yes. but I need to have 2 distances. One close and One further away.
 

jedidia

shoemaker without legs
Addon Developer
Joined
Mar 19, 2008
Messages
10,882
Reaction score
2,133
Points
203
Location
between the planets
I'm afraid I don't quite get what you're trying to do. From your above description, it sounded like the vessel would be previously docked, then undocks and immediately attaches. As I said, in that case, it's easiest to just store the handle when the vessel docks, so you can use that handle to attach it.

If this is not what you're trying to do, you'll have to explain it a bit clearer...
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,624
Reaction score
2,343
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
Yes. but I need to have 2 distances. One close and One further away.

You also lost me. Can you make a drawing of the situation and explain in comic graphical novel style, what you want to achieve? Maybe you already find the solution by drawing it.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,724
Reaction score
2,690
Points
203
Location
Dallas, TX
Ok the start of the robotic arm travel is the the red box the docking area/point is the green box.



The reason I need 2 distances would be that at the docking area it picks up another vessel attached. At the end of the travel needs to be a bigger distance. Since it makes it easier for retrival.
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,624
Reaction score
2,343
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
So you have two positions that are two different states and a transition between both states?
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,724
Reaction score
2,690
Points
203
Location
Dallas, TX
The order it goes in is translates -x from the red box to the green area. So a vessel#1 is attached and moves to the green box. Then a 180 rotation. then detach so the docking automatically occurs. Then a 90 degree rotation and attach again and undock. Translate in the z direction then a 90 degree rotation and then back translation to the left X direction).
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,624
Reaction score
2,343
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
The order it goes in is translates -x from the red box to the green area. So a vessel#1 is attached and moves to the green box. Then a 180 rotation. then detach so the docking automatically occurs. Then a 90 degree rotation and attach again and undock. Translate in the z direction then a 90 degree rotation and then back translation to the left X direction).

That makes no sense to me. Can you group it better into steps? What happens automatically and what is triggered by the player? Around which axis is the rotation?
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,724
Reaction score
2,690
Points
203
Location
Dallas, TX


All motion is user driven.

So when a key is pressed the vessel in the red box is attached and translated to the -x direction. Another key is pressed sequence #2 is a 180 rotation. There it is detached. Because the vessel is now unattached it docks at the green location. Now because it is docked you can transfer crew.

User presses key and now it rotates 90 degrees and attachs and undocks(Sequence 3).
User presses a key and now translates in the z direction (sequence 4)
Then the end of 4 is reached it rotates 90 degrees (sequence 5). user presses a key and then translate in the x direction outside the ship.

The issue is at sequence 3 even though a vessel is right there it will attach another vessel. So if i reduce the distance at the green square it makes it harder to get to the end point.
 

Donamy

Addon Developer
Addon Developer
Donator
Beta Tester
Joined
Oct 16, 2007
Messages
6,916
Reaction score
211
Points
138
Location
Cape
Let see if I'm understanding. You want to pick up something, translate it to somewhere else, then drop it and have it attach automatically where it is dropped ?
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,724
Reaction score
2,690
Points
203
Location
Dallas, TX
Let see if I'm understanding. You want to pick up something, translate it to somewhere else, then drop it and have it attach automatically where it is dropped ?

yes and dock in between.

Code:
if ((ROD2_proc>=1)&& (ROD3_check==0)&& (attach1==0)) DetachChild(POD1,0);

So if the 2nd rotation is complete and the 3rd is moving then detach POD1. This allows what was attached to be docked as the dock is placed where the attachment is/was.

the user presses a key
Code:
if (PADSel==1){
 attach1=1;
 if (ROD3_proc<1)toggle_attach();

set attach1 to 1 telling it needs to attach. this is so it will not dettach in the earlier step.
if the 3 sequence is not finished then attach. This is where it attaches another vessel already attached but not the one there.


PaD1= CreateAttachment (false,_V(-1.9, -10.931 , 12),_V(1,0,0),_V(0,1,0),"POD1",false);
PaD2= CreateAttachment (false,_V(-1.9, -6.6 , 12),_V(1,0,0),_V(0,1,0),"POD2",false);


from the scenario:

BEGIN_SHIPS
POD1:pOD1
STATUS Orbiting Earth
RPOS 3848380.27 -34.52 8915000.38
RVEL -6548.607 -0.004 3741.743
AROT -180.00 3.81 -180.00
ATTACHED 0:1,PODBAY
AFCMODE 7
PRPLEVEL 0:1.000000
IDS 0:588 100
NAVFREQ 0 0
XPDR 0
END
PODBAY:pODBAY
STATUS Orbiting Earth
RPOS 2835762.68 8.70 6408734.33
RVEL -6896.691 -0.004 3051.575
AROT 180.00 -86.19 -180.00
AFCMODE 7
PRPLEVEL 0:1.000000
IDS 0:0 100
NAVFREQ 0 0
XPDR 0
PAD 2
END
pod2:pOD2
STATUS Orbiting Earth
RPOS 2835774.80 3.46 6408735.73
RVEL -6896.691 -0.004 3051.575
AROT -180.00 3.81 -180.00
ATTACHED 0:1,PODBAY
AFCMODE 7
PRPLEVEL 0:1.000000
IDS 0:588 100
NAVFREQ 0 0
XPDR 0
END
END_SHIPS

---------- Post added 05-01-13 at 06:11 AM ---------- Previous post was 04-30-13 at 06:38 PM ----------

One solution I thought of it to make separate id for each vessel. that way each pad/attachment point can allow attach that id. So attachment point #1 can only attach a vessel with an id of 1.

Code:
const char *id = v->GetAttachmentId (hAtt);
								if (strncmp (id, "POD1", 4))PODID=1;
								if (strncmp (id, "POD2", 4))PODID=2;
								if (strncmp (id, "POD3", 4))PODID=3;

                               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) < 10) { // Is it close enough to grab?
                                   apd = dist(gpship, gaph);
                                  
								   if ((PADSel==1)&& (PODID==1)){
                                      
                                               AttachChild (hV, PaD1, hAtt);
											   break;}
                                        if ((PADSel==2)&& (PODID==2)){
                                      
                                               AttachChild (hV, PaD2, hAtt);
											   break;}
										if ((PADSel==3)&& (PODID==3)){
                                      
                                               AttachChild (hV, PaD3, hAtt);
											   break;}

but when I run it the selected vessel as an attachment ID of POD2. But when I check the id it says 3?

PODID 3

---------- Post added at 09:31 PM ---------- Previous post was at 06:11 AM ----------

ok a solution is to when the vessel is in the right area. Sequence 3. then dock to the vessel.

But I am not sure how to tell it to dock to the dock automatically. That way I don't have to deal with the attachment issue.

Code:
8.51.3.271 int VESSEL::Dock (OBJHANDLE target, UINT n, UINT tgtn, UINT mode) const
Dock to another vessel.


both docking numbers are 0. so I think I need to get the target vessel handle.
 
Last edited:

Donamy

Addon Developer
Addon Developer
Donator
Beta Tester
Joined
Oct 16, 2007
Messages
6,916
Reaction score
211
Points
138
Location
Cape
Usually, just unattaching will make it dock, if it is close enough.
 
Top