evtc/
weapon.rs

1//! Bindings & utilities for agent weapon sets.
2
3use crate::{extract::Extract, AgentId, Event, StateChange, TryExtract};
4use num_enum::{FromPrimitive, IntoPrimitive};
5
6#[cfg(feature = "serde")]
7use serde::{Deserialize, Serialize};
8
9#[cfg(feature = "strum")]
10use strum::{Display, EnumCount, EnumIter, IntoStaticStr, VariantNames};
11
12/// Active weapon set changed.
13#[derive(Debug, Clone)]
14#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
15pub struct WeaponSwapEvent {
16    /// Time of registering the weapon swap.
17    pub time: u64,
18
19    /// Agent that swapped weapon sets.
20    pub agent: AgentId,
21
22    /// New weapon set.
23    pub weapon_set: WeaponSet,
24
25    /// Previous weapon set.
26    pub prev_weapon_set: WeaponSet,
27}
28
29impl Extract for WeaponSwapEvent {
30    #[inline]
31    unsafe fn extract(event: &Event) -> Self {
32        Self {
33            time: event.time,
34            agent: AgentId::from_src(event),
35            weapon_set: event.dst_agent.into(),
36            prev_weapon_set: u64::from(event.value.cast_unsigned()).into(),
37        }
38    }
39}
40
41impl TryExtract for WeaponSwapEvent {
42    #[inline]
43    fn can_extract(event: &Event) -> bool {
44        event.get_statechange() == StateChange::WeaponSwap
45    }
46}
47
48/// Agent weapon set.
49///
50/// Typically used with an [`Event`] with [`StateChange::WeaponSwap`].
51#[derive(
52    Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, IntoPrimitive, FromPrimitive,
53)]
54#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
55#[cfg_attr(
56    feature = "strum",
57    derive(Display, EnumCount, EnumIter, IntoStaticStr, VariantNames)
58)]
59#[repr(u64)]
60pub enum WeaponSet {
61    /// First underwater weapon set.
62    Water1 = 0,
63
64    /// Second underwater weapon set.
65    Water2 = 1,
66
67    /// Bundle or kit weapon set.
68    Bundle = 2,
69
70    /// Transform weapon set.
71    Transform = 3,
72
73    /// First land weapon set.
74    Land1 = 4,
75
76    /// Second land weapon set.
77    Land2 = 5,
78
79    /// Unknown.
80    #[num_enum(catch_all)]
81    Unknown(u64),
82}