use serde::{Deserialize, Serialize};
use crate::entity::EntityId;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub enum RiderPhase {
Waiting,
Boarding(EntityId),
Riding(EntityId),
#[serde(alias = "Alighting")]
Exiting(EntityId),
Walking,
Arrived,
Abandoned,
Resident,
}
impl RiderPhase {
#[must_use]
pub const fn is_aboard(&self) -> bool {
matches!(self, Self::Boarding(_) | Self::Riding(_) | Self::Exiting(_))
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub enum RiderPhaseKind {
Waiting,
Boarding,
Riding,
Exiting,
Walking,
Arrived,
Abandoned,
Resident,
}
impl RiderPhase {
#[must_use]
pub const fn kind(&self) -> RiderPhaseKind {
match self {
Self::Waiting => RiderPhaseKind::Waiting,
Self::Boarding(_) => RiderPhaseKind::Boarding,
Self::Riding(_) => RiderPhaseKind::Riding,
Self::Exiting(_) => RiderPhaseKind::Exiting,
Self::Walking => RiderPhaseKind::Walking,
Self::Arrived => RiderPhaseKind::Arrived,
Self::Abandoned => RiderPhaseKind::Abandoned,
Self::Resident => RiderPhaseKind::Resident,
}
}
}
impl std::fmt::Display for RiderPhaseKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Waiting => write!(f, "Waiting"),
Self::Boarding => write!(f, "Boarding"),
Self::Riding => write!(f, "Riding"),
Self::Exiting => write!(f, "Exiting"),
Self::Walking => write!(f, "Walking"),
Self::Arrived => write!(f, "Arrived"),
Self::Abandoned => write!(f, "Abandoned"),
Self::Resident => write!(f, "Resident"),
}
}
}
impl std::fmt::Display for RiderPhase {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Waiting => write!(f, "Waiting"),
Self::Boarding(id) => write!(f, "Boarding({id:?})"),
Self::Riding(id) => write!(f, "Riding({id:?})"),
Self::Exiting(id) => write!(f, "Exiting({id:?})"),
Self::Walking => write!(f, "Walking"),
Self::Arrived => write!(f, "Arrived"),
Self::Abandoned => write!(f, "Abandoned"),
Self::Resident => write!(f, "Resident"),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Rider {
pub(crate) weight: f64,
pub(crate) phase: RiderPhase,
pub(crate) current_stop: Option<EntityId>,
pub(crate) spawn_tick: u64,
pub(crate) board_tick: Option<u64>,
}
impl Rider {
#[must_use]
pub const fn weight(&self) -> f64 {
self.weight
}
#[must_use]
pub const fn phase(&self) -> RiderPhase {
self.phase
}
#[must_use]
pub const fn current_stop(&self) -> Option<EntityId> {
self.current_stop
}
#[must_use]
pub const fn spawn_tick(&self) -> u64 {
self.spawn_tick
}
#[must_use]
pub const fn board_tick(&self) -> Option<u64> {
self.board_tick
}
}