pub struct Combinator { /* private fields */ }Expand description
Manages the recipes and production of complex resources for a planet.
The Combinator is responsible for storing the allowed recipes for ComplexResources
and validating creation requests.
It works in conjunction with an EnergyCell. To create a complex resource,
the combinator:
- Checks if the requested resource type is in its set of allowed recipes.
- Consumes the required input resources.
- Discharges the provided
EnergyCellto power the combination process.
Each planet instance has its own Combinator initialized with a specific set of rules.
Implementations§
Source§impl Combinator
impl Combinator
Sourcepub fn new() -> Combinator
pub fn new() -> Combinator
Creates a new Combinator with no recipes.
Sourcepub fn contains(&self, complex: ComplexResourceType) -> bool
pub fn contains(&self, complex: ComplexResourceType) -> bool
Returns true if the Combinator contains a recipe for the specified
ComplexResourceType.
Sourcepub fn all_available_recipes(&self) -> HashSet<ComplexResourceType>
pub fn all_available_recipes(&self) -> HashSet<ComplexResourceType>
Returns a HashSet of all the recipes available in the Combinator.
Source§impl Combinator
impl Combinator
Sourcepub fn make_water(
&self,
r1: Hydrogen,
r2: Oxygen,
energy_cell: &mut EnergyCell,
) -> Result<Water, (String, Hydrogen, Oxygen)>
pub fn make_water( &self, r1: Hydrogen, r2: Oxygen, energy_cell: &mut EnergyCell, ) -> Result<Water, (String, Hydrogen, Oxygen)>
Creates a new [<$result>] resource.
This method attempts to create a new instance of the corresponding
complex resource by combining two input resources (r1 and r2) and
discharging an EnergyCell.
§Arguments
r1- The first input resource ([$lhs]).r2- The second input resource ([$rhs]).energy_cell- A mutable reference to anEnergyCellwhich will be discharged to create the resource.
§Returns
A Result indicating success:
Ok([<$result>]): The complex resource was successfully created.
§Errors
Returns an error if there is no recipe for this resource, if the energy_cell is not charged, or if the energy discharge fails. The input resources are returned in the error tuple to prevent ownership loss.
Sourcepub fn make_diamond(
&self,
r1: Carbon,
r2: Carbon,
energy_cell: &mut EnergyCell,
) -> Result<Diamond, (String, Carbon, Carbon)>
pub fn make_diamond( &self, r1: Carbon, r2: Carbon, energy_cell: &mut EnergyCell, ) -> Result<Diamond, (String, Carbon, Carbon)>
Creates a new [<$result>] resource.
This method attempts to create a new instance of the corresponding
complex resource by combining two input resources (r1 and r2) and
discharging an EnergyCell.
§Arguments
r1- The first input resource ([$lhs]).r2- The second input resource ([$rhs]).energy_cell- A mutable reference to anEnergyCellwhich will be discharged to create the resource.
§Returns
A Result indicating success:
Ok([<$result>]): The complex resource was successfully created.
§Errors
Returns an error if there is no recipe for this resource, if the energy_cell is not charged, or if the energy discharge fails. The input resources are returned in the error tuple to prevent ownership loss.
Sourcepub fn make_life(
&self,
r1: Water,
r2: Carbon,
energy_cell: &mut EnergyCell,
) -> Result<Life, (String, Water, Carbon)>
pub fn make_life( &self, r1: Water, r2: Carbon, energy_cell: &mut EnergyCell, ) -> Result<Life, (String, Water, Carbon)>
Creates a new [<$result>] resource.
This method attempts to create a new instance of the corresponding
complex resource by combining two input resources (r1 and r2) and
discharging an EnergyCell.
§Arguments
r1- The first input resource ([$lhs]).r2- The second input resource ([$rhs]).energy_cell- A mutable reference to anEnergyCellwhich will be discharged to create the resource.
§Returns
A Result indicating success:
Ok([<$result>]): The complex resource was successfully created.
§Errors
Returns an error if there is no recipe for this resource, if the energy_cell is not charged, or if the energy discharge fails. The input resources are returned in the error tuple to prevent ownership loss.
Sourcepub fn make_robot(
&self,
r1: Silicon,
r2: Life,
energy_cell: &mut EnergyCell,
) -> Result<Robot, (String, Silicon, Life)>
pub fn make_robot( &self, r1: Silicon, r2: Life, energy_cell: &mut EnergyCell, ) -> Result<Robot, (String, Silicon, Life)>
Creates a new [<$result>] resource.
This method attempts to create a new instance of the corresponding
complex resource by combining two input resources (r1 and r2) and
discharging an EnergyCell.
§Arguments
r1- The first input resource ([$lhs]).r2- The second input resource ([$rhs]).energy_cell- A mutable reference to anEnergyCellwhich will be discharged to create the resource.
§Returns
A Result indicating success:
Ok([<$result>]): The complex resource was successfully created.
§Errors
Returns an error if there is no recipe for this resource, if the energy_cell is not charged, or if the energy discharge fails. The input resources are returned in the error tuple to prevent ownership loss.
Sourcepub fn make_dolphin(
&self,
r1: Water,
r2: Life,
energy_cell: &mut EnergyCell,
) -> Result<Dolphin, (String, Water, Life)>
pub fn make_dolphin( &self, r1: Water, r2: Life, energy_cell: &mut EnergyCell, ) -> Result<Dolphin, (String, Water, Life)>
Creates a new [<$result>] resource.
This method attempts to create a new instance of the corresponding
complex resource by combining two input resources (r1 and r2) and
discharging an EnergyCell.
§Arguments
r1- The first input resource ([$lhs]).r2- The second input resource ([$rhs]).energy_cell- A mutable reference to anEnergyCellwhich will be discharged to create the resource.
§Returns
A Result indicating success:
Ok([<$result>]): The complex resource was successfully created.
§Errors
Returns an error if there is no recipe for this resource, if the energy_cell is not charged, or if the energy discharge fails. The input resources are returned in the error tuple to prevent ownership loss.
Sourcepub fn make_aipartner(
&self,
r1: Robot,
r2: Diamond,
energy_cell: &mut EnergyCell,
) -> Result<AIPartner, (String, Robot, Diamond)>
pub fn make_aipartner( &self, r1: Robot, r2: Diamond, energy_cell: &mut EnergyCell, ) -> Result<AIPartner, (String, Robot, Diamond)>
Creates a new [<$result>] resource.
This method attempts to create a new instance of the corresponding
complex resource by combining two input resources (r1 and r2) and
discharging an EnergyCell.
§Arguments
r1- The first input resource ([$lhs]).r2- The second input resource ([$rhs]).energy_cell- A mutable reference to anEnergyCellwhich will be discharged to create the resource.
§Returns
A Result indicating success:
Ok([<$result>]): The complex resource was successfully created.
§Errors
Returns an error if there is no recipe for this resource, if the energy_cell is not charged, or if the energy discharge fails. The input resources are returned in the error tuple to prevent ownership loss.
Sourcepub fn try_make(
&self,
req: ComplexResourceRequest,
energy_cell: &mut EnergyCell,
) -> Result<ComplexResource, (String, GenericResource, GenericResource)>
pub fn try_make( &self, req: ComplexResourceRequest, energy_cell: &mut EnergyCell, ) -> Result<ComplexResource, (String, GenericResource, GenericResource)>
Attempts to create a complex resource based on a given request.
This method provides a generic way to request the creation of any complex resource that the combinator has a recipe for.
§Arguments
req- TheComplexResourceRequestenum variant representing the desired complex resource and its required input resources.energy_cell- A mutable reference to anEnergyCellwhich will be discharged during resource creation.
§Returns
A Result indicating success:
Ok(ComplexResource): The complex resource was successfully created.
§Errors
Returns an error if there is no recipe for the requested complex resource or if the energy cell discharge fails. The input resources are returned in the error tuple to prevent ownership loss on failure.