IMS2  Pre-Alpha
An Orbiter add-on to allow on-runtime construction of spacecraft from predefined modules
IMS_PropellantInjector Class Reference

Handles the proliferation of propellant mixtures to thrusters. More...

Public Member Functions

 IMS_PropellantInjector (vector< int > &propellant_ids, vector< float > &ratio, double efficiency, VESSEL *vessel)
 
bool ConnectTank (IMS_Storable *tank)
 Connects a tank to this injector. More...
 
bool DisconnectTank (IMS_Storable *tank)
 Disconnects a tank from this injector. More...
 
void ConnectThruster (THRUSTER_HANDLE thruster, double maxmassflow)
 Connects a thruster to this injector. More...
 
bool DisconnectThruster (THRUSTER_HANDLE thruster, double maxmassflow)
 Removes a thruster from this injector. More...
 
bool EnableThruster (THRUSTER_HANDLE thruster)
 Marks a thruster as ready for operation. More...
 
bool DisableThruster (THRUSTER_HANDLE thruster)
 Marks a thruster as not currently operational. More...
 
int GetNumberOfThrusters ()
 
double GetMass ()
 
bool PreStep ()
 Calculates propellant consumption since last call. More...
 
bool CompareMixture (vector< int > &propellant_ids, vector< float > &ratio, double efficiency)
 
double GetAvailablePropellantMass ()
 

Private Member Functions

void checkValidity ()
 Checks whether the injector can work with the currently connected tanks and sets the isViable flag accordingly.
 
void disableInjector ()
 Disables all thrusters in the injector, but without actually changing their enabled status. This is used when the injector doesn't have enough propellant anymore to work. The operational state of.
 
void enableInjector ()
 Enables all thrusters that are enabled. This is used to re-enable an injector when new propellant becomes available. The operational status of individual thrusters is not affected.
 
void scaleInjectorResource ()
 
double getAvailablePropellantMassByType (int consumable_id)
 

Private Attributes

map< int, vector< IMS_Storable * > > tanks
 contains all currently connected tanks
 
map< int, double > ratio
 maps ratioes to their respective propellant types
 
map< THRUSTER_HANDLE, bool > thrusters
 Stores all handles to thrusters proliferated by this injector, and whether they are enabled or not.
 
PROPELLANT_HANDLE injector = NULL
 The orbiter propellant resource the injector uses to satisfy orbiter. It also serves as a kind of feedback event to know how much propellant is actually consumed.
 
double currenttimewarp
 the time acceleration the sim is currently in. Needed for scaling the propellant resource.
 
double totalmaxmassflow = 0
 the maximum total massflow that can pass through this injector, in kg/s
 
VESSEL * v
 
double injectormass = 0
 
bool injectormasschanged = false
 True if the mass of the virtual resource has changed during this frame.
 
bool isViable = false
 Shows whether the injector has all necessary propellants to actually work.
 

Detailed Description

Handles the proliferation of propellant mixtures to thrusters.

You should not think of this as a physical piece of machinery running in the ship. This is a purely virtual construct for the benefit of easier code, it does not have any physical equivalent. It is named PropellantInjector because the job-description comes close to what it does (proliferation of correct mixtures from tanks to thrusters), but it really only exists because orbiter insists that a thruster take its propellant from a single propellant resource.

Constructor & Destructor Documentation

IMS_PropellantInjector::IMS_PropellantInjector ( vector< int > &  propellant_ids,
vector< float > &  ratio,
double  efficiency,
VESSEL *  vessel 
)
Parameters
propellant_idsA list of all propellant ids contained in this injectors mixture
ratioa list of ratioes at which the corresponding ids have to be mixed.
prop_efficiencyThe efficiency at which this mixture is converted into thrust by the thruster
vesselThe vessel this PropellantInjector is located on
Note
Exaple: propellant_ids{1,2} and ratio{1,6} means that the propellant type with id 1 and the propellant type with id 2 have to be mixed at a ratio of 1:6. and ratio must have the same size!

