DayZ 1.24
Loading...
Searching...
No Matches
DayZPlayerUtils.c File Reference

Go to the source code of this file.

Classes

class  ComponentCollisionBox
 
class  ComponentCollisionCapsule
 

Enumerations

enum  QueryFlags
 

Functions

enum QueryFlags EnableDebugDraw (bool pEnable)
 enables debug draw in functions
 
static proto native void DrawDebugText (string text, vector pos, float size)
 
static proto native void DrawStartFrame ()
 clear info - new draw starts
 
static proto native void DrawDebugBox (vector pos, float size, int color)
 draws debug box (color=red)
 
static proto native bool DebugOverrideAnimationTranslation (string pAnimName, vector pTranslation)
 overrides total animation translation
 
static proto native bool DebugOverrideAnimationRotation (string pAnimName, vector pRotation)
 overrides total animation rotation
 
static proto native bool DebugOverrideAnimationSpeed (string pAnimName, float pSpeed)
 overrides total animation speed
 
static proto float LinearRangeClamp (float pValueX, float pValueY, float pLimits[])
 
static proto native void PhysicsGetEntitiesInBox (vector min, vector max, notnull out array< EntityAI > entList)
 returns entities overlapping/touching in AABB box -
 
static proto native void SceneGetEntitiesInBox (vector min, vector max, notnull out array< EntityAI > entList, int flags=QueryFlags.DYNAMIC)
 returns entities overlapping/touching in AABB box -
 
static proto native void GetEntitiesInCone (vector pos, vector dir, float angle, float dist, float minHeigh, float maxHeight, out array< Object > entList)
 
static Object GetMeleeTarget (vector pos, vector dir, float angle, float dist, float minHeight, float maxHeight, EntityAI pToIgnore, array< typename > targetableObjects, out array< Object > allTargets=NULL)
 returns fight target
 
static proto native bool PlayerCanChangeStance (DayZPlayer pPlayer, int pTargetStance, bool forceCheck=false)
 
static proto native bool FindMagazinesForAmmo (DayZPlayer player, string ammoTypeName, out array< Magazine > mags)
 
static Magazine SelectStoreCartridge (DayZPlayer player, Weapon_Base weapon, int muzzleIndex, Magazine exclude_mag, float damage, string magTypeName)
 
static bool HandleDropMagazine (DayZPlayer player, Magazine mag)
 
static bool HandleDropCartridge (DayZPlayer player, float damage, string cartTypeName, string magTypeName)
 
static bool HandleStoreCartridge (DayZPlayer player, Weapon_Base weapon, int muzzleIndex, float damage, string cartTypeName, string magTypeName, bool CanDrop=true)
 
static proto native bool InitComponentCollisions (Human player, array< ref ComponentCollisionBox > boxes, array< ref ComponentCollisionCapsule > capsules)
 
static proto native bool IsComponentCollisionInitialized ()
 
static proto native void ClearComponentCollisions ()
 
static proto native vector GetMemoryPointPositionBoneRelative (DayZPlayer pPlayer, int pBoneIndex, int pPointIndex)
 
static void InitPlayerComponentCollisions (Human player)
 
static int ConvertStanceMaskToStanceIdx (int stanceMask)
 
static EWaterLevels CheckWaterLevel (DayZPlayer pPlayer, out vector waterLevel)
 
void DayZPlayerUtils ()
 cannot be instantiated
 
static void InitCachedEntList ()
 

Variables

 NONE
 
 STATIC
 Static objects are included in the query.
 
 DYNAMIC
 Dynamic objects are included in the query.
 
 ORIGIN_DISTANCE
 Check only distance to object origins, not BB.
 
 ONLY_ROADWAYS
 Only roadways are included in the query.
 
static ref array< Objectm_CachedEntList
 
class ComponentCollisionBox EnableDebugDraw
 

Enumeration Type Documentation

◆ QueryFlags

Definition at line 1 of file DayZPlayerUtils.c.

2{
3 NONE,
5 STATIC,
12}
ONLY_ROADWAYS
Only roadways are included in the query.
ORIGIN_DISTANCE
Check only distance to object origins, not BB.
DYNAMIC
Dynamic objects are included in the query.
STATIC
Static objects are included in the query.

Function Documentation

◆ CheckWaterLevel()

static EWaterLevels CheckWaterLevel ( DayZPlayer pPlayer,
out vector waterLevel )
static

if total water depth >= 1.5m && character is 1.5m in water

Definition at line 413 of file DayZPlayerUtils.c.

