DayZ 1.24
Loading...
Searching...
No Matches
DayZPlayerImplementAiming.c
Go to the documentation of this file.
1/*
2 DayZPlayerImplement
3
4 this file is implemenation of dayzPlayer in script
5 - logic of movement
6 - camera switching logic
7
8*/
9
18
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}
30
32{
33
34 //-------------------------------------------------------------
38
39 protected const float SWAY_WEIGHT_SCALER = 1;//use this to scale the sway effect up/down
40 protected float m_HorizontalNoise;
41 protected float m_HorizontalTargetValue;
42 protected float m_HorizontalNoiseVelocity[1] = {0};
45 protected float m_TotalTime;
46 protected float m_ReferenceTime = 0;
47 protected float m_SwayStateStartTime;
48 //protected float m_SwayStateStartTime[eSwayStates.MAX];
49 protected float m_LastSwayMultiplier = PlayerSwayConstants.SWAY_MULTIPLIER_DEFAULT;
52 protected float m_BreathingXAxisOffset;
53 protected float m_BreathingYAxisOffset;
54 protected bool m_HoldingBreathSet;
55 protected bool m_AimNoiseAllowed = true;
56 protected bool m_ProceduralRecoilEnabled = true;
58 protected int m_ShakeCount;
59 protected float m_SwayWeight;
60 protected float m_MaxVelocity;
62 protected float m_CamShakeX;
63 protected float m_CamShakeY;
64 protected vector m_SwayModifier = "1 1 1";//"max_speed_noise radius_noise overall_speed"
65 protected int m_SwayState = -1;
66
67 protected float m_StealthAimY_Last;
68 protected float m_FilterVelocityStealthAimY[1] = {0};
69
70 protected static float m_AimXClampRanges[] = { -180, -20, 90, 0, -50, 90, 180, -20, 90 };
71
78
80 {
82 m_CurrentRecoil = weapon.SpawnRecoilObject();
83 }
84
85 void RequestKuruShake(float amount)
86 {
87 if (!m_KuruShake)
88 m_KuruShake = new KuruShake(m_PlayerPb, amount);
89 }
90
92 {
93 Weapon_Base weapon = Weapon_Base.Cast(player.GetHumanInventory().GetEntityInHands());
94 if (weapon)
95 m_SwayModifier = weapon.GetPropertyModifierObject().m_SwayModifiers;
96 }
97
103
105 {
106 switch (state)
107 {
108 case eSwayStates.HOLDBREATH_EXHAUSTED:
109 m_PlayerPb.OnHoldBreathExhausted();
110 break;
111
112 default:
113 break;
114 }
115 }
116
118 {
119 return m_SwayWeight;
120 }
121
123 {
125 }
126
128 {
129 return m_AimNoiseAllowed;
130 }
131
136
141
142 void SetCamShakeValues(float x_axis, float y_axis)
143 {
146 }
147
149 {
151 pModel.m_fAimYMouseShift = -(pModel.m_fCurrentAimY - m_StealthAimY_Last);
152 return true;
153 }
154
156 {
157 float breathing_offset_x;
158 float breathing_offset_y;
159
160 float noise_offset_x;
161 float noise_offset_y;
162
163 float shake_offset_x;
164 float shake_offset_y;
165
168
171
172 float kuru_offset_x;
173 float kuru_offset_y;
174
175 float player_stamina = m_PlayerPb.GetStaminaHandler().GetSyncedStaminaNormalized();
176
177#ifdef DEVELOPER
178 DbgPrintAimingImplement("Player: " + m_PlayerPb + " | ProcessAimFilters | timestamp: " + m_PlayerPb.GetSimulationTimeStamp());
179#endif
180
181 //negates stamina effect during hold breath
182 if (m_PlayerPb.IsHoldingBreath())
183 player_stamina = 1;
185 m_TotalTime += pDt * speed;
186
187 if (m_PlayerPb.IsHoldingBreath() && !m_HoldingBreathSet)
189 else if (!m_PlayerPb.IsHoldingBreath() && m_HoldingBreathSet)
191
194
195 m_SwayWeight = CalculateWeight(stance_index, player_stamina, 0.5/*m_PlayerPb.m_CameraSwayModifier*/, m_PlayerPb.IsHoldingBreath()) * adjusted_sway_multiplier;
196
200
201 int shake_level = m_PlayerPb.GetShakeLevel();
202 if (shake_level != 0)
204
206 if (m_CurrentRecoil)
208
209 if (m_KuruShake)
211
215
216#ifdef DEVELOPER
217 DbgPrintAimingImplement("breathing_offset_y: " + breathing_offset_y);
218 DbgPrintAimingImplement("noise_offset_y: " + noise_offset_y);
219 DbgPrintAimingImplement("recoil_offset_hands_y: " + recoil_offset_hands_y);
220 DbgPrintAimingImplement("shake_offset_y: " + shake_offset_y);
221 DbgPrintAimingImplement("kuru_offset_y: " + kuru_offset_y);
222 DbgPrintAimingImplement("pModel.m_fAimYHandsOffset: " + pModel.m_fAimYHandsOffset);
223#endif
227
228
229#ifdef DEVELOPER
230 DbgPrintAimingImplement("m_CamShakeY: " + m_CamShakeY);
231 DbgPrintAimingImplement("pModel.m_fAimYCamOffset: " + pModel.m_fAimYCamOffset);
232#endif
233
235 if (stance_index == DayZPlayerConstants.STANCEIDX_RAISEDPRONE)
236 {
237 float newVal = DayZPlayerUtils.LinearRangeClamp(pModel.m_fCurrentAimX, pModel.m_fCurrentAimY, m_AimXClampRanges);
238 pModel.m_fAimYHandsOffset += newVal - pModel.m_fCurrentAimY;
239 }
240 float absAimY = Math.AbsFloat(pModel.m_fCurrentAimY);
241 pModel.m_fAimYHandsOffset = Math.Clamp(pModel.m_fAimYHandsOffset, absAimY - 89.9, 89.9 - absAimY); //'90' leads to rounding errors down the line
242
243 if (m_PlayerDpi.IsInOptics() && m_KuruShake)
244 {
245 //TODO - do not offset mouse
246 }
248 pModel.m_fAimXMouseShift = recoil_offset_mouse_x - kuru_offset_x / 10;
249 pModel.m_fAimYMouseShift = recoil_offset_mouse_y + kuru_offset_y / 10;
250
251#ifdef DEVELOPER
252 DbgPrintAimingImplement("recoil_offset_mouse_y: " + recoil_offset_mouse_y);
253 DbgPrintAimingImplement("pModel.m_fAimYMouseShift: " + pModel.m_fAimYMouseShift);
254#endif
255
256 if (m_PlayerPb.IsHoldingBreath() && !m_HoldingBreathSet)
257 {
258 m_HoldingBreathSet = true;
262 }
263 else if (!m_PlayerPb.IsHoldingBreath() && m_HoldingBreathSet)
264 m_HoldingBreathSet = false;
265
266 if (!m_PlayerPb.IsHoldingBreath() && m_LastSwayMultiplier == PlayerSwayConstants.SWAY_MULTIPLIER_DEFAULT && m_HorizontalNoiseXAxisOffset != 0)
267 {
271 }
272
273 if (m_PlayerPb.IsHoldingBreath())
274 m_PlayerPb.DepleteStamina(EStaminaModifiers.HOLD_BREATH, pDt * speed);
275#ifdef DEVELOPER
276 DbgPrintAimingImplement("----------------------------");
277#endif
278 return true;
279 }
280
281 protected float CalculateSwayMultiplier()
282 {
283 float max;
284 float time;
285 float time_clamped;
286 float ret;
287
288 if (m_PlayerPb.IsHoldingBreath())
289 {
291
292 if (time < PlayerSwayConstants.SWAY_TIME_IN)
293 {
294 UpdateSwayState(eSwayStates.HOLDBREATH_IN);
295 max = PlayerSwayConstants.SWAY_TIME_IN;
298 }
299 else if (time >= PlayerSwayConstants.SWAY_TIME_IN && time < (PlayerSwayConstants.SWAY_TIME_IN + PlayerSwayConstants.SWAY_TIME_STABLE))
300 {
301 UpdateSwayState(eSwayStates.HOLDBREATH_STABLE);
302 ret = PlayerSwayConstants.SWAY_MULTIPLIER_STABLE;
303 }
304 else
305 {
306 UpdateSwayState(eSwayStates.HOLDBREATH_EXHAUSTED);
307 max = PlayerSwayConstants.SWAY_TIME_EXHAUSTED;
309 ret = Math.Lerp(PlayerSwayConstants.SWAY_MULTIPLIER_STABLE, PlayerSwayConstants.SWAY_MULTIPLIER_EXHAUSTED, (time_clamped / max));
310 }
311 }
312 else
313 {
315 max = PlayerSwayConstants.SWAY_TIME_OUT;
318 }
319 return ret;
320 }
321
323 {
324 return (((1.0 - stamina) * 3.0) + 1.0) * m_SwayModifier[2]; // just 'm_SwayModifier[2]' for HoldBreath
325 }
326
327 protected bool UpdateSwayState(int state)
328 {
329 if (state != m_SwayState)
330 {
335 return true;
336 }
337
338 return false;
339 }
340
342 {
343 return m_SwayState;
344 }
345
346 protected void ApplyBreathingPattern(out float x_axis, out float y_axis, float pAmplitude, float pTotalTime, float weight)
347 {
348
349 float multiplier = Math.Lerp(PlayerSwayConstants.SWAY_MULTIPLIER_DEFAULT, 0, m_LastSwayMultiplier); //TODO revise
350#ifdef DEVELOPER
351 DbgPrintAimingImplement("m_LastSwayMultiplier: " + m_LastSwayMultiplier);
352 DbgPrintAimingImplement("pAmplitude: " + pAmplitude);
353 DbgPrintAimingImplement("pTotalTime: " + pTotalTime);
354 DbgPrintAimingImplement("weight: " + weight);
355 DbgPrintAimingImplement("multiplier: " + multiplier);
356#endif
357
359 y_axis = (Math.Sin((pTotalTime) * 0.8 + 0.6) * pAmplitude) * weight;
360#ifdef DEVELOPER
361 DbgPrintAimingImplement("y_axis_midproduct: " + y_axis);
362#endif
365 }
366
367 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)
368 {
370 {
371 //acquire new target
372 m_MaxVelocity = m_PlayerPb.GetRandomGeneratorSyncManager().GetRandomInRange(RandomGeneratorSyncUsage.RGSAimingModel, max_velocity_low, max_velocity_high);
373
374 float r = m_PlayerPb.GetRandomGeneratorSyncManager().GetRandomInRange(RandomGeneratorSyncUsage.RGSAimingModel, 0, 1);
375 m_HorizontalTargetValue = (r - 0.5) * 2 * max_distance;
377 }
378
381 float multiplier = Math.Lerp(PlayerSwayConstants.SWAY_MULTIPLIER_DEFAULT, 0, m_LastSwayMultiplier); //TODO revise
383 }
384
385 protected void ApplyShakes(out float x_axis, out float y_axis, int level)
386 {
387 float weight = level / PlayerBase.SHAKE_LEVEL_MAX;
388 m_ShakeCount++;
389 int shakes_threshold = Math.Round(m_PlayerPb.GetRandomGeneratorSyncManager().GetRandomInRange(RandomGeneratorSyncUsage.RGSAimingModel, 2, 4));
391 {
392 m_ShakeCount = 0;
393
394 float modifier = m_PlayerPb.GetRandomGeneratorSyncManager().GetRandomInRange(RandomGeneratorSyncUsage.RGSAimingModel, 0.45, 0.9);
395 x_axis = modifier * weight * m_PlayerPb.GetRandomGeneratorSyncManager().GetRandomInRange(RandomGeneratorSyncUsage.RGSAimingModel, 0, 1);
396 y_axis = modifier * weight * m_PlayerPb.GetRandomGeneratorSyncManager().GetRandomInRange(RandomGeneratorSyncUsage.RGSAimingModel, 0, 1);
397 }
398 }
399
401 {
402 if (m_PlayerDpi.GetCommand_Move() && m_PlayerDpi.GetCommand_Move().IsInRoll())//when the player is rolling, set a constant and disregard everything else
403 return PlayerSwayConstants.SWAY_ROLL;
404 float stance_modifier;
405 switch (stance_index)
406 {
407 case DayZPlayerConstants.STANCEIDX_RAISEDERECT:
408 stance_modifier = 0.5;
409 break;
410 case DayZPlayerConstants.STANCEIDX_RAISEDCROUCH:
411 stance_modifier = 0.75;
412 break;
413 case DayZPlayerConstants.STANCEIDX_RAISEDPRONE:
414 stance_modifier = 0.9;
415 break;
416 default:
417 stance_modifier = 0.75;
418 //Debug.LogError("stance mask out of definition");
419 break;
420 }
421
422#ifdef DEVELOPER
423 DbgPrintAimingImplement("current_stamina: " + current_stamina);
424 DbgPrintAimingImplement("camera_sway_modifier: " + camera_sway_modifier);
425 DbgPrintAimingImplement("holding_breath: " + holding_breath);
426#endif
427
429 }
430
432 {
433#ifdef DEVELOPER
434 if (GetDayZGame().IsAimLogEnabled())
435 Print("DayZPlayerImplementAiming | " + val);
436#endif
437 }
438}
439
DayZGame GetDayZGame()
Definition DayZGame.c:3530
static const float SWAY_TIME_OUT
enum eSwayStates SWAY_MULTIPLIER_DEFAULT
static const float SWAY_TIME_EXHAUSTED
static const float SWAY_MULTIPLIER_STABLE
static const float SWAY_ROLL
static const float SWAY_TIME_IN
static const float SWAY_MULTIPLIER_EXHAUSTED
static const float SWAY_TIME_STABLE
void DayZPlayerUtils()
cannot be instantiated
EStaminaModifiers
Super root of all classes in Enforce script.
Definition EnScript.c:11
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)
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
DayZPlayerConstants
defined in C++
Definition dayzplayer.c:597
proto void Print(void var)
Prints content of variable to console/log.
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
static proto float Lerp(float a, float b, float time)
Linearly interpolates between 'a' and 'b' given 'time'.
static proto float Round(float f)
Returns mathematical round of value.
static proto float Clamp(float value, float min, float max)
Clamps 'value' to 'min' if it is lower than 'min', or to 'max' if it is higher than 'max'.
static proto float Sin(float angle)
Returns sinus of angle in radians.
static proto float AbsFloat(float f)
Returns absolute value.
static proto float SmoothCD(float val, float target, inout float velocity[], float smoothTime, float maxVelocity, float dt)
Does the CD smoothing function - easy in | easy out / S shaped smoothing.