Member Function Documentation

bool IMS_PropellantInjector::CompareMixture ( vector< int > &  propellant_ids,
vector< float > &  ratio,
double  efficiency 
)
Returns
True if the mixture of this injector matches the mixture passed in the arguments, false otherwise
bool IMS_PropellantInjector::ConnectTank ( IMS_Storable *  tank)

Connects a tank to this injector.

Parameters
tankThe IMS_Storable to be added as a tank
Returns
True if the tank was added, false if the tank did not contain any consumable compatible with this injector
See also
DisconnectTank()
void IMS_PropellantInjector::ConnectThruster ( THRUSTER_HANDLE  thruster,
double  maxmassflow 
)

Connects a thruster to this injector.

Parameters
thrusterThe handle to a orbiter thruster
maxmassflowThe maximum massflow of the thruster, in kg/s
Note
In contrast to ConnectTank() and DisconnectTank(), this method has no way of verifying if the passed thruster is actually suited for this injector. Make sure to check compatibility using CompareMixture() before adding a thruster to an injector!
See also
DisconnectThruster()
bool IMS_PropellantInjector::DisableThruster ( THRUSTER_HANDLE  thruster)

Marks a thruster as not currently operational.

Parameters
thrusterAn orbiter THRUSTER_HANDLE to the thruster to be disabled
Returns
True if the thruster is now disabled (regardless of whether or not it was before), false if the thruster isn't actually connected to this injector.
bool IMS_PropellantInjector::DisconnectTank ( IMS_Storable *  tank)

Disconnects a tank from this injector.

Parameters
tankThe IMS_Storable to be removed from the injector
Returns
True if the tank was disconnected, false if the tank was not actually connected to this injector
See also
ConnectTank()
bool IMS_PropellantInjector::DisconnectThruster ( THRUSTER_HANDLE  thruster,
double  maxmassflow 
)

Removes a thruster from this injector.

Parameters
thrusterthe handle to an orbiter thruster
maxmassflowthe maximum massflow of the thruster, in kg/s
Returns
True if the thruster was disconnected, false if the thruster was not actually connected to this injector
Note
This should only be called if a thruster is removed from a vessel. The injector will disconnect its internal propellant resource from its thrusters when the tanks run dry to disable the thruster, this method must not be called to do that.
See also
ConnectThruster
bool IMS_PropellantInjector::EnableThruster ( THRUSTER_HANDLE  thruster)

Marks a thruster as ready for operation.

Parameters
thrusterAn orbiter THRUSTER_HANDLE to the thruster to be enabled
Returns
True if the thruster is now enabled (regardless of whether or not it was before), false if the thruster isn't actually connected to this injector.
double IMS_PropellantInjector::GetAvailablePropellantMass ( )
Returns
the total amount of propellant available to the injector, in kg
Note
This does not take the mixture into account! It may well be that the injector has a ton of propellant available, but can only burn 100 kg because the propellants are not proportional to the ratio at which they are consumed!
double IMS_PropellantInjector::getAvailablePropellantMassByType ( int  consumable_id)
private
Returns
The mass of a certain propellant type available to the injector, in kg.
Parameters
consumable_idId of the consumable you want to know the mass for. Must be present in the injector!
int IMS_PropellantInjector::GetNumberOfThrusters ( )
inline
Returns
The number of thrusters this injector currently connects to
bool IMS_PropellantInjector::PreStep ( )

Calculates propellant consumption since last call.

Resizes virtual propellant resource if necessary, draws consumed propellant from connected tanks

Returns
true if the mass of the virtual propellant resource has changed, false otherwise.
void IMS_PropellantInjector::scaleInjectorResource ( )
private

Scales the virtual propellant resource depending on time acceleration and mximum massflow of the engine

Note
This method changes the mass of the underlying orbiter vessel. Any caller is responsible to insure that the vessel mass of the IMS vessel is recalculated in the same frame, but should take care that it is not done twice in the same frame.

The documentation for this class was generated from the following files: