#include <UACS/Module.h>
………………………
public:
void clbkLoadStateEx(FILEHANDLE scn, void* status);
void clbkSaveState(FILEHANDLE scn);
void clbkPostCreation();
int clbkGeneric(int msgid, int prm, void* context);
private:
UACS::Module uacs;
UACS::VslAstrInfo vslAstrInfo; // Add if the vessel supports astronauts
UACS::VslCargoInfo vslCargoInfo; // Add if the vessel supports cargoes
Vessel::Vessel(OBJHANDLE hVessel, int flightmodel) : VESSEL4(hVessel, flightmodel), uacs(this, &vslAstrInfo, &vslCargoInfo)
void Vessel::clbkSetClassCaps(FILEHANDLE cfg)
{
………………………
UACS::AirlockInfo airInfo;
airInfo.name = "Airlock";
airInfo.pos = { 0,-0.74, 3.5 };
airInfo.dir = { 0,0,-1 };
airInfo.rot = { -1,0,0 };
airInfo.hDock = CreateDock({ 0,-1,-1 }, { 0,-1,0 }, { 0,0,-1 });
airInfo.gndInfo.pos = { 4,0,-1.3 };
vslAstrInfo.airlocks.push_back(airInfo);
vslAstrInfo.stations.emplace_back("Pilot");
UACS::SlotInfo slotInfo;
slotInfo.hAttach = CreateAttachment(false, { 0,1.3,-1 }, { 0,1,0 }, { 0,0,1 }, "UACS");
slotInfo.holdDir = { 0, -1, 0 };
slotInfo.relVel = 0.05;
slotInfo.gndInfo.pos = { -4,0,-1.3 };
vslCargoInfo.slots.push_back(slotInfo);
}
void Vessel::clbkLoadStateEx(FILEHANDLE scn, void* status)
{
char* line;
while (oapiReadScenario_nextline(scn, line))
if (!uacs.ParseScenarioLine(line)) ParseScenarioLineEx(line, status);
}
In the clbkSaveState method, call the vessel API clbkSaveState method.
In the clbkPostCreation method, call the vessel API clbkPostCreation method. Update the vessel empty mass to include mass of astronauts onboard.
In the clbkGeneric method (only if the vessel supports astronauts), update the vessel empty weight based on the received message. If the vessel has action areas, implement their logic as appropriate.
For action areas, simply add UACS::ACTN_TRIG to the switch statement, get the action area index, and handle as required.
The API setup is now complete. You can call all API methods as required.
void Vessel::clbkSaveState(FILEHANDLE scn)
{
VESSEL4::clbkSaveState(scn);
uacs.clbkSaveState(scn);
}
void Vessel::clbkPostCreation()
{
uacs.clbkPostCreation();
SetEmptyMass(GetEmptyMass() + uacs.GetTotalAstrMass()); }
int Vessel::clbkGeneric(int msgid, int prm, void* context)
{
if (msgid == UACS::MSG)
{
switch (prm)
{
case UACS::ASTR_INGRS:
{
auto astrIdx = *static_cast<size_t*>(context);
auto& astrInfo = vslAstrInfo.stations.at(astrIdx).astrInfo;
SetEmptyMass(GetEmptyMass() + astrInfo->mass);
return 1;
}
case UACS::ASTR_EGRS:
{
auto astrIdx = *static_cast<size_t*>(context);
auto& astrInfo = vslAstrInfo.stations.at(astrIdx).astrInfo;
SetEmptyMass(GetEmptyMass() - astrInfo->mass);
return 1;
}
default:
return 0;
}
}
return 0;
}