evtc\agent/
id.rs

1use crate::event::Event;
2
3#[cfg(feature = "serde")]
4use serde::{Deserialize, Serialize};
5
6/// Ids for an agent.
7#[derive(Debug, Clone)]
8#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9pub struct AgentId {
10    /// Agent id as assigned by Arc.
11    pub id: u64,
12
13    /// Instance id of the agent as appears in game at time of event.
14    pub instance_id: u16,
15
16    /// If agent has a master (e.g. is minion), will be equal to instance id of master, zero otherwise.
17    pub master_instance_id: u16,
18}
19
20impl AgentId {
21    /// Creates new agent id information.
22    #[inline]
23    pub const fn new(id: u64, instance_id: u16, master_instance_id: u16) -> Self {
24        Self {
25            id,
26            instance_id,
27            master_instance_id,
28        }
29    }
30
31    /// Creates new agent id information without a master.
32    #[inline]
33    pub const fn without_master(id: u64, instance_id: u16) -> Self {
34        Self::new(id, instance_id, 0)
35    }
36
37    /// Creates new agent id information from the [`Event`] source agent.
38    #[inline]
39    pub const fn from_src(event: &Event) -> Self {
40        Self::new(
41            event.src_agent,
42            event.src_instance_id,
43            event.src_master_instance_id,
44        )
45    }
46
47    /// Creates new agent id information from the [`Event`] destination agent.
48    #[inline]
49    pub const fn from_dst(event: &Event) -> Self {
50        Self::new(
51            event.dst_agent,
52            event.dst_instance_id,
53            event.dst_master_instance_id,
54        )
55    }
56
57    /// Returns whether the agent has a master.
58    #[inline]
59    pub const fn has_master(&self) -> bool {
60        self.master_instance_id != 0
61    }
62}