Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_SpawnLockComponent.c
Go to the documentation of this file.
4
12class SCR_SpawnLockComponent : ScriptComponent
13{
16 protected ref set<Managed> m_RequestLocks = new set<Managed>();
17
21 protected ref set<Managed> m_AuthorityLocks = new set<Managed>();
22
23 //------------------------------------------------------------------------------------------------
24 protected override void OnPostInit(IEntity owner)
25 {
26 super.OnPostInit(owner);
27 if (!PlayerController.Cast(owner))
28 Debug.Error(string.Format("%1 is not attached to a %2!", Type().ToString(), PlayerController));
29 }
30
31 //------------------------------------------------------------------------------------------------
35 void Lock(Managed source, bool auth)
36 {
37 if (auth)
38 m_AuthorityLocks.Insert(source);
39 else
40 m_RequestLocks.Insert(source);
41
42 #ifdef _ENABLE_RESPAWN_LOGS
43 PrintLocks("SCR_SpawnLockComponent::Lock()", source, auth);
44 #endif
45 }
46
47 //------------------------------------------------------------------------------------------------
51 void Unlock(Managed source, bool auth)
52 {
53 if (auth)
54 {
55 int index = m_AuthorityLocks.Find(source);
56 if (index == -1)
57 return;
58
59 m_AuthorityLocks.Remove(index);
60 }
61 else
62 {
63 int index = m_RequestLocks.Find(source);
64 if (index == -1)
65 return;
66
67 m_RequestLocks.Remove(index);
68 }
69
70 #ifdef _ENABLE_RESPAWN_LOGS
71 PrintLocks("SCR_SpawnLockComponent::Unlock()", source, auth);
72 #endif
73 }
74
75 //------------------------------------------------------------------------------------------------
81 bool IsLocked(bool auth)
82 {
83 if (auth)
84 return !m_AuthorityLocks.IsEmpty();
85 else
86 return !m_RequestLocks.IsEmpty();
87 }
88
89 //------------------------------------------------------------------------------------------------
94 bool TryLock(Managed source, bool auth)
95 {
96 if (IsLocked(auth))
97 return false;
98
99 Lock(source, auth);
100 return true;
101 }
102
103 #ifdef _ENABLE_RESPAWN_LOGS
104
105 //------------------------------------------------------------------------------------------------
110 void PrintLocks(string ctx, Managed src, bool auth)
111 {
112 Print(string.Format("%1 (reqCnt: %2 | authCnt: %3 | (src: %4, auth: %5)",
113 ctx, m_RequestLocks.Count(), m_AuthorityLocks.Count(), src, auth), LogLevel.NORMAL);
114 }
115 #endif
116}
bool IsLocked(IEntity user, BaseCompartmentSlot compartmentSlot)
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
void Unlock(Managed source, bool auth)
SCR_SpawnLockComponentClass m_RequestLocks
void Lock(Managed source, bool auth)
bool TryLock(Managed source, bool auth)
ref set< Managed > m_AuthorityLocks
int Type
Definition Debug.c:13
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
proto external string ToString()
Plain C++ pointer, no weak pointers, no memory management.