pub struct Planet {
pub ai: Box<dyn PlanetAI>,
/* private fields */
}Expand description
Main, top-level planet definition. This type is built on top of
PlanetState, PlanetType and PlanetAI, through composition.
It needs to be constructed by each group as it represents the actual planet and contains the base logic that runs the AI. Also, this is what should be returned to the orchestrator.
See module-level docs for more general info.
Fields§
§ai: Box<dyn PlanetAI>Implementations§
Source§impl Planet
impl Planet
Sourcepub fn new(
id: ID,
type_: PlanetType,
ai: Box<dyn PlanetAI>,
gen_rules: Vec<BasicResourceType>,
comb_rules: Vec<ComplexResourceType>,
orchestrator_channels: (Receiver<OrchestratorToPlanet>, Sender<PlanetToOrchestrator>),
explorers_receiver: Receiver<ExplorerToPlanet>,
) -> Result<Planet, String>
pub fn new( id: ID, type_: PlanetType, ai: Box<dyn PlanetAI>, gen_rules: Vec<BasicResourceType>, comb_rules: Vec<ComplexResourceType>, orchestrator_channels: (Receiver<OrchestratorToPlanet>, Sender<PlanetToOrchestrator>), explorers_receiver: Receiver<ExplorerToPlanet>, ) -> Result<Planet, String>
Constructor for the Planet type.
§Errors
Returns an error if the construction parameters are invalid (they violate the planet_type constraints).
§Arguments
id- The identifier to assign to the planet.planet_type- Type of the planet. Constraints the rules of the planet.ai- A group-defined struct implementing thePlanetAItrait.gen_rules- A vec ofBasicResourceTypecontaining the basic resources the planet will be able to generate.comb_rules- A vec ofComplexResourceTypecontaining the complex resources the planet will be able to make.orchestrator_channels- A pair containing the receiver and sender half of the channelsOrchestratorToPlanetandPlanetToOrchestrator.explorers_receiver- The receiver half of theExplorerToPlanetchannel where all explorers send messages to this planet (when they’re visiting it).
Sourcepub fn run(&mut self) -> Result<(), String>
pub fn run(&mut self) -> Result<(), String>
Starts the planet in a stopped state, waiting for a OrchestratorToPlanet::StartPlanetAI message,
then invokes PlanetAI::on_start and runs the main message polling loop.
See PlanetAI docs to know more about when message handlers are invoked and how the planet reacts
to the different messages.
This method is blocking and should be called by the orchestrator in a separate thread. It returns with an empty Ok when the planet has been killed (destroyed).
§Errors
If the orchestrator disconnects from the channel, this will return an Err.
Sourcepub fn planet_type(&self) -> PlanetType
pub fn planet_type(&self) -> PlanetType
Returns the planet type.
Sourcepub fn state(&self) -> &PlanetState
pub fn state(&self) -> &PlanetState
Returns an immutable borrow of planet’s internal state.
Sourcepub fn combinator(&self) -> &Combinator
pub fn combinator(&self) -> &Combinator
Returns an immutable borrow of the planet combinator.