Kerbal Space Program  1.12.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | Properties | List of all members
PartSet Class Reference

Classes

class  ResourcePrioritySet
 This class just links up the double-list of part resources with a hashset of them for fast contains checks. More...
 

Public Types

enum  PartBuildSetOptions { PartBuildSetOptions.Real = 1, PartBuildSetOptions.Simulate = 2, PartBuildSetOptions.Both = 3 }
 Options for the BuildPartSets method More...
 

Public Member Functions

bool ContainsPart (Part p)
 Checks if the part is handled by the partset More...
 
virtual void GetConnectedResourceTotals (int id, out double amount, out double maxAmount, bool pulling)
 Gets the amount and maxamount of the given resource in the partset More...
 
virtual void GetConnectedResourceTotals (int id, out double amount, out double maxAmount, bool pulling, bool simulate)
 Gets the amount and maxamount of the given resource in the partset More...
 
virtual void GetConnectedResourceTotals (int id, out double amount, out double maxAmount, double threshold, bool pulling)
 Gets the amount and maxamount of the given resource in the partset, obeying threshold More...
 
virtual void GetConnectedResourceTotals (int id, out double amount, out double maxAmount, double threshold, bool pulling, bool simulate)
 Gets the amount and maxamount of the given resource in the partset, obeying threshold More...
 
HashSet< PartGetParts ()
 Returns the set of parts or a new set if the set is null. NOTE DO NOT CHANGE THIS. For getting only. If you want to change it, use RebuildParts() More...
 
ResourcePrioritySet GetResourceList (int id, bool pulling, bool simulate)
 Get the Resource List More...
 
void HookEvents ()
 
 PartSet (HashSet< Part > parts)
 Construct a crossfeed (non-vesselwide) partset More...
 
 PartSet (Vessel v)
 Construct a vessel-wide partset More...
 
 PartSet (PartSet set)
 Makes a deep copy of the hash set but DOES NOT copy the caches More...
 
 PartSet (ShipConstruct shipRef)
 Construct a vessel-wide partset from ShipConstruct More...
 
 PartSet (ShipConstruct shipRef, HashSet< Part > newParts)
 Construct a partset from ShipConstruct - sets the target parts list in the PartSet to the passed in HashSet. More...
 
virtual void RebuildInPlace ()
 Clears cache without recreating the targetparts More...
 
virtual void RebuildParts (HashSet< Part > newParts)
 Rebuild the partset as a crossfeed set Note: Does not clear targetPats, merely replaces it More...
 
virtual void RebuildVessel (Vessel newVessel)
 Recreate the partset as a vessel-wide set More...
 
virtual void RebuildVessel (ShipConstruct newShip)
 Recreate the partset as a vessel-wide set More...
 
virtual void RebuildVessel (ShipConstruct newShip, HashSet< Part > newParts)
 Recreate the partset - sets the target parts list in the PartSet to the passed in HashSet. More...
 
virtual void RemovePart (Part part)
 Will remove a Part from the Partset. More...
 
virtual double RequestResource (Part part, int id, double demand, bool usePri)
 This method replaces the old RequestResource mechanic, and is called by Part.RequestResource. More...
 
virtual double RequestResource (Part part, int id, double demand, bool usePri, bool simulate)
 This method replaces the old RequestResource mechanic, and is called by Part.RequestResource. More...
 
bool SetsEqual (HashSet< Part > set)
 Checks if the set of parts this covers is the same as the passed set More...
 

Static Public Member Functions

static void AddPartToSet (HashSet< Part > set, Part p, Vessel v)
 Recursively add parts to a hashset, obeying crossfeed flow rules. If we are not in the editor, we check that vessels match. More...
 
static void BuildPartSets (List< Part > parts, Vessel v)
 Build the partsets for the list of parts (editor) or parts on a vessel (if vessel not null). If so, we pass back the list of sets too. More...
 
