Vessel names

Russ_H

Addon Developer
Addon Developer
Joined
Apr 15, 2008
Messages
118
Reaction score
0
Points
0
Location
louisville, Ky
I am working on payload logic and I am having trouble finding all the vessel names. I can get the vessel count and a handle by index but I can't get to the name of the vessel.

I think I need to use optiGetObjectName and then feed it a handel for it to return me the name.

I have trouble understanding how some thing works from the synopsis in the api unless I can track down a working version of it in the sampel code and then run debug on it to see how it works in realtime.

IF some one could show me what the code looks like I would be grateful.
I found some code in the shuttlea sample project that was very helpfull.

I could be wrong about this. this is way over my head I think.
 

Bj

Addon Developer
Addon Developer
Donator
Joined
Oct 16, 2007
Messages
1,886
Reaction score
11
Points
0
Location
USA-WA
Website
www.orbiter-forum.com
I am working on payload logic and I am having trouble finding all the vessel names. I can get the vessel count and a handle by index but I can't get to the name of the vessel.

I think I need to use optiGetObjectName and then feed it a handel for it to return me the name.

I have trouble understanding how some thing works from the synopsis in the api unless I can track down a working version of it in the sampel code and then run debug on it to see how it works in realtime.

IF some one could show me what the code looks like I would be grateful.
I found some code in the shuttlea sample project that was very helpfull.

I could be wrong about this. this is way over my head I think.

If I can, what is your propose of getting the vessels name?

and the get name function is like


Code:
void oapiGetObjectName (OBJHANDLE hObj,char *name,int n)
and is that all your asking?
 
Last edited:

Russ_H

Addon Developer
Addon Developer
Joined
Apr 15, 2008
Messages
118
Reaction score
0
Points
0
Location
louisville, Ky
If I can, what is your propose of getting the vessels name?

and the get name function is like


Code:
void oapiGetObjectName (OBJHANDLE hObj,char *name,int n)
and is that all your asking?

I want to list the cargo that is in orbit around me so I can load it in the cargo bay.
 

Russ_H

Addon Developer
Addon Developer
Joined
Apr 15, 2008
Messages
118
Reaction score
0
Points
0
Location
louisville, Ky
OK I got it thanks to bj's help through pm
index = 0
OBJHANDEL myhandle = opaiGetVesselByIndex (index); // this will get the first vessel in the index and give it a handle named myhandle

char *vessel_name;

oapiGetObjectByname (myhandle, vessel_name,20); the 20 is space to hold the name

vessel_name = Iss bacause the iss was in the 0 of the index

so we would get the vessel count and then increment index + or - till we find the cargo we want

Thanks bj for getting me started
Russ
 

computerex

Addon Developer
Addon Developer
Joined
Oct 16, 2007
Messages
1,282
Reaction score
17
Points
0
Location
Florida
Hi. This is the correct way to get a vessel's name:

Code:
VESSEL * v = NULL;
for (int i = 0; i < oapiGetVesselCount(); i++)
{
   v = oapiGetVesselInterface(oapiGetVesselByIndex(i));
   if (v->GetHandle() == oapiGetFocusInterface()->GetHandle())
        sprintf(oapiDebugString(), "%s", v->GetName());
}

This will print the focus vessel's name on the screen.
 

Russ_H

Addon Developer
Addon Developer
Joined
Apr 15, 2008
Messages
118
Reaction score
0
Points
0
Location
louisville, Ky
Hi. This is the correct way to get a vessel's name:

Code:
VESSEL * v = NULL;
for (int i = 0; i < oapiGetVesselCount(); i++)
{
   v = oapiGetVesselInterface(oapiGetVesselByIndex(i));
   if (v->GetHandle() == oapiGetFocusInterface()->GetHandle())
        sprintf(oapiDebugString(), "%s", v->GetName());
}
This will print the focus vessel's name on the screen.

what if I want to get the names of all the vessels around me
 

computerex

Addon Developer
Addon Developer
Joined
Oct 16, 2007
Messages
1,282
Reaction score
17
Points
0
Location
Florida
what if I want to get the names of all the vessels around me

Then:

Code:
const double MAX_DIST = 5; // 5 meters
std::vector<std::string> vesselNames;
VESSEL * v = NULL;
VECTOR3 rpos;
char name[255];
for (int i = 0; i < oapiGetVesselCount(); i++)
{
   v = oapiGetVesselInterface(oapiGetVesselByIndex(i));
   if (v->GetHandle() == GetHandle()) // don't want our name
         continue;       
   GetRelativePos(v->GetHandle(), rpos);
   if (sqrt(rpos.x*rpos.x+rpos.y*rpos.y+rpos.z*rpos.z) < MAX_DIST)
   {
     sprintf(name, "%s", v->GetName());
     vesselNames.push_back(name);
   }
}
 

Ursus

Rocket Tinker
Addon Developer
Joined
Oct 20, 2007
Messages
176
Reaction score
2
Points
18
Location
46N 123W
Then:

Code:
const double MAX_DIST = 5; // 5 meters
std::vector<std::string> vesselNames;
VESSEL * v = NULL;
VECTOR3 rpos;
char name[255];
for (int i = 0; i < oapiGetVesselCount(); i++)
{
   v = oapiGetVesselInterface(oapiGetVesselByIndex(i));
   if (v->GetHandle() == GetHandle()) // don't want our name
         continue;       
   GetRelativePos(v->GetHandle(), rpos);
   if (sqrt(rpos.x*rpos.x+rpos.y*rpos.y+rpos.z*rpos.z) < MAX_DIST)
   {
     sprintf(name, "%s", v->GetName());
     vesselNames.push_back(name);
   }
}

Seems to me that going through the vessel interface would just add unnecessary extra steps.

Code:
const double MAX_DIST = 5; // 5 meters
std::vector<std::string> vesselNames;
// VESSEL * v = NULL; // Not necessary.
OBJHANDLE v;  // use this instead.
VECTOR3 rpos;
char name[255];
for (int i = 0; i < oapiGetVesselCount(); i++)
{
   v = oapiGetVesselByIndex(i);
   if (v == GetHandle()) // don't want our name
         continue;       
   GetRelativePos(v, rpos);
   // length(rpos) is the same as sqrt(rpos.x*rpos.x+rpos.y*rpos.y+rpos.z*rpos.z)
   if (length(rpos) < MAX_DIST)
   {
     oapiGetObjectName(v, name, 255);
     vesselNames.push_back(name);
   }
}

Should work as well, if not a teeny bit faster.
 

computerex

Addon Developer
Addon Developer
Joined
Oct 16, 2007
Messages
1,282
Reaction score
17
Points
0
Location
Florida
That works if you just want to collect the vessel names, you'll have to get the interface if you are say creating a dummy thruster on the vessel.
 
Top