API Question oapiCreateVessel - Works with MFDs?

escapetomsfate

OBSP Developer
Addon Developer
Joined
Jun 21, 2008
Messages
282
Reaction score
0
Points
0
Location
GB
Hi all.

I have two questions -
1) Will the function oapiCreateVessel let me spawn ships from MFDs?
2)If so, how would I do this? please post some code.

Thanks a lot.
 

tblaxland

O-F Administrator
Administrator
Addon Developer
Webmaster
Joined
Jan 1, 2008
Messages
7,320
Reaction score
25
Points
113
Location
Sydney, Australia
1) Yes. Why not? At least LaunchMFD does it, but I don't know of any others.
2) [ame="http://www.orbithangar.com/searchid.php?ID=2802"]Launch MFD[/ame] includes its source code in the download. Have a look at that. Also have a look at the Scenario Editor code that is included with the Orbiter SDK (hint - ScnEditor::CreateVessel function).
 
Last edited:

escapetomsfate

OBSP Developer
Addon Developer
Joined
Jun 21, 2008
Messages
282
Reaction score
0
Points
0
Location
GB
Alright thanks mate. I thought the Apis are specific for certain modules, I guess they aren't.


-----Post Added-----


Have you ever just *tried* it? :p

I mean, you won't break it if it won't work ;)

I did. It just looks really complicated without an example, because of all the other APIs it needs.

Thanks though.

I now have another problem - How would I make the new vessel's status the same as the vessel you are running the MFD in?

I guess it would look a bit like this;

VESSELSTATUS2 vs;
//Get current vessel status
PlantFlagMFD::GetStatusEx (&vs);
// create the new vessel
OBJHANDLE newvessel = oapiCreateVesselEx (name, classname, &vs);
 

garyw

O-F Administrator
Administrator
Moderator
Addon Developer
Tutorial Publisher
Joined
May 14, 2008
Messages
10,485
Reaction score
209
Points
138
Location
Kent
Website
blog.gdwnet.com
BombMFD does it as well.
 

escapetomsfate

OBSP Developer
Addon Developer
Joined
Jun 21, 2008
Messages
282
Reaction score
0
Points
0
Location
GB
That doesnt have source code. :(


-----Post Added-----


Ahh I really need help with this. I need to spawn another vessel in the same place as the current vessel. I've looked at the SDK docs and a few examples, such as surveyor, and got this function to do it;

Code:
void PlantFlagMFD::SpawnObject(char* classname, char* ext, VECTOR3 ofs) {
  VESSELSTATUS vs;
  char name[256];
  GetStatus(vs);
  Local2Rel (ofs, vs.rpos);
  vs.eng_main = vs.eng_hovr = 0.0;
  vs.status = 0;
  strcpy (name, GetName()); strcat (name, ext);
  oapiCreateVessel (name, classname, vs);
}
obviously, I've initialised these functions in a header file.

And all I get is 5 "unresolved external symbol" errors. Here's an exmple;
Code:
unresolved external symbol "public: char * __thiscall PlantFlagMFD::GetName(void)const " (?GetName@PlantFlagMFD@@QBEPADXZ) referenced in function "public: void __thiscall PlantFlagMFD::SpawnObject(char *,char *,union VECTOR3)" (?SpawnObject@PlantFlagMFD@@QAEXPAD0TVECTOR3@@@Z)

Please help!
 

tblaxland

O-F Administrator
Administrator
Addon Developer
Webmaster
Joined
Jan 1, 2008
Messages
7,320
Reaction score
25
Points
113
Location
Sydney, Australia
Code:
void PlantFlagMFD::SpawnObject(char* classname, char* ext, VECTOR3 ofs) {
  VESSELSTATUS vs;
  char name[256];
  GetStatus(vs);
  Local2Rel (ofs, vs.rpos);
  vs.eng_main = vs.eng_hovr = 0.0;
  vs.status = 0;
  strcpy (name, GetName()); strcat (name, ext);
  oapiCreateVessel (name, classname, vs);
}
obviously, I've initialised these functions in a header file.

And all I get is 5 "unresolved external symbol" errors.
I'm guessing you are also getting unresolved externals on GetStatus and Local2Rel? Have you declared and defined these functions as members of the PlantFlagMFD class?

GetStatus, Local2Rel and GetName are also member functions of the VESSEL base class. If it is your intention to use those functions, rather than your own definitions of them, put a "pV->" in front of them. This will call those functions for the current VESSEL base class that the MFD is associated with (pV is initialised by the MFD base class' constructor, which you should be calling in your PlantFlagMFD initialisation list).
 

escapetomsfate

OBSP Developer
Addon Developer
Joined
Jun 21, 2008
Messages
282
Reaction score
0
Points
0
Location
GB
Yeah I had them as part of plantflagmfd class, but I didn't know about the pv thing. Thanks, will try that later.


-----Post Added-----


Woohoo it worked! PlantFlagMFD is now up on OrbitHangar. Thanks all :)

One more question (sorry) How do I make one of those input lists? I mean the ones in OrbitMFD when you press TGT, a list of ships comes up. How would I make one like that? nothing in SDK docs and no samples with it, or at least I haven't found it.
 

tblaxland

O-F Administrator
Administrator
Addon Developer
Webmaster
Joined
Jan 1, 2008
Messages
7,320
Reaction score
25
Points
113
Location
Sydney, Australia
One more question (sorry) How do I make one of those input lists? I mean the ones in OrbitMFD when you press TGT, a list of ships comes up. How would I make one like that? nothing in SDK docs and no samples with it, or at least I haven't found it.
They are not included in the API but cjp reverse engineered them as part of his Free Orbit MFD project. Get Free Orbit from OrbitHangar, it includes the source code and some very good documentation. I used it myself recently on an as-yet unreleased MFD and it works very well.
 
Top