evtc\missile/
launch.rs

1use crate::{
2    extract::{transmute_field, Extract},
3    AgentId, Event, Position, StateChange, TryExtract,
4};
5use bitflags::bitflags;
6
7#[cfg(feature = "serde")]
8use serde::{Deserialize, Serialize};
9
10/// Missile created.
11#[derive(Debug, Clone)]
12#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
13pub struct MissileLaunch {
14    /// Time of registering the missile.
15    pub time: u64,
16
17    /// Agent creating the missile.
18    pub source: AgentId,
19
20    /// Target of the missile, if set and in range.
21    pub target: AgentId,
22
23    /// Target location.
24    pub target_location: Position,
25
26    /// Current location.
27    pub current_location: Position,
28
29    /// Associated skill id.
30    pub skill_id: u32,
31
32    /// Missile motion type.
33    pub motion: u8,
34
35    /// Range or radius depending on the missile's motion.
36    pub range: i16,
37
38    /// Missile flags on launch.
39    pub flags: MissileFlags,
40
41    /// Missile speed.
42    pub speed: i16,
43
44    /// Trackable id to identify missile in other events.
45    pub tracking_id: u32,
46}
47
48impl Extract for MissileLaunch {
49    #[inline]
50    unsafe fn extract(event: &Event) -> Self {
51        let [target_x, target_y, target_z, cur_x, cur_y, cur_z] =
52            transmute_field!(event.value as [i16; 6]);
53        let skill_id = event.skill_id;
54
55        let motion = event.affinity;
56        let range = transmute_field!(event.result as i16);
57        let flags = transmute_field!(event.is_buffremove as u32);
58        let speed = transmute_field!(event.is_shields as i16);
59
60        Self {
61            time: event.time,
62            source: AgentId::from_src(event),
63            target: AgentId::from_dst(event),
64            target_location: Position::from_scaled_i16s(target_x, target_y, target_z, 10.0),
65            current_location: Position::from_scaled_i16s(cur_x, cur_y, cur_z, 10.0),
66            skill_id,
67            motion,
68            range,
69            flags: MissileFlags::from_bits_retain(flags),
70            speed,
71            tracking_id: event.get_pad_id(),
72        }
73    }
74}
75
76impl TryExtract for MissileLaunch {
77    #[inline]
78    fn can_extract(event: &Event) -> bool {
79        event.get_statechange() == StateChange::MissileCreate
80    }
81}
82
83bitflags! {
84    /// Missile flags on launch.
85    #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
86    #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
87    pub struct MissileFlags : u32 {
88        const _ = !0;
89    }
90}