DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
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;
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
13 //private float m_SecsToSound; //internal counter
14 //protected float m_MinPauseBetweenSounds; //minimal amount of seconds that needs to pass till sound is played
15 //protected float m_MaxPauseBetweenSounds; //maximal amount of seconds that can pass till sound is played
16 //private float m_SecsSinceLastAnimation; //internal counter
17 //private float m_SecsToAnimation; //internal counter
18 //protected float m_MinPauseBetweenAnimations; //minimal amount of seconds that needs to pass till animation played
19 //protected float m_MaxPauseBetweenAnimations; //maximal amount of seconds that can pass till animation is splayed
25 float m_LastMA;
26 bool m_FirstPass = true;
27 //int m_TendencyID;
28
29 PluginPlayerStatus m_ModulePlayerStatus;
30
32 {
33
34 //m_Timer1 = new Timer();
35 m_ModulePlayerStatus = PluginPlayerStatus.Cast(GetPlugin(PluginPlayerStatus));
36 m_Active = true;
37 m_Manager = manager;
38 m_Player = manager.GetPlayer();
39 m_TickInterval = 1000;
40 manager.RegisterItself(GetNotifierType(), this);
41 }
42
43 bool IsTimeToTick(int current_time)
44 {
45 return ( current_time > m_TickIntervalLastTick + m_TickInterval );
46 }
47
48
50 {
51 return m_Player.GetVirtualHud();
52 }
53
55 {
56 return m_Type;
57 }
58
59 string GetName()
60 {
61 return this.ClassName() + " Notifier";
62 }
63
64 bool IsActive()
65 {
66 return m_Active;
67 }
68
69 void SetActive( bool state )
70 {
71 m_Active = state;
72 if ( !state ) HideBadge();
73 }
74
75 void DisplayTendency(float delta)
76 {
77 }
78
79 void AddToCyclicBuffer(float value)//for tendency
80 {
84 {
86 m_ShowTendency = true;
87 }
88 }
89
90 float ReadFromCyclicBuffer(int index)
91 {
92 int indx = m_TendencyBufferWriteIterator + index;
93 if( indx >= m_TendencyBufferSize)
94 {
95 indx = indx - m_TendencyBufferSize;
96 }
97 return m_TendencyBuffer[indx];
98 }
99
100 float GetDeltaAvaraged()//for tendency
101 {
102 array<float> values = new array<float>;
103 for(int i = 0; i < m_TendencyBufferSize; i++)
104 {
105 values.Insert(ReadFromCyclicBuffer(i));
106 }
107 //SmoothOutFloatValues(values);
108
109 //--------------------------------------------------------------------------
110
111 float values_sum = 0;
112 //PrintString("----------------------------");
113 //PrintString("tendency:" + this.ClassName() );
114 for(i = 0; i < values.Count(); i++)
115 {
116 float value = values.Get(i);
117 values_sum += value;
118 //PrintString( value.ToString() );
119 }
120
121 float sma = values_sum / m_TendencyBufferSize;
122 if( m_FirstPass )
123 {
124 m_LastMA = sma;
125 m_FirstPass = false;
126 }
127
128 float tnd = sma - m_LastMA;
129 m_LastMA = sma;
130 /*
131 PrintString(GetName()+" tendency:" + tnd.ToString() );
132 PrintString("----------------------------");
133 */
134 return tnd;
135
136 //--------------------------------------------------------------------------
137
138 }
139
141 {
142 float value1;
143 float value2;
144 for(int i = 0; i < values.Count() - 1; i++)
145 {
146 value1 = values.Get(i);
147 value2 = values.Get(i + 1);
148 float average = (value1 + value2) / 2;
149 values.Set(i, average);
150 values.Set(i + 1, average);
151 }
152 int index = values.Count() - 1;
153 values.Set(index, value2);
154 }
155
156 void OnTick(float current_time)
157 {
158 //------------
159 /*
160 float time = GetGame().GetTime();
161 Print("ticking notifier "+ this.ClassName() +" for player " + m_Player.ToString() + " at time:" + time.ToString());
162 */
163 //------------
164 m_TickIntervalLastTick = current_time;
165 DisplayBadge();
168
169 }
170
171 protected int CalculateTendency(float delta, float inctresholdlow, float inctresholdmed, float inctresholdhigh, float dectresholdlow, float dectresholdmed, float dectresholdhigh)
172 {
173 int tendency = TENDENCY_STABLE;
174 if ( delta > inctresholdlow ) tendency = TENDENCY_INC_LOW;
175 if ( delta > inctresholdmed ) tendency = TENDENCY_INC_MED;
176 if ( delta > inctresholdhigh ) tendency = TENDENCY_INC_HIGH;
177 if ( delta < dectresholdlow ) tendency = TENDENCY_DEC_LOW;
178 if ( delta < dectresholdmed ) tendency = TENDENCY_DEC_MED;
179 if ( delta < dectresholdhigh ) tendency = TENDENCY_DEC_HIGH;
180 //Print(" " + delta + " tendency: " + tendency +" " + this);
181 return tendency;
182 }
183
184
185 protected eBadgeLevel DetermineBadgeLevel(float value, float lvl_1, float lvl_2, float lvl_3)
186 {
187 eBadgeLevel level = eBadgeLevel.NONE;
188 if ( value >= lvl_1 ) level = eBadgeLevel.FIRST;
189 if ( value >= lvl_2 ) level = eBadgeLevel.SECOND;
190 if ( value >= lvl_3 ) level = eBadgeLevel.THIRD;
191 return level;
192 }
193
194
195 protected void DisplayBadge()
196 {
197 }
198
199 protected void HideBadge()
200 {
201 }
202
203 protected float GetObservedValue()
204 {
205 return 0;
206 }
207}
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
void VirtualHud(PlayerBase player)
void NotifiersManager(PlayerBase player)
PluginBase GetPlugin(typename plugin_type)
bool IsTimeToTick(int current_time)
protected float GetObservedValue()
protected int CalculateTendency(float delta, float inctresholdlow, float inctresholdmed, float inctresholdhigh, float dectresholdlow, float dectresholdmed, float dectresholdhigh)
protected void DisplayBadge()
NotifiersManager m_Manager
Definition NotifierBase.c:8
float ReadFromCyclicBuffer(int index)
PlayerBase m_Player
Definition NotifierBase.c:6
void SetActive(bool state)
VirtualHud GetVirtualHud()
float m_LastTendency
void DisplayTendency(float delta)
void NotifierBase(NotifiersManager manager)
void AddToCyclicBuffer(float value)
const int TENDENCY_BUFFER_SIZE
int m_TendencyBufferWriteIterator
ref Timer m_Timer1
Definition NotifierBase.c:5
int m_TendencyBufferSize
Definition NotifierBase.c:9
protected eBadgeLevel DetermineBadgeLevel(float value, float lvl_1, float lvl_2, float lvl_3)
float m_TendencyBuffer[TENDENCY_BUFFER_SIZE]
int GetNotifierType()
string GetName()
bool m_ShowTendency
int m_TickIntervalLastTick
bool IsActive()
void OnTick(float current_time)
void SmoothOutFloatValues(array< float > values)
PluginPlayerStatus m_ModulePlayerStatus
float GetDeltaAvaraged()
protected void HideBadge()
Result for an object found in CGame.IsBoxCollidingGeometryProxy.