Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
dayzinfectedtype.c
Go to the documentation of this file.
2 {
3  float m_Distance; // [m]
4  int m_Pitch; // 1 = up, 0 = center, -1 = down
5  int m_Type; // int argument for attack command
6  float m_Subtype; // float argument for attack command
7  string m_AmmoType; // ammotype from config
8  int m_IsHeavy; // 0 - light attack; 1 - heavy attack; -> Heavy attack is not blockable
9  float m_Cooldown; // [s]
10  float m_Probability; // [0..1]
11 };
12 
14 {
15  CHASE,
16  FIGHT
17 }
18 
19 class DayZInfectedType extends DayZCreatureAIType
20 {
21  //--------------------------------------------------------
22  // Public
23  //--------------------------------------------------------
26  {
28 
30  m_DefaultHitComponent = "Torso";
33 
36  m_SuitableFinisherHitComponents.Insert("Head");
37  m_SuitableFinisherHitComponents.Insert("Neck");
38  m_SuitableFinisherHitComponents.Insert("Torso");
39 
41  DayZAIHitComponentHelpers.RegisterHitComponent(m_HitComponentsForAI, "Head", 2);
42  DayZAIHitComponentHelpers.RegisterHitComponent(m_HitComponentsForAI, "LeftArm", 50);
43  DayZAIHitComponentHelpers.RegisterHitComponent(m_HitComponentsForAI, "Torso", 65);
44  DayZAIHitComponentHelpers.RegisterHitComponent(m_HitComponentsForAI, "RightArm", 50);
45  DayZAIHitComponentHelpers.RegisterHitComponent(m_HitComponentsForAI, "LeftLeg", 50);
46  DayZAIHitComponentHelpers.RegisterHitComponent(m_HitComponentsForAI, "RightLeg", 50);
47  }
48 
50  {
56 
57  string lightAttPath = string.Format("cfgVehicles %1 AttackActions AttackShort ammoType", GetName());
58  string heavyAttPath = string.Format("cfgVehicles %1 AttackActions AttackLong ammoType", GetName());
59  string chaseAttPath = string.Format("cfgVehicles %1 AttackActions AttackRun ammoType", GetName());
60 
61  string lightAttAmmo;
62  GetGame().ConfigGetText(lightAttPath, lightAttAmmo);
63  string heavyAttAmmo;
64  GetGame().ConfigGetText(heavyAttPath, heavyAttAmmo);
65  string chaseAttAmmo;
66  GetGame().ConfigGetText(chaseAttPath, chaseAttAmmo);
67 
70 
72  RegisterAttack(DayZInfectedAttackGroupType.CHASE, /*3.0*/2.4, -1, 0, 1, chaseAttAmmo, 0, 0.3, 1.0); // center left & light
73  RegisterAttack(DayZInfectedAttackGroupType.CHASE, /*3.0*/2.4, -1, 1, 1, chaseAttAmmo, 0, 0.4, 1.0); // center right & light
74 
78 
80  RegisterAttack(DayZInfectedAttackGroupType.FIGHT, /*2.0*/1.7, 1, 0, 0, lightAttAmmo, 0, 0.3, 0.7); // up left & light
81  RegisterAttack(DayZInfectedAttackGroupType.FIGHT, /*2.0*/1.7, 1, 1, 0, lightAttAmmo, 0, 0.4, 0.7); // up right & light
82 
84  RegisterAttack(DayZInfectedAttackGroupType.FIGHT, /*2.0*/1.7, 0, 0, 1, lightAttAmmo, 0, 0.1, 0.9); // center left & light
85  RegisterAttack(DayZInfectedAttackGroupType.FIGHT, /*2.0*/1.7, 0, 1, 1, lightAttAmmo, 0, 0.2, 0.9); // center right & light
86  RegisterAttack(DayZInfectedAttackGroupType.FIGHT, /*2.5*/1.4, 0, 2, 1, heavyAttAmmo, 0/*1*/, 0.3, 0.6); // center left & heavy
87  RegisterAttack(DayZInfectedAttackGroupType.FIGHT, /*2.5*/1.4, 0, 3, 1, heavyAttAmmo, 0/*1*/, 0.4, 0.6); // center right & heavy
88 
90  RegisterAttack(DayZInfectedAttackGroupType.FIGHT, /*2.0*/1.7, -1, 0, 2, lightAttAmmo, 0, 0.2, 0.5); // down left & light
91  RegisterAttack(DayZInfectedAttackGroupType.FIGHT, /*2.0*/1.7, -1, 1, 2, lightAttAmmo, 0, 0.3, 0.4); // down right & light
92  RegisterAttack(DayZInfectedAttackGroupType.FIGHT, /*2.5*/1.4, -1, 2, 2, heavyAttAmmo, 0/*1*/, 0.5, 0.8); // down left & heavy
93  RegisterAttack(DayZInfectedAttackGroupType.FIGHT, /*2.5*/1.4, -1, 3, 2, heavyAttAmmo, 0/*1*/, 0.6, 0.8); // down right & heavy
94  }
95 
96  DayZInfectedAttackType ChooseAttack(DayZInfectedAttackGroupType pAttackGroupType, float pDistance, int pPitch)
97  {
98  array<ref DayZInfectedAttackType> attackGroup = GetAttackGroup(pAttackGroupType);
99  float rnd;
100  float highestUtility = -1;
101  DayZInfectedAttackType mostSuitableAttack = null;
102 
103  Math.Randomize(GetWorldTime() + (int)pDistance);
104 
105  for (int i = 0; i < attackGroup.Count(); ++i)
106  {
107  rnd = Math.RandomFloat01();
108  DayZInfectedAttackType attackType = attackGroup.Get(i);
109  float utility = ComputeAttackUtility(attackType, pDistance, pPitch, rnd);
110  if (utility <= 0)
111  continue;
112 
113  if (utility > highestUtility)
114  {
115  mostSuitableAttack = attackType;
116  highestUtility = utility;
117  }
118  }
119 
120  //Print("Most sutable attack selected: " + mostSuitableAttack);
121  return mostSuitableAttack;
122  }
123 
125  {
126  string hitComp;
127 
128  if (DayZAIHitComponentHelpers.SelectMostProbableHitComponent(m_HitComponentsForAI, hitComp))
129  {
130  return hitComp;
131  }
132 
133  return GetDefaultHitComponent();
134  }
135 
137  {
138  return m_DefaultHitComponent;
139  }
140 
142  {
144  }
145 
147  {
149  }
150 
151  //--------------------------------------------------------
152  // Protected
153  //--------------------------------------------------------
154 
155  protected void RegisterAttack(DayZInfectedAttackGroupType pAttackGroupType, float pDistance, int pPitch, int pType, float pSubtype, string pAmmoType, int pIsHeavy, float pCooldown, float pProbability)
156  {
158 
159  newType.m_Distance = pDistance;
160  newType.m_Pitch = pPitch;
161  newType.m_Type = pType; //If attack is left or right
162  newType.m_Subtype = pSubtype; //If attack is center, down, up or run
163  newType.m_AmmoType = pAmmoType;
164  newType.m_IsHeavy = pIsHeavy;
165  newType.m_Cooldown = pCooldown;
166  newType.m_Probability = pProbability;
167 
168  GetAttackGroup(pAttackGroupType).Insert(newType);
169  }
170 
171  protected float ComputeAttackUtility(DayZInfectedAttackType pAttackType, float pTargetDistance, int pPitch, float pProbability)
172  {
173  // pitch
174  if (pAttackType.m_Pitch != pPitch)
175  return 0;
176 
177  // distance
178  float distDiff = pAttackType.m_Distance - pTargetDistance;
179  if (distDiff < 0)
180  return 0;
181 
182  float distDiffFrac = distDiff / 10;
183  float utilityDistance = (1 - distDiffFrac) * 100; // distance is most important
184 
185  // probability
186  float probDiff = pAttackType.m_Probability - pProbability;
187  if (probDiff < 0)
188  return 0;
189 
190  float utilityProbability = (1 - probDiff) * 10; // distance is most important
191 
192  // total
193  float util = utilityDistance + utilityProbability;
194  //Print("Attack Utility " + util);
195 
196  return util;
197  }
198 
200  {
201  switch (pType)
202  {
203  case DayZInfectedAttackGroupType.CHASE:
204  return m_ChaseAttacksGroup;
205 
206  case DayZInfectedAttackGroupType.FIGHT:
207  return m_FightAttacksGroup;
208  }
209 
210  return NULL;
211  }
212 
213  //--------------------------------------------------------
214  // Members
215  //--------------------------------------------------------
216 
220 
223  protected string m_DefaultHitComponent;
226 }
GetGame
proto native CGame GetGame()
RegisterAttack
protected void RegisterAttack(DayZInfectedAttackGroupType pAttackGroupType, float pDistance, int pPitch, int pType, float pSubtype, string pAmmoType, int pIsHeavy, float pCooldown, float pProbability)
Definition: dayzinfectedtype.c:155
m_DefaultHitComponent
protected string m_DefaultHitComponent
Definition: dayzinfectedtype.c:223
m_FightAttacksGroup
private ref array< ref DayZInfectedAttackType > m_FightAttacksGroup
Definition: dayzinfectedtype.c:219
GetName
proto native owned string GetName()
Definition: syncedvalue.c:117
FIGHT
FIGHT
Definition: dayzinfectedtype.c:4
RegisterAttacks
void RegisterAttacks()
Definition: dayzinfectedtype.c:49
GetDefaultHitPositionComponent
string GetDefaultHitPositionComponent()
Definition: dayzinfectedtype.c:141
GetWorldTime
proto native float GetWorldTime()
GetSuitableFinisherHitComponents
array< string > GetSuitableFinisherHitComponents()
Definition: dayzinfectedtype.c:146
DayZInfectedAttackGroupType
DayZInfectedAttackGroupType
Definition: dayzinfectedtype.c:13
m_ChaseAttacksGroup
private ref array< ref DayZInfectedAttackType > m_ChaseAttacksGroup
selected & sorted targets by utility function
Definition: dayzinfectedtype.c:218
CHASE
CHASE
Definition: dayzinfectedtype.c:2
GetHitComponentForAI
string GetHitComponentForAI()
Definition: dayzinfectedtype.c:124
m_HitComponentsForAI
protected ref array< ref DayZAIHitComponent > m_HitComponentsForAI
Melee hit components (AI targeting)
Definition: dayzinfectedtype.c:222
RegisterHitComponentsForAI
enum DayZInfectedAttackGroupType RegisterHitComponentsForAI()
register hit components for AI melee (used by attacking AI)
Definition: dayzinfectedtype.c:25
m_DefaultHitPositionComponent
protected string m_DefaultHitPositionComponent
Definition: dayzinfectedtype.c:224
ChooseAttack
DayZInfectedAttackType ChooseAttack(DayZInfectedAttackGroupType pAttackGroupType, float pDistance, int pPitch)
Definition: dayzinfectedtype.c:96
DayZInfectedAttackType
Definition: dayzinfectedtype.c:1
array< ref DayZAIHitComponent >
GetDefaultHitComponent
string GetDefaultHitComponent()
Definition: dayzinfectedtype.c:136
DayZAIHitComponentHelpers
Definition: dayzaihitcomponents.c:8
m_SuitableFinisherHitComponents
protected ref array< string > m_SuitableFinisherHitComponents
Definition: dayzinfectedtype.c:225
DayZCreatureAIType
Definition: dayzanimaltype.c:1
Math
Definition: enmath.c:6
GetAttackGroup
protected array< ref DayZInfectedAttackType > GetAttackGroup(DayZInfectedAttackGroupType pType)
Definition: dayzinfectedtype.c:199
ComputeAttackUtility
protected float ComputeAttackUtility(DayZInfectedAttackType pAttackType, float pTargetDistance, int pPitch, float pProbability)
Definition: dayzinfectedtype.c:171