pub struct Generator { /* private fields */ }Expand description
Manages the recipes and production of basic resources for a planet.
The Generator is responsible for storing the allowed recipes for BasicResources
and validating creation requests.
Unlike the Combinator, the Generator creates resources “from scratch” (using only energy).
To create a basic resource, the generator:
- Checks if the requested resource type is in its set of allowed recipes.
- Discharges the provided
EnergyCellto power the generation process.
Each planet instance has its own Generator initialized with a specific set of rules.
Implementations§
Source§impl Generator
impl Generator
Sourcepub fn contains(&self, basic: BasicResourceType) -> bool
pub fn contains(&self, basic: BasicResourceType) -> bool
Returns true if the Generator contains a recipe for the specified
BasicResourceType.
Sourcepub fn all_available_recipes(&self) -> HashSet<BasicResourceType>
pub fn all_available_recipes(&self) -> HashSet<BasicResourceType>
Returns a HashSet of all the recipes available in the Generator.
Source§impl Generator
impl Generator
Sourcepub fn make_oxygen(
&self,
energy_cell: &mut EnergyCell,
) -> Result<Oxygen, String>
pub fn make_oxygen( &self, energy_cell: &mut EnergyCell, ) -> Result<Oxygen, String>
Creates a new [<$basic>] resource.
This method attempts to create a new instance of the corresponding basic
resource by discharging an EnergyCell.
§Arguments
energy_cell- A mutable reference to anEnergyCellwhich will be discharged to create the resource.
§Returns
A Result indicating success:
Ok([<$basic>]): The resource was successfully created.
§Errors
Returns an error if there is no recipe for this resource or if the energy_cell is not charged.
Sourcepub fn make_hydrogen(
&self,
energy_cell: &mut EnergyCell,
) -> Result<Hydrogen, String>
pub fn make_hydrogen( &self, energy_cell: &mut EnergyCell, ) -> Result<Hydrogen, String>
Creates a new [<$basic>] resource.
This method attempts to create a new instance of the corresponding basic
resource by discharging an EnergyCell.
§Arguments
energy_cell- A mutable reference to anEnergyCellwhich will be discharged to create the resource.
§Returns
A Result indicating success:
Ok([<$basic>]): The resource was successfully created.
§Errors
Returns an error if there is no recipe for this resource or if the energy_cell is not charged.
Sourcepub fn make_carbon(
&self,
energy_cell: &mut EnergyCell,
) -> Result<Carbon, String>
pub fn make_carbon( &self, energy_cell: &mut EnergyCell, ) -> Result<Carbon, String>
Creates a new [<$basic>] resource.
This method attempts to create a new instance of the corresponding basic
resource by discharging an EnergyCell.
§Arguments
energy_cell- A mutable reference to anEnergyCellwhich will be discharged to create the resource.
§Returns
A Result indicating success:
Ok([<$basic>]): The resource was successfully created.
§Errors
Returns an error if there is no recipe for this resource or if the energy_cell is not charged.
Sourcepub fn make_silicon(
&self,
energy_cell: &mut EnergyCell,
) -> Result<Silicon, String>
pub fn make_silicon( &self, energy_cell: &mut EnergyCell, ) -> Result<Silicon, String>
Creates a new [<$basic>] resource.
This method attempts to create a new instance of the corresponding basic
resource by discharging an EnergyCell.
§Arguments
energy_cell- A mutable reference to anEnergyCellwhich will be discharged to create the resource.
§Returns
A Result indicating success:
Ok([<$basic>]): The resource was successfully created.
§Errors
Returns an error if there is no recipe for this resource or if the energy_cell is not charged.
Sourcepub fn try_make(
&self,
req: BasicResourceType,
energy_cell: &mut EnergyCell,
) -> Result<BasicResource, String>
pub fn try_make( &self, req: BasicResourceType, energy_cell: &mut EnergyCell, ) -> Result<BasicResource, String>
Attempts to create a basic resource of the specified type.
This method provides a generic way to request the creation of any basic resource that the generator has a recipe for.
§Arguments
req- TheBasicResourceTypeenum variant representing the desired resource.energy_cell- A mutable reference to anEnergyCellto be used for discharging during resource creation.
§Returns
A Result indicating success:
Ok(BasicResource): The requested resource was successfully created and wrapped in theBasicResourceenum.
§Errors
Returns an error if the energy_cell is not charged or if there is no recipe
for the requested resource type.