Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_SlotService.c
Go to the documentation of this file.
2 {
3  [Attribute(defvalue: "5", params: "0 inf", desc: "Slot Search Radius Size.", category: "Slot service")]
4  protected float m_fMaxSlotDistance;
5 
6  //------------------------------------------------------------------------------------------------
8  float GetMaxSlotDistance()
9  {
10  return m_fMaxSlotDistance;
11  }
12 }
13 
15 class SCR_SlotServiceComponent : SCR_ServicePointComponent
16 {
17  protected SCR_SpawnerSlotManager m_SlotManager;
18  protected ref array<SCR_EntitySpawnerSlotComponent> m_aChildSlots = {};
19  protected ref array<SCR_EntitySpawnerSlotComponent> m_aNearSlots = {};
20 
21  //------------------------------------------------------------------------------------------------
25  void RegisterSlot(SCR_EntitySpawnerSlotComponent slot)
26  {
27  if (!CanBeSlotRegistered(slot))
28  return;
29 
30  if (!m_aNearSlots.Contains(slot))
31  m_aNearSlots.Insert(slot);
32  }
33 
34  //------------------------------------------------------------------------------------------------
38  protected bool CanBeSlotRegistered(notnull SCR_EntitySpawnerSlotComponent slot)
39  {
40  IEntity slotOwner = slot.GetOwner();
41  IEntity parent = slotOwner.GetParent();
42  if (parent && parent.FindComponent(SCR_SlotServiceComponent) && parent != GetOwner())
43  return false;
44 
45  SCR_SlotServiceComponentClass prefabData = SCR_SlotServiceComponentClass.Cast(GetComponentData(GetOwner()));
46  if (!prefabData)
47  return false;
48 
49  float maxSlotDistance = prefabData.GetMaxSlotDistance();
50  return vector.DistanceSqXZ(slotOwner.GetOrigin(), GetOwner().GetOrigin()) < maxSlotDistance * maxSlotDistance;
51  }
52 
53  //------------------------------------------------------------------------------------------------
56  protected bool SlotSearchCallback(IEntity ent)
57  {
58  SCR_EntitySpawnerSlotComponent slotComp = SCR_EntitySpawnerSlotComponent.Cast(ent.FindComponent(SCR_EntitySpawnerSlotComponent));
59  if (!slotComp)
60  return true;
61 
62  RegisterSlot(slotComp);
63  return true;
64  }
65 
66  //------------------------------------------------------------------------------------------------
68  protected void RegisterNearbySlots()
69  {
70  SCR_SlotServiceComponentClass prefabData = SCR_SlotServiceComponentClass.Cast(GetComponentData(GetOwner()));
71  if (!prefabData)
72  return;
73 
74  GetGame().GetWorld().QueryEntitiesBySphere(GetOwner().GetOrigin(), prefabData.GetMaxSlotDistance(), SlotSearchCallback);
75  }
76 
77  //------------------------------------------------------------------------------------------------
79  protected void RegisterChildSlots()
80  {
81  IEntity child = GetOwner().GetChildren();
82  while (child)
83  {
84  SCR_EntitySpawnerSlotComponent slot = SCR_EntitySpawnerSlotComponent.Cast(child.FindComponent(SCR_EntitySpawnerSlotComponent));
85  if (slot)
86  m_aChildSlots.Insert(slot);
87 
88  child = child.GetSibling();
89  }
90  }
91 
92  //------------------------------------------------------------------------------------------------
94  protected void OnSlotUpdate(SCR_EntitySpawnerSlotComponent slot, vector position)
95  {
96  if (CanBeSlotRegistered(slot))
97  {
98  if (!m_aNearSlots.Contains(slot) || m_aChildSlots.Contains(slot))
99  m_aNearSlots.Insert(slot);
100  }
101  else
102  {
103  m_aNearSlots.RemoveItem(slot);
104  }
105  }
106 
107  //------------------------------------------------------------------------------------------------
109  protected void OnSlotRemoved(SCR_EntitySpawnerSlotComponent slot)
110  {
111  m_aNearSlots.RemoveItem(slot);
112  }
113 
114  //------------------------------------------------------------------------------------------------
115  protected override void EOnInit(IEntity owner)
116  {
117  super.EOnInit(owner);
118 
119  m_SlotManager = SCR_SpawnerSlotManager.GetInstance();
120  if (!m_SlotManager)
121  {
122  Print("Slot manager is required for Slot service functionality", LogLevel.ERROR);
123  return;
124  }
125 
128 
129  m_SlotManager.GetOnSlotCreated().Insert(RegisterSlot);
130  m_SlotManager.GetOnSlotUpdated().Insert(OnSlotUpdate);
131  m_SlotManager.GetOnSlotRemoved().Insert(OnSlotRemoved);
132  }
133 }
SlotSearchCallback
protected bool SlotSearchCallback(IEntity ent)
Definition: SCR_SlotService.c:56
OnSlotRemoved
protected void OnSlotRemoved(SCR_EntitySpawnerSlotComponent slot)
Called, if slot possition was changed. If it fails to meet previously required criteria in CanBeSlotR...
Definition: SCR_SlotService.c:109
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
RegisterNearbySlots
protected void RegisterNearbySlots()
Registers slots in near distance. Kept for sake of client checks. Skips slots that are in hiearchy of...
Definition: SCR_SlotService.c:68
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
m_aChildSlots
protected ref array< SCR_EntitySpawnerSlotComponent > m_aChildSlots
Definition: SCR_SlotService.c:18
GetOrigin
vector GetOrigin()
Definition: SCR_AIUtilityComponent.c:279
m_SlotManager
SCR_SlotServiceComponentClass m_SlotManager
Service with basic slot handling functionalities.
SCR_ServicePointComponentClass
Definition: SCR_ServicePointComponent.c:1
Attribute
typedef Attribute
Post-process effect of scripted camera.
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
SCR_SlotServiceComponentClass
Definition: SCR_SlotService.c:1
EOnInit
protected override void EOnInit(IEntity owner)
Definition: SCR_SlotService.c:115
RegisterChildSlots
protected void RegisterChildSlots()
Registers slots initially created as children. There slots cannot be used by any other spawner and sh...
Definition: SCR_SlotService.c:79
RegisterSlot
void RegisterSlot(SCR_EntitySpawnerSlotComponent slot)
Definition: SCR_SlotService.c:25
OnSlotUpdate
protected void OnSlotUpdate(SCR_EntitySpawnerSlotComponent slot, vector position)
Called, if slot possition was changed. If it fails to meet previously required criteria in CanBeSlotR...
Definition: SCR_SlotService.c:94
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
position
vector position
Definition: SCR_DestructibleTreeV2.c:30
m_aNearSlots
protected ref array< SCR_EntitySpawnerSlotComponent > m_aNearSlots
Definition: SCR_SlotService.c:19
CanBeSlotRegistered
protected bool CanBeSlotRegistered(notnull SCR_EntitySpawnerSlotComponent slot)
Definition: SCR_SlotService.c:38
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180