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

Manages Storables available for propellant consumption (i.e. propellant tanks), as well as thrusters. More...

Inherits IMS_Manager_Base.

Public Member Functions

 IMS_PropulsionManager (IMS2 *_vessel)
 
void AddTank (IMS_Storable *tank)
 Adds a new tank to the propellant manager. More...
 
void RemoveTank (IMS_Storable *tank)
 Removes a tank from the propellant manager. More...
 
void OpenTank (IMS_Storable *tank)
 Opens a tank to make it accessible to thrusters. More...
 
void CloseTank (IMS_Storable *tank)
 Closes a tank and makes it inaccessible to thrusters. More...
 
THRUSTER_HANDLE AddThruster (THRUSTERMODE *thrustermode, VECTOR3 &pos, VECTOR3 &dir)
 Gets or creates an Injector compatible with the passed mixture. More...
 
void RemoveThruster (THRUSTER_HANDLE thruster, double maxflowrate, bool deletefromvessel=true)
 Removes a thruster from the manager and/or from the orbiter vessel. More...
 
void SwitchThrusterMode (THRUSTER_HANDLE thruster, THRUSTERMODE *mode)
 Changes the thrustermode of an already added thruster. More...
 
void SetThrusterEnabled (THRUSTER_HANDLE thruster, bool enabled)
 Enables or disables a thruster. A disabled thruster is considered not to be in operational condition at this time by the manager. More...
 
void AddThrusterToGroup (THRUSTER_HANDLE thruster, THGROUP_TYPE group)
 Adds a thruster to a thruster group. More...
 
void RemoveThrusterFromGroup (THRUSTER_HANDLE thruster, THGROUP_TYPE group)
 Removes a thruster from a thruster group. More...
 
void AddExhausts (THRUSTER_HANDLE thruster, vector< THRUSTEREXHAUST > &exhausts)
 adds exhausts to a thruster More...
 
void RemoveExhausts (THRUSTER_HANDLE thruster)
 Removes all exhausts associated with a thruster. More...
 
void PreStep (double simdt)
 Performs the prestep update of the PropellantManager and all injectors, thrusters and tanks it is aware of.
 

Private Member Functions

bool ProcessEvent (Event_Base *e)
 Receives all events coming through this EventHandler. More...
 
IMS_PropellantInjectorgetInjector (vector< int > propellant_ids, vector< float > ratio, double efficiency)
 Creates an IMS_PropellantInjector in the PropellantManager if a compatible one doesn't already exist. More...
 
void updateThrusterGroup (THGROUP_TYPE group)
 Updates a thruster group on the orbiter vessel. More...
 
void addTankToInjectors (IMS_Storable *tank)
 Adds a tank to all injectors that.
 
void removeTankFromInjectors (IMS_Storable *tank)
 Removes a tank from all injectors.
 

Private Attributes

map< int, vector< IMS_Storable * > > tanks
 
vector< IMS_PropellantInjector * > injectors
 list of currently present injectors
 
map< THGROUP_TYPE, vector< THRUSTER_HANDLE > > thgroups
 Contains the list of thrusters for each group.
 
map< THRUSTER_HANDLE, vector< UINT > > liveexhausts
 Maps exhaust definitions to a thruster handle.
 

Detailed Description

Manages Storables available for propellant consumption (i.e. propellant tanks), as well as thrusters.

It's important to realise that the purpose of this manager is to offer Storables SPECIFICALLY for use as propellant tanks This manager should always have knowledge of all Storables used as propellant tanks currently on the vessel. Storables registered and opened with this manager will be used when a thruster requires their consumables as propellant, and closed Storables cannot be used by thrusters, even if they would have the right contents.

Note
The class is slightly misnamed, as it also turned out to kinda manage thrusters.
See also
IMS_Storable

Constructor & Destructor Documentation

IMS_PropulsionManager::IMS_PropulsionManager ( IMS2 *  _vessel)
Parameters
vesselThe VESSEL instance this PropellantManager is responsibly for

Member Function Documentation

void IMS_PropulsionManager::AddExhausts ( THRUSTER_HANDLE  thruster,
vector< THRUSTEREXHAUST > &  exhausts 
)

adds exhausts to a thruster

Parameters
thrusterThe thruster the new exhausts are to be associated with
modeThe thrustermode set for that thruster
exhaustscreation data for the exhausts
Note
You have to call this method separately from creating a thruster. The reason is that PropellantManager cannot keep track of the relative position of the module, and there are only methods in Orbiter to create and delete exhausts, not to change them. So when an exhaust changes, Propellantmanager has to delete the old one, but then doesn't have the information to judge where the new has to be placed.
void IMS_PropulsionManager::AddTank ( IMS_Storable *  tank)

Adds a new tank to the propellant manager.

Parameters
tankA storable to be added as tank
Note
Do not add the same tank 2 times
If a tank isn't added to the propellant manager, it effectively doesn't exist on the vessel, even if the module is there.
THRUSTER_HANDLE IMS_PropulsionManager::AddThruster ( THRUSTERMODE thrustermode,
VECTOR3 &  pos,
VECTOR3 &  dir 
)

