1use 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#[derive(Debug, Clone)]
14#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
15pub struct WeaponSwapEvent {
16 pub time: u64,
18
19 pub agent: AgentId,
21
22 pub weapon_set: WeaponSet,
24
25 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#[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 Water1 = 0,
63
64 Water2 = 1,
66
67 Bundle = 2,
69
70 Transform = 3,
72
73 Land1 = 4,
75
76 Land2 = 5,
78
79 #[num_enum(catch_all)]
81 Unknown(u64),
82}