Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_EntitySpawnerSlotComponent.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted/Spawner", description: "Slot used for spawning entities.")]
2 class SCR_EntitySpawnerSlotComponentClass : ScriptComponentClass
3 {
4  [Attribute(uiwidget: UIWidgets.ComboBox, desc: "Slot size.", enums: ParamEnumArray.FromEnum(SCR_EEntitySpawnerSlotType), category: "Entity Spawner Slot")]
5  protected SCR_EEntitySpawnerSlotType m_eSlotType;
6 
7  [Attribute(defvalue: "-5 0 -5", category: "Slot Boundaries")]
8  protected vector m_vMinBounds;
9 
10  [Attribute(defvalue: "5 5 5", category: "Slot Boundaries")]
11  protected vector m_vMaxBounds;
12 
13  [Attribute(defvalue: "10", params: "0 inf", desc: "Maximum distance for rally point.", category: "Entity Spawner Slot")]
14  protected float m_fMaxRallyPointDistance;
15 
16  [Attribute(defvalue: "30", params: "1 inf", desc: "Maximum distance for teleporting characters out of slot.", category: "Entity Spawner")]
17  protected float m_fTeleportMaxDistance;
18 
19  [Attribute(defvalue: "3", params: "1 inf", desc: "Size of Cylinder used to search empty terrain position. Should be big enough to prevent empty position being too close to slot center.", category: "Entity Spawner")]
20  protected float m_fTeleportSearchSize;
21 
22  //------------------------------------------------------------------------------------------------
24  float GetMaxRallyPointDistance()
25  {
26  return m_fMaxRallyPointDistance;
27  }
28 
29  //------------------------------------------------------------------------------------------------
31  vector GetMinBoundsVector()
32  {
33  return m_vMinBounds;
34  }
35 
36  //------------------------------------------------------------------------------------------------
38  vector GetMaxBoundsVector()
39  {
40  return m_vMaxBounds;
41  }
42 
43  //------------------------------------------------------------------------------------------------
45  SCR_EEntitySpawnerSlotType GetSlotType()
46  {
47  return m_eSlotType;
48  }
49 
50  //------------------------------------------------------------------------------------------------
52  float GetTeleportMaximumDistance()
53  {
54  return m_fTeleportMaxDistance;
55  }
56 
57  //------------------------------------------------------------------------------------------------
59  float GetTeleportSearchSize()
60  {
61  return m_fTeleportSearchSize;
62  }
63 }
64 
65 //------------------------------------------------------------------------------------------------
67 class SCR_EntitySpawnerSlotComponent : ScriptComponent
68 {
69 #ifdef WORKBENCH
70 
71  [Attribute("0", desc: "Draw visualisation of bounds", category: "Debug")]
72  protected bool m_bShowDebugShape;
73 
74  protected ref Shape m_DebugShape;
75  protected int m_iDebugShapeColor = Color.CYAN;
76 #endif
77 
78  protected RplComponent m_RplComponent;
79  protected SCR_SpawnerSlotManager m_SlotManager;
80  protected SCR_EntityLabelPointComponent m_RallyPointLabelComponent;
81  protected ref array<ChimeraCharacter> m_aCharacterArray;
82  protected ref array<IEntity> m_aExcludedEntities;
83 
84  //------------------------------------------------------------------------------------------------
88  bool IsEntityLabelInRange(notnull SCR_EntityLabelPointComponent labelComp)
89  {
91  if (!prefabData)
92  return false;
93 
94  float maxDistance = prefabData.GetMaxRallyPointDistance();
95 
96  return vector.DistanceSqXZ(labelComp.GetOwner().GetOrigin(), GetOwner().GetOrigin()) > maxDistance * maxDistance;
97  }
98 
99  //------------------------------------------------------------------------------------------------
102  void SetRallyPoint(notnull SCR_EntityLabelPointComponent labelComp)
103  {
104  if (!labelComp.HasLabel(EEditableEntityLabel.GAMELOGIC_RALLYPOINT) && !IsEntityLabelInRange(labelComp))
105  return;
106 
107  m_RallyPointLabelComponent = labelComp;
108  m_RallyPointLabelComponent.GetOnOwnerUpdated().Insert(OnRallyPointUpdated);
109  }
110 
111  //------------------------------------------------------------------------------------------------
114  SCR_EntityLabelPointComponent GetRallyPoint()
115  {
117  if (!prefabData)
118  return null;
119 
121  GetGame().GetWorld().QueryEntitiesBySphere(GetOwner().GetOrigin(), prefabData.GetMaxRallyPointDistance(), RallyPointSearchCallback);
122 
124  }
125 
126  //------------------------------------------------------------------------------------------------
129  {
131  if (!prefabData)
132  return null;
133 
134  return prefabData.GetSlotType();
135  }
136 
137  //------------------------------------------------------------------------------------------------
139  bool IsOccupied()
140  {
142  if (!prefabData)
143  return false;
144 
145  TraceOBB trace = new TraceOBB();
146  GetOwner().GetWorldTransform(trace.Mat);
147 
148  if (!m_aExcludedEntities)
150 
151  trace.Start = GetOwner().GetOrigin();
152  trace.ExcludeArray = m_aExcludedEntities;
153  trace.LayerMask = EPhysicsLayerPresets.Projectile;
154  trace.Flags = TraceFlags.ENTS;
155  trace.Mins = prefabData.GetMinBoundsVector();
156  trace.Maxs = prefabData.GetMaxBoundsVector();
157 
158  GetGame().GetWorld().TracePosition(trace, TraceCallback);
159 
160  return trace.TraceEnt;
161  }
162 
163  //------------------------------------------------------------------------------------------------
166  {
167  if (!m_RplComponent || m_RplComponent.IsProxy())
168  return;
169 
170  PlayerManager playerManager = GetGame().GetPlayerManager();
171  if (!playerManager)
172  return;
173 
175  if (!prefabData)
176  return;
177 
178  //Get All characters in slot bounds
179  array<ChimeraCharacter> characterArray = {};
180  GetCharactersInSlot(characterArray);
181 
182  if (characterArray.IsEmpty())
183  return;
184 
185  //Obtain all empty terrain positions
186  array <vector> positions = {};
187  if (SCR_WorldTools.FindAllEmptyTerrainPositions(positions, GetOwner().GetOrigin(), prefabData.GetTeleportMaximumDistance(), prefabData.GetTeleportSearchSize(), maxResults:characterArray.Count()) == 0)
188  return;
189 
190  vector transform[4];
191  PlayerController playerController;
192  SCR_SpawnerRequestComponent requestComp;
193  SCR_EditableEntityComponent editableComp;
194  int playerId;
195 
196  //Move characters to found free empty terrain positions
197  foreach (int i, ChimeraCharacter character : characterArray)
198  {
199  //If there is not enough Empty terrain positions, stop teleporting characters
200  if (!positions.IsIndexValid(i))
201  break;
202 
203  playerId = playerManager.GetPlayerIdFromControlledEntity(character);
204  if (playerId > 0)
205  {
206  playerController = playerManager.GetPlayerController(playerId);
207  requestComp = SCR_SpawnerRequestComponent.Cast(playerController.FindComponent(SCR_SpawnerRequestComponent));
208  if (requestComp)
209  requestComp.RequestPlayerTeleport(positions[i]);
210  }
211  else
212  {
213  editableComp = SCR_EditableEntityComponent.Cast(character.FindComponent(SCR_EditableEntityComponent));
214  if (!editableComp)
215  continue;
216 
217  character.GetWorldTransform(transform);
218  transform[3] = positions[i];
219  SCR_TerrainHelper.OrientToTerrain(transform);
220 
221  editableComp.SetTransform(transform);
222  }
223  }
224  }
225 
226  //------------------------------------------------------------------------------------------------
229  int GetCharactersInSlot(out array<ChimeraCharacter> characterArray)
230  {
232  if (!prefabData)
233  return 0;
234 
235  vector transform[4];
236  GetOwner().GetTransform(transform);
237 
238  m_aCharacterArray = {};
239  GetGame().GetWorld().QueryEntitiesByOBB(prefabData.GetMinBoundsVector(), prefabData.GetMaxBoundsVector(), transform, CharacterFoundCallback, FilterCharactersCallback);
240  characterArray.InsertAll(m_aCharacterArray);
241 
242  m_aCharacterArray = null;
243  return characterArray.Count();
244  }
245 
246  //------------------------------------------------------------------------------------------------
247  protected void FillExcludedEntities()
248  {
249  m_aExcludedEntities = {};
250 
252  if (!comp)
253  return;
254 
255  set<SCR_EditableEntityComponent> childrenSet = new set<SCR_EditableEntityComponent> ();
256  SCR_EditableEntityComponent parent = comp.GetParentEntity();
257  if (!parent)
258  return;
259 
260  parent.GetChildren(childrenSet);
261  foreach(SCR_EditableEntityComponent editableChildren : childrenSet)
262  {
263  if (!editableChildren)
264  continue;
265 
266  m_aExcludedEntities.Insert(editableChildren.GetOwner());
267  }
268 
269  m_aExcludedEntities.Insert(parent.GetOwner());
270 
271  }
272 
273  //------------------------------------------------------------------------------------------------
277  protected bool CharacterFoundCallback(IEntity ent)
278  {
279  ChimeraCharacter character = ChimeraCharacter.Cast(ent);
280  if (character && m_aCharacterArray)
281  {
282  if (!IsEntityDestroyed(character))
283  m_aCharacterArray.Insert(character);
284  }
285 
286  return true;
287  }
288 
289  //------------------------------------------------------------------------------------------------
292  protected bool FilterCharactersCallback(IEntity ent)
293  {
294  if (ent.IsInherited(ChimeraCharacter))
295  return true;
296 
297  return false;
298  }
299 
300  //------------------------------------------------------------------------------------------------
303  protected bool TraceCallback(IEntity ent)
304  {
305  // Return false if entity is not in desired simulation state, contains cloth component (prevent detection of pouches) or is a weapon
306  if (ent.IsLoaded() || ent.GetPhysics().GetSimulationState() == 0 || ent.FindComponent(BaseLoadoutClothComponent) || ent.FindComponent(WeaponComponent))
307  return false;
308 
309  //Ignore proxy entities
310  EntityFlags entityFlags = ent.GetFlags();
311  if (entityFlags & EntityFlags.PROXY)
312  return false;
313 
314  if (ent.IsInherited(ChimeraCharacter))
315  return false;
316 
317  // Filter out dead bodies and wrecks
318  if (IsEntityDestroyed(ent))
319  {
320  if (ent.IsInherited(Vehicle) && m_RplComponent)
321  {
322  if (!m_RplComponent.IsProxy())
323  SCR_EntityHelper.DeleteEntityAndChildren(ent);
324 
325  return false;
326  }
327  }
328 
329  return true;
330  }
331 
332  //------------------------------------------------------------------------------------------------
333  protected bool IsEntityDestroyed(IEntity entity)
334  {
335  SCR_DamageManagerComponent damageManager = SCR_DamageManagerComponent.Cast(entity.FindComponent(SCR_DamageManagerComponent));
336  if (damageManager)
337  return damageManager.IsDestroyed();
338 
339  return false;
340  }
341 
342  //------------------------------------------------------------------------------------------------
344  protected void OnRallyPointUpdated()
345  {
347  return;
348 
349  m_RallyPointLabelComponent.GetOnOwnerUpdated().Remove(OnRallyPointUpdated);
352  }
353 
354  //------------------------------------------------------------------------------------------------
356  protected bool RallyPointSearchCallback(IEntity ent)
357  {
358  SCR_EntityLabelPointComponent labelComp = SCR_EntityLabelPointComponent.Cast(ent.FindComponent(SCR_EntityLabelPointComponent));
359  if (labelComp && labelComp.HasLabel(EEditableEntityLabel.GAMELOGIC_RALLYPOINT))
360  {
361  m_RallyPointLabelComponent = labelComp;
362  return false;
363  }
364 
365  return true;
366  }
367 
368  //------------------------------------------------------------------------------------------------
369  override void EOnInit(IEntity owner)
370  {
371 #ifdef WORKBENCH
372  if (m_bShowDebugShape)
373  DrawDebugShape();
374 #endif
375 
376  if (SCR_Global.IsEditMode())
377  return;
378 
379  m_SlotManager = SCR_SpawnerSlotManager.GetInstance();
380  if (!m_SlotManager)
381  {
382  Print("Gamemode is missing SCR_SlotManagerComponent, which is required for functionality of SCR_EntitySpawnerSlotComponent", LogLevel.WARNING);
383  return;
384  }
385 
386  m_SlotManager.RegisterSlot(this);
387 
388  m_RplComponent = RplComponent.Cast(owner.FindComponent(RplComponent));
389  if (!m_RplComponent)
390  Print("SCR_EntitySpawnerSlotComponent is missing RplComponent. It won't work properly without it", LogLevel.WARNING);
391  }
392 
393  //------------------------------------------------------------------------------------------------
394  override void OnPostInit(IEntity owner)
395  {
396  super.OnPostInit(owner);
397  SetEventMask(owner, EntityEvent.INIT);
398 
399 #ifdef WORKBENCH
400  if (m_bShowDebugShape)
401  SetEventMask(owner, EntityEvent.FRAME);
402 #endif
403  }
404 
405  //------------------------------------------------------------------------------------------------
406  // destructor
408  {
409  if (m_SlotManager)
410  m_SlotManager.UnregisterSlot(this);
411 
413  m_RallyPointLabelComponent.GetOnOwnerUpdated().Remove(OnRallyPointUpdated);
414  }
415 
416 #ifdef WORKBENCH
417  //------------------------------------------------------------------------------------------------
418  protected void DrawDebugShape()
419  {
421  if (!prefabData)
422  return;
423 
424  vector transform[4];
425  IEntity owner = GetOwner();
426  owner.GetTransform(transform);
427 
428  int shapeFlags = ShapeFlags.WIREFRAME;
429  m_DebugShape = Shape.Create(ShapeType.BBOX, m_iDebugShapeColor, shapeFlags, prefabData.GetMinBoundsVector(), prefabData.GetMaxBoundsVector());
430 
431  m_DebugShape.SetMatrix(transform);
432  }
433 
434  //------------------------------------------------------------------------------------------------
435  override void EOnFrame(IEntity owner, float timeSlice)
436  {
437  if (m_bShowDebugShape && m_DebugShape)
438  {
439  vector transform[4];
440  owner.GetTransform(transform);
441  m_DebugShape.SetMatrix(transform);
442  }
443  }
444 
445  //------------------------------------------------------------------------------------------------
446  override event void _WB_AfterWorldUpdate(IEntity owner, float timeSlice)
447  {
448  if (m_bShowDebugShape && m_DebugShape)
449  {
450  vector transform[4];
451  owner.GetTransform(transform);
452  m_DebugShape.SetMatrix(transform);
453  }
454  }
455 #endif
456 }
457 
459 {
460  GROUP_SMALL = 1 << 0,
461  GROUP_MEDIUM = 1 << 1,
462  GROUP_BIG = 1 << 2,
463 
464  VEHICLE_SMALL = 1 << 3,
465  VEHICLE_MEDIUM = 1 << 4,
466  VEHICLE_LARGE = 1 << 5
467 }
VEHICLE_LARGE
@ VEHICLE_LARGE
Definition: SCR_EntitySpawnerSlotComponent.c:466
SCR_TerrainHelper
Definition: SCR_TerrainHelper.c:1
EEditableEntityLabel
EEditableEntityLabel
Definition: EEditableEntityLabel.c:1
GetSlotType
SCR_EEntitySpawnerSlotType GetSlotType()
Definition: SCR_EntitySpawnerSlotComponent.c:128
GROUP_SMALL
@ GROUP_SMALL
Definition: SCR_EntitySpawnerSlotComponent.c:460
SCR_EntityHelper
Definition: SCR_EntityHelper.c:1
CharacterFoundCallback
protected bool CharacterFoundCallback(IEntity ent)
Definition: SCR_EntitySpawnerSlotComponent.c:277
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
SCR_EEntitySpawnerSlotType
SCR_EEntitySpawnerSlotType
Definition: SCR_EntitySpawnerSlotComponent.c:458
m_vMaxBounds
protected vector m_vMaxBounds
Definition: SCR_SpawnPositionComponent.c:6
RallyPointSearchCallback
protected bool RallyPointSearchCallback(IEntity ent)
Callback for Query in GetRallyPoint. Returns false, once SCR_EntityLabelPointComponent matching param...
Definition: SCR_EntitySpawnerSlotComponent.c:356
ScriptComponent
SCR_SiteSlotEntityClass ScriptComponent
DrawDebugShape
protected void DrawDebugShape(bool draw)
Definition: SCR_ScenarioFrameworkLayerBase.c:829
~SCR_EntitySpawnerSlotComponent
void ~SCR_EntitySpawnerSlotComponent()
Definition: SCR_EntitySpawnerSlotComponent.c:407
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
EOnFrame
override void EOnFrame(IEntity owner, float timeSlice)
Definition: SCR_PlayerProfileManagerComponent.c:199
m_vMinBounds
protected vector m_vMinBounds
Definition: SCR_SpawnPositionComponent.c:3
GetRallyPoint
SCR_EntityLabelPointComponent GetRallyPoint()
Definition: SCR_EntitySpawnerSlotComponent.c:114
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
SCR_WorldTools
Definition: SCR_WorldTools.c:1
FilterCharactersCallback
protected bool FilterCharactersCallback(IEntity ent)
Definition: SCR_EntitySpawnerSlotComponent.c:292
FillExcludedEntities
protected void FillExcludedEntities()
Definition: SCR_EntitySpawnerSlotComponent.c:247
GetOrigin
vector GetOrigin()
Definition: SCR_AIUtilityComponent.c:279
m_RplComponent
SCR_EntitySpawnerSlotComponentClass m_RplComponent
Specifies slot to be used with nearby Entity Spawner Components.
Attribute
typedef Attribute
Post-process effect of scripted camera.
VEHICLE_SMALL
@ VEHICLE_SMALL
Definition: SCR_EntitySpawnerSlotComponent.c:464
IsEntityLabelInRange
bool IsEntityLabelInRange(notnull SCR_EntityLabelPointComponent labelComp)
Definition: SCR_EntitySpawnerSlotComponent.c:88
OnRallyPointUpdated
protected void OnRallyPointUpdated()
Called when Rally Point gets moved.
Definition: SCR_EntitySpawnerSlotComponent.c:344
m_SlotManager
protected SCR_SpawnerSlotManager m_SlotManager
Definition: SCR_EntitySpawnerSlotComponent.c:79
IsOccupied
bool IsOccupied()
Returns true, if slot is occupied.
Definition: SCR_EntitySpawnerSlotComponent.c:139
OnPostInit
override void OnPostInit(IEntity owner)
Called on PostInit when all components are added.
Definition: SCR_EntitySpawnerSlotComponent.c:394
m_iDebugShapeColor
protected int m_iDebugShapeColor
Definition: SCR_ScenarioFrameworkLayerBase.c:69
GetCharactersInSlot
int GetCharactersInSlot(out array< ChimeraCharacter > characterArray)
Definition: SCR_EntitySpawnerSlotComponent.c:229
SetRallyPoint
void SetRallyPoint(notnull SCR_EntityLabelPointComponent labelComp)
Definition: SCR_EntitySpawnerSlotComponent.c:102
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
TraceCallback
protected bool TraceCallback(IEntity ent)
Definition: SCR_EntitySpawnerSlotComponent.c:303
GROUP_MEDIUM
@ GROUP_MEDIUM
Definition: SCR_EntitySpawnerSlotComponent.c:461
SCR_EntitySpawnerSlotComponentClass
Definition: SCR_EntitySpawnerSlotComponent.c:2
SCR_EditableEntityComponent
Definition: SCR_EditableEntityComponent.c:13
EOnInit
override void EOnInit(IEntity owner)
Definition: SCR_EntitySpawnerSlotComponent.c:369
SCR_Global
Definition: Functions.c:6
IsEntityDestroyed
protected bool IsEntityDestroyed(IEntity entity)
Definition: SCR_EntitySpawnerSlotComponent.c:333
BaseLoadoutClothComponent
Definition: BaseLoadoutClothComponent.c:12
m_RallyPointLabelComponent
protected SCR_EntityLabelPointComponent m_RallyPointLabelComponent
Definition: SCR_EntitySpawnerSlotComponent.c:80
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
m_aCharacterArray
protected ref array< ChimeraCharacter > m_aCharacterArray
Definition: SCR_EntitySpawnerSlotComponent.c:81
GROUP_BIG
@ GROUP_BIG
Definition: SCR_EntitySpawnerSlotComponent.c:462
MoveCharactersFromSlot
void MoveCharactersFromSlot()
Moves away all characters from slot, if there is suitable empty position in vicinity.
Definition: SCR_EntitySpawnerSlotComponent.c:165
m_aExcludedEntities
protected ref array< IEntity > m_aExcludedEntities
Definition: SCR_EntitySpawnerSlotComponent.c:82
PlayerManager
Definition: PlayerManager.c:12
VEHICLE_MEDIUM
@ VEHICLE_MEDIUM
Definition: SCR_EntitySpawnerSlotComponent.c:465
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180