Esempio n. 1
0
void RMANAGER::TimeStep()
{
	VESSEL * v = NULL;
	OBJHANDLE hVes = NULL;

	char ini[255];
	for (int i = 0; i < oapiGetVesselCount(); i++)
	{
		hVes = oapiGetVesselByIndex(i);
		if (!oapiIsVessel(hVes))
			continue;
		v    = oapiGetVesselInterface(hVes);
		if (isAttended(v))
			continue;
		if (!hasConfig(v))
			continue;
		sprintf(ini,"./Config/orbReentryStream/%s.ini",INI(v));
		atList.push_back(ReadAndAssign(ini,v));
	}
	VOBJ * vbj = NULL;
	for (int i = 0; i < atList.size(); i++)
	{
		if (!atList[i])
			continue;
		if (!oapiIsVessel(atList[i]->hook))
			continue;
		vbj  = atList[i];
		v    = oapiGetVesselInterface(vbj->hook);
		hVes = v->GetHandle();
		if (calcFlux(v) > vbj->flux)
		{
			if (!vbj->th)
				CreateResourceAndStreams(vbj);
			v->SetThrusterLevel(vbj->th,1);
		}else if (vbj->th)
			v->SetThrusterLevel(vbj->th,0);
	}
}
Esempio n. 2
0
DLLCLBK void opcPreStep(double simt, double simdt, double mjd)
{
	OrbiterPluginMessage * opm; // holds our msg and msg data
	char * msg;
	int len;
	// nextMessage() returns MESSAGE_OK if a message is succesfully polled
	while(OICOM::nextMessage(pid, &opm)==MESSAGE_OK)
	{
		msg=opm->strMsg;
		len=strlen(msg);
		// we don't care about any text only events for this module
		if ( opm->data == 0 ) 
		{
			// remove this message from the message stack
			OICOM::removeLastMessage(pid);
			continue;
		}
		// perma-link! hook up this module's state variables with any module providing input
		// this is powerful
		if ( !_strnicmp(msg, "link_state", len) )
			active=(bool*)opm->data;
		else if (!_strnicmp(msg, "link_setpoint", len) )
			setpoint=(double*)opm->data;
		OICOM::removeLastMessage(pid); // this is important otherwise we'll end up with an infinite loop!
									   // I am thinking about automating it.. calling this at nextMessage
	}
	// if not linked to any module for input, no need to proceed
	if ( active == 0 || setpoint == 0 ) return;

	if ( !*active ) return;
	// crappy "autopilot" code follows, IGNORE IT xD
	VESSEL * vessel = oapiGetFocusInterface();
	DWORD inx = vessel->GetGroupThrusterCount(THGROUP_MAIN);
	VECTOR3 dv;
	vessel->GetDragVector(dv);
	THRUSTER_HANDLE th;
	double e = *setpoint-vessel->GetAirspeed();
	double lvl = 0;
	for (DWORD i = 0; i < inx; i++)
	{
		th = vessel->GetGroupThruster(THGROUP_MAIN, i);
		lvl = (-dv.z+e*vessel->GetMass()*70)/vessel->GetThrusterMax0(th);
		if (lvl<0)
			lvl=0;
		else if (lvl>1)
			lvl=1;
		vessel->SetThrusterLevel(th, lvl);
	}
}