Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_PlaceableInventoryItemComponent.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted/Components", description: "")]
3 {
4 }
5 
6 class SCR_PlaceableInventoryItemComponent : SCR_BaseInventoryItemComponent
7 {
8  [Attribute("1")]
9  protected bool m_bSnapToGround;
10 
11  [Attribute("1", "Only works with Snap to ground")]
12  protected bool m_bAlignToNormal;
13 
14  protected vector m_vMat[4];
15  protected bool m_bUseTransform = false;
16 
17  //------------------------------------------------------------------------------------------------
20  // To be overridden, called when placement is done in SCR_ItemPlacementComponent
21  void PlacementDone(notnull IEntity user);
22 
23  //------------------------------------------------------------------------------------------------
29  [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
30  void RPC_DoPlaceItem(vector right, vector up, vector forward, vector position)
31  {
32  IEntity item = GetOwner();
33  InventoryItemComponent itemComponent = InventoryItemComponent.Cast(item.FindComponent(InventoryItemComponent));
34  if (!itemComponent)
35  return;
36 
37  itemComponent.EnablePhysics();
38  itemComponent.ActivateOwner(true);
39 
40  m_vMat[0] = right;
41  m_vMat[1] = up;
42  m_vMat[2] = forward;
43  m_vMat[3] = position;
44  m_bUseTransform = true;
45  }
46 
47  //------------------------------------------------------------------------------------------------
53  void PlaceItem(vector right, vector up, vector forward, vector position)
54  {
55  Rpc(RPC_DoPlaceItem, right, up, forward, position);
56  RPC_DoPlaceItem(right, up, forward, position);
57  }
58 
59  //------------------------------------------------------------------------------------------------
65  void SnapToGround(out vector normal, array<IEntity> excludeArray = null, float maxLength = 10, vector startOffset = "0 0 0", vector direction = -vector.Up)
66  {
67  IEntity owner = GetOwner();
68  vector origin = owner.GetOrigin();
69 
70  // Trace against terrain and entities to detect nearest ground
71  TraceParam param = new TraceParam();
72  param.Start = origin + startOffset;
73  param.End = origin + direction * maxLength;
74  param.Flags = TraceFlags.WORLD | TraceFlags.ENTS;
75 
76  if (excludeArray)
77  {
78  excludeArray.Insert(owner);
79  param.ExcludeArray = excludeArray;
80  }
81  else
82  param.Exclude = owner;
83 
84  param.LayerMask = EPhysicsLayerPresets.Projectile;
85  BaseWorld world = owner.GetWorld();
86  float traceDistance;
87 
88  traceDistance = world.TraceMove(param, FilterCallback);
89 
90  if (float.AlmostEqual(traceDistance, 1.0))
91  return;
92 
93  normal = param.TraceNorm;
94 
95  owner.SetOrigin(traceDistance * (param.End - param.Start) + param.Start);
96  }
97 
98  //------------------------------------------------------------------------------------------------
102  bool ValidateEntity(notnull IEntity entity)
103  {
104  Physics physics = entity.GetPhysics();
105  if (physics && (physics.IsDynamic() || physics.IsKinematic()))
106  return false;
107 
108  // F. e. Slotted vehicle parts are physically static, but their main parent (vehicle) is not, we need to check that
109  IEntity mainEntity = SCR_EntityHelper.GetMainParent(entity);
110  if (mainEntity && mainEntity != entity)
111  {
112  physics = mainEntity.GetPhysics();
113  if (physics && physics.IsDynamic())
114  return false;
115  }
116 
117  return true;
118  }
119 
120  //------------------------------------------------------------------------------------------------
124  bool FilterCallback(notnull IEntity e)
125  {
126  Physics physics = e.GetPhysics();
127  if (physics)
128  {
129  if (physics.GetInteractionLayer() & EPhysicsLayerDefs.Water)
130  return true;
131  }
132 
133  return ValidateEntity(e);
134  }
135 
136  //------------------------------------------------------------------------------------------------
137  override bool OverridePlacementTransform(IEntity caller, out vector computedTransform[4])
138  {
139  ActivateOwner(true);
140 
141  IEntity owner = GetOwner();
142  owner.Update();
143 
144  // Enable physics to receive contact events
145  Physics physics = owner.GetPhysics();
146  if (physics)
147  EnablePhysics();
148 
149  if (m_bUseTransform)
150  {
151  // Entity was purposefully "placed" somewhere so we assume it should stay there (e.g. mines and flags to mark them)
152  auto garbageSystem = SCR_GarbageSystem.GetByEntityWorld(owner);
153  if (garbageSystem)
154  garbageSystem.Withdraw(owner);
155 
156  Math3D.MatrixCopy(m_vMat, computedTransform);
157  m_bUseTransform = false;
158  return true;
159  }
160 
161  if (m_bSnapToGround)
162  {
163  caller.GetTransform(computedTransform);
164  vector normal = vector.Up;
165  SnapToGround(normal, {caller});
166  computedTransform[3] = owner.GetOrigin();
167 
168  if (m_bAlignToNormal)
169  SCR_EntityHelper.OrientUpToVector(normal, computedTransform);
170 
171  return true;
172  }
173 
174  return false;
175  }
176 }
direction
vector direction
Definition: SCR_DestructibleTreeV2.c:31
Attribute
SCR_PlaceableInventoryItemComponentClass SCR_BaseInventoryItemComponentClass Attribute("1")
Definition: SCR_PlaceableInventoryItemComponent.c:8
SCR_EntityHelper
Definition: SCR_EntityHelper.c:1
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
OverridePlacementTransform
override bool OverridePlacementTransform(IEntity caller, out vector computedTransform[4])
Definition: SCR_PlaceableInventoryItemComponent.c:137
SCR_BaseInventoryItemComponentClass
Definition: SCR_BaseInventoryItemComponent.c:1
RplRpc
SCR_AchievementsHandlerClass ScriptComponentClass RplRpc(RplChannel.Reliable, RplRcver.Owner)] void UnlockOnClient(AchievementId achievement)
Definition: SCR_AchievementsHandler.c:11
SCR_PlaceableInventoryItemComponentClass
Definition: SCR_PlaceableInventoryItemComponent.c:2
ValidateEntity
bool ValidateEntity(notnull IEntity entity)
Definition: SCR_PlaceableInventoryItemComponent.c:102
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
SCR_GarbageSystem
Script entry for garbage system modding.
Definition: SCR_GarbageSystem.c:2
InventoryItemComponent
Definition: InventoryItemComponent.c:12
FilterCallback
bool FilterCallback(notnull IEntity e)
Definition: SCR_PlaceableInventoryItemComponent.c:124
PlacementDone
override void PlacementDone(notnull IEntity user)
Definition: SCR_MineInventoryItemComponent.c:11
position
vector position
Definition: SCR_DestructibleTreeV2.c:30
SnapToGround
void SnapToGround(out vector normal, array< IEntity > excludeArray=null, float maxLength=10, vector startOffset="0 0 0", vector direction=-vector.Up)
Definition: SCR_PlaceableInventoryItemComponent.c:65
PlaceItem
void PlaceItem(vector right, vector up, vector forward, vector position)
Definition: SCR_PlaceableInventoryItemComponent.c:53
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180