4 bool m_TransferVariables;
6 bool m_ExcludeQuantity;
7 float m_quantity_override;
14 void SetTransferParams (
bool transfer_agents =
true,
bool transfer_variables =
true,
bool transfer_health =
true,
bool exclude_quantity =
false,
float quantity_override = -1)
16 m_TransferAgents = transfer_agents;
17 m_TransferVariables = transfer_variables;
18 m_TransferHealth = transfer_health;
19 m_ExcludeQuantity = exclude_quantity;
20 m_quantity_override = quantity_override;
25 super.CopyOldPropertiesToNew(old_item, new_item);
29 MiscGameplayFunctions.TransferItemProperties(old_item, new_item, m_TransferAgents, m_TransferVariables, m_TransferHealth, m_ExcludeQuantity);
30 MiscGameplayFunctions.TransferInventory(old_item, new_item,
m_Player);
33 if (
ItemBase.Cast(new_item) && m_quantity_override != -1)
35 m_quantity_override =
Math.Max(m_quantity_override,0);
36 ItemBase.Cast(new_item).SetQuantity(m_quantity_override);
41 Debug.LogError(
"TurnItemIntoItemLambda: failed to create new item",
"static");
46 override void VerifyItemTypeBySlotType ()
48 if (m_NewLocation.GetType() ==
InventoryLocationType.ATTACHMENT && m_OldItem.ConfigIsExisting(
"ChangeIntoOnAttach"))
56 m_OldItem.ConfigGetTextArray(
"ChangeInventorySlot",inventory_slots);
57 if (inventory_slots.Count() < 1)
59 inventory_slots_idx.Insert(
InventorySlots.GetSlotIdFromString(m_OldItem.ConfigGetString(
"ChangeInventorySlot")));
60 attach_types.Insert(m_OldItem.ConfigGetString(
"ChangeIntoOnAttach"));
64 inventory_slots_idx.Clear();
65 for (
int i = 0; i < inventory_slots.Count(); i++)
67 inventory_slots_idx.Insert(
InventorySlots.GetSlotIdFromString(inventory_slots.Get(i)));
69 m_OldItem.ConfigGetTextArray(
"ChangeIntoOnAttach",attach_types);
72 idx = m_NewLocation.GetSlot();
73 str = attach_types.Get(inventory_slots_idx.Find(idx));
81 override void OnSuccess (
EntityAI new_item)
83 super.OnSuccess(new_item);
86 m_Player.GetItemAccessor().OnItemInHandsChanged();
95 super.OnSuccess(new_item);
98 m_Player.GetItemAccessor().OnItemInHandsChanged();
103 class TurnItemIntoItemLambdaRestrainLambda
extends TurnItemIntoItemLambdaAnimSysNotifyLambda
107 super.OnSuccess(new_item);
124 override void CopyOldPropertiesToNew (notnull
EntityAI old_item,
EntityAI new_item)
126 super.CopyOldPropertiesToNew(old_item, new_item);
132 int count = children.Count();
133 for (
int i = 0; i < count; i++)
139 child.GetInventory().GetCurrentInventoryLocation(child_src);
145 Math3D.MatrixIdentity4(m4);
148 GameInventory.PrepareDropEntityPos(old_item, child, m4,
false, -1);
150 child_dst.SetGround(child,m4);
152 m_Player.LocalTakeToDst(child_src, child_dst);
154 GetGame().RemoteObjectTreeCreate(child);
172 if (new_item_type !=
string.
Empty)
173 Error(
"MoveEquipAndDestroyRootLambda expects new_item_type to be empty");
178 super.RemoveNetworkObjectInfo();
183 super.UndoRemoveNetworkObjectInfo();
190 super.CopyOldPropertiesToNew(old_item, new_item);
197 super.CreateNetworkObjectInfo(new_item);
213 class MiscGameplayFunctions
216 static float Truncate(
float value,
int decimals = 2)
218 int multiplier =
Math.Pow(10,decimals);
219 return Math.Clamp(
Math.Floor(value * multiplier),
float.LOWEST,
float.MAX) / multiplier;
222 static string TruncateToS(
float value,
int decimals = 2)
224 return Truncate(value, decimals).ToString();
227 static vector TruncateVec(
vector value,
int decimals = 2)
229 int multiplier =
Math.Pow(10,decimals);
230 float v1 =
Math.Clamp(
Math.Floor(value[0] * multiplier),
float.LOWEST,
float.MAX) / multiplier;
231 float v2 =
Math.Clamp(
Math.Floor(value[1] * multiplier),
float.LOWEST,
float.MAX) / multiplier;
232 float v3 =
Math.Clamp(
Math.Floor(value[2] * multiplier),
float.LOWEST,
float.MAX) / multiplier;
236 static string TruncateVecToS(
vector value,
int decimals = 2,
string delimiter =
" ")
238 return MiscGameplayFunctions.TruncateToS(value[0],decimals) + delimiter + MiscGameplayFunctions.TruncateToS(value[1],decimals) +delimiter + MiscGameplayFunctions.TruncateToS(value[2],decimals));
243 return string.Format(
"#(argb,8,8,3)color(%1,CO)",
string.Format(
"%1,%2,%3,%4", r, g, b, a));
247 static string ValueToBar(
float value,
string bar =
"[----------]",
string mark =
"x")
249 int length = bar.Length() - 2;
250 float index =
Math.Lerp(0,length, value);
251 index =
Math.Round(index);
252 index =
Math.Clamp(index,0,length);
254 return InsertAtPos(bar,mark,index);
258 static string InsertAtPos(
string base,
string insert,
int pos)
260 int length_first = pos+1;
261 int length_base = base.Length();
262 int length_second = length_base - length_first;
263 string first = base.Substring(0,length_first);
264 string second = base.Substring(pos+1,length_second);
265 return first + insert + second;
269 static void TransferItemProperties(
EntityAI source, notnull
EntityAI target,
bool transfer_agents =
true,
bool transfer_variables =
true,
bool transfer_health =
true,
bool exclude_quantity =
false)
274 if( transfer_agents ) target_ib.TransferAgents( source.GetAgents() );
276 if( transfer_variables )
278 MiscGameplayFunctions.TransferItemVariables(source_ib, target_ib, exclude_quantity);
283 if( transfer_health )
284 target_ib.SetHealth01(
"",
"", source.GetHealth01(
"",
""));
288 static void TransferItemVariables(
ItemBase source,
ItemBase target,
bool exclude_quantity =
false)
290 target.TransferVariablesFloat( source.GetVariablesFloat() );
292 if ( exclude_quantity )
296 else if ( source.IsMagazine() && target.IsMagazine() )
298 Magazine source_mag = Magazine.Cast(source);
299 Magazine target_mag = Magazine.Cast(target);
301 target_mag.ServerSetAmmoCount( source_mag.GetAmmoCount() );
304 if ( source.IsWeapon() && target.IsWeapon() )
309 target_wpn.CopyWeaponStateFrom(source_wpn);
311 else if ( source.HasEnergyManager() && target.HasEnergyManager() )
316 emt.SetEnergy(ems.GetEnergy());
318 if (ems.IsSwitchedOn())
321 else if ( source.CanDecay() && target.CanDecay() )
326 target_edb.TransferFoodStage(source_edb);
336 int count = children.Count();
337 for (
int i = 0; i < count; i++)
343 child.GetInventory().GetCurrentInventoryLocation( child_src );
346 child_dst.Copy( child_src );
347 child_dst.SetParent( targetItem );
354 targetItem.GetInventory().TakeToDst(
InventoryMode.LOCAL, child_src, child_dst);
363 player.LocalDropEntity(child);
364 GetGame().RemoteObjectTreeCreate(child);
372 static void UnlimitedAmmoDebugCheck(
Weapon_Base weapon)
379 magazine = weapon.GetMagazine(weapon.GetCurrentMuzzle());
383 if (magazine.GetAmmoCount() <= 5)
385 magazine.ServerSetAmmoMax();
391 magazine = weapon.GetMagazine(weapon.GetCurrentMuzzle());
395 if (magazine.GetAmmoCount() <= 5)
397 magazine.LocalSetAmmoMax();
407 static void TurnItemIntoItem (notnull
ItemBase old_item,
string new_item_type, notnull
PlayerBase player)
414 player.ServerReplaceItemWithNew(lambda);
417 static void TurnItemInHandsIntoItem (notnull
ItemBase old_item,
string new_item_type, notnull
PlayerBase player)
424 player.ServerReplaceItemInHandsWithNew(lambda);
428 static array<ItemBase> CreateItemBasePiles(
string item_name,
vector ground_position,
float quantity,
float health,
bool floaty_spawn =
false)
431 float max_stack_size;
435 max_stack_size =
g_Game.ConfigGetInt(
"cfgVehicles " + item_name +
" varStackMax");
436 if( max_stack_size < 1)
437 max_stack_size =
g_Game.ConfigGetInt(
"cfgVehicles " + item_name +
" varQuantityMax");
438 if( max_stack_size < 1)
441 int full_piles_count =
Math.Floor(quantity/max_stack_size);
442 int rest = quantity - (full_piles_count*max_stack_size);
444 for (
int i = 0; i < full_piles_count; i++ )
450 pile.SetQuantity(max_stack_size);
451 pile.SetHealth(health);
452 item_piles.Insert(pile);
460 pile.SetQuantity(rest);
461 pile.SetHealth(health);
462 item_piles.Insert(pile);
467 static array<Magazine> CreateMagazinePiles(
string item_name,
vector ground_position,
float quantity,
float health )
474 stack_size =
g_Game.ConfigGetInt(
"cfgMagazines " + item_name +
" count");
476 int piles_count =
Math.Floor(quantity/stack_size);
477 int rest = quantity - (piles_count*stack_size);
479 for (
int i = 0; i < piles_count; i++ )
482 pile.ServerSetAmmoCount(stack_size);
488 pile.ServerSetAmmoCount(rest);
494 static array<Magazine> CreateMagazinePilesFromBullet(
string bullet_type,
vector ground_position,
float quantity,
float health )
501 if( !
g_Game.ConfigGetText(
"cfgAmmo " + bullet_type +
" spawnPileType", item_name) )
504 stack_size =
g_Game.ConfigGetInt(
"cfgMagazines " + item_name +
" count");
508 int piles_count =
Math.Floor(quantity/stack_size);
509 int rest = quantity - (piles_count*stack_size);
511 for (
int i = 0; i < piles_count; i++ )
514 pile.ServerSetAmmoCount(stack_size);
520 pile.ServerSetAmmoCount(rest);
527 static int GetHealthLevelForAmmo(
string class_name,
float health)
529 float health_normalized = health / 100;
543 static float GetTypeMaxGlobalHealth(
string class_name,
string health_type =
"Health")
560 cfg_path = cfg_path +
" "+
class_name+
" DamageSystem GlobalHealth " + health_type +
" hitpoints";
561 max_health =
GetGame().ConfigGetFloat(cfg_path);
568 vector usti_hlavne_position = weapon.GetSelectionPositionMS(
"usti hlavne" );
569 vector konec_hlavne_position = weapon.GetSelectionPositionMS(
"konec hlavne" );
570 vector end_point = weapon.ModelToWorld(usti_hlavne_position);
571 vector begin_point = weapon.ModelToWorld(konec_hlavne_position);
573 int contact_component;
575 vector aim_point = end_point - begin_point;
577 aim_point = aim_point + end_point;
579 if (
DayZPhysics.RaycastRV(begin_point, aim_point, position, contact_dir, contact_component,
null,
null,
null,
false,
false, ObjIntersectFire))
587 int headBoneIdx = player.GetBoneIndexByName(
"Head");
588 if ( headBoneIdx == -1 )
589 { pos = player.GetPosition()[1] + 1.6; }
591 { pos = player.GetBonePositionWS(headBoneIdx); }
597 float headingAngle = GetHeadingAngle(player);
598 dir[0] =
Math.Cos(headingAngle +
Math.PI_HALF);
599 dir[2] =
Math.Sin(headingAngle +
Math.PI_HALF);
601 return dir.Normalized();
607 float headingAngle = hic.GetHeadingAngle();
612 static float GetEnergyMetabolicSpeed(
int movement_speed)
615 switch (movement_speed)
635 static float GetWaterMetabolicSpeed(
int movement_speed)
638 switch (movement_speed)
658 static string ObtainRestrainItemTargetClassname(notnull
EntityAI entity)
660 return entity.ConfigGetString(
"OnRestrainChange");
670 type = tool.ConfigGetBool(
"RestrainUnlockType");
672 string new_item_name = current_item.ConfigGetString(
"OnRestrainChange");
674 if ( new_item_name !=
"" )
678 if (player_target.IsAlive())
679 MiscGameplayFunctions.TurnItemIntoItemEx(player_target,
new ReplaceAndDestroyLambdaEx(current_item, new_item_name, player_target, type));
685 MiscGameplayFunctions.TurnItemIntoItemEx(player_target,
new ReplaceAndDestroyLambdaEx(current_item, new_item_name, player_target, type));
690 Error(
"current_item:" +current_item+
", tool:" +tool +
". No value for 'OnRestrainChange' config parameter");
694 static bool IsValueInRange(
float value,
float from,
float to)
696 return (value >= from) && (value <= to);
704 vector player_dir = player.GetDirection();
705 vector to_target_dir = target_pos - player.GetPosition();
708 to_target_dir[1] = 0;
710 player_dir.Normalize();
711 to_target_dir.Normalize();
713 float cos_fi =
vector.Dot(player_dir, to_target_dir);
714 vector cross = player_dir * to_target_dir;
716 int dir =
Math.Acos(cos_fi) *
Math.RAD2DEG;
722 if( (dir <= cone_angle && dir >= -cone_angle) ||
Math.AbsFloat(dir) == 90 )
732 static string SanitizeString(
string input)
734 int max_length = 512;
735 string output = input;
737 output = output.Substring(0,
Math.Clamp(max_length,0,output.Length()));
752 Construction construction = base_building.GetConstruction();
753 if (construction && BuildCondition( player, target, item,
false, constraction_index ))
759 partName = construction_action_data.GetBuildPartAtIndex(constraction_index).GetPartName();
763 partName = construction_action_data.GetBuildPartNoToolAtIndex(constraction_index).GetPartName();
766 if (base_building.PerformRoofCheckForBase(partName,player,boo) && boo)
768 if ( player.IsPlacingLocal() || player.IsPlacingServer() )
777 return !construction.IsColliding( partName );
791 Object targetObject = target.GetObject();
792 if ( targetObject && targetObject.CanUseConstruction() )
796 construction_action_data.SetTarget( targetObject );
801 constrution_part = construction_action_data.GetBuildPartAtIndex(constraction_index);
805 constrution_part = construction_action_data.GetBuildPartNoToolAtIndex(constraction_index);
817 if ( constrution_part )
820 bool position_check = ( base_building.MustBeBuiltFromOutside() && !base_building.IsPlayerInside(player, constrution_part.GetMainPartName()) ) || ( !base_building.MustBeBuiltFromOutside() && base_building.IsPlayerInside(player, constrution_part.GetMainPartName()) );
821 if ( position_check && !player.GetInputController().CameraIsFreeLook() )
828 return !base_building.IsFacingCamera( constrution_part.GetMainPartName() );
843 entity.GetCollisionBox(minMax);
847 float from_override = entity.HeightStartCheckOverride();
848 if (from_override > 0.0)
850 size[1] = from_override;
854 size[1] = minMax[1][1] - minMax[0][1];
857 from = entity.GetPosition() + size;
858 if ( entity.HeightCheckOverride() > 0 )
860 to = entity.GetPosition() +
Vector(0, entity.HeightCheckOverride(), 0);
872 return IsUnderRoofEx(entity, height, ObjIntersectView);
875 static bool IsUnderRoofEx(
EntityAI entity,
float height =
GameConstants.ROOF_CHECK_RAYCAST_DIST,
int geometry = ObjIntersectView)
880 IsUnderRoofFromToCalculation(entity, from, to, height);
885 int contact_component;
887 bool boo =
DayZPhysics.RaycastRV( from, to, contact_pos, contact_dir, contact_component, NULL, NULL, entity,
false,
false, geometry,0.25 );
907 float steam_offset = 0;
911 particle_pos = parent.GetPosition();
913 if ( parent.IsInherited( PortableGasStove ) )
921 if ( fireplace.IsBaseFireplace() )
925 else if ( fireplace.IsBarrelWithHoles() )
929 else if ( fireplace.IsFireplaceIndoor() )
933 else if ( fireplace.IsIndoorOven() )
940 particle_pos[1] = particle_pos[1] + steam_offset;
945 static void DropAllItemsInInventoryInBounds(
ItemBase ib,
vector halfExtents)
952 vector direction = ib.GetDirection();
955 float angle =
Math.Acos(dot);
956 if (direction[0] < 0)
959 float cos =
Math.Cos(angle);
960 float sin =
Math.Sin(angle);
963 int count = items.Count();
964 for (
int i = 0; i < count; ++i )
968 ib.GetInventory().DropEntityInBounds(
InventoryMode.SERVER, ib, item, halfExtents, angle, cos, sin);
972 static void ThrowAllItemsInInventory(notnull
EntityAI parent,
int flags)
974 vector position = parent.GetPosition();
975 vector orientation = parent.GetOrientation();
976 vector rotation_matrix[3];
980 parent.GetCollisionBox(minmax);
982 Math3D.YawPitchRollMatrix( orientation, rotation_matrix );
983 Math3D.MatrixToQuat( rotation_matrix, direction );
986 for (
int i = 0; i < parent.GetInventory().AttachmentCount(); ++i )
988 randomPos =
Vector(position[0] +
Math.RandomFloat(minmax[0][0], minmax[1][0]),
989 position[1] +
Math.RandomFloat(minmax[0][1], minmax[1][1]),
990 position[2] +
Math.RandomFloat(minmax[0][2], minmax[1][2]));
992 ThrowEntityFromInventory(parent.GetInventory().GetAttachmentFromIndex( i ), randomPos, direction, -
GetVelocity(parent),
ThrowEntityFlags.NONE);
995 for (
int j = 0; j < parent.GetInventory().GetCargo().GetItemCount(); ++j )
997 randomPos =
Vector(position[0] +
Math.RandomFloat(minmax[0][0], minmax[1][0]),
998 position[1] +
Math.RandomFloat(minmax[0][1], minmax[1][1]),
999 position[2] +
Math.RandomFloat(minmax[0][2], minmax[1][2]));
1001 ThrowEntityFromInventory(parent.GetInventory().GetCargo().GetItem( j ), randomPos, direction, -
GetVelocity(parent),
ThrowEntityFlags.NONE);
1005 static void ThrowEntityFromInventory(notnull
EntityAI entity,
vector position,
float direction[4],
vector force,
int flags)
1008 if ( !
GetGame().IsMultiplayer() )
1012 if (CastTo(entityIB, entity))
1015 dst.SetGroundEx(entity, position, direction);
1019 for (
int l = 0; l < entityIB.GetQuantity(); ++l)
1025 MiscGameplayFunctions.TransferItemProperties(entityIB, new_item);
1026 entityIB.AddQuantity( -1 );
1027 new_item.SetQuantity( 1 );
1028 new_item.ThrowPhysically(
null, force,
false);
1034 float stackable = entityIB.GetTargetQuantityMax();
1035 if ( !(stackable == 0 || stackable >= entityIB.GetQuantity()) )
1037 while (entityIB.GetQuantity() > stackable)
1040 position[1] = position[1] + 0.1;
1041 spltDst.SetGroundEx(entity, position, direction);
1043 ItemBase splitItem = entityIB.SplitIntoStackMaxToInventoryLocationEx( spltDst );
1044 splitItem.ThrowPhysically(
null, force,
false);
1049 entity.GetInventory().GetCurrentInventoryLocation(src);
1051 entity.GetInventory().TakeToDst(invMode, src, dst);
1052 entityIB.ThrowPhysically(
null, force,
false);
1057 entity.GetInventory().DropEntity(invMode, entity.GetHierarchyRoot(), entity);
1062 static float GetCurrentItemHeatIsolation(
ItemBase pItem )
1067 float heatIsolation = pItem.GetHeatIsolation();
1068 float itemHealthLabel = pItem.GetHealthLevel();
1069 float itemWetness = pItem.GetWet();
1086 wetFactor =
GameConstants.ENVIRO_ISOLATION_WETFACTOR_SOAKED;
1090 wetFactor =
GameConstants.ENVIRO_ISOLATION_WETFACTOR_DRENCHED;
1094 switch (itemHealthLabel)
1097 healthFactor =
GameConstants.ENVIRO_ISOLATION_HEALTHFACTOR_PRISTINE;
1101 healthFactor =
GameConstants.ENVIRO_ISOLATION_HEALTHFACTOR_WORN;
1105 healthFactor =
GameConstants.ENVIRO_ISOLATION_HEALTHFACTOR_DAMAGED;
1109 healthFactor =
GameConstants.ENVIRO_ISOLATION_HEALTHFACTOR_B_DAMAGED;
1113 healthFactor =
GameConstants.ENVIRO_ISOLATION_HEALTHFACTOR_RUINED;
1118 heatIsolation *= healthFactor;
1119 heatIsolation *= wetFactor;
1121 return heatIsolation;
1126 if (!obstructingObjects)
1129 for (
int i = 0; i < potentiallyObstructingObjects.Count(); ++i )
1131 Object obj = potentiallyObstructingObjects[i];
1132 if ( obj && ( obj.CanObstruct() || obj.CanProxyObstruct() ) )
1133 obstructingObjects.Insert(obj);
1137 static bool CanIgnoreDistanceCheck(
Object obj)
1139 return obj.IsTransport() || obj.CanUseConstruction();
1143 static void FilterObstructedObjectsByGrouping(
vector origin,
float range,
float distanceDelta,
array<Object> objects,
array<Object> obstructingObjects, out
array<Object> filteredObjects,
bool doDistanceCheck =
false,
bool checkIfDistanceCanBeIgnored =
false,
float maxDist = 0)
1146 vicinityObjects.Copy(objects);
1151 int mCount = vicinityObjects.Count();
1153 if (!filteredObjects)
1157 if ( doDistanceCheck )
1159 for ( i = vicinityObjects.Count() - 1; i >= 0; --i )
1161 Object obj = vicinityObjects[i];
1162 if ( obj && !CanIgnoreDistanceCheck( obj ) &&
vector.DistanceSq(origin, obj.GetPosition()) > maxDist * maxDist )
1163 vicinityObjects.Remove(i);
1171 float distance, dist1, dist2;
1173 for ( i = 0; i < obstructingObjects.Count(); ++i )
1175 distance =
vector.DistanceSq(obstructingObjects[i].GetWorldPosition(), origin);
1176 distanceHelper.Insert(distance);
1179 distanceHelperUnsorted.Copy(distanceHelper);
1180 distanceHelper.Sort();
1182 for ( i = distanceHelper.Count() - 1; i >= 0; --i )
1183 sortedObstructingObjects.Insert(obstructingObjects[distanceHelperUnsorted.Find(distanceHelper[i])]);
1189 float cos =
Math.Cos(90);
1190 float sin =
Math.Sin(90);
1193 for ( i = 0; i < sortedObstructingObjects.Count(); ++i )
1195 Object obstrObj = sortedObstructingObjects[i];
1196 vector worldPos = obstrObj.GetWorldPosition();
1199 if ( obstrObj.GetCollisionBox(minMax) )
1203 max = max * (obstrObj.GetOrientation() * range);
1205 vector center, dx, dy, dz, half;
1206 center = (min + max) * 0.5;
1207 dz = obstrObj.GetOrientation();
1209 dy =
vector.RotateAroundZero(dz,
vector.Aside, cos, sin);
1210 half = (max - min) * 0.5;
1211 half =
Vector(
Math.AbsFloat(half[0]),
Math.AbsFloat(half[1]),
Math.AbsFloat(half[2]));
1216 for ( j = vicinityObjects.Count() - 1; j >= 0; --j )
1218 Object vicObj = vicinityObjects[j];
1221 vector d = vicObj.GetWorldPosition() - worldPos + center;
1224 group.Insert(vicObj);
1225 vicinityObjects.Remove(j);
1230 if ( group.Count() > 0 )
1231 tempGroups.Insert(group);
1236 for ( i = 0; i < tempGroups.Count(); ++i )
1237 SplitArrayIntoGroupsByDistance(tempGroups[i], objectGroups, distanceDelta);
1240 SplitArrayIntoGroupsByDistance(vicinityObjects, objectGroups, distanceDelta);
1244 for ( i = 0; i < objectGroups.Count(); ++i )
1247 Object sampleObject = objectGroup[0];
1249 if ( !IsObjectObstructedEx(sampleObject, cache) )
1250 filteredObjects.InsertAll(objectGroup);
1259 for (
int i = 0; i < objects.Count(); )
1261 Object obj1 = objects[i];
1266 for (
int j = objects.Count() - 1; j > i; --j )
1268 Object obj2 = objects[j];
1271 vector start = obj1.GetWorldPosition();
1272 vector end = obj2.GetWorldPosition();
1274 float distance =
vector.DistanceSq(start, end);
1275 if ( distance < squaredDistanceDelta )
1282 objectGroups.Insert(group);
1290 static bool IsObjectObstructed(
Object object,
bool doDistanceCheck =
false,
vector distanceCheckPos =
"0 0 0",
float maxDist = 0)
1296 return IsObjectObstructedEx(
object, cache, doDistanceCheck, distanceCheckPos, maxDist);
1305 if (doDistanceCheck &&
vector.DistanceSq(player.GetPosition(), distanceCheckPos) > maxDist * maxDist)
1308 cache.ObjectCenterPos =
object.GetCenter();
1310 return IsObjectObstructedFilterEx(
object, cache, player);
1315 if (
object.CanProxyObstruct())
1318 DayZPhysics.RaycastRVProxy(rayInput, cache.HitProxyObjects);
1319 if (cache.HitProxyObjects)
1321 if (cache.HitProxyObjects.Count() > 0)
1323 if (cache.HitProxyObjects[0].hierLevel > 0)
1326 if (!cache.HitProxyObjects[0].parent.IsMan())
1328 if (cache.HitProxyObjects[0].parent)
1331 if (proxyParent.GetInventory() && proxyParent.GetInventory().GetCargo())
1344 for (
int m = 0; m < cache.HitObjects.Count(); m++ )
1346 Object hit_object = cache.HitObjects.Get(m);
1348 if ( hit_object.CanObstruct() )
1375 if (geometryTypeOverride != -1)
1376 rayInput.type = geometryTypeOverride;
1377 DayZPhysics.RaycastRVProxy(rayInput, cache.HitProxyObjects);
1381 if (cache.HitProxyObjects)
1383 count = cache.HitProxyObjects.Count();
1385 for (i = 0; i < count; i++)
1387 if (cache.HitProxyObjects[i].hierLevel > 0)
1389 parent = cache.HitProxyObjects[i].parent;
1390 if (parent && !parent.IsMan() && parent.CanProxyObstruct())
1392 if (parent !=
object || (parent ==
object &&
object.CanProxyObstructSelf()))
1400 int geometry = ObjIntersectFire;
1401 if (geometryTypeOverride != -1)
1402 geometry = geometryTypeOverride;
1403 DayZPhysics.RaycastRV(cache.RaycastStart, cache.ObjectCenterPos, cache.ObjectContactPos, cache.ObjectContactDir, cache.ContactComponent, cache.HitObjects,
object,
GetGame().
GetPlayer(),
false,
false, geometry, 0.0,
CollisionFlags.ALLOBJECTS);
1404 count = cache.HitObjects.Count();
1405 for (i = 0; i < count; i++ )
1407 if (cache.HitObjects[i].CanObstruct())
1415 static void DealAbsoluteDmg(
ItemBase item,
float dmg)
1417 item.DecreaseHealth(dmg,
false);
1421 static float Normalize(
int val,
int maxVal)
1425 Debug.LogError(
"Division by 0 is not allowed");
1429 return val / maxVal;
1432 static float Bobbing(
float period,
float amplitude,
float elapsedTime)
1438 elapsedTime /= period;
1441 cycle += elapsedTime;
1442 cycle = FModulus(cycle, 360);
1443 cycle =
Math.Sin(cycle) * amplitude;
1449 static float FModulus(
float x,
float y)
1451 return Math.ModFloat(
x,
y);
1454 static void RemoveSplint(
PlayerBase player )
1456 EntityAI entity = player.GetInventory().CreateInInventory(
"Splint");
1458 entity = player.SpawnEntityOnGroundOnCursorDir(
"Splint", 0.5);
1462 Class.CastTo(attachment, player.GetItemOnSlot(
"Splint_Right"));
1463 if ( attachment && attachment.GetType() ==
"Splint_Applied" )
1467 MiscGameplayFunctions.TransferItemProperties(attachment,new_item);
1472 if (new_item.GetHealthLevel() < 4)
1474 int newDmgLevel = new_item.GetHealthLevel() + 1;
1476 float max = new_item.GetMaxHealth(
"",
"");
1478 switch ( newDmgLevel )
1481 new_item.SetHealth(
"",
"", max *
GameConstants.DAMAGE_BADLY_DAMAGED_VALUE );
1485 new_item.SetHealth(
"",
"", max *
GameConstants.DAMAGE_DAMAGED_VALUE );
1489 new_item.SetHealth(
"",
"", max *
GameConstants.DAMAGE_WORN_VALUE );
1493 new_item.SetHealth(
"",
"", max *
GameConstants.DAMAGE_RUINED_VALUE );
1503 attachment.Delete();
1510 if( player.GetSimulationTimeStamp() < 20 && !player.IsPersistentFlag(
PersistentFlag.AREA_PRESENCE) )
1515 vector player_pos = player.GetPosition();
1516 vector closest_safe_pos = MiscGameplayFunctions.GetClosestSafePos(player_pos, safe_positions);
1518 if (player_pos!=closest_safe_pos)
1520 closest_safe_pos[1] =
GetGame().SurfaceY(closest_safe_pos[0], closest_safe_pos[2]);
1522 player.SetPosition( closest_safe_pos );
1524 GetGame().RPCSingleParam(player,
ERPCs.RPC_WARNING_TELEPORT,
null,
true, player.GetIdentity());
1534 vector closest_pos = to_pos;
1535 float smallest_dist =
float.MAX;
1543 float dist =
vector.DistanceSq(to_pos, vpos);
1544 if ( dist < smallest_dist)
1546 smallest_dist = dist;
1553 static void GenerateAINoiseAtPosition(
vector position,
float lifeTime,
NoiseParams noiseParams)
1560 noise.AddNoiseTarget(position, lifeTime, noiseParams);
1567 float minValue = 0.0;
1568 for (
int i = 0; i < pArray.Count(); i++)
1570 if (minValue == 0 || pArray.Get(i) < minValue)
1572 minValue = pArray.Get(i);
1581 float maxValue = 0.0;
1582 for (
int i = 0; i < pArray.Count(); i++)
1584 if (maxValue == 0 || pArray.Get(i) > maxValue)
1586 maxValue = pArray.Get(i);
1593 static string GetItemDisplayName(
string type)
1595 return GetGame().ConfigGetTextOut(
"CfgVehicles " + type +
" displayName");
1598 static bool IsComponentInSelection(
array<Selection> pSelection,
string pCompName)
1600 if (pSelection.Count() == 0 || pCompName.Length() == 0)
1605 for (
int i = 0; i < pSelection.Count(); ++i)
1607 pCompName.ToLower();
1608 if (pSelection[i] && pSelection[i].
GetName() == pCompName)
1619 if (!MiscGameplayFunctions.IsComponentInSelection(pSelection, pCompName))
1624 for (
int i = 0; i < pSelection.Count(); ++i)
1626 pCompName.ToLower();
1627 if (pSelection[i] && pSelection[i].
GetName() == pCompName)
1638 if (listOfTypenames.Count() > 0)
1643 Object childToRemove = child;
1644 child =
Object.Cast(child.GetSibling());
1646 if (childToRemove.IsAnyInherited(listOfTypenames))
1648 vector pos = childToRemove.GetPosition();
1649 parent.RemoveChild(childToRemove,
false);
1652 Math3D.MatrixIdentity4(m4);
1654 childToRemove.SetTransform(m4);
1655 childToRemove.PlaceOnSurface();
1663 IEntity child = parent.GetChildren();
1666 outputObjects.Insert(child);
1667 child = child.GetSibling();
1671 static void SoakItemInsideParentContainingLiquidAboveThreshold(notnull
ItemBase item, notnull
ItemBase parent,
float liquidQuantityThresholdPercentage = 0.05)
1675 if (parent.GetLiquidType() != 0 && parent.GetQuantityNormalized() > liquidQuantityThresholdPercentage)
1689 old_item.GetTransform(mtx);
1691 player.GetTransform(mtx);
1692 gnd.SetGround(NULL, mtx);
1693 OverrideNewLocation(gnd);
1696 protected override void RemoveOldItemFromLocation()
1698 super.RemoveOldItemFromLocation();
1699 m_Player.GetHumanInventory().OnEntityInHandsDestroyed(m_OldLocation);