static void BuildPartSets (List< Part > parts, Vessel v, bool simulate)
 Build the partsets for the list of parts (editor) or parts on a vessel (if vessel not null) or parts in a ShipConstruct (if ship not null). If so, we pass back the list of sets too. More...
 
static void BuildPartSets (List< Part > parts, Vessel v, PartBuildSetOptions buildoptions)
 Build the partsets for the list of parts (editor) or parts on a vessel (if vessel not null) or parts in a ShipConstruct (if ship not null). If so, we pass back the list of sets too. More...
 
static HashSet< PartSetBuildPartSimulationSets (List< Part > parts)
 Build simulation partsets for the list of parts. More...
 

Public Attributes

int setId
 

Static Public Attributes

static int _id = 0
 

Protected Member Functions

void AddPartResource (PartResource r, Dictionary< int, ResourcePrioritySet > dict)
 This will add a new partresource to the given (push/pull) dictionary. More...
 
ResourcePrioritySet BuildResList (int id, bool pull)
 This will build the res list for a given resource id and pull/push It will iterate over all parts in the set and see if they have the resource of the given ID and whether it can flow in the given direction. If so it's added, with its priority, to the set. More...
 
ResourcePrioritySet BuildResList (int id, bool pull, bool simulate)
 This will build the res list for a given resource id and pull/push It will iterate over all parts in the set and see if they have the resource of the given ID and whether it can flow in the given direction. If so it's added, with its priority, to the set. More...
 
ResourcePrioritySet GetOrCreateList (int id, bool pulling)
 This will get the ResourcePrioritySet for the appropriate resource ID and whether we are pulling or pushing. If it does not yet exist, it is created. More...
 
ResourcePrioritySet GetOrCreateList (int id, bool pulling, bool simulate)
 This will get the ResourcePrioritySet for the appropriate resource ID and whether we are pulling or pushing. If it does not yet exist, it is created. More...
 
void OnFlowModeChange (GameEvents.HostedFromToAction< PartResource, PartResource.FlowMode > data)
 
void OnFlowStateChange (GameEvents.HostedFromToAction< PartResource, bool > data)
 
double ProcessRequest (Part part, ResourcePrioritySet resList, double demand, bool usePri, bool pulling)
 This works on the list of resources (in priority order) and handles the demand. More...
 
double ProcessRequest (Part part, ResourcePrioritySet resList, double demand, bool usePri, bool pulling, bool simulate)
 This works on the list of resources (in priority order) and handles the demand. More...
 
void RemovePartResource (PartResource r, Dictionary< int, ResourcePrioritySet > dict)
 This will remove a partresource from the given (push/pull) dictionary More...
 

Protected Attributes

Dictionary< int,
ResourcePrioritySet
pullList = new Dictionary<int, ResourcePrioritySet>()
 
Dictionary< int,
ResourcePrioritySet
pushList = new Dictionary<int, ResourcePrioritySet>()
 
ShipConstruct ship
 if in editor scene in ShipConstruct mode, the current ship More...
 
bool simulationSet = false
 
HashSet< ParttargetParts
 if in partset mode, the set of parts we care about More...
 
Vessel vessel
 if in vessel mode, the current vessel More...
 
bool vesselWide
 determines what mode this PartResourceSet is in More...
 

Static Protected Attributes

static Dictionary< HashSet
< Part >, PartSet
setsHolder = new Dictionary<HashSet<Part>, PartSet>()
 Temporary holder for the sets. Used to interact with the flow graph code. More...
 

Properties

bool ListsExist [get]
 
static int NextID [get]
 

Member Enumeration Documentation

Options for the BuildPartSets method

Enumerator
Real 

Do the real set only

Simulate 

Do the simulation set only

Both 

Do both real and simulation

Constructor & Destructor Documentation

PartSet.PartSet ( HashSet< Part parts)
inline

Construct a crossfeed (non-vesselwide) partset

