Dayz Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
Loading...
Searching...
No Matches
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
18
19class DayZInfectedType extends DayZCreatureAIType
20{
21 //--------------------------------------------------------
22 // Public
23 //--------------------------------------------------------
26 {
28
30 m_DefaultHitComponent = "Torso";
33
38 m_SuitableFinisherHitComponents.Insert("Torso");
39
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 g_Game.ConfigGetText(lightAttPath, lightAttAmmo);
63 string heavyAttAmmo;
64 g_Game.ConfigGetText(heavyAttPath, heavyAttAmmo);
65 string chaseAttAmmo;
66 g_Game.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
129 {
130 return hitComp;
131 }
132
133 return GetDefaultHitComponent();
134 }
135
137 {
139 }
140
145
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 {
204 return m_ChaseAttacksGroup;
205
207 return m_FightAttacksGroup;
208 }
209
210 return NULL;
211 }
212
213 //--------------------------------------------------------
214 // Members
215 //--------------------------------------------------------
216
220
223 protected string m_DefaultHitComponent;
226}
static bool SelectMostProbableHitComponent(array< ref DayZAIHitComponent > pHitComponents, out string pHitComponent)
static void RegisterHitComponent(array< ref DayZAIHitComponent > pHitComponents, string pName, float pWeight)
proto native owned string GetName()
Definition enmath.c:7
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
DayZGame g_Game
Definition dayzgame.c:3942
ref array< ref DayZInfectedAttackType > m_ChaseAttacksGroup
selected & sorted targets by utility function
void RegisterAttack(DayZInfectedAttackGroupType pAttackGroupType, float pDistance, int pPitch, int pType, float pSubtype, string pAmmoType, int pIsHeavy, float pCooldown, float pProbability)
ref array< ref DayZInfectedAttackType > m_FightAttacksGroup
DayZInfectedAttackGroupType
float ComputeAttackUtility(DayZInfectedAttackType pAttackType, float pTargetDistance, int pPitch, float pProbability)
DayZInfectedAttackType ChooseAttack(DayZInfectedAttackGroupType pAttackGroupType, float pDistance, int pPitch)
void RegisterAttacks()
array< ref DayZInfectedAttackType > GetAttackGroup(DayZInfectedAttackGroupType pType)
ref array< ref DayZAIHitComponent > m_HitComponentsForAI
Melee hit components (AI targeting).
Definition dayzplayer.c:587
ref array< string > m_SuitableFinisherHitComponents
Definition dayzplayer.c:591
void RegisterHitComponentsForAI()
register hit components for AI melee (used by attacking AI)
Definition dayzplayer.c:463
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
string GetHitComponentForAI()
Definition dayzplayer.c:485
array< string > GetSuitableFinisherHitComponents()
Definition dayzplayer.c:507
static proto int Randomize(int seed)
Sets the seed for the random number generator.
static float RandomFloat01()
Returns a random float number between and min [inclusive] and max [inclusive].
Definition enmath.c:126
proto native float GetWorldTime()