Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_PrefabsSpawner.c
Go to the documentation of this file.
4 {
5  [Attribute("0", UIWidgets.EditComboBox, "Defines which spawner uses this Spawn Point", "", ParamEnumArray.FromEnum(EPrefabSpawnType))]
6  protected EPrefabSpawnType m_eType;
7 
8  [Attribute("0", uiwidget: UIWidgets.Flags, "Game Flags required to spawn contained prefabs.", "", ParamEnumArray.FromEnum(EGameFlags))]
9  protected EGameFlags m_eRequiredGameFlags;
10 
11  [Attribute("50", UIWidgets.Slider, "Percentage of how many prefabs to spawn based on how many SCR_PrefabSpawnPoints(with defined type) exists in Mission.", "0 100")]
12  protected int m_iTotalPrefabs;
13 
14  [Attribute("", UIWidgets.Object, "Add categories of prefabs and/or specific prefabs to spawn.")]
15  protected ref array<ref SCR_BasePrefabCategory> m_aPrefabsCategories;
16 
18  protected ref array<SCR_PrefabSpawnPoint> m_aPrefabSpawnPoints;
19 
20  //------------------------------------------------------------------------------------------------
22  EPrefabSpawnType GetType()
23  {
24  return m_eType;
25  }
26 
27  //------------------------------------------------------------------------------------------------
30  void Spawn(array<SCR_PrefabSpawnPoint> prefabSpawnPoints)
31  {
32  if (m_eRequiredGameFlags != 0 && !GetGame().AreGameFlagsSet(m_eRequiredGameFlags))
33  return;
34 
35  if (prefabSpawnPoints == null)
36  {
37  Debug.Error("Can't spawn items of type: " + m_eType.ToString() + " because no spawn points are available.");
38  return;
39  }
40 
41  m_aPrefabSpawnPoints = prefabSpawnPoints;
42 
43  int numberOfPrefabsToSpawn = m_aPrefabSpawnPoints.Count() * m_iTotalPrefabs * 0.01;
44  SpawnPrefabsCategories(numberOfPrefabsToSpawn, m_aPrefabsCategories);
45  }
46 
47  //------------------------------------------------------------------------------------------------
51  void SpawnPrefabsCategories(int numberOfPrefabsToSpawn, array<ref SCR_BasePrefabCategory> prefabsCategories)
52  {
53  int totalRatio = GetTotalRatio(prefabsCategories);
54 
55  if (totalRatio == 0)
56  return;
57 
58  foreach (SCR_BasePrefabCategory prefabCategory : prefabsCategories)
59  {
60  prefabCategory.Spawn(numberOfPrefabsToSpawn * prefabCategory.GetRatio() / totalRatio, this);
61  }
62  }
63 
64  //------------------------------------------------------------------------------------------------
68  void SpawnPrefabCategory(int totalprefabs, ResourceName prefab)
69  {
70  if (totalprefabs <= 0 || m_aPrefabSpawnPoints == null)
71  return;
72 
73  for (int i = 0; i < totalprefabs; i++)
74  {
75  SCR_PrefabSpawnPoint prefabSpawnPoint = m_aPrefabSpawnPoints.GetRandomElement();
76  m_aPrefabSpawnPoints.RemoveItem(prefabSpawnPoint);
77 
78  vector mat[4];
79  prefabSpawnPoint.GetWorldTransform(mat);
80 
81  if (prefabSpawnPoint.ShouldSnapToGround())
82  {
83  vector position = mat[3];
84  position[1] = prefabSpawnPoint.GetWorld().GetSurfaceY(position[0], position[2]);
85  mat[3] = position;
86  }
87 
88  EntitySpawnParams spawnParams = new EntitySpawnParams();
89  spawnParams.TransformMode = ETransformMode.WORLD;
90  spawnParams.Transform = mat;
91 
92  Resource resource = Resource.Load(prefab);
93  if (resource.IsValid())
94  GetGame().SpawnEntityPrefab(resource, null, spawnParams);
95  }
96  }
97 
98  //------------------------------------------------------------------------------------------------
102  protected int GetTotalRatio(array<ref SCR_BasePrefabCategory> prefabsCategories)
103  {
104  int totalWeight = 0;
105  foreach (SCR_BasePrefabCategory prefabCategory : prefabsCategories)
106  {
107  totalWeight += prefabCategory.GetRatio();
108  }
109 
110  return totalWeight;
111  }
112 }
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
AreGameFlagsSet
bool AreGameFlagsSet(EGameFlags checkGameFlags)
Definition: game.c:567
EGameFlags
EGameFlags
GameMode Game Flags represented by bit mask.
Definition: game.c:16
Attribute
typedef Attribute
Post-process effect of scripted camera.
EPrefabSpawnType
EPrefabSpawnType
Definition: SCR_PrefabsSpawnerManager.c:1
m_eType
protected SCR_ECampaignBaseType m_eType
Definition: SCR_CampaignMilitaryBaseComponent.c:59
SCR_PrefabsSpawner
Base class for Prefabs Spawning.
Definition: SCR_PrefabsSpawner.c:3
SCR_BasePrefabCategory
Base class for Prefab Spawning.
Definition: SCR_BasePrefabCategory.c:3
position
vector position
Definition: SCR_DestructibleTreeV2.c:30
SCR_PrefabSpawnPoint
void SCR_PrefabSpawnPoint(IEntitySource src, IEntity parent)
Definition: SCR_PrefabSpawnPoint.c:40
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