Parameters
parts
PartSet.PartSet ( Vessel  v)
inline

Construct a vessel-wide partset

Parameters
v
PartSet.PartSet ( PartSet  set)
inline

Makes a deep copy of the hash set but DOES NOT copy the caches

Parameters
set
PartSet.PartSet ( ShipConstruct  shipRef)
inline

Construct a vessel-wide partset from ShipConstruct

Parameters
shipRef
PartSet.PartSet ( ShipConstruct  shipRef,
HashSet< Part newParts 
)
inline

Construct a partset from ShipConstruct - sets the target parts list in the PartSet to the passed in HashSet.

Parameters
shipRefThe ShipConstruct reference
newPartsHashSet of parts to set to the target parts list in the PartSet - if Null target parts list is determined from the ShipRef

Member Function Documentation

void PartSet.AddPartResource ( PartResource  r,
Dictionary< int, ResourcePrioritySet dict 
)
inlineprotected

This will add a new partresource to the given (push/pull) dictionary.

Parameters
r
dict
static void PartSet.AddPartToSet ( HashSet< Part set,
Part  p,
Vessel  v 
)
inlinestatic

Recursively add parts to a hashset, obeying crossfeed flow rules. If we are not in the editor, we check that vessels match.

Parameters
set
p
v

< check fuel lines

< check surface attachments (i.e. our children)

static void PartSet.BuildPartSets ( List< Part parts,
Vessel  v 
)
inlinestatic

Build the partsets for the list of parts (editor) or parts on a vessel (if vessel not null). If so, we pass back the list of sets too.

Parameters
parts
v
static void PartSet.BuildPartSets ( List< Part parts,
Vessel  v,
bool  simulate 
)
inlinestatic

Build the partsets for the list of parts (editor) or parts on a vessel (if vessel not null) or parts in a ShipConstruct (if ship not null). If so, we pass back the list of sets too.

Parameters
partsThe list of parts
vThe vessel reference or null
simulatetrue to use the simulation resource set. Otherwise false to use the real resource set.
static void PartSet.BuildPartSets ( List< Part parts,
Vessel  v,
PartBuildSetOptions  buildoptions 
)
inlinestatic

Build the partsets for the list of parts (editor) or parts on a vessel (if vessel not null) or parts in a ShipConstruct (if ship not null). If so, we pass back the list of sets too.

Parameters
partsThe list of parts
vThe vessel reference or null
buildoptionswhether to build the simulation resource set, real resourec set or both
static HashSet<PartSet> PartSet.BuildPartSimulationSets ( List< Part parts)
inlinestatic

Build simulation partsets for the list of parts.

Parameters
partsThe list of parts
Returns
hashset of the PartSets generated
ResourcePrioritySet PartSet.BuildResList ( int  id,
bool  pull 
)
inlineprotected

This will build the res list for a given resource id and pull/push It will iterate over all parts in the set and see if they have the resource of the given ID and whether it can flow in the given direction. If so it's added, with its priority, to the set.

Parameters
idThe resource id
pullare we pulling or pushing?
Returns
ResourcePrioritySet PartSet.BuildResList ( int  id,
bool  pull,
bool  simulate 
)
inlineprotected

This will build the res list for a given resource id and pull/push It will iterate over all parts in the set and see if they have the resource of the given ID and whether it can flow in the given direction. If so it's added, with its priority, to the set.

Parameters
idThe resource id
pullare we pulling or pushing?
simulatetrue to use the simulation resource set. Otherwise false to use the real resource set.
Returns

< iterator for the target parts

< a holder for the values

< the list of lists to return

< go through all parts, finding relevant resources

< asc order

bool PartSet.ContainsPart ( Part  p)
inline

Checks if the part is handled by the partset

Parameters
p
Returns
virtual void PartSet.GetConnectedResourceTotals ( int  id,
out double  amount,
out double  maxAmount,
bool  pulling 
)
inlinevirtual

