API Question SetPropellantMass Odd Behavior

Zane

New member
Joined
Jun 13, 2009
Messages
41
Reaction score
0
Points
0
Location
Dublin, Ohio
For some reason, the SetPropellantMass method is not setting the amount of fuel properly.

See, I've got this code:
Code:
    this->SeparationFuel = this->CreatePropellantResource(100);

    this->SeparationThrust[0] = this->CreateThruster(
        _V(0,22,35), _V(0,0,-1), 20000, this->SeparationFuel, 200);

    this->SeparationThrust[1] = this->CreateThruster(
        _V(0,-22,35), _V(0,0,-1), 20000, this->SeparationFuel, 200);

    this->SeparationThrust[2] = this->CreateThruster(
        _V(22,0,35), _V(0,0,-1), 20000, this->SeparationFuel, 200);

    this->SeparationThrust[3] = this->CreateThruster(
        _V(-22,0,35), _V(0,0,-1), 20000, this->SeparationFuel, 200);

    this->CreateThrusterGroup(this->SeparationThrust, 4, THGROUP_MAIN);

    this->AddExhaust(SeparationThrust[0], 16, 2);
    this->AddExhaust(SeparationThrust[1], 16, 2);
    this->AddExhaust(SeparationThrust[2], 16, 2);
    this->AddExhaust(SeparationThrust[3], 16, 2);

    this->SetPropellantMass(this->SeparationFuel, 100);

    this->SetThrusterGroupLevel(THGROUP_MAIN, 1.00);

This is right in the clbkSetClassCaps callback of my dll, which is the separated first stage of a rocket. Its supposed to make 4 stage separation motors that fire to bring the first stage of the rocket away from the second.

However, the engines never fire because the fuel tank doesn't get filled. What am I doing wrong here?
 

tblaxland

O-F Administrator
Administrator
Addon Developer
Webmaster
Joined
Jan 1, 2008
Messages
7,320
Reaction score
25
Points
113
Location
Sydney, Australia
From the docs:
clbkSetClassCaps
· This function is called after the vessel has been created, but before its state is read from the scenario file. This means that its state (position, velocity, fuel level, etc.) is undefined at this point.
· Use this function to set vessel class capabilities, not vessel state
parameters
.
You want to set the fuel levels in clbkSetStateEx:
clbkSetStateEx
This function is called when the vessel is being created with oapiCreateVesselEx, after its clbkSetClassCaps has been invoked and before its clbkPostCreation method is invoked.
BTW, you can get rid of all the "this->", C++ adds them automagically if you do not explicitly put them there.
 

Zane

New member
Joined
Jun 13, 2009
Messages
41
Reaction score
0
Points
0
Location
Dublin, Ohio
Thanks for the advice. I eventually ended up putting the fuel code somewhere other than the clbkSetStateEx callback (it runs just once during clbkPreStep), but it all works correctly.
About manually specifying this->, it's because I prefer to minimize situations where ambiguous references can occur (Although I don't go as far as specifying namespaces for every object/method... I leave that up to the using namespace directive), plus you can tell right away that whatever you are calling is a method in the class you're dealing with, not a method outside of the class.

Anyway, thanks so much for your advice!
 
Top