Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_SpawnArea.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted/GameMode", description: "Area that provides events and API when an enemy enters it.")]
3 {
4 };
5 
7 void SpawnAreaCharacterEventDelegate(SCR_SpawnArea area, IEntity character, bool isFriendly);
9 typedef ScriptInvokerBase<SpawnAreaCharacterEventDelegate> SpawnAreaEvent;
10 
12 void SpawnAreaAlertEventDelegate(SCR_SpawnArea area, array<IEntity> enemies);
14 typedef ScriptInvokerBase<SpawnAreaAlertEventDelegate> SpawnAreaAlertEvent;
15 
16 //------------------------------------------------------------------------------------------------
23 class SCR_SpawnArea : ScriptedGameTriggerEntity
24 {
26  [Attribute("", UIWidgets.EditBox, "The key specifying which faction this area belongs to.")]
27  protected FactionKey m_sFactionKey;
28 
34  protected ref set<SCR_ChimeraCharacter>> m_sOccupants = new set<SCR_ChimeraCharacter>();
35 
37  protected ref SpawnAreaEvent m_pOnCharacterEnter = new SpawnAreaEvent();
38 
40  protected ref array<IEntity> m_aEnemies = {};
41 
42  //------------------------------------------------------------------------------------------------
44  SpawnAreaEvent GetCharacterEnterInvoker()
45  {
46  return m_pOnCharacterEnter;
47  }
48 
50  protected ref SpawnAreaEvent m_pOnCharacterExit = new SpawnAreaEvent();
51 
52  //------------------------------------------------------------------------------------------------
54  SpawnAreaEvent GetCharacterExitInvoker()
55  {
56  return m_pOnCharacterExit;
57  }
58 
60  protected ref SpawnAreaAlertEvent m_pOnAlert = new SpawnAreaAlertEvent();
61 
62  //------------------------------------------------------------------------------------------------
64  SpawnAreaAlertEvent GetOnAlertInvoker()
65  {
66  return m_pOnAlert;
67  }
68 
69  //------------------------------------------------------------------------------------------------
71  Faction GetAffiliatedFaction()
72  {
73  return GetGame().GetFactionManager().GetFactionByKey(GetAffiliatedFactionKey());
74  }
75 
76  //------------------------------------------------------------------------------------------------
78  FactionKey GetAffiliatedFactionKey()
79  {
80  return m_sFactionKey;
81  }
82 
83  //------------------------------------------------------------------------------------------------
88  bool IsInside(SCR_ChimeraCharacter character)
89  {
90  if (!character)
91  return false;
92 
93  return m_sOccupants.Contains(character);
94  }
95 
96  //------------------------------------------------------------------------------------------------
101  bool IsFriendly(notnull SCR_ChimeraCharacter character)
102  {
103  Faction faction = character.GetFaction();
104  if (!faction)
105  {
106  if (m_sFactionKey.IsEmpty())
107  return true;
108 
109  return false;
110  }
111 
112  Faction areaFaction = GetAffiliatedFaction();
113  if (areaFaction && areaFaction.IsFactionFriendly(faction))
114  return true;
115 
116  return false;
117  }
118 
119 
120  //------------------------------------------------------------------------------------------------
127  int GetFriendlyCharactersInside(out notnull array<SCR_ChimeraCharacter> outCharacters)
128  {
129  outCharacters.Clear();
130  int count = 0;
131  foreach (SCR_ChimeraCharacter character : m_sOccupants)
132  {
133  if (!character)
134  continue;
135 
136  if (IsFriendly(character))
137  {
138  outCharacters.Insert(character);
139  count++;
140  }
141  }
142 
143  return count;
144  }
145 
146  //------------------------------------------------------------------------------------------------
153  int GetEnemyCharactersInside(out notnull array<SCR_ChimeraCharacter> outCharacters)
154  {
155  outCharacters.Clear();
156  int count = 0;
157  foreach (SCR_ChimeraCharacter character : m_sOccupants)
158  {
159  if (!character)
160  continue;
161 
162  if (!IsFriendly(character))
163  {
164  outCharacters.Insert(character);
165  count++;
166  }
167  }
168 
169  return count;
170  }
171 
172 
173  //------------------------------------------------------------------------------------------------
179  int GetCharactersInside(out notnull array<SCR_ChimeraCharacter> outCharacters)
180  {
181  outCharacters.Clear();
182  int count = 0;
183  foreach (SCR_ChimeraCharacter character : m_sOccupants)
184  {
185  outCharacters.Insert(character);
186  count++;
187  }
188 
189  return count;
190  }
191 
192  //------------------------------------------------------------------------------------------------
194  override bool ScriptedEntityFilterForQuery(IEntity ent)
195  {
196  SCR_ChimeraCharacter character = SCR_ChimeraCharacter.Cast(ent);
197  if (!character)
198  return false;
199 
200  return !character.GetCharacterController().IsDead();
201  }
202 
203  //------------------------------------------------------------------------------------------------
204  protected bool IsLocalEntity(notnull IEntity ent)
205  {
206  PlayerController playerController = GetGame().GetPlayerController();
207  if (playerController && playerController.GetControlledEntity() == ent)
208  return true;
209 
210  return false;
211  }
212 
213  //------------------------------------------------------------------------------------------------
215  protected override void OnActivate(IEntity ent)
216  {
217  SCR_ChimeraCharacter character = SCR_ChimeraCharacter.Cast(ent);
218  if (!character)
219  return;
220 
221  // Push new character into occupants
222  if (!m_sOccupants.Contains(character))
223  {
224  m_sOccupants.Insert(character);
225 
226  // Raise callback
227  OnCharacterEnter(character, IsFriendly(character));
228  }
229  }
230 
231  //------------------------------------------------------------------------------------------------
232  protected event void OnCharacterEnter(IEntity character, bool isFriendly)
233  {
234  m_pOnCharacterEnter.Invoke(this, character, isFriendly)
235  }
236 
237  //------------------------------------------------------------------------------------------------
239  protected override void OnDeactivate(IEntity ent)
240  {
241  SCR_ChimeraCharacter character = SCR_ChimeraCharacter.Cast(ent);
242  if (!character)
243  return;
244 
245  if (m_sOccupants.Contains(character))
246  {
247  int index = m_sOccupants.Find(character);
248  m_sOccupants.Remove(index);
249 
250  OnCharacterExit(character, IsFriendly(character));
251  }
252  }
253 
254  //------------------------------------------------------------------------------------------------
255  protected event void OnCharacterExit(IEntity character, bool isFriendly)
256  {
257  m_pOnCharacterExit.Invoke(this, character, isFriendly)
258  }
259 
260  //------------------------------------------------------------------------------------------------
262  protected override void OnInit(IEntity owner)
263  {
264  // Enable OnFrame event mask
265  SetEventMask(EntityEvent.FRAME);
266  }
267 
268  //------------------------------------------------------------------------------------------------
269  protected override void OnFrame(IEntity owner, float timeSlice)
270  {
271  super.OnFrame(owner, timeSlice);
272 
273  m_aEnemies.Clear();
274  // Ignore dead characters and find if there is at least one enemy
275  foreach (SCR_ChimeraCharacter character : m_sOccupants)
276  {
277  if (character.GetCharacterController().IsDead())
278  continue;
279 
280  if (!IsFriendly(character))
281  m_aEnemies.Insert(character);
282  }
283 
284  // Raise alert event if any
285  if (!m_aEnemies.IsEmpty())
286  OnAlert(m_aEnemies);
287  }
288 
289  //------------------------------------------------------------------------------------------------
290  protected event void OnAlert(array<IEntity> enemies)
291  {
292  m_pOnAlert.Invoke(this, enemies);
293  }
294 };
SpawnAreaAlertEventDelegate
func SpawnAreaAlertEventDelegate
Definition: SCR_SpawnArea.c:13
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SpawnAreaAlertEvent
ScriptInvokerBase< SpawnAreaAlertEventDelegate > SpawnAreaAlertEvent
Definition: SCR_SpawnArea.c:14
SpawnAreaEvent
ScriptInvokerBase< SpawnAreaCharacterEventDelegate > SpawnAreaEvent
Definition: SCR_SpawnArea.c:9
func
func
Definition: SCR_AIThreatSystem.c:5
m_sFactionKey
protected FactionKey m_sFactionKey
Definition: SCR_ScenarioFrameworkLayerBase.c:25
SCR_SpawnAreaClass
Definition: SCR_SpawnArea.c:2
ScriptedGameTriggerEntityClass
Definition: ScriptedGameTriggerEntity.c:12
Attribute
typedef Attribute
Post-process effect of scripted camera.
SpawnAreaCharacterEventDelegate
func SpawnAreaCharacterEventDelegate
Definition: SCR_SpawnArea.c:8
Faction
Definition: Faction.c:12
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition: SCR_DestructionSynchronizationComponent.c:17
SCR_SpawnArea
Definition: SCR_SpawnArea.c:23
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180