Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ObjectPositionalInsects.c
Go to the documentation of this file.
1 [BaseContainerProps(configRoot: true)]
4 {
5  [Attribute(defvalue: "100", UIWidgets.Slider, params: "0 1000 1", desc: "How far the player has to move (squared distance) in order to refresh insects around")]
6  protected int m_iMinimumMoveDistanceSq;
7 
8  [Attribute(defvalue: "30", UIWidgets.Slider, params: "0 100 1", desc: "How far it will seek the objects in range for the Insects to spawn around")]
9  protected float m_fSearchDistance;
10 
11  [Attribute(desc: "Enables setting up which effects are to be spawned around which entitites")]
12  protected ref array<ref SCR_PositionalInsectType> m_aPositionalInsectType;
13 
14  protected ref array<ref SCR_InsectSpawnDef> m_aSpawnDef = {};
15  protected vector m_vCameraPosLooped;
16 
17  protected ref array<float> m_aDayTimeCurve = {};
18  protected ref array<float> m_aRainIntensityCurve = {};
19 
20  //------------------------------------------------------------------------------------------------
22  override void Update(float worldTime, vector cameraPos, float timeOfDay, float rainIntensity)
23  {
24  // Limit processing by time and moved distance
25  if (vector.DistanceSqXZ(m_vCameraPosLooped, cameraPos) < m_iMinimumMoveDistanceSq)
26  return;
27 
28  m_vCameraPosLooped = cameraPos;
29 
30  // First we get closest entities coresponding to each InsectType
31  GetClosestsEntities(cameraPos);
32 
33  // Then we trigger update for each InsectType
34  foreach (SCR_PositionalInsectType type : m_aPositionalInsectType)
35  {
36  type.Update(cameraPos);
37  }
38  }
39 
40  //------------------------------------------------------------------------------------------------
42  protected void ProcessEntity(notnull IEntity entity)
43  {
44  EntityPrefabData prefabData = entity.GetPrefabData();
45  if (!prefabData)
46  return;
47 
48  BaseContainer prefabContainer = prefabData.GetPrefab();
49  if (!prefabContainer)
50  return;
51 
52  float dayTimeCurve;
53  float rainIntensityCurve;
54 
55  // According to the prefab, if time and weather conditions are valid, it is added to the respective Insect type
56  foreach (int i, SCR_PositionalInsectType type : m_aPositionalInsectType)
57  {
59  if (leaves)
60  continue;
61 
62  if (m_aDayTimeCurve[i] <= 0)
63  continue;
64 
65  if (m_aRainIntensityCurve[i] <= 0)
66  continue;
67 
68  BaseContainer prefabContainerToTest = prefabContainer;
69  while (prefabContainerToTest)
70  {
71  if (type.GetPrefabContainerSet().Contains(prefabContainerToTest))
72  {
73  type.AddClosestEntity(entity);
74  return;
75  }
76 
77  prefabContainerToTest = prefabContainerToTest.GetAncestor();
78  }
79  }
80  }
81 
82  //------------------------------------------------------------------------------------------------
84  void GetClosestsEntities(vector cameraPos)
85  {
86  // Clear closest entities for all types and retrieve their curve values for time and weather
87  foreach (int i, SCR_PositionalInsectType type : m_aPositionalInsectType)
88  {
89  type.ClearClosestEntities();
90 
91  m_aDayTimeCurve[i] = SCR_AmbientSoundsComponent.GetPoint(m_AmbientInsectsComponent.GetTimeOfDay(), m_aSpawnDef[i].m_TimeModifier);
92  m_aRainIntensityCurve[i] = SCR_AmbientSoundsComponent.GetPoint(m_AmbientInsectsComponent.GetRainIntensity(), m_aSpawnDef[i].m_RainModifier);
93  }
94 
95  ChimeraWorld world = GetGame().GetWorld();
96  if (!world)
97  return;
98 
99  // Using TagManager we get array of closest entities where Insects can spawn
100  TagSystem tagSystem = TagSystem.Cast(world.FindSystem(TagSystem));
101  if (!tagSystem)
102  {
103  Print("AMBIENT LIFE: SCR_AmbientInsectsComponent: Missing TagManager in the world", LogLevel.WARNING);
104  m_AmbientInsectsComponent.RemoveInsectEffect(this);
105 
106  return;
107  }
108 
109  array<IEntity> closestEntities = {};
110  tagSystem.GetTagsInRange(closestEntities, cameraPos, m_fSearchDistance, ETagCategory.Insect);
111 
112  // Process each entity to add it to the respective Insect type
113  foreach (IEntity entity : closestEntities)
114  {
115  ProcessEntity(entity);
116  }
117  }
118 
119  //------------------------------------------------------------------------------------------------
121  override void OnPostInit(SCR_AmbientSoundsComponent ambientSoundsComponent, SCR_AmbientInsectsComponent ambientInsectsComponent, SignalsManagerComponent signalsManagerComponent)
122  {
123  super.OnPostInit(ambientSoundsComponent, ambientInsectsComponent, signalsManagerComponent);
124 
125  SCR_InsectSpawnDef spawnDef = null;
126  foreach (SCR_PositionalInsectType type : m_aPositionalInsectType)
127  {
128  type.Init(ambientSoundsComponent);
129 
130  if (!type.m_sSpawnDef.IsEmpty())
131  {
132  Resource holder = BaseContainerTools.LoadContainer(type.m_sSpawnDef);
133  if (holder)
134  spawnDef = SCR_InsectSpawnDef.Cast(BaseContainerTools.CreateInstanceFromContainer(holder.GetResource().ToBaseContainer()));
135  }
136 
137  if (!spawnDef)
138  {
139  Print("AMBIENT LIFE: SCR_AmbientInsectsComponent: Missing Spawn Definition Config", LogLevel.WARNING);
140  m_AmbientInsectsComponent.RemoveInsectEffect(this);
141 
142  return;
143  }
144 
145  // Preparing curves and SpawnDefs
146  m_aDayTimeCurve.Insert(1);
147  m_aRainIntensityCurve.Insert(1);
148  m_aSpawnDef.Insert(spawnDef);
149  }
150  }
151 }
ChimeraWorld
Definition: ChimeraWorld.c:12
SCR_AmbientInsectsComponent
Definition: SCR_AmbientInsectsComponent.c:18
SCR_PositionalAmbientLeafParticles
Handles insects that are supposed to be spawned trees.
Definition: SCR_PositionalInsectType.c:230
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
SCR_ObjectPositionalInsects
Handles looped ambient effects around specific entities.
Definition: SCR_ObjectPositionalInsects.c:3
TagSystem
Definition: TagSystem.c:12
ETagCategory
ETagCategory
Definition: ETagCategory.c:1
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_PositionalInsectType
Base class that handles different insects based on their type.
Definition: SCR_PositionalInsectType.c:3
SCR_AmbientSoundsComponent
Definition: SCR_AmbientSoundsComponent.c:17
SCR_InsectSpawnDef
Definition: SCR_InsectSpawnDef.c:2
SCR_AmbientInsectsEffect
Definition: SCR_AmbientInsectEffect.c:2
type
EDamageType type
Definition: SCR_DestructibleTreeV2.c:32
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
BaseContainerProps
SCR_AIGoalReaction_Follow BaseContainerProps
Handles insects that are supposed to be spawned around selected prefabs defined in prefab names array...
Definition: SCR_AIGoalReaction.c:468