Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_WallGroupContainer.c
Go to the documentation of this file.
1 #ifdef WORKBENCH
2 class SCR_WallGroupContainer
4 {
5  bool m_bGenerated;
6  float m_fMiddleObjectLength;
7  float m_fSmallestWall = float.MAX;
8 
9  // for quick access, wallgroup lengths are in a seperate array (indices corresponding with those in wallgroup array)
10  protected ref array<float> m_aLengths = {};
11 
12  protected ref array<ref SCR_WallGroup> m_aWallGroups = {}; // sorted by ascending length
13  protected WallGeneratorEntity m_WallGenerator;
14 
15  //------------------------------------------------------------------------------------------------
16  bool IsEmpty()
17  {
18  return m_aWallGroups.IsEmpty();
19  }
20 
21  //------------------------------------------------------------------------------------------------
22  SCR_WallPair GetRandomWall(float biggestSmallerThan = -1)
23  {
24  for (int i = m_aLengths.Count() - 1; i >= 0; i--) // find the longest wall which is smaller than given amount
25  {
26  if (m_aLengths[i] < biggestSmallerThan)
27  return m_aWallGroups[i].GetRandomWall();
28  }
29 
30  return null;
31  }
32 
33  //------------------------------------------------------------------------------------------------
35  void PrepareWallGroups(notnull array<ref WallLengthGroup> groups, bool forward, string middleObj, WorldEditorAPI api)
36  {
37  m_aWallGroups.Clear();
38 
39  array<ref SCR_WallGroup> wallGroupsTmp = {};
40 
41  int forwardAxis = 2;
42  if (forward)
43  forwardAxis = 0;
44 
45  if (!middleObj.IsEmpty())
46  m_fMiddleObjectLength = WallGeneratorEntity.MeasureEntity(middleObj, forwardAxis, api);
47 
48  SCR_WallGroup wallGroup;
49  SCR_WallPair wallPair;
50  float wallLength;
51  foreach (WallLengthGroup group : groups)
52  {
53  wallGroup = new SCR_WallGroup();
54 
55  foreach (WallWeightPair pair : group.m_aWallPrefabs)
56  {
57  wallPair = new SCR_WallPair();
58 
59  wallPair.m_sWallAsset = pair.m_sWallAsset;
60  wallPair.m_fPostPadding = pair.m_fPostPadding;
61  wallPair.m_fPrePadding = pair.m_fPrePadding;
62  wallGroup.m_aWeights.Insert(pair.m_fWeight);
63 
64  wallLength = WallGeneratorEntity.MeasureEntity(wallPair.m_sWallAsset, forwardAxis, api);
65  // wallLength += wallPair.m_fPostPadding;
66  wallPair.m_fWallLength = wallLength;
67 
68  if (wallLength > wallGroup.m_fWallLength)
69  wallGroup.m_fWallLength = wallLength; // biggest length is the one being used for the whole group
70 
71  if (!wallPair.m_sWallAsset.IsEmpty())
72  wallGroup.m_aWallPairs.Insert(wallPair);
73  }
74 
75  if (!wallGroup.m_aWallPairs.IsEmpty())
76  {
77  wallGroupsTmp.Insert(wallGroup);
78  m_bGenerated = true;
79  }
80  }
81 
82  float smallestSize;
83  int smallestIndex;
84 
85  // order groups by length
86  while (!wallGroupsTmp.IsEmpty())
87  {
88  smallestSize = float.MAX;
89  smallestIndex = 0;
90  foreach (int i, SCR_WallGroup g : wallGroupsTmp)
91  {
92  if (g.m_fWallLength < smallestSize)
93  {
94  smallestSize = g.m_fWallLength;
95  if (smallestSize < m_fSmallestWall)
96  m_fSmallestWall = smallestSize;
97 
98  smallestIndex = i;
99  }
100  }
101 
102  m_aWallGroups.Insert(wallGroupsTmp[smallestIndex]);
103  m_aLengths.Insert(wallGroupsTmp[smallestIndex].m_fWallLength);
104  wallGroupsTmp.Remove(smallestIndex);
105  }
106 
107  if (m_WallGenerator && m_WallGenerator.m_bDebug)
108  {
109  foreach (SCR_WallGroup group : m_aWallGroups)
110  {
111  Print(group.m_fWallLength, LogLevel.NORMAL);
112  foreach (SCR_WallPair pair : group.m_aWallPairs)
113  {
114  Print(pair.m_sWallAsset, LogLevel.NORMAL);
115  Print(pair.m_fWallWeight, LogLevel.NORMAL);
116  }
117  }
118  }
119  }
120 
121  //------------------------------------------------------------------------------------------------
122  // constructor
123  void SCR_WallGroupContainer(WorldEditorAPI api, array<ref WallLengthGroup> items, bool forward, string middleObj, WallGeneratorEntity ent)
124  {
125  m_WallGenerator = ent;
126  PrepareWallGroups(items, forward, middleObj, api);
127  }
128 }
129 #endif // WORKBENCH
WallLengthGroup
Definition: WallLengthGroup.c:2
WallWeightPair
Properties exposed in the wall generator property grid after adding a new wall length group.
Definition: WallWeightPair.c:3
SCR_WallGroup
Definition: SCR_WallGroup.c:5
SCR_WallPair
Definition: SCR_WallPair.c:1