ok. I got them to create and to attach. I had to add the child info to the cfg.
Yeah Thanks.
Now to get the airbag module to scale the bags.
void LEONOVOEXT::clbkPostCreation (void)
{
LEONOVOEXT *dg = (LEONOVOEXT*)vessel;
bagdoor_operate = dg->bagdoor_status;
dg->Airbag_Check();
...this last option is entirely optional but I'm going to do it because I'm a completionist and knowing how to do it may come in handy later. Lets set the propellant levels in our spawned descent stage to those in our parent vessel's descent tanks.
For this to work we need to do it after we've spawned the descent stage vessel but before we delete the descent tanks from our parent vessel.
Code:oapiCreateVessel (name, "UMMU_Apollo/LM_descentstage", vs); // create descent stage vessel [COLOR="red"]// Match descent stage's propellant levels to LM's descent tanks OBJHANDLE oh_descent = oapiGetObjectByName (name); // get handle of descent stage vessel VESSEL *ds = oapiGetVesselInterface (oh_descent); // get interface for descent stage ds->SetPropellantMass (ds->GetPropellantHandleByIndex (0), GetPropellantMass (ph_descentFuel)); ds->SetPropellantMass (ds->GetPropellantHandleByIndex (1), GetPropellantMass (ph_descentO2)); ds->SetPropellantMass (ds->GetPropellantHandleByIndex (2), GetPropellantMass (ph_descentH2O));[/COLOR] // Remove descent stage from vessel instance DelThruster (th_descent); // Delete descent stage engine
This is actually our first interaction with external class interfaces/instances.
"OBJHANDLE oh_descent = oapiGetObjectByName (name);" gets a handle for the descent stage vessel that we just created.
"VESSEL *ds = oapiGetVesselInterface (oh_descent);" This function creates a new class interface (it does not create a new vessel) called "ds" that points to an existing vessel (our descent stage). Using this interface we can call functions in that vessel's code as well as our own.
NOTE: much care should be taken in which functions you call. All sort of errors/bugs can arise from calling a function that is not declared or has a different definition from the vessel you're calling it from. To play it safe, restrict these calls to default Orbiter API functions such as the above.
"ds->" indicates that we are calling the function that follows in "ds"'s code rather than our own vessel's. In this case we are getting handles for 3 of ds's propellant tanks and setting their propellant masses to the masses in our parent vessel's descent tanks.
NOTE: this assumes that the descent stage vessel has 3 tanks. this can cause issues if does not. To head-off any such problems I will simply post the source code of my descent stage here. At this point, if you've been following along, you should know what to do with it.
...
void LEONOVOEXT::clbkPostCreation (void)
{
LEONOVOEXT *dg = (LEONOVOEXT*)vessel;
bagdoor_operate = dg->bagdoor_status;
dg->Airbag_Check();
void LEONOVOEXT::Airbag_Check()
{
VESSELSTATUS2 vs;
vs.version = 2;
vs.flag=0;
GetStatusEx (&vs);
}
void LEONOVOEXT::clbkPostCreation (void)
{
LEONOVOEXT *dg = (LEONOVOEXT*)vessel;
bagdoor_operate = dg->bagdoor_status;
Airbag_Check();
if (bagdoor_status >= CLOSING) {
double da = simdt * LIFT_SPEED;
if (bagdoor_status == CLOSING) {
if (bagdoor_proc > 0.0) bagdoor_proc = max (0.0, bagdoor_proc-da);
else bagdoor_status = CLOSED;
} else {
if (bagdoor_proc < 1.0) bagdoor_proc = min (1.0, bagdoor_proc+da);
else bagdoor_status = OPEN;
}
void LEONOVOEXT::RevertAIRBAG (void)
{
bagdoor_status = ((bagdoor_status == CLOSED || bagdoor_status == CLOSING )? OPENING : CLOSING);
}
Yes but "dg" has to actually connect to another vessel and the bagdoor function must be declared within it otherwise you will get a unresolved external symbol error and/or CTD
So how it is connect?
airbag1 = oapiCreateVesselEx ("airbag1", "leonovairbag1B", &vs);
airbag2 = oapiCreateVesselEx ("airbag2", "leonovairbag2C", &vs);
airbag3 = oapiCreateVesselEx ("airbag3", "leonovairbag3C", &vs);
airbag4 = oapiCreateVesselEx ("airbag4", "leonovairbag4B", &vs);
airbag5 = oapiCreateVesselEx ("airbag5", "leonovairbag5B", &vs);
airbag6 = oapiCreateVesselEx ("airbag6", "leonovairbag6B", &vs);
airbag1_vessel = oapiGetVesselInterface (airbag1);
airbag2_vessel = oapiGetVesselInterface (airbag2);
airbag3_vessel = oapiGetVesselInterface (airbag3);
airbag4_vessel = oapiGetVesselInterface (airbag4);
airbag5_vessel = oapiGetVesselInterface (airbag5);
airbag6_vessel = oapiGetVesselInterface (airbag6);
void Airbag::Timestep (double simt)
{
//bagdoor animation
if (bagdoor_operate >= 2 && airbag_jettison == 0) {
double da = oapiGetSimStep() * BAGDOOR_OPERATING_SPEED;
if (bagdoor_operate == 2) {
if (bagdoor_proc > 0.0)
bagdoor_proc = max (0.0, bagdoor_proc - da);
else
bagdoor_operate = 0;
} else
{
if (bagdoor_proc < 1.0)
bagdoor_proc = min (1.0, bagdoor_proc + da);
else
{
bagdoor_operate = 1;
}
}
if (_stricmp (GetName(), "airbag1") == 0)
SetAnimation (anim_bagdoor1, bagdoor_proc);
else if (_stricmp (GetName(), "airbag2") == 0)
SetAnimation (anim_bagdoor2, bagdoor_proc);
else if (_stricmp (GetName(), "airbag3") == 0)
SetAnimation (anim_bagdoor3, bagdoor_proc);
else if (_stricmp (GetName(), "airbag4") == 0)
SetAnimation (anim_bagdoor4, bagdoor_proc);
else if (_stricmp (GetName(), "airbag5") == 0)
SetAnimation (anim_bagdoor5, bagdoor_proc);
else if (_stricmp (GetName(), "airbag6") == 0)
SetAnimation (anim_bagdoor6, bagdoor_proc);
}
}
I don't see how these bagdoor_operate and airbag_jettison get taken from the mothership
dg->Airbag_Check();
DLLCLBK void ovcTimestep (VESSEL *vessel, double simt)
{
Leonov *dg = (Leonov*)vessel;
dg->Timestep (simt);
bagdoor_operate = dg->bagdoor_status;
if (dg->rotating == 0)
{
dg->rotating = 1;
dg->rotsect_status = dg->ROT;
}
dg->TransRings_Check();
dg->Airbag_Check();
}