Gets or creates an Injector compatible with the passed mixture.

Parameters
propellant_idsA list of all ids of propellants appearing in the mixture
ratioA list with the mix ratios for the above propellants
efficiencyThe efficiency of the mixture, between 0 and 1
exhaustsA list of exhaust data that defines all exhausts associated with the thruster, pos and dir vessel-relative!
Returns
A pointer to an Injector compatible with the propellant mixture, either pre-existing or newly created.
Note
This method guarantees that there is only one injector for each mixture in the manager.
ratios to be given in whole numbers, sequentially matched with propellant_ids. example: propellant_ids {1, 2} and ratio {2, 3} means propellants 1 and 2 are mixed in a ratio of 2 to 3.
void IMS_PropulsionManager::AddThrusterToGroup ( THRUSTER_HANDLE  thruster,
THGROUP_TYPE  group 
)

Adds a thruster to a thruster group.

Parameters
thrusterHandle to the thruster to be added.
groupThe thruster group the thruster should be added to
void IMS_PropulsionManager::CloseTank ( IMS_Storable *  tank)

Closes a tank and makes it inaccessible to thrusters.

Parameters
tankThe tank to be closed. It is expected that the tank has been added to the PropellantManager prior to this operation!
IMS_PropellantInjector * IMS_PropulsionManager::getInjector ( vector< int >  propellant_ids,
vector< float >  ratio,
double  efficiency 
)
private

Creates an IMS_PropellantInjector in the PropellantManager if a compatible one doesn't already exist.

Parameters
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
Returns
The newly created injector, or the existing injector compatible with the mixture
See also
IMS_PropellantInjector
void IMS_PropulsionManager::OpenTank ( IMS_Storable *  tank)

Opens a tank to make it accessible to thrusters.

Parameters
tankThe tank to be opened. It is expected that the tank has been added
forceevaluationPass true to force injectors to evaluate the tank, even if it was already open.
Note
Usually the tank will only be evaluated by injectors if the valve was closed before, since it can be assumed that otherwise it would already be registered with the propper injectors. This does not hold true if a tank is added to the vessel with valve already open, in which case this method must be forced to pass the tank to the injectors for evaluation in any case. to the PropellantManager prior to this operation!
bool IMS_PropulsionManager::ProcessEvent ( Event_Base e)
privatevirtual

Receives all events coming through this EventHandler.

Overload to implement event handling in your inheriting class. The function will receive Events one by one as they are coming through your event sinks, regardless of which pipe they belong to. Return true to consume an event, but be sure it was only meant for you when you do that.

Parameters
eThe event coming through the event pipe
Note
Event generators will NOT send events to this function, only sinks.

Implements EventHandler.

void IMS_PropulsionManager::RemoveExhausts ( THRUSTER_HANDLE  thruster)

Removes all exhausts associated with a thruster.

Parameters
Thethruster for which to delete the exhausts
Note
If you have exhausts that change, call this first and then add them again.
void IMS_PropulsionManager::RemoveTank ( IMS_Storable *  tank)

Removes a tank from the propellant manager.

Parameters
tankThe tank to be removed from the manager
Note
A tank not unregistered from the propellant manager will still be controlled by this manager, even if the module is not in this vessel anymore!
void IMS_PropulsionManager::RemoveThruster ( THRUSTER_HANDLE  thruster,
double  maxflowrate,
bool  deletefromvessel = true 
)

Removes a thruster from the manager and/or from the orbiter vessel.

Parameters
thrusterA handle to the thruster to be removed
maxflowrateThe maximum flowrate of the thruster (needed to adjust size of virtual propellant source)
deletefromvesselPass false if you do not want the thruster handle deleted from the vessel
Note
Thruster MUST be removed from any groups prior to calling this, or there will be trouble!
void IMS_PropulsionManager::RemoveThrusterFromGroup ( THRUSTER_HANDLE  thruster,
THGROUP_TYPE  group 
)

Removes a thruster from a thruster group.

Parameters
thrusterThe thruster to be removed from a group
groupThe group the thruster is currently a member of
void IMS_PropulsionManager::SetThrusterEnabled ( THRUSTER_HANDLE  thruster,
bool  enabled 
)

Enables or disables a thruster. A disabled thruster is considered not to be in operational condition at this time by the manager.

Parameters
thrusterA handle to the thruster to be enabled or disabled.
enabledPass true if the thruster is ready to operate, false if not.
void IMS_PropulsionManager::SwitchThrusterMode ( THRUSTER_HANDLE  thruster,
THRUSTERMODE mode 
)

Changes the thrustermode of an already added thruster.

Parameters
thrusterThe thruster handle of the thruster that switches modes.
modeThe thrustermode thruster is to be set to.
void IMS_PropulsionManager::updateThrusterGroup ( THGROUP_TYPE  group)
private

Updates a thruster group on the orbiter vessel.

Parameters
groupThe group to update
Note
This MUST be called after any changes to thgroups, as the array wrapped by a vector is not guaranteed to retain its memory address when changing!

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