Resources#

class Resources#

Represents the collection of resources stored in a vessel, stage or part. Created by calling Vessel::resources(), Stage::resources(), EditorVessel::resources() or Part::resources().

std::vector<Resource> all()#

All the individual resources that can be stored.

Game Scenes:

Flight, Editor Vab, Editor Sph

std::vector<Resource> with_resource(std::string name)#

All the individual resources with the given name that can be stored.

Parameters:

Game Scenes:

Flight, Editor Vab, Editor Sph

std::vector<std::string> names()#

A list of resource names that can be stored.

Game Scenes:

Flight, Editor Vab, Editor Sph

bool has_resource(std::string name)#

Check whether the named resource can be stored.

Parameters:
  • name – The name of the resource.

Game Scenes:

Flight, Editor Vab, Editor Sph

float amount(std::string name)#

Returns the amount of a resource that is currently stored.

Parameters:
  • name – The name of the resource.

Game Scenes:

Flight, Editor Vab, Editor Sph

float max(std::string name)#

Returns the amount of a resource that can be stored.

Parameters:
  • name – The name of the resource.

Game Scenes:

Flight, Editor Vab, Editor Sph

static float density(Client &connection, std::string name)#

Returns the density of a resource, in \(kg/l\).

Parameters:
  • name – The name of the resource.

Game Scenes:

Flight, Editor Vab, Editor Sph

static ResourceFlowMode flow_mode(Client &connection, std::string name)#

Returns the flow mode of a resource.

Parameters:
  • name – The name of the resource.

Game Scenes:

Flight, Editor Vab, Editor Sph

bool enabled()#
void set_enabled(bool value)#

Whether use of all the resources are enabled.

Game Scenes:

Flight, Editor Vab, Editor Sph

Note

This is true if all of the resources are enabled. If any of the resources are not enabled, this is false.

class Resource#

An individual resource stored within a part. Created using methods in the Resources class.

std::string name()#

The name of the resource.

Game Scenes:

Flight, Editor Vab, Editor Sph

Part part()#

The part containing the resource.

Game Scenes:

Flight, Editor Vab, Editor Sph

float amount()#

The amount of the resource that is currently stored in the part.

Game Scenes:

Flight, Editor Vab, Editor Sph

float max()#

The total amount of the resource that can be stored in the part.

Game Scenes:

Flight, Editor Vab, Editor Sph

float density()#

The density of the resource, in \(kg/l\).

Game Scenes:

Flight, Editor Vab, Editor Sph

ResourceFlowMode flow_mode()#

The flow mode of the resource.

Game Scenes:

Flight, Editor Vab, Editor Sph

bool enabled()#
void set_enabled(bool value)#

Whether use of this resource is enabled.

Game Scenes:

Flight, Editor Vab, Editor Sph

class ResourceTransfer#

Transfer resources between parts.

static ResourceTransfer start(Client &connection, Part from_part, Part to_part, std::string resource, float max_amount)#

Start transferring a resource transfer between a pair of parts. The transfer will move at most max_amount units of the resource, depending on how much of the resource is available in the source part and how much storage is available in the destination part. Use ResourceTransfer::complete() to check if the transfer is complete. Use ResourceTransfer::amount() to see how much of the resource has been transferred.

Parameters:
  • from_part – The part to transfer to.

  • to_part – The part to transfer from.

  • resource – The name of the resource to transfer.

  • max_amount – The maximum amount of resource to transfer.

Note

Use ResourceTransfer::cancel() to stop the transfer before it finishes; a canceled transfer is marked as complete. Use ResourceTransfer::remove() to release the memory the server holds for a transfer that is done with. A transfer is stopped and removed if the client that started it disconnects, or if the flight it runs in is left.

void cancel()#

Cancel the transfer. No more of the resource is moved and ResourceTransfer::complete() becomes true.

void remove()#

Remove the transfer, releasing the memory the server holds for it. The transfer is canceled if it has not finished.

Note

Any further use of this object throws an exception. A transfer that is left is held until the parts it runs between are gone, the flight it runs in is left, or the client that started it disconnects, whichever comes first; the first of those may be the rest of the flight away.

float amount()#

The amount of the resource that has been transferred.

bool complete()#

Whether the transfer has completed. Also becomes true if the transfer is canceled by calling ResourceTransfer::cancel().

enum struct ResourceFlowMode#

The way in which a resource flows between parts. See Resources::flow_mode().

enumerator vessel#

The resource flows to any part in the vessel. For example, electric charge.

enumerator stage#

The resource flows from parts in the first stage, followed by the second, and so on. For example, mono-propellant.

enumerator adjacent#

The resource flows between adjacent parts within the vessel. For example, liquid fuel or oxidizer.

enumerator none#

The resource does not flow. For example, solid fuel.