Gets the amount and maxamount of the given resource in the partset

Parameters
id
amount
maxAmount
pulling
virtual void PartSet.GetConnectedResourceTotals ( int  id,
out double  amount,
out double  maxAmount,
bool  pulling,
bool  simulate 
)
inlinevirtual

Gets the amount and maxamount of the given resource in the partset

Parameters
idThe resource id
amountwill be populated with the amount available
maxAmountwill be populated with the maxamount available
pullingtrue if pulling resource or false if pushing
simulatetrue to use the simulation resource set. Otherwise false to use the real resource set.
virtual void PartSet.GetConnectedResourceTotals ( int  id,
out double  amount,
out double  maxAmount,
double  threshold,
bool  pulling 
)
inlinevirtual

Gets the amount and maxamount of the given resource in the partset, obeying threshold

Parameters
id
amount
maxAmount
threshold
pullingtrue if pulling resource or false if pushing
virtual void PartSet.GetConnectedResourceTotals ( int  id,
out double  amount,
out double  maxAmount,
double  threshold,
bool  pulling,
bool  simulate 
)
inlinevirtual

Gets the amount and maxamount of the given resource in the partset, obeying threshold

Parameters
idThe resource id
amountwill be populated with the amount available
maxAmountwill be populated with the maxamount available
thresholdThe threshold amount to obey
pullingtrue if pulling resource or false if pushing
simulatetrue to use the simulation resource set. Otherwise false to use the real resource set.
ResourcePrioritySet PartSet.GetOrCreateList ( int  id,
bool  pulling 
)
inlineprotected

This will get the ResourcePrioritySet for the appropriate resource ID and whether we are pulling or pushing. If it does not yet exist, it is created.

Parameters
idThe resource id
pullingtrue if pulling resource or false if pushing
Returns
ResourcePrioritySet PartSet.GetOrCreateList ( int  id,
bool  pulling,
bool  simulate 
)
inlineprotected

This will get the ResourcePrioritySet for the appropriate resource ID and whether we are pulling or pushing. If it does not yet exist, it is created.

Parameters
idThe resource id
pullingtrue if pulling resource or false if pushing
simulatetrue to use the simulation resource set. Otherwise false to use the real resource set.
Returns
HashSet<Part> PartSet.GetParts ( )
inline

Returns the set of parts or a new set if the set is null. NOTE DO NOT CHANGE THIS. For getting only. If you want to change it, use RebuildParts()

Returns
ResourcePrioritySet PartSet.GetResourceList ( int  id,
bool  pulling,
bool  simulate 
)
inline

Get the Resource List

Parameters
idThe resource id
pullingtrue if pulling resource or false if pushing
simulatetrue if simulation otherwise false to use the real resource list.
Returns
void PartSet.HookEvents ( )
inline
void PartSet.OnFlowModeChange ( GameEvents.HostedFromToAction< PartResource, PartResource.FlowMode data)
inlineprotected
void PartSet.OnFlowStateChange ( GameEvents.HostedFromToAction< PartResource, bool >  data)
inlineprotected
double PartSet.ProcessRequest ( Part  part,
ResourcePrioritySet  resList,
double  demand,
bool  usePri,
bool  pulling 
)
inlineprotected

This works on the list of resources (in priority order) and handles the demand.

Parameters
partSource part
resListthe set to work on for that ID and mode
demandthe amount demanded
usePrido we draw equally or use priority?
pullingare we pulling or pushing?
Returns
double PartSet.ProcessRequest ( Part  part,
ResourcePrioritySet  resList,
double  demand,
bool  usePri,
bool  pulling,
bool  simulate 
)
inlineprotected

This works on the list of resources (in priority order) and handles the demand.

Parameters
partSource part
resListthe set to work on for that ID and mode
demandthe amount demanded
usePrido we draw equally or use priority?
pullingare we pulling or pushing?
simulatetrue to use the simulation resource set. Otherwise false to use the real resource set.
Returns

