26 #ifdef _DAYZ_CREATURE_DEBUG_SHADOW
93 GetTransform(parentTransMat);
98 Math3D.YawPitchRollMatrix(closeBoneRotWS *
Math.RAD2DEG,rotMatrix);
100 parentTransMat[0] = rotMatrix[0];
101 parentTransMat[1] = rotMatrix[1];
102 parentTransMat[2] = rotMatrix[2];
103 parentTransMat[3] = closeBonePosWS;
106 arrow.GetTransform(arrowTransMat);
107 Math3D.MatrixInvMultiply4(parentTransMat, arrowTransMat, arrowTransMat);
109 Math3D.MatrixOrthogonalize4(arrowTransMat);
110 arrow.SetTransform(arrowTransMat);
126 bool ModCommandHandlerBefore(
float pDt,
int pCurrentCommandID,
bool pCurrentCommandFinished)
144 proto native
AIAgent GetAIAgent();
146 proto native
bool IsSoundInsideBuilding();
147 #ifdef DIAG_DEVELOPER
148 proto native
void DebugDisableAIControl();
149 proto native
void DebugRestoreAIControl();
151 proto native
void AddDamageSphere(
string bone_name,
string ammo_name,
float radius,
float duration,
bool invertTeams);
158 proto native
void InitAIAgent(
AIGroup group);
159 proto native
void DestroyAIAgent();
161 int m_EffectTriggerCount;
168 RegisterAnimEvents();
173 void IncreaseEffectTriggerCount()
175 m_EffectTriggerCount++;
178 void DecreaseEffectTriggerCount()
180 m_EffectTriggerCount--;
183 void AddDamageSphere(AnimDamageParams damage_params)
185 AddDamageSphere(damage_params.m_sBoneName, damage_params.m_sAmmoName, damage_params.m_fRadius, damage_params.m_fDuration, damage_params.m_bInvertTeams);
190 super.EEKilled(killer);
211 void OnSoundEvent(
int event_id,
string event_user_string)
213 AnimSoundEvent sound_event = GetCreatureAIType().GetSoundEvent(event_id);
214 if(sound_event != NULL)
216 ProcessSoundEvent(sound_event);
220 void OnSoundVoiceEvent(
int event_id,
string event_user_string)
222 AnimSoundVoiceEvent voice_event = GetCreatureAIType().GetSoundVoiceEvent(event_id);
223 if(voice_event != NULL)
225 ProcessSoundVoiceEvent(voice_event);
229 void OnStepEvent(
int event_id,
string event_user_string)
231 AnimStepEvent step_event = GetCreatureAIType().GetStepEvent(event_id);
232 if(step_event != NULL)
234 ProcessStepEvent(step_event);
238 void OnDamageEvent(
int event_id,
string event_user_string)
240 AnimDamageEvent damage_event = GetCreatureAIType().GetDamageEvent(event_id);
241 if(damage_event != NULL)
243 ProcessDamageEvent(damage_event);
247 protected void RegisterAnimEvents()
251 Print(
"Error registering anim. event (Sound)");
256 Print(
"Error registering anim. event (SoundVoice)");
259 if(!
GetGame().IsDedicatedServer())
263 Print(
"Error registering anim. event (Step)");
269 Print(
"Error registering anim. event (Damage)");
273 private void ProcessSoundEvent(AnimSoundEvent sound_event)
275 if(!
GetGame().IsDedicatedServer())
278 if(NULL != objectBuilder)
281 SoundObject soundObject = objectBuilder.BuildSoundObject();
288 if(sound_event.m_NoiseParams != NULL)
289 GetGame().GetNoiseSystem().AddNoise(
this, sound_event.m_NoiseParams);
293 private void ProcessSoundVoiceEvent(AnimSoundVoiceEvent sound_event)
295 if(!
GetGame().IsDedicatedServer())
298 if(NULL != objectBuilder)
301 SoundObject soundObject = objectBuilder.BuildSoundObject();
302 AttenuateSoundIfNecessary(soundObject);
309 if(sound_event.m_NoiseParams != NULL)
310 GetGame().GetNoiseSystem().AddNoise(
this, sound_event.m_NoiseParams);
314 private void ProcessStepEvent(AnimStepEvent step_event)
316 SoundObjectBuilder soundBuilder = step_event.GetSoundBuilder(GetSurfaceType().Hash());
317 if(soundBuilder == NULL)
321 SoundObject soundObject = soundBuilder.BuildSoundObject();
322 AttenuateSoundIfNecessary(soundObject);
328 private void ProcessDamageEvent(AnimDamageEvent damage_event)
330 AddDamageSphere(damage_event.m_DamageParams);
333 protected void AttenuateSoundIfNecessary(
SoundObject soundObject)
337 soundObject.SetKind(
WaveKind.WAVEATTALWAYS);
341 soundObject.SetKind(
WaveKind.WAVEEFFECTEX);
376 m_CinematicPlayer = player;
379 bool CinematicCanJump()
386 if (!m_CinematicPlayer)
388 return super.ModCommandHandlerBefore(pDt, pCurrentCommandID, pCurrentCommandFinished);
391 UAInterface input = m_CinematicPlayer.GetInputInterface();
394 GetGame().GameScript.CallFunction(
this,
"GetInputController", controller, 0);
396 if (!input || !controller)
398 return super.ModCommandHandlerBefore(pDt, pCurrentCommandID, pCurrentCommandFinished);
401 float movementX = input.SyncedValue_ID(UAAimRight) - input.SyncedValue_ID(UAAimLeft);
403 float maxTurnSpeed = 100.0;
404 movementX =
Math.Clamp(movementX * maxTurnSpeed * pDt, -180, 180);
406 if (input.SyncedValue_ID(UALookAround) > 0)
411 bool isJump = input.SyncedValue_ID(UAGetOver) > 0;
412 bool isMove = input.SyncedValue_ID(UAMoveForward) > 0;
414 bool isRest = input.SyncedValue_ID(UAMoveBack) > 0;
415 bool isSleep = input.SyncedValue_ID(UAReloadMagazine) > 0;
429 bool isSprint = input.SyncedValue_ID(UATurbo) > 0;
430 bool isJog = input.SyncedValue_ID(UAWalkRunTemp) > 0;
431 bool isWalk = !isSprint && !isJog;
450 if (
Class.CastTo(animalController, controller))
472 if (iSpeed > 0 && lowVel)
480 if (animalController)
499 controller.OverrideTurnSpeed(
true,
Math.PI2 / pDt);
500 controller.OverrideMovementSpeed(
true, fSpeed);
501 controller.OverrideHeading(
true, heading *
Math.DEG2RAD);
502 controller.OverrideAlertLevel(
true,
true, iAlert, fAlert);
504 if (CinematicCanJump() && isJump)
506 controller.OverrideJump(
true, 101, 2.0);
513 enum DayZAnimalConstants
613 protected vector m_DefaultHitPosition;
619 proto native
void StartCommand_Jump();
620 proto native
void StartCommand_Attack();
621 proto native
void StartCommand_Hit(
int pType,
int pDirection);
624 proto native DayZAnimalCommandScript
StartCommand_Script(DayZAnimalCommandScript pInfectedCommand);
628 proto native
void SignalAIAttackStarted();
629 proto native
void SignalAIAttackEnded();
644 override bool IsHealthVisible()
649 override bool IsAnimal()
661 return EInventoryIconVisibility.HIDE_VICINITY;
671 void CommandHandler(
float dt,
int currentCommandID,
bool currentCommandFinished)
681 if (HandleDeath(currentCommandID, inputController))
686 if (currentCommandFinished)
688 if (currentCommandID == DayZAnimalConstants.COMMANDID_ATTACK)
690 SignalAIAttackEnded();
704 if (HandleDamageHit(currentCommandID))
706 if (currentCommandID == DayZAnimalConstants.COMMANDID_ATTACK)
708 SignalAIAttackEnded();
713 if (currentCommandID == DayZAnimalConstants.COMMANDID_MOVE)
715 if (inputController.IsJump())
721 if (inputController.IsAttack())
723 StartCommand_Attack();
724 SignalAIAttackStarted();
736 bool m_DamageHitToProcess =
false;
737 int m_DamageHitType = 0;
738 int m_DamageHitDirection = 0;
742 if (inputController.IsDead())
744 if (currentCommandID == DayZAnimalConstants.COMMANDID_DEATH)
749 if (m_DamageHitToProcess)
751 m_DamageHitToProcess =
false;
766 bool HandleDamageHit(
int currentCommandID)
768 if (m_DamageHitToProcess)
770 m_DamageHitToProcess =
false;
772 if (currentCommandID != DayZAnimalConstants.COMMANDID_HIT)
774 StartCommand_Hit(m_DamageHitType, m_DamageHitDirection);
783 super.EEHitBy(damageResult, damageType, source,
component, dmgZone, ammo, modelPos, speedCoef);
784 m_TransportHitRegistered =
false;
786 int transferShockToDamageCoef =
g_Game.ConfigGetInt(
string.Format(
"%1 %2 DamageApplied transferShockToDamage",
CFG_AMMO, ammo));
787 if (transferShockToDamageCoef == 1)
790 AddHealth(
"",
"Health", -ConvertNonlethalDamage(damageResult.GetDamage(dmgZone,
"Shock"), damageType));
795 animal_bleeding.CreateWound( damageResult, dmgZone, ammo );
800 if (ComputeDamageHitParams(source, dmgZone, ammo, type, direction) ==
true)
802 QueueDamageHit(type, direction);
807 void QueueDamageHit(
int type,
int direction)
809 m_DamageHitToProcess =
true;
810 m_DamageHitType = type;
811 m_DamageHitDirection = direction;
814 bool ComputeDamageHitParams(
EntityAI source,
string dmgZone,
string ammo, out
int type, out
int direction)
818 float angleDeg = ComputeHitDirectionAngleDeg(source);
819 direction = TranslateHitAngleDegToDirectionIndex(angleDeg);
821 direction += FindComponentDirectionOffset(dmgZone);
826 float ComputeHitDirectionAngleDeg(
EntityAI source)
828 vector targetDirection = GetDirection();
831 targetDirection[1] = 0;
832 toSourceDirection[1] = 0;
834 targetDirection.Normalize();
835 toSourceDirection.Normalize();
837 float cosFi =
vector.Dot(targetDirection, toSourceDirection);
838 vector cross = targetDirection * toSourceDirection;
840 float dirAngleDeg =
Math.Acos(cosFi) *
Math.RAD2DEG;
842 dirAngleDeg = -dirAngleDeg;
847 int TranslateHitAngleDegToDirectionIndex(
float angleDeg)
849 if (angleDeg >= -20 && angleDeg <= 20)
853 else if (angleDeg < 0)
861 int FindComponentDirectionOffset(
string component)
863 const int directionCount = 4;
872 offset = directionCount;
876 offset = 2 * directionCount;
880 offset = 3 * directionCount;
901 RegisterTransportHit(transport);
942 return m_DefaultHitPosition;
945 protected vector SetDefaultHitPosition(
string pSelection)
947 return GetSelectionPositionMS(pSelection);
950 override protected float ConvertNonlethalDamage(
float damage,
DamageType damageType)
955 return damage *
GameConstants.NL_DAMAGE_CLOSECOMBAT_CONVERSION_ANIMALS;
957 return damage *
GameConstants.NL_DAMAGE_FIREARM_CONVERSION_ANIMALS;
960 return super.ConvertNonlethalDamage(damage, damageType);