1- use crate :: heatmap_analyser:: { Class , Death , PlayerEntity , Team } ;
1+ use crate :: heatmap_analyser:: { Death , PlayerEntity , Team , PlayerState } ;
22use enum_dispatch:: enum_dispatch;
3+ use std:: fmt:: Display ;
34use tf_demo_parser:: demo:: vector:: Vector ;
45
56#[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
@@ -12,13 +13,91 @@ pub enum OrderedOperator {
1213 SmallerOrEqual ,
1314}
1415
16+ impl OrderedOperator {
17+ pub const ALL : [ OrderedOperator ; 6 ] = [
18+ OrderedOperator :: Equal ,
19+ OrderedOperator :: NotEqual ,
20+ OrderedOperator :: Greater ,
21+ OrderedOperator :: Smaller ,
22+ OrderedOperator :: GreaterOrEqual ,
23+ OrderedOperator :: SmallerOrEqual ,
24+ ] ;
25+ }
26+
27+ impl Default for OrderedOperator {
28+ fn default ( ) -> Self {
29+ OrderedOperator :: Equal
30+ }
31+ }
32+
33+ impl Display for OrderedOperator {
34+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
35+ match self {
36+ OrderedOperator :: Equal => write ! ( f, "=" ) ,
37+ OrderedOperator :: NotEqual => write ! ( f, "≠" ) ,
38+ OrderedOperator :: Greater => write ! ( f, ">" ) ,
39+ OrderedOperator :: Smaller => write ! ( f, "<" ) ,
40+ OrderedOperator :: GreaterOrEqual => write ! ( f, "≥" ) ,
41+ OrderedOperator :: SmallerOrEqual => write ! ( f, "≤" ) ,
42+ }
43+ }
44+ }
45+
1546#[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
16- pub enum UnorderedOperator {
17- Is ,
18- IsNot ,
47+ pub enum PropertyOperator {
48+ IsPresent ,
49+ IsNotPresent ,
50+ }
51+
52+ impl PropertyOperator {
53+ pub const ALL : [ PropertyOperator ; 2 ] = [ PropertyOperator :: IsPresent , PropertyOperator :: IsNotPresent ] ;
54+ }
55+
56+ impl Default for PropertyOperator {
57+ fn default ( ) -> Self {
58+ PropertyOperator :: IsPresent
59+ }
60+ }
61+
62+ impl Display for PropertyOperator {
63+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
64+ match self {
65+ PropertyOperator :: IsPresent => write ! ( f, "present" ) ,
66+ PropertyOperator :: IsNotPresent => write ! ( f, "not present" ) ,
67+ }
68+ }
69+ }
70+
71+ #[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
72+ pub enum Property {
73+ Suicide ,
74+ Posthumous ,
75+ }
76+
77+ impl Property {
78+ pub const ALL : [ Property ; 2 ] = [
79+ Property :: Suicide ,
80+ Property :: Posthumous ,
81+ ] ;
82+ }
83+
84+ impl Default for Property {
85+ fn default ( ) -> Self {
86+ Property :: Suicide
87+ }
88+ }
89+
90+ impl Display for Property {
91+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
92+ match self {
93+ Property :: Suicide => write ! ( f, "Suicide" ) ,
94+ Property :: Posthumous => write ! ( f, "Posthumous" ) ,
95+ }
96+ }
1997}
2098
2199#[ enum_dispatch]
100+ #[ derive( Debug ) ]
22101pub enum Filter {
23102 KillerTeamFilter ,
24103 VictimTeamFilter ,
@@ -28,73 +107,72 @@ pub enum Filter {
28107 VictimElevationFilter ,
29108 Distance2DFilter ,
30109 Distance3DFilter ,
110+ RoundFilter ,
111+ PropertyFilter ,
31112}
32113
33114#[ enum_dispatch( Filter ) ]
34115pub trait FilterTrait {
35116 fn apply ( & self , death : & Death ) -> bool ;
36117}
37118
119+ #[ derive( Debug ) ]
38120pub struct KillerTeamFilter {
39- pub op : UnorderedOperator ,
40121 pub team : Team ,
41122}
42123
43124impl FilterTrait for KillerTeamFilter {
44125 fn apply ( & self , death : & Death ) -> bool {
45- match ( & death. killer_entity_state , self . op ) {
46- ( Some ( PlayerEntity { team, .. } ) , UnorderedOperator :: Is ) => * team == self . team ,
47- ( Some ( PlayerEntity { team, .. } ) , UnorderedOperator :: IsNot ) => * team != self . team ,
48- ( None , _) => false ,
126+ match & death. killer_entity_state {
127+ Some ( PlayerEntity { team, .. } ) => * team == self . team ,
128+ None => false ,
49129 }
50130 }
51131}
52132
133+ #[ derive( Debug ) ]
53134pub struct VictimTeamFilter {
54- pub op : UnorderedOperator ,
55135 pub team : Team ,
56136}
57137
58138impl FilterTrait for VictimTeamFilter {
59139 fn apply ( & self , death : & Death ) -> bool {
60- match ( & death. victim_entity_state , self . op ) {
61- ( Some ( PlayerEntity { team, .. } ) , UnorderedOperator :: Is ) => * team == self . team ,
62- ( Some ( PlayerEntity { team, .. } ) , UnorderedOperator :: IsNot ) => * team != self . team ,
63- ( None , _) => false ,
140+ match & death. victim_entity_state {
141+ Some ( PlayerEntity { team, .. } ) => * team == self . team ,
142+ None => false ,
64143 }
65144 }
66145}
67146
147+ #[ derive( Debug ) ]
68148pub struct KillerClassFilter {
69- pub op : UnorderedOperator ,
70- pub class : Class ,
149+ pub classes : [ bool ; 10 ] ,
71150}
72151
73152impl FilterTrait for KillerClassFilter {
74153 fn apply ( & self , death : & Death ) -> bool {
75- match ( & death. killer_entity_state , self . op ) {
76- ( Some ( PlayerEntity { class, .. } ) , UnorderedOperator :: Is ) => * class == self . class ,
77- ( Some ( PlayerEntity { class, .. } ) , UnorderedOperator :: IsNot ) => * class != self . class ,
78- ( None , _) => false ,
154+ match & death. killer_entity_state {
155+ Some ( PlayerEntity { class, .. } ) => self . classes [ * class as usize ] ,
156+ None => false ,
79157 }
80158 }
81159}
82160
161+ #[ derive( Debug ) ]
83162pub struct VictimClassFilter {
84- pub op : UnorderedOperator ,
85- pub class : Class ,
163+ pub classes : [ bool ; 10 ] ,
86164}
87165
88166impl FilterTrait for VictimClassFilter {
89167 fn apply ( & self , death : & Death ) -> bool {
90- match ( & death. victim_entity_state , self . op ) {
91- ( Some ( PlayerEntity { class, .. } ) , UnorderedOperator :: Is ) => * class == self . class ,
92- ( Some ( PlayerEntity { class, .. } ) , UnorderedOperator :: IsNot ) => * class != self . class ,
93- ( None , _) => false ,
168+ match & death. victim_entity_state {
169+ Some ( PlayerEntity { class, .. } ) => self . classes [ * class as usize ] ,
170+ None => false ,
94171 }
95172 }
96173}
97174
175+ #[ derive( Debug ) ]
98176pub struct KillerElevationFilter {
99177 pub op : OrderedOperator ,
100178 pub z : f32 ,
@@ -114,6 +192,7 @@ impl FilterTrait for KillerElevationFilter {
114192 }
115193}
116194
195+ #[ derive( Debug ) ]
117196pub struct VictimElevationFilter {
118197 pub op : OrderedOperator ,
119198 pub z : f32 ,
@@ -133,6 +212,7 @@ impl FilterTrait for VictimElevationFilter {
133212 }
134213}
135214
215+ #[ derive( Debug ) ]
136216pub struct Distance2DFilter {
137217 pub op : OrderedOperator ,
138218 pub distance : f32 ,
@@ -158,6 +238,7 @@ impl FilterTrait for Distance2DFilter {
158238 }
159239}
160240
241+ #[ derive( Debug ) ]
161242pub struct Distance3DFilter {
162243 pub op : OrderedOperator ,
163244 pub distance : f32 ,
@@ -183,3 +264,44 @@ impl FilterTrait for Distance3DFilter {
183264 }
184265 }
185266}
267+
268+ #[ derive( Debug ) ]
269+ pub struct RoundFilter {
270+ pub op : OrderedOperator ,
271+ pub round : u32 ,
272+ }
273+
274+ impl FilterTrait for RoundFilter {
275+ fn apply ( & self , death : & Death ) -> bool {
276+ match self . op {
277+ OrderedOperator :: Equal => death. round == self . round ,
278+ OrderedOperator :: NotEqual => death. round != self . round ,
279+ OrderedOperator :: Greater => death. round > self . round ,
280+ OrderedOperator :: Smaller => death. round < self . round ,
281+ OrderedOperator :: GreaterOrEqual => death. round >= self . round ,
282+ OrderedOperator :: SmallerOrEqual => death. round <= self . round ,
283+ }
284+ }
285+ }
286+
287+ #[ derive( Debug ) ]
288+ pub struct PropertyFilter {
289+ pub op : PropertyOperator ,
290+ pub property : Property ,
291+ }
292+
293+ impl FilterTrait for PropertyFilter {
294+ fn apply ( & self , death : & Death ) -> bool {
295+ let ret = match self . property {
296+ Property :: Suicide => death. killer == death. victim ,
297+ Property :: Posthumous => match death. killer_entity_state {
298+ Some ( PlayerEntity { state : PlayerState :: Alive , .. } ) => false ,
299+ _ => true
300+ }
301+ } ;
302+ match self . op {
303+ PropertyOperator :: IsPresent => ret,
304+ PropertyOperator :: IsNotPresent => !ret,
305+ }
306+ }
307+ }
0 commit comments