414 {
415 SHumanCommandSwimSettings swimData = pPlayer.GetDayZPlayerType().CommandSwimSettingsW();
416 vector pp = pPlayer.GetPosition();
417 waterLevel = HumanCommandSwim.WaterLevelCheck(pPlayer, pp);
418
419 if (waterLevel[1] < swimData.m_fToCrouchLevel)
420 return EWaterLevels.LEVEL_LOW;
421 else if (waterLevel[1] >= swimData.m_fToCrouchLevel && waterLevel[1] < swimData.m_fToErectLevel)
422 return EWaterLevels.LEVEL_CROUCH;
423 else// if (waterLevel[1] >= swimData.m_fToErectLevel)
424 {
426 if (waterLevel[0] >= swimData.m_fWaterLevelIn && waterLevel[1] >= swimData.m_fWaterLevelIn)
427 return EWaterLevels.LEVEL_SWIM_START;
428 else
429 return EWaterLevels.LEVEL_ERECT;
430 }
431 }
EWaterLevels
Definition EWaterLevels.c:2
class HumanCommandLadder HumanCommandSwim()
Definition human.c:669

References HumanCommandSwim().

◆ ClearComponentCollisions()

ClearComponentCollisions ( )
static

◆ ConvertStanceMaskToStanceIdx()

static int ConvertStanceMaskToStanceIdx ( int stanceMask)
static

Definition at line 387 of file DayZPlayerUtils.c.

388 {
389 switch (stanceMask)
390 {
391 case stanceMask &DayZPlayerConstants.STANCEMASK_PRONE:
392 return DayZPlayerConstants.STANCEIDX_PRONE;
393
394 case stanceMask &DayZPlayerConstants.STANCEMASK_CROUCH:
395 return DayZPlayerConstants.STANCEIDX_CROUCH;
396
397 case stanceMask &DayZPlayerConstants.STANCEMASK_ERECT:
398 return DayZPlayerConstants.STANCEIDX_ERECT;
399
400 case stanceMask &DayZPlayerConstants.STANCEMASK_RAISEDPRONE:
401 return DayZPlayerConstants.STANCEIDX_RAISEDPRONE;
402
403 case stanceMask &DayZPlayerConstants.STANCEMASK_RAISEDCROUCH:
404 return DayZPlayerConstants.STANCEIDX_RAISEDCROUCH;
405
406 case stanceMask &DayZPlayerConstants.STANCEMASK_RAISEDERECT:
407 return DayZPlayerConstants.STANCEIDX_RAISEDERECT;
408 }
409
410 return -1;
411 }
DayZPlayerConstants
defined in C++
Definition dayzplayer.c:597

◆ DayZPlayerUtils()

◆ DebugOverrideAnimationRotation()

static proto native bool DebugOverrideAnimationRotation ( string pAnimName,
vector pRotation )
static

overrides total animation rotation

◆ DebugOverrideAnimationSpeed()

static proto native bool DebugOverrideAnimationSpeed ( string pAnimName,
float pSpeed )
static

overrides total animation speed

◆ DebugOverrideAnimationTranslation()

static proto native bool DebugOverrideAnimationTranslation ( string pAnimName,
vector pTranslation )
static

overrides total animation translation

◆ DrawDebugBox()

static proto native void DrawDebugBox ( vector pos,
float size,
int color )
static

draws debug box (color=red)

◆ DrawDebugText()

static proto native void DrawDebugText ( string text,
vector pos,
float size )
static

◆ DrawStartFrame()

static proto native void DrawStartFrame ( )
static

clear info - new draw starts

◆ EnableDebugDraw()

enum QueryFlags EnableDebugDraw ( bool pEnable)

enables debug draw in functions

◆ FindMagazinesForAmmo()

static proto native bool FindMagazinesForAmmo ( DayZPlayer player,
string ammoTypeName,
out array< Magazine > mags )
static

◆ GetEntitiesInCone()

static proto native void GetEntitiesInCone ( vector pos,
vector dir,
float angle,
float dist,
float minHeigh,
float maxHeight,
out array< Object > entList )
static

Referenced by GetMeleeTarget().

◆ GetMeleeTarget()

static Object GetMeleeTarget ( vector pos,
vector dir,
float angle,
float dist,
float minHeight,
float maxHeight,
EntityAI pToIgnore,
array< typename > targetableObjects,
out array< Object > allTargets = NULL )
static

returns fight target

Definition at line 88 of file DayZPlayerUtils.c.

