I'm writing a stage seperation routine based on the stock Atlantis' Tank seperation routine. I've got the basic routine working but I can't seem to figure out how to set the propellant levels in the seperated stage via VESSELSTATUS::FUELSPEC to the levels that they were at prior to seperation.
I can set an empty tank and I can set a full tank but is there any way to set an "in between" tank.
here is the pertinant portion of my function.
---------- Post added at 13:25 ---------- Previous post was at 12:23 ----------
So I tried a different tack by trying to create a VESSEL interface instance after the seperated stage had already spawned but this didn't work either.
the code compiles and runs just fine, the levels just aren't being set.
Does anybody have any ideas?
---------- Post added at 14:37 ---------- Previous post was at 13:25 ----------
...and now I feel silly.
I had forgotten to include "ds->" in the "GetPropellantHandleByIndex" call. :facepalm:
the following code does the job...
I can set an empty tank and I can set a full tank but is there any way to set an "in between" tank.
here is the pertinant portion of my function.
Code:
// Create descent stage as individual object
memset (&vs, 0, sizeof (vs));
vs.version = 2;
GetStatusEx (&vs);
vs.flag = VS_FUELLIST;
vs.fuel = &fuel;
double fuel_lvl, O2_lvl, H2O_lvl;
fuel_lvl = GetPropellantMass (ph_descentFuel) / GetPropellantMaxMass (ph_descentFuel);
O2_lvl = GetPropellantMass (ph_descentO2) / GetPropellantMaxMass (ph_descentO2);
H2O_lvl = GetPropellantMass (ph_descentH2O) / GetPropellantMaxMass (ph_descentH2O);
//How?
set proplevel 0 to fuel_lvl
set proplevel 1 to O2_lvl
set proplevel 2 to H2O_lvl
---------- Post added at 13:25 ---------- Previous post was at 12:23 ----------
So I tried a different tack by trying to create a VESSEL interface instance after the seperated stage had already spawned but this didn't work either.
Code:
strcpy (name, GetName ());
strcat (name, "-DescentStage");
oapiCreateVesselEx (name, "UMMU_Apollo/LM_descentstage", &vs);
OBJHANDLE oh_descent = oapiGetObjectByName (name);
VESSEL *ds = oapiGetVesselInterface (oh_descent);
ds->SetPropellantMass (GetPropellantHandleByIndex (0), GetPropellantMass (ph_descentFuel));
ds->SetPropellantMass (GetPropellantHandleByIndex (1), GetPropellantMass (ph_descentO2));
ds->SetPropellantMass (GetPropellantHandleByIndex (2), GetPropellantMass (ph_descentH2O));
the code compiles and runs just fine, the levels just aren't being set.
Does anybody have any ideas?
---------- Post added at 14:37 ---------- Previous post was at 13:25 ----------
...and now I feel silly.
I had forgotten to include "ds->" in the "GetPropellantHandleByIndex" call. :facepalm:
the following code does the job...
Code:
void LM::StageSeparation (void)
{
if (VesselStatus == DESCENT) // Sanity check, is there a descent stage to jettison?
{
VESSELSTATUS vs;
char name[256];
VECTOR3 ofs, rofs;
VECTOR3 sdir = { 0,-1, 0}; // Seperation direction
double svel = 0.3; // Separation velocity
// Create descent stage as seperate vessel
GetStatus (vs);
ofs = LM_DES_OFFSET;
Local2Rel (ofs, vs.rpos);
vs.status = 0;
Local2Rel (ofs, vs.rpos);
GlobalRot (sdir, rofs);
vs.rvel += rofs*svel;
strcpy (name, GetName());
strcat (name, "-DescentStage");
oapiCreateVessel (name, "UMMU_Apollo/LM_descentstage", vs); // create descent stage vessel
// Match descent stage's propellant levels to current
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));
// Remove descent stage from vessel instance
DelThruster (th_descent); // Delete descent stage engine
DelPropellantResource (ph_descentH2O); // Delete descent stage water tank
DelPropellantResource (ph_descentO2); // Delete descent stage O2 tank
DelPropellantResource (ph_descentFuel); // Delete descent stage propellant tank
DelMesh (mesh_Descent); // Delete descent stage mesh
VesselStatus = ASCENT; // Set vessel status to ascent
} // End "if (VesselStatus == DESCENT)"
} // End "LM::StageSeparation"
Last edited: