Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
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  //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
20  int m_TickInterval;
21  int m_TickIntervalLastTick;
22  float m_TendencyBuffer[TENDENCY_BUFFER_SIZE];
23  int m_TendencyBufferWriteIterator;
24  float m_LastTendency;
25  float m_LastMA;
26  bool m_FirstPass = true;
27  //int m_TendencyID;
28 
29  PluginPlayerStatus m_ModulePlayerStatus;
30 
31  void NotifierBase(NotifiersManager manager)
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 
49  VirtualHud GetVirtualHud()
50  {
51  return m_Player.GetVirtualHud();
52  }
53 
54  int GetNotifierType()
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  {
81  m_TendencyBuffer[m_TendencyBufferWriteIterator] = value;
82  m_TendencyBufferWriteIterator++;
83  if( m_TendencyBufferWriteIterator == m_TendencyBufferSize )
84  {
85  m_TendencyBufferWriteIterator = 0;
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 
140  void SmoothOutFloatValues(array<float> values)
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();
166  AddToCyclicBuffer( GetObservedValue() );
167  if (m_ShowTendency) DisplayTendency( GetDeltaAvaraged() );
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 }
TENDENCY_INC_LOW
const int TENDENCY_INC_LOW
Definition: _constants.c:53
m_Type
eBleedingSourceType m_Type
Definition: bleedingsource.c:25
m_Manager
ModifiersManager m_Manager
Definition: modifierbase.c:12
eBadgeLevel
eBadgeLevel
Definition: _constants.c:1
VirtualHud
void VirtualHud(PlayerBase player)
Definition: displaystatus.c:36
GetPlugin
PluginBase GetPlugin(typename plugin_type)
Definition: pluginmanager.c:316
NotifiersManager
void NotifiersManager(PlayerBase player)
Definition: notifiersmanager.c:36
PlayerBase
Definition: playerbaseclient.c:1
TENDENCY_INC_MED
const int TENDENCY_INC_MED
Definition: _constants.c:54
m_Player
DayZPlayer m_Player
Definition: hand_events.c:42
TENDENCY_STABLE
const int TENDENCY_STABLE
Definition: _constants.c:52
NotifierBase
Definition: notifierbase.c:1
array< float >
TENDENCY_DEC_MED
const int TENDENCY_DEC_MED
Definition: _constants.c:57
m_ModulePlayerStatus
PluginPlayerStatus m_ModulePlayerStatus
Definition: modifierbase.c:30
TENDENCY_DEC_HIGH
const int TENDENCY_DEC_HIGH
Definition: _constants.c:58
Timer
Definition: dayzplayerimplement.c:62
TENDENCY_INC_HIGH
const int TENDENCY_INC_HIGH
Definition: _constants.c:55
TENDENCY_DEC_LOW
const int TENDENCY_DEC_LOW
Definition: _constants.c:56