Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
dayzplayerimplementaiming.c
Go to the documentation of this file.
1/*
2DayZPlayerImplement
3
4this file is implemenation of dayzPlayer in script
5- logic of movement
6- camera switching logic
7
8*/
9
18
19class PlayerSwayConstants
20{
21 static const float SWAY_MULTIPLIER_DEFAULT = 1.0;
22 static const float SWAY_MULTIPLIER_STABLE = 0.05;
23 static const float SWAY_MULTIPLIER_EXHAUSTED = 0.6;
24 static const float SWAY_TIME_IN = 1.5;
25 static const float SWAY_TIME_STABLE = 3.0;
26 static const float SWAY_TIME_EXHAUSTED = 1.5;
27 static const float SWAY_TIME_OUT = 0.5;
28 static const float SWAY_ROLL = 3;
29 static const float HOLD_BREATH_STAMINA_THRESHOLD = 0.5;
30}
31
33{
34
35 //-------------------------------------------------------------
39
40 protected const float SWAY_WEIGHT_SCALER = 1;//use this to scale the sway effect up/down
41 protected float m_HorizontalNoise;
42 protected float m_HorizontalTargetValue;
43 protected float m_HorizontalNoiseVelocity[1] = {0};
46 protected float m_TotalTime;
47 protected float m_ReferenceTime = 0;
48 protected float m_StaminaPercentage;
49 protected float m_HoldBreathSwayCoef = 1.0;
50 protected float m_SwayStateStartTime;
51 //protected float m_SwayStateStartTime[eSwayStates.MAX];
52 protected float m_LastSwayMultiplier = PlayerSwayConstants.SWAY_MULTIPLIER_DEFAULT;
55 protected float m_BreathingXAxisOffset;
56 protected float m_BreathingYAxisOffset;
57 protected bool m_HoldingBreathSet;
58 protected bool m_AimNoiseAllowed = true;
59 protected bool m_ProceduralRecoilEnabled = true;
61 protected int m_ShakeCount;
62 protected float m_SwayWeight;
63 protected float m_MaxVelocity;
64 protected ref KuruShake m_KuruShake;
65 protected float m_CamShakeX;
66 protected float m_CamShakeY;
67 protected vector m_SwayModifier = "1 1 1";//"max_speed_noise radius_noise overall_speed"
68 protected int m_SwayState = -1;
69
70 protected float m_StealthAimY_Last;
71 protected float m_FilterVelocityStealthAimY[1] = {0};
72
73 protected static float m_AimXClampRanges[] = { -180, -20, 90, 0, -50, 90, 180, -20, 90 };
74
76 {
77 m_PlayerDpi = player;
78 Class.CastTo(m_PlayerPb, player);
80 }
81
83 {
85 {
86 m_CurrentRecoil = weapon.SpawnRecoilObject();
87 }
88 }
89
90 void RequestKuruShake(float amount)
91 {
92 if (!m_KuruShake)
93 m_KuruShake = new KuruShake(m_PlayerPb, amount);
94 }
95
97 {
98 Weapon_Base weapon = Weapon_Base.Cast(player.GetHumanInventory().GetEntityInHands());
99 if (weapon)
100 {
101 m_SwayModifier = weapon.GetPropertyModifierObject().m_SwayModifiers;
102 }
103 }
104
105 void OnFinisherBegin(float currentAimY)
106 {
107 m_StealthAimY_Last = currentAimY;
109 }
110
111 void OnSwayStateChange(int state)
112 {
113 switch (state)
114 {
115 case eSwayStates.HOLDBREATH_EXHAUSTED:
116 m_PlayerPb.OnHoldBreathExhausted();
117 break;
118
119 default:
120 break;
121 }
122 }
123
125 {
126 return m_SwayWeight;
127 }
128
129 void SetAimNoiseAllowed(bool state)
130 {
131 m_AimNoiseAllowed = state;
132 }
133
135 {
136 return m_AimNoiseAllowed;
137 }
138
140 {
142 }
143
148
149 void SetCamShakeValues(float x_axis, float y_axis)
150 {
151 m_CamShakeX = x_axis;
152 m_CamShakeY = y_axis;
153 }
154
155 bool ProcessStealthFilters(float pDt, SDayZPlayerAimingModel pModel)
156 {
158 pModel.m_fAimYMouseShift = -(pModel.m_fCurrentAimY - m_StealthAimY_Last);
159 return true;
160 }
161
162 bool ProcessAimFilters(float pDt, SDayZPlayerAimingModel pModel, int stance_index)
163 {
164 float breathing_offset_x;
165 float breathing_offset_y;
166
167 float noise_offset_x;
168 float noise_offset_y;
169
170 float shake_offset_x;
171 float shake_offset_y;
172
173 float recoil_offset_mouse_x;
174 float recoil_offset_mouse_y;
175
176 float recoil_offset_hands_x;
177 float recoil_offset_hands_y;
178
179 float kuru_offset_x;
180 float kuru_offset_y;
181
182 float player_stamina = m_PlayerPb.GetStaminaHandler().GetSyncedStaminaNormalized();
183
184 #ifdef DEVELOPER
185 DbgPrintAimingImplement("Player: " + m_PlayerPb + " | ProcessAimFilters | timestamp: " + m_PlayerPb.GetSimulationTimeStamp());
186 #endif
187
188 //negates stamina effect during hold breath
189 if (m_PlayerPb.IsHoldingBreath())
190 {
191 player_stamina = 1;
192 }
193 float speed = CalculateSpeedMultiplier(player_stamina);
194 m_TotalTime += pDt * speed;
195
196 if (m_PlayerPb.IsHoldingBreath() && !m_HoldingBreathSet)
197 {
199 m_StaminaPercentage = m_PlayerPb.GetStaminaHandler().GetSyncedStaminaNormalized();
200 m_HoldBreathSwayCoef = Math.InverseLerp(0,PlayerSwayConstants.HOLD_BREATH_STAMINA_THRESHOLD,m_StaminaPercentage);
202 m_HoldBreathSwayCoef = Math.Lerp(PlayerSwayConstants.HOLD_BREATH_STAMINA_THRESHOLD,1,m_HoldBreathSwayCoef);
203 }
204 else if (!m_PlayerPb.IsHoldingBreath() && m_HoldingBreathSet)
205 {
207 }
208
209 float adjusted_sway_multiplier = CalculateSwayMultiplier();
210 m_LastSwayMultiplier = adjusted_sway_multiplier;
211
212 m_SwayWeight = CalculateWeight( stance_index, player_stamina, 0.5/*m_PlayerPb.m_CameraSwayModifier*/, m_PlayerPb.IsHoldingBreath()) * adjusted_sway_multiplier;
213
215 ApplyBreathingPattern(breathing_offset_x, breathing_offset_y, 3.0, m_TotalTime, m_SwayWeight);
216 ApplyHorizontalNoise(noise_offset_x, noise_offset_y, 0.2, 0.5, 3.0 * m_SwayModifier[0], speed, 3 * m_SwayModifier[1], m_SwayWeight, pDt);
217
218 int shake_level = m_PlayerPb.GetShakeLevel();
219 if (shake_level != 0)
220 {
221 ApplyShakes(shake_offset_x, shake_offset_y, shake_level);
222 }
223
225 if (m_CurrentRecoil)
226 {
227 m_CurrentRecoil.Update(pModel, recoil_offset_mouse_x, recoil_offset_mouse_y, recoil_offset_hands_x, recoil_offset_hands_y, pDt);
228 }
229
230 if (m_KuruShake)
231 {
232 m_KuruShake.Update(pDt, kuru_offset_x, kuru_offset_y);
233 }
234
236 pModel.m_fAimXHandsOffset = breathing_offset_x + noise_offset_x + recoil_offset_hands_x + shake_offset_x + kuru_offset_x;
237 pModel.m_fAimYHandsOffset = breathing_offset_y + noise_offset_y + recoil_offset_hands_y + shake_offset_y + kuru_offset_y;
238
239 #ifdef DEVELOPER
240 DbgPrintAimingImplement("breathing_offset_y: " + breathing_offset_y);
241 DbgPrintAimingImplement("noise_offset_y: " + noise_offset_y);
242 DbgPrintAimingImplement("recoil_offset_hands_y: " + recoil_offset_hands_y);
243 DbgPrintAimingImplement("shake_offset_y: " + shake_offset_y);
244 DbgPrintAimingImplement("kuru_offset_y: " + kuru_offset_y);
245 DbgPrintAimingImplement("pModel.m_fAimYHandsOffset: " + pModel.m_fAimYHandsOffset);
246 #endif
248 pModel.m_fAimXCamOffset = -shake_offset_x - recoil_offset_hands_x - kuru_offset_x + m_CamShakeX;
249 pModel.m_fAimYCamOffset = -shake_offset_y - recoil_offset_hands_y - kuru_offset_y + m_CamShakeY;
250
251
252 #ifdef DEVELOPER
253 DbgPrintAimingImplement("m_CamShakeY: " + m_CamShakeY);
254 DbgPrintAimingImplement("pModel.m_fAimYCamOffset: " + pModel.m_fAimYCamOffset);
255 #endif
256
258 if (stance_index == DayZPlayerConstants.STANCEIDX_RAISEDPRONE)
259 {
260 float newVal = DayZPlayerUtils.LinearRangeClamp(pModel.m_fCurrentAimX, pModel.m_fCurrentAimY, m_AimXClampRanges);
261 pModel.m_fAimYHandsOffset += newVal - pModel.m_fCurrentAimY;
262 }
263 float absAimY = Math.AbsFloat(pModel.m_fCurrentAimY);
264 pModel.m_fAimYHandsOffset = Math.Clamp(pModel.m_fAimYHandsOffset,absAimY - 89.9,89.9 - absAimY); //'90' leads to rounding errors down the line
265
266 if (m_PlayerDpi.IsInOptics() && m_KuruShake)
267 {
268 //TODO - do not offset mouse
269 }
271 pModel.m_fAimXMouseShift = recoil_offset_mouse_x -kuru_offset_x / 10;
272 pModel.m_fAimYMouseShift = recoil_offset_mouse_y + kuru_offset_y / 10;
273
274 #ifdef DEVELOPER
275 DbgPrintAimingImplement("recoil_offset_mouse_y: " + recoil_offset_mouse_y);
276 DbgPrintAimingImplement("pModel.m_fAimYMouseShift: " + pModel.m_fAimYMouseShift);
277 #endif
278
279 if (m_PlayerPb.IsHoldingBreath() && !m_HoldingBreathSet)
280 {
281 m_HoldingBreathSet = true;
282 m_HorizontalNoiseXAxisOffset = noise_offset_x;
283 m_BreathingXAxisOffset = breathing_offset_x;
284 m_BreathingYAxisOffset = breathing_offset_y;
285 }
286 else if (!m_PlayerPb.IsHoldingBreath() && m_HoldingBreathSet)
287 {
288 m_HoldingBreathSet = false;
289 }
290
291 if (!m_PlayerPb.IsHoldingBreath() && m_LastSwayMultiplier == PlayerSwayConstants.SWAY_MULTIPLIER_DEFAULT && m_HorizontalNoiseXAxisOffset != 0)
292 {
296 }
297
298 if (m_PlayerPb.IsHoldingBreath())
299 {
300 m_PlayerPb.DepleteStaminaEx(EStaminaModifiers.HOLD_BREATH, pDt * speed, m_HoldBreathSwayCoef);
301 }
302 #ifdef DEVELOPER
303 DbgPrintAimingImplement("----------------------------");
304 #endif
305 return true;
306 }
307
308 protected float CalculateSwayMultiplier()
309 {
310 float max;
311 float time;
312 float time_clamped;
313 float ret;
314
315 if (m_PlayerPb.IsHoldingBreath())
316 {
318
319 if (time < (PlayerSwayConstants.SWAY_TIME_IN * m_HoldBreathSwayCoef))
320 {
321 UpdateSwayState(eSwayStates.HOLDBREATH_IN);
322 max = PlayerSwayConstants.SWAY_TIME_IN * m_HoldBreathSwayCoef;
323 time_clamped = Math.Clamp((m_TotalTime - m_SwayStateStartTime),0,max);
324 ret = Math.Lerp(m_LastSwayMultiplier,PlayerSwayConstants.SWAY_MULTIPLIER_STABLE,time_clamped/max);
325 }
326 else if (time >= (PlayerSwayConstants.SWAY_TIME_IN * m_HoldBreathSwayCoef) && time < (m_HoldBreathSwayCoef * (PlayerSwayConstants.SWAY_TIME_IN + PlayerSwayConstants.SWAY_TIME_STABLE)))
327 {
328 UpdateSwayState(eSwayStates.HOLDBREATH_STABLE);
329 ret = PlayerSwayConstants.SWAY_MULTIPLIER_STABLE;
330 }
331 else
332 {
333 UpdateSwayState(eSwayStates.HOLDBREATH_EXHAUSTED);
334 max = PlayerSwayConstants.SWAY_TIME_EXHAUSTED * m_HoldBreathSwayCoef;
335 time_clamped = Math.Clamp((m_TotalTime - m_SwayStateStartTime),0,max);
336 ret = Math.Lerp(PlayerSwayConstants.SWAY_MULTIPLIER_STABLE,PlayerSwayConstants.SWAY_MULTIPLIER_EXHAUSTED,(time_clamped/max));
337 }
338 }
339 else
340 {
342 max = PlayerSwayConstants.SWAY_TIME_OUT;
343 time_clamped = Math.Clamp((m_TotalTime - m_SwayStateStartTime),0,max);
344 ret = Math.Lerp(m_LastSwayMultiplier,1,time_clamped/max);
345 }
346 return ret;
347 }
348
349 float CalculateSpeedMultiplier(float stamina)
350 {
351 return (((1.0 - stamina) * 3.0) + 1.0) * m_SwayModifier[2]; // just 'm_SwayModifier[2]' for HoldBreath
352 }
353
354 protected bool UpdateSwayState(int state)
355 {
356 if (state != m_SwayState)
357 {
358 m_SwayState = state;
361 OnSwayStateChange(state);
362 return true;
363 }
364
365 return false;
366 }
367
369 {
370 return m_SwayState;
371 }
372
373 protected void ApplyBreathingPattern(out float x_axis, out float y_axis, float pAmplitude, float pTotalTime, float weight)
374 {
375
376 float multiplier = Math.Lerp(PlayerSwayConstants.SWAY_MULTIPLIER_DEFAULT,0,m_LastSwayMultiplier); //TODO revise
377 #ifdef DEVELOPER
378 DbgPrintAimingImplement("m_LastSwayMultiplier: " + m_LastSwayMultiplier);
379 DbgPrintAimingImplement("pAmplitude: " + pAmplitude);
380 DbgPrintAimingImplement("pTotalTime: " + pTotalTime);
381 DbgPrintAimingImplement("weight: " + weight);
382 DbgPrintAimingImplement("multiplier: " + multiplier);
383 #endif
384
385 x_axis = (Math.Sin(pTotalTime) * pAmplitude / 4) * weight;
386 y_axis = (Math.Sin((pTotalTime) * 0.8 + 0.6) * pAmplitude) * weight;
387 #ifdef DEVELOPER
388 DbgPrintAimingImplement("y_axis_midproduct: " + y_axis);
389 #endif
390 x_axis += m_BreathingXAxisOffset * multiplier;
391 y_axis += m_BreathingYAxisOffset * multiplier;
392 }
393
394 protected void ApplyHorizontalNoise(out float x_axis, out float y_axis, float smooth_time,float max_velocity_low, float max_velocity_high, float velocity_modifier, float max_distance, float weight, float pDt)
395 {
396 if (Math.AbsFloat(m_HorizontalTargetValue - m_HorizontalNoise) < 0.01)
397 {
398 //acquire new target
399 m_MaxVelocity = m_PlayerPb.GetRandomGeneratorSyncManager().GetRandomInRange(RandomGeneratorSyncUsage.RGSAimingModel, max_velocity_low, max_velocity_high);
400
401 float r = m_PlayerPb.GetRandomGeneratorSyncManager().GetRandomInRange(RandomGeneratorSyncUsage.RGSAimingModel, 0, 1);
402 m_HorizontalTargetValue = (r - 0.5) * 2 * max_distance;
404 }
405
407 x_axis = m_HorizontalNoise * weight;
408 float multiplier = Math.Lerp(PlayerSwayConstants.SWAY_MULTIPLIER_DEFAULT,0,m_LastSwayMultiplier); //TODO revise
409 x_axis += m_HorizontalNoiseXAxisOffset * multiplier;
410 }
411
412 protected void ApplyShakes(out float x_axis, out float y_axis, int level)
413 {
414 float weight = level / PlayerBase.SHAKE_LEVEL_MAX;
415 m_ShakeCount++;
416 int shakes_threshold = Math.Round(m_PlayerPb.GetRandomGeneratorSyncManager().GetRandomInRange(RandomGeneratorSyncUsage.RGSAimingModel, 2, 4));
417 if (m_ShakeCount > shakes_threshold)
418 {
419 m_ShakeCount = 0;
420
421 float modifier = m_PlayerPb.GetRandomGeneratorSyncManager().GetRandomInRange(RandomGeneratorSyncUsage.RGSAimingModel, 0.45, 0.9);
422 x_axis = modifier * weight * m_PlayerPb.GetRandomGeneratorSyncManager().GetRandomInRange(RandomGeneratorSyncUsage.RGSAimingModel, 0, 1);
423 y_axis = modifier * weight * m_PlayerPb.GetRandomGeneratorSyncManager().GetRandomInRange(RandomGeneratorSyncUsage.RGSAimingModel, 0, 1);
424 }
425 }
426
427 protected float CalculateWeight(int stance_index, float current_stamina, float camera_sway_modifier, bool holding_breath)
428 {
429 if (m_PlayerDpi.GetCommand_Move() && m_PlayerDpi.GetCommand_Move().IsInRoll())//when the player is rolling, set a constant and disregard everything else
430 {
431 return PlayerSwayConstants.SWAY_ROLL;
432 }
433 float stance_modifier;
434 switch (stance_index)
435 {
436 case DayZPlayerConstants.STANCEIDX_RAISEDERECT:
437 stance_modifier = 0.5;
438 break;
439 case DayZPlayerConstants.STANCEIDX_RAISEDCROUCH:
440 stance_modifier = 0.75;
441 break;
442 case DayZPlayerConstants.STANCEIDX_RAISEDPRONE:
443 stance_modifier = 0.925;
444 break;
445 default:
446 stance_modifier = 0.75;
447 //Debug.LogError("stance mask out of definition");
448 break;
449 }
450
451 #ifdef DEVELOPER
452 DbgPrintAimingImplement("current_stamina: " + current_stamina);
453 DbgPrintAimingImplement("camera_sway_modifier: " + camera_sway_modifier);
454 DbgPrintAimingImplement("holding_breath: " + holding_breath);
455 #endif
456
457 return (1 - stance_modifier) * m_AimNoiseAllowed * camera_sway_modifier * SWAY_WEIGHT_SCALER;
458 }
459
460 void DbgPrintAimingImplement(string val)
461 {
462 #ifdef DEVELOPER
463 if (GetDayZGame().IsAimLogEnabled())
464 Print("DayZPlayerImplementAiming | " + val);
465 #endif
466 }
467}
468
Super root of all classes in Enforce script.
Definition enscript.c:11
at which point does the stabilization start to get affected
float m_HoldBreathSwayCoef
stamina percentage at hold breath start
float CalculateWeight(int stance_index, float current_stamina, float camera_sway_modifier, bool holding_breath)
void DayZPlayerImplementAiming(DayZPlayerImplement player)
float CalculateSpeedMultiplier(float stamina)
void SetCamShakeValues(float x_axis, float y_axis)
void ApplyShakes(out float x_axis, out float y_axis, int level)
float m_SwayStateStartTime
proportionally shortens de/stabilization process and duration. Also affects stamina consumption (temp...
void SetRecoil(Weapon_Base weapon)
void ApplyBreathingPattern(out float x_axis, out float y_axis, float pAmplitude, float pTotalTime, float weight)
bool ProcessStealthFilters(float pDt, SDayZPlayerAimingModel pModel)
void OnRaiseBegin(DayZPlayerImplement player)
bool ProcessAimFilters(float pDt, SDayZPlayerAimingModel pModel, int stance_index)
void OnFinisherBegin(float currentAimY)
void ApplyHorizontalNoise(out float x_axis, out float y_axis, float smooth_time, float max_velocity_low, float max_velocity_high, float velocity_modifier, float max_distance, float weight, float pDt)
Definition enmath.c:7
void Update(SDayZPlayerAimingModel pModel, out float axis_mouse_x, out float axis_mouse_y, out float axis_hands_x, out float axis_hands_y, float pDt)
Definition recoilbase.c:68
DayZGame GetDayZGame()
Definition dayzgame.c:3870
DayZPlayerConstants
defined in C++
Definition dayzplayer.c:602
enum eSwayStates SWAY_MULTIPLIER_DEFAULT
EStaminaModifiers
proto void Print(void var)
Prints content of variable to console/log.