File size: 5,640 Bytes
24b81cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
class NotifierBase
{
	
	float				m_DeltaT; // time in seconds since the last tick
	ref Timer 			m_Timer1; // timer which can be used for whatever
	PlayerBase			m_Player; //the player this Notifier belongs to
	int					m_Type;
	NotifiersManager	m_Manager;
	int 				m_TendencyBufferSize = 3;//for best results, this should be somewhat aligned with modifier frequency
	const int 			TENDENCY_BUFFER_SIZE = 30;//this needs to be bigger or same size as buffer size of any invidual buffer size
	bool				m_ShowTendency;
	bool				m_Active;
	//private float		m_SecsToSound; //internal counter
	//protected float		m_MinPauseBetweenSounds; //minimal amount of seconds that needs to pass till sound is played
	//protected float		m_MaxPauseBetweenSounds; //maximal amount of seconds that can pass till sound is played
	//private float		m_SecsSinceLastAnimation; //internal counter
	//private float		m_SecsToAnimation; //internal counter
	//protected float		m_MinPauseBetweenAnimations; //minimal amount of seconds that needs to pass till animation played
	//protected float		m_MaxPauseBetweenAnimations; //maximal amount of seconds that can pass till animation is splayed
	int					m_TickInterval;
	int					m_TickIntervalLastTick;
	float				m_TendencyBuffer[TENDENCY_BUFFER_SIZE];
	int					m_TendencyBufferWriteIterator;
	float 				m_LastTendency;
	float				m_LastMA;
	bool				m_FirstPass = true;
	//int					m_TendencyID;
	
	PluginPlayerStatus 	m_ModulePlayerStatus;
		
	void NotifierBase(NotifiersManager manager)
	{

		//m_Timer1 = new Timer();
		m_ModulePlayerStatus = PluginPlayerStatus.Cast(GetPlugin(PluginPlayerStatus));
		m_Active = true; 
		m_Manager = manager;
		m_Player = manager.GetPlayer();
		m_TickInterval = 1000;
		manager.RegisterItself(GetNotifierType(), this);
	}

	bool IsTimeToTick(int current_time)
	{
		return ( current_time > m_TickIntervalLastTick + m_TickInterval );
	}
	
	
	VirtualHud GetVirtualHud()
	{
		return m_Player.GetVirtualHud();
	}

	int GetNotifierType()
	{
		return m_Type;
	}

	string GetName()
	{
		return this.ClassName() + " Notifier";
	}

	bool IsActive()
	{
		return m_Active;
	}

	void SetActive( bool state )
	{
		m_Active = state;
		if ( !state ) HideBadge();
	}

	void DisplayTendency(float delta)
	{
	}

	void AddToCyclicBuffer(float value)//for tendency
	{
		m_TendencyBuffer[m_TendencyBufferWriteIterator] = value;
		m_TendencyBufferWriteIterator++;
		if( m_TendencyBufferWriteIterator == m_TendencyBufferSize )
		{
			m_TendencyBufferWriteIterator = 0;
			m_ShowTendency = true;
		}
	}
	
	float ReadFromCyclicBuffer(int index)
	{
		int indx = m_TendencyBufferWriteIterator + index;
		if( indx >= m_TendencyBufferSize)
		{
			indx = indx - m_TendencyBufferSize;
		}
		return m_TendencyBuffer[indx];
	}
	
	float GetDeltaAvaraged()//for tendency
	{
		array<float> values = new array<float>;
		for(int i = 0; i < m_TendencyBufferSize; i++)
		{
			values.Insert(ReadFromCyclicBuffer(i));
		}
		//SmoothOutFloatValues(values);
		
		//--------------------------------------------------------------------------
		
		float values_sum = 0;
		//PrintString("----------------------------");
		//PrintString("tendency:" + this.ClassName() );
		for(i = 0; i < values.Count(); i++)
		{
			float value = values.Get(i);
			values_sum += value;
			//PrintString( value.ToString() );
		}
		
		float sma = values_sum / m_TendencyBufferSize;
		if( m_FirstPass ) 
		{
			m_LastMA = sma;
			m_FirstPass = false;
		}
		
		float tnd = sma - m_LastMA;
		m_LastMA = sma;
		/*
		PrintString(GetName()+" tendency:" + tnd.ToString() );
		PrintString("----------------------------");
		*/
		return tnd;
		
		//--------------------------------------------------------------------------
		
	}
	
	void SmoothOutFloatValues(array<float> values)
	{
		float value1;
		float value2;
		for(int i = 0; i < values.Count() - 1; i++)
		{
			value1 = values.Get(i);
			value2 = values.Get(i + 1);
			float average = (value1 + value2) / 2;
			values.Set(i, average);
			values.Set(i + 1, average);
		}
		int index = values.Count() - 1;
		values.Set(index, value2);
	}

	void OnTick(float current_time)
	{
		//------------
		/*
		float time = GetGame().GetTime();
		Print("ticking notifier "+ this.ClassName() +" for player " + m_Player.ToString() + " at time:" + time.ToString());
		*/
		//------------
		m_TickIntervalLastTick = current_time;
		DisplayBadge();
		AddToCyclicBuffer( GetObservedValue() );
		if (m_ShowTendency) DisplayTendency( GetDeltaAvaraged() );

	}
	
	protected int CalculateTendency(float delta, float inctresholdlow, float inctresholdmed, float inctresholdhigh, float dectresholdlow, float dectresholdmed, float dectresholdhigh)
	{                                        	
		int tendency = TENDENCY_STABLE;
		if ( delta > inctresholdlow ) 	tendency = TENDENCY_INC_LOW;
		if ( delta > inctresholdmed )  	tendency = TENDENCY_INC_MED;
		if ( delta > inctresholdhigh ) 	tendency = TENDENCY_INC_HIGH;	
		if ( delta < dectresholdlow )  	tendency = TENDENCY_DEC_LOW;
		if ( delta < dectresholdmed )  	tendency = TENDENCY_DEC_MED;
		if ( delta < dectresholdhigh ) 	tendency = TENDENCY_DEC_HIGH;
		//Print(" " + delta + " tendency:  " + tendency +" " + this);
		return tendency;
	}
	
	
	protected eBadgeLevel DetermineBadgeLevel(float value, float lvl_1, float lvl_2, float lvl_3)
	{
		eBadgeLevel level = eBadgeLevel.NONE;
		if ( value >= lvl_1 ) 	level = eBadgeLevel.FIRST;
		if ( value >= lvl_2 )  	level = eBadgeLevel.SECOND;
		if ( value >= lvl_3 ) 	level = eBadgeLevel.THIRD;
		return 	level;
	}
	

	protected void DisplayBadge()
	{
	}

	protected void HideBadge()
	{
	}

	protected float GetObservedValue()
	{
		return 0;
	}
}