Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
notifierbase.c
Go to the documentation of this file.
2{
3
4 float m_DeltaT; // time in seconds since the last tick
5 ref Timer m_Timer1; // timer which can be used for whatever
6 PlayerBase m_Player; //the player this Notifier belongs to
7 int m_Type;
8 NotifiersManager m_Manager;
9 int m_TendencyBufferSize = 3;//for best results, this should be somewhat aligned with modifier frequency
10 const int TENDENCY_BUFFER_SIZE = 30;//this needs to be bigger or same size as buffer size of any invidual buffer size
11 bool m_ShowTendency;
12 bool m_Active;
13 int m_TickInterval;
14 int m_TickIntervalLastTick;
15 float m_TendencyBuffer[TENDENCY_BUFFER_SIZE];
16 int m_TendencyBufferWriteIterator;
17 float m_LastTendency;
18 float m_LastMA;
19 bool m_FirstPass = true;
20
21 PluginPlayerStatus m_ModulePlayerStatus;
22
23 void NotifierBase(NotifiersManager manager)
24 {
25 m_ModulePlayerStatus = PluginPlayerStatus.Cast(GetPlugin(PluginPlayerStatus));
26 m_Active = true;
27 m_Manager = manager;
28 m_Player = manager.GetPlayer();
29 m_TickInterval = 1000;
30 manager.RegisterItself(GetNotifierType(), this);
31 }
32
33 bool IsTimeToTick(int current_time)
34 {
35 return (current_time > m_TickIntervalLastTick + m_TickInterval);
36 }
37
38 VirtualHud GetVirtualHud()
39 {
40 return m_Player.GetVirtualHud();
41 }
42
43 int GetNotifierType()
44 {
45 return m_Type;
46 }
47
48 string GetName()
49 {
50 return this.ClassName() + " Notifier";
51 }
52
53 bool IsActive()
54 {
55 return m_Active;
56 }
57
58 void SetActive(bool state)
59 {
60 m_Active = state;
61 if (!state)
62 HideBadge();
63
64
65 }
66
67 void DisplayTendency(float delta);
68
69 void AddToCyclicBuffer(float value)//for tendency
70 {
71 m_TendencyBuffer[m_TendencyBufferWriteIterator] = value;
72 m_TendencyBufferWriteIterator++;
73 if (m_TendencyBufferWriteIterator == m_TendencyBufferSize)
74 {
75 m_TendencyBufferWriteIterator = 0;
76 m_ShowTendency = true;
77 }
78 }
79
80 float ReadFromCyclicBuffer(int index)
81 {
82 int indx = m_TendencyBufferWriteIterator + index;
83 if ( indx >= m_TendencyBufferSize)
84 {
85 indx = indx - m_TendencyBufferSize;
86 }
87
88 return m_TendencyBuffer[indx];
89 }
90
91 float GetDeltaAvaraged() //for tendency
92 {
93 array<float> values = new array<float>();
94 for (int i = 0; i < m_TendencyBufferSize; i++)
95 {
96 values.Insert(ReadFromCyclicBuffer(i));
97 }
98
99 float valuesSum = 0;
100
101 for (i = 0; i < values.Count(); i++)
102 {
103 float value = values.Get(i);
104 valuesSum += value;
105 }
106
107 float sma = valuesSum / m_TendencyBufferSize;
108 if (m_FirstPass)
109 {
110 m_LastMA = sma;
111 m_FirstPass = false;
112 }
113
114 float tnd = sma - m_LastMA;
115 m_LastMA = sma;
116
117 return tnd;
118 }
119
120 void SmoothOutFloatValues(array<float> values)
121 {
122 float value1;
123 float value2;
124 for (int i = 0; i < values.Count() - 1; i++)
125 {
126 value1 = values.Get(i);
127 value2 = values.Get(i + 1);
128 float average = (value1 + value2) / 2;
129 values.Set(i, average);
130 values.Set(i + 1, average);
131 }
132
133 int index = values.Count() - 1;
134 values.Set(index, value2);
135 }
136
137 void OnTick(float current_time)
138 {
139 m_TickIntervalLastTick = current_time;
140
141 DisplayBadge();
142 AddToCyclicBuffer(GetObservedValue());
143
144 if (m_ShowTendency)
145 DisplayTendency(GetDeltaAvaraged());
146
147 }
148
149 protected int CalculateTendency(float delta, float inctresholdlow, float inctresholdmed, float inctresholdhigh, float dectresholdlow, float dectresholdmed, float dectresholdhigh)
150 {
151 int tendency = TENDENCY_STABLE;
152 if (delta > inctresholdlow)
153 tendency = TENDENCY_INC_LOW;
154 if (delta > inctresholdmed)
155 tendency = TENDENCY_INC_MED;
156 if (delta > inctresholdhigh)
157 tendency = TENDENCY_INC_HIGH;
158 if (delta < dectresholdlow)
159 tendency = TENDENCY_DEC_LOW;
160 if (delta < dectresholdmed)
161 tendency = TENDENCY_DEC_MED;
162 if (delta < dectresholdhigh)
163 tendency = TENDENCY_DEC_HIGH;
164
165 return tendency;
166 }
167
168
169 protected eBadgeLevel DetermineBadgeLevel(float value, float lvl_1, float lvl_2, float lvl_3)
170 {
171 eBadgeLevel level = eBadgeLevel.NONE;
172 if (value >= lvl_1)
173 level = eBadgeLevel.FIRST;
174 if (value >= lvl_2)
175 level = eBadgeLevel.SECOND;
176 if (value >= lvl_3)
177 level = eBadgeLevel.THIRD;
178
179 return level;
180 }
181
182
183 protected void DisplayBadge();
184 protected void HideBadge();
185
186 protected float GetObservedValue()
187 {
188 return 0.0;
189 }
190}
eBleedingSourceType m_Type
const int TENDENCY_INC_LOW
Definition _constants.c:53
const int TENDENCY_DEC_HIGH
Definition _constants.c:58
const int TENDENCY_DEC_MED
Definition _constants.c:57
const int TENDENCY_INC_MED
Definition _constants.c:54
const int TENDENCY_DEC_LOW
Definition _constants.c:56
const int TENDENCY_INC_HIGH
Definition _constants.c:55
const int TENDENCY_STABLE
Definition _constants.c:52
eBadgeLevel
Definition _constants.c:2
eBadgeLevel DetermineBadgeLevel(float value, float lvl_1, float lvl_2, float lvl_3)
int CalculateTendency(float delta, float inctresholdlow, float inctresholdmed, float inctresholdhigh, float dectresholdlow, float dectresholdmed, float dectresholdhigh)
void HideBadge()
void DisplayBadge()
float GetObservedValue()
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
void VirtualHud(PlayerBase player)
DayZPlayer m_Player
Definition hand_events.c:42
ModifiersManager m_Manager
PluginPlayerStatus m_ModulePlayerStatus
max 32 synced modifiers supported, 0 == no sync
void NotifiersManager(PlayerBase player)
PluginBase GetPlugin(typename plugin_type)
void SetActive()
Definition trapbase.c:414