Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
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 //------------------------------------------------------------------------------------------------
9 {
10 return m_fMaxSlotDistance;
11 }
12}
13
15class 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
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 {
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}
ArmaReforgerScripted GetGame()
Definition game.c:1398
vector GetOrigin()
void RegisterSlot(SCR_WeaponRackSlotEntity slot)
SCR_CharacterSoundComponentClass GetComponentData()
vector position
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
ref array< SCR_EntitySpawnerSlotComponent > m_aNearSlots
bool SlotSearchCallback(IEntity ent)
void RegisterChildSlots()
Registers slots initially created as children. There slots cannot be used by any other spawner and sh...
void OnSlotRemoved(SCR_EntitySpawnerSlotComponent slot)
Called, if slot possition was changed. If it fails to meet previously required criteria in CanBeSlotR...
bool CanBeSlotRegistered(notnull SCR_EntitySpawnerSlotComponent slot)
SCR_SlotServiceComponentClass m_SlotManager
Service with basic slot handling functionalities.
ref array< SCR_EntitySpawnerSlotComponent > m_aChildSlots
void RegisterNearbySlots()
Registers slots in near distance. Kept for sake of client checks. Skips slots that are in hiearchy of...
void OnSlotUpdate(SCR_EntitySpawnerSlotComponent slot, vector position)
Called, if slot possition was changed. If it fails to meet previously required criteria in CanBeSlotR...
proto external Managed FindComponent(typename typeName)
proto external vector GetOrigin()
proto external IEntity GetChildren()
proto external IEntity GetParent()
proto external IEntity GetSibling()
IEntity GetOwner()
Owner entity of the fuel tank.
override void EOnInit(IEntity owner)
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
SCR_FieldOfViewSettings Attribute