89 {
90 // Print("In: GetFightTarget");
92
94
95 Object ret = NULL;
96 Object obj = NULL;
97
98 float retVal = dist * 2; // max value
99 float tgAngle = Math.Tan(Math.DEG2RAD * angle);
100
101 // DrawStartFrame();
102
103 foreach (auto ent: m_CachedEntList)
104 {
105 if (ent == pToIgnore)
106 continue;
107
108 Class.CastTo(obj, ent);
109 if (obj)
110 {
111 // check for targetable objects
112 if (!obj.IsAnyInherited(targetableObjects))
113 continue;
114
115 if (!obj.IsAlive())
116 continue;
117 }
118
119 vector entpos = ent.GetPosition();
120
121 vector diff = entpos - pos;
122 float cDistSq = diff.LengthSq();
123 if (cDistSq > dist * dist) // out of distance
124 {
125 //Print("out of distance");
126 continue;
127 }
128
129 float frontDist = diff[0] * dir[0] + diff[2] * dir[2];
130 if (frontDist < 0.1) // behind the pos/dist half plane or further than dist
131 {
132 //Print("behind the pos/dist half plane or further than dist");
133 continue;
134 }
135
136 vector project = pos + dir * frontDist;
137 vector posdiff = Vector(project[0] - entpos[0], 0, project[2] - entpos[2]);
138 float sideDist = posdiff.LengthSq();
139
140 if (sideDist > tgAngle) // out of cone
141 {
142 //Print("out of cone");
143 continue;
144 }
145
146 float sum = frontDist + sideDist;
147 if (sum < retVal)
148 {
149 ret = ent;
150 retVal = sum;
151 }
152 else
153 {
154 //Print("sum !< retVal");
155 }
156
157 // string txt = project.ToString() + ": " + sum.ToString();
158 // DrawDebugBox(project,0.01,0xffff0000);
159 // DrawDebugBox(entpos,0.01,0xffff0000);
160 // DrawDebugText(txt, project, 1.0);
161 allTargets.Insert(ent);
162 }
163
164 return ret;
165 }
static ref array< Object > m_CachedEntList
static proto native void GetEntitiesInCone(vector pos, vector dir, float angle, float dist, float minHeigh, float maxHeight, out array< Object > entList)
static void InitCachedEntList()
Super root of all classes in Enforce script.
Definition EnScript.c:11
Definition EnMath.c:7
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
static proto float Tan(float angle)
Returns tangent of angle in radians.
static const float DEG2RAD
Definition EnMath.c:17

References Class::CastTo(), Math::DEG2RAD, GetEntitiesInCone(), InitCachedEntList(), m_CachedEntList, Math::Tan(), and Vector().

◆ GetMemoryPointPositionBoneRelative()

static proto native vector GetMemoryPointPositionBoneRelative ( DayZPlayer pPlayer,
int pBoneIndex,
int pPointIndex )
static

◆ HandleDropCartridge()

static bool HandleDropCartridge ( DayZPlayer player,
float damage,
string cartTypeName,
string magTypeName )
static

Definition at line 263 of file DayZPlayerUtils.c.

264 {
265 vector pos = player.GetPosition();
266 EntityAI entityGround = player.SpawnEntityOnGroundPos(magTypeName, pos);
267 if (entityGround && entityGround.IsInherited(Magazine))
268 {
271 {
272 magazineGround.ServerSetAmmoCount(0);
273 magazineGround.SetHealth("", "", (1 - damage) * magazineGround.GetMaxHealth());
274 if (magazineGround.ServerStoreCartridge(damage, cartTypeName))
275 return true;
276 }
277 }
278
279 return false;
280 }

References Class::CastTo().

Referenced by HandleStoreCartridge().

◆ HandleDropMagazine()

static bool HandleDropMagazine ( DayZPlayer player,
Magazine mag )
static

We don't care if a valid transform couldn't be found, we just want to preferably use it instead of placing on the player

Definition at line 244 of file DayZPlayerUtils.c.

245 {
246 vector m4[4];
248
252 il_mag_next.SetGround(mag, m4);
254 if (mag.GetInventory().GetCurrentInventoryLocation(il_mag_curr))
256 else
257 {
258 Error("DayZPlayerUtils::HandleDropMagazine - cannot get current inv location of mag=" + mag);
259 return false;
260 }
261 }
script counterpart to engine's class Inventory
Definition Inventory.c:79
static proto native bool PrepareDropEntityPos(EntityAI owner, notnull EntityAI item, out vector mat[4], bool useValuesInMatrix=false, int conflictCheckDepth=-1)
Finds a transformation for the item to be dropped to If the initial transforation overlaps with anoth...
static proto native bool LocationSyncMoveEntity(notnull InventoryLocation src_loc, notnull InventoryLocation dst_loc)
synchronously removes item from current inventory location and adds it to destination no anims involv...
InventoryLocation.
void Error(string err)
Messagebox with error message.
Definition EnDebug.c:90
static void MatrixIdentity4(out vector mat[4])
Creates identity matrix.
Definition EnMath3D.c:233

