Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_EntitySpawnerSlotComponent.c
Go to the documentation of this file.
1[EntityEditorProps(category: "GameScripted/Spawner", description: "Slot used for spawning entities.")]
3{
4 [Attribute(uiwidget: UIWidgets.ComboBox, desc: "Slot size.", enums: ParamEnumArray.FromEnum(SCR_EEntitySpawnerSlotType), category: "Entity Spawner Slot")]
6
7 [Attribute(defvalue: "-5 0 -5", category: "Slot Boundaries")]
9
10 [Attribute(defvalue: "5 5 5", category: "Slot Boundaries")]
12
13 [Attribute(defvalue: "10", params: "0 inf", desc: "Maximum distance for rally point.", category: "Entity Spawner Slot")]
14 protected float m_fMaxRallyPointDistance;
15
16 [Attribute(defvalue: "30", params: "1 inf", desc: "Maximum distance for teleporting characters out of slot.", category: "Entity Spawner")]
17 protected float m_fTeleportMaxDistance;
18
19 [Attribute(defvalue: "3", params: "1 inf", desc: "Size of Cylinder used to search empty terrain position. Should be big enough to prevent empty position being too close to slot center.", category: "Entity Spawner")]
20 protected float m_fTeleportSearchSize;
21
22 //------------------------------------------------------------------------------------------------
28
29 //------------------------------------------------------------------------------------------------
32 {
33 return m_vMinBounds;
34 }
35
36 //------------------------------------------------------------------------------------------------
39 {
40 return m_vMaxBounds;
41 }
42
43 //------------------------------------------------------------------------------------------------
49
50 //------------------------------------------------------------------------------------------------
56
57 //------------------------------------------------------------------------------------------------
60 {
62 }
63}
64
65//------------------------------------------------------------------------------------------------
67class SCR_EntitySpawnerSlotComponent : ScriptComponent
68{
69#ifdef WORKBENCH
70
71 [Attribute("0", desc: "Draw visualisation of bounds", category: "Debug")]
72 protected bool m_bShowDebugShape;
73
74 protected ref Shape m_DebugShape;
75 protected int m_iDebugShapeColor = Color.CYAN;
76#endif
77
78 protected RplComponent m_RplComponent;
79 protected SCR_SpawnerSlotManager m_SlotManager;
80 protected SCR_EntityLabelPointComponent m_RallyPointLabelComponent;
81 protected ref array<ChimeraCharacter> m_aCharacterArray;
82 protected ref array<IEntity> m_aExcludedEntities;
83
84 //------------------------------------------------------------------------------------------------
88 bool IsEntityLabelInRange(notnull SCR_EntityLabelPointComponent labelComp)
89 {
91 if (!prefabData)
92 return false;
93
94 float maxDistance = prefabData.GetMaxRallyPointDistance();
95
96 return vector.DistanceSqXZ(labelComp.GetOwner().GetOrigin(), GetOwner().GetOrigin()) > maxDistance * maxDistance;
97 }
98
99 //------------------------------------------------------------------------------------------------
102 void SetRallyPoint(notnull SCR_EntityLabelPointComponent labelComp)
103 {
104 if (!labelComp.HasLabel(EEditableEntityLabel.GAMELOGIC_RALLYPOINT) && !IsEntityLabelInRange(labelComp))
105 return;
106
107 m_RallyPointLabelComponent = labelComp;
108 m_RallyPointLabelComponent.GetOnOwnerUpdated().Insert(OnRallyPointUpdated);
109 }
110
111 //------------------------------------------------------------------------------------------------
114 SCR_EntityLabelPointComponent GetRallyPoint()
115 {
117 if (!prefabData)
118 return null;
119
121 GetGame().GetWorld().QueryEntitiesBySphere(GetOwner().GetOrigin(), prefabData.GetMaxRallyPointDistance(), RallyPointSearchCallback);
122
124 }
125
126 //------------------------------------------------------------------------------------------------
129 {
131 if (!prefabData)
132 return SCR_EEntitySpawnerSlotType.INVALID;
133
134 return prefabData.GetSlotType();
135 }
136
137 //------------------------------------------------------------------------------------------------
140 {
142 if (!prefabData)
143 return false;
144
145 TraceOBB trace = new TraceOBB();
146 GetOwner().GetWorldTransform(trace.Mat);
147
150
151 trace.Start = GetOwner().GetOrigin();
152 trace.ExcludeArray = m_aExcludedEntities;
153 trace.LayerMask = EPhysicsLayerPresets.Projectile;
154 trace.Flags = TraceFlags.ENTS;
155 trace.Mins = prefabData.GetMinBoundsVector();
156 trace.Maxs = prefabData.GetMaxBoundsVector();
157
158 GetGame().GetWorld().TracePosition(trace, TraceCallback);
159
160 return trace.TraceEnt;
161 }
162
163 //------------------------------------------------------------------------------------------------
166 {
167 if (!m_RplComponent || m_RplComponent.IsProxy())
168 return;
169
170 PlayerManager playerManager = GetGame().GetPlayerManager();
171 if (!playerManager)
172 return;
173
175 if (!prefabData)
176 return;
177
178 //Get All characters in slot bounds
179 array<ChimeraCharacter> characterArray = {};
180 GetCharactersInSlot(characterArray);
181
182 if (characterArray.IsEmpty())
183 return;
184
185 //Obtain all empty terrain positions
186 array <vector> positions = {};
187 if (SCR_WorldTools.FindAllEmptyTerrainPositions(positions, GetOwner().GetOrigin(), prefabData.GetTeleportMaximumDistance(), prefabData.GetTeleportSearchSize(), maxResults:characterArray.Count()) == 0)
188 return;
189
190 vector transform[4];
191 PlayerController playerController;
192 SCR_SpawnerRequestComponent requestComp;
193 SCR_EditableEntityComponent editableComp;
194 int playerId;
195
196 //Move characters to found free empty terrain positions
197 foreach (int i, ChimeraCharacter character : characterArray)
198 {
199 //If there is not enough Empty terrain positions, stop teleporting characters
200 if (!positions.IsIndexValid(i))
201 break;
202
203 playerId = playerManager.GetPlayerIdFromControlledEntity(character);
204 if (playerId > 0)
205 {
206 playerController = playerManager.GetPlayerController(playerId);
207 requestComp = SCR_SpawnerRequestComponent.Cast(playerController.FindComponent(SCR_SpawnerRequestComponent));
208 if (requestComp)
209 requestComp.RequestPlayerTeleport(positions[i]);
210 }
211 else
212 {
213 editableComp = SCR_EditableEntityComponent.Cast(character.FindComponent(SCR_EditableEntityComponent));
214 if (!editableComp)
215 continue;
216
217 character.GetWorldTransform(transform);
218 transform[3] = positions[i];
220
221 editableComp.SetTransform(transform);
222 }
223 }
224 }
225
226 //------------------------------------------------------------------------------------------------
229 int GetCharactersInSlot(out array<ChimeraCharacter> characterArray)
230 {
232 if (!prefabData)
233 return 0;
234
235 vector transform[4];
236 GetOwner().GetTransform(transform);
237
239 GetGame().GetWorld().QueryEntitiesByOBB(prefabData.GetMinBoundsVector(), prefabData.GetMaxBoundsVector(), transform, CharacterFoundCallback, FilterCharactersCallback);
240 characterArray.InsertAll(m_aCharacterArray);
241
242 m_aCharacterArray = null;
243 return characterArray.Count();
244 }
245
246 //------------------------------------------------------------------------------------------------
247 protected void FillExcludedEntities()
248 {
250
252 if (!comp)
253 return;
254
255 set<SCR_EditableEntityComponent> childrenSet = new set<SCR_EditableEntityComponent> ();
257 if (!parent)
258 return;
259
260 parent.GetChildren(childrenSet);
261 foreach(SCR_EditableEntityComponent editableChildren : childrenSet)
262 {
263 if (!editableChildren)
264 continue;
265
266 m_aExcludedEntities.Insert(editableChildren.GetOwner());
267 }
268
269 m_aExcludedEntities.Insert(parent.GetOwner());
270
271 }
272
273 //------------------------------------------------------------------------------------------------
277 protected bool CharacterFoundCallback(IEntity ent)
278 {
279 ChimeraCharacter character = ChimeraCharacter.Cast(ent);
280 if (character && m_aCharacterArray)
281 {
282 if (!IsEntityDestroyed(character))
283 m_aCharacterArray.Insert(character);
284 }
285
286 return true;
287 }
288
289 //------------------------------------------------------------------------------------------------
293 {
294 if (ent.IsInherited(ChimeraCharacter))
295 return true;
296
297 return false;
298 }
299
300 //------------------------------------------------------------------------------------------------
303 protected bool TraceCallback(IEntity ent)
304 {
305 // Return false if entity is not in desired simulation state, contains cloth component (prevent detection of pouches) or is a weapon
306 if (ent.IsLoaded() || ent.GetPhysics().GetSimulationState() == 0 || ent.FindComponent(BaseLoadoutClothComponent) || ent.FindComponent(WeaponComponent))
307 return false;
308
309 //Ignore proxy entities
310 EntityFlags entityFlags = ent.GetFlags();
311 if (entityFlags & EntityFlags.PROXY)
312 return false;
313
314 if (ent.IsInherited(ChimeraCharacter))
315 return false;
316
317 // Filter out dead bodies and wrecks
318 if (IsEntityDestroyed(ent))
319 {
320 if (ent.IsInherited(Vehicle) && m_RplComponent)
321 {
322 if (!m_RplComponent.IsProxy())
323 SCR_EntityHelper.DeleteEntityAndChildren(ent);
324
325 return false;
326 }
327 }
328
329 return true;
330 }
331
332 //------------------------------------------------------------------------------------------------
333 protected bool IsEntityDestroyed(IEntity entity)
334 {
335 SCR_DamageManagerComponent damageManager = SCR_DamageManagerComponent.Cast(entity.FindComponent(SCR_DamageManagerComponent));
336 if (damageManager)
337 return damageManager.IsDestroyed();
338
339 return false;
340 }
341
342 //------------------------------------------------------------------------------------------------
353
354 //------------------------------------------------------------------------------------------------
357 {
358 SCR_EntityLabelPointComponent labelComp = SCR_EntityLabelPointComponent.Cast(ent.FindComponent(SCR_EntityLabelPointComponent));
359 if (labelComp && labelComp.HasLabel(EEditableEntityLabel.GAMELOGIC_RALLYPOINT))
360 {
361 m_RallyPointLabelComponent = labelComp;
362 return false;
363 }
364
365 return true;
366 }
367
368 //------------------------------------------------------------------------------------------------
369 override void EOnInit(IEntity owner)
370 {
371#ifdef WORKBENCH
372 if (m_bShowDebugShape)
374#endif
375
377 return;
378
379 m_SlotManager = SCR_SpawnerSlotManager.GetInstance();
380 if (!m_SlotManager)
381 {
382 Print("Gamemode is missing SCR_SlotManagerComponent, which is required for functionality of SCR_EntitySpawnerSlotComponent", LogLevel.WARNING);
383 return;
384 }
385
386 m_SlotManager.RegisterSlot(this);
387
388 m_RplComponent = RplComponent.Cast(owner.FindComponent(RplComponent));
389 if (!m_RplComponent)
390 Print("SCR_EntitySpawnerSlotComponent is missing RplComponent. It won't work properly without it", LogLevel.WARNING);
391 }
392
393 //------------------------------------------------------------------------------------------------
394 override void OnPostInit(IEntity owner)
395 {
396 super.OnPostInit(owner);
397 SetEventMask(owner, EntityEvent.INIT);
398
399#ifdef WORKBENCH
400 if (m_bShowDebugShape)
401 SetEventMask(owner, EntityEvent.FRAME);
402#endif
403 }
404
405 //------------------------------------------------------------------------------------------------
406 // destructor
408 {
409 if (m_SlotManager)
410 m_SlotManager.UnregisterSlot(this);
411
413 m_RallyPointLabelComponent.GetOnOwnerUpdated().Remove(OnRallyPointUpdated);
414 }
415
416#ifdef WORKBENCH
417 //------------------------------------------------------------------------------------------------
418 protected void DrawDebugShape()
419 {
420 SCR_EntitySpawnerSlotComponentClass prefabData = SCR_EntitySpawnerSlotComponentClass.Cast(GetComponentData(GetOwner()));
421 if (!prefabData)
422 return;
423
424 vector transform[4];
425 IEntity owner = GetOwner();
426 owner.GetTransform(transform);
427
428 int shapeFlags = ShapeFlags.WIREFRAME;
429 m_DebugShape = Shape.Create(ShapeType.BBOX, m_iDebugShapeColor, shapeFlags, prefabData.GetMinBoundsVector(), prefabData.GetMaxBoundsVector());
430
431 m_DebugShape.SetMatrix(transform);
432 }
433
434 //------------------------------------------------------------------------------------------------
435 override void EOnFrame(IEntity owner, float timeSlice)
436 {
437 if (m_bShowDebugShape && m_DebugShape)
438 {
439 vector transform[4];
440 owner.GetTransform(transform);
441 m_DebugShape.SetMatrix(transform);
442 }
443 }
444
445 //------------------------------------------------------------------------------------------------
446 override int _WB_GetAfterWorldUpdateSpecs(IEntity owner, IEntitySource src)
447 {
448 return EEntityFrameUpdateSpecs.CALL_WHEN_ENTITY_VISIBLE;
449 }
450
451 //------------------------------------------------------------------------------------------------
452 override event void _WB_AfterWorldUpdate(IEntity owner, float timeSlice)
453 {
454 if (m_bShowDebugShape && m_DebugShape)
455 {
456 vector transform[4];
457 owner.GetTransform(transform);
458 m_DebugShape.SetMatrix(transform);
459 }
460 }
461#endif
462}
463
EEditableEntityLabel
ArmaReforgerScripted GetGame()
Definition game.c:1398
vector GetOrigin()
RplComponent m_RplComponent
SCR_CharacterSoundComponentClass GetComponentData()
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
int GetCharactersInSlot(out array< ChimeraCharacter > characterArray)
bool IsOccupied()
Returns true, if slot is occupied.
void SetRallyPoint(notnull SCR_EntityLabelPointComponent labelComp)
bool FilterCharactersCallback(IEntity ent)
void ~SCR_EntitySpawnerSlotComponent()
ref array< ChimeraCharacter > m_aCharacterArray
bool IsEntityDestroyed(IEntity entity)
SCR_EntityLabelPointComponent m_RallyPointLabelComponent
bool RallyPointSearchCallback(IEntity ent)
Callback for Query in GetRallyPoint. Returns false, once SCR_EntityLabelPointComponent matching param...
ref array< IEntity > m_aExcludedEntities
void OnRallyPointUpdated()
Called when Rally Point gets moved.
SCR_EEntitySpawnerSlotType GetSlotType()
bool TraceCallback(IEntity ent)
SCR_EntityLabelPointComponent GetRallyPoint()
void FillExcludedEntities()
bool IsEntityLabelInRange(notnull SCR_EntityLabelPointComponent labelComp)
bool CharacterFoundCallback(IEntity ent)
void MoveCharactersFromSlot()
Moves away all characters from slot, if there is suitable empty position in vicinity.
enum EFuelFlowCapacityIn VEHICLE_SMALL
Definition SCR_FuelNode.c:1
enum EFuelFlowCapacityIn VEHICLE_MEDIUM
Definition SCR_FuelNode.c:2
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
void DrawDebugShape(bool draw)
SCR_SlotServiceComponentClass m_SlotManager
Service with basic slot handling functionalities.
enum EVehicleType IEntity
event int _WB_GetAfterWorldUpdateSpecs(IEntity owner, IEntitySource src)
Called after _WB_OnInit or also later when editor needs to know whether _WB_AfterWorldUpdate needs to...
proto external int SetEventMask(notnull IEntity owner, int mask)
proto external GenericComponent FindComponent(typename typeName)
event void _WB_AfterWorldUpdate(IEntity owner, float timeSlice)
Called after updating world in Workbench. The entity must be selected. You can use editor API here an...
proto external EntityFlags GetFlags()
proto external Managed FindComponent(typename typeName)
proto external vector GetOrigin()
proto external Physics GetPhysics()
proto external void GetWorldTransform(out vector mat[])
See IEntity::GetTransform.
proto external bool IsLoaded()
proto external void GetTransform(out vector mat[])
void GetChildren(out notnull set< SCR_EditableEntityComponent > entities, bool onlyDirect=false, bool skipIgnored=false)
bool SetTransform(vector transform[4], bool changedByUser=false)
SCR_EditableEntityComponent GetParentEntity()
static bool IsEditMode()
Definition Functions.c:1566
static bool OrientToTerrain(out vector transform[4], BaseWorld world=null, bool noUnderwater=false, TraceParam trace=null)
void EOnFrame(IEntity owner, float timeSlice)
proto external GenericEntity GetOwner()
Get owner entity.
void EOnInit(IEntity owner)
enum EPhysicsLayerPresets Vehicle
Definition gameLib.c:24
EPhysicsLayerPresets
Enum is filled by C++ by data in project config PhysicsSettings.LayerPresets.
Definition gameLib.c:19
IEntity GetOwner()
Owner entity of the fuel tank.
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
ShapeType
Definition ShapeType.c:13
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
ShapeFlags
Definition ShapeFlags.c:13
SCR_FieldOfViewSettings Attribute
EntityEvent
Various entity events.
Definition EntityEvent.c:14
EntityFlags
Various entity flags.
Definition EntityFlags.c:14
@ INVALID
Missing components, or obstruction test was not possible.
TraceFlags
Definition TraceFlags.c:13