[−][src]Trait weasel::space::SpaceRules
Rules to govern the space dimension in a game.
This rules are used to determine if an entity can occupy a given position and to keep a model containing all entities' positions.
Associated Types
type Position: Eq + Clone + Debug + Send + Serialize + for<'a> Deserialize<'a>
See Position.
type SpaceSeed: Clone + Debug + Send + Serialize + for<'a> Deserialize<'a>
See SpaceSeed.
type SpaceAlteration: Clone + Debug + Send + Serialize + for<'a> Deserialize<'a>
See SpaceAlteration.
type SpaceModel
See SpaceModel.
Required methods
fn generate_model(&self, seed: &Option<Self::SpaceSeed>) -> Self::SpaceModel
Generates a SpaceModel
starting from a SpaceSeed
.
Provided methods
fn check_move(
&self,
_model: &Self::SpaceModel,
_claim: PositionClaim<'_, R>,
_position: &Self::Position
) -> WeaselResult<(), R>
&self,
_model: &Self::SpaceModel,
_claim: PositionClaim<'_, R>,
_position: &Self::Position
) -> WeaselResult<(), R>
Checks if the given entity can occupy a new position.
The claim tells in which context the entity is trying to acquire the position.
The provided implementation accepts every move.
fn move_entity(
&self,
_model: &mut Self::SpaceModel,
_claim: PositionClaim<'_, R>,
_position: Option<&Self::Position>,
_metrics: &mut WriteMetrics<'_, R>
)
&self,
_model: &mut Self::SpaceModel,
_claim: PositionClaim<'_, R>,
_position: Option<&Self::Position>,
_metrics: &mut WriteMetrics<'_, R>
)
Moves an entity into a new position.
Position's correctness will be validated beforehand with check_move
,
unless it is None
.
An empty position means that the entity is disappearing from the battle.
The claim tells in which context the entity is trying to acquire the position.
The provided implementation does nothing.
fn translate_entity(
&self,
_model: &Self::SpaceModel,
_new_model: &mut Self::SpaceModel,
_entity: &mut dyn Entity<R>,
_event_queue: &mut Option<EventQueue<R>>,
_metrics: &mut WriteMetrics<'_, R>
)
&self,
_model: &Self::SpaceModel,
_new_model: &mut Self::SpaceModel,
_entity: &mut dyn Entity<R>,
_event_queue: &mut Option<EventQueue<R>>,
_metrics: &mut WriteMetrics<'_, R>
)
Translates an entity from one space model to another one.
This method must apply the necessary changes to the entity's position and to the new model so that positions consistency is preserved.
The provided implementation does nothing.
fn alter_space(
&self,
_entities: &Entities<R>,
_rounds: &Rounds<R>,
_model: &mut Self::SpaceModel,
_alteration: &Self::SpaceAlteration,
_event_queue: &mut Option<EventQueue<R>>,
_metrics: &mut WriteMetrics<'_, R>
)
&self,
_entities: &Entities<R>,
_rounds: &Rounds<R>,
_model: &mut Self::SpaceModel,
_alteration: &Self::SpaceAlteration,
_event_queue: &mut Option<EventQueue<R>>,
_metrics: &mut WriteMetrics<'_, R>
)
Changes the current space model, starting from the information contained in alteration
.
Consequences of this change should be applied by registering events inside event_queue
.
The provided implementation does nothing.