References Error(), GameInventory::LocationSyncMoveEntity(), Math3D::MatrixIdentity4(), and GameInventory::PrepareDropEntityPos().

◆ HandleStoreCartridge()

static bool HandleStoreCartridge ( DayZPlayer player,
Weapon_Base weapon,
int muzzleIndex,
float damage,
string cartTypeName,
string magTypeName,
bool CanDrop = true )
static

find suitable heap / mag

create a new one in inventory

drop on ground

Definition at line 282 of file DayZPlayerUtils.c.

283 {
284 if (damage < 1.0)
285 {
288 if (DayZPlayerUtils.FindMagazinesForAmmo(player, magTypeName, magazines))
289 {
290 int healthLevel = -1;
291 float testHeatlh = 1 - damage;
292 foreach (Magazine magazine : magazines)
293 {
294 if (healthLevel == -1)
295 {
296 if (magazine.CanAddCartridges(1))
297 {
298 int numberOfHealthLevels = magazine.GetNumberOfHealthLevels();
299 for (int i = 1; i < numberOfHealthLevels; i++)
300 {
301 if (magazine.GetHealthLevelValue(i) < testHeatlh)
302 {
303 healthLevel = i - 1;
304 break;
305 }
306 }
307 }
308 }
309
310 if (magazine.GetHealthLevel() == healthLevel)
311 {
312 if (magazine.ServerStoreCartridge(damage, cartTypeName))
313 return true;
314 }
315 }
316 }
317
320 if (player.GetInventory().FindFirstFreeLocationForNewEntity(magTypeName, FindInventoryLocationType.ANY, inventoryLocation))
321 {
323 if (entityInventory && entityInventory.IsInherited(Magazine))
324 {
327 {
328 magazineInventory.ServerSetAmmoCount(0);
329 magazineInventory.SetHealth("", "", (1 - damage) * magazineInventory.GetMaxHealth());
330 if (magazineInventory.ServerStoreCartridge(damage, cartTypeName))
331 return true;
332 }
333 }
334 }
335
337 if (CanDrop)
339 }
340
341 return false;
342 }
proto native void SpawnEntity(string sClassName, vector vPos, float fRange, int iCount)
Spawn an entity through CE.
const int ECE_IN_INVENTORY
const int RF_DEFAULT
void DayZPlayerUtils()
cannot be instantiated
static bool HandleDropCartridge(DayZPlayer player, float damage, string cartTypeName, string magTypeName)
FindInventoryLocationType
flags for searching locations in inventory

References Class::CastTo(), DayZPlayerUtils(), ECE_IN_INVENTORY, HandleDropCartridge(), RF_DEFAULT, and SpawnEntity().

◆ InitCachedEntList()

static void InitCachedEntList ( )
staticprivate

Definition at line 444 of file DayZPlayerUtils.c.

445 {
446 if (m_CachedEntList == NULL)
448
449 m_CachedEntList.Clear();
450 }

References m_CachedEntList.

Referenced by GetMeleeTarget().

◆ InitComponentCollisions()

static proto native bool InitComponentCollisions ( Human player,
array< ref ComponentCollisionBox > boxes,
array< ref ComponentCollisionCapsule > capsules )
static

◆ InitPlayerComponentCollisions()

static void InitPlayerComponentCollisions ( Human player)
static

Definition at line 364 of file DayZPlayerUtils.c.

365 {
367 Error("DayZPlayerUtils.InitComponentCollisions: already initialized!");
368
370 b.Insert(new ComponentCollisionBox(0.40, 0.31, 0.31, "Pelvis", "Spine2"));
371 b.Insert(new ComponentCollisionBox(0.40, 0.31, 0.31, "Spine3", "Neck"));
372
374 c.Insert(new ComponentCollisionCapsule(0.11, "Neck1", "Head"));
375 c.Insert(new ComponentCollisionCapsule(0.09, "LeftArm", "LeftArmRoll"));
376 c.Insert(new ComponentCollisionCapsule(0.08, "LeftForeArm", "LeftHand"));
377 c.Insert(new ComponentCollisionCapsule(0.09, "RightArm", "RightArmRoll"));
378 c.Insert(new ComponentCollisionCapsule(0.08, "RightForeArm", "RightHand"));
379 c.Insert(new ComponentCollisionCapsule(0.11, "LeftUpLeg", "LeftUpLegRoll"));
380 c.Insert(new ComponentCollisionCapsule(0.10, "LeftLeg", "LeftFoot"));
381 c.Insert(new ComponentCollisionCapsule(0.11, "RightUpLeg", "RightUpLegRoll"));
382 c.Insert(new ComponentCollisionCapsule(0.10, "RightLeg", "RightFoot"));
383
384 DayZPlayerUtils.InitComponentCollisions(player, b, c);
385 }
static proto native bool IsComponentCollisionInitialized()

