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#[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 Player,
21
22 Npc(u16),
26
27 Gadget(u16),
31}
32
33impl AgentKind {
34 #[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}