< in this case we go through each priority list individually in order

< cache the pre-request demand to know if we drained successfully

< first get the sum of the amount we can request.

< check if that sum is more than we're requesting or not

< we are checking each iteration, so don't bother to check afterwards

< check if that sum is more than we're requesting or not

< shared across all partresources

< we don't need to check if we met the demand because we already went through all parts anyway.

virtual void PartSet.RebuildInPlace ( )
inlinevirtual

Clears cache without recreating the targetparts

virtual void PartSet.RebuildParts ( HashSet< Part newParts)
inlinevirtual

Rebuild the partset as a crossfeed set Note: Does not clear targetPats, merely replaces it

Parameters
newParts
virtual void PartSet.RebuildVessel ( Vessel  newVessel)
inlinevirtual

Recreate the partset as a vessel-wide set

Parameters
newVessel
virtual void PartSet.RebuildVessel ( ShipConstruct  newShip)
inlinevirtual

Recreate the partset as a vessel-wide set

Parameters
newShipThe ShipConstruct reference
virtual void PartSet.RebuildVessel ( ShipConstruct  newShip,
HashSet< Part newParts 
)
inlinevirtual

Recreate the partset - sets the target parts list in the PartSet to the passed in HashSet.

Parameters
newShipThe ShipConstruct reference
newPartsHashSet of parts to set to the target parts list in the PartSet - if Null target parts list is determined from the ShipRef
virtual void PartSet.RemovePart ( Part  part)
inlinevirtual

Will remove a Part from the Partset.

Parameters
partThe Part to remove from the PartSet
void PartSet.RemovePartResource ( PartResource  r,
Dictionary< int, ResourcePrioritySet dict 
)
inlineprotected

This will remove a partresource from the given (push/pull) dictionary

Parameters
r
dict
virtual double PartSet.RequestResource ( Part  part,
int  id,
double  demand,
bool  usePri 
)
inlinevirtual

This method replaces the old RequestResource mechanic, and is called by Part.RequestResource.

Parameters
partthe requesting part
idthe resource hash
demandthe demand
usePrido we draw across all tracked parts or do we draw by priority set?
Returns
virtual double PartSet.RequestResource ( Part  part,
int  id,
double  demand,
bool  usePri,
bool  simulate 
)
inlinevirtual

This method replaces the old RequestResource mechanic, and is called by Part.RequestResource.

Parameters
partthe requesting part
idthe resource hash
demandthe demand
usePrido we draw across all tracked parts or do we draw by priority set?
simulatetrue to use the simulation resource set. Otherwise false to use the real resource set.
Returns
bool PartSet.SetsEqual ( HashSet< Part set)
inline

Checks if the set of parts this covers is the same as the passed set

Parameters
set
Returns

< they aren't the same type of set!

< faster than SetsEqual, and no GC

Member Data Documentation

int PartSet._id = 0
static
Dictionary<int, ResourcePrioritySet> PartSet.pullList = new Dictionary<int, ResourcePrioritySet>()
protected
Dictionary<int, ResourcePrioritySet> PartSet.pushList = new Dictionary<int, ResourcePrioritySet>()
protected
int PartSet.setId
Dictionary<HashSet<Part>, PartSet> PartSet.setsHolder = new Dictionary<HashSet<Part>, PartSet>()
staticprotected

Temporary holder for the sets. Used to interact with the flow graph code.

ShipConstruct PartSet.ship
protected

if in editor scene in ShipConstruct mode, the current ship

bool PartSet.simulationSet = false
protected
HashSet<Part> PartSet.targetParts
protected

if in partset mode, the set of parts we care about

Vessel PartSet.vessel
protected

if in vessel mode, the current vessel

bool PartSet.vesselWide
protected

determines what mode this PartResourceSet is in

Property Documentation

bool PartSet.ListsExist
get
int PartSet.NextID
staticget

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