Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
dayzanimal.c
Go to the documentation of this file.
2{
3 private void DayZCreatureAnimInterface() {}
4 private void ~DayZCreatureAnimInterface() {}
5
6 //-----------------------------------------------------
7 // Binds, returns -1 when error, otherwise if ok
8
10 proto native TAnimGraphCommand BindCommand(string pCommandName);
11
13 proto native TAnimGraphVariable BindVariableFloat(string pVariable);
14 proto native TAnimGraphVariable BindVariableInt(string pVariable);
15 proto native TAnimGraphVariable BindVariableBool(string pVariable);
16
18 proto native TAnimGraphTag BindTag(string pTagName);
19
21 proto native TAnimGraphEvent BindEvent(string pEventName);
22}
23
24class DayZCreature extends EntityAI
25{
26 #ifdef _DAYZ_CREATURE_DEBUG_SHADOW
27 proto native void DebugSetShadow(DayZCreature creature);
28 #endif
29
30 proto native bool RegisterAnimationEvent(string event_name, string function_name);
31
32 proto native void SetAnimationInstanceByName(string animation_instance_name, int instance_uuid, float duration);
34
36
37
38 proto native void UpdateSimulationPrecision(int simLOD);
39
40 //---------------------------------------------------------
41 // helper functions for disabling simulation upon death
42 proto native void StartDeath();
43 proto native void ResetDeath();
44
45 proto native void ResetDeathCooldown();
46 proto native bool IsDeathProcessed();
47 proto native bool IsDeathConditionMet();
48
49 //---------------------------------------------------------
50 // bone transforms
51
53 proto native int GetBoneIndexByName(string pBoneName);
54
55 override bool IsDayZCreature()
56 {
57 return true;
58 }
59
60 override bool CanBeSkinned()
61 {
62 return !GetIsFrozen();
63 }
64
66 {
67 return IsRuined();
68 }
69
70 override bool IsManagingArrows()
71 {
72 return true;
73 }
74
75 override bool DisableVicinityIcon()
76 {
77 return true;
78 }
79
80 override void AddArrow(Object arrow, int componentIndex, vector closeBonePosWS, vector closeBoneRotWS)
81 {
82 CachedObjectsArrays.ARRAY_STRING.Clear();
83 GetActionComponentNameList(componentIndex, CachedObjectsArrays.ARRAY_STRING, "fire");
84
85 int pivot = -1;
86
87
88 for (int i = 0; i < CachedObjectsArrays.ARRAY_STRING.Count() && pivot == -1; i++)
89 {
90 pivot = GetBoneIndexByName(CachedObjectsArrays.ARRAY_STRING.Get(i));
91 }
92
93 vector parentTransMat[4];
94 vector arrowTransMat[4];
95
96 if (pivot == -1)
97 {
98 GetTransform(parentTransMat);
99 }
100 else
101 {
102 vector rotMatrix[3];
103 Math3D.YawPitchRollMatrix(closeBoneRotWS * Math.RAD2DEG,rotMatrix);
104
105 parentTransMat[0] = rotMatrix[0];
106 parentTransMat[1] = rotMatrix[1];
107 parentTransMat[2] = rotMatrix[2];
108 parentTransMat[3] = closeBonePosWS;
109 }
110
111 arrow.GetTransform(arrowTransMat);
112 Math3D.MatrixInvMultiply4(parentTransMat, arrowTransMat, arrowTransMat);
113 // orthogonalize matrix - parent might be skewed
114 Math3D.MatrixOrthogonalize4(arrowTransMat);
115 arrow.SetTransform(arrowTransMat);
116
117 AddChild(arrow, pivot);
118 }
119
121 {
122 return true;
123 }
124
125 override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
126 {
127 super.GetDebugActions(outputList);
128
129 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.DELETE, "Delete", FadeColors.RED));
130 if (Gizmo_IsSupported())
131 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.GIZMO_OBJECT, "Gizmo Object", FadeColors.LIGHT_GREY));
132 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.GIZMO_PHYSICS, "Gizmo Physics (SP Only)", FadeColors.LIGHT_GREY)); // intentionally allowed for testing physics desync
133 outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.SEPARATOR, "___________________________", FadeColors.RED));
134 }
135
136 override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
137 {
138 if (super.OnAction(action_id, player, ctx))
139 return true;
140
141 if (GetGame().IsClient() || !GetGame().IsMultiplayer())
142 {
143 switch (action_id)
144 {
145 case EActions.GIZMO_OBJECT:
146 GetGame().GizmoSelectObject(this);
147 return true;
148 case EActions.GIZMO_PHYSICS:
149 GetGame().GizmoSelectPhysics(GetPhysics());
150 return true;
151 }
152 }
153
154 if (GetGame().IsServer())
155 {
156 switch (action_id)
157 {
158 case EActions.DELETE:
159 Delete();
160 return true;
161 }
162 }
163
164 return false;
165 }
166
167 //-------------------------------------------------------------
171 // these functions are for modded overide in script command mods
172
173 bool ModCommandHandlerBefore(float pDt, int pCurrentCommandID, bool pCurrentCommandFinished)
174 {
175 return false;
176 }
177
178 bool ModCommandHandlerInside(float pDt, int pCurrentCommandID, bool pCurrentCommandFinished)
179 {
180 return false;
181 }
182
183 bool ModCommandHandlerAfter(float pDt, int pCurrentCommandID, bool pCurrentCommandFinished)
184 {
185 return false;
186 }
187}
188
190{
191 proto native AIAgent GetAIAgent();
192
193 proto native bool IsSoundInsideBuilding();
194#ifdef DIAG_DEVELOPER
195 proto native void DebugDisableAIControl();
196 proto native void DebugRestoreAIControl();
197#endif
198 proto native void AddDamageSphere(string bone_name, string ammo_name, float radius, float duration, bool invertTeams);
199
200 proto native DayZCreatureAIType GetCreatureAIType();
205 proto native void InitAIAgent(AIGroup group);
206 proto native void DestroyAIAgent();
207
208 int m_EffectTriggerCount;//how many effect triggers is this AI inside of(overlapping triggers)
209
211
212
214 {
215 RegisterAnimEvents();
216 SetFlags(EntityFlags.TOUCHTRIGGERS, false);
217 }
218
219
221 {
222 m_EffectTriggerCount++;
223 }
224
226 {
227 m_EffectTriggerCount--;
228 }
229
230 void AddDamageSphere(AnimDamageParams damage_params)
231 {
232 AddDamageSphere(damage_params.m_sBoneName, damage_params.m_sAmmoName, damage_params.m_fRadius, damage_params.m_fDuration, damage_params.m_bInvertTeams);
233 }
234
235 override void EEKilled(Object killer)
236 {
237 super.EEKilled(killer);
238 CreateComponent(COMP_TYPE_BODY_STAGING); // TO DO: This is never called on clients in multiplayer! That's why skinning doesn't work properly in MP. DAYZ-28269
239 }
240
242 {
243 return AnimBootsType.None;
244 }
245
247 {
248 if(so == NULL)
249 {
250 return NULL;
251 }
252
253 so.SetPosition(GetPosition());
254 AbstractWave wave = GetGame().GetSoundScene().Play3D(so, sob);
255 return wave;
256 }
257
258 void OnSoundEvent(int event_id, string event_user_string)
259 {
260 AnimSoundEvent sound_event = GetCreatureAIType().GetSoundEvent(event_id);
261 if(sound_event != NULL)
262 {
263 ProcessSoundEvent(sound_event);
264 }
265 }
266
267 void OnSoundVoiceEvent(int event_id, string event_user_string)
268 {
269 AnimSoundVoiceEvent voice_event = GetCreatureAIType().GetSoundVoiceEvent(event_id);
270 if(voice_event != NULL)
271 {
272 ProcessSoundVoiceEvent(voice_event);
273 }
274 }
275
276 void OnStepEvent(int event_id, string event_user_string)
277 {
278 AnimStepEvent step_event = GetCreatureAIType().GetStepEvent(event_id);
279 if(step_event != NULL)
280 {
281 ProcessStepEvent(step_event);
282 }
283 }
284
285 void OnDamageEvent(int event_id, string event_user_string)
286 {
287 AnimDamageEvent damage_event = GetCreatureAIType().GetDamageEvent(event_id);
288 if(damage_event != NULL)
289 {
290 ProcessDamageEvent(damage_event);
291 }
292 }
293
294 protected void RegisterAnimEvents()
295 {
296 if(!RegisterAnimationEvent("Sound", "OnSoundEvent"))
297 {
298 Print("Error registering anim. event (Sound)");
299 }
300
301 if(!RegisterAnimationEvent("SoundVoice", "OnSoundVoiceEvent"))
302 {
303 Print("Error registering anim. event (SoundVoice)");
304 }
305
306 if(!GetGame().IsDedicatedServer())
307 {
308 if(!RegisterAnimationEvent("Step", "OnStepEvent"))
309 {
310 Print("Error registering anim. event (Step)");
311 }
312 }
313
314 if(!RegisterAnimationEvent("Damage", "OnDamageEvent"))
315 {
316 Print("Error registering anim. event (Damage)");
317 }
318 }
319
320 private void ProcessSoundEvent(AnimSoundEvent sound_event)
321 {
322 if(!GetGame().IsDedicatedServer())
323 {
324 SoundObjectBuilder objectBuilder = sound_event.GetSoundBuilder();
325 if(NULL != objectBuilder)
326 {
327 objectBuilder.AddEnvSoundVariables(GetPosition());
328 SoundObject soundObject = objectBuilder.BuildSoundObject();
329 PlaySound(soundObject, objectBuilder);
330 }
331 }
332
333 if(GetGame().IsServer())
334 {
335 if(sound_event.m_NoiseParams != NULL)
336 GetGame().GetNoiseSystem().AddNoise(this, sound_event.m_NoiseParams, GetGame().GetWeather().GetNoiseReductionByWeather());
337 }
338 }
339
340 private void ProcessSoundVoiceEvent(AnimSoundVoiceEvent sound_event)
341 {
342 if(!GetGame().IsDedicatedServer())
343 {
344 SoundObjectBuilder objectBuilder = sound_event.GetSoundBuilder();
345 if(NULL != objectBuilder)
346 {
347 objectBuilder.AddEnvSoundVariables(GetPosition());
348 SoundObject soundObject = objectBuilder.BuildSoundObject();
349 AttenuateSoundIfNecessary(soundObject);
350 PlaySound(soundObject, objectBuilder);
351 }
352 }
353
354 if(GetGame().IsServer())
355 {
356 if(sound_event.m_NoiseParams != NULL)
357 GetGame().GetNoiseSystem().AddNoise(this, sound_event.m_NoiseParams, GetGame().GetWeather().GetNoiseReductionByWeather());
358 }
359 }
360
361 private void ProcessStepEvent(AnimStepEvent step_event)
362 {
363 SoundObjectBuilder soundBuilder = step_event.GetSoundBuilder(GetSurfaceType().Hash());
364 if(soundBuilder == NULL)
365 return;
366
367 soundBuilder.AddEnvSoundVariables(GetPosition());
368 SoundObject soundObject = soundBuilder.BuildSoundObject();
369 AttenuateSoundIfNecessary(soundObject);
370 PlaySound(soundObject, soundBuilder);
371
372 //TODO effects
373 }
374
375 private void ProcessDamageEvent(AnimDamageEvent damage_event)
376 {
377 AddDamageSphere(damage_event.m_DamageParams);
378 }
379
380 protected void AttenuateSoundIfNecessary(SoundObject soundObject)
381 {
382 if (GetGame().GetPlayer() != NULL && (IsSoundInsideBuilding() != GetGame().GetPlayer().IsSoundInsideBuilding() || GetGame().GetPlayer().IsCameraInsideVehicle()))
383 {
384 soundObject.SetKind(WaveKind.WAVEATTALWAYS);
385 }
386 else
387 {
388 soundObject.SetKind(WaveKind.WAVEEFFECTEX);
389 }
390 }
391
393 {
394 return false;
395 }
396
397 // ================
398 // EASTER EGG
399 // ================
400
401 //Used for easter egg sound selection
402 bool IsDanger()
403 {
404 return false;
405 }
406
408 {
409 return "";
410 }
411
413 {
414 return "";
415 }
416
417 // ================
418 // CINEMATIC CONTROLLER
419 // ================
420
422 {
423 m_CinematicPlayer = player;
424 }
425
427 {
428 return true;
429 }
430
431 override bool ModCommandHandlerBefore(float pDt, int pCurrentCommandID, bool pCurrentCommandFinished)
432 {
433 if (!m_CinematicPlayer)
434 {
435 return super.ModCommandHandlerBefore(pDt, pCurrentCommandID, pCurrentCommandFinished);
436 }
437
438 UAInterface input = m_CinematicPlayer.GetInputInterface();
439
441 GetGame().GameScript.CallFunction(this, "GetInputController", controller, 0);
442
443 if (!input || !controller)
444 {
445 return super.ModCommandHandlerBefore(pDt, pCurrentCommandID, pCurrentCommandFinished);
446 }
447
448 float movementX = input.SyncedValue_ID(UAAimRight) - input.SyncedValue_ID(UAAimLeft);
449
450 float maxTurnSpeed = 100.0;
451 movementX = Math.Clamp(movementX * maxTurnSpeed * pDt, -180, 180);
452
453 if (input.SyncedValue_ID(UALookAround) > 0)
454 {
455 movementX = 0;
456 }
457
458 bool isJump = input.SyncedValue_ID(UAGetOver) > 0;
459 bool isMove = input.SyncedValue_ID(UAMoveForward) > 0;
460
461 bool isRest = input.SyncedValue_ID(UAMoveBack) > 0;
462 bool isSleep = input.SyncedValue_ID(UAReloadMagazine) > 0;
463
464 float heading = GetOrientation()[0] + movementX;
465
466 int iAlert = 0;
467 float fAlert = 0;
468 int iSpeed = 0;
469 float fSpeed = 0;
470
471 if (isMove)
472 {
473 iAlert = 1;
474 fAlert = 0.2;
475
476 bool isSprint = input.SyncedValue_ID(UATurbo) > 0;
477 bool isJog = input.SyncedValue_ID(UAWalkRunTemp) > 0;
478 bool isWalk = !isSprint && !isJog;
479 if (isSprint)
480 {
482 iSpeed = 3;
483 }
484 else if (isJog)
485 {
487 iSpeed = 2;
488 }
489 else if (isWalk)
490 {
492 iSpeed = 1;
493 }
494 }
495
496 DayZAnimalInputController animalController;
497 if (Class.CastTo(animalController, controller))
498 {
499 animalController.OverrideBehaviourSlot(true, DayZAnimalBehaviourSlot.NON_SPECIFIC_THREAT);
500 animalController.OverrideBehaviourAction(true, DayZAnimalBehaviourAction.TRAVELING_INPUT);
501
502 if (!isMove)
503 {
504 if (isRest)
505 {
506 iSpeed = 0;
507 animalController.OverrideBehaviourAction(true, DayZAnimalBehaviourAction.IDLE1_INPUT);
508 }
509
510 if (isSleep)
511 {
512 iSpeed = 0;
513 animalController.OverrideBehaviourAction(true, DayZAnimalBehaviourAction.WALKING_INPUT);
514 }
515 }
516 }
517
518 bool lowVel = GetVelocity(this).Length() < 0.5;
519 if (iSpeed > 0 && lowVel)
520 {
521 iAlert = 4;
522 fAlert = 1.0;
523
524 iSpeed = 3;
525 }
526
527 if (animalController)
528 {
529 switch (iSpeed)
530 {
531 case 0:
532 fSpeed = 0;
533 break;
534 case 1:
535 fSpeed = 2;
536 break;
537 case 2:
538 fSpeed = 3;
539 break;
540 case 3:
541 fSpeed = 5;
542 break;
543 }
544 }
545
546 controller.OverrideTurnSpeed(true, Math.PI2 / pDt);
547 controller.OverrideMovementSpeed(true, fSpeed);
548 controller.OverrideHeading(true, heading * Math.DEG2RAD);
549 controller.OverrideAlertLevel(true, true, iAlert, fAlert);
550
551 if (CinematicCanJump() && isJump)
552 {
553 controller.OverrideJump(true, 101, 2.0);
554 }
555
556 return true;
557 }
558}
559
560enum DayZAnimalConstants
561{
568};
569
571{
572
573}
574
575class DayZAnimalCommandAttack extends AnimCommandBase
576{
577
578}
579
580class DayZAnimalCommandJump extends AnimCommandBase
581{
582
583}
584
585class DayZAnimalCommandLookAt extends AnimCommandBase
586{
587
588}
589
590class DayZAnimalCommandBehaviourModifier extends AnimCommandBase
591{
592
593}
594
595class DayZAnimalCommandHit extends AnimCommandBase
596{
597
598}
599
600class DayZAnimalCommandDeath extends AnimCommandBase
601{
602
603}
604
605class DayZAnimalCommandAnimCallback extends AnimCommandBase
606{
607
608}
609
617class DayZAnimalCommandScript extends AnimCommandBase
618{
620 //void DayZAnimalCommandScript(DayZAnimal pAnimal)
621
622 //---------------------------------------------------------------
623 // usable everywhere
624
626 proto native void SetFlagFinished(bool pFinished);
627
628 //---------------------------------------------------------------
629 // PrePhys Update
630
632 proto native bool PrePhys_GetTranslation(out vector pOutTransl); // vec3 in local space !
633 proto native bool PrePhys_GetRotation(out float pOutRot[4]); // quaternion in local space !
634 proto native void PrePhys_SetTranslation(vector pInTransl); // vec3 in local space !
635 proto native void PrePhys_SetRotation(float pInRot[4]); // quaternion in local space !
636
637 //---------------------------------------------------------------
638 // PostPhys Update
639
643 bool PostPhysUpdate(float pDt);
644
646 proto native void PostPhys_GetPosition(out vector pOutTransl);
647 proto native void PostPhys_GetRotation(out float pOutRot[4]);
648 proto native void PostPhys_SetPosition(vector pInTransl);
649 proto native void PostPhys_SetRotation(float pInRot[4]);
650 proto native void PostPhys_LockRotation();
651}
652
654{
655
658 protected string m_DefaultHitComponent;
661
663
664 proto native void StartCommand_Death(int pType, int pDirection);
665 proto native void StartCommand_Move();
666 proto native void StartCommand_Jump();
667 proto native void StartCommand_Attack();
668 proto native void StartCommand_Hit(int pType, int pDirection);
669
671 proto native DayZAnimalCommandScript StartCommand_Script(DayZAnimalCommandScript pInfectedCommand);
672 proto native DayZAnimalCommandScript StartCommand_ScriptInst(typename pCallbackClass);
673 proto native DayZAnimalCommandScript GetCommand_Script();
674
675 proto native void SignalAIAttackStarted();
676 proto native void SignalAIAttackEnded();
677
679 {
680 // testing: animals have no inventory by default
681 //GetInventory().LockInventory(LOCK_FROM_SCRIPT); // Hides animals from vicinity in inventory. Remove this if wanted otherwise.
682
684
686
688 m_DefaultHitPosition = SetDefaultHitPosition(GetDefaultHitPositionComponent());
689
690 SetEventMask(EntityEvent.CONTACT);
691 }
692
693 override bool IsHealthVisible()
694 {
695 return false;
696 }
697
698 override bool IsAnimal()
699 {
700 return true;
701 }
702
703 override bool IsInventoryVisible()
704 {
705 return false;
706 }
707
708 override int GetHideIconMask()
709 {
710 return EInventoryIconVisibility.HIDE_VICINITY;
711 /*
712 if (IsAlive())
713 {
714 return EInventoryIconVisibility.HIDE_VICINITY;
715 }
716 return super.GetHideIconMask();
717 */
718 }
719
720 void CommandHandler(float dt, int currentCommandID, bool currentCommandFinished)
721 {
722 DayZAnimalInputController inputController = GetInputController();
723
725 if( ModCommandHandlerBefore(dt, currentCommandID, currentCommandFinished) )
726 {
727 return;
728 }
729
730 if (HandleDeath(currentCommandID, inputController))
731 {
732 return;
733 }
734
735 if (currentCommandFinished)
736 {
737 if (currentCommandID == DayZAnimalConstants.COMMANDID_ATTACK)
738 {
739 SignalAIAttackEnded();
740 }
741
742 StartCommand_Move();
743
744 return;
745 }
746
748 if( ModCommandHandlerInside(dt, currentCommandID, currentCommandFinished) )
749 {
750 return;
751 }
752
753 if (HandleDamageHit(currentCommandID))
754 {
755 if (currentCommandID == DayZAnimalConstants.COMMANDID_ATTACK)
756 {
757 SignalAIAttackEnded();
758 }
759 return;
760 }
761
762 if (currentCommandID == DayZAnimalConstants.COMMANDID_MOVE)
763 {
764 if (inputController.IsJump())
765 {
766 StartCommand_Jump();
767 return;
768 }
769
770 if (inputController.IsAttack())
771 {
772 StartCommand_Attack();
773 SignalAIAttackStarted();
774 return;
775 }
776 }
777
779 if( ModCommandHandlerAfter(dt, currentCommandID, currentCommandFinished) )
780 {
781 return;
782 }
783 }
784
785 bool m_DamageHitToProcess = false;
786 int m_DamageHitType = 0;
787 int m_DamageHitDirection = 0;
788
789 bool HandleDeath(int currentCommandID, DayZAnimalInputController inputController)
790 {
791 if (inputController.IsDead())
792 {
793 if (currentCommandID == DayZAnimalConstants.COMMANDID_DEATH)
794 {
795 return true;
796 }
797
798 if (m_DamageHitToProcess)
799 {
800 m_DamageHitToProcess = false;
801
802 StartCommand_Death(m_DamageHitType, m_DamageHitDirection);
803 }
804 else
805 {
806 StartCommand_Death(0, 0);
807 }
808
809 return true;
810 }
811
812 return false;
813 }
814
815 bool HandleDamageHit(int currentCommandID)
816 {
817 if (m_DamageHitToProcess)
818 {
819 m_DamageHitToProcess = false;
820
821 if (currentCommandID != DayZAnimalConstants.COMMANDID_HIT)
822 {
823 StartCommand_Hit(m_DamageHitType, m_DamageHitDirection);
824 }
825 return true;
826 }
827 return false;
828 }
829
830 override void EEHitBy(TotalDamageResult damageResult, int damageType, EntityAI source, int component, string dmgZone, string ammo, vector modelPos, float speedCoef)
831 {
832 super.EEHitBy(damageResult, damageType, source, component, dmgZone, ammo, modelPos, speedCoef);
833 m_TransportHitRegistered = false;
834
835 int transferShockToDamageCoef = g_Game.ConfigGetInt(string.Format("%1 %2 DamageApplied transferShockToDamage", CFG_AMMO, ammo));
836 if (transferShockToDamageCoef == 1)
837 {
838 //Print("DayZAnimal | EEHitBy | nonlethal hit");
839 AddHealth("", "Health", -ConvertNonlethalDamage(damageResult.GetDamage(dmgZone, "Shock"), damageType));
840 }
841 else
842 {
843 ComponentAnimalBleeding animal_bleeding = ComponentAnimalBleeding.Cast( GetComponent( COMP_TYPE_ANIMAL_BLEEDING ) );
844 animal_bleeding.CreateWound( damageResult, dmgZone, ammo );
845 }
846
847 int type = 0;
848 int direction = 0;
849 if (ComputeDamageHitParams(source, dmgZone, ammo, type, direction) == true)
850 {
851 QueueDamageHit(type, direction);
852 }
853
854 }
855
856 void QueueDamageHit(int type, int direction)
857 {
858 m_DamageHitToProcess = true;
859 m_DamageHitType = type;
860 m_DamageHitDirection = direction;
861 }
862
863 bool ComputeDamageHitParams(EntityAI source, string dmgZone, string ammo, out int type, out int direction)
864 {
865 type = 0; // not used right now
866
867 float angleDeg = ComputeHitDirectionAngleDeg(source);
868 direction = TranslateHitAngleDegToDirectionIndex(angleDeg);
869
870 direction += FindComponentDirectionOffset(dmgZone);
871
872 return true;
873 }
874
876 {
877 vector targetDirection = GetDirection();
878 vector toSourceDirection = (source.GetPosition() - GetPosition());
879
880 targetDirection[1] = 0;
881 toSourceDirection[1] = 0;
882
883 targetDirection.Normalize();
884 toSourceDirection.Normalize();
885
886 float cosFi = vector.Dot(targetDirection, toSourceDirection);
887 vector cross = targetDirection * toSourceDirection;
888
889 float dirAngleDeg = Math.Acos(cosFi) * Math.RAD2DEG;
890 if ( cross[1] < 0 )
891 dirAngleDeg = -dirAngleDeg;
892
893 return dirAngleDeg;
894 }
895
897 {
898 if (angleDeg >= -20 && angleDeg <= 20) // front
899 {
900 return 1;
901 }
902 else if (angleDeg < 0) // left
903 {
904 return 2;
905 }
906
907 return 3; // right
908 }
909
911 {
912 const int directionCount = 4;
913
914 int offset = 0;
915 if (component.Length() == 0)
916 {
917 offset = 0;
918 }
919 else if (component == "Zone_Head")
920 {
921 offset = directionCount;
922 }
923 else if (component == "Zone_Chest" || component == "Zone_Legs_Front" || component == "Zone_Spine_Front" || component == "Zone_Neck")
924 {
925 offset = 2 * directionCount;
926 }
927 else
928 {
929 offset = 3 * directionCount;
930 }
931
932 return offset;
933 }
934
935 //-------------------------------------------------------------
939
940 override protected void EOnContact(IEntity other, Contact extra)
941 {
942 if( !IsAlive() )
943 return;
944
945 Transport transport = Transport.Cast(other);
946 if( transport )
947 {
948 if ( GetGame().IsServer() )
949 {
950 RegisterTransportHit(transport);
951 }
952 }
953 }
954
957 {
959 m_DefaultHitComponent = "Zone_Chest";
962
964 DayZAIHitComponentHelpers.RegisterHitComponent(m_HitComponentsForAI, "Zone_Chest", 50);
965 }
966
967 override string GetHitComponentForAI()
968 {
969 string hitComp;
970
971 if (DayZAIHitComponentHelpers.SelectMostProbableHitComponent(m_HitComponentsForAI, hitComp))
972 {
973 return hitComp;
974 }
975
976 return GetDefaultHitComponent();
977 }
978
979 override string GetDefaultHitComponent()
980 {
982 }
983
985 {
987 }
988
990 {
991 return m_DefaultHitPosition;
992 }
993
994 protected vector SetDefaultHitPosition(string pSelection)
995 {
996 return GetSelectionPositionMS(pSelection);
997 }
998
999 override protected float ConvertNonlethalDamage(float damage, DamageType damageType)
1000 {
1001 switch (damageType)
1002 {
1003 case DamageType.CLOSE_COMBAT:
1004 return damage * GameConstants.NL_DAMAGE_CLOSECOMBAT_CONVERSION_ANIMALS;
1005 case DamageType.FIRE_ARM:
1006 return damage * GameConstants.NL_DAMAGE_FIREARM_CONVERSION_ANIMALS;
1007 }
1008
1009 return super.ConvertNonlethalDamage(damage, damageType);
1010 }
1011}
Param4< int, int, string, int > TSelectableActionInfoWithColor
Definition entityai.c:97
class AnimalBase extends DayZAnimal RegisterHitComponentsForAI()
Definition animalbase.c:40
vector GetOrientation()
base class of all commands exposed to script to provide common functionality over animations
Definition animcommand.c:3
Super root of all classes in Enforce script.
Definition enscript.c:11
void CreateWound(TotalDamageResult damage_result, string zone_name, string ammo)
do not process rotations !
Definition dayzanimal.c:654
vector SetDefaultHitPosition(string pSelection)
Definition dayzanimal.c:994
proto native void SignalAIAttackEnded()
bool HandleDeath(int currentCommandID, DayZAnimalInputController inputController)
Definition dayzanimal.c:789
override bool IsAnimal()
Definition dayzanimal.c:698
proto native DayZAnimalCommandScript StartCommand_Script(DayZAnimalCommandScript pInfectedCommand)
scripted commands
proto native void StartCommand_Hit(int pType, int pDirection)
proto native void StartCommand_Jump()
proto native DayZAnimalCommandScript GetCommand_Script()
void RegisterHitComponentsForAI()
register hit components for AI melee (used by attacking AI)
Definition dayzanimal.c:956
int FindComponentDirectionOffset(string component)
Definition dayzanimal.c:910
bool HandleDamageHit(int currentCommandID)
Definition dayzanimal.c:815
override string GetDefaultHitPositionComponent()
Definition dayzanimal.c:984
bool ComputeDamageHitParams(EntityAI source, string dmgZone, string ammo, out int type, out int direction)
Definition dayzanimal.c:863
void DayZAnimal()
Definition dayzanimal.c:678
override vector GetDefaultHitPosition()
Definition dayzanimal.c:989
proto native void StartCommand_Attack()
override void EEHitBy(TotalDamageResult damageResult, int damageType, EntityAI source, int component, string dmgZone, string ammo, vector modelPos, float speedCoef)
Definition dayzanimal.c:830
override int GetHideIconMask()
Definition dayzanimal.c:708
override bool IsHealthVisible()
Definition dayzanimal.c:693
string m_DefaultHitComponent
Definition dayzanimal.c:658
proto native DayZAnimalInputController GetInputController()
override bool IsInventoryVisible()
Definition dayzanimal.c:703
override string GetHitComponentForAI()
Definition dayzanimal.c:967
float ConvertNonlethalDamage(float damage, DamageType damageType)
Definition dayzanimal.c:999
proto native void StartCommand_Death(int pType, int pDirection)
ref array< ref DayZAIHitComponent > m_HitComponentsForAI
Melee hit components (AI targeting)
Definition dayzanimal.c:657
proto native DayZAnimalCommandScript StartCommand_ScriptInst(typename pCallbackClass)
void CommandHandler(float dt, int currentCommandID, bool currentCommandFinished)
Definition dayzanimal.c:720
void EOnContact(IEntity other, Contact extra)
Definition dayzanimal.c:940
proto native void StartCommand_Move()
override string GetDefaultHitComponent()
Definition dayzanimal.c:979
vector m_DefaultHitPosition
Definition dayzanimal.c:660
float ComputeHitDirectionAngleDeg(EntityAI source)
Definition dayzanimal.c:875
string m_DefaultHitPositionComponent
Definition dayzanimal.c:659
proto native void SignalAIAttackStarted()
void QueueDamageHit(int type, int direction)
Definition dayzanimal.c:856
int TranslateHitAngleDegToDirectionIndex(float angleDeg)
Definition dayzanimal.c:896
void AttenuateSoundIfNecessary(SoundObject soundObject)
Definition dayzanimal.c:380
DayZPlayer m_CinematicPlayer
Definition dayzanimal.c:210
void OnSoundVoiceEvent(int event_id, string event_user_string)
Definition dayzanimal.c:267
string CaptureSound()
Definition dayzanimal.c:407
bool CinematicCanJump()
Definition dayzanimal.c:426
void OnStepEvent(int event_id, string event_user_string)
Definition dayzanimal.c:276
bool ResistContaminatedEffect()
Definition dayzanimal.c:392
AbstractWave PlaySound(SoundObject so, SoundObjectBuilder sob)
Definition dayzanimal.c:246
bool IsDanger()
Definition dayzanimal.c:402
void DayZCreatureAI()
Definition dayzanimal.c:213
void RegisterAnimEvents()
Definition dayzanimal.c:294
override bool ModCommandHandlerBefore(float pDt, int pCurrentCommandID, bool pCurrentCommandFinished)
Definition dayzanimal.c:431
void AddDamageSphere(AnimDamageParams damage_params)
Definition dayzanimal.c:230
void OnDamageEvent(int event_id, string event_user_string)
Definition dayzanimal.c:285
void DecreaseEffectTriggerCount()
Definition dayzanimal.c:225
void CinematicTakeControl(DayZPlayer player)
Definition dayzanimal.c:421
override void EEKilled(Object killer)
Definition dayzanimal.c:235
void OnSoundEvent(int event_id, string event_user_string)
Definition dayzanimal.c:258
void IncreaseEffectTriggerCount()
Definition dayzanimal.c:220
AnimBootsType GetBootsType()
Definition dayzanimal.c:241
string ReleaseSound()
Definition dayzanimal.c:412
Definition enmath.c:7
Serialization general interface. Serializer API works with:
Definition serializer.c:56
Native class for boats - handles physics simulation.
Definition boat.c:28
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
DamageType
exposed from C++ (do not change)
override bool DisableVicinityIcon()
Definition dayzanimal.c:75
proto native DayZCreatureAnimInterface GetAnimInterface()
proto native void PrePhys_SetRotation(float pInRot[4])
bool PostPhysUpdate(float pDt)
class DayZCreatureAI extends DayZCreature COMMANDID_ATTACK
proto native void SetAnimationInstanceByName(string animation_instance_name, int instance_uuid, float duration)
proto native void PostPhys_SetPosition(vector pInTransl)
quaternion in world space
bool ModCommandHandlerInside(float pDt, int pCurrentCommandID, bool pCurrentCommandFinished)
Definition dayzanimal.c:178
class DayZCreatureAI extends DayZCreature COMMANDID_HIT
class DayZCreatureAnimInterface RegisterAnimationEvent(string event_name, string function_name)
class DayZAnimalCommandMove extends AnimCommandBase SetFlagFinished(bool pFinished)
DayZAnimalCommandScript fully scriptable command.
override bool HasFixedActionTargetCursorPosition()
Definition dayzanimal.c:120
override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
Definition dayzanimal.c:136
proto native void UpdateSimulationPrecision(int simLOD)
proto native bool PrePhys_GetRotation(out float pOutRot[4])
proto native int GetCurrentAnimationInstanceUUID()
proto native bool IsDeathProcessed()
proto native void PostPhys_GetRotation(out float pOutRot[4])
vec3 in world space
class DayZCreatureAI extends DayZCreature COMMANDID_MOVE
override void AddArrow(Object arrow, int componentIndex, vector closeBonePosWS, vector closeBoneRotWS)
Definition dayzanimal.c:80
proto native int GetBoneIndexByName(string pBoneName)
returns bone index for a name (-1 if pBoneName doesn't exist)
class DayZCreatureAI extends DayZCreature COMMANDID_SCRIPT
proto native bool PrePhys_GetTranslation(out vector pOutTransl)
script function usable in PrePhysUpdate
proto native void PostPhys_SetRotation(float pInRot[4])
vec3 in world space
override bool IsIgnoredByConstruction()
Definition dayzanimal.c:65
proto native void PrePhys_SetTranslation(vector pInTransl)
proto native void ResetDeath()
proto native void StartDeath()
override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
Definition dayzanimal.c:125
class DayZCreatureAI extends DayZCreature COMMANDID_JUMP
proto native void PostPhys_LockRotation()
quaternion in world space
override bool CanBeSkinned()
Definition dayzanimal.c:60
proto native void ResetDeathCooldown()
bool ModCommandHandlerBefore(float pDt, int pCurrentCommandID, bool pCurrentCommandFinished)
Definition dayzanimal.c:173
class DayZCreatureAI extends DayZCreature COMMANDID_DEATH
override bool IsManagingArrows()
Definition dayzanimal.c:70
bool ModCommandHandlerAfter(float pDt, int pCurrentCommandID, bool pCurrentCommandFinished)
Definition dayzanimal.c:183
override bool IsDayZCreature()
Definition dayzanimal.c:55
proto native void PostPhys_GetPosition(out vector pOutTransl)
script function usable in PostPhysUpdate
proto native bool IsDeathConditionMet()
DayZAnimalBehaviourSlot
defined in C++
DayZAnimalBehaviourAction
defined in C++
AnimBootsType
DayZGame g_Game
Definition dayzgame.c:3868
ref array< ref DayZAIHitComponent > m_HitComponentsForAI
Melee hit components (AI targeting)
Definition dayzplayer.c:587
string GetDefaultHitComponent()
Definition dayzplayer.c:497
string m_DefaultHitComponent
Definition dayzplayer.c:588
string GetDefaultHitPositionComponent()
Definition dayzplayer.c:502
string m_DefaultHitPositionComponent
Definition dayzplayer.c:589
EActions
Definition eactions.c:2
proto native CGame GetGame()
const int COMP_TYPE_ANIMAL_BLEEDING
Definition component.c:11
const int COMP_TYPE_BODY_STAGING
Definition component.c:10
proto void Print(void var)
Prints content of variable to console/log.
proto native void SetFlags(ShapeFlags flags)
EntityEvent
Entity events for event-mask, or throwing event from code.
Definition enentity.c:45
EntityFlags
Entity flags.
Definition enentity.c:115
const string CFG_AMMO
Definition constants.c:223
proto native vector GetVelocity(notnull IEntity ent)
Returns linear velocity.
const int SAT_DEBUG_ACTION
Definition constants.c:454
class AbstractSoundScene SoundObjectBuilder(SoundParams soundParams)
class JsonUndergroundAreaTriggerData GetPosition
void AbstractWave()
Definition sound.c:167
class HumanInputController TAnimGraphCommand
void PlaySound()
class BoxCollidingParams component
ComponentInfo for BoxCollidingResult.
PlayerBase GetPlayer()
WaveKind
Definition sound.c:2