evtc\agent/
agent_kind.rs

1use std::mem::transmute;
2
3#[cfg(feature = "serde")]
4use serde::{Deserialize, Serialize};
5
6#[cfg(feature = "strum")]
7use strum::{Display, EnumCount, EnumIter, IntoStaticStr, VariantNames};
8
9/// Possible agent kinds.
10#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
11#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
12#[cfg_attr(
13    feature = "strum",
14    derive(Display, EnumCount, EnumIter, IntoStaticStr, VariantNames)
15)]
16pub enum AgentKind {
17    /// Agent is a player.
18    ///
19    /// `prof` is the Profession and `elite` the Elite-Specialization.
20    Player,
21
22    /// Agent is an NPC.
23    ///
24    /// The included id is the (reliable) species id.
25    Npc(u16),
26
27    /// Agent is a gadget.
28    ///
29    /// The included id is a volatile pseudo id.
30    Gadget(u16),
31}
32
33impl AgentKind {
34    /// Determines the kind of agent for the given profession and elite.
35    #[inline]
36    pub const fn new(prof: u32, elite: u32) -> Self {
37        if elite == u32::MAX {
38            let (lower, upper): (u16, u16) = unsafe { transmute(prof) };
39            if upper == u16::MAX {
40                AgentKind::Gadget(lower)
41            } else {
42                AgentKind::Npc(lower)
43            }
44        } else {
45            AgentKind::Player
46        }
47    }
48}
49
50impl From<(u32, u32)> for AgentKind {
51    #[inline]
52    fn from((prof, elite): (u32, u32)) -> Self {
53        Self::new(prof, elite)
54    }
55}