Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
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.")]
5
7void SpawnAreaCharacterEventDelegate(SCR_SpawnArea area, IEntity character, bool isFriendly);
9typedef ScriptInvokerBase<SpawnAreaCharacterEventDelegate> SpawnAreaEvent;
10
12void SpawnAreaAlertEventDelegate(SCR_SpawnArea area, array<IEntity> enemies);
14typedef ScriptInvokerBase<SpawnAreaAlertEventDelegate> SpawnAreaAlertEvent;
15
16//------------------------------------------------------------------------------------------------
23class SCR_SpawnArea : ScriptedGameTriggerEntity
24{
26 [Attribute("", UIWidgets.EditBox, "The key specifying which faction this area belongs to.")]
28
34 protected ref set<SCR_ChimeraCharacter>> m_sOccupants = new set<SCR_ChimeraCharacter>();
35
38
40 protected ref array<IEntity> m_aEnemies = {};
41
42 //------------------------------------------------------------------------------------------------
48
51
52 //------------------------------------------------------------------------------------------------
58
61
62 //------------------------------------------------------------------------------------------------
68
69 //------------------------------------------------------------------------------------------------
72 {
73 return GetGame().GetFactionManager().GetFactionByKey(GetAffiliatedFactionKey());
74 }
75
76 //------------------------------------------------------------------------------------------------
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 //------------------------------------------------------------------------------------------------
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())
287 }
288
289 //------------------------------------------------------------------------------------------------
290 protected event void OnAlert(array<IEntity> enemies)
291 {
292 m_pOnAlert.Invoke(this, enemies);
293 }
294};
ArmaReforgerScripted GetGame()
Definition game.c:1398
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
func SpawnAreaAlertEventDelegate
ScriptInvokerBase< SpawnAreaCharacterEventDelegate > SpawnAreaEvent
ScriptInvokerBase< SpawnAreaAlertEventDelegate > SpawnAreaAlertEvent
func SpawnAreaCharacterEventDelegate
override void OnFrame(IEntity owner, float timeSlice)
bool IsFriendly(notnull SCR_ChimeraCharacter character)
ref set< SCR_ChimeraCharacter > m_sOccupants
override bool ScriptedEntityFilterForQuery(IEntity ent)
Override this method in inherited class to define a new filter.
SpawnAreaAlertEvent GetOnAlertInvoker()
Returns invoker that is invoked when area is occupied by at least one enemy character.
FactionKey GetAffiliatedFactionKey()
Returns the faction key of faction this area is affiliated with or empty if none.
int GetEnemyCharactersInside(out notnull array< SCR_ChimeraCharacter > outCharacters)
int GetFriendlyCharactersInside(out notnull array< SCR_ChimeraCharacter > outCharacters)
ref SpawnAreaEvent m_pOnCharacterExit
Callback raised when a character leaves this area.
override void OnInit(IEntity owner)
Initializes this area by initializing and preallocating required resources.
SpawnAreaEvent GetCharacterEnterInvoker()
Returns invoker that is invoked when a character enters this area.
ref array< IEntity > m_aEnemies
Buffer of all enemy entities for a single frame.
int GetCharactersInside(out notnull array< SCR_ChimeraCharacter > outCharacters)
ref SpawnAreaAlertEvent m_pOnAlert
Callback raised when area is occupied by at least one enemy character.
ref SpawnAreaEvent m_pOnCharacterEnter
Callback raised when a character enters this area.
event void OnCharacterExit(IEntity character, bool isFriendly)
override void OnDeactivate(IEntity ent)
callback - deactivation - occurs when and entity which was activated (OnActivate) leaves the Trigger
override void OnActivate(IEntity ent)
callback - activation - occurs when and entity which fulfills the filter definitions enters the Trigg...
Faction GetAffiliatedFaction()
Returns the faction this area is affiliated with or null if none.
bool IsInside(SCR_ChimeraCharacter character)
bool IsLocalEntity(notnull IEntity ent)
event void OnAlert(array< IEntity > enemies)
event void OnCharacterEnter(IEntity character, bool isFriendly)
SpawnAreaEvent GetCharacterExitInvoker()
Returns invoker that is invoked when a character leaves this area.
FactionKey m_sFactionKey
Key of faction this area belongs to.
SCR_FieldOfViewSettings Attribute
EntityEvent
Various entity events.
Definition EntityEvent.c:14