Planet

Struct Planet 

Source
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

Source

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 the PlanetAI trait.
  • gen_rules - A vec of BasicResourceType containing the basic resources the planet will be able to generate.
  • comb_rules - A vec of ComplexResourceType containing the complex resources the planet will be able to make.
  • orchestrator_channels - A pair containing the receiver and sender half of the channels OrchestratorToPlanet and PlanetToOrchestrator.
  • explorers_receiver - The receiver half of the ExplorerToPlanet channel where all explorers send messages to this planet (when they’re visiting it).
Source

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.

Source

pub fn id(&self) -> ID

Returns the planet id.

Source

pub fn planet_type(&self) -> PlanetType

Returns the planet type.

Source

pub fn state(&self) -> &PlanetState

Returns an immutable borrow of planet’s internal state.

Source

pub fn generator(&self) -> &Generator

Returns an immutable borrow of the planet generator.

Source

pub fn combinator(&self) -> &Combinator

Returns an immutable borrow of the planet combinator.

Auto Trait Implementations§

§

impl Freeze for Planet

§

impl !RefUnwindSafe for Planet

§

impl Send for Planet

§

impl !Sync for Planet

§

impl Unpin for Planet

§

impl !UnwindSafe for Planet

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.