Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_LockContextComponent.c
Go to the documentation of this file.
1 [ComponentEditorProps(category: "GameScripted/AIComponent", description: "Scripted component for synchronization", icon: HYBRID_COMPONENT_ICON)]
2 class SCR_LockContextComponentClass : AIComponentClass
3 {
4 }
5 
6 class SCR_Key
7 {
8  string m_key;
11 }
12 
13 class SCR_LockContextComponent : AIComponent
14 {
15  private ref array<ref SCR_Key> m_aKeys;
16 
17  //------------------------------------------------------------------------------------------------
18  private int IsKeyRegistered (string key)
19  {
20  for (int i, lenght = m_aKeys.Count(); i < lenght; i++)
21  {
22  if (m_aKeys[i].m_key == key)
23  return i;
24  }
25  return -1;
26  }
27 
28  //------------------------------------------------------------------------------------------------
29  // constructor
33  void SCR_LockContextComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
34  {
35  m_aKeys = {};
36  }
37 
38  //------------------------------------------------------------------------------------------------
43  bool JoinKey (string key, int maxAllowedHolders)
44  {
45  int keyIndex = IsKeyRegistered(key);
46  if ( keyIndex > -1 )
47  {
48  if (m_aKeys[keyIndex].m_maxAllowedHolders >= m_aKeys[keyIndex].m_numOfKeyHolders + 1)
49  {
50  if (maxAllowedHolders != m_aKeys[keyIndex].m_maxAllowedHolders)
51  {
52  Print("Error: key is used with different max allowed holders!", LogLevel.NORMAL);
53  return false;
54  }
55  m_aKeys[keyIndex].m_numOfKeyHolders++;
56  //Print("Semaphore is Opened");
57  return true;
58  }
59  else
60  //Print("Semaphore is Full");
61  return false;
62  }
63  else
64  {
65  SCR_Key newKey = new SCR_Key();
66  newKey.m_key = key;
67  newKey.m_maxAllowedHolders = maxAllowedHolders;
68  if (maxAllowedHolders < 1)
69  {
70  Print("Error: key is set with no holders allowed!", LogLevel.NORMAL);
71  return false;
72  }
73  newKey.m_numOfKeyHolders = 1;
74  m_aKeys.Insert(newKey);
75  //Print("Semaphore is Opened");
76  return true;
77  }
78  }
79 
80  //------------------------------------------------------------------------------------------------
84  bool LeaveKey (string key)
85  {
86  int keyIndex = IsKeyRegistered(key);
87  if ( keyIndex > -1 )
88  {
89  if (m_aKeys[keyIndex].m_numOfKeyHolders == 1)
90  {
91  m_aKeys.Remove(keyIndex);
92  //Print("Semaphore is Closed");
93  return true;
94  }
95  else
96  {
97  m_aKeys[keyIndex].m_numOfKeyHolders--;
98  return true;
99  }
100  }
101  Print("Error: key that should be returned was not found!", LogLevel.NORMAL);
102  return false;
103  }
104 }
ComponentEditorProps
SCR_FragmentEntityClass ComponentEditorProps
m_key
SCR_LockContextComponentClass m_key
m_numOfKeyHolders
int m_numOfKeyHolders
Definition: SCR_LockContextComponent.c:9
SCR_LockContextComponent
Definition: SCR_LockContextComponent.c:13
SCR_LockContextComponentClass
Definition: SCR_LockContextComponent.c:2
m_maxAllowedHolders
int m_maxAllowedHolders
Definition: SCR_LockContextComponent.c:10
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180