References DayZPlayerUtils(), Error(), and IsComponentCollisionInitialized().

◆ IsComponentCollisionInitialized()

IsComponentCollisionInitialized ( )
static
Returns
true if already initialized

Referenced by InitPlayerComponentCollisions().

◆ LinearRangeClamp()

static proto float LinearRangeClamp ( float pValueX,
float pValueY,
float pLimits[] )
static

pLimits in form Xvalue, Ymin, Ymax, Xvalue1, Ymin1, Ymax1, .... sample 0, 0, 5, 1, 2, 3, 2, 0, 1 for X <= 0 it clamps Y to Rangle (0,5) for X == 0.5 it clamps Y to Rangle (1,4) for X == 1 it clamps Y to Rangle (2,3) for X == 1.5 it clamps Y to Rangle (1,2) for X >= 2 it clamps Y to Rangle (0,1)

◆ PhysicsGetEntitiesInBox()

static proto native void PhysicsGetEntitiesInBox ( vector min,
vector max,
notnull out array< EntityAI > entList )
static

returns entities overlapping/touching in AABB box -

◆ PlayerCanChangeStance()

static proto native bool PlayerCanChangeStance ( DayZPlayer pPlayer,
int pTargetStance,
bool forceCheck = false )
static

◆ SceneGetEntitiesInBox()

static proto native void SceneGetEntitiesInBox ( vector min,
vector max,
notnull out array< EntityAI > entList,
int flags = QueryFlags.DYNAMIC )
static

returns entities overlapping/touching in AABB box -

◆ SelectStoreCartridge()

static Magazine SelectStoreCartridge ( DayZPlayer player,
Weapon_Base weapon,
int muzzleIndex,
Magazine exclude_mag,
float damage,
string magTypeName )
static

Definition at line 195 of file DayZPlayerUtils.c.

196 {
197 if (damage < 1.0)
198 {
199 // find suitable heap / mag (but not the excluded one)
201 if (DayZPlayerUtils.FindMagazinesForAmmo(player, magTypeName, mags))
202 {
203 int sz = mags.Count();
204 for (int i = 0; i < sz; ++i)
205 {
206 Magazine mag_i = mags.Get(i);
207 if (mag_i != exclude_mag && mag_i.CanAddCartridges(1))
208 return mag_i;
209 }
210 }
211
212 // create a new one in inventory
214 if (player.GetInventory().FindFirstFreeLocationForNewEntity(magTypeName, FindInventoryLocationType.ANY, inv_loc))
215 {
217 if (eai_inv && eai_inv.IsInherited(Magazine))
218 {
221 {
222 mag_inv.ServerSetAmmoCount(0);
223 return mag_inv;
224 }
225 }
226 }
227 }
228
229 vector pos = player.GetPosition();
230 EntityAI eai_gnd = player.SpawnEntityOnGroundPos(magTypeName, pos);
231 if (eai_gnd && eai_gnd.IsInherited(Magazine))
232 {
235 {
236 mag_gnd.ServerSetAmmoCount(0);
237 return mag_gnd;
238 }
239 }
240
241 return NULL;
242 }

References Class::CastTo(), DayZPlayerUtils(), ECE_IN_INVENTORY, RF_DEFAULT, and SpawnEntity().

Variable Documentation

◆ DYNAMIC

@ DYNAMIC

Dynamic objects are included in the query.

Definition at line 4 of file DayZPlayerUtils.c.

◆ EnableDebugDraw

class ComponentCollisionBox EnableDebugDraw
private

◆ m_CachedEntList

ref array<Object> m_CachedEntList
staticprivate

Definition at line 437 of file DayZPlayerUtils.c.

Referenced by GetMeleeTarget(), and InitCachedEntList().

◆ NONE

@ NONE

Definition at line 0 of file DayZPlayerUtils.c.

◆ ONLY_ROADWAYS

ONLY_ROADWAYS

Only roadways are included in the query.

Definition at line 8 of file DayZPlayerUtils.c.

◆ ORIGIN_DISTANCE

ORIGIN_DISTANCE

Check only distance to object origins, not BB.

Definition at line 6 of file DayZPlayerUtils.c.

◆ STATIC

@ STATIC

Static objects are included in the query.

Definition at line 2 of file DayZPlayerUtils.c.