Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ScenarioFrameworkArea.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted/ScenarioFramework", description: "")]
3 {
4 }
5 
6 // Helper class for designer to specify what tasks will be available in this area
8 class SCR_ScenarioFrameworkTaskType
9 {
10  [Attribute("Type of task", UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(SCR_ESFTaskType))]
11  protected SCR_ESFTaskType m_eTypeOfTask;
12 
13  //------------------------------------------------------------------------------------------------
15  SCR_ESFTaskType GetTaskType()
16  {
17  return m_eTypeOfTask;
18  }
19 }
20 
25 {
26  [Attribute(uiwidget: UIWidgets.ResourcePickerThumbnail, "Trigger for area", category: "Trigger")]
27  ResourceName m_sTriggerResource;
28 
29  [Attribute(defvalue: "5.0", UIWidgets.Slider, params: "1.0 1000.0 0.5", desc: "Radius of the trigger area", category: "Trigger")]
30  float m_fAreaRadius;
31 
32  [Attribute(defvalue: "1", UIWidgets.CheckBox, desc: "Activate the trigger once or everytime the activation condition is true?", category: "Trigger")]
33  bool m_bOnce;
34 
35  [Attribute(desc: "Actions that will be activated when Trigger gets activated", category: "OnActivation")]
36  ref array<ref SCR_ScenarioFrameworkActionBase> m_aTriggerActions;
37 
38  [Attribute(desc: "Should the dynamic Spawn/Despawn based on distance from observer cameras be enabled?", category: "Activation")]
39  bool m_bDynamicDespawn;
40 
41  [Attribute(defvalue: "750", desc: "How close at least one observer camera must be in order to trigger spawn", category: "Activation")]
42  int m_iDynamicDespawnRange;
43 
44  SCR_BaseTriggerEntity m_Trigger;
45  ref ScriptInvoker<SCR_ScenarioFrameworkArea, SCR_ScenarioFrameworkEActivationType> m_OnTriggerActivated;
46  ref ScriptInvoker m_OnAreaInit = new ScriptInvoker();
47  bool m_bAreaSelected;
48  SCR_BaseTask m_Task;
49  string m_sItemDeliveryPointName;
50  SCR_ScenarioFrameworkLayerTask m_LayerTask;
51  SCR_ScenarioFrameworkSlotTask m_SlotTask; //storing this one in order to get the task title and description
52 
53  [Attribute(defvalue: "0", desc: "Show the debug shapes in Workbench", category: "Debug")]
54  protected bool m_bShowDebugShapesInWorkbench;
55 
56  //------------------------------------------------------------------------------------------------
58  bool GetDynamicDespawnEnabled()
59  {
60  return m_bDynamicDespawn;
61  }
62 
63  //------------------------------------------------------------------------------------------------
65  void SetDynamicDespawnEnabled(bool enabled)
66  {
67  m_bDynamicDespawn = enabled;
68  }
69 
70  //------------------------------------------------------------------------------------------------
72  int GetDynamicDespawnRange()
73  {
74  return m_iDynamicDespawnRange;
75  }
76 
77  //------------------------------------------------------------------------------------------------
79  void SetDynamicDespawnRange(int range)
80  {
81  m_iDynamicDespawnRange = range;
82  }
83 
84  //------------------------------------------------------------------------------------------------
86  SCR_BaseTask GetTask()
87  {
88  return m_Task;
89  }
90 
91  //------------------------------------------------------------------------------------------------
93  SCR_ScenarioFrameworkSlotTask GetSlotTask()
94  {
95  return m_SlotTask;
96  }
97 
98  //------------------------------------------------------------------------------------------------
100  void SetSlotTask(SCR_ScenarioFrameworkSlotTask slotTask)
101  {
102  m_SlotTask = slotTask;
103  }
104 
105  //------------------------------------------------------------------------------------------------
106  override SCR_ScenarioFrameworkLayerTask GetLayerTask()
107  {
108  return m_LayerTask;
109  }
110 
111  //------------------------------------------------------------------------------------------------
113  void SetLayerTask(SCR_ScenarioFrameworkLayerTask layerTask)
114  {
115  m_LayerTask = layerTask;
116  }
117 
118  //------------------------------------------------------------------------------------------------
120  string GetLayerTaskName()
121  {
122  return m_LayerTask.GetOwner().GetName();
123  }
124 
125  //------------------------------------------------------------------------------------------------
127  SCR_ESFTaskType GetLayerTaskType()
128  {
129  return m_LayerTask.GetTaskType();
130  }
131 
132  //------------------------------------------------------------------------------------------------
134  string GetDeliveryPointName()
135  {
136  return m_sItemDeliveryPointName;
137  }
138 
139  //------------------------------------------------------------------------------------------------
142  void StoreDeliveryPoint(string sDeliveryPointName)
143  {
144  m_sItemDeliveryPointName = sDeliveryPointName;
145  if (!SCR_TaskDeliver.Cast(m_Task))
146  return;
147 
148  SCR_TaskDeliver.Cast(m_Task).SetTriggerNameToDeliver(sDeliveryPointName);
149  }
150 
151  //------------------------------------------------------------------------------------------------
154  void StoreTaskToArea(SCR_BaseTask task)
155  {
156  m_Task = task;
157  }
158 
159  //------------------------------------------------------------------------------------------------
162  SCR_ScenarioFrameworkLayerTask Create()
163  {
164  array<SCR_ScenarioFrameworkLayerBase> aSlotsOut = {};
165  GetAllSlots(aSlotsOut);
166  if (aSlotsOut.IsEmpty())
167  return null;
168 
169  Math.Randomize(-1);
170  SCR_ScenarioFrameworkLayerBase layer = SCR_ScenarioFrameworkLayerBase.Cast(aSlotsOut.GetRandomElement());
171  if (layer)
172  layer.Init(this);
173 
174  return SCR_ScenarioFrameworkLayerTask.Cast(layer);
175  }
176 
177  //------------------------------------------------------------------------------------------------
181  SCR_ScenarioFrameworkLayerTask Create(SCR_ESFTaskType eTaskType)
182  {
183  array<SCR_ScenarioFrameworkLayerBase> aSlotsOut = {};
184  GetSuitableLayersForTaskType(aSlotsOut, eTaskType);
185  if (aSlotsOut.IsEmpty())
186  return null;
187 
188  //there might be more layers in the area conforming to the task type (i.e. 2x the Truck task)
189  Math.Randomize(-1);
190  m_LayerTask = SCR_ScenarioFrameworkLayerTask.Cast(aSlotsOut.GetRandomElement());
191  if (m_LayerTask)
192  m_LayerTask.Init(this, SCR_ScenarioFrameworkEActivationType.ON_TASKS_INIT);
193 
194  return m_LayerTask;
195  }
196 
197  //------------------------------------------------------------------------------------------------
200  void Create(SCR_ScenarioFrameworkLayerTask layerTask)
201  {
202  if (!layerTask)
203  return;
204 
205  m_LayerTask = layerTask;
206  m_LayerTask.Init(this, SCR_ScenarioFrameworkEActivationType.ON_TASKS_INIT);
207  }
208 
209  //------------------------------------------------------------------------------------------------
211  SCR_BaseTriggerEntity GetTrigger()
212  {
213  return m_Trigger;
214  }
215 
216  //------------------------------------------------------------------------------------------------
218  void SpawnTrigger()
219  {
220  Resource resource = Resource.Load(m_sTriggerResource);
221  if (!resource)
222  return;
223 
224  EntitySpawnParams spawnParams = new EntitySpawnParams();
225  spawnParams.TransformMode = ETransformMode.WORLD;
226  GetOwner().GetWorldTransform(spawnParams.Transform);
227 
228  //--- Apply rotation
229  vector angles = Math3D.MatrixToAngles(spawnParams.Transform);
230  Math3D.AnglesToMatrix(angles, spawnParams.Transform);
231 
232 
233  //--- Spawn the prefab
234  BaseResourceObject resourceObject = resource.GetResource();
235  if (!resourceObject)
236  return;
237 
238  string resourceName = resourceObject.GetResourceName();
239  m_Trigger = SCR_BaseTriggerEntity.Cast(GetGame().SpawnEntityPrefab(resource, GetGame().GetWorld(), spawnParams));
240  if (!m_Trigger)
241  return;
242 
243  //m_Trigger.Show(false);
244  m_Trigger.SetSphereRadius(m_fAreaRadius);
245  m_Trigger.GetOnActivate().Insert(OnAreaTriggerActivated);
246 
247  SCR_CharacterTriggerEntity characterTrigger = SCR_CharacterTriggerEntity.Cast(m_Trigger);
248  if (characterTrigger)
249  characterTrigger.SetOnce(m_bOnce);
250  }
251 
252  //------------------------------------------------------------------------------------------------
255  void MoveTaskIconToArea(notnull SCR_BaseTask task)
256  {
257  task.SetOrigin(GetOwner().GetOrigin());
258 
259  }
260 
261  //------------------------------------------------------------------------------------------------
264  bool GetIsTaskSuitableForArea(SCR_ESFTaskType eTaskType)
265  {
266  array<SCR_ESFTaskType> aTaskTypes = {};
267  GetAvailableTaskTypes(aTaskTypes);
268  if (aTaskTypes.IsEmpty())
269  return false;
270 
271  return aTaskTypes.Find(eTaskType) != -1;
272  }
273 
274  //------------------------------------------------------------------------------------------------
276  void GetAvailableTaskTypes(out array<SCR_ESFTaskType> aTaskTypes)
277  {
278  array<SCR_ScenarioFrameworkLayerBase> aSlots = {};
279  GetAllSlots(aSlots);
280  SCR_ESFTaskType eType;
281  SCR_ScenarioFrameworkLayerTask pos;
282  foreach (SCR_ScenarioFrameworkLayerBase layer : aSlots)
283  {
284  pos = SCR_ScenarioFrameworkLayerTask.Cast(layer);
285  if (!pos)
286  continue;
287 
288  eType = pos.GetTaskType();
289  if (aTaskTypes.Find(eType) == -1)
290  aTaskTypes.Insert(eType);
291  }
292  }
293 
294  //------------------------------------------------------------------------------------------------
297  void GetSuitableLayersForTaskType(out notnull array<SCR_ScenarioFrameworkLayerBase> aSlotsOut, SCR_ESFTaskType eTaskType)
298  {
299  SCR_ESFTaskType eType;
300  array<SCR_ScenarioFrameworkLayerBase> aSlots = {};
301  GetAllSlots(aSlots);
302  SCR_ScenarioFrameworkLayerTask pos;
303  foreach (SCR_ScenarioFrameworkLayerBase layer : aSlots)
304  {
305  pos = SCR_ScenarioFrameworkLayerTask.Cast(layer);
306  if (!pos)
307  continue;
308 
309  eType = pos.GetTaskType();
310  if (eTaskType == eType)
311  aSlotsOut.Insert(pos);
312  }
313  }
314 
315  //------------------------------------------------------------------------------------------------
317  void GetAllSlots(out array<SCR_ScenarioFrameworkLayerBase> aSlots)
318  {
319  SCR_ScenarioFrameworkLayerBase slotComponent;
320  IEntity child = GetOwner().GetChildren();
321  while (child)
322  {
323  slotComponent = SCR_ScenarioFrameworkLayerBase.Cast(child.FindComponent(SCR_ScenarioFrameworkLayerBase));
324  if (slotComponent)
325  {
326  aSlots.Insert(slotComponent);
327  }
328  child = child.GetSibling();
329  }
330  }
331 
332  //------------------------------------------------------------------------------------------------
334  void GetAllLayerTasks(out notnull array<SCR_ScenarioFrameworkLayerTask> aLayerTasks)
335  {
336  aLayerTasks = {};
337  SCR_ScenarioFrameworkLayerTask layerTask;
338  IEntity child = GetOwner().GetChildren();
339  while (child)
340  {
341  layerTask = SCR_ScenarioFrameworkLayerTask.Cast(child.FindComponent(SCR_ScenarioFrameworkLayerTask));
342  if (layerTask)
343  aLayerTasks.Insert(layerTask);
344 
345  child = child.GetSibling();
346  }
347  }
348 
349  //------------------------------------------------------------------------------------------------
351  void SetAreaSelected(bool bSet)
352  {
353  m_bAreaSelected = bSet;
354  }
355 
356  //------------------------------------------------------------------------------------------------
358  bool GetIsAreaSelected()
359  {
360  return m_bAreaSelected;
361  }
362 
363  //------------------------------------------------------------------------------------------------
365  void OnAreaTriggerActivated(IEntity entity)
366  {
367  if (m_OnTriggerActivated)
368  {
369  m_OnTriggerActivated.Invoke(this, SCR_ScenarioFrameworkEActivationType.ON_AREA_TRIGGER_ACTIVATION, false);
370  m_OnTriggerActivated.Clear();
371  if (!m_bOnce)
372  return;
373 
374  m_Trigger.Deactivate();
375  }
376  }
377 
378  //------------------------------------------------------------------------------------------------
380  ScriptInvoker GetOnAreaTriggerActivated()
381  {
382  if (!m_OnTriggerActivated)
383  m_OnTriggerActivated = new ScriptInvoker<SCR_ScenarioFrameworkArea, SCR_ScenarioFrameworkEActivationType>();
384 
385  return m_OnTriggerActivated;
386  }
387 
388  //------------------------------------------------------------------------------------------------
390  ScriptInvoker GetOnAreaInit()
391  {
392  return m_OnAreaInit;
393  }
394 
395  //------------------------------------------------------------------------------------------------
397  override void RestoreToDefault(bool includeChildren = false, bool reinitAfterRestoration = false)
398  {
399  m_Trigger = null;
400  m_sItemDeliveryPointName = "";
401  m_LayerTask = null;
402  m_SlotTask = null;
403 
404  super.RestoreToDefault(includeChildren, reinitAfterRestoration);
405  }
406 
407  //------------------------------------------------------------------------------------------------
408  override void DynamicReinit()
409  {
410  Init();
411  }
412 
413  //------------------------------------------------------------------------------------------------
414  override void DynamicDespawn(SCR_ScenarioFrameworkLayerBase layer)
415  {
417  return;
418 
419  m_bInitiated = false;
422  {
423  child.DynamicDespawn(this);
424  }
425 
426  m_aChildren.Clear();
427  }
428 
429  //------------------------------------------------------------------------------------------------
430  override void Init(SCR_ScenarioFrameworkArea area = null, SCR_ScenarioFrameworkEActivationType activation = SCR_ScenarioFrameworkEActivationType.SAME_AS_PARENT)
431  {
433  return;
434 
436  {
437  //If just one condition is false, we don't continue and interrupt the init
438  if (!activationCondition.Init(GetOwner()))
439  {
441  return;
442  }
443  }
444 
445  if (m_eActivationType != SCR_ScenarioFrameworkEActivationType.ON_INIT)
446  PrintFormat("ScenarioFramework: Area %1 is set to %2 activation type, but area will always spawn on Init as default", GetOwner().GetName(), activation, LogLevel.WARNING);
447 
448  if (!m_Trigger)
449  SpawnTrigger();
450 
451  // Area is always spawned on the start
452  super.Init(this, SCR_ScenarioFrameworkEActivationType.ON_INIT);
453 
454  if (m_Trigger)
455  {
456  foreach (SCR_ScenarioFrameworkActionBase triggerAction : m_aTriggerActions)
457  {
458  triggerAction.Init(m_Trigger);
459  }
460  }
461  }
462 
463  //------------------------------------------------------------------------------------------------
464  override void EOnInit(IEntity owner)
465  {
467  if (!gameMode)
468  return;
469 
470  SCR_GameModeSFManager gameModeManager = SCR_GameModeSFManager.Cast(gameMode.FindComponent(SCR_GameModeSFManager));
471  if (gameModeManager)
472  gameModeManager.RegisterArea(this);
473  }
474 
475  override void OnPostInit(IEntity owner)
476  {
477  SetEventMask(owner, EntityEvent.INIT);
478 
479  super.OnPostInit(owner);
480  }
481 
482  //------------------------------------------------------------------------------------------------
483  override protected void DrawDebugShape(bool draw)
484  {
485  Shape dbgShape = null;
486  if (!draw)
487  return;
488 
489  dbgShape = Shape.CreateSphere(
491  ShapeFlags.TRANSP | ShapeFlags.DOUBLESIDE | ShapeFlags.NOZWRITE | ShapeFlags.ONCE | ShapeFlags.NOOUTLINE,
492  GetOwner().GetOrigin(),
494  );
495 
496  if (m_sTriggerResource.IsEmpty())
497  return;
498 
499  Shape triggerdbgShape = null;
500  triggerdbgShape = Shape.CreateSphere(
501  ARGB(100, 0x99, 0x10, 0xF2),
502  ShapeFlags.TRANSP | ShapeFlags.DOUBLESIDE | ShapeFlags.NOZWRITE | ShapeFlags.ONCE | ShapeFlags.NOOUTLINE,
503  GetOwner().GetOrigin(),
504  m_fAreaRadius
505  );
506  }
507 
508 #ifdef WORKBENCH
509  //------------------------------------------------------------------------------------------------
510  override void _WB_AfterWorldUpdate(IEntity owner, float timeSlice)
511  {
512  DrawDebugShape(m_bShowDebugShapesInWorkbench);
513  }
514 
515  //------------------------------------------------------------------------------------------------
516  override bool _WB_OnKeyChanged(IEntity owner, BaseContainer src, string key, BaseContainerList ownerContainers, IEntity parent)
517  {
518  if (key == "m_bShowDebugShapesInWorkbench")
519  DrawDebugShape(m_bShowDebugShapesInWorkbench);
520 
521  return false;
522  }
523 #endif
524 
525  //------------------------------------------------------------------------------------------------
526  // constructor
530  void SCR_ScenarioFrameworkArea(IEntityComponentSource src, IEntity ent, IEntity parent)
531  {
532  m_fDebugShapeRadius = m_iDynamicDespawnRange;
533 #ifdef WORKBENCH
534  m_iDebugShapeColor = ARGB(32, 0x99, 0xF3, 0x12);
535 #endif
536  }
537 }
SCR_BaseGameMode
Definition: SCR_BaseGameMode.c:137
SCR_ScenarioFrameworkActivationConditionBase
Definition: SCR_ScenarioFrameworkSlotBase.c:677
m_eActivationType
protected SCR_ScenarioFrameworkEActivationType m_eActivationType
Definition: SCR_ScenarioFrameworkLayerBase.c:43
GetName
string GetName()
Definition: SCR_ScenarioFrameworkLayerBase.c:85
m_bInitiated
protected bool m_bInitiated
Definition: SCR_ScenarioFrameworkLayerBase.c:72
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
m_Task
SCR_EditableTaskComponentClass m_Task
Editable SCR_BaseTask.
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
SCR_BaseTask
A base class for tasks.
Definition: SCR_BaseTask.c:8
InvokeAllChildrenSpawned
void InvokeAllChildrenSpawned()
Definition: SCR_ScenarioFrameworkLayerBase.c:460
m_bExcludeFromDynamicDespawn
protected bool m_bExcludeFromDynamicDespawn
Definition: SCR_ScenarioFrameworkLayerBase.c:52
GetGameMode
SCR_BaseGameMode GetGameMode()
Definition: SCR_BaseGameModeComponent.c:15
GetOrigin
vector GetOrigin()
Definition: SCR_AIUtilityComponent.c:279
Attribute
typedef Attribute
Post-process effect of scripted camera.
m_bDynamicDespawn
protected bool m_bDynamicDespawn
Definition: SCR_GameModeSFManager.c:49
m_bOnce
protected bool m_bOnce
Definition: SCR_CharacterTriggerEntity.c:38
m_bDynamicallyDespawned
protected bool m_bDynamicallyDespawned
Definition: SCR_ScenarioFrameworkLayerBase.c:74
SCR_ScenarioFrameworkArea
Definition: SCR_ScenarioFrameworkArea.c:24
m_aChildren
protected ref array< SCR_ScenarioFrameworkLayerBase > m_aChildren
Definition: SCR_ScenarioFrameworkLayerBase.c:57
SCR_TaskDeliver
Definition: SCR_ScenarioFrameworkTaskDeliver.c:27
m_iDebugShapeColor
protected int m_iDebugShapeColor
Definition: SCR_ScenarioFrameworkLayerBase.c:69
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
SCR_ScenarioFrameworkAreaClass
Definition: SCR_ScenarioFrameworkArea.c:2
SCR_CharacterTriggerEntity
Definition: SCR_CharacterTriggerEntity.c:17
m_bIsTerminated
protected bool m_bIsTerminated
Definition: SCR_ScenarioFrameworkLayerBase.c:75
m_aTriggerActions
protected ref array< ref SCR_ScenarioFrameworkActionBase > m_aTriggerActions
Definition: SCR_ScenarioFrameworkSlotTrigger.c:9
SCR_ScenarioFrameworkLayerBase
void SCR_ScenarioFrameworkLayerBase(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_ScenarioFrameworkLayerBase.c:875
m_fDebugShapeRadius
protected float m_fDebugShapeRadius
Definition: SCR_ScenarioFrameworkLayerBase.c:66
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
BaseContainerProps
SCR_ScenarioFrameworkAreaClass SCR_ScenarioFrameworkLayerBaseClass BaseContainerProps()] class SCR_ScenarioFrameworkTaskType
Definition: SCR_ScenarioFrameworkArea.c:7
GetTaskType
SCR_ESFTaskType GetTaskType()
Definition: SCR_ScenarioFrameworkLayerTask.c:119
SCR_ScenarioFrameworkLayerBaseClass
Definition: SCR_ScenarioFrameworkLayerBase.c:2
m_aActivationConditions
protected ref array< ref SCR_ScenarioFrameworkActivationConditionBase > m_aActivationConditions
Definition: SCR_ScenarioFrameworkLayerBase.c:46
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180